Peaceful
Peaceful

Reputation: 5450

Writing output files in different directory when many output files are being created

I am using fortran 95. I have a question very similar to Accessing files in sub directory of main program

The additional problem that I am having is this: I am creating files in a loop using following commands:

write(fn,fmt='(a,i0,a)')"degseqA",filenumber,'.dat'
open(unit=filenumber,file=fn)

Hence I cannot use 'output/myfile.dat' to make myfile.dat go to the directory output. Is there any way to solve this?

Thanks

Upvotes: 1

Views: 1001

Answers (1)

If the directory already exists, it is totally straightforward.

write(fn,fmt='(a,i0,a)') "output/degseqA",filenumber,'.dat'

open(unit=filenumber,file=fn)

or in general

write(fn,fmt='(a,i0,a)') trim(directory_name)//"degseqA",filenumber,'.dat'

where directory_name is a character variable with the name of the directory.

Make sure fn is large enough.

Upvotes: 5

Related Questions