How to manage Fortran file units in Julia?

If you are using the GNU Fortran Compiler, you can call FNUM (in Fortran) to convert a file number to a POSIX file descriptor, and given that you can call fdio in Julia to get an IO object.

(This is a GNU extension; other compilers may or may not have similar extensions. Intel Fortran has a similar function called PXFFILENO, and Oracle/Sun Fortran has getfd.)

I can’t find any inverse of FNUM, so you may have to open all the files on the Fortran side and then convert them to Julia IO objects as needed, rather than the reverse.

Don’t close it? OPEN and CLOSE are managed manually in Fortran, as I understand it, so you can do whatever you want.

I’ve been there, so I feel your pain. Ideally, you could port as much of the I/O as possible first, so that you are doing all of your I/O on the Julia side and just calling Fortran for computational routines.

4 Likes