- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am moving code from VAX VMS to the PC, most of this code is old F77 from the 70's and 80's.
The code has many variable length format statements;
as format(I)
and format(F10.6) where N4 is a variable (int).
What can I replace these with to make the code more portable?
Thanks
Nigel
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In most cases, 1000i4 will do (or whatever number is large enough). The Fortran rule is that "unused" format descriptors will be discarded after I/O operation is completed, and this won't affect the efficiency whatsoever.
The problem may occur if theIx is immediately followed by another descriptor on the same line. E.g. if you should read/write a number of integers followed by something else, like:
(I'm not sure if extra parens around i3 are required, but they won't harm. When the format descriptor is exhausted, the next item is read by "reversing" the format to the previous paren).
Finally, in such cases you can construct an appropriate format string on the fly (but you can't use FORMAT statement, but an "inline" FORM=). This is somewhat clumsy and should be used when the goal cannot be achieved by other means:
The problem may occur if the
4In such cases, you can use either non-advancing I/O:
12 66 38 52 3.14159
READ(11,"(i1)") nInt
READ(11,"(i3, f10.0)") (iX(i), i=1,nInt), Pi
READ(11,"((i3))", ADVANCE="no") (iX(i), i=1,nInt)
READ(11,"(F10.0)") Pi
(I'm not sure if extra parens around i3 are required, but they won't harm. When the format descriptor is exhausted, the next item is read by "reversing" the format to the previous paren).
Finally, in such cases you can construct an appropriate format string on the fly (but you can't use FORMAT statement, but an "inline" FORM=). This is somewhat clumsy and should be used when the goal cannot be achieved by other means:
CHARACTER(10) sFormat
...
READ(11,"(i1)") nInt
WRITE(sFormat, "(a,i0,a)") "(", nInt, "i3, f10.0)"
READ(11, sFormat) (iX(i), i=1,nInt), Pi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Of course, you don't have to change it if you're using the Intel compiler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the replies
Steve
We are due to get the intel compiler at work soon (takes about 2 months to buy anything!), I was just having a 'quick look ' at some of the code at home using the free G95 compiler.
Thanks
Nigel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We do have a free 30-day evaluation version of the Intel compiler.

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