Fortran Open from current directory
I am writing a fortran program and I would like to know if it is possible
to open a file from the same directory where the program itself is placed.
I am using Ubuntu 12.04 BTW.
For example, if I put the compiled program at the directory
"/home/username/foo" I would like the program to open the file
"/home/username/foo/bar.txt" and write "Hello!" in it.
My minimal working example is the following:
program main
implicit none
open(unit=20,file="bar.txt",action="write")
WRITE(20,*) "Hello!"
close(20)
end program main
When I compile using gfortran it opens and writes in the file
"/home/username/bar.txt" no matter where I put the program file.
On the other hand, when I compile it for windows (using mingw) making a
.exe file and execute it in windows it does what I want, it opens the file
where the executable file is placed.
Can anyone help me with that?
Thanks in advance.
No comments:
Post a Comment