Re: dynamic filename string



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.
.



Relevant Pages

  • Re: how to trim file path from filename
    ... But for the the file to be effective I need to trim the path from the ... filename and leave just the filename. ... The traditional directory separator is regular slash, ... UNIX may contain backslash as well. ...
    (comp.lang.javascript)
  • Re: What is error 0x8007007B "The filename, directory name, or volume label syntax is incorrect."
    ... filename. ... Please read this before replying: ... Trim & respond inline ...
    (microsoft.public.win32.programmer.directx.video)
  • Help trimming off filename from path
    ... I've got a form where i need to pull both the directory of a filename ... and the directory with the filename of an .inf file... ... I did this hoping to dynamically trim off any inf filename that is ...
    (microsoft.public.dotnet.languages.vb)
  • Re: GraphEdit Render Media File...
    ... It calls IFileSourceFilter::Load with the filename. ... Please read this before replying: ... Trim & respond in-line (please don't top post or snip everything) ...
    (microsoft.public.win32.programmer.directx.video)
  • Import multiple excel files
    ... I had to remove the ".xls" on the file names to use this. ... able to trim that off. ... Private Sub Command0_Click ... Dim filename As String ...
    (microsoft.public.access.externaldata)