Hi,
Im new to fortran and Im trying and (failing) to solve my little
problem. Any help would be much appreciated?!
Im trying to read a text header that I have appended to the top of a
binary file and then read the binary file
ie.
1
360
720
0
Blah blah blah
where blah is the start of the binary file.
I can't seem to work out how to read the binary part - i.e. skip over
the header bit. So far I have
PROGRAM read_binary
IMPLICIT NONE
INTEGER :: num_rows , num_cols , num_frames , sizeofbyte = 1
INTEGER, ALLOCATABLE, DIMENSION (:) :: pft
INTEGER :: junk(10)
INTEGER :: i, stdin = 10, hdr_length = 4
INTEGER :: ioerr = 0
OPEN ( stdin, FILE = '/dev/stdin', STATUS = 'old', ACCESS = 'stream',
&
FORM = 'FORMATTED', IOSTAT = ioerr )
IF ( ioerr /= 0 ) THEN
PRINT *, "Error opening file"
STOP
END IF
DO i = 1, hdr_length
READ ( stdin, *, iostat = ioerr ) hdr_stuff(i)
IF ( ioerr /= 0 ) THEN
PRINT *, "Error reading file header"
STOP
END IF
END DO
num_frames = hdr_stuff(1)
num_rows = hdr_stuff(2)
num_cols = hdr_stuff(3)
ALLOCATE ( pft(num_rows * num_cols * num_frames) )
PRINT *, num_frames
PRINT *, num_rows
PRINT *, num_cols
CLOSE ( stdin, IOSTAT = ioerr )
IF ( ioerr /= 0 ) THEN
PRINT *, "Error closing file"
STOP
END IF
OPEN ( stdin, file = '/dev/stdin', form = 'unformatted', access =
'direct', &
recl = sizeofbyte, iostat = ioerr )
IF ( ioerr /= 0 ) THEN
PRINT *, "Error opening file for bin"
STOP
END IF
END PROGRAM read_binary
As I said I think that the way I have approached it thus far is ok -
open file read header, close file, reopen file and try and read
binary. Only I have no idea how to read the binary part - I can't seem
to skip over the binary bit!!
Thanks.


|