Skip to content

Commit

Permalink
smurf: Ensure pol2cat runs even if no GLOBAL.sdf file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
David Berry committed Nov 28, 2012
1 parent 3610c94 commit 2e4af16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
9 changes: 7 additions & 2 deletions applications/smurf/scripts/pol2cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
* Original version
* 16-NOV-2012 (DSB):
* Use a temporary ADAM directory for each invocation.
* 27-NOV-2012 (DSB):
* Ensure the script runs even if no ~/adam/GLOBAL.sdf file exists.
*-
'''
Expand All @@ -202,6 +204,7 @@
import starutil
from starutil import invoke
from starutil import NDG
from starutil import Parameter
from starutil import ParSys
from starutil import msg_out

Expand All @@ -219,7 +222,8 @@
params = []

params.append(starutil.ParNDG("IN", "The input POL2 time series NDFs",
starutil.get_task_par("DATA_ARRAY","GLOBAL")))
starutil.get_task_par("DATA_ARRAY","GLOBAL",
default=Parameter.UNSET)))

params.append(starutil.Par0S("CAT", "The output FITS vector catalogue",
"out.FIT"))
Expand Down Expand Up @@ -253,7 +257,8 @@
noprompt=True))

params.append(starutil.Par0S("DEVICE", "Device for graphical output",
starutil.get_task_par("GRAPHICS_DEVICE","GLOBAL"),
starutil.get_task_par("GRAPHICS_DEVICE",
"GLOBAL",default=None),
noprompt=True))

params.append(starutil.Par0L("RETAIN", "Retain temporary files?", False,
Expand Down
26 changes: 21 additions & 5 deletions applications/smurf/scripts/starutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ def invoke(command,aslist=False,buffer=None):
return outtxt


def get_task_par( parname, taskname ):
def get_task_par( parname, taskname, **kwargs ):
"""
Get the current value of an ATASK parameter.
Invocation:
value = get_task_par( parname, taskname )
value = get_task_par( parname, taskname, default=??? )
Arguments:
parname = string
Expand All @@ -310,15 +310,31 @@ def get_task_par( parname, taskname ):
parentheses to the end of the parameter name.
taskname = string
The name of the task.
default = string
A default value to return if the specified parameter cannot be
accessed (e.g. if the parameter file does not exist, or does not
contain the required parameter). If "default" is not supplied,
an exception will be raised if the parameter cannot be accessed.
Returned Value:
The parameter value. This will be a single value if the task parameter
is a scalar value, and a list if the task parameter is a vector.
"""

text = invoke("$KAPPA_DIR/parget {0} {1} vector=yes".format( shell_quote(parname),taskname), False )
return eval( text.replace('\n', '' ) )
cmd = "$KAPPA_DIR/parget {0} {1} vector=yes".format( shell_quote(parname),taskname)

if 'default' in kwargs:
try:
text = invoke( cmd, False )
result = eval( text.replace('\n', '' ) )
except AtaskError:
result = kwargs['default']
else:
text = invoke( cmd, False )
result = eval( text.replace('\n', '' ) )

return result


def shell_quote(text):
Expand Down Expand Up @@ -873,7 +889,7 @@ def _getParameterValue(self):
value = default
defaultUsed = True
else:
raise NoValueError("\n{0}No value obtained for parameter '{1}'.".format(_cmd_token(),name))
raise NoValueError("\n{0}No value obtained for parameter '{1}'.".format(_cmd_token(),self.__name))

elif value == "!!" :
raise AbortError("\n{0}Aborted prompt for parameter '{1}'.".format(_cmd_token(),name))
Expand Down

0 comments on commit 2e4af16

Please sign in to comment.