Fortran77 automatically determine how many lines of text are at the top of a data file -


an (old) instrument of mine generating ascii data files text descriptions @ top of file, before data. number of lines of descriptive text varies run run. how can fortran77 determine automatically? here example data file, below line.

line of explanatory text.  notice possible blank lines. more text. number of lines not same every time.  1.0, 2.0 2.0, 4.0 3.0, 6.0 4.0, 8.0 

[i found answer myself. posting here others. quite annoying having wait 8 hours answer own question, understand why rule exists. stupid posers!]

a crude effective solution, if text never starts number (which case):

assume input file named data.dat.

    integer numtextlines     real x     open(8,"data.dat")     numtextlines=-1 50  numtextlines=numtextlines+1     read(8,*,err=50) x     close(8)     open(8,"data.dat") 

every time program tries read word text line real variable x, read statement errors , program control goes line 50. if read statement successful, don't want increment numtextlines more. close file , re-open start on beginning. know numtextlines. can read text 1 line @ time, , either save or skip it.

{above method works on of files, not all. way read each line character*500 variable (say, a), test ascii value of first element of character array. gets complicated.}


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -