OPEN statement in Fortran (g77)

Toon Moene toon@moene.indiv.nluug.nl
Sat Sep 13 15:32:00 GMT 2003


Prof. M.B. Patil wrote:

> 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.

Yep, same reason.  $HOME is expanded by the shell (it's an environment 
variable of the shell, after all).

The following should work (this all non-standard Fortran, but supported 
by many compilers):

       CHARACTER*128 HOME
       CALL GETENV('HOME', HOME) ! Gets value of the HOME env. var.
       OPEN(UNIT=1,FILE=HOME(1:LEN_TRIM(HOME))//'/xyz/try2.in',
      ,     STATUS='OLD')

Hope this helps,

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://gcc-g95.sourceforge.net/ (under construction)



More information about the Gcc-bugs mailing list