How to do a seek (nonadvancing read) on a stream file?

Jerry D jvdelisle2@gmail.com
Mon Feb 3 20:44:35 GMT 2025


On 2/3/25 12:10 PM, Andi McClure wrote:
> (This is an attempt to reply to a Mon Feb 3 19:09:38 GMT 2025 message by 
> Steve Kargl.)
> 
>  > I believe that you are misreading C1223.  The file is
>  > opened with form='unformatted'.
> 
> Hm, okay. I guess it comes down to whether you "diagram" the sentence in 
> the spec as "An ADVANCE= specifier shall appear only in a formatted 
> (sequential or stream) data transfer statement"  or "An ADVANCE= 
> specifier shall appear only in a (formatted sequential) or (stream data 
> transfer) statement". If you interpret it the first way the gfortran 
> behavior is correct (although the error message could be improved…), if 
> you interpret it the second way gfortran is incorrect.
> 
>  > PS: You're looking for the INQUIRE statement.
> 
> In the context of the program I was trying to write, INQUIRE can be used 
> to get the byte length of the file. That is not something I was trying 
> to do. The data was structured, and needed to be parsed to determine the 
> allocation size. In other words INQUIRE is the equivalent of C ftell() 
> and I am looking for the equivalent of C fseek(). (Which the standard 
> appears to only offer through nonadvancing reads… which gfortran appears 
> to disallow for an unformatted stream file. Unless you do the "silly" 
> thing I eventually did, which is to bundle your seek together with the 
> next advancing read.)
> 
> Thanks for the information.
> 

This mailing list is intended for developers and contributors.

I suggest you post your Fortran questions to this group which is a lot 
of users.

https://fortran-lang.discourse.group/

Regards,

Jerry


More information about the Fortran mailing list