Manual Reference Pages  - get_env (3m_unicode)

NAME

get_env(3f) - [M_unicode:SYSTEM] return value of environment variable (LICENSE:MIT)

CONTENTS

Synopsis
Characteristics
Description
Options
Returns
Examples
Author
License

SYNOPSIS

impure elemental function get_env(name,default) result(out)

     type(unicode_type),intent=(in) :: name
     type(unicode_type),optional    :: default
     type(unicode_type)             :: out

CHARACTERISTICS

NAME and DEFAULT may be default CHARACTER type as well.

DESCRIPTION

get_env(3) gets the value of the requested environment variable as TYPE(UNICODE_TYPE) .

OPTIONS

name name of environment variable to return the value of. Typically the name may only contain the characters A-Z,a-z,0-9 and underscore; but allowed values are system-dependent.
default
  value to return if environment variable NAME is not set or set to a blank value

RETURNS

out value assigned based on value of environment variable NAME

EXAMPLES

Sample program:

    program demo_get_env
    use M_unicode, only : get_env, ut=> unicode_type
    use M_unicode, only : assignment(=), operator(//)
    implicit none
    type(ut) :: name
    type(ut) :: default
    type(ut) :: value
    type(ut) :: smiley
    integer  :: i
    character(len=*),parameter :: bracket= ’(1x,*("[",a,"]",:))’
       !
       smiley=128515 ! set with Unicode code point
       name=’UTF8’   ! set with ASCII
       default=’Have a nice day ’//smiley//’!’ ! set with unicode_type
       !
       ! arguments can be type(unicode_type) or character
       ! but type(unicode_type) is always returned
       value=get_env(name,             default             )
       value=get_env(name%character(), default%character() )
       value=get_env(name,             default%character() )
       value=get_env(name%character(), default             )
       !
       write(*,*)value%character()
       !
       ! print each glyph surrounded by brackets
       write(*,bracket)(value%character(i,i),i=1,value%len())
       !
    end program demo_get_env

Results:

    > Have a nice day 😃!
    > [H][a][v][e][ ][a][ ][n][i][c][e][ ][d][a][y][ ][😃][!]

AUTHOR

John S. Urban

LICENSE

    MIT