I am editing a fortran 90 to read a file. A particular file happens to be ‘contaminated’ with some extra information, so I wanted to attempt a read and then rewind; reread if in error:
open(filenum,file=filename,form="unformatted",iostat=ierr) //'direct' access
...lots of stuff...
here = ftell(filenum)
read(filenum,iostat=ierr) var1, var2 //try reading as var1, var2
if(iswrong(var1, var2)) then //check if correct
call fseek(filenum,here-ftell(filenum),1) //rewind
read(filenum,iostat=ierr) vara, varb, varc //read as different type
endif
However, when I compile this program, I get
Undefined symbols:
"_fseek_", referenced from:
___myreader__subroutine_name in myreader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
(I am trying to compile on gfortran (i686-apple-darwin8-gfortran-4.2)). I understand that fseek is not a standard fortran routine.
I wonder if there is an alternative. I understand I can do something like read(filenum,rec=somevalue) but how can I use this in a similar fashion? I also thought to attempt reading with read(,advance='no') for testing and then reading again with advance='yes' if it is in the correct format, but this requires a specific format expression, which is not specified. Thank you.
You have to use backspace to go back to the previous record. Traditional Fortran IO is record based, non stream based (like in C)