Appending data to an binary stream file in Fortran

Hi,

I’m writing a binary file in Fortran using stream access, opened as follows:

open(500,file='temp.bin',status="new",action="write",access='stream',form='unformatted')

Now, at a later stage I want to reopen the file and append additional data to it. I figured the way to do this is to use the position=‘append’ specifier as follows:

open(500,file='temp.bin',status="old",action="write",access='stream',form='unformatted',position='append')

With the Intel compiler this works fine. With PGI I get the following runtime error:
PGFIO-F-202/OPEN/unit=500/conflicting specifiers.

Why does this not work with PGI, and what would be the best alternative?

Thanks in advance,
Maarten

Hi Maarten,

Can you please either post or send to PGI Customer Service (trs@pgroup.com) a reproducing example? Also, please include what version of the compiler and OS you’re using.

Note that the first open shouldn’t matter given the error has to with some conflict with the specifiers given in the second open. However I’m not sure what the conflict is. The open statement looks fine to me and when I try it in a simple example, it works as expected.

Thanks,
Mat

Hi Mat,

Thanks for your reply. Here’s the output from pgf95 -V:
pgf95 11.10-0 64-bit target on x86-64 Linux -tp istanbul

The code below generates the following run-time error on my system:
PGFIO-F-202/OPEN/unit=500/conflicting specifiers.
File name = test.bin
In source file binappendtest.f90, at line number 8

Best,
Maarten

program test
integer, parameter :: PR = 8
real(PR) :: tmp(5)
open(500,file='test.bin',status='new',action='write',access='stream',form='unformatted')
write(500) 1._PR,2._PR,3._PR
call flush(500)
close(500)
open(500,file='test.bin',status='old',action='write',access='stream',form='unformatted',position='append')
write(500) 4._PR, 5._PR
call flush(500)
close(500)
open(500,file='test.bin',status='old',action='read',access='stream',form='unformatted')
read(500) tmp
print *, tmp
end program test

Hi Maarten,

While I’d need to do some digging as to why, this issue seems to have gone away with the 12.6 release. Do you have access to a newer compiler version?

  • Mat

I’ll ask my sysadmin. I’ve found a workaround so it’s not very urgent any more. But I’d still be interested to be updated about this.

Best,
Maarten

I found the TPR, #18677. Looks like prior to 12.6 we disallowed using position with stream access. There was a secondary issue where position couldn’t zero that was fixed in 12.10.

  • Mat