Re: Generating filenames
- From: Paul Van Delst <Paul.vanDelst@xxxxxxxx>
- Date: Fri, 27 Jan 2006 21:54:42 -0500
Joli.LeChat@xxxxxxxxx wrote:
Hi.
I wrote a program that does a simulation in function of a parameter. This parameter is variable inside a DO loop. I'd like to ask you if there's a way to generate a filename for each step of the loop, so I can store the results. Something like result1.dat, result2.dat, etc.
For filenames like result001.dat, result002.dat, ..., result010.dat, ... result100.dat, etc you can do:
character(256) :: filename integer :: i
do i = 1, 20
write(filename,'("result",i3.3,".dat")' ) i
....
end doFor filenames like result1.dat, result2.dat, ..., result10.dat, ... result100.dat, i.e. no leading zeroes, you can do
character(256) :: filename character(10) :: result_number integer :: i
do i = 1, 100
write(result_number,'(i10)') i
filename = 'result' // TRIM(ADJUSTL(result_number)) // '.dat'
....
end doI'm not sure if the ADJUSTL is required in the second example, but the first example is clearer (IMO). The first example also makes the files easier to sort in *nix too.
cheers,
paulv
-- Paul van Delst CIMSS @ NOAA/NCEP/EMC .
- References:
- Generating filenames
- From: Joli . LeChat
- Generating filenames
- Prev by Date: Re: Are generic linked lists possible in Fortran95?
- Next by Date: Re: Generating filenames
- Previous by thread: Re: Generating filenames
- Index(es):
Relevant Pages
|
|