env.gex - GrADS Extensions for Environment Variable Manipulation |
env.gex - GrADS Extensions for Environment Variable Manipulation
env CMD - Expands environment variables in CMD and executes it
getenv NAME - Print value of NAME
setenv NAME VALUE - Set environment variable NAME to VALUE
printenv STRING - Expands all environment variables in <STRING>
getenv(NAME) - Return value of environment variable NAME
setenv(NAME,VALUE) - Set environment variable NAME to VALUE
printenv(STRING) - Return string with expansion of all environment variables in <STRING>
This library implements GrADS extensions (gex) with commands for setting and retriving environment variables. In addition it can exapand all environment variables in a GrADS command string and then execute the command after the expansion takes places. These features are available at the GrADS prompt or as GrADS Scription Language functions.
Environment variables can be used in GrADS in a variety of ways. Prior
to starting GrADS you can set up environment variables with the
locations of your data directories and use this environment variable
when opening your files, for example. Another useful application is
for holding truly global information which persists throughout the
extent of your GrADS session. You can use this technique for
communicating between GrADS scripts that are invoked from different
run
commands.
ga-> getenv USER HOME TMPDIR Environment variable USER = dasilva Environment variable HOME = /Users/dasilva Environment variable TMPDIR = <undef>
Notice that environment variable TMPDIR
was not defined in this case.
ga-> setenv OPENGRADS /share/dasilva/opengrads Environment variable OPENGRADS = /share/dasilva/opengrads
ga-> printenv $HOME/src/grads/test_data /Users/dasilva/src/grads/test_data
Notice that undefined variables exapand to a blank string:
ga-> printenv Undefined variable FOO = <$FOO> Undefined variable FOO = <>
ga-> printenv /tmp/tempfile.$$ /tmp/tempfile.21386
ga-> env open $OPENGRADS/test_data/model.ctl
Notice that you can use @ as a short hand for env:
ga-> @ open $OPENGRADS/test_data/model.ctl
Using the @ short-hand for env:
ga-> @ setenv FILE $HOME/data/model.ctl setenv FILE /Users/dasilva/data/model.ctl Environment variable FILE = /Users/dasilva/data/model.ctl
ga-> @ open $FILE open /Users/dasilva/data/model.ctl Scanning description file: /Users/dasilva/data/model.ctl Data file /Users/dasilva/data/model.grb is open as file 1 LON set to 0 360 LAT set to -90 90 LEV set to 1000 1000 Time values set: 1987:1:1:0 1987:1:1:0
You can use env variables to save long expressions:
ga-> setenv EXPR ua;va;sqrt(ua*ua+va*va) Environment variable EXPR = ua;va;sqrt(ua*ua+va*va)
ga-> @ display $EXPR display ua;va;sqrt(ua*ua+va*va)
The following commands are loosely based on the C-Shell syntax:
This command expands environment variables in string CMD and executes it as a GrADS command after expansion. Example:
ga-> env open $HOME/data/model.ctl open /Users/dasilva/data/model.ctl Scanning description file: /Users/dasilva/data/model.ctl Data file /Users/dasilva/data/model.grb is open as file 1 LON set to 0 360 LAT set to -90 90 LEV set to 1000 1000 Time values set: 1987:1:1:0 1987:1:1:0
This command takes a list of environment variables and prints the value of each one. Example:
ga-> getenv USER HOME DISPLAY Environment variable USER = dasilva Environment variable HOME = /Users/dasilva Environment variable DISPLAY = :0.0
This command sets environment variable NAME to VALUE. Example:
ga-> setenv DATADIR /archive/data Environment variable DATADIR = /archive/data
This command expands all environment variables in STRING, printing the result to the screeen. Example:
ga-> printenv My home directory is $HOME My home directory is /Users/dasilva
Same as printenv.
Same as env.
http://opengrads.org/ - OpenGrADS Home Page
http://opengrads.org/wiki/index.php - OpenGrADS User Defined Extensions
http://www.iges.org/grads/ - Official GrADS Home Page
Arlindo da Silva (dasilva@opengrads.org)
Copyright (C) 2007-2008 Arlindo da Silva; All Rights Reserved.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
env.gex - GrADS Extensions for Environment Variable Manipulation |