Last modified: December 2013

URL: https://cxc.cfa.harvard.edu/ciao/ahelp/paramopen.html
Jump to: Description · Examples · See Also


AHELP for CIAO 4.16

paramopen

Context: paramio

Synopsis

Open a parameter file.

Syntax

fp = paramopen(parname)
fp = paramopen(parname, mode)
fp = paramopen(parname, mode, arglist)
fp = paramopen(None, mode, arglist)

Description

Open a parameter file, returning an object which can be used with the other paramio functions. If you are going to be accessing the same parameter file multiple times then it is more efficient to use the value returned by paramopen() in the function calls rather than to repeatedly use the name of the tool.

The mode defaults to "r" and should be one of the "IRAF-compatible" paramater-interface access modes (eg "r", "rw", "rH", etc).

If the arglist is supplied then it should be an array of strings containing parameter settings that over-ride those given in the parameter file. The first element of the array should contain the name of the tool (i.e. the name used to access the parameter file).

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


Examples

Example 1

from paramio import *
fp = paramopen("dmextract")
opt = pget(fp, "opt")
print("The opt parameter is set to {0}".format(opt))
paramclose(fp)

Open the parameter file for the dmextract tool. As no mode is given it defaults to "r" - ie read-only. The variable returned by paramopen() is then used in a call to pget() to find out the value of the "opt" parameter, before the parameter file is closed via the call to paramclose().

Example 2

from paramio import *
args = ["dmcopy", "test.fits", "out=out.fits", "cl+"]
fp = paramopen("dmcopy", "rw", args)
ifile = pquery(fp, "infile")
print("The infile is {0}".format(ifile))
paramclose(fp)

In this example, open the parameter file for dmcopy. This time it is given the "rw" mode, and an argument list containing parameter settings that over-ride those given in the parameter file. Then print out the name of the infile which is 'test.fits' the new value for the parameter. Notice the first argument in the args list is the name of the tool, "dmcopy".

See Also

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