Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 Discussions

Visual Fortran WRITE statement writes to more than one line

deedub
Beginner
993 Views

I'm running into a problem with Digital Visual Fortran. It seems that it will only write 6 records per line, e.g. the code

Write(10,*) 1, 2, 3, 4, 5, 6 ,7, 8, 9

Produces the output

1 2 3 4 5 6

7 8 9

How do you make it write it all on the same line, producing a file with n lines and 9 columns, where n is the number of write statements?

David

0 Kudos
6 Replies
TimP
Honored Contributor III
993 Views
Specify a format. Be as old-fashioned as you like. e.g.
write(10,'(9i3)')...
0 Kudos
Steven_L_Intel1
Employee
993 Views
You are using list-directed formatting, which gives the "processor" (compiler/run-time system) great lattitude in how it formats the lines and when it starts new lines. As Tim suggests, if you want a specific layout, use explicit formatting.

You can also open the output file with RECL= and specify a value that will be used (I think) as the line width. But this is not portable and I do not recommend it.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
993 Views
Um, not portable? AFAIK that's perfectly standard Fortran. What is not portable is the default field length of list-directed output, but if one specifies "sufficiently long" RECL it shouldn't matter.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
993 Views
What I meant was that the effect of using RECL= on list-directed output is non-standard and therefore non-portable.
0 Kudos
emc-nyc
Beginner
993 Views
Won't specifying a RECL also blank-pad the lines?

Incidentally, I can find (in the Rules for List-Directed Sequential WRITE Statements section of the lang_for.pdf document) that list-directed output will wrap. This is fine. Including when it will wrap for files opened without a RECL specifier would be nice.
0 Kudos
Steven_L_Intel1
Employee
993 Views
No, it won't blank-pad. For the purpose of list-directed output, RECL= specifies the "margin" at which a new record will be started. You can find the default RECL values in the Building Applications manual.
0 Kudos
Reply