This question already has an answer here:
- Skip a line from text file in Fortran90 3 answers
I have this data file
and want to read this data without line 1,2,3,4,5
program example
real data(15,9)
OPEN ( unit=10, file='filename' )
do i = 1, 15
READ (10, *) (data(i,j), j=1,10)
enddo
print *, data(4,1), data(4,2), data(4,3)
stop
end
this is my fortran code.
how can i change this code
Looking something like this?
input file: data
fortran code:
Result
NB: This is a minimal example, just for showing the skipping. You will change the read inside
lread
loop to actually read your file according to your data formatOne way to do this is to put in a READ statement for each line that you want to "skip". Each time a READ statement is encountered, it reads in the data and then moves the "pointer" in the file down to the next line. So, for example, to skip 3 lines of header information:
This in effect READs and stores nothing, but moves the pointer in the file forward 3 lines.