readenv(3f) - [M_io:QUERY] a function returning the value of an environment variable (LICENSE:PD)
Syntax
Description
Options
Returns
Example
See Also
Author
License
function readenv(NAME,DEFAULT,IERR=IERR) result(VALUE)
character(len=*),intent(in) :: NAME character(len=*),intent(in),optional :: DEFAULT integer,intent(out),optional :: IERR character(len=:),allocatable :: VALUEor
character(len=*),intent(in) :: NAME real,intent(in),optional :: DEFAULT integer,intent(out),optional :: IERR real :: VALUE
or
character(len=*),intent(in) :: NAME integer,intent(in),optional :: DEFAULT integer,intent(out),optional :: IERR integer :: VALUE
or
character(len=*),intent(in) :: NAME doubleprecision,intent(in),optional :: DEFAULT integer,intent(out),optional :: IERR doubleprecision :: VALUE or
character(len=*),intent(in) :: NAME logical,intent(in),optional :: DEFAULT integer,intent(out),optional :: IERR logical :: VALUE
Get the value of an environment variable or optionally return a default value if the returned value would be a blank string.The type returned is the same as the type of the default
NAME name of environment variable DEFAULT value to return if environment variable is not set or set to an empty string. May be CHARACTER, REAL, INTEGER, or DOUBLEPRECISION. Defaults to a null CHARACTER value.
VALUE the value of the environment variable or the default. The type is the same as DEFAULT. If an error occurs and it is numeric, huge(0|0.0|0.0d0) is returned. For a LOGICAL type, Any environment variable value starting with F,f,N or n is .FALSE. and any value starting with Y,y,T or t is true. A leading period (".") is ignored. Anything else returns .false. .
IERR return error code. Must be specified with a keyword. It is zero if no error occurred.
Sample program:
program demo_readenv use M_io, only : readenv, getname character(len=*),parameter :: g=(*(g0)) integer :: ierrif(readenv(STOP).eq.RUN)then write(*,g)repeat(-,80) write(*,g)readenv(CHARACTER,string) write(*,g)readenv(INTEGER,100) write(*,g)readenv(REAL,200.0) write(*,g)readenv(DOUBLE,300.0d0) write(*,g)readenv(LOGICAL,.true.)
write(*,g)repeat(-,80) write(*,g)readenv(CHARACTER,string,ierr=ierr) write(*,*)ierr=,ierr write(*,g)readenv(INTEGER,100,ierr=ierr) write(*,*)ierr=,ierr write(*,g)readenv(REAL,200.0,ierr=ierr) write(*,*)ierr=,ierr write(*,g)readenv(DOUBLE,300.0d0,ierr=ierr) write(*,*)ierr=,ierr write(*,g)readenv(LOGICAL,.true.) write(*,*)ierr=,ierr
write(*,g)repeat(-,80) write(*,g)readenv(CHARACTER) write(*,g)readenv(HOME) else write(*,g)repeat(-,80) call execute_command_line(env STOP=RUN //getname()) call execute_command_line(env STOP=RUN CHARACTER=aaaa & & INTEGER=1 REAL=2.3 DOUBLE=444444444444 //getname()) call execute_command_line(env STOP=RUN CHARACTER=bbbb & & INTEGER=1 REAL=2.3 DOUBLE=44.555 //getname()) call execute_command_line(env STOP=RUN CHARACTER=cccc & & INTEGER=asdf REAL=asdf DOUBLE=adsf //getname()) write(*,g)repeat(-,80) stop endif
end program demo_readenv
get_environment_variable(3fortran), system_getenv(3m_system), set_environment_variable(3m_system), system_putenv(3m_system), system_clearenv(3m_system), system_initenv(3m_system), system_getenv(3m_system), system_unsetenv(3m_system)
John S. Urban
Public Domain
Nemo Release 3.1 | readenv (3) | February 23, 2025 |