Reading Fortran Data

Carl Banks pavlovevidence at
Mon Jan 22 03:42:32 CET 2007

Beliavsky wrote:
> Carl Banks wrote:
> <snip>
> > >   WRITE(90,*) nfault,npoint
> >
> > Fortran writes this as two arbitrary integers separated by a space.
> I wrote a paragraph in my reply explaining why this is wrong.

It's a safe assumption for a line of two integers.  It might not
exactly produce what a Fortran program would, but it would work in a
read statement.

> A Fortran
> list-directed write can print results in an almost arbitrary format,
> depending on the compiler. Many compilers will separate integers by
> several spaces, not just one, and they could use commas instead of
> spaces if they wanted.

1. Hardly any compiler will produce a line of two integers, or reals,
that another compiler couldn't read back.
2. The number of spaces separating the numbers isn't important when
reading back free-form data.
3. Fear that a Fortran compiler might use commas or wrap lines at ten
columns or whatever, because it's not based on a standard, is misguided

> The number of items printed before a new line is
> started is also compiler-dependent. For more control, one uses a
> formatted write, for example
> write (90,"(2(1x,i0))") nfault,npoint

I think it's just more work to guard against something isn't very
relevant in practice.

Carl Banks

More information about the Python-list mailing list