Re: dynamic filename string



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.

.



Relevant Pages

  • Re: Where does fmtutil get its inputs?
    ... Here I first look into fmtutil.cnf to see that the 'latex' format ... uses the pdfetex engine. ... the command - thanks. ... been able to work out what texconfig does exactly, ...
    (comp.text.tex)
  • when section heading at top of page, top margin wrong!
    ... For a thesis, my university requires a top margin of 1" throughout, ... % and format the table of contents. ... \doublespacing % command from setspace package to invoke double ... reduce vertical space by 7pt. ...
    (comp.text.tex)
  • Re: dynamic filename string
    ... integer separately to a character variable and use adjust, trim, and ... Another useful format is "" (of course you can replace the ... and the command convert will generate a strange movie. ...
    (comp.lang.fortran)
  • Re: Debug.exe for win32
    ... Format is: n) e address t=n ... Display the debug registers. ... R DRx command. ... The help output can be limited by specifying the first letterof the ...
    (alt.lang.asm)
  • Re: MacBook Pro with a new weird AWFUL bug
    ... is an ATSUI crash. ... command-z after every alignement command. ... You should then be able to format within whole ... publisher of the font and the date and version number of the font file). ...
    (microsoft.public.mac.office.word)