REC length problem when writing unformatted, direct access

I’m a fortran starter. I’m reusing some code. My goal is to have a file with 4 4byte vars and a variable number of 2byte vars, usually a very big number. I’m using fortran77 so I can’t use the ‘binary’ form (is that correct?). So my code goes more or less like this:

open(unit=13,err=49,file=fnamer,status=‘new’,
& form=‘unformatted’,access=‘direct’,recl=4)
write(13,REC=1) ncon
write(13,REC=2) nskip
write(13,REC=3) nleap
write(13,REC=4) nvar
C Unit 13 is closed so can be opened with a record length of 2 bytes
close(unit=13)
open(unit=13,err=49,file=fnamer,status=‘old’,
& form=‘unformatted’,access=‘direct’,recl=2)
rewind(unit=13)

+++++ some stuff in here ++++++
+++++ next is inside a do loop ++++

ii = ii + 1
C The file already has 16 bytes written, so, it starts at 8*2+1
write(13,REC=ii+8) rmsdi

So this, whether “well” programmed or not, usually works. The problem is: in certain cases I have huge amount of data so that “ii” is bigger than 2147483647, maximum number of items for a 4byte integer.

The error goes like this:

214PGFIO-F-242/unformatted write/unit=13/illegal operation on direct access file.
File name = rmsdmat.bin unformatted, direct access record = 2147483647

I tried to declare ii as integer*8 but the error is the same. So, finally, my question is: am I having the problem with the variable (somehow not being 8byte though declared) or the problem is with “REC”, not being allowed to be grater than 4byte integer?

Thank you in advanced and remember I’m new into fortran77 world!

I’m thinking about closing the file before it reaches limit, create a new one, and then use unix’s cat to concatenate them. Not clean, not elegant, but probably would work.

Note that you are writing record information for every record.

If you are using a fairly recent version of pgf77, you can use:

open(unit=10,file=‘test.dat’,access=‘sequential’,form=‘binary’)

And that might give you better luck. You do not need to specify a
record number then.
Also, there is no need to write out the entire data block in one fell swoop, if you don’t want to.

Note that in PGI 7.0, the recommended method will be to use the new F2003 feature of “stream i/o”.

I’ll try thank you!

Anyway I tried closing the file when “ii” was huge, then create another file, and finally concatenated them.

If you’re on a 32-bit system, try adding “-Mlfs” to enable large file support.

  • Mat