Re: dynamic filename string
- From: fj <francois.jacq@xxxxxxx>
- Date: Wed, 28 Nov 2007 01:06:37 -0800 (PST)
On 28 nov, 09:56, fj <francois.j...@xxxxxxx> wrote:
On 27 nov, 22:51, gary.l.sc...@xxxxxxxx wrote:
On Nov 27, 3:34 pm, apek <apek1...@xxxxxxxxx> wrote:
Í need to store data in seperate files dependeng on some integer
count, e.g.,
Do i = 1, N
...
filename = ?
...
Open(unit=1, file=filename,action="write",status="replace")
...
Close(1)
End do
How can I update the filename, such that it become a dynamic string
depent on the index i as follows
i=1 -> filename="data1.txt"
i=2 -> filename="data2.txt"
...
Allan
program fn
character(80) :: filename = ' '
integer :: i = 0
do i = 1,10
write(filename,'(a,i0,a)')'data',i,'.txt'
write(*,*)'fn=',trim(filename)
end do
end
If your compiler doesn't support "i0" format, you could write the
integer separately to a character variable and use adjust, trim, and
concatenation operators.
Another useful format is "(a,i5.5,a)" (of course you can replace the
digit 5 by a more suitable value). The file names will have the
following form : data00001.txt ... data00999.txt ...
The advantage is the fact that the file names respect the alphabetic
order. This is often useful. For instance, if each file represent a
photo, then you can make a simple movie just using a command like :
convert data* movie.gifr
With the format (a,i0,a) on the contrary, the file data5.txt, for
instance, is "after" the file data10.txt even it is produced before
and the command convert will generate a strange movie.
Oups ! Jan was faster than me is publishing this solution when I was
writing my message ! Sorry for this double answer.
.
- References:
- dynamic filename string
- From: apek
- Re: dynamic filename string
- From: gary . l . scott
- Re: dynamic filename string
- From: fj
- dynamic filename string
- Prev by Date: Re: dynamic filename string
- Next by Date: Re: Read DOS or Unix files with the same fortran code
- Previous by thread: Re: dynamic filename string
- Index(es):