Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Format descriptors

nige
Beginner
748 Views
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
0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
748 Views
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 the Ix 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:
4
12 66 38 52 3.14159

READ(11,"(i1)") nInt
READ(11,"(i3, f10.0)") (iX(i), i=1,nInt), Pi
In such cases, you can use either non-advancing I/O:

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
0 Kudos
Steven_L_Intel1
Employee
748 Views
Of course, you don't have to change it if you're using the Intel compiler.
0 Kudos
nige
Beginner
748 Views
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
0 Kudos
Steven_L_Intel1
Employee
748 Views
We do have a free 30-day evaluation version of the Intel compiler.
0 Kudos
Reply