Translating Fortran to Julia

I’m translating some old Fortran code to Julia. It’s pretty straightforward, but I only picked up Fortran to be able to translate this project. I see at some points things like

     OPEN(2, file='pv.txt')
     WRITE(2, *)"lambda1",19,20,21

What would be the equivalent in Julia?

1 Like

I am old enough to remember programming in Fortran using magnetic tapes.
The REWIND statement rewinds the tape to the start. So you will effectively be overwriting that file.
Just open a file for writing as normal, not as an append.
open(“pv.txt”, “w”)

Stop me before I start talking about mounting ring out / ring in


haha, I have heard about those magnetic tapes you talk about.

The equivalent of REWIND in C stdlib and also Julia is the seek function. Without the REWIND (or seek) the writing would start wherever the tape had been left. Perhaps this is not relevant any more for modern I/O. But just in case I would translate the REWIND to seek(io, 0) .


Could I help with your translation project? I even have this book on my bookshelf, and no it is not a spoof!

Oh, thank you!

It’s around 20k lines of code but very straightforward, as it is mainly manipulation of matrices and vectors.

I’m checking that matrices that are constructed inside subroutines are preallocated (Fortran does that in the declaration of variables section of a subroutine).

The main time-consuming task is changing the indexation of matrices from () to []. It is time consuming because one has to interpret whether some parenthesis are actually grouping operations, rather than indexing or calling functions.

I’m also changing spelled-out greek letters to unicode (alpha to α), but that’s just me.

@Raf posted this rough translator:, but it doesn’t catch all translation instances (and I think it doesn’t work with Julia 1+).

If that is something you are interested in, I uploaded some of the files to my GitHub:


Sorry for being off-topic.
Actually, I think it is. We used a lot of tapes for long-term backup (see: LTO)
As far as I know it is pretty common for backup solutions.


Yes, there should be still tape drives around. According to my memory the FORTRAN rewind (on VAX VMS, Norsk Data SINTRAN, etc.) would rewind the tape drive and subsequent writes would then overwrite files that were on the tape before, starting with the first one, and make the full length of the tape available for writing. To do this in Julia, one would need to use an external utility like mt. However, the file name 'pv.txt' suggests, that this is intended for ordinary files on a disk, and then the REWIND just after the OPEN has no effect. Just don’t open for appending, as already said. The equivalent of the WRITE is probably println (write would be in case of `OPEN( …, FORMAT=‘unformatted’) in FORTRAN).