Re: How to transfer a file in an array




Jean-Charles wrote:
Hello,

I have a file of bytes (containing values between 0 included and 255
included).
I want to transfer this files (by i/o non formatted) in an array of
integer * 1 by fortran 90.

What are the instructions, please ?

--
JC

it's your lucky day. I had exactly that code open in anther window
as I was reading your message. Nwo note, there probably isnt a totally
portable way to do this in FORTRAN. The language is nice enough to
allow you to do I/O and guarantee what you write you can read, in
FORTRAN. But compatibility with raw system binary files is probably
more than the language can guarantee. Also getting the file length
apriori I fudged on and used a DEC function. Here's my code:


subroutine ViewIt( Fn ); USE DFLIB; implicit none;
INTEGER, PARAMETER :: OpenedOkay = 00000;
INTEGER, PARAMETER :: ReadOkay = 00000;
CHARACTER * ( * ), Intent( IN ) :: Fn;
INTEGER :: InFileUnit, OpenCode, &
Answer, AllocStatus, ReadCode, handle, RetCode;
INTEGER* 1, ALLOCATABLE :: FBuf( : );
type( FILE$INFO ) :: Buffer
CONTINUE

InFileUnit = 1; Fn = 'Foo.Bin';

OPEN( UNIT = InFileUnit, NAME = Fn, ERR = 999, &
MODE = 'READ', IOSTAT = OpenCode, RECL=1, &
FORM='BINARY', BUFFERCOUNT = 20, BLOCKSIZE = 512, &
STATUS = 'OLD' )

if( OpenCode == OpenedOkay ) THEN

handle = FILE$FIRST

Answer = GETFILEINFOQQ ( Fn, buffer, handle ) ;
if( Answer > 0 ) THEN
InFileLength = Buffer.Length;
ELSE
print *, 'cant get file info'
ENDIF

ALLOCATE( FBuf( InFileLength ), STAT = AllocStatus );
FBuf = 99;
READ( UNIT = InFileUnit, IOSTAT = ReadCode ) FBuf;
IF( ReadCode == ReadOkay ) THEN

.