Can I Use Fortran to Open Multiple Files Using a List of File Names?

  • Topic: Fortran 
  • Thread starter Thread starter ivans1984
  • Start date Start date
  • Tags Tags
    files Fortran
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 3K views
ivans1984
Messages
2
Reaction score
0
Hello oeveryone

i've got many txt files each with a different name, such as

filename1.txt
filename2.txt
...


i've got another txt in which I've got the list of the name
of the files

i want to allocate in a vector of characters che name of the files
and use this to open all files with a do cycle, like

do i=1,n

open (10+i, file='file(i)',status='old')

end do


but doing so the code doesn't work, the file is not found
(even though i successfully allocated filenames into the vector file(i))

can you tell me where is the mistake?

thanks
 
Physics news on Phys.org
ivans1984 said:
open (10+i, file='file(i)',status='old')

This tries to open a file named, literally, 'file(i)' (including the parentheses and the letter 'i'). Try instead:

Code:
open (10+i, file=file(i),status='old')

without the quotes, which uses the character string that is stored in file(i).

(I assume you have declared 'file' as something like

Code:
character*10 file(20)

which is an array of 20 character strings, each with length 10.)