next up previous contents
Next: FTNUNSTRIP - convert C Up: Data Format conversion Previous: FTNSTRIP - Importing Fortran   Contents

Going from C to Fortran

It is fairly easy to transport data made with Fortran code to C, however, it may not be so easy to go the other way. On the SGI Power Challenge, it is possible to read a file of C-floats called ``infile'' via, open and read statements that look like:

OPEN(99,file='infile',form='system') 

DO i=1,number
READ(99) tempnumber
Array(i)=tempnumber
END DO

CLOSE(99)

The statement "form='system'" does not work on all machines, however, as it is likely that this is not standard Fortran. The general format command to read in binary is "form='unformatted'". This may not work on other systems, (for example, SUN). Indeed, it may not be generally guaranteed that you can read binary files in Fortran that have been created with a C-programs (as in SU).

If you have problems with binary and the input files are not too big you could convert to ASCII (using 'b2a') and use formatted I/0

OPEN(99,file='infile')

DO i=1,number
READ(99,*) tempnumber
Array(i)=tempnumber
END DO

CLOSE(99)



Subsections

John Stockwell 2007-04-10