I am trying to read/write a binary file in Linux. I am converting code from an older Microsoft FORTRAN '95. I can’t seem to correctly read/write the binary source file, named: CLTAPE. You’ll see the gfortran compile statement in the comments.
This is the hex representation of the first 64 bytes of my CLTAPE file:
1 | 3 | 1 | 4294967278
0 01 00 00 00 03 00 00 00 01 00 00 00 ee ff ff ff ................
10 04 00 00 00 01 00 00 00 e8 03 00 00 01 00 00 00 ................
20 00 00 00 00 00 00 00 00 30 30 30 30 30 31 20 20 ........000001
30 0d 00 00 00 02 00 00 00 d0 07 00 00 15 04 00 00 ................
and my code:
C TAPERD_test.FOR, 22MAR21 JOM
C Compile in Linux with this stmt:
C $ gfortran -std=legacy -o taperd_test *.FOR
PROGRAM taperd_test
INTEGER*4 ibufno,indxbg, irecf, irecl
OPEN (UNIT=2, FILE='CLTAPE', STATUS='OLD',
+ ACCESS='SEQUENTIAL',
+ RECL= 4,
+ FORM='UNFORMATTED')
READ (UNIT=2, IOSTAT=istat)
+ ibufno, indxbg, irecf, irecl
WRITE (*,'(A8,I4,A9,I4)') 'IBUFNO=',ibufno,'INDXBG=',indxbg
WRITE (*,'(A7,I2,A7,I6)') 'IRECF=',irecf, 'IRECL=', irecl
END
Execution Results:
$ ./taperd_test
IBUFNO=**** INDXBG=****
IRECF= 1 IRECL= 0
I think I should be hoping to see:
IBUFNO= 1 INDXBG= 3
IRECF= 1 IRECL= 4294967278
I have tried different record lengths: 8, 64, 1024
and a few other unit numbers to no avail.
Any suggestions as to why the output does not correspond to what I am expecting?
thanks for reading…
p.s. - those are just my remarks above the hex code: 1 | 3 | 1 | 4294967278
edited 23Mar2021
This is the solution, and the code that worked:
PROGRAM taperd_test ! TAPERD test for CLTAPE; IBM 360 APT
! Compiled with: $ gfortran -o taperd_test *.FOR
OPEN (UNIT=2, FILE='CLTAPE', STATUS='OLD',
+ ACCESS='STREAM',
+ FORM='UNFORMATTED')
READ (UNIT=2, IOSTAT=istat)
+ ibufno, indxbg, irecf, irecl
WRITE (*,'(A8,I4,A9,I4)') 'IBUFNO=',ibufno,'INDXBG=',indxbg
WRITE (*,'(A7,I2,A7,I6)') 'IRECF=',irecf,'IRECL=',irecl
END
and the results:
$ ./taperd_test
IBUFNO= 1 INDXBG= 3
IRECF= 1 IRECL= -18
thanks guys…