For I/O of 2-dimensional arrays, don't forget the VERY OLD trick of
executing a SEPARATE READ or WRITE for each row. This makes the printed
output start each row on a new line. The advantage is that the FORMAT
does not have to know how many elements are in each row. [Of course this
separate I/O statement is in a DO loop that gets executed once for each
row.]
The READ or WRITE statement uses an array section (or if more
complicated, an array constructor or an implied DO) to transfer all of
the elements of a row. This is done the same as for a 1-dimensional
array, described below. If there are too many elements to fit on a line,
you can use a FORMAT statement with rescan to get special effects such
as "hanging indent". The first line can include extra stuff like the row
number, and the rescan can start later in the format.
All of this is described in any good Fortran 77 or Fortran 90/95
textbook. (I could recommend some good books, but modesty forbids.)
= = =
Loren P Meissner
[log in to unmask]
> -----Original Message-----
> From: [log in to unmask]
> [mailto:[log in to unmask]]On Behalf Of Richard
> Maine
> Sent: Saturday, March 06, 1999 11:22 PM
> To: comp-fortran-90
> Subject: Re:
>
>
> Jaehoon Seol writes:
> > > ! write ( unit=10,fmt=* ) myarray.
> <=========== 1
> > > write (unit=10, fmt="(f10.0,2f20.5,e15.3)")
> myarray <===== 2
> >
> > If the size of myarray is 10, statement (1) will print all
> the entries in
> > a single line.
>
> Not true. The compiler is allowed a lot of freedom in line splitting
> with list-directed output. Some compilers might write it all on one
> line, but this certainly isn't required.
>
> > Byt (2) will print in 3 different lines. What I want to
> > know is if there is any SIMPLE way to print all the
> entries in a single
> > line in f10.2 format, for instance.
>
> Yes. The simplest is
>
> write (10, "(10f10.2)") myarray
>
> If you want it to work with larger arrays, then make the repeat count
> larger than any realistic array. Perhaps something like
>
> write (10, "(99f10.2)") myarray
>
> Presumably, you are unlikely to need to write more than 99 values on
> a single line. (That would make for a bit of a longish line).
> Some compilers may run into limits if you try to put unreasonably
> much on a single line, but 10 fields of 10 characters each doesn't
> sound like much of a problem.
>
> --
> Richard Maine
> [log in to unmask]
>
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|