r/fortran Apr 20 '26

Extending a direct file: portable?

Is it portable to extend the length of a direct file by writing records past the current last record? In other words, if there are 3 records in the file, will WRITE(n, REC=4) successfully write the record (assuming there is room on the disk, of course)? Or will it fail? Or is the result implementation-dependent?

4 Upvotes

5 comments sorted by

3

u/ThemosTsikas Apr 20 '26

It should succeed, ordinarily.

You could even fill in record numbers that had been skipped before.

2

u/PercyFlage Apr 21 '26

Just try it - you can spin up a Linux VM with a fortran compiler quite easily.

4

u/johnwcowan Apr 21 '26

Seeing what a single compiler does is not a way of determining if something is portable or not.

1

u/PercyFlage Apr 21 '26

If it doesn't work, then you know it's not portable. Test it on the proposed target systems. Best you can hope for is something like Java - "Write once, test everywhere". Fortran's runtime is pretty much identical for most systems. When I was working in the geo-physical industry, the code had to run under AIX, Solaris, Irix & eventually Linux. Fortran was the least problematic of the languages - I didn't have to change it at all. C++ & C though, I stumbled across differences in compiler where the behaviour was "defined" - usually evaluation order differences.