Re: Fortran to read 16 or 32 bit binary files



<pradeep.bhattad@xxxxxxxxx> wrote in message news:b89c4858-29b4-4f1c-89a0-8629b14f0120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Hi Everyone
| I use XLF95 compiler on UNIX operating system. I am able to read and
| write binary files successfully using following piece of code.
|
| PROGRAM TEST
| IMPLICIT NONE
| CHARACTER(1)::B
| INTEGER::MAT(100),I
|
| ! To Read 8 bit Binary Files
| OPEN(UNIT=1,FILE='file_read.bin',FORM='UNFORMATTED',ACCESS='STREAM')
| DO I=1,100
| READ(1) B
| MAT(I)=ICHAR(B)
| ENDDO
| CLOSE(1)
|
| ! To Write 8 bit Binary Files
| OPEN
| (UNIT=1,FILE='file_write.bin',FORM='UNFORMATTED',ACCESS='STREAM')
| DO I=1,50
| WRITE(1) CHAR(MAT(I))
| ENDDO
| CLOSE
| (1)
|
| STOP
| END PROGRAM TEST
|
|
| However i can read and write integer values between 0-255 (8 bit or
| 2^8). I there a way to read / write 16 or 32 bit integer values?

I guess that it depends on whether you want to process arbitrary
binary files, or whether you just want to read and write
32-bit integers (and other things such as REALs, etc.

So, which is it?


.


Quantcast