David Byrne wrote:
>
> Any thoughts on the following formatting
> issue would be much appreciated:
>
> I have a program where several vectors are
> of length determined by a parameter
>
> integer,parameter :: n=10
> real,dimension(n) :: vector
>
> and I write these to files at several places.
> I'd like to have a format statement that
> adjusts to the parameter, like
>
> write(unit=*,fmt=1)
> 1 format(1x,n(f10.8,1x))
The "n" doesn't have to match the list if there is nothing to
follow it.
You can use a format like
1 format(1x,99(f10.8,1x))
if you'd like. It'll write as many elements as there are. If there are
more than 99 it will start a new line. You could use 999999999999
instead on 99, but the problem with big numbers is that most processors
have line length limits and will abort if you try to write too much
on one line.
You can also simplify the format to
1 format(99f11.8)
if the number will fit into an 10.8 field, then an 11.8 will give
an extra space at the start of each value.
Dick Hendrickson
>
> but this doesn't work.
> In other words, I don't want to have to go through
> the code and change 10's to 20's when n changes to 20.
>
> Thanks a lot.
|