OPEN statement in Fortran (g77)

Prof. M.B. Patil mbpatil@ee.iitb.ac.in
Sat Sep 13 09:15:00 GMT 2003


> > A question about OPEN statement in Fortran:
> >
> > The following does not seem to work:
> >       open (unit=1,file='~/xyz/try2.in',status='old')
> >
> > The error message I get is the following:
> >
> > open: No such file or directory
> > apparent state: unit 1 named ~xyz/try2.in
> > lately writing direct unformatted external IO
> > Aborted
>
> This is unfortunate, but inevitable.  The home directory character ~ is
> specific to certain shells, i.e., they only work if you type something like:
>
> ls -l ~/xyz/try2.in
>
> in your shell, which interprets it as `ls -l $HOME/xyz/try2.in'.
>
> The above program just opens the file with name '~/xyz/try2.in' - it
> doesn't do any such "translation", because the Fortran standard mandates
> it to use the name literally.
>

Thanks a lot. Is there any other way to access the home directory? (The
program may be residing one/two/three/.. levels below the home directory,
otherwise I could have used ../ or ../../ etc. These seem to work fine)

I tried using $HOME instead of tilde, but that gave the same error.

Regards,
Mahesh Patil




More information about the Gcc-bugs mailing list