I have two suggestions.
1. Use a character string for the format and write n to is
character *19 afmt='(1x,bbbb(f10.8,1x))'
write(afmt(5:8), fmt='(i4)') n
write(fmt=afmt) vector
2. Write each index without an end of line character
do i = 1,n
write(fmt='(f10.8)', advance='no') vector(i)
end do
It depends on you situation as to which you use.
> -----Original Message-----
> From: David Byrne [SMTP:[log in to unmask]]
> Sent: Wednesday, March 26, 2003 09:54
> To: [log in to unmask]
> Subject: flexible format statements
>
> 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))
>
> 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.
This email message and any attachment(s) are for the sole use of the intended recipient(s)
and may contain proprietary and/or confidential information which may be privileged or
otherwise protected from disclosure.
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient(s), please contact the sender by reply email and destroy the original
message and any copies of the message as well as any attachment(s) to the original
message.
|