Skip to the navigation links
Last modified: December 2009

URL: http://cxc-newtest.cfa.harvard.edu/ciao4.2/paramio_pget.html
AHELP for CIAO 4.2

pget

Context: paramio

Synopsis

Get a parameter value within S-Lang.

Syntax

String_Type pget( paramfile, param )

Description

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.

The paramio module is not available by default; to use it in a S-Lang program, it must be loaded using the S-Lang require() function:

  require("paramio");

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.

Error handling

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.

Example 1

slsh> punlearn("dmcopy");
slsh> ifile = pget("dmcopy","infile");
slsh> clval = pget("dmcopy","clobber");
slsh> ifile;

slsh> if ( ifile == "" ) print("infile is empty");;
"infile is empty"
slsh> clval;
no

Here we use pget() to find the current settings of the "infile" and "clobber" parameters of the "dmcopy" parameter file.

Example 2

slsh> punlearn("dmcopy");
slsh> fp = paramopen("dmcopy");
slsh> ifile = pget(fp,"infile");
Input dataset/block specification (): in.fits
slsh> clval = pget(fp,"clobber");
slsh> paramclose(fp);
slsh> ifile;
in.fits
slsh> 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.

Example 3

slsh> punlearn("dmcopy");
slsh> fp = paramopen("dmcopy","rH");
slsh> ifile = pget(fp,"infile");
slsh> paramclose(fp);
slsh> 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.

Bugs

See the bugs page for the paramio module on the CIAO website for an up-to-date listing of known bugs.

See Also

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

Last modified: December 2009