Index: /branches/eam_branches/ipp-20120905/Ohana/src/addstar/src/psps_ids.c
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/addstar/src/psps_ids.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/addstar/src/psps_ids.c	(revision 34735)
@@ -21,5 +21,5 @@
 CreatePSPSStackDetectionID(int sourceID, int imageID, int detID)
 {
-  // sourceID : ID of database + table that tracked the image (< 0x100 = 256)
+  // sourceID : ID of database + table that tracked the image (< 0x7f = 127)
   // imageID : external ID of the image which provided the detections (< 0x1000.0000 ~ 2.7e8)
   // detID : detection sequence in image (< 0x1000.0000 ~ 2.7e8)
@@ -27,5 +27,5 @@
   assert (detID    < 0x10000000);
   assert (imageID  < 0x10000000);
-  assert (sourceID < 0x100);
+  assert (sourceID < 0x7f);
   
   uint64_t detectid = ((uint64_t)sourceID << 56) + ((uint64_t)imageID << 28) + (uint64_t)detID;
Index: /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/Ohana/src/libdvo/include/dvo.h	(revision 34735)
@@ -193,4 +193,5 @@
   ID_PHOTOM_PASS_3    = 0x00000800, // average magnitude calculated in 3th pass
   ID_PHOTOM_PASS_4    = 0x00001000, // average magnitude calculated in 4th pass
+  ID_PSPS_OBJ_EXT     = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
   ID_SECF_OBJ_EXT     = 0x01000000, // extended in this band
 } DVOSecfiltFlags;
Index: /branches/eam_branches/ipp-20120905/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- /branches/eam_branches/ipp-20120905/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 34735)
@@ -304,4 +304,6 @@
         $skycell_id = $component;
         $command = "$stacktool -sumskyfile -dbname $imagedb";
+        # only consider stacks in full state.
+        $command .= " -state full";
         $id_opt = "-stack_id";
         $component_args = " -skycell_id $skycell_id" if $skycell_id and $skycell_id ne  'all';
@@ -894,7 +896,7 @@
         } else {
             # skip these obsolete tesselations unless they were explicitly asked for
-            # should I do this?
             next if $tess_id eq "FIXNS";
             next if $tess_id eq "ALLSKY";
+            next if $tess_id eq "RINGS.V0";
         }
         next if $requested_skycell and ($skycell_id ne $requested_skycell);
@@ -1287,4 +1289,5 @@
 
     my $id_name = $stage . "_id";
+    $id_name = 'exp_id' if $stage eq 'raw';
 
     # input list is "order by exp_id, run_id DESC"   run_id is one of (chip_id, warp_id, diff_id)
@@ -1307,4 +1310,5 @@
         my $magicked = $input->{magicked};  # this will be either stageRun.magicked or stage%file.magicked
         my $state = $input->{state};
+        $state = $input->{data_state} if !defined $state;
 
         # can't process run in these states
Index: /branches/eam_branches/ipp-20120905/ippMonitor/INSTALL
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/INSTALL	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/INSTALL	(revision 34735)
@@ -24,2 +24,5 @@
 # Note: we use a 'science databases (replication) slave' and the ippMonitor read-only account to connect to that database
 psconfigure --dbhost scidbs1 --dbuser ippMonitor --dbpass ippMonitor --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
+
+psconfigure --dbhost scidbm --dbuser ipp --dbpass ipp --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
+
Index: /branches/eam_branches/ipp-20120905/ippMonitor/Makefile.in
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/Makefile.in	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/Makefile.in	(revision 34735)
@@ -240,5 +240,7 @@
 $(DESTWWW)/lapRuns.php \
 $(DESTWWW)/lapExposures.php \
-$(DESTWWW)/lapStacks.php
+$(DESTWWW)/lapStacks.php \
+$(DESTWWW)/failedStaticsky.php \
+$(DESTWWW)/staticsky_failure.php
 
 PICTURES = \
Index: /branches/eam_branches/ipp-20120905/ippMonitor/def/failedStaticsky.d
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/def/failedStaticsky.d	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/def/failedStaticsky.d	(revision 34735)
@@ -0,0 +1,27 @@
+TABLE staticskyRun JOIN staticskyResult USING(sky_id) JOIN staticskyInput USING(sky_id) JOIN stackRun USING(stack_id)
+TITLE Static Sky Failed
+FILE  failedStaticsky.php
+MENU  ipp.stack.dat
+
+WHERE staticskyResult.fault != 0
+
+ARGS  ARG1   staticskyRun.sky_id=$staticskyRun.sky_id
+ARGS  ARG1   basename=$staticskyResult.path_base
+
+#        field                          size  format  name           show     link to         extras
+FIELD staticskyRun.sky_id,          5, %d,     Sky ID
+FIELD staticskyRun.label,    	    7, %s,     Label
+FIELD staticskyRun.state,    	    7, %s,     State,		value,		staticsky_failure.php, ARG1
+FIELD stackRun.skycell_id,          5, %s,     Skycell ID
+FIELD stackRun.tess_id,             5, %s,     Tess ID
+FIELD count(stackRun.filter),       5, %d,     #Filters	
+FIELD stackRun.label AS stackRunLabel,   5, %s,     Stack Label
+FIELD staticskyRun.data_group, 	    7, %s,     data grp
+FIELD staticskyRun.dist_group, 	    7, %s,     dist grp
+FIELD staticskyResult.sources,      7, %d,     n(sources)
+FIELD staticskyResult.fault,        7, %d,     fault
+FIELD staticskyResult.quality,      7, %d,     quality
+FIELD staticskyResult.path_base,    5, %s,     path_base,     none
+
+MODE summary
+GROUP staticskyRun.sky_id
Index: /branches/eam_branches/ipp-20120905/ippMonitor/def/staticsky_failure.d
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/def/staticsky_failure.d	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/def/staticsky_failure.d	(revision 34735)
@@ -0,0 +1,27 @@
+TABLE staticskyRun JOIN staticskyResult USING(sky_id) JOIN staticskyInput USING(sky_id) JOIN stackRun USING(stack_id)
+TITLE Static Sky Failed (Log)
+FILE  failedStaticsky.php
+MENU  ipp.stack.dat
+
+WHERE staticskyResult.fault != 0
+
+ARGS  ARG1   staticskyResult.path_base=$staticskyResult.path_base
+
+#        field                          size  format  name           show     link to         extras
+FIELD staticskyRun.sky_id,          5, %d,     Sky ID
+FIELD staticskyRun.label,    	    7, %s,     Label
+FIELD staticskyRun.state,    	    7, %s,     State,		value,		staticsky_failure.php, ARG1
+FIELD stackRun.skycell_id,          5, %s,     Skycell ID
+FIELD stackRun.tess_id,             5, %s,     Tess ID
+FIELD count(stackRun.filter),       5, %d,     #Filters	
+FIELD stackRun.label,               5, %s,     Stack Label
+FIELD staticskyRun.data_group, 	    7, %s,     data grp
+FIELD staticskyRun.dist_group, 	    7, %s,     dist grp
+FIELD staticskyResult.sources,      7, %d,     n(sources)
+FIELD staticskyResult.fault,        7, %d,     fault
+FIELD staticskyResult.quality,      7, %d,     quality
+FIELD staticskyResult.path_base,    5, %s,     path_base,     none
+
+GROUP staticskyRun.sky_id
+
+TAIL PHP insert_log ('LOG.EXP');
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php	(revision 34735)
@@ -465,5 +465,5 @@
         createFormattedTableCell($anyFaults, $link, $str, $anyFaults, 0);
 
-        $link = $defaultlink;
+        $link = "failedStaticsky.php?pass=" . $pass . "&proj=" . $proj . "&staticskyRun.label=" . $thisLabel . "&staticskyRun.state=".$searchState;
         getStateAndFaults($db, $thisLabel, $selectedState, "staticsky", $str, $anyFaults);
         createFormattedTableCell($anyFaults, $link, $str, $anyFaults, 0);
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.php
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.php	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.php	(revision 34735)
@@ -799,9 +799,15 @@
   // echo "<b>class_id: $class_id</b><br>\n";
   // echo "<b>camera:   $camera</b><br>\n";
+  // echo "<b>filerule:   $filerule</b><br>\n";
 
   if (! $class_id) { $class_id = "NONE"; }
 
+  //SCH: I set a default value for the 'camera' which is based on the
+  //'proj' parameter.
+  //It's necessary for staticsky logs and it would require to join tables
+  //back to the warpRun table
+  if (! $camera) { $camera = strtoupper($_GET['proj']); }
+
   if ($basename && $camera && $filerule) {
-
     // do I need to do this to the output result as well?
     $basename = escapeshellarg($basename);
@@ -841,4 +847,5 @@
       return;
     }
+    echo "<b>log filename: $filename</b><br>\n";
 
     echo "<pre>\n";
@@ -850,4 +857,5 @@
   }
 }
+
 
 // expect image supplied with key=name
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.stack.dat
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.stack.dat	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.stack.dat	(revision 34735)
@@ -36,2 +36,3 @@
 menulink  | menuselect   | link    | Static Sky Processed Skyfile | staticskyProcessedSkyfile.php
 menulink  | menuselect   | link    | Static Sky Failed Skyfile    | staticskyFailedSkyfile.php
+menulink  | menuselect   | link    | Static Sky Failed            | failedStaticsky.php
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in	(revision 34735)
@@ -47,8 +47,13 @@
 $REPL_DBNAME_ISP = "ippc17 (isp)";
 
-$REPL_HOST_NEBULOUS_SECONDARY = "ippc63.IfA.Hawaii.Edu";
+$REPL_HOST_NEBULOUS_SECONDARY = "ippdb04.IfA.Hawaii.Edu";
 $REPL_USER_NEBULOUS_SECONDARY = "ippMonitor";
 $REPL_PASSWORD_NEBULOUS_SECONDARY = "ippMonitor";
-$REPL_DBNAME_NEBULOUS_SECONDARY = "ippc63 (secondary nebulous / 50,000 sec behind is acceptable)";
+$REPL_DBNAME_NEBULOUS_SECONDARY = "ippdb04 (secondary nebulous / 50,000 sec behind is acceptable / usually stopped on Mondays and Tuesdays)";
+
+$REPL_HOST_NEBULOUS_TERNARY = "ippc63.IfA.Hawaii.Edu";
+$REPL_USER_NEBULOUS_TERNARY = "ippMonitor";
+$REPL_PASSWORD_NEBULOUS_TERNARY = "ippMonitor";
+$REPL_DBNAME_NEBULOUS_TERNARY = "ippc63 (secondary nebulous / 50,000 sec behind is acceptable / usually stopped on Mondays and Tuesdays)";
 
 
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl	(revision 34735)
@@ -88,5 +88,5 @@
 my $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id) or my_die( "Unable to get log filename", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR );
 
-$ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
+$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
 
 # Recipes to use based on reduction class
@@ -158,11 +158,18 @@
 &my_die("Can't find input astrometry: $astrometry", $warp_bg_id, $skycell_id, $PS_EXIT_PROG_ERROR) unless $ipprc->file_exists($astrometry);
 
-my $out_image = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
-my $out_mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
-my $out_stats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
-my $out_config = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
-my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
-
-my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
+#my $out_image = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
+#my $out_mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
+#my $out_stats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
+#my $out_config = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
+#my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
+
+my $out_image = prepare_output("PSWARP.OUTPUT", $outroot, $skycell_id,  1);
+my $out_mask = prepare_output("PSWARP.OUTPUT.MASK", $outroot, $skycell_id, 1);
+my $out_stats = prepare_output("SKYCELL.STATS", $outroot, $skycell_id, 1);
+my $out_config = prepare_output("PSWARP.CONFIG", $outroot, $skycell_id, 1);
+my $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1);
+
+my $skyFile = prepare_output("SKYCELL.TEMPLATE", $outroot, $skycell_id, 1);
+
 $ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR);
 
@@ -239,4 +246,18 @@
 ### Pau.
 
+sub prepare_output
+{
+    my $filerule = shift;
+    my $outroot  = shift;
+    my $skycell_id = shift;
+    my $delete = shift;
+    $delete = 0 if !defined $delete;
+
+    my $error;
+    my $output = $ipprc->prepare_output($filerule, $outroot, $skycell_id, $delete, \$error)
+                    or &my_die("failed to prepare output file for: $filerule", $warp_bg_id, $skycell_id, $error);
+    return $output;
+}
+
 
 sub my_die
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl	(revision 34735)
@@ -440,6 +440,6 @@
     }
 
+    my $backup_url = shift;
     my $original_url = shift;
-    my $backup_url = shift;
 
     # rename the backup as the orig
@@ -449,5 +449,5 @@
     my $moved;
     eval {
-        $moved = nebulous->move($backup_url, $original_url);
+        $moved = $nebulous->move($backup_url, $original_url);
     };
     if ($@ or not $moved) {
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl	(revision 34735)
@@ -671,4 +671,21 @@
 # 	}
 	# Do quality checks here
+	if ($verbose) {
+	    printf("TEST: %d %d %d\n",$exposure->{exp_id},$exposure->{chip_id},$exposure->{chip_component_count});
+	}
+	# Checks to ensure we do not divide by zero.  Mostly happens with old diffs, it seems.
+	if ($exposure->{chip_component_count} == 0) {
+	    $exposure->{chip_component_count} = 1;
+	}
+	if ($exposure->{cam_component_count} == 0) {
+	    $exposure->{cam_component_count} = 1;
+	}
+	if ($exposure->{warp_component_count} == 0) {
+	    $exposure->{warp_component_count} = 1;
+	}
+	if ($exposure->{diff_component_count} == 0) {
+	    $exposure->{diff_component_count} = 1;
+	}
+
 	my $is_bad_quality = 0;
 	if ((defined($exposure->{chipRun_state}))&&($exposure->{chipRun_state} eq 'full')&&
Index: /branches/eam_branches/ipp-20120905/ippToPsps/config/OB/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/config/OB/tables.vot	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/config/OB/tables.vot	(revision 34735)
@@ -45,13 +45,4 @@
         <DESCRIPTION> Declination error</DESCRIPTION>
       </FIELD>
-      <FIELD name="cx" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>Cartesian x</DESCRIPTION>
-      </FIELD>
-      <FIELD name="cy" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>Cartesian y</DESCRIPTION>
-      </FIELD>
-      <FIELD name="cz" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>Cartesian z</DESCRIPTION>
-      </FIELD>
       <FIELD name="lambda" arraysize="1" datatype="double" unit="degree">
         <DESCRIPTION> ecliptic longitude</DESCRIPTION>
@@ -66,10 +57,4 @@
         <DESCRIPTION> galactic latitude</DESCRIPTION>
       </FIELD>
-      <FIELD name="lsg" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>supergalactic longitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="bsg" arraysize="1" datatype="double" unit="unknown">
-        <DESCRIPTION>supergalactic latitude</DESCRIPTION>
-      </FIELD>
       <FIELD name="nDetections" arraysize="1" datatype="short" unit="unknown">
         <DESCRIPTION>total number of detection measurements in all filters</DESCRIPTION>
@@ -201,8 +186,8 @@
         <DESCRIPTION> 80 pct w magnitude</DESCRIPTION>
       </FIELD>
-      <FIELD name="gStackPSFFlux" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="gStackPSFMag" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> g stack psf flux </DESCRIPTION>
       </FIELD>
-      <FIELD name="gStackPSFFluxErr" arraysize="1" datatype="double" unit="mag">
+      <FIELD name="gStackPSFMagErr" arraysize="1" datatype="double" unit="mag">
 	<DESCRIPTION> estimated error in g stack psf flux</DESCRIPTION>
       </FIELD>
@@ -216,8 +201,11 @@
         <DESCRIPTION>flags for g stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="rStackPSFFlux" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="gStackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="rStackPSFMag" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> r stack psf flux </DESCRIPTION>
       </FIELD>
-      <FIELD name="rStackPSFFluxErr" arraysize="1" datatype="double" unit="mag">
+      <FIELD name="rStackPSFMagErr" arraysize="1" datatype="double" unit="mag">
         <DESCRIPTION> estimated error in r stack psf flux</DESCRIPTION>
       </FIELD>
@@ -231,8 +219,11 @@
         <DESCRIPTION>flags for r stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="iStackPSFFlux" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="rStackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="iStackPSFMag" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> i stack psf flux </DESCRIPTION>
       </FIELD>
-      <FIELD name="iStackPSFFluxErr" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="iStackPSFMagErr" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> estimated error in i stack psf flux</DESCRIPTION>
       </FIELD>
@@ -246,8 +237,11 @@
         <DESCRIPTION>flags for i stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="zStackPSFFlux" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="iStackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zStackPSFMag" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> z stack psf flux </DESCRIPTION>
       </FIELD>
-      <FIELD name="zStackPSFFluxErr" arraysize="1" datatype="float" unit="mag">
+      <FIELD name="zStackPSFMagErr" arraysize="1" datatype="float" unit="mag">
         <DESCRIPTION> estimated error in z stack psf flux</DESCRIPTION>
       </FIELD>
@@ -261,8 +255,11 @@
         <DESCRIPTION>flags for z stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="yStackPSFFlux" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="zStackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="yStackPSFMag" arraysize="1" datatype="float" unit="unknown">
         <DESCRIPTION>y band stack PSF flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="yStackPSFFluxErr" arraysize="1" datatype="float" unit="unknown">
+      <FIELD name="yStackPSFMagErr" arraysize="1" datatype="float" unit="unknown">
         <DESCRIPTION>y band stack psf flux err</DESCRIPTION>
       </FIELD>
@@ -276,6 +273,9 @@
         <DESCRIPTION>flags for y stack</DESCRIPTION>
       </FIELD>
-      <FIELD name="extra" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>currently unused</DESCRIPTION>
+      <FIELD name="yStackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="qfPerfect" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>qf perfect</DESCRIPTION>
       </FIELD>
       <FIELD name="sgSep" arraysize="1" datatype="float" unit="unknown">
Index: /branches/eam_branches/ipp-20120905/ippToPsps/config/P2/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/config/P2/tables.vot	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/config/P2/tables.vot	(revision 34735)
@@ -404,8 +404,8 @@
         <DESCRIPTION> estimated error in y</DESCRIPTION>
       </FIELD>
-      <FIELD name="instFlux" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="psfFlux" arraysize="1" datatype="float" unit="adu/s">
         <DESCRIPTION> PSF instrumental flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="instFluxErr" arraysize="1" datatype="float" unit="adu/s">
+      <FIELD name="psfFluxErr" arraysize="1" datatype="float" unit="adu/s">
         <DESCRIPTION> estimated error in flux</DESCRIPTION>
       </FIELD>
@@ -425,6 +425,6 @@
         <DESCRIPTION>PSF likelihood</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfCf" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
+      <FIELD name="psfQf" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>PSF qf</DESCRIPTION>
       </FIELD>
       <FIELD name="momentXX" arraysize="1" datatype="float" unit="arcsec">
@@ -437,14 +437,14 @@
         <DESCRIPTION> momeny YY</DESCRIPTION>
       </FIELD>
-      <FIELD name="apMag" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION> Aperture magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apMagErr" arraysize="1" datatype="float" unit="magnitude">
-        <DESCRIPTION> Aperture magnitude error</DESCRIPTION>
-      </FIELD>
-      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="magnitude">
+      <FIELD name="apFlux" arraysize="1" datatype="float" unit="adu/s">
+        <DESCRIPTION> Aperture Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFluxErr" arraysize="1" datatype="float" unit="adu/s">
+        <DESCRIPTION> Aperture Flux error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="kronFlux" arraysize="1" datatype="float" unit="adu/s">
         <DESCRIPTION> Kron flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="magnitude">
+      <FIELD name="kronFluxErr" arraysize="1" datatype="float" unit="adu/s">
         <DESCRIPTION> Kron flux error</DESCRIPTION>
       </FIELD>
@@ -455,17 +455,17 @@
         <DESCRIPTION> Kron radius error</DESCRIPTION>
       </FIELD>
-      <FIELD name="crLikelihood" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>Likelihood the source is a cosmic ray</DESCRIPTION>
-      </FIELD>
-      <FIELD name="extendedLikelihood" arraysize="1" datatype="float" unit="unknown">
-        <DESCRIPTION>Likelihood the source is extended</DESCRIPTION>
+      <FIELD name="psfQfPerfect" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>psf QF Perfect</DESCRIPTION>
+      </FIELD>
+      <FIELD name="psfChiSq" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>PSF Chi sq</DESCRIPTION>
       </FIELD>
       <FIELD name="infoFlag" arraysize="1" datatype="long" unit="unknown">
         <DESCRIPTION>flag indicating provenance information</DESCRIPTION>
       </FIELD>
-      <FIELD name="sky" arraysize="1" datatype="float" unit="adu">
+      <FIELD name="sky" arraysize="1" datatype="float" unit="adu/s/pixel">
         <DESCRIPTION> PSF sky level at source</DESCRIPTION>
       </FIELD>
-      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu">
+      <FIELD name="skyErr" arraysize="1" datatype="float" unit="adu/s/pixel">
         <DESCRIPTION> estimated error in sky</DESCRIPTION>
       </FIELD>
@@ -539,4 +539,56 @@
       </DATA>
     </TABLE>
+    <TABLE name="DetectionCalib">
+      <DESCRIPTION>VOTable description of PSPS table DetectionCalib</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="detectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>IPP object number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>filter identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>survey identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpErr" arraysize="1" datatype="float" unit="magnitude">
+        <DESCRIPTION>zerop point offset error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="s">
+        <DESCRIPTION>exposure time</DESCRIPTION>
+      </FIELD>
+      <FIELD name="airMass" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>airmass</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
   </RESOURCE>
 </VOTABLE>
Index: /branches/eam_branches/ipp-20120905/ippToPsps/config/ST/tables.vot
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/config/ST/tables.vot	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/config/ST/tables.vot	(revision 34735)
@@ -148,7 +148,4 @@
         <DESCRIPTION>projection cell identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="obsTime" arraysize="1" datatype="double">
-        <DESCRIPTION> Time of mid observation (unit = day)</DESCRIPTION>
-      </FIELD>
       <FIELD name="xPos" arraysize="1" datatype="float">
         <DESCRIPTION>measured x on CCD from PSF fit</DESCRIPTION>
@@ -163,8 +160,8 @@
         <DESCRIPTION>estimated error in y</DESCRIPTION>
       </FIELD>
-      <FIELD name="instFlux" arraysize="1" datatype="float">
+      <FIELD name="psfFlux" arraysize="1" datatype="float">
         <DESCRIPTION>PSF instrumental flux</DESCRIPTION>
       </FIELD>
-      <FIELD name="instFluxErr" arraysize="1" datatype="float">
+      <FIELD name="psfFluxErr" arraysize="1" datatype="float">
         <DESCRIPTION>estimated error in instrumental flux</DESCRIPTION>
       </FIELD>
@@ -193,7 +190,10 @@
         <DESCRIPTION>PSF likelihood</DESCRIPTION>
       </FIELD>
-      <FIELD name="psfCf" arraysize="1" datatype="float">
-        <DESCRIPTION>PSF coverage factor</DESCRIPTION>
-      </FIELD>
+      <FIELD name="psfQf" arraysize="1" datatype="float">
+        <DESCRIPTION>PSF Q factor</DESCRIPTION>
+      </FIELD>
+       <FIELD name="psfQfPerfect" arraysize="1" datatype="float">
+        <DESCRIPTION>PSF QF Perfect</DESCRIPTION>
+      </FIELD> 
       <FIELD name="momentXX" arraysize="1" datatype="float">
         <DESCRIPTION> moment XX (unit = arcsec)</DESCRIPTION>
@@ -223,21 +223,21 @@
         <DESCRIPTION> moment RH (unit = arcsec)</DESCRIPTION>
       </FIELD>
-      <FIELD name="apMag" arraysize="1" datatype="float">
-        <DESCRIPTION> Aperture magnitude (unit = magnitude)</DESCRIPTION>
-      </FIELD>
-      <FIELD name="apMagErr" arraysize="1" datatype="float">
-        <DESCRIPTION> Aperture magnitude error (unit = magnitude)</DESCRIPTION>
+      <FIELD name="apFlux" arraysize="1" datatype="float">
+        <DESCRIPTION> Aperture flux (unit = adu/s)</DESCRIPTION>
+      </FIELD>
+      <FIELD name="apFluxErr" arraysize="1" datatype="float">
+        <DESCRIPTION> Aperture flux error (unit = adu/s)</DESCRIPTION>
       </FIELD>
       <FIELD name="kronFlux" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron flux (unit = magnitude)</DESCRIPTION>
+        <DESCRIPTION> Kron flux (unit = adu/s)</DESCRIPTION>
       </FIELD>
       <FIELD name="kronFluxErr" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron flux error (unit = magnitude)</DESCRIPTION>
+        <DESCRIPTION> Kron flux error (unit = adu/s)</DESCRIPTION>
       </FIELD>
       <FIELD name="kronRad" arraysize="1" datatype="float">
         <DESCRIPTION> Kron radius (unit = arcsecs)</DESCRIPTION>
       </FIELD>
-      <FIELD name="kronRadErr" arraysize="1" datatype="float">
-        <DESCRIPTION> Kron radius error (unit = arcsecs)</DESCRIPTION>
+      <FIELD name="psfChiSq" arraysize="1" datatype="float">
+        <DESCRIPTION> psf chi sq</DESCRIPTION>
       </FIELD>
       <FIELD name="infoFlag" arraysize="1" datatype="long">
@@ -293,9 +293,9 @@
         <DESCRIPTION>stack identifier</DESCRIPTION>
       </FIELD>
-      <FIELD name="isophotMag" arraysize="1" datatype="float">
-        <DESCRIPTION>isophotal magnitude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="isophotMagErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in isophotal magnitude</DESCRIPTION>
+      <FIELD name="isophotFlux" arraysize="1" datatype="float">
+        <DESCRIPTION>isophotal flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="isophotFluxErr" arraysize="1" datatype="float">
+        <DESCRIPTION>estimated error in isophotal flux</DESCRIPTION>
       </FIELD>
       <FIELD name="isophotMajAxis" arraysize="1" datatype="float">
@@ -332,9 +332,9 @@
         <DESCRIPTION>estimated error inPetrosian radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="petMag" arraysize="1" datatype="float">
-        <DESCRIPTION>Petrosian magntiude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="petMagErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in petMag</DESCRIPTION>
+      <FIELD name="petFlux" arraysize="1" datatype="float">
+        <DESCRIPTION>Petrosian Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="petFluxErr" arraysize="1" datatype="float">
+        <DESCRIPTION>estimated error in petFlux</DESCRIPTION>
       </FIELD>
       <FIELD name="petR50" arraysize="1" datatype="float">
@@ -765,8 +765,8 @@
         <DESCRIPTION>estimated error in deVaucouleurs radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVMag" arraysize="1" datatype="float">
+      <FIELD name="deVFlux" arraysize="1" datatype="float">
         <DESCRIPTION>deVaucouleurs magntiude</DESCRIPTION>
       </FIELD>
-      <FIELD name="deVMagErr" arraysize="1" datatype="float">
+      <FIELD name="deVFluxErr" arraysize="1" datatype="float">
         <DESCRIPTION>estimated error in deV_mag</DESCRIPTION>
       </FIELD>
@@ -891,9 +891,9 @@
         <DESCRIPTION>estimated error in Exponential fit radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="expMag" arraysize="1" datatype="float">
-        <DESCRIPTION>Exponential fit magntiude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="expMagErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in expMag</DESCRIPTION>
+      <FIELD name="expFlux" arraysize="1" datatype="float">
+        <DESCRIPTION>Exponential fit flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expFluxErr" arraysize="1" datatype="float">
+        <DESCRIPTION>estimated error in expFlux</DESCRIPTION>
       </FIELD>
       <FIELD name="expAb" arraysize="1" datatype="float">
@@ -1017,9 +1017,9 @@
         <DESCRIPTION>estimated error in Sersic radius</DESCRIPTION>
       </FIELD>
-      <FIELD name="serMag" arraysize="1" datatype="float">
-        <DESCRIPTION>Sersic magntiude</DESCRIPTION>
-      </FIELD>
-      <FIELD name="serMagErr" arraysize="1" datatype="float">
-        <DESCRIPTION>estimated error in serMag</DESCRIPTION>
+      <FIELD name="serFlux" arraysize="1" datatype="float">
+        <DESCRIPTION>Sersic Flux</DESCRIPTION>
+      </FIELD>
+      <FIELD name="serFluxErr" arraysize="1" datatype="float">
+        <DESCRIPTION>estimated error in serFlux</DESCRIPTION>
       </FIELD>
       <FIELD name="serAb" arraysize="1" datatype="float">
@@ -1240,4 +1240,56 @@
       </DATA>
     </TABLE>
+       <TABLE name="StackDetectionCalib">
+      <DESCRIPTION>VOTable description of PSPS table StackDetectionCalib</DESCRIPTION>
+      <PARAM arraysize="1" datatype="char" ucd="meta.bib.author" name="Author" value="PSPS"></PARAM>
+      <FIELD name="objID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM object identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="stackDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>ODM detection identifier index</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippObjID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>IPP object number</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ippDetectID" arraysize="1" datatype="long" unit="unknown">
+        <DESCRIPTION>detection ID generated by IPP</DESCRIPTION>
+      </FIELD>
+      <FIELD name="filterID" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>filter identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="surveyID" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>survey identifier</DESCRIPTION>
+      </FIELD>
+      <FIELD name="ra" arraysize="1" datatype="double" unit="degrees">
+        <DESCRIPTION>right ascension</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dec" arraysize="1" datatype="double" unit="degrees">
+        <DESCRIPTION>declination</DESCRIPTION>
+      </FIELD>
+      <FIELD name="raErr" arraysize="1" datatype="float" unit="arcsec">
+        <DESCRIPTION>right ascension error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="decErr" arraysize="1" datatype="float" unit="arcsec">
+        <DESCRIPTION>declination error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zp" arraysize="1" datatype="float" unit="magnitude">
+        <DESCRIPTION>zero point offset</DESCRIPTION>
+      </FIELD>
+      <FIELD name="zpErr" arraysize="1" datatype="float" unit="magnitude">
+        <DESCRIPTION>zerop point offset error</DESCRIPTION>
+      </FIELD>
+      <FIELD name="expTime" arraysize="1" datatype="float" unit="s">
+        <DESCRIPTION>exposure time</DESCRIPTION>
+      </FIELD>
+      <FIELD name="airMass" arraysize="1" datatype="float" unit="unknown">
+        <DESCRIPTION>airmass</DESCRIPTION>
+      </FIELD>
+      <FIELD name="dataRelease" arraysize="1" datatype="unsignedByte" unit="unknown">
+        <DESCRIPTION>Data release to propagate to the object</DESCRIPTION>
+      </FIELD>
+      <DATA>
+        <TABLEDATA></TABLEDATA>
+      </DATA>
+    </TABLE>
   </RESOURCE>
 </VOTABLE>
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/detectionbatch.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/detectionbatch.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/detectionbatch.py	(revision 34735)
@@ -388,8 +388,11 @@
         # delete all detections with PSF_INST_MAG < 17.5, as decreed by Gene
         BEFORE = self.scratchDb.getRowCount(ippTableName)
-        sql = "DELETE FROM " + ippTableName + " WHERE PSF_INST_MAG < -17.5"
-        self.scratchDb.execute(sql)
+        #don't do this anymore
+        #sql = "DELETE FROM " + ippTableName + " WHERE PSF_INST_MAG < -17.5"
+        #self.scratchDb.execute(sql)
         #DELETED = BEFORE - self.scratchDb.getRowCount(ippTableName)
-        results['SATDET'] = BEFORE - self.scratchDb.getRowCount(ippTableName)
+        #results['SATDET'] = BEFORE - self.scratchDb.getRowCount(ippTableName)
+        #we aren't deletng these now
+        results['SATDET'] = 0 
         #self.logger.infoPair("Saturated detections", "%d deleted" % DELETED)
 
@@ -404,6 +407,6 @@
                ,xPosErr \
                ,yPosErr \
-               ,instFlux \
-               ,instFluxErr \
+               ,psfFlux \
+               ,psfFluxErr \
                ,peakADU \
                ,psfWidMajor \
@@ -411,11 +414,13 @@
                ,psfTheta \
                ,psfLikelihood \
-               ,psfCf \
+               ,psfQf \
                ,momentXX \
                ,momentXY \
                ,momentYY \
-               ,apMag \
+               ,apFlux \
                ,kronFlux \
                ,kronFluxErr \
+               ,psfQfPerfect \
+               ,psfChiSq \
                ,infoFlag \
                ,sky \
@@ -447,10 +452,12 @@
                ,MOMENTS_XY \
                ,MOMENTS_YY \
-               ,AP_MAG \
+               ,POW(10.0, -0.4 *AP_MAG) / " + self.header['EXPTIME'] + " \
                ,KRON_FLUX / " + self.header['EXPTIME'] + " \
                ,KRON_FLUX_ERR / " + self.header['EXPTIME'] + " \
-               ,FLAGS\
-               ,SKY \
-               ,SKY_SIGMA \
+               ,PSF_QF_PERFECT \
+               ,PSF_CHISQ \
+               ,FLAGS2 << 32 | FLAGS \
+               ,SKY  / " + self.header['EXPTIME'] + " \
+               ,SKY_SIGMA  / " + self.header['EXPTIME'] + " \
                ,EXT_NSIGMA \
                , 0 \
@@ -459,19 +466,28 @@
                , " + str(self.config.dataRelease) + "\
                FROM " + ippTableName
+        # self.logger.info(sql)
         self.scratchDb.execute(sql)
 
         # now delete bad flux and bad chip positions
-        sql="DELETE FROM " + pspsTableName + " WHERE instFlux < 0.0000001" # TODO clearly a hack = 0 not allowed for instFlux
-        self.scratchDb.execute(sql)
-
+        #sql="DELETE FROM " + pspsTableName + " WHERE instFlux < 0.0000001" # TODO clearly a hack = 0 not allowed for instFlux
+        #self.scratchDb.execute(sql)
+
+        # add a instFlux = 0.0 -> 0.000001
+        sql="UPDATE " + pspsTableName + " SET psfFlux = 0.0000001 WHERE psfFlux =  0"
+        self.scratchDb.execute(sql)
+      
         # update cosmic ray and extended likelihoods
-        sql="UPDATE " + pspsTableName + " SET extendedLikelihood = 0, crLikelihood = 1.0 - psfLikelihood WHERE sgSep <= 0"
-        self.scratchDb.execute(sql)
-        sql="UPDATE " + pspsTableName + " SET crLikelihood = 0, extendedLikelihood = 1.0 - psfLikelihood WHERE sgSep > 0"
-        self.scratchDb.execute(sql)
+        #sql="UPDATE " + pspsTableName + " SET extendedLikelihood = 0, crLikelihood = 1.0 - psfLikelihood WHERE sgSep <= 0"
+        #self.scratchDb.execute(sql)
+        #sql="UPDATE " + pspsTableName + " SET crLikelihood = 0, extendedLikelihood = 1.0 - psfLikelihood WHERE sgSep > 0"
+        #self.scratchDb.execute(sql)
 
         # remove detections will NULL inst flux or NULL peak ADU
-        results['NULLINSTFLUX'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
-        results['NULLPEAKADU'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
+        # leave them in at this stage- don't delete them.
+        #results['NULLINSTFLUX'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "instFlux")
+        #results['NULLPEAKADU'] = self.scratchDb.reportAndDeleteRowsWithNULLS(pspsTableName, "peakADU")
+        #we don't delete thos anymore
+        results['NULLINSTFLUX'] = 0;
+        results['NULLPEAKADU'] = 0;
 
     '''
@@ -504,4 +520,49 @@
 
     '''
+    Populates the DetectionCalib table for this OTA
+    '''
+    def populateDetectionCalibTable(self, ota):
+
+        tableName = "DetectionCalib_" + ota
+        # drop then re-create table
+        self.scratchDb.dropTable(tableName)
+        sql = "CREATE TABLE " + tableName + " LIKE DetectionCalib"
+        try: self.scratchDb.execute(sql)
+        except: pass
+
+        # insert all detections into table
+        sql = "INSERT INTO " + tableName + " ( \
+               objID \
+               ,detectID \
+               ,ippObjID \
+               ,ippDetectID \
+               ,filterID \
+               ,surveyID \
+               ) \
+               SELECT \
+               objID \
+               ,detectID \
+               ,ippObjID \
+               ,ippDetectID \
+               ,filterID \
+               ,surveyID \
+               FROM Detection_" + ota
+        self.scratchDb.execute(sql)
+
+        # insert calibration information from dvoDetections into the Table
+        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
+            SET a.ra = b.ra, \
+            a.dec = b.dec_, \
+            a.raErr = b.raErr, \
+            a.decErr = b.decErr, \
+            a.zp = b.zp, \
+            a.zpErr = b.zpErr, \
+            a.expTime = b.expTime, \
+            a.airMass = b.airMass   \
+            WHERE a.objID = b.objID AND a.detectID = b.detectID"
+        self.scratchDb.execute(sql)
+        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease))
+        
+    '''
     Populates the Detection table for this OTA
     '''
@@ -587,4 +648,10 @@
             if not self.getIDsFromDVO(): return False
 
+        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of 
+        # the column in PSPS
+        self.scratchDb.execute("ALTER TABLE DetectionCalib CHANGE dec_ `dec` double")
+
+
+
         return True
 
@@ -608,5 +675,5 @@
                 extension = "XY%d%d_psf" % (x, y)
                 self.scratchDb.createIndex(extension, "IPP_IDET")
-
+        self.logger.infoPair("created indexes on", "IPP tables")      
     '''
     Updates provided table with DVO IDs from DVO table
@@ -620,5 +687,5 @@
                a.detectID = b.detectID, \
                a.objID = b.objID, \
-               a.infoFlag = b.flags << 32 | a.infoFlag \
+               a.infoFlag = b.flags << 45 | a.infoFlag \
                WHERE a.ippDetectID = b.ippDetectID \
                AND b.imageID = " + str(imageID)
@@ -658,13 +725,17 @@
                     self.logger.info("| %5s |            ------------- Bad astrometric solution : rejecting ------------                    |" % ota)
                     continue
-
+               # self.logger.info("populate stuff ");
                 # populate remainder of tables
                 self.populateDetectionTable(ota, results)
-
+               # self.logger.info("successful populate ");
                 # now add DVO IDs
                 self.updateDvoIDs("Detection_" + ota, self.imageIDs[ota])
+               # self.logger.info("updated dvoids")
                 results['NULLOBJID'] = self.scratchDb.reportAndDeleteRowsWithNULLS("Detection_" + ota, "objID")
-                self.updateImageID("Detection_" + ota, x, y) 
+                #self.logger.info("deleted nulls")
+                self.updateImageID("Detection_" + ota, x, y)
+               # self.logger.info("updateImageId")
                 rowCount = self.scratchDb.getRowCount("Detection_" + ota) 
+              #  self.logger.info("got row count")
                 self.logger.info("| %5s | %13d | %13d | %13d | %13d | %13d | %13d |", 
                         ota, 
@@ -675,5 +746,4 @@
                         results['NULLOBJID'],
                         rowCount)
-
                 totalOriginal = totalOriginal + results['ORIGINALTOTAL']
                 totalSatDet = totalSatDet + results['SATDET']
@@ -682,5 +752,5 @@
                 totalNullObjID = totalNullObjID + results['NULLOBJID']
                 totalDetections = totalDetections + rowCount
-
+                #self.logger.info("updated totals")
                 # check we have something in this Detection table TODO add this to table above
                 if rowCount < 1:
@@ -692,8 +762,13 @@
                        SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(self.imageIDs[ota]))
                 self.scratchDb.execute(sql)
-
+                
+                #self.logger.info("updated imagedata")
                 self.populateSkinnyObjectTable(ota)
+                #self.logger.info("updated skinnyobject")
                 self.populateObjectCalColorTable(ota)
-
+                #self.logger.info("updated objectcalcolor")
+                self.populateDetectionCalibTable(ota)
+                #self.logger.info("updated detectioncalibtable")
+                
                 # add these to list of tables to export later
                 self.tablesToExport.append("ImageMeta_" + ota)
@@ -701,8 +776,9 @@
                 self.tablesToExport.append("SkinnyObject_" + ota)
                 self.tablesToExport.append("ObjectCalColor_" + ota)
+                self.tablesToExport.append("DetectionCalib_" + ota)
                 tables.append("Detection_" + ota)
            
                 otaCount = otaCount + 1
-
+                #self.logger.info("end of ota") 
         # print totals
         self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+---------------+")
@@ -757,5 +833,5 @@
        else : regex = ".*.psf"
   
-       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS SKY SKY_SIGMA EXT_NSIGMA"
+       columns = "IPP_IDET X_PSF Y_PSF X_PSF_SIG Y_PSF_SIG PSF_INST_MAG PSF_INST_MAG_SIG PEAK_FLUX_AS_MAG PSF_MAJOR PSF_MINOR PSF_THETA EXT_NSIGMA PSF_QF MOMENTS_XX MOMENTS_XY MOMENTS_YY AP_MAG KRON_FLUX KRON_FLUX_ERR FLAGS FLAGS2 SKY SKY_SIGMA EXT_NSIGMA PSF_QF_PERFECT PSF_CHISQ"
 
        return super(DetectionBatch, self).importIppTables(columns, regex)
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/dvodetections.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/dvodetections.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/dvodetections.py	(revision 34735)
@@ -44,5 +44,5 @@
            self.importFits(
                    cpmPath,
-                   "IMAGE_ID DET_ID OBJ_ID CAT_ID EXT_ID DB_FLAGS",
+                   "IMAGE_ID DET_ID OBJ_ID CAT_ID EXT_ID DB_FLAGS PHOTCODE AIRMASS M_TIME M_CAL MAG_CAL_ERR D_RA D_DEC PLTSCALE X_CCD_ERR Y_CCD_ERR",
                    cpmTableName)
 
@@ -50,4 +50,6 @@
            self.scratchDb.createIndex(cpmTableName, "CAT_ID")
            self.scratchDb.createIndex(cpmTableName, "OBJ_ID")
+
+           # XXX: Should we create index on PHOTCODE?
 
            # we can now report that we have imported this table
@@ -60,5 +62,5 @@
        self.importFits(
                cptPath,
-               "OBJ_ID CAT_ID EXT_ID",
+               "OBJ_ID CAT_ID EXT_ID RA DEC",
                cptTableName)
 
@@ -67,17 +69,35 @@
        self.scratchDb.createIndex(cptTableName, "OBJ_ID")
 
+       # SA10
+       # Columns needed for DetectionCalib and StackDetectionCalib
+       # zp      = photcode.K * (AIRMASS - 1) + photcode.C_LAM * 0.001 - cpm.M_CAL
+       # zpErr   = cpm.MAG_CAL_ERR
+       # airMass = cpm.AIRMASS
+       # expTime = POW(10.0, 0.4 * cpm.M_TIME)
+       # ra      = cpt.RA  - (cpm.D_RA  / 3600.0)
+       # dec     = cpt.DEC - (cpm.D_DEC / 3600.0)
+       # raErr   = cpm.X_CCD_ERR * cpm.PLTSCALE
+       # decErr  = cpm.Y_CCD_ERR * cpm.PLTSCALE
+
        self.logger.infoPair("Adding","PSPS objIDs")
-       # first try to add a column for PSPS_OBJ_ID. catch failure and continue
+       # first try to add the new columns. catch failure and continue
        try:
-           sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (PSPS_OBJ_ID BIGINT)"
+           sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (PSPS_OBJ_ID BIGINT), (ZP REAL), (RA FLOAT), (DEC FLOAT)"
            self.scratchDb.execute(sql)
        except:
            self.logger.infoPair("Already added PSPS_OBJ_ID column to", cpmTableName)
                
-       # shove PSPS objIDs from cpt table into measurement table
-       sql = "UPDATE " + cpmTableName + " AS a, " + cptTableName + " AS b \
-              SET a.PSPS_OBJ_ID = b.EXT_ID \
+       # shove PSPS objIDs from cpt table and the calibrated zero point and coordinates which are formed 
+       # by combining values from multiple tables into cpt table
+       sql = "UPDATE " + cpmTableName + " AS a, " + cptTableName + " AS b, " \
+              + self.scratchDb.dvoPhotcodesTable + " AS c \
+              SET a.PSPS_OBJ_ID = b.EXT_ID, \
+              b.ZP  = c.C_LAM * 0.001 + c.K * (b.AIRMASS - 1) - b.M_CAL, \
+              b.RA  = a.RA  - (b.D_RA  / 3600.0), \
+              b.DEC = a.DEC - (b.D_DEC / 3600.0) \
               WHERE a.CAT_ID = b.CAT_ID \
-              AND a.OBJ_ID = b.OBJ_ID"
+              AND a.OBJ_ID = b.OBJ_ID   \
+              AND b.PHOTCODE = c.CODE"
+
        self.scratchDb.execute(sql)
 
@@ -86,4 +106,5 @@
        # PSPS object IDs assigned in the corresponding cpt file. This is believed to be a chip-boundary 
        # issue within DVO. So, for now, we take the first IMAGE_ID/DET_ID detection we find, and ignore the rest
+       # XXX: Bills 2012-10031 Does this problem still exist?
        self.logger.infoPair("Merging into", self.scratchDb.dvoDetectionTable)
        sql = "INSERT IGNORE INTO " + self.scratchDb.dvoDetectionTable + " (\
@@ -94,4 +115,12 @@
               ,objID \
               ,flags \
+              ,zp   \
+              ,zpErr    \
+              ,airMass  \
+              ,expTime  \
+              ,ra   \
+              ,dec_  \
+              ,raErr    \
+              ,decErr   \
               ,fileID \
               ) SELECT \
@@ -102,6 +131,15 @@
               ,PSPS_OBJ_ID \
               ,DB_FLAGS \
+              ,ZP   \
+              ,MAG_CAL_ERR  \
+              ,AIRMASS  \
+              ,POW(10.0, 0.4 * M_TIME)  \
+              ,RA   \
+              ,DEC  \
+              ,X_CCD_ERR*PLTSCALE   \
+              ,Y_CCD_ERR*PLTSCALE   \
               , " + str(fileId) + " \
               FROM " + cpmTableName
+
        try:
            self.scratchDb.execute(sql)
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/ipptopspsdb.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/ipptopspsdb.py	(revision 34735)
@@ -638,4 +638,6 @@
             and not self.processingNow(batchType, stageID) \
             and not self.consistentlyFailed(batchType, stageID)): 
+            
+            self.logger.infoPair("heather:","passed logic")
 
             sql = "INSERT INTO batch ( \
@@ -652,4 +654,5 @@
                        '" + self.config.datastoreProduct + "' \
                        )"
+            self.logger.infoPair("heather:","sql")
 
             self.execute(sql)
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/loader.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/loader.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/loader.py	(revision 34735)
@@ -123,13 +123,13 @@
 
                 self.logger.infoPair("Boxes with unprocessed data", "%d" % len(boxIds))
-    
+                self.logger.infoPair("numAttempts", str(numAttempts))
                 if len(boxIds) > 0: numAttempts = 0
 
                 for boxId in boxIds:
-          
+                    self.logger.infoPair("Check","client status")
                     if not self.checkClientStatus():
                         abort = True
                         break
-    
+                    self.logger.infoPair("client status", "ok")
                     # get box info. if boxes have changed, break and start again
                     try:
@@ -138,5 +138,5 @@
                         self.logger.infoPair("Can't get details for this box", "%d" % boxId)
                         break
-     
+                    self.logger.infoPair("client status", "ok")
                     ids = self.ippToPspsDb.getPendingIdsForThisBox(boxId, batchType)
                 
@@ -150,5 +150,5 @@
                     self.logger.infoPair(batchType + " items found in this box", "%d" % len(ids))
                     boxSizeWithBorder = boxDim['SIDE'] + (self.config.BORDER * 2)
-     
+                    self.logger.infoPair("got here", "ok")
                     useFullTables = 0
                     if batchType != "OB":
@@ -174,5 +174,5 @@
                         abort = True
                         break
-
+                    self.logger.infoPair("processed","ok")
             if abort or not self.checkClientStatus(): abort = True
             elif numAttempts > 1 and not self.waitForPollTime():  break
@@ -188,15 +188,20 @@
         # loop round IDs of all items to be processed
         self.ippToPspsDb.lockBatchTable()
+        self.logger.infoPair("heather:","lockbatchtable")
         unattemptedCount = 0
         for id in ids:
-    
+            self.logger.infoPair("heather:","in ids")
+            self.logger.infoPair("heather:id",str(id))
             batchID = self.ippToPspsDb.createNewBatch(batchType, id)
-            
+            self.logger.infoPair("heather:","creatednewbatch")
+            self.logger.infoPair("heather:batchId", str(batchID))
             if batchID < 0: 
                 unattemptedCount += 1
                 continue
-    
+            self.logger.infoPair("heather:","passed logic")
             self.ippToPspsDb.unlockTables()
+            self.logger.infoPair("heather:","unlock table")
             self.ippToPspsDb.deletePendingItem(batchType, id)
+            self.logger.infoPair("heather:","deleted pending item")
 
             # catch any raised exceptions in batch constructors
@@ -234,12 +239,14 @@
    
             # if batch fails, ignore and move on to the next one
-            except: 
+            except Exception, e: 
+                self.logger.error("EXCEPTION: " + str(e))
                 self.logger.errorPair("Problem with this %s batch (%d)" % (batchType, id), "skipping")
                 pass
 
             if not self.checkClientStatus(): return False
-    
+            self.logger.infoPair("checkclient status", "ok")
+
             self.ippToPspsDb.lockBatchTable()
-    
+            self.logger.infoPair("lockbatchtable", "ok")
             self.logger.infoSeparator()
     
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/objectbatch.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/objectbatch.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/objectbatch.py	(revision 34735)
@@ -114,6 +114,11 @@
         for filter in filters:
 
-            sql = "UPDATE Object \
-                   JOIN " + cpsTable + " AS cps ON (cps.row = (Object.row*" + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
+            filterID = self.scratchDb.getFilterID(filter[1])
+
+            # NOTE: Manipulation of FLAGS from cpsTable is to move ID_SECF_OBJ_EXT flag (0x01000000)
+	    # from bit 24 to bit 13 so that it fits into the SMALLINT Object.Flags
+
+            sql = "UPDATE Object JOIN \
+                   " + cpsTable + " AS cps ON (cps.row = (Object.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) \
                    SET \
                    n" + filter[1] + " = NCODE \
@@ -122,14 +127,26 @@
                    ," + filter[1] + "MeanKronMag = MAG_KRON \
                    ," + filter[1] + "MeanKronMagErr = MAG_KRON_ERR \
-                   ," + filter[1] + "StackPSFFlux = FLUX_PSF \
-                   ," + filter[1] + "StackPSFFluxErr = FLUX_PSF_ERR \
+                   ," + filter[1] + "StackPSFMag = -2.5 * log10(FLUX_PSF) + 8.9 \
+                   ," + filter[1] + "StackPSFMagErr = FLUX_PSF_ERR / FLUX_PSF \
                    ," + filter[1] + "StackKronMag = -2.5 * log10(FLUX_KRON) + 8.9 \
                    ," + filter[1] + "StackKronMagErr = FLUX_KRON_ERR / FLUX_KRON \
                    ," + filter[1] + "20pct = MAG_20/1000 \
                    ," + filter[1] + "80pct = MAG_80/1000 \
-                   ," + filter[1] + "Flags = FLAGS "  
-                   
+                   ," + filter[1] + "Flags = (0x7fff & FLAGS) | ((FLAGS >> 11) & 0x2000) \
+                   ," + filter[1] + "StackDetectID = STACK_DETECT_ID + " + str(filterID)
+
+            #self.logger.info(sql)
+            self.scratchDb.execute(sql)
+
+        self.logger.infoPair("Calculating nDetections from", "n[filters]")
+        for filter in filters:
+            # now do a sum of n[filters], but do not include the ones with -999
+            sql = "UPDATE Object \
+                   SET nDetections = nDetections + n" + filter[1] + " \
+                   WHERE n" + filter[1] + " != -999"
+            self.scratchDb.execute(sql)
             
-            self.scratchDb.execute(sql)
+
+
 
         # now set to null all MeanMagErr values > 0.5 (cut set by Gene, 2012-04-12)
@@ -189,5 +206,27 @@
         cpsTableName = self.scratchDb.getDbFriendlyTableName(self.region + ".cps")
 
-        self.logger.infoPair("Populating", "Object")
+        self.logger.infoPair("setting to null  > 1e-38 and < 1e-38 in", "cps FLUX_KRON_ERR")
+        sql = "UPDATE " + cpsTableName + " set FLUX_KRON_ERR = NULL where FLUX_KRON_ERR < 1e-37 AND FLUX_KRON_ERR > -1e-37 "
+      
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("Couldn't squash out of range stuff", sql)
+            return False
+
+        self.logger.infoPair("setting to null  > 1e-38 and < 1e-38 in", "cps FLUX_KRON")
+        sql = "UPDATE " + cpsTableName + " set FLUX_KRON = NULL where FLUX_KRON < 1e-37 AND FLUX_KRON > -1e-37 "
+      
+        try:
+            self.scratchDb.execute(sql)
+        except:
+            self.logger.errorPair("Couldn't squash out of range stuff", sql)
+            return False
+
+
+
+
+        
+        self.logger.infoPair("Populating", "Object s")
         self.logger.infoPair("Inserting objects from", "cpt file")
 
@@ -204,5 +243,5 @@
                ,decErr \
                ,nDetections \
-               ,extra \
+               ,qfPerfect \
                ,sgSep \
                ,dataRelease \
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/scratchdb.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/scratchdb.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/scratchdb.py	(revision 34735)
@@ -68,4 +68,6 @@
                DECLARE t REAL; \
                DECLARE z REAL; \
+               DECLARE s INT; \
+               SET s= SIGN(x); \
                SET x = ABS(x) / 1.4142135623731; \
                SET z=ABS(x); \
@@ -75,4 +77,5 @@
                SET ans = 2.0 - ans; \
                END IF; \
+               SET ans = ans * s; \
                RETURN ans; \
                END"
@@ -385,4 +388,12 @@
                objID BIGINT, \
                flags INT, \
+               zp REAL, \
+               zpErr REAL, \
+               airMass REAL, \
+               expTime REAL, \
+               ra FLOAT, \
+               dec_ FLOAT, \
+               raErr REAL, \
+               decErr REAL, \
                PRIMARY KEY (imageID, ippDetectID) \
                )"
Index: /branches/eam_branches/ipp-20120905/ippToPsps/jython/stackbatch.py
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/jython/stackbatch.py	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/jython/stackbatch.py	(revision 34735)
@@ -76,4 +76,8 @@
        self.projectioncell = self.skycell
 
+       # proposed new values. Need to coordinate with the SkyCell table
+       # this fits in 32 bits for 0 < tessID < 214
+       # self.skycell = str( (tessID * (10000 * 1000)) + (int(self.projectioncell) * 1000) + cellID )
+
        self.analysisVer = meta[2];
 
@@ -89,4 +93,5 @@
        self.scratchDb.dropTable("SkinnyObject")
        self.scratchDb.dropTable("ObjectCalColor")
+       self.scratchDb.dropTable("StackDetectionCalib")
 
        # delete IPP tables
@@ -140,43 +145,43 @@
 
         sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
-        "+prefix+"flxR1=b.APER_FLUX_1, \
-        "+prefix+"flxR1Err=b.APER_FLUX_ERR_1, \
-        "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1, \
+        "+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
+        "+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
+        "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
         "+prefix+"flxR1Fill=b.APER_FILL_1, \
-        "+prefix+"flxR2=b.APER_FLUX_2, \
-        "+prefix+"flxR2Err=b.APER_FLUX_ERR_2, \
-        "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2, \
+        "+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
+        "+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
+        "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
         "+prefix+"flxR2Fill=b.APER_FILL_2, \
-        "+prefix+"flxR3=b.APER_FLUX_3, \
-        "+prefix+"flxR3Err=b.APER_FLUX_ERR_3, \
-        "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3, \
+        "+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
+        "+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
+        "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
         "+prefix+"flxR3Fill=b.APER_FILL_3, \
-        "+prefix+"flxR4=b.APER_FLUX_4, \
-        "+prefix+"flxR4Err=b.APER_FLUX_ERR_4, \
-        "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4, \
+        "+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
+        "+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
+        "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
         "+prefix+"flxR4Fill=b.APER_FILL_4, \
-        "+prefix+"flxR5=b.APER_FLUX_5, \
-        "+prefix+"flxR5Err=b.APER_FLUX_ERR_5, \
-        "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5, \
+        "+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
+        "+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
+        "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
         "+prefix+"flxR5Fill=b.APER_FILL_5, \
-        "+prefix+"flxR6=b.APER_FLUX_6, \
-        "+prefix+"flxR6Err=b.APER_FLUX_ERR_6, \
-        "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6, \
+        "+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
+        "+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
+        "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
         "+prefix+"flxR6Fill=b.APER_FILL_6, \
-        "+prefix+"flxR7=b.APER_FLUX_7, \
-        "+prefix+"flxR7Err=b.APER_FLUX_ERR_7, \
-        "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7, \
+        "+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
+        "+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
+        "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
         "+prefix+"flxR7Fill=b.APER_FILL_7, \
-        "+prefix+"flxR8=b.APER_FLUX_8, \
-        "+prefix+"flxR8Err=b.APER_FLUX_ERR_8, \
-        "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8, \
+        "+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
+        "+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
+        "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
         "+prefix+"flxR8Fill=b.APER_FILL_8, \
-        "+prefix+"flxR9=b.APER_FLUX_9, \
-        "+prefix+"flxR9Err=b.APER_FLUX_ERR_9, \
-        "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9, \
+        "+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
+        "+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
+        "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
         "+prefix+"flxR9Fill=b.APER_FILL_9, \
-        "+prefix+"flxR10=b.APER_FLUX_10, \
-        "+prefix+"flxR10Err=b.APER_FLUX_ERR_10, \
-        "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10, \
+        "+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
+        "+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
+        "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
         "+prefix+"flxR10Fill=b.APER_FILL_10 \
         WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
@@ -196,6 +201,6 @@
         sql = "UPDATE StackModelFit AS a, SkyChip_xfit AS b SET \
         "+model+"Radius=b.EXT_WIDTH_MAJ,  \
-        "+model+"Mag=b.EXT_INST_MAG,  \
-        "+model+"MagErr=b.EXT_INST_MAG_SIG,  \
+        "+model+"Flux=POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " ,  \
+        "+model+"FluxErr=ABS(b.EXT_INST_MAG_SIG) * POW(10, -0.4 * b.EXT_INST_MAG) / " + str(self.expTime) + " / 1.085736, \
         "+model+"Ab=b.EXT_WIDTH_MAJ/b.EXT_WIDTH_MIN, \
         "+model+"Phi=b.EXT_THETA,  \
@@ -319,11 +324,10 @@
                ,skyCellID \
                ,projectionCellID \
-               ,obsTime \
                ,xPos \
                ,yPos \
                ,xPosErr \
                ,yPosErr \
-               ,instFlux \
-               ,instFluxErr \
+               ,psfFlux \
+               ,psfFluxErr \
                ,peakFlux \
                ,sky \
@@ -335,5 +339,6 @@
                ,psfLikelihood \
                ,infoFlag \
-               ,psfCf \
+               ,psfQf \
+               ,psfQfPerfect \
                ,momentXX \
                ,momentXY \
@@ -345,10 +350,10 @@
                ,momentR1 \
                ,momentRH \
-               ,apMag \
-               ,apMagErr \
+               ,apFlux \
+               ,apFluxErr \
                ,kronFlux \
                ,kronFluxErr \
                ,kronRad \
-               ,kronRadErr \
+               ,psfChiSq \
                ,nFrames \
                ,assocDate \
@@ -359,5 +364,4 @@
                ," + self.skycell + " \
                ," + self.projectioncell + " \
-               ," + self.header['MJD-OBS'] + " \
                ,X_PSF \
                ,Y_PSF \
@@ -367,6 +371,6 @@
                ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / " + str(self.expTime) + ")) / 1.085736) \
                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / " + str(self.expTime) + " \
-               ,SKY \
-               ,SKY_SIGMA \
+               ,SKY / " + str(self.expTime) + " \
+               ,SKY_SIGMA / " + str(self.expTime) + " \
                ,EXT_NSIGMA \
                ,PSF_MAJOR \
@@ -374,6 +378,7 @@
                ,PSF_THETA \
                ,psfLikelihood(EXT_NSIGMA) \
-               ,FLAGS2 << 32 | FLAGS \
+               , FLAGS2 << 32 | FLAGS \
                ,PSF_QF \
+               ,PSF_QF_PERFECT \
                ,MOMENTS_XX \
                ,MOMENTS_XY \
@@ -385,10 +390,10 @@
                ,MOMENTS_R1 \
                ,MOMENTS_RH \
-               ,AP_MAG \
-               , NULL \
+               ,POW(10.0, -0.4*AP_MAG) / " + str(self.expTime) + " \
+               ,NULL \
                ,KRON_FLUX / " + str(self.expTime) + " \
                ,KRON_FLUX_ERR / " + str(self.expTime) + " \
-               , MOMENTS_R1 * 2.5 \
-               , NULL \
+               ,MOMENTS_R1 * 2.5 \
+               ,PSF_CHISQ \
                ,N_FRAMES \
                , '" + self.dateStr + "' \
@@ -417,5 +422,5 @@
         self.updateStackTypeID("StackDetection")
         
-        self.updateDvoIDs("StackDetection")
+        self.updateDvoIDsAndFlags("StackDetection")
         
         sql = "ALTER IGNORE TABLE StackDetection ADD PRIMARY KEY (objID)"
@@ -427,6 +432,6 @@
             #if deep stack and instFlux = null and err not null
             sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
-                   SET instFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
-                   WHERE instFlux IS NULL \
+                   SET psfFlux = 2*b.PSF_INST_FLUX_SIG / " + str(self.expTime) + " \
+                   WHERE psfFlux IS NULL \
                    AND a.ippDetectID = b.IPP_IDET  \
                    AND b.PSF_INST_FLUX_SIG IS NOT NULL"
@@ -434,6 +439,6 @@
             self.scratchDb.execute(sql)
             
-        
-        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
+        #leave null instflux in
+        #self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
         
         self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
@@ -474,6 +479,6 @@
         petRadius=b.PETRO_RADIUS \
         ,petRadiusErr=b.PETRO_RADIUS_ERR \
-        ,petMag=b.PETRO_MAG \
-        ,petMagErr=b.PETRO_MAG_ERR \
+        ,petFlux=POW(10.0, -0.4 * b.PETRO_MAG) /" + str(self.expTime) + " \
+        ,petFluxErr=ABS(b.PETRO_MAG_ERR) * POW(10.0, (-0.4*b.PETRO_MAG)) / " + str(self.expTime) + " / 1.085736  \
         ,petR50=b.PETRO_RADIUS_50 \
         ,petR50Err=b.PETRO_RADIUS_50_ERR \
@@ -587,4 +592,45 @@
         self.scratchDb.updateAllRows("SkinnyObject", "dataRelease", str(self.config.dataRelease))
 
+    '''    
+    Populates the StackDetectionCalib table
+    '''
+    def populateStackDetectionCalib(self):
+        self.logger.infoPair("Processing table", "StackDetectionCalib")
+        tableName = "StackDetectionCalib"
+        # insert all detections into table
+        sql = "INSERT INTO " + tableName + " ( \
+               objID \
+               ,stackDetectID \
+               ,ippObjID \
+               ,ippDetectID \
+               ,filterID \
+               ,surveyID \
+               ) \
+               SELECT \
+               objID \
+               ,stackDetectID \
+               ,ippObjID \
+               ,ippDetectID \
+               ,filterID \
+               ,surveyID \
+               FROM StackDetection"
+        self.scratchDb.execute(sql)
+        # insert calibration information from dvoDetections into the Table
+        sql = "UPDATE " + tableName + " AS a, "  + self.scratchDb.dvoDetectionTable + " AS b \
+            SET a.ra = b.ra, \
+            a.dec = b.dec_, \
+            a.raErr = b.raErr, \
+            a.decErr = b.decErr, \
+            a.zp = b.zp, \
+            a.zpErr = b.zpErr, \
+            a.expTime = b.expTime, \
+            a.airMass = b.airMass   \
+            WHERE a.stackDetectID = b.detectID"
+        self.scratchDb.execute(sql)
+        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.config.dataRelease))
+        
+    
+
+
     '''
     Populates the ObjectCalColor table
@@ -620,4 +666,8 @@
         self.scratchDb.createIndex("StackModelFit", "ippDetectID")
 
+        # dec is reserved in MySQL, so STILTS replaces if with dec_, which is not the name of 
+        # the column in PSPS
+        self.scratchDb.execute("ALTER TABLE StackDetectionCalib CHANGE dec_ `dec` double")
+
         return True
 
@@ -645,11 +695,28 @@
         sql = "UPDATE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
                a.ippObjID = b.ippObjID, \
-               a.stackDetectID = 10 * b.detectID + " + str(self.filterID) + ", \
+               a.stackDetectID = b.detectID, \
                a.objID = b.objID \
                WHERE a.ippDetectID = b.ippDetectID \
                AND b.imageID = " + str(imageID)
-        
-        self.scratchDb.execute(sql)
-        
+        self.scratchDb.execute(sql)
+    
+    '''
+    Updates Flags
+    '''
+    def updateDvoIDsAndFlags(self, table):
+        self.logger.infoPair("getting","imageID")
+        imageID = self.scratchDb.getImageIDFromExternID(self.header['IMAGEID'])
+        self.logger.infoPair("obtained","imageID")
+        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
+        sql = "UPDATE " + table + " AS a, " + self.scratchDb.dvoDetectionTable + " AS b SET \
+               a.ippObjID = b.ippObjID, \
+               a.stackDetectID = b.detectID, \
+               a.objID = b.objID, \
+               a.infoFlag = b.flags << 45 | a.infoFlag \
+               WHERE a.ippDetectID = b.ippDetectID \
+               AND b.imageID = " + str(imageID)
+        self.scratchDb.execute(sql)
+    
+    
     '''
     Does the processing, i.e. pulling stuff from IPP tables into PSPS tables
@@ -660,15 +727,22 @@
             if not self.getIDsFromDVO():
                 return False
-
+        #self.logger.infoPair("populating","StackMeta")    
         self.populateStackMeta()
+        #self.logger.infoPair("populating","StackDetection") 
         self.populateStackDetection()
-
+        
         if self.stackType != "NIGHTLY_STACK": 
+            #self.logger.infoPair("populating","StackModelFit") 
             self.populateStackModelFit()
+            #self.logger.infoPair("populating","StackApFlx") 
             self.populateStackApFlx()
-   
+        #self.logger.infoPair("populating","StackToImage") 
         self.populateStackToImage()
+        #self.logger.infoPair("populating","SkinnyObject") 
         self.populateSkinnyObject()
+        #self.logger.infoPair("populating","ObjectCalColor") 
         self.populateObjectCalColor()
+        #self.logger.infoPair("populating","StackDetectionCalib") 
+        self.populateStackDetectionCalib()
 
         self.setMinMaxObjID(["StackDetection"])
Index: /branches/eam_branches/ipp-20120905/ippToPsps/src/Dvo.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippToPsps/src/Dvo.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippToPsps/src/Dvo.c	(revision 34735)
@@ -90,12 +90,24 @@
             }
             else {
+                Average *ave  = &dvoDetections[i].ave;
+                Measure *meas = &dvoDetections[i].meas;
+                PhotCode *code = GetPhotcodebyCode(meas->photcode);
                 sprintf(sql, 
-                        "INSERT INTO dvoDetection (imageID, ippDetectID, detectID, ippObjID, objID, flags) VALUES (%d, %u, %lu, %lu, %lu, %u)",
+                        "INSERT INTO dvoDetection (imageID, ippDetectID, detectID, ippObjID, objID, flags, zp, zpErr, airMass, expTime, ra, dec_, raErr, decErr) VALUES (%d, %u, %lu, %lu, %lu, %u, %f, %f, %f, %f, %lf, %lf, %f %f)",
                         image->imageID,    // imageID
-                        dvoDetections[i].meas.detID,   // ippDetectID
-                        dvoDetections[i].meas.extID,   // detectID
-                        (uint64_t)dvoDetections[i].ave.catID*1000000000 + (uint64_t)dvoDetections[i].ave.objID, // ippObjID
-                        dvoDetections[i].ave.extID, // objID
-                        dvoDetections[i].meas.dbFlags); // flags
+                        meas->detID,   // ippDetectID
+                        meas->extID,   // detectID
+                        (uint64_t)ave->catID*1000000000 + (uint64_t)ave->objID, // ippObjID
+                        dvoDetections[i].ave.extID,   // objID
+                        meas->dbFlags,                // flags
+                        code->C * 0.001 + code->K * (meas->airmass - 1) - meas->Mcal,   // zp
+                        meas->dMcal,                  // zpErr
+                        meas->airmass,
+                        pow(10.0, 0.4 * meas->dt),    // expTime
+                        ave->R - meas->dR / 3600.,    // ra
+                        ave->D - meas->dR / 3600.,    // dec
+                        meas->dXccd * meas->pltscale, // estimate of raErr
+                        meas->dYccd * meas->pltscale  // estimate of decErr
+                        );
 
                 mysql_query(this->mysql, sql); 
Index: /branches/eam_branches/ipp-20120905/ippTools/share/bgtool_towarp.sql
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/share/bgtool_towarp.sql	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/share/bgtool_towarp.sql	(revision 34735)
@@ -1,3 +1,3 @@
-SELECT
+SELECT DISTINCT
     warpBackgroundRun.*,
     warpRun.tess_id,
Index: /branches/eam_branches/ipp-20120905/ippTools/share/magicdstool_torevert_camera.sql
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/share/magicdstool_torevert_camera.sql	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/share/magicdstool_torevert_camera.sql	(revision 34735)
@@ -23,4 +23,6 @@
     JOIN rawExp using(exp_id)
 WHERE magicDSRun.stage = 'camera'
+    AND camProcessedExp.fault = 0
+    AND camRun.state = 'full'
     AND ((magicDSRun.state = 'new' AND magicDSFile.fault > 0)
          OR ((magicDSRun.state = 'goto_censored' OR magicDSRun.state = 'goto_restored')
Index: /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_result.sql
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_result.sql	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_result.sql	(revision 34735)
@@ -7,4 +7,7 @@
     stackRun.skycell_id,
     count(stackRun.filter) AS num_filters,
+    TRUNCATE(skycell.radeg/15., 4) AS rahours,
+    skycell.radeg,
+    skycell.decdeg,
     skycell.glong,
     skycell.glat
Index: /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_todo.sql
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_todo.sql	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/share/staticskytool_todo.sql	(revision 34735)
@@ -7,8 +7,14 @@
     stackRun.tess_id,
     stackRun.skycell_id,
+    TRUNCATE(skycell.radeg/15., 4) as rahours,
+    skycell.radeg,
+    skycell.decdeg,
+    skycell.glong,
+    skycell.glat,
     IFNULL(Label.priority, 10000) AS priority
 FROM staticskyRun
 JOIN staticskyInput USING (sky_id)
 JOIN stackRun USING (stack_id)
+JOIN skycell USING(tess_id, skycell_id)
 LEFT JOIN staticskyResult USING(sky_id)
 LEFT JOIN Label ON staticskyRun.label = Label.label
Index: /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c	(revision 34735)
@@ -970,10 +970,10 @@
     psFree(where);
 
+    int numDeleted = psDBAffectedRows(config->dbh);
     if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
     }
-    int numUpdated = psDBAffectedRows(config->dbh);
-    psLogMsg("camtool", PS_LOG_INFO, "Updated %d camProcessedExps", numUpdated);
+    psLogMsg("camtool", PS_LOG_INFO, "Deleted %d camProcessedExps", numDeleted);
 
     return true;
Index: /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c	(revision 34735)
@@ -1115,4 +1115,5 @@
     PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "==");
     PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE");
+    PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "==");
     pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE");
     pxAddLabelSearchArgs(config, where, "-data_group", "stackRun.data_group", "LIKE");
Index: /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c	(revision 34735)
@@ -206,4 +206,5 @@
     psMetadataAddF64(sumskyfileArgs, PS_LIST_TAIL, "-mjd_obs_begin",  0,      "search by mjd_obs (average mjd_obs of inputs <=)", NAN);
     psMetadataAddF64(sumskyfileArgs, PS_LIST_TAIL, "-mjd_obs_end",  0,      "search by mjd_obs (average mjd_obs of inputs>=)", NAN);
+    psMetadataAddStr(sumskyfileArgs, PS_LIST_TAIL, "-state", 0,             "search by state", NULL);
     psMetadataAddS16(sumskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
     psMetadataAddU64(sumskyfileArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config	(revision 34735)
@@ -79,4 +79,10 @@
   DIFFABLE  BOOL FALSE
   DIST      S16  30
+  # bump the retention times for the time being
+  CHIP S16 60
+  WARP S16 60
+  DIFF S16 60
+  CHIPBG S16 60
+  WARPBG S16 60
 END
 TARGETS METADATA
@@ -211,7 +217,7 @@
   REDUCTION STR STS_DATASET
   # bump the retention times for the time being
-  CHIP S16 7
-  WARP S16 7
-  DIFF S16 7
+  CHIP S16 60
+  WARP S16 60
+  DIFF S16 60
 END
 TARGETS METADATA
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/ppSub.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/ppSub.config	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/ppSub.config	(revision 34735)
@@ -90,4 +90,20 @@
 # Recipe overrides for DIFF
 DIFF	METADATA
+	DUAL		BOOL	TRUE	# Dual convolution?
+	INVERSE		BOOL	TRUE	# Generate inverse subtraction?
+	PHOTOMETRY	BOOL	TRUE	# Perform photometry?
+
+	# penalty of 1.0
+	# DUAL convolution is more sensitive to the number of kernels
+	# do not provide as many orders as for SINGLE
+        # @ISIS.WIDTHS	F32	2.4  5.0  10.0  # Gaussian kernel FWHM values
+	@ISIS.WIDTHS	F32	1.5  3.0  6.0   # Gaussian kernel FWHM values
+	# @ISIS.WIDTHS	F32	2.0  3.0  5.0   # Gaussian kernel FWHM values
+        # @ISIS.WIDTHS	F32	2.1  4.2  8.4   # Gaussian kernel FWHM values
+	@ISIS.ORDERS	S32	2    2    2     # Polynomial orders for ISIS kernels
+
+	SCALE.REF	F32     5.0		# FWHM reference for kernel parameter scaling
+	KERNEL.SIZE     S32	15		# Kernel half-size (pixels)
+	STAMP.FOOTPRINT S32	15		# Size of stamps (pixels)
 END
 
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config	(revision 34735)
@@ -558,5 +558,5 @@
 DIFF	METADATA
   DIFF_STATS			    BOOL TRUE	       # Calculate diff-specific stats
-  OUTPUT.FORMAT		            STR  PS1_DV2       # Format of output file
+  OUTPUT.FORMAT		            STR  PS1_DV3       # Format of output file
 
   # Extended source fit parameters
@@ -575,5 +575,5 @@
   PEAKS_NSIGMA_LIMIT_2                F32   4.0             # peak significance threshold  
   DIFF_STATS			    BOOL TRUE	       # Calculate diff-specific stats
-  OUTPUT.FORMAT		            STR  PS1_DV2       # Format of output file
+  OUTPUT.FORMAT		            STR  PS1_DV3       # Format of output file
 
   # Extended source fit parameters
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/reductionClasses.mdc
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/reductionClasses.mdc	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/reductionClasses.mdc	(revision 34735)
@@ -260,4 +260,28 @@
 	STACK_PSPHOT	  STR	  STACK
 	DIFF_PPSUB	  STR	  DIFF
+	DIFF_PSPHOT	  STR	  SSTF_DIFF
+	JPEG_BIN1	  STR	  PPIMAGE_J1
+	JPEG_BIN2	  STR	  PPIMAGE_J2
+	FAKEPHOT	  STR	  FAKEPHOT
+	ADDSTAR		  STR	  ADDSTAR
+	PSASTRO		  STR	  DEFAULT_RECIPE
+	STACKPHOT_PSPHOT  STR     STACKPHOT
+	STACKPHOT_PPSUB   STR     STACKPHOT
+	STACKPHOT_PPSTACK STR     STACKPHOT
+	STACKPHOT_SINGLE_PSPHOT  STR     STACKPHOT_SINGLE
+	BACKGROUND_PPBACKGROUND	STR	BACKGROUND
+	BACKGROUND_PSWARP	STR	BACKGROUND
+        PSVIDEOPHOT             STR     PSVIDEOPHOT
+END
+
+# Sweetspot reduction class
+SWEETSPOT_WS		METADATA
+	CHIP_PPIMAGE	  STR	  CHIP
+	CHIP_PSPHOT	  STR	  CHIP
+	WARP_PSWARP	  STR	  WARP
+	STACK_PPSTACK	  STR	  QUICKSTACK
+	STACK_PPSUB	  STR	  STACK
+	STACK_PSPHOT	  STR	  STACK
+	DIFF_PPSUB	  STR	  WARPSTACK
 	DIFF_PSPHOT	  STR	  SSTF_DIFF
 	JPEG_BIN1	  STR	  PPIMAGE_J1
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile	(revision 34735)
@@ -1,7 +1,16 @@
-SOURCE=PSDC-940-005
+SOURCE  = PSDC-940-005
+
+FIGURES = figures/exposure_ota.eps \
+	figures/ext_theta.eps \
+	figures/ipp_workflow.eps
 
 RM=/bin/rm -f
 
-all:
+figures/%.eps: figures/%.fig
+	fig2dev -L eps $< $@
+
+all: figures
+	latex $(SOURCE).tex
+	bibtex $(SOURCE)
 	latex $(SOURCE).tex
 	latex $(SOURCE).tex
@@ -12,4 +21,7 @@
 	@echo 
 
+figures: $(FIGURES)
+
 clean:
-	$(RM) *.aux *.dvi *.out *.pdf *.toc *.log *~
+	$(RM) *.aux *.dvi *.out *.pdf *.toc *.log *~ *.blg *.bbl
+	$(RM) $(FIGURES)
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/PSDC-940-005.tex
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/PSDC-940-005.tex	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/PSDC-940-005.tex	(revision 34735)
@@ -2,9 +2,23 @@
 \documentclass[panstarrs,spec]{panstarrs}
 \usepackage{nonfloat}
-
-\newcommand{\sccomment}[1]{%
-  \textcolor{green}{SC: #1}}
+\usepackage{caption}
+
+\usepackage{etoolbox}
+\patchcmd{\thebibliography}{\chapter*}{\subsection*}{}{}
+
 \newcommand{\outformatversion}{%
   \texttt{PS1\_DV3}}
+
+\newcommand{\commentFrom}[4]{%
+  \mbox{ }\\\null\hfill\begin{tabular}{|p{4in}}
+    \hline
+    \emph{Comment from {#1} (#2)}: {#3}\\
+    \hline
+    Answer: {#4}\\
+    \hline
+  \end{tabular}}
+
+\newcommand{\commentFromSC}[3]{%
+  \commentFrom{SC}{#1}{#2}{#3}}
 
 % basic document variables
@@ -12,5 +26,5 @@
 \subtitle{Pan-STARRS IPP-MOPS ICD for PS-1}
 \shorttitle{IPP-MOPS ICD}
-\author{Eugene Magnier, Larry Denneau, Jr., Robert Jedicke}
+\author{\parbox{3in}{Serge Chastel; Larry Denneau, Jr.; Denver Green; Robert Jedicke; Eugene Magnier}}
 \audience{Pan-STARRS PMO}
 \group{Pan-STARRS IPP \& MOPS}
@@ -26,14 +40,20 @@
 \RevisionsStart
 % version  Date            Description
-03 & 2012 Oct 04 & \texttt{PS1\_DV3}: Fitted trails, new parameters\\ 
-\hline
-02 & 2011 Apr 19 & Synchronization with "ICD Lite" wiki page \\ 
-\hline
-01 & 2010 Oct 27 & New CMF Parameters \\ 
-\hline
-00 & 2006 Mar 01 & Initial version \\ \hline
+04 & 2012 Nov 20  & Modifications integrating DG comments/questions \\ 
+\hline
+03 & 2012 Oct 04  & \texttt{PS1\_DV3}: Fitted trails, new parameters\\ 
+\hline
+02 & 2011 Apr 19  & Synchronization with "ICD Lite" wiki page \\ 
+\hline
+01 & 2010 Oct 27  & New CMF Parameters \\ 
+\hline
+00 & 2006 Mar 01  & Initial version \\ 
+\hline
 \RevisionsEnd
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+\bibliographystyle{amsplain}
+\bibliography{icd}
 
 \DocumentsInternal
@@ -116,4 +136,24 @@
 \DocumentsEnd
 
+\subsection{Acronyms}
+
+\begin{table}
+  \small
+  \caption{Acronyms used in this document\label{table-acronyms}}
+  \begin{tabular}{ll}
+    \hline
+    {\bf Acronym}            & {\bf Definition} \\
+    \hline
+    ADU & Analog to Digital Units (counts in an image) \\
+    ICRS  & International Celestial Reference System \\
+    IPP   & Pan-STARRS Image Processing Pipeline \\
+    FPA   & Focal Plane Array \\
+    MOPS  & Pan-STARRS Moving Object Processing System \\
+    MPC   & Center for Astrophysics Minor Planet Center \\
+    TTI   & Transient-Time Interval (about 60 minutes) \\
+    \hline
+  \end{tabular}
+\end{table}
+
 \section{Interface Overview}
 
@@ -144,10 +184,10 @@
 
 This document discusses the software interface between IPP and MOPS.
-IPP must send transient detection descriptions to the MOPS; MOPS
-must be able to query the IPP regarding whether a particular (RA,
-Dec) pair could have been detected in a particular focal plane array (FPA).  This document
-defines the data to be transferred between IPP and MOPS and the
-mechanisms to be used for that interchange.  These interfaces are
-identified as \#005 in Figure~\ref{fig:overview}.  The Interfaces
+IPP must send transient detection descriptions to the MOPS; MOPS must
+be able to query the IPP regarding whether a particular (RA, Dec) pair
+could have been detected in a particular focal plane array (FPA).
+This document defines the data to be transferred between IPP and MOPS
+and the mechanisms to be used for that interchange.  These interfaces
+are identified as \#005 in Figure~\ref{fig:overview}.  The Interfaces
 addressed by this document are marked in the table.
 
@@ -235,5 +275,9 @@
 Though efforts have been made to avoid this from occurring, where
 header keyword names are longer than the usual 8 character maximum,
-the HIERARCH convention will be used.
+the HIERARCH convention will be used (see the NASA webpages:
+\htmladdnormallink{Registered FITS
+  Convention}{http://fits.gsfc.nasa.gov/registry/hierarch_keyword.html}
+and \htmladdnormallink{4.12.4 HIERARCH Convention for Extended Keyword
+  Names}{http://heasarc.nasa.gov/docs/software/fitsio/c/f_user/node28.html}).
 
 \subsection{IPP-MOPS Exchange}
@@ -241,8 +285,10 @@
 MOPS requires from the IPP a stream of transient detections and their
 FPA metadata obtained from processing of difference images acquired by
-the PS-1 camera.  IPP is additionally required by MOPS to be able to
-indicate whether a set of detections (with RA, Dec, flux, length,
-orientation, etc.) on a previously acquired FPA was detectable by the
-PS-1 telescope.
+the PS-1 camera. 
+
+IPP is additionally required by MOPS to be able to indicate whether a
+set of detections (with RA, Dec, flux, length, orientation, etc.) on a
+previously acquired FPA was detectable by the PS-1 telescope. This
+functionality is provided through the detectability server.
 
 \subsubsection{Conventions}
@@ -305,8 +351,9 @@
 
 \begin{itemize}
-\item{EXTNAME} - Giving a unique name for the metadata table. Such a
-  name shall contain only the characters a-z, and ``\_''.
-\item{CMFVERSION} - A string specifying the version of the table
-  description file for this table.
+\item{EXTNAME} - A \emph{string} giving a unique name for the metadata
+  table. Such a name shall contain only the characters a-z, A-Z, and
+  ``\_''.
+\item{CMFVERSION} - A \emph{string} specifying the version of the
+  table description file for this table.
 \end{itemize}
 
@@ -389,259 +436,348 @@
 exposure.
 
-In addition to the required BINTABLE extension header keywords
-described above, the FITS header shall include the keywords shown in
-table \ref{trans-keywords}.  The subsequent FITS table, with EXTNAME
-of \code{MOPS_TRANSIENT_DETECTIONS}, shall include columns whose
-definitions are listed in table \ref{trans-table}.
-
 {\centering%
-  \tabcaption{IPP-MOPS Transient Detection Keywords\label{trans-keywords}}
-  \begin{longtable}{|lcp{0.5in}p{3in}|}
-    \hline \hline {\bf FITS Keyword}
-    & \parbox{0.5in}{\textbf{Version}}
-    & {\bf Precision} & {\bf Description}\\
-    \hline \hline
-    \multicolumn{4}{|l|}{\null\hspace{10mm}\textbf{Version Information}}\\
-    \hline
-    SWSOURCE & 1+ & string & source of software (e.g., "60eb6cdc-a59c-4636-a4e0-dba66a9721fd")\\
-    \hline
-    SWVERSN & 1+ & string & version of software (e.g., "trunk/ppMops@24658")\\
-    \hline
-    HIERARCH\_CMFVERSION & 2+ & char(7) & PS1\_DV1 or PS1\_DV2 or PS1\_DV3 \\
-    \hline
-    \multicolumn{4}{|l|}{\null\hspace{10mm}\textbf{Provenance Information}}\\
-    \hline
-    EXP\_NAME & 1+ & string & Exposure name (e.g., "o1234g5678")\\
-    \hline
-    EXP\_ID & 1+ & S64 & Exposure identifier \\
-    \hline
-    CHIP\_ID & 1+ & S64 & Chip stage identifier \\
-    \hline
-    CAM\_ID & 1+ & S64 & Camera stage identifier \\
-    \hline
-    FAKE\_ID & 1+ & S64 & Fake stage identifier \\
-    \hline
-    WARP\_ID  & 1+ & S64 & Warp stage identifier \\
-    \hline
-    DIFF\_ID & 1+ & S64 & Diff stage \\
-    \hline
-    DIFF\_POS & 1+ & boolean & Sense of subtraction; T for forward, F for backward\\
-    \hline
-    \multicolumn{4}{|l|}{\null\hspace{10mm}\textbf{Exposure Details}}\\
-    \hline MJD-OBS & 0+
-    & F64 & midpoint time of the exposure as a MJD and day fraction \\
-    \hline
-    RA & 0+
-    & {\tiny HH:MM:SS.SSS} & field center RA at exposure midpoint, string \\
-    \hline
-    DEC & 0+ &
-    {\tiny sDD:MM:SS}& (s is + or -) field center declination at exposure midpoint, string \\
-    \hline
-    EXPTIME & 0+
-    & F64 & exposure time in seconds \\
-    \hline
-    ROTANGLE & 0+
-    & F64 & image rotation of the y-axis in degrees, from local N toward E \\
-    \hline
-    FILTER & 0+ & char(3) & effective filter used for the exposure,
-    one of g, r, i, z, y, B, V, w
-    appended with '.00000'\\
-    \hline
-    AIRMASS & 0+ & F64
-    & airmass at exposure midpoint \\
-    \hline
-    OBSCODE & 0+ & char(5) & MPC three-character observatory code \\
-    \hline
-    TEL\_ALT & 0+ & F64 & telescope altitude at exposure midpoint, in degrees \\
-    \hline
-    TEL\_AZ & 0+ & F64 & telescope azimuth at exposure midpoint, in degrees \\
-    \hline
-    SEEING & 1+ & F32 & Measured seeing at diff stage, arcsec \\
-    \hline
-    MAGZP & 1+ & F32 & Magnitude zero point \\
-    \hline
-    MAGZPERR & 1+ & F32 & Error in magnitude zero point \\
-    \hline
-    ASTRORMS & 1+ & F32 & RMS of astrometric fit, arcsec \\
-    \hline
-    COMMENT & 3+ & String & Comment associated to the exposure\\
-    \hline
-    OBS\_MODE & 3+ & String & Observation mode (e.g. MD, 3PI...)\\
-    \hline
-    DIFFTYPE & 3+ & String & Difference type: WW (Warp-Warp Difference), WS (Warp-Stack Difference)\\
-    \hline
-    SKY  & 3+ & F64 & Exposure average sky background \\
-    \hline
-    SHUTOUTC & 3+ & String & Camera exposure shutter open (UTC) \\
-    \hline
+  \tabcaption{IPP-MOPS Data Types Definition\label{table-datatypes}}
+  \begin{longtable}{|cp{5in}|}
+    \hline
+    \textbf{Alias} & \textbf{Description} \\
+    \texttt{bool} & (Not a FITS type) An enumerated type defining a Boolean
+    value, either \texttt{true} or \texttt{false}\\
+    \texttt{char($n$)} & (Not a FITS type) A sequence of exactly $n$ bytes that
+    can be interpreted
+    as a sequence of ASCII characters\\
+    \texttt{HH:MM:SS.sss} & (Not a FITS type) a \texttt{char(12)} encoding
+    a time or an angle: (1) the hours \texttt{HH} are encoded with two
+    decimal figures; (2) a separator \texttt{:} between the hours and
+    the minutes; (3) the minutes \texttt{MM} are encoded with two
+    decimal figures; (4) a separator \texttt{:} between the minutes
+    and the seconds; (5) the seconds \texttt{SS} are encoded with two
+    decimal figures; (6) a separator \texttt{.} between the seconds
+    and the milli(arc)seconds; (7)
+    the milli(arc)seconds \texttt{ss} are encoded with three decimal figures; \\
+    \texttt{sDD:MM:SS} & (Not a FITS type) a \texttt{char(9)} encoding an
+    angle. (1) \texttt{s} is either the \texttt{+} or \texttt{-} sign;
+    (2) \texttt{DD} is the number of degrees encoded with two decimal
+    figures; (3) a separator \texttt{:} between the degrees and the
+    minutes; (4) the minutes \texttt{MM} are encoded with two decimal
+    figures; (5) a separator \texttt{:} between the minutes and the
+    seconds; (6) the
+    seconds \texttt{SS} are encoded with two decimal figures;\\
+    \texttt{enum} & (Not a FITS type) a \texttt{string} having a fixed number of
+    different values. The explicit set of values shall be expressed in
+    this ICD.\\
+    \texttt{F32} & (FITS type) IEEE 32-bit single precision floating point real numbers \\
+    \texttt{F64} & (FITS type) IEEE 64-bit double precision floating point real numbers \\
+    \texttt{S16} & (FITS type) 16-bit signed integer \\
+    \texttt{S32} & (FITS type) 32-bit signed integer \\
+    \texttt{S64} & (FITS type) 64-bit signed integer \\
+    \texttt{string} & (Not a FITS type) Sequence of bytes of arbitrary length 
+    usually interpreted as a sequence of ASCII characters \\
+    \texttt{U16} & (FITS type) 16-bit unsigned integer \\
+    \texttt{U32} & (FITS type) 32-bit unsigned integer \\
     \hline
   \end{longtable}
 }
 
-{\centering
-  \tabcaption{IPP-MOPS Transient Detection Table Columns\label{trans-table}}
-  \begin{longtable}{|lclp{3.5in}|}
+In addition to the required BINTABLE extension header keywords
+described above (TODO: Where? What?), the FITS header shall include the
+keywords shown in tables relative to versioning
+\ref{table-keywords-versioning}, data provenance
+\ref{table-keywords-provenance}, and exposure
+\ref{table-keywords-exposure}. The subsequent FITS table, with EXTNAME
+of \code{MOPS_TRANSIENT_DETECTIONS}, shall include columns whose
+definitions are listed in table \ref{table-detections} and, when trail
+fitting has been succesfully performed, \ref{table-detections-ext}.
+
+\begin{center}
+  \begin{longtable}{|lcp{0.5in}p{3in}|}
+    \caption{IPP-MOPS Transient Detection Keywords:\\ Version Information}\label{table-keywords-versioning}\\
+    \hline\hline
+    \multicolumn{4}{|l|}{\null\hspace*{1in}\textbf{Version Information}}\\
+    \hline\hline
+    {\bf FITS Keyword}
+    & \parbox{0.5in}{\textbf{Version}}
+    & {\bf Precision}
+    & {\bf Description} \\
+    \hline
+    SWSOURCE & 1+ & \texttt{string} & source of software (e.g., "60eb6cdc-a59c-4636-a4e0-dba66a9721fd") \\
+    \hline
+    SWVERSN & 1+ & \texttt{string} & version of software (e.g., "trunk/ppMops@24658") \\
+    \hline
+    HIERARCH CMFVERSION & 2+ & \texttt{enum} & \texttt{PS1\_DV3} \\
+    \hline\hline
+  \end{longtable}
+\end{center}
+
+\begin{center}
+  \begin{longtable}{|lcp{0.5in}p{3in}|}
+    \caption{IPP-MOPS Transient Detection Keywords:\\ Provenance Information}\label{table-keywords-provenance}\\
+    \hline\hline
+    \multicolumn{4}{|l|}{\null\hspace{10mm}\textbf{Provenance Information}}\\
     \hline \hline
-    {\bf Column} & \textbf{Version} & {\bf Precision} & {\bf Description} \\
-    \hline 
-    RA & 1+ & F64 & detection center coordinates in degrees\\
-    \hline
-    RA\_ERR & 1+ & F64 & error in the detection center, in degrees \\
-    \hline
-    DEC & 1+  & F64 & detection center coordinates in degrees \\
-    \hline
-    DEC\_ERR & 1+ & F64 & error in the detection center, in degrees \\
-    \hline
-    MAG & 1+ & F32 & Magnitude \\
-    \hline
-    MAG\_ERR & 1+ & F32 & Magnitude error \\
-    \hline
-    PSF\_CHI2 & 1+ & F32 & $\chi^2$ of PSF fit \\
-    \hline
-    PSF\_DOF & 1+ & S32 & Degrees of freedom of PSF fit \\
-    \hline
-    CR\_SIGNIFICANCE & 1+ & F32 & Significance of Cosmic Ray \\
-    \hline
-    EXT\_SIGNIFICANCE & 1+ & F32 & Significance of extendedness \\
-    \hline
-    PSF\_MAJOR & 1+ & F32 & PSF major axis (pixels) \\
-    \hline
-    PSF\_MINOR & 1+ & F32 & PSF minor axis (pixels) \\
-    \hline
-    PSF\_THETA & 1+ & F32 & PSF position angle (deg on chip) \\
-    \hline
-    PSF\_QUALITY & 1+ & F32 & PSF quality factor \\
-    \hline
-    PSF\_NPIX & 1+ & S32 & Number of pixels in PSF \\
-    \hline
-    MOMENTS\_XX & 1+ & F32 & xx moment \\
-    \hline
-    MOMENTS\_XY & 1+ & F32 & xy moment \\
-    \hline
-    MOMENTS\_YY & 1+ & F32 & yy moment \\
-    \hline
-    N\_POS & 1+ & S32 & Number of positive pixels \\
-    \hline
-    F\_POS & 1+ & F32 & Fraction of positive pixels \\
-    \hline
-    RATIO\_BAD & 1+ & F32 & Ratio of positive pixels to negative \\
-    \hline
-    RATIO\_MASK & 1+ & F32 & Ratio of positive pixels to masked \\
-    \hline
-    RATIO\_ALL & 1+ & F32 & Ratio of positive pixels to all \\
-    \hline
-    FLAGS & 1+ & U32 & Detection bit flags\footnote{See \htmladdnormallink{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS}{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS} for the meaning of each bit}\\
-    \hline
-    DIFF\_SKYFILE\_ID & 1+ & S64 & Identifier for diff skyfile. A
-    diff\_id (for Warp-Warp difference) or a stack\_id
-    (for Warp-Stack difference) \\
-    \hline
-    IPP\_IDET & 2+ & U32 & IPP detection identifier index \\
-    \hline
-    PSF\_INST\_FLUX & 2+ & F32 & PSF fit instrumental magnitude \\
-    \hline
-    PSF\_INST\_FLUX\_SIG & 2+ & F32 & Sigma of PSF instrumental magnitude \\
-    \hline
-    AP\_MAG & 2+ & F32 & magnitude in standard aperture \\
-    \hline
-    AP\_MAG\_RAW & 2+ & F32 & magnitude in real aperture \\
-    \hline
-    AP\_MAG\_RADIUS & 2+ & F32 & radius used for aperture mags \\
-    \hline
-    AP\_FLUX & 2+ & F32 & instrumental flux in standard aperture \\
-    \hline
-    AP\_FLUX\_SIG & 2+ & F32 & aperture flux error \\
-    \hline
-    PEAK\_FLUX\_AS\_MAG & 2+ & F32 & Peak flux expressed as magnitude \\
-    \hline
-    CAL\_PSF\_MAG & 2+ & F32 & PSF Magnitude using supplied calibration \\
-    \hline
-    CAL\_PSF\_MAG\_SIG & 2+ & F32 & measured scatter of zero point calibration \\
-    \hline
-    SKY & 2+ & F32 & Sky level \\
-    \hline
-    SKY\_SIGMA & 2+ & F32 & Sigma of sky level \\
-    \hline
-    PSF\_QF\_PERFECT & 2+ & F32 & PSF coverage/quality factor (poor) \\
-    \hline
-    MOMENTS\_R1 & 2+ & F32 & first radial moment \\
-    \hline
-    MOMENTS\_RH & 2+ & F32 & half radial moment \\
-    \hline
-    KRON\_FLUX & 2+ & F32 & Kron Flux (in 2.5 R1) \\
-    \hline
-    KRON\_FLUX\_ERR & 2+ & F32 & Kron Flux Error \\
-    \hline
-    KRON\_FLUX\_INNER & 2+ & F32 & Kron Flux (in 1.0 R1) \\
-    \hline
-    KRON\_FLUX\_OUTER & 2+ & F32 & Kron Flux (in 4.0 R1) \\
-    \hline
-    DIFF\_R\_P & 2+ & F32 & distance to positive match source \\
-    \hline
-    DIFF\_SN\_P & 2+ & F32 & signal-to-noise of pos match src \\
-    \hline
-    DIFF\_R\_M & 2+ & F32 & distance to negative match source \\
-    \hline
-    DIFF\_SN\_M & 2+ & F32 & signal-to-noise of neg match src \\
+    {\bf FITS Keyword}
+    & \parbox{0.5in}{\textbf{Version}}
+    & {\bf Precision}
+    & {\bf Description} \\
+    \hline
+    EXP\_NAME & 1+ & \texttt{string} & Exposure name (e.g., "o1234g5678")\\
+    \hline
+    EXP\_ID & 1+ & \texttt{S64} & Exposure identifier \\
+    \hline
+    CHIP\_ID & 1+ & \texttt{S64} & Chip stage identifier \\
+    \hline
+    CAM\_ID & 1+ & \texttt{S64} & Camera stage identifier \\
+    \hline
+    FAKE\_ID & 1+ & \texttt{S64} & Fake stage identifier \\
+    \hline
+    WARP\_ID  & 1+ & \texttt{S64} & Warp stage identifier \\
+    \hline
+    DIFF\_ID & 1+ & \texttt{S64} & Diff stage \\
+    \hline
+    DIFF\_POS & 1+ & \texttt{bool} & Sense of subtraction; \texttt{true} for forward, 
+    \texttt{false} for backward\\
+    \hline
+  \end{longtable}
+\end{center}
+  
+\begin{center}
+  \begin{longtable}{|lcp{0.5in}p{3in}c|}
+    \caption{IPP-MOPS Transient Detection Keywords:\\ Exposure Details}\label{table-keywords-exposure}\\
+    \hline \hline
+    \multicolumn{5}{|l|}{\null\hspace{10mm}\textbf{Exposure Details}}\\
+    \hline \hline {\bf FITS Keyword}
+    & \parbox{0.5in}{\textbf{Version}} & {\bf Precision} & {\bf
+      Description}
+    & \textbf{Units}\\
+    \hline MJD-OBS & 0+ & \texttt{F64} & midpoint time of the exposure
+    as a MJD and day fraction
+    & N/A\\
+    \hline RA & 0+ & {\tiny \texttt{HH:MM:SS.SSS}}
+    & Field center RA at exposure midpoint & N/A \\
+    \hline DEC & 0+ & {\tiny \texttt{sDD:MM:SS}} &
+    (s is + or -) Field center declination at exposure midpoint & N/A \\
+    \hline EXPTIME & 0+ & \texttt{F64}
+    & Exposure time & seconds \\
+    \hline ROTANGLE & 0+ & \texttt{F64}
+    & Image rotation of the y-axis from local N toward E & degrees \\
+    \hline FILTER & 0+ & \texttt{char(7)} & Effective filter used for
+    the exposure, one of \texttt{g}, \texttt{r}, \texttt{i},
+    \texttt{z}, \texttt{y}, \texttt{B},
+    \texttt{V}, \texttt{w} appended with '.00000' & N/A \\
+    \hline AIRMASS & 0+ & \texttt{F64}
+    & Airmass at exposure midpoint & N/A\\
+    \hline OBSCODE & 0+ & char(5) &
+    MPC 3-character observatory code (F51 for PS1) & N/A \\
+    \hline TEL\_ALT & 0+ & \texttt{F64} &
+    Telescope altitude at exposure midpoint & degrees \\
+    \hline TEL\_AZ & 0+ & \texttt{F64}
+    & Telescope azimuth at exposure midpoint & degrees \\
+    \hline SEEING & 1+ & \texttt{F32} &
+    Measured seeing at diff stage & arcsec \\
+    \hline MAGZP & 1+ & \texttt{F32} &
+    Magnitude zero point & N/A \\
+    \hline MAGZPERR & 1+ & \texttt{F32} &
+    Error in magnitude zero point & N/A \\
+    \hline ASTRORMS & 1+ & \texttt{F32} &
+    RMS of astrometric fit & arcsec \\
+    \hline CMMTOBS & 3+ & \texttt{string} &
+    Comment associated to the exposure & N/A\\
+    \hline OBS\_MODE & 3+ & \texttt{enum} & Observation modes list:
+    3PI, CNP, ESS, M31, MD, MSS, OSS, PI, STD (Note: The exposures
+    having the following PS1 observation modes are not used by MOPS:
+    CAL, PR201108, SAS2, SS, STS, STS2A, STS2B) & N/A\\
+    \hline DIFFTYPE & 3+ & \texttt{enum} &
+    Difference type: \texttt{WW} (Warp-Warp Difference), \texttt{WS} (Warp-Stack Difference) & N/A\\
+    \hline SKY & 3+ & \texttt{F64} &
+    Exposure average sky background & counts/pixel \\
+    \hline SHUTOUTC & 3+ & \texttt{string} &
+    Camera exposure shutter open (UTC) & N/A \\
+    \hline \hline
+  \end{longtable}
+\end{center}
+
+\begin{center}
+  \begin{longtable}{|lclp{3.5in}c|}
+    \caption{IPP-MOPS Transient Detection Table Columns:\\ Detection Details}\label{table-detections}\\
+    \hline \hline
+    \multicolumn{5}{|l|}{\null\hspace{10mm}\textbf{Detection Details}}\\
+    \hline \hline
+    {\bf Column} & \textbf{Version} & {\bf Precision} & {\bf Description} & \textbf{Units}\\
+    \hline
+    RA & 1+ & F64 & Detection center coordinates & degrees\\
+    \hline
+    RA\_ERR & 1+ & F64 & Error in the detection center & degrees \\
+    \hline
+    DEC & 1+ & F64 & Detection center coordinates & degrees \\
+    \hline
+    DEC\_ERR & 1+ & F64 & Error in the detection center & degrees \\
+    \hline
+    MAG & 1+ & F32 & Filter magnitude & N/A \\
+    \hline
+    MAG\_ERR & 1+ & F32 & Filter magnitude error & N/A  \\
+    \hline
+    PSF\_CHI2 & 1+ & F32 & $\chi^2$ of PSF fit & N/A \\
+    \hline
+    PSF\_DOF & 1+ & S32 & Degrees of freedom of PSF fit & N/A  \\
+    \hline
+    CR\_SIGNIFICANCE & 1+ & F32 & Significance of cosmic ray (source: \emph{src/psphot/psphotSourceSize.c}) & N/A  \\
+    \hline
+    EXT\_SIGNIFICANCE & 1+ & F32 & Significance of extendedness (source: \emph{src/psphot/psphotSourceSize.c}) & N/A  \\
+    \hline
+    PSF\_MAJOR & 1+ & F32 & PSF major axis & pixels \\
+    \hline
+    PSF\_MINOR & 1+ & F32 & PSF minor axis & pixels \\
+    \hline
+    PSF\_THETA & 1+ & F32 & PSF position angle on chip & degrees \\
+    \hline
+    PSF\_QUALITY & 1+ & F32 & PSF quality factor & N/A \\
+    \hline
+    PSF\_NPIX & 1+ & S32 & Number of pixels in PSF & N/A \\
+    \hline
+    MOMENTS\_XX & 1+ & F32 & xx moment & N/A \\
+    \hline
+    MOMENTS\_XY & 1+ & F32 & xy moment & N/A \\
+    \hline
+    MOMENTS\_YY & 1+ & F32 & yy moment & N/A \\
+    \hline
+    N\_POS & 1+ & S32 & Number of positive pixels & N/A \\
+    \hline
+    F\_POS & 1+ & F32 & Fraction of positive pixels & N/A \\
+    \hline
+    RATIO\_BAD & 1+ & F32 & Ratio of positive pixels to negative & N/A \\
+    \hline
+    RATIO\_MASK & 1+ & F32 & Ratio of positive pixels to masked & N/A \\
+    \hline
+    RATIO\_ALL & 1+ & F32 & Ratio of positive pixels to all & N/A \\
+    \hline
+    FLAGS & 1+ & U32 & Detection bit flags\footnote{See \htmladdnormallink{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS}{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS} for the meaning of each bit}. The PM\_SOURCE\_MODE\_EXTENDED\_FIT flag (at position 0x00800000) is set when the Trail Fitting is attempted. It does not mean that the Trail Fitting is successful. \\
+    \hline DIFF\_SKYFILE\_ID & 1+ & S64 & Identifier for diff
+    skyfile. Either a diff\_id (for Warp-Warp difference) or a
+    stack\_id
+    (for Warp-Stack difference) & N/A \\
+    \hline
+    IPP\_IDET & 2+ & U32 & IPP detection identifier index & N/A \\
+    \hline
+    PSF\_INST\_FLUX & 2+ & F32 & PSF fit instrumental magnitude & N/A \\
+    \hline
+    PSF\_INST\_FLUX\_SIG & 2+ & F32 & Sigma of PSF instrumental magnitude & N/A \\
+    \hline
+    AP\_MAG & 2+ & F32 & magnitude in standard aperture (i.e. 25 pixels radius) & N/A \\
+    \hline
+    AP\_MAG\_RAW & 2+ & F32 & magnitude in real aperture & N/A \\
+    \hline
+    AP\_MAG\_RADIUS & 2+ & F32 & radius used for aperture mags & pixels \\
+    \hline
+    AP\_FLUX & 2+ & F32 & instrumental flux in standard aperture & ADU \\
+    \hline
+    AP\_FLUX\_SIG & 2+ & F32 & aperture flux error & N/A \\
+    \hline
+    PEAK\_FLUX\_AS\_MAG & 2+ & F32 & Peak flux expressed as magnitude & N/A \\
+    \hline
+    CAL\_PSF\_MAG & 2+ & F32 & PSF Magnitude using supplied calibration & N/A \\
+    \hline
+    CAL\_PSF\_MAG\_SIG & 2+ & F32 & Measured standard-deviation of zero point calibration & N/A \\
+    \hline
+    SKY & 2+ & F32 & Sky level & counts/pixel \\
+    \hline
+    SKY\_SIGMA & 2+ & F32 & Sigma of sky level  & counts/pixel\\
+    \hline PSF\_QF\_PERFECT & 2+ & F32 & PSF coverage/quality factor
+    (poor): PSF value weighted by unmasked pixels
+    (source: psmodules/src/objects/pmSourcePhotometry.c) & N/A \\
+    \hline
+    MOMENTS\_R1 & 2+ & F32 & first radial moment & N/A \\
+    \hline
+    MOMENTS\_RH & 2+ & F32 & half radial moment & N/A \\
+    \hline
+    KRON\_FLUX & 2+ & F32 & Kron Flux (that is, flux in 2.5 $\times$ first radial moment) & N/A \\
+    \hline
+    KRON\_FLUX\_ERR & 2+ & F32 & Kron Flux Error & N/A \\
+    \hline
+    KRON\_FLUX\_INNER & 2+ & F32 & Inner Kron Flux (that is, flux in 1.0 $\times$ first radial moment) & N/A \\
+    \hline
+    KRON\_FLUX\_OUTER & 2+ & F32 & Outer Kron Flux (that is, flux in 4.0 $\times$ first radial moment) & N/A \\
+    \hline
+    DIFF\_R\_P & 2+ & F32 & distance from detection to positive matching source & pixels \\
+    \hline
+    DIFF\_SN\_P & 2+ & F32 & signal-to-noise of pos match src & N/A \\
+    \hline
+    DIFF\_R\_M & 2+ & F32 & distance from detectionto negative match source & pixels \\
+    \hline
+    DIFF\_SN\_M & 2+ & F32 & signal-to-noise of neg match src & N/A \\
     \hline
     FLAGS2 & 2+ & U32 & psphot analysis flags (group 2)\footnote{See \htmladdnormallink{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS}{http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PSPSFlags\#StackDetectionFull.infoFlagsFLAGS232FLAGS} for the meaning of each bit}\\
     \hline
-    N\_FRAMES & 2+ & U16 & Number of frames overlapping source center \\
+    N\_FRAMES & 2+ & U16 & Number of exposures overlapping source center \\
     \hline
     PADDING & 2+ & S16 & padding \\
-    \hline
-    \multicolumn{4}{|c|}{\textbf{Extended (trail fitting) parameters}}\\
-    \multicolumn{4}{|c|}{Values like \texttt{NaN} mean that the extended parameters are undefined for the detection}\\
-    \hline
-    X\_EXT & 2+ & F32 & Extended model X coordinate \\
-    \hline
-    Y\_EXT & 2+ & F32 & Extended model Y coordinate \\
-    \hline
-    X\_EXT\_SIG & 2+ & F32 & Sigma in extended model X coordinate \\
-    \hline
-    Y\_EXT\_SIG & 2+ & F32 & Sigma in extended model Y coordinate \\
-    \hline
-    EXT\_INST\_MAG & 2+ & F32 & Extended fit instrumental magnitude \\
-    \hline
-    EXT\_INST\_SIG\_MAG & 2+ & F32 & Sigma of extended fit instrumental magnitude \\
-    \hline
-    NPARAMS & 2+ & F32 & Number of model parameters \\
-    \hline
-    EXT\_WIDTH\_MAJ & 2+ & F32 & EXT width (major axis), length for trail \\
-    \hline
-    EXT\_WIDTH\_MIN & 2+ & F32 & EXT width (minor axis), sigma for trail \\
-    \hline
-    EXT\_THETA & 2+ & F32 & EXT orientation angle\\
-    \hline
-    EXT\_WIDTH\_MAJ\_ERR & 2+ & F32 & EXT width error (major axis)\\
-    \hline
-    EXT\_WIDTH\_MIN\_ERR & 2+ & F32 & EXT width error (minor axis)\\
-    \hline
-    EXT\_THETA\_ERR & 2+ & F32 & EXT orientation angle (error)\\
-    \hline
-    RA\_EXT & 3+ & F32 & Fitted centroid RA \\
-    \hline
-    RA\_EXT\_SIGMA & 3+ & F32 & Fitted RA sigma \\
-    \hline
-    DEC\_EXT & 3+ & F32 & Fitted centroid DEC \\
-    \hline
-    DEC\_EXT\_SIGMA & 3+ & F32 & Fitted DEC sigma \\
-    \hline
-    POSANG\_EXT & 3+ & F32 & Fitted position angle \\
-    \hline
-    PLTSCALE\_EXT & 3+ & F32 & Plate scale at centroid \\
-    \hline
-    EXT\_FLUX & 3+ & F32 & Fitted flux \\
-    \hline
-    EXT\_CAL\_MAG & 3+ & F32 & Calibrated magnitude \\
-    \hline
-    EXT\_MAG\_SIG & 3+ & F32 & Sigma of calibrated magnitude \\
-    \hline
-    EXT\_CHISQ & 3+ & F32 & $\chi^2$ of fit \\
-    \hline
-    EXT\_NDOF & 3+ & S32 & Fit degrees of freedom \\
-    \hline
+    \hline \hline
   \end{longtable}
-}
+\end{center}
+
+\begin{center}
+  \begin{longtable}{|lclp{3.5in}c|}
+    \caption{IPP-MOPS Transient Detection Table Columns:\\ Extended (Trail Fitting) Details}\label{table-detections-ext}\\
+    \hline \hline
+    \multicolumn{5}{|c|}{\textbf{Extended (trail fitting) parameters}}\\
+    \multicolumn{5}{|c|}{Values like \texttt{NaN} mean that the extended parameters are undefined for the detection}\\
+    \hline
+    X\_EXT & 2+ & F32 & 
+    Extended model X coordinate & pixels\\
+    \hline
+    Y\_EXT & 2+ & F32 & 
+    Extended model Y coordinate & pixels \\
+    \hline
+    X\_EXT\_SIG & 2+ & F32 & 
+    Sigma in extended model X coordinate & pixels \\
+    \hline
+    Y\_EXT\_SIG & 2+ & F32 & 
+    Sigma in extended model Y coordinate & pixels \\
+    \hline
+    EXT\_INST\_MAG & 2+ & F32 & 
+    Extended fit instrumental magnitude & N/A \\
+    \hline
+    EXT\_INST\_SIG\_MAG & 2+ & F32 & 
+    Sigma of extended fit instrumental magnitude & N/A \\
+    \hline
+    NPARAMS & 2+ & S32 & 
+    Number of model parameters (see \cite{VerJedDen2012IAAaPwTF}) & N/A \\
+    \hline
+    EXT\_WIDTH\_MAJ & 2+ & F32 & % The name is weird but it's because of normalization
+    Length of trail & pixels \\  % in the IPP: Check if MOPS want to change it
+    \hline
+    EXT\_WIDTH\_MIN & 2+ & F32 &  % The name is weird but it's because of normalization
+    Sigma of trail & pixels \\    % in the IPP: Check if MOPS want to change it
+    \hline
+    EXT\_THETA & 2+ & F32 & EXT orientation angle & radians \\
+    \hline
+    EXT\_WIDTH\_MAJ\_ERR & 2+ & F32 & EXT width error (major axis) & pixels \\
+    \hline
+    EXT\_WIDTH\_MIN\_ERR & 2+ & F32 & EXT width error (minor axis) & pixels \\
+    \hline
+    EXT\_THETA\_ERR & 2+ & F32 & EXT orientation angle (error) & radians \\
+    \hline
+    RA\_EXT & 3+ & F32 & Fitted centroid RA & degrees \\
+    \hline
+    RA\_EXT\_SIGMA & 3+ & F32 & Fitted RA sigma & degrees? \\
+    \hline
+    DEC\_EXT & 3+ & F32 & Fitted centroid DEC & degrees \\
+    \hline
+    DEC\_EXT\_SIGMA & 3+ & F32 & Fitted DEC sigma & degrees? \\
+    \hline
+    POSANG\_EXT & 3+ & F32 & Fitted position angle & degrees \\
+    \hline
+    PLTSCALE\_EXT & 3+ & F32 & Plate scale at centroid & arcsec/pixel \\
+    \hline
+    EXT\_FLUX & 3+ & F32 & Fitted flux & ADU \\
+    \hline
+    EXT\_CAL\_MAG & 3+ & F32 & Calibrated magnitude & N/A \\
+    \hline
+    EXT\_MAG\_SIG & 3+ & F32 & Sigma of calibrated magnitude & N/A \\
+    \hline
+    EXT\_CHISQ & 3+ & F32 & $\chi^2$ of fit & N/A \\
+    \hline
+    EXT\_NDOF & 3+ & S32 & Fit degrees of freedom & N/A \\
+    \hline
+  \end{longtable}
+\end{center}
 
 \subsection{MOPS Detectability Query}
@@ -764,7 +900,654 @@
 
 \pagebreak
+
+\section{Changes}
+
+\subsection{Changes in PS1\_DV3 from PS1\_DV2}
+
+\subsubsection{New Keywords}
+
+\paragraph{Per Exposure (in FITS header)}
+\begin{itemize}
+\item CMMTOBS
+\item OBS\_MODE
+\item DIFFTYPE
+\item SKY
+\item SHUTOUTC
+\end{itemize}
+
+\paragraph{Per Detection (in FITS extension)}
+\begin{itemize}
+\item RA\_EXT
+\item RA\_EXT\_SIGMA
+\item DEC\_EXT
+\item DEC\_EXT\_SIGMA
+\item POSANG\_EXT
+\item PLTSCALE\_EXT
+\item EXT\_FLUX
+\item EXT\_CAL\_MAG
+\item EXT\_MAG\_SIG
+\item EXT\_CHISQ
+\item EXT\_NDOF
+\end{itemize}
+
+\subsubsection{Removed Keywords}
+
+None
+
+\subsubsection{Datatypes}
+\begin{itemize}
+\item NPARAMS is now a S32 and no more a F32.
+\end{itemize}
+
+\subsubsection{Known Bugs and Associated Fix}
+
+\begin{itemize}
+\item None
+\end{itemize}
+
+\newpage
+
 \appendix
 
-\section{Appendix}
+\section{The IPP Data Workflow}
+
+The objective of this section is to provide some details about the IPP
+Workflow. It is intentionnally MOPS oriented in the sense that some
+details have been voluntarily omitted.
+
+\begin{minipage}{0.65\linewidth}
+  The IPP receives "exposures" from the telescope. An "exposure" is an
+  image of 60 OTAs (see figure~\ref{fig-exposure-otas}) taken by the
+  GPC1 camera and its associated metadata. All science exposures
+  (which are interesting MOPS) are processed in the IPP according to
+  the following stages.
+
+  The first stage is the CHIP stage. Detrending and objects detections
+  are performed on each OTA at this stage.
+
+  The second stage is the CAMERA stage. Calibration and astrometry are
+  performed on the exposure at this stage.
+
+  The third stage is the WARP stage\footnote{For simplicity and since
+    nothing is performed in this stage, the FAKE stage has been
+    ommitted.}. The image pixels are warped to fit a predefined sky
+  tessellation (it is actually a covering). Cells of the tessellation
+  are called \emph{skycells} and each pixel in a skycell has a size of
+  $0.25" \times 0.25"$. The skycell is oriented so that increasing X
+  (wrt Y) pixel coordinate corresponds to a move toward the West (wrt
+  North).
+
+  The fourth stage is the DIFF stage. The difference between two
+  skycells having the same spatial coordinates but being distant in
+  time (by less than the TTI) is computed. To avoid deconvolution,
+  the image difference can be performed in bothways When the newer
+  image is diffed with the older image, the difference image is called
+  the \emph{positive} image. When the older image is diffed with the
+  newer image, the difference image is called the \emph{negative}
+  image.
+
+  Another stage is executed in parallel of the fourth stage: the STACK
+  stage. Its products (the stacks, that is, "average" observations in
+  a skycell) can be used in the DIFF stage to compute WARP-STACK
+  differences (e.g for MD observations). STACK-WARP are not computed
+  (so far).
+
+  The fifth and last stage is the PPMOPS stage. The exposure is
+  rebuilt from the differences obtained in each skycell of the DIFF
+  stage. For detections falling in areas covered by two or more
+  skycells, the data of the detection being the nearest to a skycell
+  center are taken.
+\end{minipage}\hfill\begin{minipage}{0.3\linewidth}
+  \begin{center}
+    \includegraphics[width=\linewidth]{figures/ipp_workflow.eps}
+    \captionof{figure}{Caption for figure}
+    \label{fig-ipp-workflow}
+  \end{center}
+\end{minipage}
+
+\begin{center}
+  \includegraphics[width=4in]{figures/exposure_ota.eps}
+  \captionof{figure}{Exposure / OTA TODO + Move somewhere else}
+  \label{fig-exposure-otas}
+\end{center}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\newpage
+\section{\texttt{ppMops} Implementation Details}
+\label{sec-ppmops}
+
+\subsection{Source Code}
+\label{sec-ppmops-sourcecode}
+
+The \texttt{ppMops} source code can be found at
+\url{https://svn.pan-starrs.ifa.hawaii.edu/repo/ipp/trunk/ppTranslate}. The
+SVN revision of the analyzed code as well as the corresponding
+software version depends on the version of this document and can be
+found in the History subsection (see subsection
+\ref{sec-ppmops-sourcecodehistory}).
+
+\subsection{Source Code Analysis History}
+\label{sec-ppmops-sourcecodehistory}
+\begin{tabular}{|c|c|c|p{2in}|c|c|}
+  \hline
+  \parbox{.5in}{Doc Version} & Date & Author & Description & SVN Rev. & \parbox{.5in}{Software Version}\\
+  \hline
+  \hline
+  --- & 2012-09-14 & SC & Creation & 34439 & 3\footnotemark{}\\
+  \hline
+\end{tabular}\footnotetext{Modified version 3}
+
+\subsection{Main}
+Source code: \texttt{src/ppMops.c}.
+
+\texttt{ppMops} can be run on the command line independently from the
+IPP framework. It is functionnally made of four parts:
+\begin{enumerate}
+\item Analyzing the command-line arguments (see subsection
+  \ref{sec-implementation-args});
+\item Reading the detections from the input diff files and the exposure
+  parameters (see subsection \ref{sec-implementation-read});
+\item Removing the duplicated detections (see subsection
+  \ref{sec-implementation-merge});
+\item Writing the products (see subsection
+  \ref{sec-implementation-write});
+\end{enumerate}
+
+\subsection{Command-Line Arguments Analysis}
+\label{sec-implementation-args}
+
+Source code: \texttt{src/ppMopsArguments.c}.
+
+\subsubsection{Parameters}
+
+There are only two mandatory arguments:
+\begin{enumerate}
+\item The first argument is a filename. The associated file contains
+  the list of the names of all the diff files that will be used as
+  input. For simplicity, we will identify that list by:
+  \texttt{list\_of\_diffs\_inputs}.
+\item The second argument is the name of the output file. We will call
+  it \texttt{output\_file\_name}.
+\end{enumerate}
+
+The following parameters can be taken from the command line arguments
+options (if they are provided, otherwise they take the default value):
+\begin{itemize}
+\item \texttt{exp\_name}: exposure name (default: NULL);
+\item \texttt{exp\_id}: Exposure identifier (IPP internal; default: 0);
+\item \texttt{chip\_id}: Chip stage identifier (IPP internal; default: 0);
+\item \texttt{cam\_id}: Camera stage identifier (IPP internal; default: 0);
+\item \texttt{fake\_id}: Fake stage identifier (IPP internal; default: 0);
+\item \texttt{warp\_id}: Warp stage identifier (IPP internal; default: 0);
+\item \texttt{diff\_id}: Diff stage identifier (IPP internal; default: 0);
+\item \texttt{inverse}: Inverse subtraction (boolean; default: false);
+\item \texttt{zp}: Magnitude zero point (default: NAN);
+\item \texttt{zp\_error}: Error in magnitude zero point (default: NAN);
+\item \texttt{astrom\_rms}: Astrometric solution RMS (default: NAN);
+\item \texttt{version}: CMF file version (default: 0);
+\end{itemize}
+
+\subsubsection{Parameters Values Validation}
+\begin{itemize}
+\item If the list of input file names is empty, an error is displayed
+  and \texttt{ppMops} exits.
+\item There is no check on the validity of the different parameters
+  (values, files existence...).
+\end{itemize}
+
+\subsection{Reading Detections}
+\label{sec-implementation-read}
+
+Source code: \texttt{src/ppMopsRead.c}.
+
+Each file from the \texttt{list\_of\_diffs\_inputs} is opened. A
+\texttt{ppMopsDetections} object is populated from the data that are
+read from that file. The set (namely a \texttt{psArray}) of all the
+valid \texttt{ppMopsDetections} objects is the product of this part.
+
+The data which are extracted from each file are the following:
+\begin{itemize}
+\item From the header are extracted:
+  \begin{itemize}
+  \item \texttt{diffSkyfileId}: Its value is
+    associated to the keyword \texttt{IMAGEID}. If not present or 0, the
+    program exits with an error.
+  \item The current diff version is derived from the value associated
+    to EXTTYPE. If the \texttt{version} has not already been set, it
+    is set to the value which has just been read. If it was set at
+    some point (either through the command line, or from a previous
+    input), the current diff version value is checked against the
+    \texttt{version}. Different values will produce warning messages.
+  \item \texttt{raBoresight} is given the value associated to
+    \texttt{FPA.RA};
+  \item \texttt{decBoresight} is given the value associated to
+    \texttt{FPA.DEC};
+  \item \texttt{filter} is given the value associated to
+    \texttt{FPA.FILTER};
+  \item \texttt{airmass} is given the value associated to
+    \texttt{AIRMASS};
+  \item \texttt{exptime} is given the value associated to
+    \texttt{EXPTIME};
+  \item \texttt{posangle} is given the value associated to
+    \texttt{FPA.POSANGLE};
+  \item \texttt{alt} is given the value associated to
+    \texttt{FPA.ALT};
+  \item \texttt{az} is given the value associated to
+    \texttt{FPA.AZ};
+  \item \texttt{mjd} is computed from the \texttt{mjdobs} value
+    associated to \texttt{MJD-OBS} by: \[\mathtt{mjd} = \mathtt{mjdobs} +
+    \frac{\mathtt{exptime}}{2*3600*24}\]
+  \item \texttt{seeing} is initialized (note that it is modified in
+    the loop over the valid detections) using
+    $\mathtt{fwhm}_\mathtt{maj}$ (wrt $\mathtt{fwhm}_\mathtt{min}$)
+    associated to the keyword \texttt{FWHM\_MAJ} (wrt
+    \texttt{FWHM\_MIN});
+  \item \texttt{naxis1} is set to the value associated to
+    \texttt{IMNAXIS1}, that is the number of columns of the original
+    image;
+  \item \texttt{naxis2} is set to the value associated to
+    \texttt{IMNAXIS2}, that is the number of rows of the original
+    image;
+  \end{itemize}
+\item From the \texttt{SkyChip.psf} extension:
+  \begin{itemize}
+  \item This extension contains all the detections. One row is
+    associated to each detection.
+  \item A detection is rejected if at least one of the following
+    parameters has an non-finite value: \texttt{x}, \texttt{y},
+    \texttt{ra}, \texttt{dec}, \texttt{mag}, \texttt{magErr},
+    \texttt{xErr}, \texttt{yErr}, \texttt{scale}, \texttt{angle}.
+  \item A detection is rejected if its associated \texttt{flags}
+    matches:
+    {\small
+    \texttt{PM\_SOURCE\_MODE\_FAIL | PM\_SOURCE\_MODE\_BADPSF |
+      PM\_SOURCE\_MODE\_SATURATED | PM\_SOURCE\_MODE\_CR\_LIMIT |
+      PM\_SOURCE\_MODE\_SKY\_FAILURE}}
+  \item \texttt{x} is associated to the \texttt{X\_PSF} keyword;
+  \item \texttt{y} is associated to the \texttt{Y\_PSF} keyword;
+  \item \texttt{ra} is associated to the \texttt{RA\_PSF} keyword. It
+    is converted to radians;
+  \item \texttt{dec} is associated to the \texttt{DEC\_PSF} keyword. It
+    is converted to radians;
+  \item \texttt{mag} is computed from the value associated the
+    \texttt{PSF\_INST\_MAG} keyword, namely:
+    \[
+    \mathtt{mag} = \mathtt{PSF\_INST\_MAG} + \mathtt{zp}
+    \]
+    where \texttt{zp} is defined in the arguments list (see subsection
+    \ref{sec-implementation-args});
+  \item \texttt{magErr} is associated to the
+    \texttt{PSF\_INST\_MAG\_SIG} keyword;
+  \item \texttt{xErr} is associated to the \texttt{X\_PSF\_SIG}
+    keyword;
+  \item \texttt{yErr} is associated to the \texttt{Y\_PSF\_SIG}
+    keyword;
+  \item \texttt{scale} is associated to the \texttt{PLTSCALE}
+    keyword;
+  \item \texttt{angle} is associated to the \texttt{POSANGLE}
+    keyword;
+  \item \texttt{flags} is associated to the \texttt{FLAGS} keyword;
+  \item \texttt{raErr} is defined by: 
+    \[
+    \mathtt{raErr} = \frac{\mathtt{scale}}{3600}
+    \sqrt{\cos^2(\mathtt{angle}) \mathtt{xErr}^2 +
+      \sin^2(\mathtt{angle}) \mathtt{yErr}^2}
+    \]
+  \item \texttt{decErr} is defined by: 
+    \[
+    \mathtt{decErr} = \frac{\mathtt{scale}}{3600}
+    \sqrt{\sin^2(\mathtt{angle}) \mathtt{xErr}^2 +
+      \cos^2(\mathtt{angle}) \mathtt{yErr}^2}
+    \]
+  \end{itemize}
+\item \texttt{seeing} is defined as the product of the mean of
+  $\mathtt{fwhm}_\mathtt{maj}$ and $\mathtt{fwhm}_\mathtt{min}$ by the
+  mean of the \texttt{scale} values for valid detections, that is:
+  \[
+  \mathtt{seeing} = \frac{\mathtt{fwhm}_\mathtt{maj} +
+    \mathtt{fwhm}_\mathtt{min}}{2} \times \frac{\sum_{\mathtt{valid\
+        detections}}(scale)}{\#(\mathtt{valid\ detections})}
+  \]
+\item The number of valid detections is also kept (but not used).
+\item For each row of the \texttt{SkyChip.xfit} extension:
+  \begin{itemize}
+  \item This extension contains only a subset of the detections. Each
+    row contains the index of the current detection which is the value
+    associated to the keyword \texttt{IPP\_IDET};
+  \item Note that detections parameters whose index could not be found
+    in the \texttt{SkyChip.xfit} extension are set to NaN.
+  \item The following columns are extracted \texttt{X\_EXT},
+    \texttt{Y\_EXT}, \texttt{X\_EXT\_SIG}, \texttt{Y\_EXT\_SIG},
+    \texttt{EXT\_INST\_MAG}, \texttt{EXT\_INST\_MAG\_SIG},
+    \texttt{NPARAMS}, \texttt{EXT\_WIDTH\_MAJ}, \texttt{EXT\_WIDTH\_MIN},
+    \texttt{EXT\_THETA}, \texttt{EXT\_WIDTH\_MAJ\_ERR},
+    \texttt{EXT\_WIDTH\_MIN\_ERR}, and \texttt{EXT\_THETA\_ERR}. No check is
+    performed on them at this stage.
+  \end{itemize}
+\end{itemize}
+
+At the end of this stage, all input files have been used to populate a
+collection of sets of detections. Let us call that collection $({\cal
+  D}_{i})_{i \in \{1..n\}}$. Each of those sets contains data read
+from one file and it is important to note that only a few checks have
+been performed on the data (more precisely, only non-masked detections
+which have defined values have been inserted). The following cases can
+therefore happen: (1) Any ${\cal D}_i$ can be "empty", that is, does
+not contain any valdiated detection; (2) Some parameters like
+\texttt{seeing} can have an undefined value (e.g. \texttt{NaN}).
+
+\subsection{Merging Detections}
+\label{sec-implementation-merge}
+
+Source code: \texttt{src/ppMopsMerge.c}.
+
+That part of the code essentially uses a kd-tree implementation to
+compare distances between detections. The collection of sets of
+detections will be called $({\cal D}_{i})_{i \in \{1..n\}}$ (see
+previous section). 
+
+\subsubsection{Checks}
+\label{sec-implementation-merge-checks}
+
+Checks are performed on data that have been extracted from FITS files
+headers. Namely, they are:
+\begin{itemize}
+\item \texttt{raBoresight} constancy across all the detections;
+\item \texttt{decBoresight} constancy across all the detections;
+\item \texttt{filter} constancy across all the detections;
+\item \texttt{airmass} constancy across all the detections;
+\item \texttt{exptime} constancy across all the detections;
+\item \texttt{posangle} constancy across all the detections;
+\item \texttt{alt} constancy across all the detections;
+\item \texttt{az} constancy across all the detections;
+\item \texttt{mjd} constancy across all the detections;
+\end{itemize}
+
+Any inconsistency displays an error and the program exits.
+
+\subsubsection{kd-Tree Merging}
+\label{sec-implementation-merge-kdtree}
+
+All valid detections are inserted into a kd-tree (using the
+\texttt{psTree} implementation). \texttt{ra} and \texttt{dec} are used
+as keys for the nearest neighbor search. An iteration over all valid
+detections is then performed. 
+
+The detection in a 1 arcsec neighborhood around the current valid
+detection which is the closest to the image center is chosen as the
+best candidate for the source. Then, the best of the candidates is
+chosen as the source. All other detections are considered duplicates,
+and marked as invalid, then removed from the detections set to which
+they belong.
+
+Note that \texttt{numGood} which is supposed to give the number of
+valid detections is not updated.
+
+\subsection{Writing Final Product}
+\label{sec-implementation-write}
+
+Source code: \texttt{src/ppMopsWrite.c}.
+
+To resolve any ambiguity, we will note the parameter named
+\texttt{param} which was built for the set of detections ${\cal
+  D}_{i}$ will be denoted by ${\cal D}_{i}(\mathtt{param})$. 
+
+Note that, except for the parameters that have been checked at the
+merge stage (see paragraph~\ref{sec-implementation-merge-checks}),
+there is no guarantee that ${\cal D}_{i}(\mathtt{param}) = {\cal
+  D}_{j}(\mathtt{param})$ when $i \neq j$. There is no guarantee to
+that ${\cal D}_{i}(\mathtt{param})$ is defined (in the mathematical
+sense), e.g. it could be \texttt{NaN}...
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\subsubsection{Exposure Parameters: Header Details}
+\label{sec-implementation-write-header}
+
+The first set of detections among the $({\cal D}_{i})_i$ that contains
+at least one valid detection is chosen. To fix ideas, let us denote
+it by ${\cal D}_{i_0}$. 
+
+The following parameters are written to the product FITS header:
+
+\begin{itemize}
+\item \texttt{SWSOURCE} (Software source): Constructed from the SVN
+  repository value. Generated when compiled.
+\item \texttt{SWVERSN} (Software version): Constructed from the SVN
+  version value. Generated when compiled.
+\item \texttt{EXP\_NAME} (Exposure name): Set by \texttt{exp\_name}
+  argument value;
+\item \texttt{EXP\_ID} (Exposure identifier): Set by \texttt{exp\_id}
+  argument value;
+\item \texttt{CHIP\_ID} (Chip stage identifier): Set by
+  \texttt{chip\_id} argument value;
+\item \texttt{CAM\_ID} (Cam stage identifier): Set by \texttt{cam\_id}
+  argument value;
+\item \texttt{FAKE\_ID} (Fake stage identifier): Set by
+  \texttt{fake\_id} argument value;
+\item \texttt{WARP\_ID} (Warp stage identifier): Set by
+  \texttt{warp\_id} argument value;
+\item \texttt{DIFF\_ID} (Diff stage identifier): Set by
+  \texttt{diff\_id} argument value;
+\item \texttt{DIFF\_POS} (Positive subtraction): Set by
+  \texttt{inverse} argument value;
+\item \texttt{MJD-OBS} (MJD of exposure midpoint): Set by ${\cal
+    D}_{i_0}(\mathtt{mjd})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{RA} (Right Ascension of boresight): Set by ${\cal
+    D}_{i_0}(\mathtt{raBoresight})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{DEC} (Declination of boresight): Set by ${\cal
+    D}_{i_0}(\mathtt{decBoresight})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{TEL\_ALT} (Telescope altitude): Set by ${\cal
+    D}_{i_0}(\mathtt{alt})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{TEL\_AZ} (Telescope azimuth): Set by ${\cal
+    D}_{i_0}(\mathtt{az})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{EXPTIME} (Exposure time (sec)): Set by ${\cal
+    D}_{i_0}(\mathtt{exptime})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{ROTANGLE} (Rotator position angle): Set by ${\cal
+    D}_{i_0}(\mathtt{rotangle})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{FILTER} (Filter name): Set by ${\cal
+    D}_{i_0}(\mathtt{filter})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{AIRMASS} (Airmass of exposure): Set by ${\cal
+    D}_{i_0}(\mathtt{airmass})$. Uniqueness guaranteed by
+  \ref{sec-implementation-merge-checks};
+\item \texttt{SEEING} (Mean seeing): Set by the median of defined (not
+  \texttt{NaN}, not \texttt{Infinity}) of $({\cal
+    D}_{i}(\mathtt{seeing}))_i$;
+  \commentFromSC{2012-09-18}{Check if it is what we
+    really expect. Take the example of 3 set of detections for which
+    \texttt{seeing} is defined, assuming the first one contains 1000
+    detections with a \texttt{seeing} of 1.0, the second one contains
+    10 detections with a \texttt{seeing} of 2.0, the third one 10
+    detections with a \texttt{seeing} of 3.0. Do we really want the
+    global \texttt{seeing} value to be 2.0?}{}
+\item \texttt{OBSCODE} (IAU Observatory code): Hard-coded value
+  defined in \texttt{src/ppMops.h} (value \texttt{F51});
+  \commentFromSC{2012-09-18}{I'm surprised that it's defined locally
+    and not in some high-level project header file}{}
+\item \texttt{MAGZP} (Magnitude zero point): Set by \texttt{zp}
+  argument value;
+\item \texttt{MAGZPERR} (Error in magnitude zero point): Set by
+  \texttt{zp\_error} argument value;
+\item \texttt{ASTRORMS} (Error in magnitude zero point): Set by
+  \texttt{astrom\_rms} argument value;
+\item \texttt{CMFVERSION} (CMF version): Set by \texttt{version}
+  argument value but possibly modified by first \texttt{EXTTYPE}
+  value;
+  \commentFromSC{2012-09-18}{Depends on the order of the input FITS
+    file and their \texttt{EXTTYPE} value (e.g. if \texttt{-version 0}
+    is used as argument and two files are used, one with
+    \texttt{EXTTYPE} of 1, the other with \texttt{EXTTYPE} of
+    2). However we do not expect to have different values for
+    \texttt{EXTTYPE}, do we?}{}
+\end{itemize}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\subsubsection{Detection Parameters: Extension Details}
+\label{sec-implementation-write-detection}
+
+If no detection is present in any detections set, an extension is
+still created and contains exactly one row of undefined values
+(\texttt{NaN} for floating-point data, 0 for integral types).
+
+To resolve any ambiguity, we will note the parameter named
+\texttt{param} which was built for the detection $j$ in the set of
+detections ${\cal D}_{i}$ will be denoted by ${\cal
+  D}_{ij}(\mathtt{param})$ where \texttt{param} was defined in
+paragraph~\ref{sec-implementation-read}. When the \texttt{param}
+parameter is the exact copy of the value associated to the keyword
+\texttt{INPUT\_KEY}, we will write it as ${\cal
+  D}_{ij}(\mathtt{INPUT\_KEY})$ (note the use of the uppercase
+letters).
+
+For each detection $j$ in each detections set ${\cal D}_{i}$, the
+following products are written to the output FITS file:
+\begin{itemize}
+\item \texttt{RA} associated to ${\cal D}_{ij}(\mathtt{ra})$ (which is
+  identical to ${\cal D}_{ij}(\mathtt{RA\_PSF})$);
+\item \texttt{RA\_ERR} associated to ${\cal D}_{ij}(\mathtt{raErr})$;
+\item \texttt{DEC} associated to ${\cal D}_{ij}(\mathtt{dec})$ (which
+  is identical to ${\cal D}_{ij}(\mathtt{DEC\_PSF})$);
+\item \texttt{DEC\_ERR} associated to ${\cal
+    D}_{ij}(\mathtt{decErr})$;
+\item \texttt{MAG} associated to ${\cal D}_{ij}(\mathtt{mag})$;
+\item \texttt{MAG\_ERR} associated to ${\cal D}_{ij}(\mathtt{magErr})$
+  (which is identical to ${\cal
+    D}_{ij}(\mathtt{PSF\_INST\_MAG\_SIG})$);
+\item \texttt{PSF\_CHI2} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_CHISQ})$;
+\item \texttt{PSF\_DOF} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_NDOF})$;
+\item \texttt{CR\_SIGNIFICANCE} associated to ${\cal
+    D}_{ij}(\mathtt{CR\_NSIGMA})$;
+\item \texttt{EXT\_SIGNIFICANCE} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_NSIGMA})$;
+\item \texttt{PSF\_MAJOR} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_MAJOR})$;
+\item \texttt{PSF\_MINOR} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_MINOR})$;
+\item \texttt{PSF\_THETA} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_THETA})$;
+\item \texttt{PSF\_QUALITY} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_QF})$;
+\item \texttt{PSF\_NPIX} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_NPIX})$;
+\item \texttt{MOMENTS\_XX} associated to ${\cal
+    D}_{ij}(\mathtt{MOMENTS\_XX})$;
+\item \texttt{MOMENTS\_XY} associated to ${\cal
+    D}_{ij}(\mathtt{MOMENTS\_XY})$;
+\item \texttt{MOMENTS\_YY} associated to ${\cal
+    D}_{ij}(\mathtt{MOMENTS\_YY})$;
+\item \texttt{N\_POS} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_NPOS})$;
+\item \texttt{F\_POS} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_FRATIO})$;
+\item \texttt{RATIO\_BAD} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_NRATIO\_BAD})$;
+\item \texttt{RATIO\_MASK} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_NRATIO\_MASK})$;
+\item \texttt{RATIO\_ALL} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_NRATIO\_ALL})$;
+\item \texttt{FLAGS} associated to ${\cal D}_{ij}(\mathtt{FLAGS})$;
+\item \texttt{DIFF\_SKYFILE\_ID} associated to ${\cal
+    D}_{i}(\mathtt{diffSkyfileId})$ (that is, the \texttt{diff\_id} of
+  the file which was used to compute the difference);
+\item \texttt{IPP\_IDET} associated to ${\cal
+    D}_{ij}(\mathtt{IPP\_DET})$ (since it is the position of the
+  detection if the $i$th diff file, it is not very useful. However
+  gaps in the numbering show that detections have been removed.
+\item \texttt{PSF\_INST\_FLUX} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_INST\_FLUX})$;
+\item \texttt{PSF\_INST\_FLUX\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_INST\_FLUX\_SIG})$;
+\item \texttt{AP\_MAG} associated to ${\cal D}_{ij}(\mathtt{AP\_MAG})$;
+\item \texttt{AP\_MAG\_RAW} associated to ${\cal
+    D}_{ij}(\mathtt{AP\_MAG\_RAW})$;
+\item \texttt{AP\_MAG\_RADIUS} associated to ${\cal
+    D}_{ij}(\mathtt{AP\_MAG\_RADIUS})$;
+\item \texttt{AP\_FLUX} associated to ${\cal D}_{ij}(\mathtt{AP\_FLUX})$;
+\item \texttt{AP\_FLUX\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{AP\_FLUX\_SIG})$;
+\item \texttt{PEAK\_FLUX\_AS\_MAG} associated to ${\cal
+    D}_{ij}(\mathtt{PEAK\_FLUX\_AS\_MAG})$;
+\item \texttt{CAL\_PSF\_MAG} associated to ${\cal
+    D}_{ij}(\mathtt{CAL\_PSF\_MAG})$;
+\item \texttt{CAL\_PSF\_MAG\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{CAL\_PSF\_MAG\_SIG})$;
+\item \texttt{SKY} associated to ${\cal D}_{ij}(\mathtt{SKY})$;
+\item \texttt{SKY\_SIGMA} associated to ${\cal D}_{ij}(\mathtt{SKY\_SIGMA})$;
+\item \texttt{PSF\_QF\_PERFECT} associated to ${\cal
+    D}_{ij}(\mathtt{PSF\_QF\_PERFECT})$;
+\item \texttt{MOMENTS\_R1} associated to ${\cal D}_{ij}(\mathtt{MOMENTS\_R1})$;
+\item \texttt{MOMENTS\_RH} associated to ${\cal D}_{ij}(\mathtt{MOMENTS\_RH})$;
+\item \texttt{KRON\_FLUX} associated to ${\cal D}_{ij}(\mathtt{KRON\_FLUX})$;
+\item \texttt{KRON\_FLUX\_ERR} associated to ${\cal
+    D}_{ij}(\mathtt{KRON\_FLUX\_ERR})$;
+\item \texttt{KRON\_FLUX\_INNER} associated to ${\cal
+    D}_{ij}(\mathtt{KRON\_FLUX\_INNER})$;
+\item \texttt{KRON\_FLUX\_OUTER} associated to ${\cal
+    D}_{ij}(\mathtt{KRON\_FLUX\_OUTER})$;
+\item \texttt{DIFF\_R\_P} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_R\_P})$;
+\item \texttt{DIFF\_SN\_P} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_SN\_P})$;
+\item \texttt{DIFF\_R\_M} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_R\_M})$;
+\item \texttt{DIFF\_SN\_M} associated to ${\cal
+    D}_{ij}(\mathtt{DIFF\_SN\_M})$;
+\item \texttt{FLAGS2} associated to ${\cal D}_{ij}(\mathtt{FLAGS2})$;
+\item \texttt{N\_FRAMES} associated to ${\cal
+    D}_{ij}(\mathtt{N\_FRAMES})$;
+\item \texttt{PADDING} associated to ${\cal
+    D}_{ij}(\mathtt{PADDING})$;
+\item \texttt{X\_EXT} associated to ${\cal D}_{ij}(\mathtt{X\_EXT})$;
+\item \texttt{Y\_EXT} associated to ${\cal D}_{ij}(\mathtt{Y\_EXT})$;
+\item \texttt{X\_EXT\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{X\_EXT\_SIG})$;
+\item \texttt{Y\_EXT\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{Y\_EXT\_SIG})$;
+\item \texttt{EXT\_INST\_MAG} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_INST\_MAG})$;
+\item \texttt{EXT\_INST\_MAG\_SIG} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_INST\_MAG\_SIG})$;
+\item \texttt{NPARAMS} associated to ${\cal
+    D}_{ij}(\mathtt{NPARAMS})$;
+\item \texttt{EXT\_WIDTH\_MAJ} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_WIDTH\_MAJ})$;
+\item \texttt{EXT\_WIDTH\_MIN} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_WIDTH\_MIN})$;
+\item \texttt{EXT\_THETA} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_THETA})$;
+\item \texttt{EXT\_WIDTH\_MAJ\_ERR} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_WIDTH\_MAJ\_ERR})$;
+\item \texttt{EXT\_WIDTH\_MIN\_ERR} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_WIDTH\_MIN\_ERR})$;
+\item \texttt{EXT\_THETA\_ERR} associated to ${\cal
+    D}_{ij}(\mathtt{EXT\_THETA\_ERR})$;
+\end{itemize}
+
+\subsection{Testing}
+\label{sec-implementation-test}
+
+No test data have been provided.
+
+\commentFromSC{2012-09-18}{No data exists to test the software. It
+  would be good to make sure that the products are consistent at least
+  (1) From one software release to another; (2) From one software
+  execution to another; (3) To check if the product depends one the
+  order in which the input data are ingested and processed. Stress
+  tests could also be imagined, e.g. involving large data sets}{ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\newpage
+\section{Obsolete Stuff?}
+
+TODO (SC): The following stuff seems obsolete. Tell me if I can remove it.
 
 \subsection{IPP to MOPS}
@@ -797,24 +1580,4 @@
 \hline
 Detectability Query         & \code{MOPS_DETECTABILITY_QUERY} & table of detectability query tuples (RA, Dec, FPA) \\
-\end{tabular}
-\end{center}
-\end{table}
-
-\subsection{Acronyms}
-
-\begin{table}[htbp]
-\begin{center}
-\small
-\caption{Acronyms used in this document\label{table-acronyms}}
-\begin{tabular}{ll}
-\hline
-\hline
-{\bf Acronym}            & {\bf Definition} \\
-\hline
-MOPS     & Pan-STARRS Moving Object Processing System \\
-IPP      & Pan-STARRS Image Processing Pipeline \\
-FPA      & Focal plane array \\
-MPC      & Center for Astrophysics Minor Planet Center \\
-\hline
 \end{tabular}
 \end{center}
@@ -841,101 +1604,4 @@
 \end{itemize}
 
-\subsection{Example}
-\label{sec-example}
-
-\begin{verbatim}
-XTENSION= 'BINTABLE'           / binary table extension
-BITPIX  =                    8 / 8-bit bytes
-NAXIS   =                    2 / 2-dimensional binary table
-NAXIS1  =                  120 / width of table in bytes
-NAXIS2  =                42032 / number of rows in table
-PCOUNT  =                    0 / size of special data area
-GCOUNT  =                    1 / one data group (required keyword)
-TFIELDS =                   25 / number of fields in each row
-TTYPE1  = 'RA      '           / label for field   1
-TFORM1  = '1D      '           / data format of field: 8-byte DOUBLE
-TTYPE2  = 'RA_ERR  '           / label for field   2
-TFORM2  = '1D      '           / data format of field: 8-byte DOUBLE
-TTYPE3  = 'DEC     '           / label for field   3
-TFORM3  = '1D      '           / data format of field: 8-byte DOUBLE
-TTYPE4  = 'DEC_ERR '           / label for field   4
-TFORM4  = '1D      '           / data format of field: 8-byte DOUBLE
-TTYPE5  = 'MAG     '           / label for field   5
-TFORM5  = '1E      '           / data format of field: 4-byte REAL
-TTYPE6  = 'MAG_ERR '           / label for field   6
-TFORM6  = '1E      '           / data format of field: 4-byte REAL
-TTYPE7  = 'PSF_CHI2'           / label for field   7
-TFORM7  = '1E      '           / data format of field: 4-byte REAL
-TTYPE8  = 'PSF_DOF '           / label for field   8
-TFORM8  = '1J      '           / data format of field: 4-byte INTEGER
-TTYPE9  = 'CR_SIGNIFICANCE'    / label for field   9
-TFORM9  = '1E      '           / data format of field: 4-byte REAL
-TTYPE10 = 'EXT_SIGNIFICANCE'   / label for field  10
-TFORM10 = '1E      '           / data format of field: 4-byte REAL
-TTYPE11 = 'PSF_MAJOR'          / label for field  11
-TFORM11 = '1E      '           / data format of field: 4-byte REAL
-TTYPE12 = 'PSF_MINOR'          / label for field  12
-TFORM12 = '1E      '           / data format of field: 4-byte REAL
-TTYPE13 = 'PSF_THETA'          / label for field  13
-TFORM13 = '1E      '           / data format of field: 4-byte REAL
-TTYPE14 = 'PSF_QUALITY'        / label for field  14
-TFORM14 = '1E      '           / data format of field: 4-byte REAL
-TTYPE15 = 'PSF_NPIX'           / label for field  15
-TFORM15 = '1J      '           / data format of field: 4-byte INTEGER
-TTYPE16 = 'MOMENTS_XX'         / label for field  16
-TFORM16 = '1E      '           / data format of field: 4-byte REAL
-TTYPE17 = 'MOMENTS_XY'         / label for field  17
-TFORM17 = '1E      '           / data format of field: 4-byte REAL
-TTYPE18 = 'MOMENTS_YY'         / label for field  18
-TFORM18 = '1E      '           / data format of field: 4-byte REAL
-TTYPE19 = 'N_POS   '           / label for field  19
-TFORM19 = '1J      '           / data format of field: 4-byte INTEGER
-TTYPE20 = 'F_POS   '           / label for field  20
-TFORM20 = '1E      '           / data format of field: 4-byte REAL
-TTYPE21 = 'RATIO_BAD'          / label for field  21
-TFORM21 = '1E      '           / data format of field: 4-byte REAL
-TTYPE22 = 'RATIO_MASK'         / label for field  22
-TFORM22 = '1E      '           / data format of field: 4-byte REAL
-TTYPE23 = 'RATIO_ALL'          / label for field  23
-TFORM23 = '1E      '           / data format of field: 4-byte REAL
-TTYPE24 = 'FLAGS   '           / label for field  24
-TFORM24 = '1J      '           / data format of field: 4-byte INTEGER
-TZERO24 =           2147483648 / offset for unsigned integers
-TSCAL24 =                    1 / data are not scaled
-TTYPE25 = 'DIFF_SKYFILE_ID'    / label for field  25
-TFORM25 = '1K      '           / data format of field: 8-byte INTEGER
-SWSOURCE= '60eb6cdc-a59c-4636-a4e0-dba66a9721fd' / Software source
-SWVERSN = 'branches/pap_mops/ppMops@25227' / Software version
-HISTORY ppMops at 2009-09-02T03:48:46.695783
-HISTORY psLib version: branches/pap_mops/psLib@25227
-HISTORY psLib source: 60eb6cdc-a59c-4636-a4e0-dba66a9721fd
-HISTORY ppMops version: branches/pap_mops/ppMops@25227
-HISTORY ppMops source: 60eb6cdc-a59c-4636-a4e0-dba66a9721fd
-EXP_NAME= 'o4995g0129o'        / Exposure name
-EXP_ID  =                77164 / Exposure identifier
-CHIP_ID =                24019 / Chip stage identifier
-CAM_ID  =                17726 / Cam stage identifier
-FAKE_ID =                10227 / Fake stage identifier
-WARP_ID =                 8842 / Warp stage identifier
-DIFF_ID =                19219 / Diff stage identifier
-DIFF_POS=                    F / Positive subtraction?
-MJD-OBS =     54995.4740598313 / MJD of exposure midpoint
-RA      = '18:25:01.988'       / Right Ascension of boresight
-DEC     = '-17:20:40.069'      / Declination of boresight
-TEL_ALT =            51.951873 / Telescope altitude
-TEL_AZ  =           179.483883 / Telescope azimuth
-EXPTIME =                  38. / Exposure time (sec)
-ROTANGLE=             333.1039 / Rotator position angle
-FILTER  = 'r.00000 '           / Filter name
-AIRMASS =                1.269 / Airmass of exposure
-OBSCODE = 'F51     '           / IAU Observatory code
-SEEING  =             1.678401 / Mean seeing
-MAGZP   =             28.65226 / Magnitude zero point
-MAGZPERR=             0.353063 / Error in magnitude zero point
-ASTRORMS=            0.3111496 / RMS of astrometric fit
-EXTNAME = 'MOPS_TRANSIENT_DETECTIONS'
-\end{verbatim}
-
-
 \end{document}
 
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/basics.xfig
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/basics.xfig	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/basics.xfig	(revision 34735)
@@ -0,0 +1,290 @@
+#FIG 3.2  Produced by xfig version 3.2.5b
+Landscape
+Center
+Metric
+A4      
+100.00
+Single
+-2
+1200 2
+0 32 #dc9d92
+0 33 #f0ebdf
+0 34 #c2c2c2
+0 35 #e1c7a7
+0 36 #e0e0e0
+0 37 #d1d1d1
+0 38 #ececec
+0 39 #d97a1a
+0 40 #f0e31a
+0 41 #877dc1
+0 42 #afa092
+0 43 #827cdc
+0 44 #d5d5d5
+0 45 #8b8ba4
+0 46 #4a4a4a
+0 47 #8b6b6b
+0 48 #636363
+0 49 #8d8d8d
+0 50 #b69a73
+0 51 #4192fe
+0 52 #be703b
+0 53 #da7700
+0 54 #d9b700
+0 55 #006400
+0 56 #5a6b3b
+0 57 #d2d2d2
+0 58 #a9a9a9
+0 59 #8d8da3
+0 60 #f2b85d
+0 61 #88986b
+0 62 #646464
+0 63 #d5d5d5
+0 64 #8b8ba4
+0 65 #5a5a5a
+0 66 #b6e5fe
+0 67 #85bfeb
+0 68 #bcbcbc
+0 69 #d29552
+0 70 #8d8d8d
+0 71 #97d1fd
+0 72 #8d8d8d
+0 73 #616161
+0 74 #adb1ad
+0 75 #717171
+0 76 #fe9900
+0 77 #d5d5d5
+0 78 #8b8ba4
+0 79 #8b6b6b
+0 80 #8b9b6b
+0 81 #f66b00
+0 82 #5a6b39
+0 83 #8b9b6b
+0 84 #d5d5d5
+0 85 #8b8ba4
+0 86 #8b6b6b
+0 87 #8b9b6b
+0 88 #f66b00
+0 89 #8b9b7b
+0 90 #184a18
+0 91 #d5d5d5
+0 92 #acacac
+0 93 #8b8ba4
+0 94 #f6bc5a
+0 95 #8b9b6b
+0 96 #636b9b
+0 97 #8b6b6b
+0 98 #f6f6f6
+0 99 #dd0000
+0 100 #8b9b6b
+0 101 #d5d5d5
+0 102 #acacac
+0 103 #8b8ba4
+0 104 #f6bc5a
+0 105 #8b9b6b
+0 106 #d5d5d5
+0 107 #acacac
+0 108 #8b8ba4
+0 109 #f6bc5a
+0 110 #8b9b6b
+0 111 #636b9b
+0 112 #526b29
+0 113 #939393
+0 114 #006300
+0 115 #8b8ba4
+0 116 #8b8ba4
+0 117 #8b8ba4
+0 118 #00634a
+0 119 #7b834a
+0 120 #e6bc7b
+0 121 #8b9b7b
+0 122 #a4b4c5
+0 123 #6b6b93
+0 124 #836b6b
+0 125 #529b4a
+0 126 #d5e6e6
+0 127 #526363
+0 128 #186b4a
+0 129 #9ba4b4
+0 130 #fe9300
+0 131 #fe9300
+0 132 #8b6b6b
+0 133 #d5d5d5
+0 134 #acacac
+0 135 #8b8ba4
+0 136 #8b6b6b
+0 137 #acacac
+0 138 #8b9b6b
+0 139 #acacac
+0 140 #d2d2d2
+0 141 #a9a9a9
+0 142 #8d8da3
+0 143 #f2b85d
+0 144 #88986b
+0 145 #d5d5d5
+0 146 #8b8ba4
+0 147 #d5d5d5
+0 148 #8b8ba4
+0 149 #8b6b6b
+0 150 #8b9b6b
+0 151 #d5d5d5
+0 152 #8b8ba4
+0 153 #8b6b6b
+0 154 #8b9b7b
+0 155 #000000
+0 156 #f63829
+0 157 #000000
+0 158 #fefe52
+0 159 #52794a
+0 160 #63995a
+0 161 #c56142
+0 162 #e66942
+0 163 #fe7952
+0 164 #dddddd
+0 165 #acacac
+0 166 #8b8ba4
+0 167 #f6bc5a
+0 168 #8b9b6b
+0 169 #636b9b
+0 170 #f6f6f6
+0 171 #d5d5d5
+0 172 #8b6b6b
+0 173 #d2d2d2
+0 174 #a9a9a9
+0 175 #8d8da3
+0 176 #f2b85d
+0 177 #88986b
+0 178 #d2d2d2
+0 179 #a9a9a9
+0 180 #8d8da3
+0 181 #f2b85d
+0 182 #88986b
+0 183 #d2d2d2
+0 184 #a9a9a9
+0 185 #8d8da3
+0 186 #f2b85d
+0 187 #88986b
+0 188 #d2d2d2
+0 189 #a9a9a9
+0 190 #8d8da3
+0 191 #f2b85d
+0 192 #88986b
+0 193 #d2d2d2
+0 194 #a9a9a9
+0 195 #8d8da3
+0 196 #f2b85d
+0 197 #88986b
+0 198 #d5d5d5
+0 199 #8b8ba4
+0 200 #d2d2d2
+0 201 #a9a9a9
+0 202 #8d8da3
+0 203 #f2b85d
+0 204 #88986b
+0 205 #d2d2d2
+0 206 #a9a9a9
+0 207 #8d8da3
+0 208 #f2b85d
+0 209 #88986b
+0 210 #d2d2d2
+0 211 #a9a9a9
+0 212 #8d8da3
+0 213 #f2b85d
+0 214 #88986b
+0 215 #d2d2d2
+0 216 #a9a9a9
+0 217 #8d8da3
+0 218 #f2b85d
+0 219 #88986b
+0 220 #d5d5d5
+0 221 #8b8ba4
+0 222 #f2edd2
+0 223 #f4ad5d
+0 224 #95cd98
+0 225 #a9a9a9
+0 226 #b4157d
+0 227 #ededed
+0 228 #838383
+0 229 #d5d5d5
+0 230 #acacac
+0 231 #8b8ba4
+0 232 #f6bc5a
+0 233 #8b9b6b
+0 234 #636b9b
+0 235 #7b7b7b
+0 236 #005a00
+0 237 #e67373
+0 238 #f6f6f6
+0 239 #dd0000
+0 240 #feca31
+0 241 #29794a
+0 242 #dd2821
+0 243 #2159c5
+0 244 #f7f7f7
+0 245 #ededed
+0 246 #e5e5e5
+0 247 #7b834a
+0 248 #d5d5d5
+0 249 #acacac
+0 250 #63737b
+0 251 #e6bc7b
+0 252 #8b9b7b
+0 253 #a4b4c5
+0 254 #6b6b93
+0 255 #836b6b
+0 256 #529b4a
+0 257 #d5e6e6
+0 258 #9ba4b4
+0 259 #21835a
+0 260 #8b8ba4
+0 261 #f6bc5a
+0 262 #8b9b6b
+0 263 #636b9b
+0 264 #d5d5d5
+0 265 #acacac
+0 266 #8b8ba4
+0 267 #f6bc5a
+0 268 #8b9b6b
+0 269 #8b6b6b
+0 270 #9b0000
+0 271 #9b0000
+0 272 #8b8b8b
+0 273 #424242
+0 274 #8b8b8b
+0 275 #424242
+0 276 #8b8b8b
+0 277 #424242
+0 278 #8b8b8b
+0 279 #424242
+0 280 #8b8b8b
+0 281 #424242
+0 282 #8b8b8b
+0 283 #424242
+0 284 #8b8b8b
+0 285 #8b8b8b
+0 286 #8b8b8b
+0 287 #8b8b8b
+0 288 #8b8b8b
+0 289 #8b8b8b
+0 290 #8b8b8b
+0 291 #8b8b8b
+0 292 #8b8b8b
+0 293 #8b8b8b
+0 294 #8b8b8b
+0 295 #8b8b8b
+0 296 #6e6e6e
+0 297 #444444
+0 298 #8d8e8d
+0 299 #8d8e8d
+0 300 #adadad
+0 301 #333333
+0 302 #939295
+0 303 #747075
+0 304 #555555
+0 305 #b2b2b2
+0 306 #c2c2c2
+0 307 #6d6d6d
+0 308 #454545
+0 309 #8d8d8d
+0 310 #8d8e8d
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6975 4950 5180 5180 6975 4950 7200 10125
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6975 4950 450 450 6975 4950 6975 5400
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/exposure_ota.fig
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/exposure_ota.fig	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/exposure_ota.fig	(revision 34735)
@@ -0,0 +1,12 @@
+#FIG 3.2  Produced by xfig version 3.2.5b
+Landscape
+Center
+Metric
+A4      
+100.00
+Single
+-2
+1200 2
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2295 1035 6705 1035 6705 3150 2295 3150 2295 1035
+4 0 0 50 -1 0 12 0.0000 4 165 1170 3780 1980 exposure OTAs\001
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ext_theta.fig
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ext_theta.fig	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ext_theta.fig	(revision 34735)
@@ -0,0 +1,39 @@
+#FIG 3.2  Produced by xfig version 3.2.5b
+Landscape
+Center
+Metric
+A4      
+100.00
+Single
+-2
+1200 2
+5 1 0 2 0 7 50 -1 -1 0.000 0 1 1 0 5538.104 4894.526 5805 4320 5130 4410 4950 5130
+	3 1 1.00 60.00 120.00
+6 3870 2610 9900 5580
+1 1 0 2 0 7 50 -1 -1 0.000 1 0.4363 8135 3547 1206 424 8135 3547 9398 3395
+2 1 1 2 0 7 50 -1 -1 6.000 0 0 -1 1 0 2
+	3 1 1.00 55.77 111.55
+	 4126 5520 9592 2831
+2 1 1 2 0 7 50 -1 -1 6.000 0 0 -1 1 0 2
+	3 1 1.00 55.77 111.55
+	 8474 4317 7794 2779
+-6
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	3 1 1.00 60.00 120.00
+	 3600 7200 10575 7200
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 1 2
+	3 1 1.00 60.00 120.00
+	3 1 1.00 60.00 120.00
+	 7740 5400 9855 4447
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 1 2
+	3 1 1.00 60.00 120.00
+	3 1 1.00 60.00 120.00
+	 9850 3332 9470 2516
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	3 1 1.00 60.00 120.00
+	 5850 7650 5850 1350
+4 0 0 50 -1 0 12 0.0000 4 150 810 4725 4185 EXT_THETA\001
+4 0 0 50 -1 0 16 0.0000 4 135 90 10260 7650 W\001
+4 0 0 50 -1 0 12 0.0000 4 150 1170 8550 5490 EXT_WIDTH_MAJ\001
+4 0 0 50 -1 0 12 0.0000 4 150 1170 9675 2700 EXT_WIDTH_MIN\001
+4 0 0 50 -1 -1 16 0.0000 4 135 90 6030 1530 N\001
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ipp_workflow.fig
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ipp_workflow.fig	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/figures/ipp_workflow.fig	(revision 34735)
@@ -0,0 +1,84 @@
+#FIG 3.2  Produced by xfig version 3.2.5b
+Landscape
+Center
+Metric
+A4      
+100.00
+Single
+-2
+1200 2
+6 2700 2700 4500 3600
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2700 2700 4500 2700 4500 3600 2700 3600 2700 2700
+4 0 0 50 -1 0 12 0.0000 4 135 360 3420 3217 CHIP\001
+-6
+6 2700 450 4500 1350
+1 1 0 1 0 7 50 -1 -1 0.000 1 0.0000 3600 900 900 450 3600 900 4500 1350
+4 0 0 50 -1 0 12 0.0000 4 165 900 3150 952 "exposure"\001
+-6
+6 2700 4050 4500 4950
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2700 4050 4500 4050 4500 4950 2700 4950 2700 4050
+4 0 0 50 -1 0 12 0.0000 4 135 540 3330 4567 CAMERA\001
+-6
+6 2700 5400 4500 6300
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2700 5400 4500 5400 4500 6300 2700 6300 2700 5400
+4 0 0 50 -1 0 12 0.0000 4 135 360 3420 5917 WARP\001
+-6
+6 2700 6750 4500 7650
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2700 6750 4500 6750 4500 7650 2700 7650 2700 6750
+4 0 0 50 -1 0 12 0.0000 4 135 360 3420 7267 DIFF\001
+-6
+6 2700 8100 4500 9000
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 2700 8100 4500 8100 4500 9000 2700 9000 2700 8100
+4 0 0 50 -1 0 12 0.0000 4 135 540 3330 8617 PPMOPS\001
+-6
+6 5400 6525 7200 7425
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 5400 6525 7200 6525 7200 7425 5400 7425 5400 6525
+4 0 0 50 -1 0 12 0.0000 4 135 450 6075 7042 STACK\001
+-6
+6 2700 10350 4500 11250
+1 1 0 1 0 7 50 -1 -1 0.000 1 0.0000 3600 10800 900 450 3600 10800 4500 11250
+4 0 0 50 -1 0 12 0.0000 4 165 1170 3015 10852 MOPS products\001
+-6
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 1350 3600 2700
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 3600 3600 4050
+2 1 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
+	 1800 0 1800 1800 7650 1800 7650 0
+2 2 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 7650 2250 6750 2250 6750 2700 7650 2700 7650 2250
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 4950 3600 5400
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 6300 3600 6750
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 7650 3600 8100
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 6300 6300 6525
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 6300 7425 3600 8100
+2 2 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 1800 2250 7650 2250 7650 9450 1800 9450 1800 2250
+2 1 0 3 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
+	 1800 11700 1800 9900 7650 9900 7650 11700
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 9000 3600 10350
+4 0 0 50 -1 0 12 0.0000 4 135 1620 5400 675 Interface with the\001
+4 0 0 50 -1 0 12 0.0000 4 165 810 5400 870 telescope\001
+4 0 0 50 -1 0 12 0.0000 4 135 270 7065 2542 IPP\001
+4 0 0 50 -1 0 12 0.0000 4 135 1620 5400 10575 Interface with the\001
+4 0 0 50 -1 0 12 0.0000 4 135 360 5400 10770 MOPS\001
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/icd.bib
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/icd.bib	(revision 34735)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/icd.bib	(revision 34735)
@@ -0,0 +1,19 @@
+@ARTICLE{VerJedDen2012IAAaPwTF,
+   author = {{Vere{\v s}}, P. and {Jedicke}, R. and {Denneau}, L. and
+                  {Wainscoat}, R. and {Holman}, M.~J. and {Lin},
+                  H.-W.},
+    title = "{Improved Asteroid Astrometry and Photometry with Trail
+                  Fitting}",
+  journal = {PASP},
+archivePrefix = "arXiv",
+   eprint = {1209.6106},
+ primaryClass = "astro-ph.IM",
+ keywords = {Data Analysis and Techniques},
+     year = 2012,
+    month = nov,
+   volume = 124,
+    pages = {1197-1207},
+      doi = {10.1086/668616},
+   adsurl = {http://adsabs.harvard.edu/abs/2012PASP..124.1197V},
+  adsnote = {Provided by the SAO/NASA Astrophysics Data System}
+}
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMops.h
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMops.h	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMops.h	(revision 34735)
@@ -59,4 +59,5 @@
   psVector *raExtErr, *decExtErr;     // Error in sky coordinates for RA_EXT and DEC_EXT
   psVector *mask;                     // Mask for detections
+    float platescale; //Plate scale at centroid
 } ppMopsDetections;
 
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c	(revision 34735)
@@ -1,79 +1,3 @@
-/*
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- * THIS CODE CONTAINS DIRTY BUG FIXES!
- *
- *
- *
- *
- *
- *
- *
- * Look for "DIRTY_BUG_FIX" to know where
- * 
- * and set the following to 0 to change the code
- */
-#define DIRTY_BUG_FIX 1
-/*
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- */
+#define DIRTY_BUG_FIX 0
 
 #ifdef HAVE_CONFIG_H
@@ -90,7 +14,4 @@
 static void replaceDummyValuesS32(const char* colName, psMetadata* source, psMetadata* target, psVector* indexes);
 static void renameDummyValuesF32(const char* colNameSource, psMetadata* source, const char* colNameTarget, psMetadata* target, psVector* indexes);
-#if DIRTY_BUG_FIX
-static psVector* createDummyF32_default(long size, float default_value);
-#endif
 
 /*
@@ -145,9 +66,9 @@
     if (skyChipPsfVersion != args->version) {
       if (skyChipPsfVersion > args->version) {
-	psWarning("The FITS data will be downgraded from PS1_DV%d to PS1_DV%d\n",
-		  skyChipPsfVersion, args->version);
+        psWarning("The FITS data will be downgraded from PS1_DV%d to PS1_DV%d\n",
+                  skyChipPsfVersion, args->version);
       } else { // Necessarily: skyChipPsfVersion > args->version
-	psWarning("The FITS data will be upgraded from PS1_DV%d to PS1_DV%d (new values set to default 0, NaN...)\n",
-		  skyChipPsfVersion, args->version);
+        psWarning("The FITS data will be upgraded from PS1_DV%d to PS1_DV%d (new values set to default 0, NaN...)\n",
+                  skyChipPsfVersion, args->version);
       }
     }
@@ -199,63 +120,60 @@
       addDummyValues(det->table, size, args->version);
       if (!psFitsMoveExtName(fits, "SkyChip.xfit")) {
-	psTrace("ppMops.read", 3, "No fitted trails extension");
+        psTrace("ppMops.read", 3, "No fitted trails extension");
       } else {
-	psTrace("ppMops.read", 3, "Fitted trails extension found\n");
-	psTrace("ppMops.read", 10, "Getting size?\n");
-	int fittedTrailsSize = psFitsTableSize(fits);
-	psTrace("ppMops.read", 10, "size = %d\n", fittedTrailsSize);
-	if (fittedTrailsSize <= 0) {
-	  psErrorStackPrint(stderr, "Unable to determine size of fitted trails extension table %d", i);
-	  psTrace("ppMops.read", 3, "No entry in fitted trails extension!!!!\n");
-	  psErrorClear();
-	} else {
-	  psTrace("ppMops.read", 10, "Reading table of interest?\n");
-	  psMetadata* fittedTrails = psFitsReadTableAllColumns(fits); // Table of interest
-	  psTrace("ppMops.read", 10, "OK for table of interest\n");
-	  if (!fittedTrails) {
-	    psError(PS_ERR_IO, false, "Unable to read fittedTrails table in file %d", i);
-	    return NULL;
-	  }
-	  //Iterate on the different names and types expected in the fittedTrails parameters
-	  psTrace("ppMops.read", 10, "Getting IPP_IDET\n");
-	  psVector* idet = psMetadataLookupVector(NULL, fittedTrails, "IPP_IDET");
-	  replaceDummyValuesF32("X_EXT", fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("Y_EXT", fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("X_EXT_SIG", fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("Y_EXT_SIG", fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_INST_MAG",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_INST_MAG_SIG",  fittedTrails, det->table, idet);
-	  replaceDummyValuesS32("NPARAMS",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_WIDTH_MAJ",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_WIDTH_MIN",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_THETA",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_WIDTH_MAJ_ERR",  fittedTrails, det->table, idet);
-	  // EXT_WIDTH_MIN_ERR is actually undefined but set to 0. in CMF files
-	  // We explicitely let it set to NaN, hence the commented out
-	  // following line
-	  //replaceDummyValuesF32("EXT_WIDTH_MIN_ERR",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("EXT_THETA_ERR",  fittedTrails, det->table, idet);
-	  psTrace("ppMops.read", 10, "Got all version 2 values\n");
-	  if (skyChipPsfVersion >= 3) {
-	    psTrace("ppMops.read", 10, "Getting PS1_DV3 data\n");
-	    replaceDummyValuesF32("RA_EXT",  fittedTrails, det->table, idet);
-	    // Note: RA_EXT_SIGMA is computed (see det->raExtErr)
-	    replaceDummyValuesF32("DEC_EXT",  fittedTrails, det->table, idet);
-	    // Note: DEC_EXT_SIGMA is computed (see det->decExtErr)
-	    //Note: POSANG_EXT is POSANGLE in xfit
-#if DIRTY_BUG_FIX
-#else
- 	    renameDummyValuesF32("POSANGLE",  fittedTrails, "POSANG_EXT", det->table, idet);
-#endif    
-	    //Note: PLTSCALE_EXT in xfit is PLTSCALE
- 	    renameDummyValuesF32("PLTSCALE", fittedTrails, "PLTSCALE_EXT", det->table, idet);
-	    renameDummyValuesF32("EXT_INST_FLUX", fittedTrails, "EXT_FLUX", det->table, idet);
-	    replaceDummyValuesF32("EXT_CAL_MAG", fittedTrails, det->table, idet);
-	    renameDummyValuesF32("EXT_INST_MAG_SIG", fittedTrails, "EXT_MAG_SIG", det->table, idet);
-	    replaceDummyValuesF32("EXT_CHISQ", fittedTrails, det->table, idet);
-	    replaceDummyValuesS32("EXT_NDOF", fittedTrails, det->table, idet);
-	    psTrace("ppMops.read", 10, "Got all version 3 values\n");
-	  }
-	}
+        psTrace("ppMops.read", 3, "Fitted trails extension found\n");
+        psTrace("ppMops.read", 10, "Getting size?\n");
+        int fittedTrailsSize = psFitsTableSize(fits);
+        psTrace("ppMops.read", 10, "size = %d\n", fittedTrailsSize);
+        if (fittedTrailsSize <= 0) {
+          psErrorStackPrint(stderr, "Unable to determine size of fitted trails extension table %d", i);
+          psTrace("ppMops.read", 3, "No entry in fitted trails extension!!!!\n");
+          psErrorClear();
+        } else {
+          psTrace("ppMops.read", 10, "Reading table of interest?\n");
+          psMetadata* fittedTrails = psFitsReadTableAllColumns(fits); // Table of interest
+          psTrace("ppMops.read", 10, "OK for table of interest\n");
+          if (!fittedTrails) {
+            psError(PS_ERR_IO, false, "Unable to read fittedTrails table in file %d", i);
+            return NULL;
+          }
+          //Iterate on the different names and types expected in the fittedTrails parameters
+          psTrace("ppMops.read", 10, "Getting IPP_IDET\n");
+          psVector* idet = psMetadataLookupVector(NULL, fittedTrails, "IPP_IDET");
+          replaceDummyValuesF32("X_EXT", fittedTrails, det->table, idet);
+          replaceDummyValuesF32("Y_EXT", fittedTrails, det->table, idet);
+          replaceDummyValuesF32("X_EXT_SIG", fittedTrails, det->table, idet);
+          replaceDummyValuesF32("Y_EXT_SIG", fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_INST_MAG",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_INST_MAG_SIG",  fittedTrails, det->table, idet);
+          replaceDummyValuesS32("NPARAMS",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_WIDTH_MAJ",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_WIDTH_MIN",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_THETA",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_WIDTH_MAJ_ERR",  fittedTrails, det->table, idet);
+          // EXT_WIDTH_MIN_ERR is actually undefined but set to 0. in CMF files
+          // We explicitely let it set to NaN, hence the commented out
+          // following line
+          //replaceDummyValuesF32("EXT_WIDTH_MIN_ERR",  fittedTrails, det->table, idet);
+          replaceDummyValuesF32("EXT_THETA_ERR",  fittedTrails, det->table, idet);
+          psTrace("ppMops.read", 10, "Got all version 2 values\n");
+          if (skyChipPsfVersion >= 3) {
+            psTrace("ppMops.read", 10, "Getting PS1_DV3 data\n");
+            replaceDummyValuesF32("RA_EXT",  fittedTrails, det->table, idet);
+            // Note: RA_EXT_SIGMA is computed (see det->raExtErr)
+            replaceDummyValuesF32("DEC_EXT",  fittedTrails, det->table, idet);
+            // Note: DEC_EXT_SIGMA is computed (see det->decExtErr)
+            //Note: POSANG_EXT is POSANGLE in xfit
+            renameDummyValuesF32("POSANGLE",  fittedTrails, "POSANG_EXT", det->table, idet);
+            //Not written anymore but still used in computation
+            renameDummyValuesF32("PLTSCALE", fittedTrails, "PLTSCALE_EXT", det->table, idet);
+            renameDummyValuesF32("EXT_INST_FLUX", fittedTrails, "EXT_FLUX", det->table, idet);
+            replaceDummyValuesF32("EXT_CAL_MAG", fittedTrails, det->table, idet);
+            renameDummyValuesF32("EXT_INST_MAG_SIG", fittedTrails, "EXT_MAG_SIG", det->table, idet);
+            replaceDummyValuesF32("EXT_CHISQ", fittedTrails, det->table, idet);
+            replaceDummyValuesS32("EXT_NDOF", fittedTrails, det->table, idet);
+            psTrace("ppMops.read", 10, "Got all version 3 values\n");
+          }
+        }
       }
     }
@@ -264,5 +182,5 @@
     if (args->version == 0) {
       if (skyChipPsfVersion < 2) {
-	// XXX: TODO: Do we need to add dummy vectors for the missing columns?
+        // XXX: TODO: Do we need to add dummy vectors for the missing columns?
       }
     }
@@ -324,7 +242,7 @@
       psU32 flags = flagsV->data.U32[row]; // psFitsTableGetU32(NULL, table, row, "FLAGS");
       if (flags & SOURCE_MASK) {
-	psTrace("ppMops.read", 10, "Discarding row %ld from input %d because of flags: %ud", row, i, flags);
-	det->mask->data.U8[row] = 0xFF;
-	continue;
+        psTrace("ppMops.read", 10, "Discarding row %ld from input %d because of flags: %ud", row, i, flags);
+        det->mask->data.U8[row] = 0xFF;
+        continue;
       }
 
@@ -333,24 +251,19 @@
       double yErr = yErrV->data.F32[row];
       double scale = scaleV->data.F32[row];
-#if DIRTY_BUG_FIX
-      double angle = 0. * angleV->data.F32[row];
-#else
       double angle = angleV->data.F32[row];
-#endif
-
       if (!isfinite(det->x->data.F32[row]) || !isfinite(det->y->data.F32[row]) ||
-	  !isfinite(det->ra->data.F64[row]) || !isfinite(det->dec->data.F64[row]) ||
-	  !isfinite(mag->data.F32[row]) || !isfinite(magErr->data.F32[row]) ||
-	  !isfinite(xErr) || !isfinite(yErr) || !isfinite(scale) || !isfinite(angle)) {
-	psTrace("ppMops.read", 10,
-		"Discarding row %ld from input %d because of non-finite values: "
-		"%f %f %lf %lf %f %f %f %f %f %f",
-		row, i,
-		det->x->data.F32[row], det->y->data.F32[row],
-		det->ra->data.F64[row], det->dec->data.F64[row],
-		mag->data.F32[row], magErr->data.F32[row],
-		xErr, yErr, scale, angle);
-	det->mask->data.U8[row] = 0xFF;
-	continue;
+          !isfinite(det->ra->data.F64[row]) || !isfinite(det->dec->data.F64[row]) ||
+          !isfinite(mag->data.F32[row]) || !isfinite(magErr->data.F32[row]) ||
+          !isfinite(xErr) || !isfinite(yErr) || !isfinite(scale) || !isfinite(angle)) {
+        psTrace("ppMops.read", 10,
+                "Discarding row %ld from input %d because of non-finite values: "
+                "%f %f %lf %lf %f %f %f %f %f %f",
+                row, i,
+                det->x->data.F32[row], det->y->data.F32[row],
+                det->ra->data.F64[row], det->dec->data.F64[row],
+                mag->data.F32[row], magErr->data.F32[row],
+                xErr, yErr, scale, angle);
+        det->mask->data.U8[row] = 0xFF;
+        continue;
       }
 
@@ -364,25 +277,25 @@
       det->mask->data.U8[row] = 0;
       plateScale += scale;
+      //Update the platescale value (should be a constant)
+      if (isfinite(scale)) {
+          det->platescale = scale;
+      }
       numGood++;
 
       // Same for EXT data if version permits
       if (skyChipPsfVersion >= 3) {
-	xErr = xExtErrV->data.F32[row];
-	yErr = yExtErrV->data.F32[row];
-	scale = scaleExtV->data.F32[row]/3600.;
-#if DIRTY_BUG_FIX
-	angle = 0.;
-#else
-	angle = angleExtV->data.F32[row];
-#endif
-	cosAngle = cos(angle);
-	sinAngle = sin(angle);
-	cosAngle2 = PS_SQR(cosAngle);
-	sinAngle2 = PS_SQR(sinAngle);
-	xErr2 = PS_SQR(xErr);
-	yErr2 = PS_SQR(yErr);
-	errScale = scale / 3600.0;
-	det->raExtErr->data.F64[row] = errScale * sqrt(cosAngle2 * xErr2 + sinAngle2 * yErr2);
-	det->decExtErr->data.F64[row] = errScale * sqrt(sinAngle2 * xErr2 + cosAngle2 * yErr2);
+        xErr = xExtErrV->data.F32[row];
+        yErr = yExtErrV->data.F32[row];
+        scale = scaleExtV->data.F32[row]/3600.;
+        angle = angleExtV->data.F32[row];
+        cosAngle = cos(angle);
+        sinAngle = sin(angle);
+        cosAngle2 = PS_SQR(cosAngle);
+        sinAngle2 = PS_SQR(sinAngle);
+        xErr2 = PS_SQR(xErr);
+        yErr2 = PS_SQR(yErr);
+        errScale = scale / 3600.0;
+        det->raExtErr->data.F64[row] = errScale * sqrt(cosAngle2 * xErr2 + sinAngle2 * yErr2);
+        det->decExtErr->data.F64[row] = errScale * sqrt(sinAngle2 * xErr2 + cosAngle2 * yErr2);
       }
     }
@@ -406,14 +319,8 @@
   return dummy;
 }
-#if DIRTY_BUG_FIX
-static psVector* createDummyF32_default(long size, float default_value) {
-  psVector* dummy = psVectorAlloc(size, PS_TYPE_F32);
-  psVectorInit(dummy, default_value);
-  return dummy;
-}
-#endif
+
 static psVector* createDummyS32(long size) {
   psVector* dummy = psVectorAlloc(size, PS_TYPE_S32);
-  psVectorInit(dummy, NAN);
+  psVectorInit(dummy, 0);
   return dummy;
 }
@@ -439,9 +346,5 @@
     psMetadataAdd(md, PS_LIST_TAIL, "DEC_EXT",  PS_DATA_VECTOR, "Fitted centroid DEC", createDummyF32(size));
 /*     psMetadataAdd(md, PS_LIST_TAIL, "DEC_EXT_SIGMA",  PS_DATA_VECTOR, "Fitted DEC sigma", createDummyF32(size)); *\/ */
-#if DIRTY_BUG_FIX
-    psMetadataAdd(md, PS_LIST_TAIL, "POSANG_EXT",  PS_DATA_VECTOR, "Fitted position angle", createDummyF32_default(size, 0.));
-#else
     psMetadataAdd(md, PS_LIST_TAIL, "POSANG_EXT",  PS_DATA_VECTOR, "Fitted position angle", createDummyF32(size));
-#endif
     psMetadataAdd(md, PS_LIST_TAIL, "PLTSCALE_EXT",  PS_DATA_VECTOR, "Plate scale at centroid", createDummyF32(size));
     psMetadataAdd(md, PS_LIST_TAIL, "EXT_FLUX",  PS_DATA_VECTOR, "Fitted flux", createDummyF32(size));
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c	(revision 34735)
@@ -48,5 +48,5 @@
     }
   }
-  //Get the SEEING weighted mean
+  //Get the SEEING weighted mean. Update the PLTSCALE value
   float seeing = 0.;
   int totalGood = 0;
@@ -55,6 +55,10 @@
       seeing += ((ppMopsDetections*) detections->data[d])->seeing;
       totalGood += 1;
-    }
-  }
+      if (isfinite(((ppMopsDetections*) detections->data[d])->platescale)) {
+          det->platescale = ((ppMopsDetections*) detections->data[d])->platescale;
+      }
+    }
+  }
+  printf("plate-scale = [%g]\n", det->platescale);
   seeing /= (float) totalGood;
   if (det != NULL) {
@@ -80,9 +84,11 @@
   psMetadataAddF32(header, PS_LIST_TAIL, "MAGZPERR", 0, "Error in magnitude zero point", args->zpErr);
   psMetadataAddF32(header, PS_LIST_TAIL, "ASTRORMS", 0, "RMS of astrometric fit", args->rmsAstrom);
-  psMetadataAddStr(header, PS_LIST_TAIL, "COMMENT", 0, "Exposure comment", args->comment);
+  psMetadataAddStr(header, PS_LIST_TAIL, "CMMTOBS", 0, "Exposure comment", args->comment);
   psMetadataAddStr(header, PS_LIST_TAIL, "OBS_MODE", 0, "Exposure observation mode", args->obsMode);
   psMetadataAddStr(header, PS_LIST_TAIL, "DIFFTYPE", 0, "WW: Warp-Warp diff / WS: Warp-Stack diff / SW: Stack-Warp diff", args->difftype);
   psMetadataAddF32(header, PS_LIST_TAIL, "SKY", 0, "Exposure avg sky background", args->sky);
   psMetadataAddStr(header, PS_LIST_TAIL, "SHUTOUTC", 0, "Camera exposure shutter open (UTC)", args->shutoutc);
+  psMetadataAddF32(header, PS_LIST_TAIL, "PLTSCALE_EXT", 0, "Plate scale at centroid", det->platescale);
+  psMetadataAddF32(header, PS_LIST_TAIL, "PLTSCALE", 0, "Plate scale at centroid", det->platescale);
 
   //field in header that tells about the CMF version
@@ -92,5 +98,4 @@
 
   // Find the total number of detections
-
   long total = 0;
   for (long i=0; i<detections->n; i++) {
@@ -191,27 +196,25 @@
                      0);
       if (args->version == 3) {
-	// Write data of version 3 (see ICD)
-	psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT",         PS_DATA_F32, "Fitted centroid RA", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT_SIGMA",   PS_DATA_F32, "Fitted RA sigma", 
-		       0);
-	psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT",        PS_DATA_F32, "Fitted centroid DEC", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT_SIGMA",  PS_DATA_F32, "Fitted DEC sigma", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "POSANG_EXT",     PS_DATA_F32, "Fitted position angle", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE_EXT",   PS_DATA_F32, "Plate scale at centroid", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "EXT_FLUX",       PS_DATA_F32, "Fitted flux", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "EXT_CAL_MAG",    PS_DATA_F32, "Calibrated mag", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "EXT_MAG_SIG",    PS_DATA_F32, "Mag sigma", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ",      PS_DATA_F32, "Chi^2 of fit", 
-		       0);
- 	psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF",       PS_DATA_F32, "Fit degrees of freedom", 
-		       0);
+// Write data of version 3 (see ICD)
+        psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT",         PS_DATA_F32, "Fitted centroid RA",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "RA_EXT_SIGMA",   PS_DATA_F32, "Fitted RA sigma",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT",        PS_DATA_F32, "Fitted centroid DEC",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "DEC_EXT_SIGMA",  PS_DATA_F32, "Fitted DEC sigma",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "POSANG_EXT",     PS_DATA_F32, "Fitted position angle",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_FLUX",       PS_DATA_F32, "Fitted flux",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_CAL_MAG",    PS_DATA_F32, "Calibrated mag",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_MAG_SIG",    PS_DATA_F32, "Mag sigma",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_CHISQ",      PS_DATA_F32, "Chi^2 of fit",
+                       0);
+        psMetadataAdd (row, PS_LIST_TAIL, "EXT_NDOF",       PS_DATA_F32, "Fit degrees of freedom",
+                       0);
       }
     }
@@ -308,5 +311,4 @@
       addColumn("DEC_EXT_SIGMA", NULL, 0);
       addColumn("POSANG_EXT", NULL, 0);
-      addColumn("PLTSCALE_EXT", NULL, 0);
       addColumn("EXT_FLUX", NULL, 0);
       addColumn("EXT_CAL_MAG", NULL, 0);
Index: /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.dat
===================================================================
--- /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.dat	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.dat	(revision 34735)
@@ -12,5 +12,5 @@
 #          JD           TAI-UTC    Const 1       Const 2
 #        (days)          (sec)      (none)       (none)
-#          psF64	         psF64      psF64         psF64
+#         psF64	        psF64      psF64         psF64
         2437300.5      1.4228180    37300.0     0.0012960
         2437512.5      1.3728180    37300.0     0.0012960
@@ -51,2 +51,3 @@
 	2453736.5     33.0000000    41317.0     0.0000000
 	2454832.5     34.0000000    41317.0     0.0000000
+        2456109.5     35.0000000    41317.0     0.0000000
Index: /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.raw
===================================================================
--- /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.raw	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psLib/share/tai_utc.raw	(revision 34735)
@@ -37,2 +37,3 @@
  2006 JAN  1 =JD 2453736.5  TAI-UTC=  33.0       S + (MJD - 41317.) X 0.0      S
  2009 JAN  1 =JD 2454832.5  TAI-UTC=  34.0       S + (MJD - 41317.) X 0.0      S
+ 2012 JUL  1 =JD 2456109.5  TAI-UTC=  35.0       S + (MJD - 41317.) X 0.0      S
Index: /branches/eam_branches/ipp-20120905/psLib/src/imageops/psImageConvolve.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psLib/src/imageops/psImageConvolve.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psLib/src/imageops/psImageConvolve.c	(revision 34735)
@@ -605,6 +605,16 @@
     PS_ASSERT_IMAGE_NON_NULL(image, false);
 
+    if (sigma < 0.25) {
+        psTrace("psLib.imageops", 5, "sigma: %f < 0.25 skipping smoothing", sigma);
+        return true;
+    }
+
     // relevant terms
     int Nrange = sigma*Nsigma + 0.5;    // Number of pixels either side for convolution kernel
+    if (Nrange < 1) {
+        // using zero will cause an arithmetic exception in the loop
+        psTrace("psLib.imageops", 5, "Nrange %d for smoothing too small skipping smoothing", Nrange);
+        return true;
+    }
     int Nx = image->numCols;            // Number of columns
     int Ny = image->numRows;            // Number of rows
Index: /branches/eam_branches/ipp-20120905/psLib/src/math/psHistogram.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psLib/src/math/psHistogram.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psLib/src/math/psHistogram.c	(revision 34735)
@@ -58,5 +58,5 @@
     psTrace("psLib.math", 3, "---- %s() begin  ----\n", __func__);
     psTrace("psLib.math", 5, "(lower, upper, n) is (%f, %f, %d)\n", lower, upper, n);
-    psAssert(n > 0, "Number of bins must be positive");
+    psAssert(n > 0, "Number of bins must be positive not %d", n);
     psAssert(upper >= lower, "Bounds must be sensical");
 
Index: /branches/eam_branches/ipp-20120905/psLib/src/math/psStats.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psLib/src/math/psStats.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psLib/src/math/psStats.c	(revision 34735)
@@ -764,4 +764,8 @@
             goto escape;
         }
+        if (!isfinite(max - min)) {
+            COUNT_WARNING(10, 100, "Range of of the input vector is too large: %lf.\n", (double)max - (double) min);
+            goto escape;
+        }
         psTrace(TRACE, 6, "Data min/max is (%.2f, %.2f)\n", min, max);
 
@@ -802,4 +806,9 @@
         psTrace(TRACE, 6, "Numbins is %ld\n", numBins);
         psTrace(TRACE, 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max);
+
+        // We are sometimes causing psHistogramAlloc to assert.
+        // Assert here so we can get more information about what is going wrong.
+        psAssert(numBins > 0, "Invalid numBins: %ld max: %f min: %f binSize: %f", numBins, max, min, binSize);
+        
         // Generate the histogram
         histogram = psHistogramAlloc(min - 2.0*binSize, max + 2.0*binSize, numBins);
@@ -858,4 +867,8 @@
             // if we did not mask anything, give up.
         }
+
+        // We were causing psHistogramAlloc to assert. 
+        // Assert here so we can get more information about what is going wrong.
+        psAssert(numBins > 0, "Invalid numBins %ld max: %f min: %f binSize: %f", numBins, max, min, binSize);
 
         // ADD step 1: Convert the specific histogram to a cumulative histogram
Index: /branches/eam_branches/ipp-20120905/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psModules/src/objects/pmSourceIO.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psModules/src/objects/pmSourceIO.c	(revision 34735)
@@ -1028,4 +1028,5 @@
 	if (strcmp (xtension, "BINTABLE")) {
 	    psWarning ("no binary table in extension %s, skipping\n", dataname);
+            psFree(tableHeader);
 	    return false;
 	}
@@ -1242,4 +1243,5 @@
     if (!xtension) psAbort("cannot read table type");
     if (strcmp (xtension, "BINTABLE")) {
+        psFree(tableHeader);
         psWarning ("no binary table in extension %s, skipping\n", xsrcname);
         return false;
@@ -1281,4 +1283,5 @@
     if (strcmp (xtension, "BINTABLE")) {
         psWarning ("no binary table in extension %s, skipping\n", extname);
+        psFree(tableHeader);
         return false;
     }
@@ -1318,4 +1321,5 @@
     if (strcmp (xtension, "BINTABLE")) {
         psWarning ("no binary table in extension %s, skipping\n", extname);
+        psFree(tableHeader);
         return false;
     }
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotDeblendSatstars.c	(revision 34735)
@@ -498,5 +498,5 @@
     psStatsInit (fluxStats);
 
-    while (logR->data.F32[bin] < lRmax) {
+    while (bin < logR->n && logR->data.F32[bin] < lRmax) {
       if (isfinite(flux->data.F32[bin])) {
 	  psVectorAppend (fluxVals, flux->data.F32[bin]);
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotReplaceUnfit.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotReplaceUnfit.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotReplaceUnfit.c	(revision 34735)
@@ -35,8 +35,6 @@
     // loop over the available readouts
     for (int i = 0; i < num; i++) {
-	if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) {
-	    psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i);
-	    return false;
-	}
+        // ignore return value. False means "sources not subtracted", not a failure condition
+	(void) psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, ignoreState);
     }
     return true;
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFs.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFs.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFs.c	(revision 34735)
@@ -108,16 +108,13 @@
     bool notMatched = psMetadataLookupBool(NULL, readoutOut->analysis, "NOT.PSF.MATCHED");
     if (notMatched) {
-        if (!readoutOut->image) {
-            // our images got freed in the matching process. Recreate them so that they
-            // are available when sources are copied to this readout.
-            readoutOut->image = psImageCopy(NULL, readoutSrc->image, PS_TYPE_F32);
-            if (readoutSrc->variance) {
-                psFree(readoutOut->variance);
-                readoutOut->variance = psImageCopy(NULL, readoutSrc->variance, PS_TYPE_F32);
-            }
-            if (readoutSrc->mask) {
-                psFree(readoutOut->mask);
-                readoutOut->mask = psImageCopy(NULL, readoutSrc->mask, PS_TYPE_IMAGE_MASK);
-            }
+        psFree(readoutOut->image);
+        readoutOut->image = psImageCopy(NULL, readoutSrc->image, PS_TYPE_F32);
+        psFree(readoutOut->variance);
+        if (readoutSrc->variance) {
+            readoutOut->variance = psImageCopy(NULL, readoutSrc->variance, PS_TYPE_F32);
+        }
+        psFree(readoutOut->mask);
+        if (readoutSrc->mask) {
+            readoutOut->mask = psImageCopy(NULL, readoutSrc->mask, PS_TYPE_IMAGE_MASK);
         }
     }
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFsUtils.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFsUtils.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotStackMatchPSFsUtils.c	(revision 34735)
@@ -303,9 +303,14 @@
 	if (!pmSubtractionMatch(NULL, readoutOut, fake, readoutSrc, footprint, stride, regionSize, spacing, threshold, stampSources, stampsName, type, size, order, widthsCopy, orders, inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh, iter, rej, normFrac, sysError, skyErr, kernelError, covarFrac, maskVal, maskBad, maskPoor, poorFrac, badFrac, PM_SUBTRACTION_MODE_2)) {
             int errorCode = psErrorCodeLast();
-            if (errorCode == PM_ERR_SMALL_AREA) {
+            if (errorCode == PM_ERR_SMALL_AREA || errorCode == PM_ERR_STAMPS) {
                 // failed to match but, don't fault. Just drop this input from measurements that need the
                 // matched readout.
+                psErrorClear();
                 rejectReadout = true;
-                psLogMsg("psphot", PS_LOG_WARN, "PSF match failed for input %d. Too few pixels.", index);
+                if (errorCode == PM_ERR_SMALL_AREA) {
+                    psLogMsg("psphot", PS_LOG_WARN, "PSF match failed for input %d. Too few pixels.", index);
+                } else if (errorCode == PM_ERR_STAMPS) {
+                    psLogMsg("psphot", PS_LOG_WARN, "PSF match failed for input %d. Failed to find stamps.", index);
+                }
             } else {
                 psError(psErrorCodeLast(), false, "Unable to match images.");
@@ -324,6 +329,8 @@
     
     if (rejectReadout) {
+        psMetadataAddBool(readoutSrc->analysis, PS_LIST_TAIL, "NOT.PSF.MATCHED", PS_META_REPLACE, "", true);
         psMetadataAddBool(readoutOut->analysis, PS_LIST_TAIL, "NOT.PSF.MATCHED", PS_META_REPLACE, "", true);
     } else {
+        psMetadataAddBool(readoutSrc->analysis, PS_LIST_TAIL, "NOT.PSF.MATCHED", PS_META_REPLACE, "", false);
         psMetadataAddBool(readoutOut->analysis, PS_LIST_TAIL, "NOT.PSF.MATCHED", PS_META_REPLACE, "", false);
     }
Index: /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c
===================================================================
--- /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/psphot/src/psphotStackReadout.c	(revision 34735)
@@ -409,9 +409,10 @@
             }
         }
+        // mark any inputs that we want to skip the matched apertures for
+        psphotStackSetInputsToSkip(config, view, STACK_CNV, true);
+        psphotStackSetInputsToSkip(config, view, STACK_OUT, true);
         psphotRadialApertures (config, view, STACK_CNV, 0); // entry 0 == unmatched
         psMemDump("extmeas");
 
-        // mark any inputs that we want to skip the matched apertures for
-        psphotStackSetInputsToSkip(config, view, STACK_OUT, true);
 
         int nRadialEntries = psphotStackMatchPSFsEntries(config, view, STACK_OUT);
@@ -439,4 +440,5 @@
         }
     }
+    psphotStackSetInputsToSkip(config, view, STACK_CNV, false);
     psphotStackSetInputsToSkip(config, view, STACK_OUT, false);
 
Index: /branches/eam_branches/ipp-20120905/pstamp/scripts/psmkreq
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/scripts/psmkreq	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/scripts/psmkreq	(revision 34735)
@@ -52,11 +52,4 @@
 my $comment;
 
-my $survey_name = 'null';
-my $release = 'null';
-my $stack_type = 'null';
-my $bgrestore;
-my $jpeg;
-my $nocompress;
-
 my $missing_tools;
 my $pstamp_request_file  = can_run('pstamp_request_file')  or (warn "Can't find required program pstamp_request_file"  and $missing_tools = 1);
@@ -75,6 +68,5 @@
     'width=i'           => \$width,
     'height=i'          => \$height,
-# pixcenter is deprecated
-#    'pixcenter'         => \$pixcenter,
+    'pixcenter'         => \$pixcenter,
     'arcseconds'        => \$arcseconds,
     'coord_mask=i'      => \$coord_mask,
@@ -95,14 +87,9 @@
     'comment=s'         => \$comment,
 
-    # new columns for version 2
-    'survey=s'          => \$survey_name,
-    'release=s'         => \$release,
-    'stack_type'        => \$stack_type,
-
     'option_mask=i'     => \$option_mask,
     'image'             => \$image,
     'mask'              => \$mask,
     'variance'          => \$variance,
-    'sources'           => \$cmf,
+    'cmf'               => \$cmf,
     'psf'               => \$psf,
     'backmdl'           => \$backmdl,
@@ -112,8 +99,4 @@
     'do_not_wait'       => \$no_wait,
 
-    # new options for version 2
-    'no_compress'       => \$nocompress,
-    'bgrestore'         => \$bgrestore,
-
     'verbose'           => \$verbose,
     'save-temps'        => \$save_temps,
@@ -127,7 +110,7 @@
 
 pod2usage( -msg => "Invalid job_type: $job_type", -exitval =>1 )
-        unless ($job_type eq 'stamp' or $job_type eq 'get_image' or $job_type eq 'listtargets');
-
-if (($job_type eq 'stamp') or ($job_type eq 'listtargets')) {
+        unless ($job_type eq 'stamp' or $job_type eq 'get_image');
+
+if ($job_type eq 'stamp') {
     if (defined $list) {
         pod2usage( -msg => "--ra --dec --x --y are not used with --list", -exitval =>1 )
@@ -169,7 +152,6 @@
 $id = 0 if !$id;
 
-
-unless (($job_type eq 'listtargets' and $stage eq 'exposure') or $stage eq 'raw' or $stage eq 'chip' or $stage eq 'warp' or $stage eq 'diff' or $stage eq 'stack') {
-    die "$stage is not a valid stage for $job_type jobs\n";
+unless ($stage eq 'raw' or $stage eq 'chip' or $stage eq 'warp' or $stage eq 'diff' or $stage eq 'stack') {
+    die "$stage is not a valid value for stage\n";
 }
 
@@ -225,16 +207,16 @@
 } else {
     $rows = [];
-    push @$rows, buildRow("", $comment, $x, $y, $filter, $mjd_min, $mjd_max, $survey_name, $release, $stack_type);
+    push @$rows, buildRow("", $comment, $x, $y, $filter, $mjd_min, $mjd_max);
 }
 
 my ($tdf, $table_def_name) = tempfile ("/tmp/tabledef.XXXX", UNLINK => !$save_temps);
-print $tdf "$req_name 2\n";
+print $tdf "$req_name 1\n";
 my $rownum = 0;
 foreach my $row (@$rows) {
     $rownum++;
     my $line = "$rownum $row->{ra}\t$row->{dec}\t$width $height"
-        . " $coord_mask $job_type $option_mask $project $row->{survey_name} $row->{release} $req_type"
+        . " $coord_mask $job_type $option_mask $project $req_type"
         . " $stage $id $tess_id $component $data_group"
-        . " $row->{filter} $row->{mjd_min} $row->{mjd_max} $row->{stack_type}";
+        . " $row->{filter} $row->{mjd_min} $row->{mjd_max}";
 
     if ($row->{comment} and $row->{comment} ne '') {
@@ -248,7 +230,4 @@
 }
 close $tdf;
-
-system "cat $table_def_name";
-#exit 0;
 
 {
@@ -298,9 +277,6 @@
     $row->{dec}     = checkDEC($vals[1], $linenumber);
     $row->{filter}  = checkFilter($vals[2], $filter, $linenumber);
-    $row->{mjd_min} = checkMJD($vals[3], $mjd_min, $linenumber);
-    $row->{mjd_max} = checkMJD($vals[4], $mjd_max, $linenumber);
-    $row->{survey_name}  = $vals[5];
-    $row->{release} = $vals[6];
-    $row->{stack_type} = $vals[7];
+    $row->{mjd_min} = checkMJD($vals[3], $mjd_min, $linenumber);;
+    $row->{mjd_max} = checkMJD($vals[4], $mjd_max, $linenumber);;
     $row->{comment} = $comment;
 
Index: /branches/eam_branches/ipp-20120905/pstamp/scripts/pstamp_checkdependent.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/scripts/pstamp_checkdependent.pl	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/scripts/pstamp_checkdependent.pl	(revision 34735)
@@ -262,7 +262,9 @@
         } elsif ($chip->{state} eq 'goto_cleaned') {
 
-            if ($chip->{data_state} eq 'full') {
-                # cleanup has been queued, but has not yet finished. (cleanup pantasks is probably stopped)
-                # Since this chip is in full go ahead and set the run to state update and change the label.
+            # we don't need to check for full data_state
+            # if ($chip->{data_state} eq 'full') {
+            {
+                # cleanup must not be running. Set state to update. If this chip is not 'full' it will be
+                # set to be updated the next time this script is invoked
                 # XXX: In the very rare case that this chip run is actually in the running cleanup pantasks
                 # queue things may get confused but we can live with that
@@ -341,4 +343,10 @@
     }
 }
+
+    my $tess_id = $metadata->{tess_id};
+    if ($tess_id eq 'RINGS.V0') {
+        # we have stopped updating data from RINGS.V0
+        return $PSTAMP_GONE
+    }
     if (($state =~ /error/) or ($state =~ /purged/) or ($state =~ /scrubbed/) or ($state eq 'drop') or
          ($data_state =~ /error/) or ($data_state =~ /purged/) or ($data_state =~ /scrubbed/) or ($data_state eq 'drop')) {
@@ -365,7 +373,9 @@
     my $skycell = $metadata;
 
-    if ($skycell->{state} eq 'goto_cleaned' and $skycell->{data_state} eq 'full') {
-        # cleanup has been queued, but hasn't been done. it's "safe" to set the state back to full
-        # XXX: seem comments in check_states_chip
+    # if ($skycell->{state} eq 'goto_cleaned' and $skycell->{data_state} eq 'full') {
+    if ($skycell->{state} eq 'goto_cleaned') {
+        # cleanup has been queued, but hasn't finished, probably due to an error or cleanup is not running.
+        # It's "safe" to set the state to update. If the skycell is not full it will be set to update
+        # the next time this task runs
         my $command = "$warptool -updaterun -set_state update -warp_id $warp_id";
         $command .= " -set_label $rlabel" if $rlabel;
@@ -468,5 +478,8 @@
     my $skycell_id = $skycell->{skycell_id};
 
-    if ($metadata->{state} eq 'goto_cleaned' and $metadata->{data_state} eq 'full') {
+    # if ($metadata->{state} eq 'goto_cleaned' and $metadata->{data_state} eq 'full') {
+    if ($metadata->{state} eq 'goto_cleaned') {
+        # cleanup must not be running. Set state to update. If the skycell is not 'full' it will be
+        # set to be updated the next time this script is invoked
         print "changing state of diffRun $diff_id from goto_cleaned to update. skycell $skycell_id is full\n";
         my $command = "$difftool -updaterun -set_state update -diff_id $diff_id";
Index: /branches/eam_branches/ipp-20120905/pstamp/src/ppstampArguments.c
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/ppstampArguments.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/ppstampArguments.c	(revision 34735)
@@ -25,6 +25,9 @@
     fprintf(stderr, "   [-mask   mk_image]    : mask image\n");
     fprintf(stderr, "   [-variance var_image] : variance image\n");
+    fprintf(stderr, "   [-sources sources]    : sources cmf (ignored for chip stage)\n");
     fprintf(stderr, "   [-stage stage]        : stage of input image (raw, chip, warp, stack, diff)\n");
     fprintf(stderr, "   [-write_jpeg]         : write a JPEG  format of the image stamp\n");
+    fprintf(stderr, "   [-write_cmf]          : create an output cmf with the sources overlapping the stamp\n");
+    fprintf(stderr, "   [-wholefile]          : ignore the region of interest and process the entire input image\n");
     // fprintf(stderr, "   [-no_censor_masked]   : do not set masked pixels to NAN\n");
     fprintf(stderr, "\n");
@@ -92,17 +95,39 @@
         options->stage = psStringCopy(argv[argnum]);
         psArgumentRemove(argnum, &argc, argv);
+    } else {
+        // Should we require this? 
+        options->stage = psStringCopy("unknown");
     }
     if ((argnum = psArgumentGet(argc, argv, "-write_jpeg"))) {
         psArgumentRemove(argnum, &argc, argv);
         options->writeJPEG = true;
-    } else {
-        options->writeJPEG = false;
+    }
+    if ((argnum = psArgumentGet(argc, argv, "-write_cmf"))) {
+        psArgumentRemove(argnum, &argc, argv);
+        options->writeCMF = true;
     }
 
-    pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist");
+    // XXX: Note: the various list options have never been tested with ppstamp to my knowledge
+    bool gotAstrom = false;
+    if ((argnum = psArgumentGet(argc, argv, "-astrom"))) {
+        gotAstrom = true;
+        pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist");
+    }
     pmConfigFileSetsMD(config->arguments, &argc, argv, "MASK",   "-mask", "-masklist");
     pmConfigFileSetsMD(config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
 
-    // the input file is a required argument; if not found, we will exit
+    if ((argnum = psArgumentGet(argc, argv, "-sources"))) {
+        pmConfigFileSetsMD(config->arguments, &argc, argv, "SOURCES", "-sources", "-sourceslist");
+        // supplying a sources file implies that we want to save the output
+        options->writeCMF = true;
+    } else if (options->writeCMF && !gotAstrom) {
+        // if we didn't get a sources file but the user wanted us to write the sources we must
+        // have an astrometry file supplied
+        // XXX: Is this too restrictive? Could the sources be contained in say the input file?
+        psError(PSTAMP_ERR_ARGUMENTS, true, "cannot write cmf file unless input sources are supplied\n");
+        usage();
+    }
+
+    // the input image file is a required argument; if not found, we will exit
     bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     if (!status) {
@@ -126,5 +151,5 @@
     }
 
-    // finally the output file
+    // finally the only argument left must be output outroot
     if (argc < 2) {
         psError(PSTAMP_ERR_ARGUMENTS, true, "must specify OUTPUT\n");
@@ -135,8 +160,5 @@
     }
 
-    // Add the output image (which remains on the command-line) to the arguments list
     psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]);
-
-    // psMetadataPrint(stdout, config->arguments,0);
 
     return config;
Index: /branches/eam_branches/ipp-20120905/pstamp/src/ppstampMakeStamp.c
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/ppstampMakeStamp.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/ppstampMakeStamp.c	(revision 34735)
@@ -19,4 +19,5 @@
 static void chipToSky(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
 static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
+static bool copySources(pmReadout *outputReadout, pmReadout *inputReadout, pmReadout *astromReadout, psRegion extractRegion);
 
 // convert the input chip's transforms to the output
@@ -80,19 +81,26 @@
 }
 
-static bool copyMetadata(pmFPAfile *output, pmFPAfile *input, pmChip *inChip, ppstampOptions *options, pmAstromObj *center)
+static bool copyMetadata(pmFPAfile *output, pmFPAfile *input, pmChip *inChip, ppstampOptions *options, pmAstromObj *center, pmFPAfile *astrom, pmFPAview *inView)
 {
     pmChip    *outChip;
-    pmFPAview *view = pmFPAviewAlloc(0);
+    pmFPAview *outView = pmFPAviewAlloc(0);
 
     // our output file has a single chip
-    view->chip = 0;
-    outChip = pmFPAviewThisChip(view, output->fpa);
-    psFree(view);
-
-    // copy data from the input chip header to the output.
+    outView->chip = 0;
+    outChip = pmFPAviewThisChip(outView, output->fpa);
+    psFree(outView);
+    pmHDU *outHDU = pmHDUGetHighest(output->fpa, outChip, NULL);
+
+    // copy data from the input's chip header to the output.
     // since some of the keywords might be duplicated we may not want to copy both
 
-    pmHDU *inHDU  = pmHDUFromChip(inChip);
-    pmHDU *outHDU = pmHDUGetHighest(output->fpa, outChip, NULL);
+    pmHDU *inHDU  = NULL;
+    if (strcmp(options->stage, "raw") && input != astrom) {
+        // Copy the header from the astrometry file since it contains the psphot and psastro results
+        pmChip *astromChip = pmFPAviewThisChip(inView, astrom->fpa);
+        inHDU  = pmHDUFromChip(astromChip);
+    } else {
+        inHDU  = pmHDUFromChip(inChip);
+    }
 
     if (inHDU->header) {
@@ -102,7 +110,10 @@
     }
 
-    // copy the fpa concepts
+    // copy the fpa and chip concepts
     pmConceptsCopyFPA(output->fpa, input->fpa, false, false);
+    // Needed to preserve FPA.ZP
     pmConceptsCopyChip(outChip, inChip, false);
+
+    // copy the cell concepts (needed to get CELL.EXPOSURE which gets used to set EXPTIME)
     pmCell *outCell = outChip->cells->data[0]; // The only output cell
 
@@ -122,5 +133,5 @@
     }
 
-    // If input had WCS convert it for stamp
+    // If input had WCS convert it for the new image coordinate system of our stamp
     if (input->fpa->toSky) {
         // copy the input fpa's transforms
@@ -135,9 +146,21 @@
         }
     } else {
-        psWarning("No WCS present in input\n");
-    }
-
+        psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "No WCS present in input.");
+    }
+
+    // Save our specific metadata
     psMetadataAddF64(outHDU->header, PS_LIST_TAIL, "RA_DEG", PS_META_REPLACE, "Right Ascension of stamp center", RAD_TO_DEG(center->sky->r));
     psMetadataAddF64(outHDU->header, PS_LIST_TAIL, "DEC_DEG", PS_META_REPLACE, "Declination of stamp center", RAD_TO_DEG(center->sky->d));
+
+    // XXX: TODO: save the region of interest boundary and the offset to be applied. 
+    // XXX: Gene thinks that there may be a way to handle this in the WCS
+
+    // Now a few sanity checks
+    // Make sure zero point in the fpa concepts matches the observed value in the input header
+    bool status;
+    float zpt_obs = psMetadataLookupF32(&status, outHDU->header, "ZPT_OBS");
+    if (status) {
+        psMetadataAddF32(output->fpa->concepts, PS_LIST_TAIL, "FPA.ZP", PS_META_REPLACE, "Magnitude zero point", zpt_obs);
+    }
 
     ppstampVersionMetadata(outHDU->header, options);
@@ -324,7 +347,7 @@
 
             if (options->censorMasked && !setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) {
-                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
-                 status = false;
-                 break;
+                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
+                status = false;
+                break;
             }
         }
@@ -335,4 +358,16 @@
         status = true;
 
+        if (options->writeCMF) {
+            pmReadout *astromReadout = NULL;
+            if (astrom->fpa != input->fpa) {
+                astromReadout = pmFPAviewThisReadout(srcView, astrom->fpa);
+            }
+            if (!copySources(outReadout, astromReadout, astromReadout, extractRegion)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to extract sources from region of interest.\n");
+                status = false;
+                break;
+            }
+        }
+
         psFree(outReadout); // drop reference
     }
@@ -341,5 +376,6 @@
 
     if (status) {
-        status = copyMetadata(output, input, inChip, options, center);
+        // For raw stage we need to do more work to build a proper header
+        status = copyMetadata(output, input, inChip, options, center, astrom, view);
     }
     return status ? PS_EXIT_SUCCESS : PS_EXIT_UNKNOWN_ERROR;
@@ -428,11 +464,12 @@
     double dy = 0.5 * options->roip.dDEC / fpa->toSky->Ys;
 
-    if (dx > 5000) {
-        fprintf(stderr, "requested width %f too large reducing to 5000\n", dx);
-        dx = 5000;
-    }
-    if (dy > 5000) {
-        fprintf(stderr, "requested height %f too large reducing to 5000\n", dy);
-        dy = 5000;
+    // XXX: why do we limit this?
+    if (dx > 8000) {
+        psWarning( "requested width %f too large reducing to 8000\n", dx);
+        dx = 8000;
+    }
+    if (dy > 8000) {
+        psWarning( "requested height %f too large reducing to 8000\n", dy);
+        dy = 8000;
     }
 
@@ -480,6 +517,4 @@
     ppstampOverlap   returnval = PPSTAMP_OFF;
 
-//    fprintf(stderr, "ppstampChipBounds: %s\n", psRegionToString(*chipBounds));
-
     // set up the astrometry
     pmHDU *hdu = pmFPAviewThisHDU(view, astrom->fpa);
@@ -498,5 +533,4 @@
         }
     } else {
-        // we use a default FPA pixel scale of 1.0
         if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0) && mustHaveAstrometry) {
             psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");
@@ -537,5 +571,7 @@
             center->chip->yErr = 0;
             onChip = true;
-            chipToSky(center, input->fpa, chip);
+            if (input->fpa->toSky) {
+                chipToSky(center, input->fpa, chip);
+            }
         }
     }
@@ -550,11 +586,11 @@
                 int width  = options->roip.dX;
                 int height = options->roip.dY;
-                if (width > 7000) {
-                    fprintf(stderr, "requested width %d too large reducing to 7000\n", width);
-                    width = 7000;
+                if (width > 8000) {
+                    psWarning( "requested width %d too large reducing to 8000\n", width);
+                    width = 8000;
                 }
-                if (height > 7000) {
-                    fprintf(stderr, "requested height %d too large reducing to 7000\n", height);
-                    height = 7000;
+                if (height > 8000) {
+                    psWarning( "requested height %d too large reducing to 8000\n", height);
+                    height = 8000;
                 }
 
@@ -675,5 +711,5 @@
 
     if (!foundOverlap && (returnval == PS_EXIT_SUCCESS)) {
-        fprintf(stderr, "ROI not found in input\n");
+        psWarning( "ROI not found in input\n");
         returnval = PSTAMP_NO_OVERLAP;
     }
@@ -739,7 +775,63 @@
     }
 
-    // XXX: this shouldn't be a fprintf
-    fprintf(stderr, "Censored %ld masked pixels\n", numCensored);
+    psLogMsg("ppstamp", PS_LOG_DETAIL, "Censored %ld masked pixels\n", numCensored);
 
     return true;
 }
+
+static bool copySources(pmReadout *outReadout, pmReadout *inReadout, pmReadout *astromReadout, psRegion extractRegion) {
+    bool status;
+
+    // first look for detections in the input readout. Those would have come from the -sources file
+    pmDetections *inDetections = psMetadataLookupPtr (&status, inReadout->analysis, "PSPHOT.DETECTIONS");
+    if (!inDetections) {
+        // No detections on the input readout. Try the astrometry readout if supplied.
+        if (astromReadout) {
+            inDetections = psMetadataLookupPtr (&status, astromReadout->analysis, "PSPHOT.DETECTIONS");
+            if (!inDetections) {
+                psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no detections found on input or astrometry readout\n");
+                return false;
+            } else {
+                psLogMsg("ppstampMakeStamp", PS_LOG_INFO, "using detections from astrom file\n");
+            }
+        } else {
+            psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no detections found on input readout\n");
+            return false;
+        }
+    }
+    if (!inDetections->allSources) {
+        psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no sources array found on detections structure\n");
+        return false;
+    }
+
+    // Ok we have sources, allocate a detections structure and copy them to the output readout
+    psArray *inSources = inDetections->allSources;
+
+    pmDetections *outDetections = pmDetectionsAlloc();
+    psMetadataAddPtr (outReadout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN,
+        "psphot detections", outDetections);
+
+    psArray *outSources = outDetections->allSources = psArrayAllocEmpty( 100 );
+
+    // include sources that are off the stamp by just a little bit
+    #define EXPAND_SIZE 16
+    psRegion sourceRegion = extractRegion;
+    sourceRegion.x0 -= EXPAND_SIZE;
+    sourceRegion.y0 -= EXPAND_SIZE;
+    sourceRegion.x1 += EXPAND_SIZE;
+    sourceRegion.y1 += EXPAND_SIZE;
+
+    for (int i = 0; i < inSources->n; i++ ) {
+        pmSource *src = inSources->data[i];
+
+        float x = src->peak->xf;
+        float y = src->peak->yf;
+        if (x < sourceRegion.x0 || x > sourceRegion.x1 ||
+            y < sourceRegion.y0 || y > sourceRegion.y1) {
+            continue;
+        }
+        psArrayAdd(outSources, 100, src);
+    }
+
+    return true;
+}
Index: /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.c
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.c	(revision 34735)
@@ -32,4 +32,5 @@
     options->censorMasked = false;
     options->writeJPEG = false;
+    options->writeCMF = false;
     options->nocompress = false;
     options->wholeFile = false;
Index: /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.h
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.h	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/ppstampOptions.h	(revision 34735)
@@ -14,4 +14,5 @@
     bool        censorMasked;
     bool        writeJPEG;
+    bool        writeCMF;
     bool        nocompress;
     //
Index: /branches/eam_branches/ipp-20120905/pstamp/src/ppstampParseCamera.c
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/ppstampParseCamera.c	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/ppstampParseCamera.c	(revision 34735)
@@ -120,4 +120,34 @@
     }
 
+    // Set up the input and output sources files if needed
+    if (options->writeCMF) {
+        bool status;
+
+        // see if -sources file was supplied. 
+        // If so define the file.
+        psPtr sourcesFile = psMetadataLookupStr(&status, config->arguments, "SOURCES");
+        if (sourcesFile) {
+            pmFPAfile *sources = pmFPAfileBindFromArgs(&status, input, config, "PPSTAMP.INPUT.SOURCES", "SOURCES");
+            if (!status) {
+                psError(psErrorCodeLast(), false, "Failed to load file definition for PPSTAMP.INPUT.SOURCES");
+                return false;
+            }
+            if (!sources && !astrom) {
+                psError(psErrorCodeLast(), false, "Failed to define input sources file");
+                return false;
+            }
+        } else {
+            psLogMsg ("ppstamp", PS_LOG_INFO, "output sources file requested but no input supplied. Will try the supplied astrometry file.\n");
+        }
+        
+        pmFPAfile *outputSources = NULL;
+        outputSources = pmFPAfileDefineSkycell(config, output->fpa, "PPSTAMP.OUTPUT.SOURCES");
+        if (!outputSources) {
+            psError(psErrorCodeLast(), false, "Failed to define output sources file");
+            return false;
+        }
+        outputSources->save = true;
+    }
+
     pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSTAMP.CHIP");
     if (!chipImage) {
Index: /branches/eam_branches/ipp-20120905/pstamp/src/pstamp.h
===================================================================
--- /branches/eam_branches/ipp-20120905/pstamp/src/pstamp.h	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/pstamp/src/pstamp.h	(revision 34735)
@@ -26,15 +26,24 @@
 
 // values for options mask.
-#define PSTAMP_SELECT_IMAGE      1
-#define PSTAMP_SELECT_MASK       2
-#define PSTAMP_SELECT_WEIGHT     4
-#define PSTAMP_SELECT_CMF        8
-#define PSTAMP_SELECT_PSF       16
-#define PSTAMP_SELECT_BACKMDL   32
-#define PSTAMP_SELECT_INVERSE 1024
-#define PSTAMP_SELECT_UNCONV  2048
-#define PSTAMP_USE_IMFILE_ID 16384
+#define PSTAMP_SELECT_IMAGE         1
+#define PSTAMP_SELECT_MASK          2
+#define PSTAMP_SELECT_WEIGHT        4
+#define PSTAMP_SELECT_SOURCES       8
+#define PSTAMP_SELECT_CMF           8
+#define PSTAMP_SELECT_PSF           16
+#define PSTAMP_SELECT_BACKMDL       32
+#define PSTAMP_SELECT_JPEG          64
+// unused                           128
+// unused                           256
+#define PSTAMP_SELECT_UNCOMPRESSED  512
+#define PSTAMP_SELECT_INVERSE       1024
+#define PSTAMP_SELECT_UNCONV        2048
+#define PSTAMP_RESTORE_BACKGROUND   4096
+// unused                           8192
+#define PSTAMP_USE_IMFILE_ID        16384
 
-#define PSTAMP_NO_WAIT_FOR_UPDATE 32768
+#define PSTAMP_NO_WAIT_FOR_UPDATE   32768
+#define PSTAMP_REQUEST_UNCENSORED  0x10000
+#define PSTAMP_REQUIRE_UNCENSORED  0x20000
 
 #define PSTAMP_CENTER_IN_PIXELS 1
Index: /branches/eam_branches/ipp-20120905/tools/fixburntool
===================================================================
--- /branches/eam_branches/ipp-20120905/tools/fixburntool	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/tools/fixburntool	(revision 34735)
@@ -6,4 +6,5 @@
 use strict;
 use warnings;
+
 use Carp;
 use IPC::Cmd 0.36 qw( can_run run );
@@ -28,5 +29,5 @@
 my $class_id;
 my $dbname = 'gpc1';
-my $verbose = 1;
+my $verbose = 0;
 GetOptions(
     'exp_id|e=s'    => \$exp_id,
@@ -35,5 +36,5 @@
 ) or pod2usage( 2 );
 
-die "usage: $0 (exp_id) (class_id)\n" unless $class_id and $exp_id;
+die "usage: $0 --exp_id (exp_id) --class_id (class_id)\n" unless $class_id and $exp_id;
 
 $regtool  .= " -dbname gpc1 -exp_id $exp_id -class_id $class_id";
@@ -45,5 +46,5 @@
     my $command = "$regtool -processedimfile";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => 0);
+        run(command => $command, verbose => $verbose);
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
@@ -68,5 +69,5 @@
     my $command = "neb-stat $table";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => 0);
+        run(command => $command, verbose => $verbose);
     if ($success) {
         $table_exists = 1;
@@ -96,5 +97,4 @@
 # print "$left $num $end\n";
 
-
 my $prev = $num - 1;
 my $prev_name = sprintf "$left%04d$end", $prev;
@@ -105,10 +105,9 @@
 # print "$prev_name $prev_uri\n";
 
-
 {
     my $command = "$burntool --continue 10 --exp_id $exp_id --class_id $class_id --this_uri $uri --previous_uri $prev_uri";
     print "$command\n";
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => $command, verbose => 0);
+        run(command => $command, verbose => 1);
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
Index: /branches/eam_branches/ipp-20120905/tools/runwarpskycell.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/tools/runwarpskycell.pl	(revision 34734)
+++ /branches/eam_branches/ipp-20120905/tools/runwarpskycell.pl	(revision 34735)
@@ -16,5 +16,5 @@
 
 my $dbname = "gpc1";
-my ($warp_id, $skycell_id, $threads, $update, $redirect, $pretend, $save_temps);
+my ($warp_id, $skycell_id, $threads, $update, $redirect, $pretend, $save_temps, $outdir);
 my $zaplog;
 
@@ -26,4 +26,5 @@
     'zaplog'            => \$zaplog,
     'redirect-output'   => \$redirect,
+    'outdir=s'          => \$outdir,
     'update'            => \$update,
     'dbname=s'          => \$dbname,
@@ -74,4 +75,10 @@
 } else {
     die "unexpected warpRun.state found: $state\n";
+}
+
+if ($outdir) {
+    my $base = basename($path_base);
+    $path_base = "$outdir/$base";
+    print "changing path_base to $path_base\n";
 }
 
