Pan-Tasks regularly runs:

	p2tool -pendingimfile

This returns a list of pending imfiles that are ready to be processed
at the phase 2 level, i.e., they are science exposures that have
passed through phase 1 (or phase 0 if phase 1 doesn't exist).  Each
imfile is characterised by: exp_id, class_id, version, uri.

*** To do: function to get output file name(s) from input parameters.

For each imfile, we run:

	phase2run.pl -exp_id $expId -class_id $classId -version $version -uri $uri -out $out

phase2run.pl is a helper script that runs ppImage:

	ppImage -file $uri $out -recipe PPIMAGE PPIMAGE_PHASE2

and then updates the database with the processed imfile:

    XXX is -version nessicary or can it be automated?
	p2tool -addprocessedimfile -exp_id $expId -class_id $classId -version
$version -uri $out -recip $recipe -bg $background -bg_stdev $background_stdev
-bg_mean_stdev $mean_background -b1_uri $bin1_uri -b2_uri $bin2_uri

*** To do: do we need "-b1" and "-b2" flags to add the binned images?

"p2search -update" ticks off the appropriate imfile in phase 2.


We also desire to (manually) re-run a phase2 for a particular
exposure, excluding certain chips (which may be bad, etc):

	p2search -rerunexp -exp_id $expId -exclude ccd01 -exclude ccd13

This option will (1) put new copy of that exposure into p2pending
table (w/o the specified "-exclude" components), (2) increment the
version number for each, (3) decrement the number of components by the
number of "-exclude" components.

Downstream, there will be no processing using mixed versions within an
exposure; e.g., we don't allow building a phase 4 using version 1 of
ccd01 and version 2 of ccd13.
