input - Fortran non advancing reading of a text file -


i have text file header of information followed lines numbers, data read.

i don't know how many lines there in header, , variable number.

here example:

filehandle:                65536 total # scientific data sets:        1 file description: file contains northern hemisphere polar stereographic map of snow , ice coverage @ 1024x1024 resolution.  map produced using noaa/nesdis interactive multisensorsnow , ice mapping system (ims) developed under directionof interactive processing branch (ipb) of satellite services division (ssd).  more information, contact:  mr. bruce ramsay @ bramsay@ssd.wwb.noaa.gov.  data set #       1 data label:                           northern hemisphere 1024x1024 snow & ice chart coordinate system:                   polar stereographic data type:                           byte format:                              i3 dimensions:                                  1024        1024 min/max values:                         0 165 units:                               8-bit flag dimension #       0   dim label:                         longitude   dim format:                        device coordinates   dim units:                         pixels dimension #       1   dim label:                         latitude   dim format:                        device coordinates   dim units:                         pixels 1    0    0    0    0    0    0    0    0    0    0    0    0    0    0  0 2    0    0    0    0    0    0    0    0    0    0    0    0    0    0  0 3    0    0    0    0    0    0    0    0    0    0    0    0    0    0  0 0    0    0    0    0    0    0    0    0    0    0    0    0    0    0  0 0    0    0    0    0    0    0    0    0    0    0    0    0    0    0  0 

..........................

i open file using:

open(newunit=u, file = valfile, status = 'old', access = 'sequential', action = 'read') 

then, read file line line , test type of line: header line or data line:

ios = 0 while ( .not. is_iostat_end(ios)   )     read(u, '(a)', iostat = ios, advance = 'no') line ! shouldn't advance next line     if (is_iostat_end(ios)) stop "end of file reached before data section."     tol = gettypeofline(line, nvalues) ! nvalues = 1024, needed test if line data.     if ( tol > 0 )   ! if line holds data.         exit    ! exits loop     else         read(u, '(a)', iostat = ios, advance = 'yes') line ! advance next line     end if end 

but first read in loop, advances next line, , problem.

after exiting above loop, enter new loop read data:

read(u, '(1024i1)', iostat = ios) values(c,:) 

the 1024 set of data can span lines, each set row in matrix "values".

the problem second loop doesn't read last line read in testing loop (which first line of data).

a possible solution read lines in testing loop, without advancing next line. used this, advance='no', still advances next line, why?.

a non-advancing read still set file position before start of next record if end of current record encountered while reading file satisfy items in output item list of read statement - non-advancing doesn't mean "never-advancing". can use value assigned variable nominated in iostat specifier read statement see if end of current record reached - use is_iostat_eor intrinsic or test against equivalent value iso_fortran_env.

(implicit in above fact non-advancing read still advances on file positions correspond items read... hence once gettypeofline procedure decides has line of data @ least part of line has been read. unless reposition file subsequent "data" read statements miss part.)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -