Q:

Directory navigation in OPEN clause

How can I read from a parent directory using the OPEN clause? Let's say
OPEN (11,file='../inf/input.dat',form='formatted',status='old') 

, which doesn't work. I get:
forrtl: severe (29): file not found, unit 11, file /home/cg/compile/comp/../inf/input.dat

I would like to read from the parent directory just before inf. Is that possible?

A:

Unfortunately there is no unique way to do this, since paths are OS dependent. In order to this in a robust way you might need to define a function that look for the OS while preprocessing (cf. compilation flags e.g. here).
For *nix systems (Unix, including OSX, and Linux) the option you provided should suffice
../

in the path goes to the previous directory.
However in windows there is no way that I know to go in the above directory (I don't have a Windows system with me at the moment).
However you can workaround this limitation with the GetModuleFileName API function. (note that this will not work in the systems above)
CHARACTER*(*) pathname          ! full name  
INTEGER       L                 ! length  
L= GetModuleFileName(NULL,pathname,LEN(pathname))

Fullname will now contain the full path where you run your program, so you can do all sort of string operation you want.
If you want to go above one level 
Idx = index(trim(pathname), '/', .True.)

Finds the index of the last '/' character in the pathname (you might need to look for the one before the last).
outfile_path=pathname(:idx)+'/inf/input.dat'

will be now the path you want.

