- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to use an internal read as follows:
if (iStnPress /= 99999) read(iStnPress, '(f5.1)') StnPress
Here, iStnPress is declared an integer; StnPress is declared real.
Before the line is executed, iStnPress has been read as '9245'.
My hope was to have StnPress be set to '924.5'
Unfortunately, I get a runtime crash w/ IVF, with the hint that it's taking '9245' to be a unit number.
Any thoughts? Am I trying to do the impossible?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The first argument of READ should be an integer or a character variable/expression. If the former, that argument is the unit number of an external file. If the latter, that argument is regarded as the contents of an internal file. A useful way to think of the state of affairs is to think of the unit number as a defined channel number from which to read via an unnamed buffer, and the internal file as a named buffer that has already been filled in some way, leaving the original unit number unnamed.
You are trying to make up additional interpretations that are not only outside of the Fortran rules, but in disagreement with the rules. When do you expect an integer to be interpreted as a unit number and when should the same integer be interpreted differently? Secondly, remember that an integer is represented internally in 2-s complement binary. How could you ever read a binary integer using an Fw.d format, and what should w and d stand for? They cannot be counts of decimal digits, so should they be counts of binary, octal or hexadecimal digits? What about the sign, since there is no sign bit for integers?
Why not just write:
if (iStnPress /= 99999) StnPress = 0.1*iStnPress
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or as I said, I'm trying to do the impossible. In the past, I've had great success with internal reads like this:
read(StringFull(1:12),'(a12)') String1
which is a partial indexed read of StringFull. What I was trying to above was an impossible extension of that, perhaps trying to be too creative.
Your
if (iStnPress /= 99999) StnPress = 0.1*iStnPress
sounds fine. Thanks mecej4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm on my Linux system at the moment, and the runtime of IFort 15.0.2 says
forrtl: No such file or directory forrtl: severe (29): file not found, unit 9245, file /home/users/XYZ/fort.9245
which is explicit as to the attempted read on a unit numbered 9245. Did you not see a similarly clear message on Windows?
Is is only after these messages that the program aborts with a stack trace.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, mecej4 - I did see something like that. That is what I meant when I wrote "with the hint that it's taking '9245' to be a unit number."
Thanks again for your help & tutelage on this. I'm on my way ...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page