Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: December 2013

URL: http://cxc.harvard.edu/ciao/ahelp/paramio_pquery.html
Jump to: Description · Examples · See Also


AHELP for CIAO 4.9

pquery

Context: paramio

Synopsis

Query a parameter value.

Syntax

pquery(paramfile, param)

Description

This function is essentially the same as the command-line version (see "ahelp tools pquery"), although only one parameter - the param value above - can be queried at a time. The parameter value is always returned as a string by this function.

paramfile is a string

If called with the name of the parameter file then the function will, if it is not a hidden parameter, prompt the user and then return the selected value.

paramfile is a Param_File object

The behavior is the same if the paramopen() call was made without supplying the optional third argument. If the third argument was given then, before querying the user, the routine searches for the parameter value among these values. If the parameter is found in this list then the user will not be queried for the value.

The paramio module is not available by default; see "ahelp paramio" for information on loading the module.

Example 1

>>> from paramio import *
>>> punlearn("dmcopy")
>>> pset("dmcopy", "infile", "in.fits")
>>> ifile = pquery("dmcopy", "infile")
>>> print(ifile)
in.fits
>>> clval = pquery("dmcopy", "clobber")
>>> print(clval)
no

The pset() call sets the value for the infile parameter of dmcopy to "in.fits". We then call pquery() to find its value and - since it is not a hidden parameter - we are prompted for a value. In this example we accept the default value, and so the contents of ifile are "in.fits".

The query of the "clobber" parameter does not result in an interactive query since it is a hidden parameter.

Example 2

>>> punlearn("dmcopy")
>>> fp = paramopen("dmcopy", "rw")
>>> pset(fp, "infile", "in.fits")
>>> ifile = pquery( fp, "infile")
Input dataset/block specification (in.fits): test.fits
>>> print(ifile)
test.fits
>>> print(pget(fp, "infile"))
test.fits
>>> paramclose(fp)
>>> print(pget("dmcopy", "infile"))
test.fits

In this example, since we explicitly open the parameter file as read-write, the pquery() call results in the parameter file being changed.

Example 3

>>> args = ["dmcopy", "test.fits", "out=out.fits", "cl+"]
>>> fp = paramopen("dmcopy", "rw", args)
>>> ifile = pquery(fp, "infile")
>>> print(ifile)
test.fits
>>> ofile = pquery(fp, "outfile")
>>> print(ofile)
out.fits
>>> clval = pquery(fp, "clobber")
>>> print(clval)
yes
>>> paramclose(fp)
>>> print(pget("dmcopy", "outfile"))
out.fits
>>> print(pget( "dmcopy", "clobber"))
no

Here we use the three-argument form of paramopen() to set parameter values as if the command had been run from the command-line. Since the parameter values for "infile" and "outfile" are contained in the parameter list (the args array here), the pquery() calls do not need to ask the user what the value is. And, as the parameter file was opened with a mode of "rw", these new parameter settings are written to the parameter file if the parameter mode is not "hidden".

See Also

paramio
paccess, paramclose, paramio, paramopen, pget, pgets, plist, pset, punlearn

Last modified: December 2013
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email:   cxchelp@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2017. All rights reserved.