1

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.

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you Mike, I had actually just read through that page. I think i am close. I am just running into an end-of-record error. Ahh, the fun of a new language :)
If you're specifying a set record length, you probably don't need to - reading and writing ASCII usually isn't done with record sizes, but there are always exceptions :) If you're hitting EOF before you think you should, that's a different story.
Well, when reading an array, should i not specify the length? I two values specifying the size of a 2D array preceeding the array values. I am using: READ(iFile,*) (nb2(i),i=1,2) to read 'two' values. Thank you again Mike
Okay, this got strange. I removed the file from disk and started over. Seems to be working now! :D
Wow! just read your last two comments. Strange. Do you know if you might have had an extra crlf in there, or maybe no crlf when your code was expecting one?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.