One recipe for testing for a spectrum is to look at the axis labels. (whereas a modern approach might use WCS information). Here is a longer example showing how this might be implemented. Suppose the name of the dataset being probed is stored in variable ndf.
# Get the full attributes.
ndftrace $ndf fullaxis accept > /dev/null
# Assign the axis labels and number of dimensions to variables.
set axlabel = `parget atype ndftrace`
set nodims = `parget ndim`
# Exit the script when there are too many dimensions to handle.
if ( $nodims > 2 ) then
echo Cannot process a $nodims-dimensional dataset.
goto exit
endif
# Loop for each dimension or until a spectral axis is detected.
set i = 1
set spectrum = FALSE
while ( $i <= nodims && $spectrum == FALSE )
# For simplicity the definition of a spectral axis is that
# the axis label is one of a list of acceptable values. This
# test could be made more sophisticated. The toupper converts the
# label to uppercase to simplify the comparison. Note the \ line
# continuation.
set uaxlabel = `echo $axlabel[$i] | awk '{print toupper($0)}'`
if ( $uaxlabel == "WAVELENGTH" || $uaxlabel == "FREQUENCY" \
$uaxlabel == "VELOCITY" ) then
# Record that the axis is found and which dimension it is.
set spectrum = TRUE
set spaxis = $i
endif
@ i++
end
# Process the spectrum.
if ( $spectrum == TRUE ) then
# Rotate the dataset to make the spectral axis along the first
# dimension.
if ( $spaxis == 2 ) then
irot90 $file $file"_rot" accept
# Fit the continuum.
sfit spectrum=$file"_rot" order=2 output=$file"_fit" accept
else
sfit spectrum=$file order=2 output=$file"_fit accept
end if
endif
C-shell Cookbook