Software Archive
Read-only legacy content
17061 Discussions

Record Length

Intel_C_Intel
Employee
496 Views
Hi,
I want to open an existing direct access unformatted file, whose record length I don't know. In which way I can get the record legth for OPEN statement. Following does not work, because it returns always 0 or 132.

INQUIRE(FILE=FNAME,RECL=LRL_H)

The file has been created as follows:

OPEN(LU, ACCESS='DIRECT', ERR=999, FILE=FNAME,
& FORM='UNFORMATTED', STATUS='NEW', RECORDTYPE='FIXED',
& RECL=LRL_H)

Thanks! KK
0 Kudos
3 Replies
Steven_L_Intel1
Employee
496 Views
There's no way to do this reliably - the record length is not stored in the file. If you have some idea of the length, you can see if it is an integral divisor of the file size in bytes (keep in mind that unformatted RECL values are in units of 4 bytes.)

Steve
0 Kudos
sabalan
New Contributor I
496 Views
I was just wondering: Shouldn't you open the file with STATUS='OLD' if it is an EXISTING file you are trying to open?

Regards,
Sabalan.
0 Kudos
Intel_C_Intel
Employee
496 Views
If the record length has been written into a direct access file, it can be opened correctly with two subsequent OPEN calls. Consider following simple example:

WRITE(LU,REC=1) Rec_len
CLOSE(LU)

IRECL = 256
OPEN(LU,ACCESS='DIRECT',ERR=999,FILE=FNAME,
& FORM='UNFORMATTED',STATUS='OLD',RECL=IRECL)
READ(LU,REC=1) Rec_len

CLOSE(LU)
OPEN(LU,ACCESS='DIRECT',ERR=999,FILE=FNAME,
& FORM='UNFORMATTED',STATUS='OLD',RECL=Rec_len)

This is, of course, possible if the record length has been written into the file. It is not necessary that it is the first item in the first record, but thus makes things easier.

Kari K
0 Kudos
Reply