reading string of floats without specifying field widths

I have a large text file with a lot of lines of the form:

solzen= 0.0000000E+00 10.00000
alb,xindx,imin,frac,aeropt = 6.761 0.023 11 100.0 0.19440E+00
1.8679 1.8538 1.8439 1.8197 1.7722 1.7360 1.7019

and I’m trying to read it into my Fortran code without laboriously
counting the field widths for each of the floats. The formatting
of this file is not constant.

I’m able to read in the first line correctly with :
read(10, ‘(10x, f, f)’, iostat=istat) sza_low, sza_upp

but am unable to read in the second line:
read(10,‘(30x,f,f,i,f,f)’,iostat=istat) f1,f2,i1,f3,f4

where all of the variables are real’s except for the integer i1.

I would appreciate some information as to how best to read in
this file. I’m really trying to avoid having to specify field
widths for all the “f” and “i” formatting statements because it’s
a very large text file.

Thanks,

Catherine

Hi Catherine,

You might be able to use list-directed I/O, provided the number of entries are consistent with each read. If it’s variable and you don’t always know how the data will be presented in the file, you may need to dump the whole line into a character array and then parse the array. Another idea is to write a C function and use scanf.

Hope this helps,
Mat