Home > Archive > Fortran > January 2006 > Generating filenames
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Generating filenames
|
|
| Joli.LeChat@gmail.com 2006-01-27, 9:57 pm |
| 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.
Thank you very much.
| |
| James Van Buskirk 2006-01-27, 9:57 pm |
| <Joli.LeChat@gmail.com> wrote in message
news:1138414918.698445.266290@g47g2000cwa.googlegroups.com...
> 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.
program untested
implicit none
integer i
character(80) filename
do i = 1, 10
write(filename,'(a,i0,a)') 'result',i,'.dat'
open(10,file=filename)
write(10,'(a,i0)') 'For this file, i =',i
close(10)
end do
end program untested
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
| |
| Paul Van Delst 2006-01-27, 9:57 pm |
| Joli.LeChat@gmail.com 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 do
For 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 do
I'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
| |
| Paul Van Delst 2006-01-27, 9:57 pm |
| James Van Buskirk wrote:
> <Joli.LeChat@gmail.com> wrote in message
> news:1138414918.698445.266290@g47g2000cwa.googlegroups.com...
>
>
>
>
> program untested
> implicit none
> integer i
> character(80) filename
>
> do i = 1, 10
> write(filename,'(a,i0,a)') 'result',i,'.dat'
> open(10,file=filename)
> write(10,'(a,i0)') 'For this file, i =',i
> close(10)
> end do
> end program untested
oo oo .... I forgot about i0! Darn it! :o)
cheers,
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|
|
|