kxk7607
kxk7607

Reputation: 207

Accessing files in sub directory of main program

The folder containing my main executable is very cluttered with input, output and source files. I would like to move some of these files into a different directory to my executable but still be able to access them. It would be fantastic if I could make a directory, for example ./main/outfile, that holds all the output files from my program. Is it possible to include a path when accessing these files in Fortran 77/90?

If compilers are of any importance, I use gfortran which is running on Ubuntu 11.10.

Upvotes: 3

Views: 9093

Answers (2)

bananafish
bananafish

Reputation: 2917

for input/output files, just specify the path when you are opening the file. For example:

open(unit=3,file='outputdata/data_modified.txt',status='unknown')

will open a file in the outputdata folder. Note that the outputdata folder has to exist beforehand, or you will likely get an error.

Upvotes: 7

janneb
janneb

Reputation: 37258

The starting directory at runtime is not the directory where your main program happens to reside, but rather the current directory when starting the program.

For instance

mkdir run_N && cd run_N && ../my_program

Will read and write files in the current directory (./run_N) even though the application binary is in another directory.

Upvotes: 2

Related Questions