- #1
kranthi4689
- 16
- 0
Hi All,
While trying to read a matrix from data file using fortran90 code ,I get garbage values and a backtrace error.
The code I use is
I attached my data file. I want to read the matrix that starts after str_name.
Kindly help me in understanding the error in my code. thank you.
While trying to read a matrix from data file using fortran90 code ,I get garbage values and a backtrace error.
Error termination. Backtrace:
#0 0x7f4a4de3631a
#1 0x7f4a4de36ec5
#2 0x7f4a4de3768d
#3 0x7f4a4dfa4d42
#4 0x7f4a4dfa6ad5
#5 0x7f4a4dfa80f9
#6 0x56040bbeae57
#7 0x56040bbeaf93
#8 0x7f4a4da4bb96
#9 0x56040bbeaa29
#10 0xffffffffffffffff
The code I use is
read_file.f90:
program read_file
implicit none
integer :: ios,i,j
character (len =40) :: str_name
character (len=1000) :: line
integer , dimension (10) :: vect
real , dimension (11,16) :: hamilt
str_name = ' OVERLAP MATRIX - CELL N. 1( 0 0 0)'
open(unit=20,FILE='data.txt',iostat=ios,status='old')
if ( ios /= 0 ) stop "Error opening inputfile"
do
read(20,'(A)',end=100) line
if (line(1:40) == str_name ) then
write (*,*) "found line"
write (*,*) line
!read (20,*) (a(i,j), j = 1,16))
do i = 0,10
read (20,*,end =100) (hamilt(i,j), j=1,16)
write (*,*) hamilt(i,j)
enddo
endif
enddo
100 close(20)
end program
Kindly help me in understanding the error in my code. thank you.