Menu
Eg, in Dec fortran, this is -convert bigendian. Detect the byte order of your machine and swap as needed. Again, you need to know what convention your input file is to know if it is different from the machine you are reading from (usually easy to figure out since the data will be garbage if you have it wrong). A Fortran program reads from standard input or from a file using the read statement, and it can write to standard output using the print statement. With the write statement one can write to standard output or to a file. Before writing to a file, the file must be opened and assigned a unit number with which the programmer may reference the file.
![]()
Dealing with Binary Data FilesBinary (unformatted) files are 100% compatible among all fortran compilers and all c compilers on all hardware platforms. You just have to know how to read them! Some conventions will make this trivial as opposed to a hardship.
![]()
I regularly exchange data among Sun, Alpha, Athlon, Intel, G4, IBM SP, you name it, and have figured out how to make it work seamlessly - mostly by using netCDF.ALWAYS use direct access for binary output. This avoids currupting the file with headers on each record and allows you to read the data in arbitrary chunks, not just the chunks of the writing program. With sequential access, you not only need to know how big the data array is, but how it was written. Also, sharing between c and fortran causes real headaches with sequential access.Direct access is awkward for saving mixed data to a single file.
That's probably a bad idea anyway - how are you going to remember what's in the file? Use a self-describing format like ascii or netCDF for mixed-data files. Or use separate files for each data type with filenames that tell you what's in them.Note that on some compilers (eg Dec Fortran) you need to specify the record length is measured in bytes (eg -assume byterecl).
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |