- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all I am using the following code to create a new file PROGRAM TEST_IO INTEGER*4 UNIT,IOS OPEN (UNIT=119, FILE = '$HOME/compile.log', IOSTAT = IOS, - STATUS = 'NEW', RECL = 132, FORM = 'FORMATTED', - RECORDTYPE = 'VARIABLE', ORGANIZATION = 'SEQUENTIAL', - CARRIAGECONTROL = 'FORTRAN') PRINT *,IOS END PROGRAM Here HOME(/home/my_name) is an environment variable.When I execute this code I am always getting the IOS as 46.Without using a function to get the value of the environment variable, Can I solve this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should not expect Fortran (or C, etc.) to do symbol substitutions or globbing in the same manner that we expect the Linux shell to do. You can call a library function to obtain the values of environment variables. See https://software.intel.com/en-us/node/526226; you can do
USE IFPORT character(len=50) :: buf ... call getenv('HOME',buf) OPEN (UNIT=119, FILE = trim(buf)//'/compile.log', IOSTAT = IOS, - STATUS = 'NEW', RECL = 132, FORM = 'FORMATTED', - RECORDTYPE = 'VARIABLE', ORGANIZATION = 'SEQUENTIAL', - CARRIAGECONTROL = 'FORTRAN') ...
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should not expect Fortran (or C, etc.) to do symbol substitutions or globbing in the same manner that we expect the Linux shell to do. You can call a library function to obtain the values of environment variables. See https://software.intel.com/en-us/node/526226; you can do
USE IFPORT character(len=50) :: buf ... call getenv('HOME',buf) OPEN (UNIT=119, FILE = trim(buf)//'/compile.log', IOSTAT = IOS, - STATUS = 'NEW', RECL = 132, FORM = 'FORMATTED', - RECORDTYPE = 'VARIABLE', ORGANIZATION = 'SEQUENTIAL', - CARRIAGECONTROL = 'FORTRAN') ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:
You should not expect Fortran (or C, etc.) to do symbol substitutions or globbing in the same manner that we expect the Linux shell to do. You can call a library function to obtain the values of environment variables. See https://software.intel.com/en-us/node/526226; you can do
USE IFPORT character(len=50) :: buf ... call getenv('HOME',buf) OPEN (UNIT=119, FILE = trim(buf)//'/compile.log', IOSTAT = IOS, - STATUS = 'NEW', RECL = 132, FORM = 'FORMATTED', - RECORDTYPE = 'VARIABLE', ORGANIZATION = 'SEQUENTIAL', - CARRIAGECONTROL = 'FORTRAN') ...
Standard Fortran subroutine (i.e., intrinsic procedure) GET_ENVIRONMENT_VARIABLE would now be preferable over an Intel extension of getenv:
See https://software.intel.com/en-us/node/580640.
With GET_ENVIRONMENT_VARIABLE, one does not need to include "USE IFPORT" statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One caveat on the suggestion is if the environment variable 'HOME' is not specified, then the filename '/compile.log' places the log file in the root directory. It might be better to test buf for all blanks and/or with trailing '/'.
BUF = ADJUSTL(BUF)
IF(BUF.EQ.' ') THEN
BUF = './'
ELSE
IF(BUF(LEN_TRIM(BUF):LEN_TRIM(BUF)) .NE. '/') BUF = TRIM(BUF)//'/'
ENDIF
Consider adjusting the above to handle '\' as separator.
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page