ANN: FortranFiles.jl

Dear Julia community,

I’d like to announce FortranFiles.jl, a small package for reading and writing Fortran “unformatted” (i.e. binary) files. You might want to use this if you have legacy data produced by Fortran programs, or if you need to produce data which your Fortran program can digest. Thus it can help to incrementally move your computing tools from Fortran to Julia. :wink:

The package is available in METADATA, so you can just Pkg.add it. Julia versions 0.5 and 0.6 are supported. Full documentation is available here, including examples of how to translate your Fortran read and write statements into Julia.

The package currently focuses on “sequential-access” files, which are the most commonly used binary files in Fortran. In such files, data records are preceeded and followed by “record markers” which encode the length of the record. Unfortunately, Fortran compilers differed in the way to encode these markers, and this package supports various such encodings (well, the ones I know of).

“Direct-access” files are currently not supported, but the package has been designed such that it shouldn’t be too difficult to add support. However, I have no experience with such files and no idea about potential platform-dependent quirks, so your input would be needed if you need support for such files. Feel free to open an issue or PR.

Modern Fortran also offers “stream-access” which is basically like binary output in C. Julia’s native facilities should have no trouble interfacing with such data.



Excellent. Thanks much for this.

Nice, can this package also read / write Fortran namelist ?

Sorry, no. This package only reads binary files. Reading namelists would require parsing a substantial amount of Fortran syntax, which is quite orthogonal to what this package does.

Great package.

Just a suggestion: perhaps when reading into a preexisting array, the reading function should be called read!, with the exclamation mark, and not return anything?

You are right, it should be read! for reading into existing arrays. I’ve opened an issue so I don’t forget to fix it in a future release.

1 Like