ARG (l) | ARG (l) |
Arg is a program to facilitate writing long scripts, where the same command or set of commands need to be repeated for a large number of input values (e.g., a list of file names, image names, numeric constants, etc..). Using arg, one only needs to write a template for the script, in which the variable input is represented by a unique marker character (e.g., '&', '$', '%', '@') or character sequence (e.g., '$1', '$2', '%1', '%2', 'INFIL', 'OUFIL', 'X_IN', 'Y_IN') that is not used in the template script to denote anything other than such variable input.
For each line in inputs , arg will substitute the marker string(s) in template by the current replacement string from inputs in either one of three ways, selected by run-mode switch -m<#> , for integer <#>, as follows:
Output is to the standard output (i.e., the screen) but may be redirected to any other device. For -m0 only, commented lines in the template (lines starting with a "#") may be skipped and omitted from the output using the -c run-mode switch. Use of this switch is currently not supported for the other modes.
If arg is invoked without any arguments or with invalid arguments, a short version of this man-page is printed.
1. We constructed a super dark image and associated sigma image by combining the dark frames from several observing runs with the same CCD camera. For the individual runs we then construct master dark images by replacing pixels in a copy of that super dark that differ more than 3σ from the mean in a contemporaneous dark by values taken from that contemporaneous dark in order to account for systematic changes over time. The mean of the super dark frame is 0.183; the ampersands ('&') in "script.tem" will be replaced by the observing run identifier ('Nov01', 'Feb02', etc..) and the percentage signs ('%') in "expr.tem" will be replaced with a mean value of the dark frame of a run that will be determined on-the-fly. We will further assume that our programming environment will be NOAO's Image Reduction and Analysis Facility (IRAF).
Create a file "expr.tem" (command string/expression for task 'imcalc' in the 'stsdas' package) with the following contents:
cl> type expr.tem if ( abs( im1 - 0.183 - (im3 - % ) ) > 3*abs(im2) ) then im3 else ( im1 - 0.183 + % )
Create the template script "script.tem" with the following contents:
cl> type script.tem imstat ("&/DARK.fits[256:768,256:768]", fields="mean", lower=INDEF, upper=INDEF, nclip=3, lsigma=3., usigma=3., format-, > "tmp.stat") print ("!arg tmp.stat expr.tem '%' > imcalc.expr") | cl imcalc ("SUPERDARK,e_SUPERDARK,&/DARK", "&/MASTERDARK", "@imcalc.expr") delete ("tmp.stat,imcalc.expr", yes, verify-)
Create an input list of the observing run identifier strings with the following contents:
cl> type runs.lis Nov01 Feb02 Apr02 Jun02 Oct02
Replicate the template script while substituting each occurance of marker character '&' with the current replacement string read from "runs.lis", then execute that script (after verifying it makes sense):
cl> !arg runs.lis script.tem '&' > script.cl cl> type script.cl cl> cl < script.cl
2. Assume we retrieved a large (N≫1) number of image files from a telescope data archive and want to rename and move them:
$> cd /scratch/ $> \ls -1 0*.fits > /data/im.lis $> cd /data/
We will use fitsheader, and awk and cut to retrieve the original object names (and to demonstrate the usage of arg), but any other means (e.g., from within IRAF or IDL, or listhead included in W.D. Pence's 'cfitsio' library) can be used as well; we'll also assume our shell is 'csh' or 'tcsh':
$> echo "fitsheader /scratch/& -k object | awk '{print $3}' | \ >>> cut -c2- >> name.lis" > getname.tem $> arg -m0 im.lis getname.tem > getname $> source getname $> echo "\mv /scratch/$ /data/%" > rename.tem $> arg -m0 im.lis rename.tem '$' > rename.1 $> arg -m1 name.lis rename.1 '%' > rename $> source rename
So with few commands and without any editing one can complete tedious tasks like these quickly. Of course, this was a simple example (which might have been achieved even quicker using just some Unix magic), but for more complicated, multi-line scripts that would expand to thousands of lines of code, arg will be very efficient.
narg
R.A. Jansen <Rolf.Jansen@asu.edu>
©1998–2013 R.A. Jansen/DinoSoft; The name 'arg' and one of the run-modes are based in part on earlier code by M. Franx.
Rev. 2.3 | 23 May 2013 | ARG (l) |