How to read number of lines present in a text file.
My text file seems to be like:
1
2
3
.
.
.
n
Although unclear, but i think, if you just have to know the number lines in the files, just use wc -l in the command line
if you want to do anything further, just read the number of lines a character string and count until the end of file is encountered. here is the code below
character :: inputline*200
OPEN(lin, file=inputfile, status='old', action='read', position='rewind')
loop1: DO
READ(lin,*,iostat=eastat) inputline
IF (eastat < 0) THEN
numvalues = numvalues + 1
WRITE(*,*) trim(inputfile), ' :number of records =', numvalues-1
EXIT loop1
ELSE IF (eastat > 0) THEN
STOP 'IO-error'
ENDIF
numvalues = numvalues + 1
END DO loop1
hope that helps!