Try this
program test
implicit none
integer,parameter :: n=6
CHARACTER (LEN=6) :: internal_file
CHARACTER (LEN=20) :: my_format
REAL :: v(n)
v=1.0
WRITE (internal_file, FMT='(i3)') n
my_format = "("//TRIM(internal_file)//'f10.3'//")"
write(unit=*,fmt=my_format) v
READ (*, *)
STOP
END program test
Dennis
Dr Dennis Dunn
JJ Thomson Physical Laboratory
University of Reading
Whiteknights, Reading
Berks. UK
RG6 6AF
Telephone: +44 (0) 118 931 8538
Fax: +44 (0) 118 975 0203
----- Original Message -----
From: "David Byrne" <[log in to unmask]>
To: <[log in to unmask]>
Sent: Wednesday, March 26, 2003 3:54 PM
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.
>
|