Question

I am trying to read a formatted 2D array from a file on disk into a variable. I have the write operation, which is rather simple, but am stuck on reading the same file. Could someone point me to a sample/writeup on how to do this? The net seems saturated, but I can't find a useful article.

By the way, the reason for the formatted file is to keep it human readable as it contains configuration options.

Was it helpful?

Solution

I've actually found that the physical documentation that comes with the compiler is generally the most readable and most informative for Fortran compilers. Of course, that's not an option if you're using g95 or something like that.

Here's a pretty good page describing most of the technical specs of the read statement. Particularly, see the section on "Format Edit Descriptors" - very handy.

On a side note, if you have the exact write format string, you can usually drop that into a read format string, but if you're writing with WRITE(*,*) or something like that, you probably won't have a valid write format statement to use.

Finally, if you're dumping this out to ASCII so people can read it, and you don't have to worry about backward compatibility, consider dumping everything out as fixed-length fields, as they are by far the easiest things to read back in.

Sorry I can't think of better online resources, but Fortran is woefully underdocumented on the web. I remember once checking to see if g95 had Fortran reference docs, but they mostly only have docs on their specific compiler settings. Good luck, though!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top