Accessing files in sub directory of main program

夙愿已清 提交于 2019-12-10 18:32:44

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9573475/accessing-files-in-sub-directory-of-main-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!