next up previous contents
Next: H2B - Importing 8 Up: Going from C to Previous: Going from C to   Contents

FTNUNSTRIP - convert C binary floats to Fortran style floats

However, another possibility is to make ``fake'' Fortran floats with a C-program. Such a program is ftnunstrip.

This program assumes that the record length is constant throughout the input and output files. In fortran code reading these floats, the following implied do loop syntax would be used: DO i=1,n2 READ (10) (someARRAY(j), j=1,n1) END DO Here n1 is the number of samples per record, n2 is the number of records, 10 is some default file (fort.10, for example) which is opened as form='unformatted'. Here ``someArray(j)'' is an array dimensioned to size n1.

Please note that the Fortran style of having BOR and EOR markers is smart, if used properly, but is stupid if used incorrectly. The Fortran READ statement finds out from the BOR marker how many bytes will follow, reads the number of values specified, keeping track of the number of bytes. When it finishes reading, it compares the number of bytes read to the number of bytes listed in the EOR value, and can effectively trap errors in bytes read, or premature EOR.

Because there is an additional ``sizeof(int)'' (usually 4 bytes) at the beginning and end of every record, it is smart to have as few records as is necessary. The worst case scenario is to have every value of data be a record, meaning that the size of the file could be 2/3 BOR and EOR markers and 1/3 data!


next up previous contents
Next: H2B - Importing 8 Up: Going from C to Previous: Going from C to   Contents
John Stockwell 2007-04-10