Get a parameter value within S-Lang.
String_Type pget( paramfile, param )
This function is essentially the same as the command-line
version (see "ahelp tools pget"), although only one
parameter - the param value above - can be accessed at a time.
To use pget() the paramio module must have been loaded.
The parameter value is always returned as a string by this
function; the paramio library does contain functions - such
as pgetb() and pgetf() - which will automatically convert
the value into the requested datatype, or you can use the S-Lang intrinsic
functions to do this.
The pquery() function may also be of interest.
As with all the paramio routines, the PF_Errno variable
is set to 0 on success, or on error it is set to
one of the error codes listed in the paramio documentation.
chips> punlearn("dmcopy")
chips> ifile = pget("dmcopy","infile")
chips> clval = pget("dmcopy","clobber")
chips> ifile
chips> if ( ifile == "" ) print("infile is empty")
infile is empty
chips> clval
no
Here we use pget() to find the current settings of the
"infile" and "clobber" parameters of the "dmcopy"
parameter file.
chips> punlearn("dmcopy")
chips> fp = paramopen("dmcopy")
chips> ifile = pget(fp,"infile")
Input dataset/block specification (): in.fits
chips> clval = pget(fp,"clobber")
chips> paramclose(fp)
chips> ifile
in.fits
chips> clval
no
This example is similar to the first except that
we use the return value of paramopen() to access
the parameter file. If you make many paramio
calls on a single parameter file then it is more
efficient to use paramopen() than just using the
name of the parameter file.
Since we did not supply a mode parameter for the paramopen()
call, it defaults to "r" and so the paramater was prompted for
when pget() was called.
chips> punlearn("dmcopy")
chips> fp = paramopen("dmcopy","rH")
chips> ifile = pget(fp,"infile")
chips> paramclose(fp)
chips> if ( ifile == "" ) print("infile is empty")
infile is empty
By opening the parameter file with the mode set to "rH"
we avoid the interactive prompt when pget() is called.
- concept
-
parameter
- modules
-
paramio
- paramio
-
paccess,
paramclose,
paramopen,
pgets,
plist_names,
pquery,
pset,
punlearn
- tools
-
dmhistory,
dmkeypar,
dmmakepar,
dmreadpar,
paccess,
pdump,
pget,
pline,
plist,
pquery,
pset,
punlearn
|