Format in Fortran

Format in Fortran

Hi all,

I'm attempting to write a file data that it's a matrix (851*851), but when I try to write more than 80 col. in a line, the rest of the line is written on the next line. Is there a way to write in 1 line, and undetermined number of columns? I tried with:

  Write(99,10) zeonmatch(ii,:)
  10 FORMAT (A851)

but neither worked.

Thank you all,


4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I assume that your first try was with list-directed output (format *). With that, you are allowing the compiler to choose a line break wherever it wants. You can open the unit with a long value for RECL and list-directed formatting will use that. In a future version we'll enable some more control over this.

Your second try encountered an obscure language feature called "format reversion". When the closing parenthesis of a format is reached and there are still more items to process, a new record is started and the format "reverts" to the left parenthesis matching the last right parenthesis seen. I don't think you really meant A851 here, as that is a single character item that is 851 characters long. Anyway, here is what you want to use:

10 FORMAT (*(G0,1X))

The * is a Fortran 2008 feature called "unlimited format repeat count" which repeats the following format group as many times as is needed to satisfy the I/O list. G0 is a general purpose format that will accept any datatype. You can substitute any format edit descriptor you want there, such as E, I or A. If you like G but want to specify a number of digits to the right of the decimal point, use G0.4, for example.

Steve - Intel Developer Support

As it happens I wrote a blog post about format reversion - read it for all the gory details. Doctor Fortran in "Revert! Revert! The End (of the format) is Nigh!"

Steve - Intel Developer Support

Thank you Steve, the option:

10 FORMAT (*(G0,1X)),

formally solved the problem.


Leave a Comment

Please sign in to add a comment. Not a member? Join today