setting file position in fortran / std preprocessor defs

Hi all,

I recently found that setting the file position indicator using WRITE() and the POS specifier seems to set the position one byte further than fseek() in C would. Basically, the following code would NOT put your file position back to the same location:

inquire(unit=unitNo,pos=filePos)
write(unit=unitNo,pos=filePos)

Is this correct behavior?


The intel compiler behaves like fseek() in this respect. Since I need to port my code between the two compilers, I want to solve this using the preprocessor. Is there a standard PP defition that identifies the PGI compiler? I can’t find it in any manual.

Thanks in advance and best,
Maarten

The Fortran 2003 Standard says in Section 9.5.1.10:

1 If the file is connected for formatted stream access, the file position specified by POS= shall be equal to

2 either 1 (the beginning of the file) or a value previously returned by a POS= specifier in an INQUIRE

3 statement for the file.

Hi Maarten,

Is this correct behavior?

No. This appears to be a compiler error when using formatted and unformatted streams. This has been logged as TPR#18246 and is expected to be fixed in the 12.0 release.

Thanks for the report,
Mat

Hi Mat

No. This appears to be a compiler error when using formatted and unformatted streams. This has been logged as TPR#18246 and is expected to be fixed in the 12.0 release.

Thanks! I thought it’d be weird if the inquiring and setting of file position would behave differently.

Before I have version 12.0 I need to find a solution to make my code portable. Is there a standard preprocessor definition that indentifies the PGI compiler?

Best,
Maarten

Maarten,

I have used __PGI in the past to preprocess out bug-inducing code. Try that.

Matt

I have used __PGI in the past to preprocess out bug-inducing code. Try that.

Thanks! That worked.

Maarten