Index: /branches/eam_branches/ipp-20120905/DataStore/lib/DataStore/FileSet.pm
===================================================================
--- /branches/eam_branches/ipp-20120905/DataStore/lib/DataStore/FileSet.pm	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/DataStore/lib/DataStore/FileSet.pm	(revision 34566)
@@ -109,4 +109,7 @@
 sub new
 {
+    # turn off param validation as it has been causing problems
+    local $Params::Validate::NO_VALIDATION = 1;
+
     my $class = shift;
 
Index: /branches/eam_branches/ipp-20120905/ippMonitor/czartool/czartool/czarconfig.xml
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/czartool/czartool/czarconfig.xml	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/czartool/czartool/czarconfig.xml	(revision 34566)
@@ -19,9 +19,15 @@
 
   <!-- gpc1 Db section -->
+<!--   <gpc1database> -->
+<!--     <name>gpc1</name> -->
+<!--     <host>scidbs1</host> -->
+<!--     <user>ippMonitor</user> -->
+<!--     <password>ippMonitor</password> -->
+<!--   </gpc1database> -->
   <gpc1database>
     <name>gpc1</name>
-    <host>scidbs1</host>
-    <user>ippMonitor</user>
-    <password>ippMonitor</password>
+    <host>scidbm</host>
+    <user>ippuser</user>
+    <password>ippuser</password>
   </gpc1database>
 
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/czartool_labels.php	(revision 34566)
@@ -219,4 +219,5 @@
       showReplicationsStatus($REPL_HOST_IPPADMIN, $REPL_USER_IPPADMIN, $REPL_PASSWORD_IPPADMIN, $REPL_DBNAME_IPPADMIN);
       showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
+      showReplicationsStatus($REPL_HOST_NEBULOUS_SECONDARY, $REPL_USER_NEBULOUS_SECONDARY, $REPL_PASSWORD_NEBULOUS_SECONDARY, $REPL_DBNAME_NEBULOUS_SECONDARY);
       echo "</table>";
 
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.css
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.css	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/ipp.css	(revision 34566)
@@ -144,5 +144,5 @@
 td.body  { 
            text-align: left; 
-           font-size: small;  
+           font-size: normal;  
            font-weight: normal;  
            vertical-align: top;
Index: /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in
===================================================================
--- /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippMonitor/raw/site.php.in	(revision 34566)
@@ -47,4 +47,8 @@
 $REPL_DBNAME_ISP = "ippc17 (isp)";
 
+$REPL_HOST_NEBULOUS_SECONDARY = "ippc63.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)";
 
 
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/ipp_apply_burntool_single.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/ipp_apply_burntool_single.pl	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/ipp_apply_burntool_single.pl	(revision 34566)
@@ -241,5 +241,5 @@
     $status = vsystem ($command, $REALRUN);
     if ($status) {
-	&my_die("failed to update imfile");
+	&my_die("failed to update imfile",$exp_id,$class_id);
     }
 
@@ -274,4 +274,5 @@
         my $exp_id = shift;
         my $class_id = shift;
+	sleep(5); # Take a quick nap to let the database cool down, in case we failed doing an update.
         vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state 0 -set_state pending_burntool",1);
     }
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/publish_file.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/publish_file.pl	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/publish_file.pl	(revision 34566)
@@ -32,4 +32,5 @@
 my $pubtool = can_run('pubtool') or (warn "Can't find pubtool" and $missing_tools = 1);
 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
+my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
 my $ppMops = can_run('ppMops') or (warn "Can't find ppMops" and $missing_tools = 1);
@@ -44,5 +45,5 @@
 my ( $pub_id, $camera, $stage, $stage_id, $fileset, $format, $product, $workdir, $need_magic );
 my ( $dbname, $verbose, $no_update, $no_op, $save_temps, $redirect );
-my ( $output_format );
+my ( $output_format, $difftype );
 
 GetOptions(
@@ -72,5 +73,6 @@
     defined $stage and
     defined $stage_id and
-    defined $workdir;
+    defined $workdir and
+    defined $dbname;
 
 my $outroot = "$workdir/$product.$pub_id"; # Output root name
@@ -166,5 +168,5 @@
     my %negative;               # Data for negative diff detections
     foreach my $comp ( @$components ) {
-        my $path_base = $comp->{path_base}; # Base name for file
+	my $path_base = $comp->{path_base}; # Base name for file
         if (!$need_magic and $comp->{magicked}) {
             # This client is authorized to receive uncensored detections
@@ -194,4 +196,45 @@
 
         $filename = $resolved;
+
+	my $cam_id = $comp->{cam_id_1};
+	#print "Getting info from camera stage $cam_id\n";
+	my $cam_command =  "$camtool -processedexp -cam_id $cam_id";
+	$cam_command .= " -dbname $dbname" if defined $dbname;
+	my ( $cam_success, $cam_error_code, $cam_full_buf, $cam_stdout_buf, $cam_stderr_buf ) =
+	    run(command => $cam_command, verbose => $verbose);
+	&my_die( "Unable to retrieve filename", $pub_id, $PS_EXIT_SYS_ERROR) unless $cam_success;
+	my $cam_metadata = $mdcParser->parse(join "", @$cam_stdout_buf) or
+	    &my_die("Unable to parse metadata config", $pub_id, $PS_EXIT_PROG_ERROR);
+	my $cam_components = parse_md_list($cam_metadata) or
+	    &my_die("Unable to parse metadata list", $pub_id, $PS_EXIT_PROG_ERROR);
+	&my_die("More than one entry for cam_id $stage_id", $pub_id, $PS_EXIT_PROG_ERROR) if scalar @$cam_components > 1;
+	my $cam_comp = $$cam_components[0];
+
+	my $exp_id = $comp->{exp_id_1};
+	#print "Getting info from raw stage $exp_id\n";
+	my $reg_command =  "$regtool -processedimfile -exp_id $exp_id";
+	$reg_command .= " -dbname $dbname" if defined $dbname;
+	my ( $reg_success, $reg_error_code, $reg_full_buf, $reg_stdout_buf, $reg_stderr_buf ) =
+	    run(command => $reg_command, verbose => $verbose);
+	&my_die( "Unable to retrieve filename", $pub_id, $PS_EXIT_SYS_ERROR) unless $reg_success;
+	my $reg_metadata = $mdcParser->parse(join "", @$reg_stdout_buf) or
+	    &my_die("Unable to parse metadata config", $pub_id, $PS_EXIT_PROG_ERROR);
+	my $reg_components = parse_md_list($reg_metadata) or
+	    &my_die("Unable to parse metadata list", $pub_id, $PS_EXIT_PROG_ERROR);
+	my $reg_comp = $$reg_components[0];
+
+	# Now get the difftype value from diff->{diff_mode}
+	my $difftype = "";
+	if ($comp->{diff_mode} == 1) {
+	    $difftype = "WW";
+	} elsif ($comp->{diff_mode} == 2) {
+	    $difftype = "WS";
+	} elsif ($comp->{diff_mode} == 3) {
+	    $difftype = "SW"; # Not used yet
+	} elsif ($comp->{diff_mode} == 4) {
+	    $difftype = "SS";
+	} else {
+	    $difftype = "Unsupported diff_mode value: [" . $comp->{diff_mode} . "]";
+	}
 
         my $data = { zp => $zp,
@@ -207,6 +250,12 @@
                      output_format => $comp->{output_format},
                      direction => 1,
+		     comment => $reg_comp->{comment},
+		     obsmode => $reg_comp->{obs_mode},
+		     difftype => $difftype,
+		     sky => $cam_comp->{bg},
+		     shutoutc => $reg_comp->{dateobs},
         };
 
+	#warn("Checking for positive");
         diff_check(\%positive, $data, "positive");
 
@@ -239,6 +288,12 @@
                          diff_id => $comp->{diff_id},
                          direction => 0,
+			 comment => $reg_comp->{comment},
+			 obsmode => $reg_comp->{obs_mode},
+			 difftype => $difftype,
+			 sky => $cam_comp->{bg},
+			 shutoutc => $reg_comp->{dateobs},
             };
 
+	    #warn("Checking for negative");
             diff_check(\%negative, $data, "negative");
 
@@ -288,6 +343,4 @@
     &my_die( "Unable to register with data store", $pub_id, $PS_EXIT_SYS_ERROR) unless $success;
 }
-
-
 
 ### Pau.
@@ -311,4 +364,9 @@
     $data->{diff_id} = $comp->{diff_id} unless defined $data->{diff_id};
     $data->{direction} = $comp->{direction} unless defined $data->{direction};
+    $data->{comment} = $comp->{comment} unless defined $data->{comment};
+    $data->{obsmode} = $comp->{obsmode} unless defined $data->{obsmode};
+    $data->{difftype} = $comp->{difftype} unless defined $data->{difftype};
+    $data->{sky} = $comp->{sky} unless defined $data->{sky};
+    $data->{shutoutc} = $comp->{shutoutc} unless defined $data->{shutoutc};
 
     &my_die("zp value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{zp} and $comp->{zp} != $data->{zp};
@@ -323,4 +381,9 @@
     &my_die("diff_id value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{diff_id} and $comp->{diff_id} != $data->{diff_id};
     &my_die("direction value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{direction} and $comp->{direction} != $data->{direction};
+    &my_die("comment value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{comment} and $comp->{comment} ne $data->{comment};
+    &my_die("obsmode value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{obsmode} and $comp->{obsmode} ne $data->{obsmode};
+    &my_die("difftype value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{difftype} and $comp->{difftype} ne $data->{difftype};
+    &my_die("sky value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{sky} and $comp->{sky} != $data->{sky};
+    &my_die("shutoutc value for $name doesn't match", $pub_id, $PS_EXIT_SYS_ERROR) if defined $data->{shutoutc} and $comp->{shutoutc} ne $data->{shutoutc};
 
     return 1;
@@ -350,4 +413,9 @@
     $command .= " -astrom_rms " . $data->{astrom} if defined $data->{astrom};
     $command .= " -version " . $data->{output_format} if defined $data->{output_format};
+    $command .= " -comment \"" . $data->{comment} . "\"" if defined $data->{comment};
+    $command .= " -obsmode " . $data->{obsmode} if defined $data->{obsmode};
+    $command .= " -difftype " . $data->{difftype} if defined $data->{difftype};
+    $command .= " -sky " . $data->{sky} if defined $data->{sky};
+    $command .= " -shutoutc \"" . $data->{shutoutc} . "\"" if defined $data->{shutoutc};
 
     unless ($no_op) {
Index: /branches/eam_branches/ipp-20120905/ippScripts/scripts/staticsky.pl
===================================================================
--- /branches/eam_branches/ipp-20120905/ippScripts/scripts/staticsky.pl	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippScripts/scripts/staticsky.pl	(revision 34566)
@@ -302,9 +302,10 @@
             $mask   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
             $variance = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
+            $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
         } else {
             $image  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
             $mask   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
             $variance = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
-            $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Weight name
+            $expnum = $ipprc->filename("PPSTACK.OUTPUT.EXPNUM", $path_base ); # Expnum name
         }
 
Index: /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/camtool.c	(revision 34566)
@@ -974,4 +974,6 @@
         return false;
     }
+    int numUpdated = psDBAffectedRows(config->dbh);
+    psLogMsg("camtool", PS_LOG_INFO, "Updated %d camProcessedExps", numUpdated);
 
     return true;
Index: /branches/eam_branches/ipp-20120905/ippTools/src/chiptool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/chiptool.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/chiptool.c	(revision 34566)
@@ -2066,4 +2066,5 @@
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     PXOPT_COPY_STR(config->args, where, "-state", "chipRun.state", "==");
+    PXOPT_COPY_STR(config->args, where, "-tess_id", "chipRun.tess_id", "LIKE");
     pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE");
     pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE");
Index: /branches/eam_branches/ipp-20120905/ippTools/src/chiptoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/chiptoolConfig.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/chiptoolConfig.c	(revision 34566)
@@ -254,4 +254,5 @@
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by chipRun label (LIKE comparison)", NULL);
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-state",              0, "search by chipRun state", NULL);
+    psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-tess_id",            0, "search by chipRun tess_id (LIKE comparison)", NULL);
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-data_group",  PS_META_DUPLICATE_OK, "search by chipRun data_group (LIKE comparison)", NULL);
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-dist_group",  PS_META_DUPLICATE_OK, "search by chipRun dist_group (LIKE comparison)", NULL);
Index: /branches/eam_branches/ipp-20120905/ippTools/src/difftool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/difftool.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/difftool.c	(revision 34566)
@@ -97,6 +97,6 @@
         MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP,        definewarpwarpMode);
         MODECASE(DIFFTOOL_MODE_DEFINESTACKSTACK,      definestackstackMode);
-	MODECASE(DIFFTOOL_MODE_TOSUMMARY,             tosummaryMode);
-	MODECASE(DIFFTOOL_MODE_ADDSUMMARY,            addsummaryMode);
+        MODECASE(DIFFTOOL_MODE_TOSUMMARY,             tosummaryMode);
+        MODECASE(DIFFTOOL_MODE_ADDSUMMARY,            addsummaryMode);
         MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
         MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode);
@@ -170,10 +170,10 @@
             exposure,
             false,
-	    NULL, // software version
-	    0,    // mask stat npix
-	    NAN,    // static
-	    NAN,    // dynamic
-	    NAN,    // magic
-	    NAN,    // advisory
+            NULL, // software version
+            0,    // mask stat npix
+            NAN,    // static
+            NAN,    // dynamic
+            NAN,    // magic
+            NAN,    // advisory
             diff_mode,
             note
@@ -579,7 +579,7 @@
     PXOPT_LOOKUP_F32(maskfrac_magic, config->args, "-maskfrac_magic", false, false);
     PXOPT_LOOKUP_F32(maskfrac_advisory, config->args, "-maskfrac_advisory", false, false);
-    
+
     psTrace("czw.test",1,"Received versions: pslib %s psmodules %s psphot %s ppstats %s ppsub %s streaks %s\n",
-	    ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppsub,ver_streaks);
+            ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppsub,ver_streaks);
     psString ver_code = NULL;
     if ((ver_pslib)&&(ver_psmodules)) {
@@ -631,11 +631,11 @@
                            fault,
                            quality,
-			   magicked,
-			   ver_code,
-			   maskfrac_npix,
-			   maskfrac_static,
-			   maskfrac_dynamic,
-			   maskfrac_magic,
-			   maskfrac_advisory
+                           magicked,
+                           ver_code,
+                           maskfrac_npix,
+                           maskfrac_static,
+                           maskfrac_dynamic,
+                           maskfrac_magic,
+                           maskfrac_advisory
           )) {
         if (!psDBRollback(config->dbh)) {
@@ -726,48 +726,48 @@
         psS64 magicked = psMetadataLookupS64(NULL, row, "magicked");
 
-	psString software_ver = NULL;
-	psS64 maskfrac_npix = 0;
-	psF32 maskfrac_static = 0;
-	psF32 maskfrac_dynamic = 0;
-	psF32 maskfrac_magic = 0;
-	psF32 maskfrac_advisory = 0;
-
-	// Calculate run level masking and software state
-	if (!pxCoalesceRunStatus(config,"difftool_coalesce_run.sql",diff_id,
-				 &software_ver,&maskfrac_npix,
-				 &maskfrac_static,&maskfrac_dynamic,
-				 &maskfrac_magic,&maskfrac_advisory)) {
-	  psError(PS_ERR_UNKNOWN, false, "failed to generate run level statistics");
-	  psFree(output);
-	  if (!psDBRollback(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	  }
-	  return(false);
-	}
-	// Set diffRun.software_ver to the appropriate value
-	if (software_ver) {
-	  if (!pxSetRunSoftware(config, "diffRun", "diff_id", diff_id, software_ver)) {
-	    psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,
-		    diff_id);
-	    psFree(output);
-	    if (!psDBRollback(config->dbh)) {
-	      psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return(false);
-	  }
-	}
-	// Set diffRun.maskfrac* to the appropriate values.
-	if (maskfrac_npix) {
-	  if (!pxSetRunMaskfrac(config, "diffRun", "diff_id", diff_id, maskfrac_npix, maskfrac_static,
-				maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) {
-	    psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,
-		    diff_id);
-	    psFree(output);
-	    if (!psDBRollback(config->dbh)) {
-	      psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return(false);
-	  }
-	}
+        psString software_ver = NULL;
+        psS64 maskfrac_npix = 0;
+        psF32 maskfrac_static = 0;
+        psF32 maskfrac_dynamic = 0;
+        psF32 maskfrac_magic = 0;
+        psF32 maskfrac_advisory = 0;
+
+        // Calculate run level masking and software state
+        if (!pxCoalesceRunStatus(config,"difftool_coalesce_run.sql",diff_id,
+                                 &software_ver,&maskfrac_npix,
+                                 &maskfrac_static,&maskfrac_dynamic,
+                                 &maskfrac_magic,&maskfrac_advisory)) {
+          psError(PS_ERR_UNKNOWN, false, "failed to generate run level statistics");
+          psFree(output);
+          if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+          }
+          return(false);
+        }
+        // Set diffRun.software_ver to the appropriate value
+        if (software_ver) {
+          if (!pxSetRunSoftware(config, "diffRun", "diff_id", diff_id, software_ver)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,
+                    diff_id);
+            psFree(output);
+            if (!psDBRollback(config->dbh)) {
+              psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return(false);
+          }
+        }
+        // Set diffRun.maskfrac* to the appropriate values.
+        if (maskfrac_npix) {
+          if (!pxSetRunMaskfrac(config, "diffRun", "diff_id", diff_id, maskfrac_npix, maskfrac_static,
+                                maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,
+                    diff_id);
+            psFree(output);
+            if (!psDBRollback(config->dbh)) {
+              psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return(false);
+          }
+        }
         // set diffRun.state to 'full'
         if (!setdiffRunState(config, diff_id, "full", magicked)) {
@@ -857,5 +857,5 @@
         }
     }
-            
+
     // treat limit == 0 as "no limit"
     if (limit) {
@@ -1092,10 +1092,10 @@
             false,
             0,       // magicked
-	    NULL, // software version
-	    0,    // mask stat npix
-	    NAN,    // static
-	    NAN,    // dynamic
-	    NAN,    // magic
-	    NAN,    // advisory
+            NULL, // software version
+            0,    // mask stat npix
+            NAN,    // static
+            NAN,    // dynamic
+            NAN,    // magic
+            NAN,    // advisory
             diff_mode, // diff_mode
             note
@@ -1475,19 +1475,19 @@
         }
 
-	psString warp_data_group = psMetadataLookupStr(&mdok, row, "data_group");
-	if (!mdok) {
-	  psError(PXTOOLS_ERR_PROG, false, "warp data_group not found");
-	  psFree(warp2Query);
-	  psFree(stackQuery);
-	  psFree(skycell_query);
-	  if (!psDBRollback(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	  }
-	  return false;
-	}
-	if (warp_data_group) {
-	  data_group = warp_data_group;
-	}
-	
+        psString warp_data_group = psMetadataLookupStr(&mdok, row, "data_group");
+        if (!mdok) {
+          psError(PXTOOLS_ERR_PROG, false, "warp data_group not found");
+          psFree(warp2Query);
+          psFree(stackQuery);
+          psFree(skycell_query);
+          if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+          }
+          return false;
+        }
+        if (!data_group && warp_data_group) {
+          data_group = warp_data_group;
+        }
+
         if (!p_psDBRunQueryF(config->dbh, skycell_query, stackQuery, warp_id, filter, warp2Query)) {
             psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1515,6 +1515,6 @@
         // ok we've got one create the diffRun
         diffRunRow *run = diffRunRowAlloc(
-                0,	      // ID
-                "reg",	      // state
+                0,            // ID
+                "reg",        // state
                 workdir,
                 label,
@@ -1522,16 +1522,16 @@
                 dist_group,
                 reduction,
-                NULL,	      // dvodb
+                NULL,         // dvodb
                 registered,
                 tess_id,
                 bothways,     // bothways (default is false)
-                true,	      // exposure
-                0,	      // magicked
-		NULL,	      // software version
-		0,	      // mask stat npix
-		NAN,	      // static
-		NAN,	      // dynamic
-		NAN,	      // magic
-		NAN,	      // advisory
+                true,         // exposure
+                0,            // magicked
+                NULL,         // software version
+                0,            // mask stat npix
+                NAN,          // static
+                NAN,          // dynamic
+                NAN,          // magic
+                NAN,          // advisory
                 IPP_DIFF_MODE_WARP_STACK,
                 note
@@ -1562,5 +1562,6 @@
         psFree(query);
         query = NULL;
-        psStringAppend(&query, "INSERT INTO diffInputSkyfile SELECT * from skycellsToDiff");
+        psStringAppend(&query,
+                       "INSERT INTO diffInputSkyfile(diff_id, skycell_id, warp1, stack1, warp2, stack2, tess_id) SELECT diff_id, skycell_id, warp1, stack1, warp2, stack2, tess_id from skycellsToDiff");
         if (!p_psDBRunQuery(config->dbh, query)) {
             psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1868,8 +1869,8 @@
         const char *template = psMetadataLookupStr(NULL, row, "template_warp_id");
         const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id");
-	psString input_data_group = psMetadataLookupStr(NULL, row, "input_data_group");
-	if (!data_group) {
-	  data_group = input_data_group;
-	}
+        psString input_data_group = psMetadataLookupStr(NULL, row, "input_data_group");
+        if (!data_group) {
+          data_group = input_data_group;
+        }
 
         if (!input_id || !template || !tess_id) {
@@ -1883,5 +1884,5 @@
             return false;
         }
-	
+
         diffRunRow *run = diffRunRowAlloc(0,
                                           "reg",
@@ -1897,10 +1898,10 @@
                                           true,  // exposure
                                           false, // magicked
-					  NULL, // software version
-					  0,    // mask stat npix
-					  NAN,    // static
-					  NAN,    // dynamic
-					  NAN,    // magic
-					  NAN,    // advisory					 
+                                          NULL, // software version
+                                          0,    // mask stat npix
+                                          NAN,    // static
+                                          NAN,    // dynamic
+                                          NAN,    // magic
+                                          NAN,    // advisory
                                           IPP_DIFF_MODE_WARP_WARP,
                                           note); // Run to insert
@@ -1958,7 +1959,7 @@
             // seem to be a way to pass in NULL for skycell_id, stack1 and stack2
             psString dummyQuery = NULL;
-            psStringAppend(&dummyQuery, 
+            psStringAppend(&dummyQuery,
               "INSERT INTO diffInputSkyfile VALUES(%" PRId64 ", NULL, %s, NULL, %s, NULL, '%s', 0)",
-                    run->diff_id, 
+                    run->diff_id,
                     input,                      // warp1
                     template,                   // warp2
@@ -1980,5 +1981,5 @@
             psFree(dummyQuery);
             psString finishQuery = NULL;
-            psStringAppend( &finishQuery, 
+            psStringAppend( &finishQuery,
                 "UPDATE diffRun set state ='full', dist_group = NULL, note = 'dummy run - no overlap' WHERE diff_id = %" PRId64,
                 run->diff_id);
@@ -2063,5 +2064,5 @@
 
     if (!(label)) {
-	PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false);
+        PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false);
     }
 
@@ -2071,36 +2072,36 @@
 
     if (psListLength(stack1Where->list)) {
-	psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL);
-	psStringAppend(&stack1Query, "AND %s", whereClause);
-	psFree(whereClause);
-    } 
+        psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL);
+        psStringAppend(&stack1Query, "AND %s", whereClause);
+        psFree(whereClause);
+    }
     psFree(stack1Where);
 
     if (psListLength(stack2Where->list)) {
-	psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL);
-	psStringAppend(&stack2Query, "AND %s", whereClause);
-	psFree(whereClause);
-    } 
+        psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL);
+        psStringAppend(&stack2Query, "AND %s", whereClause);
+        psFree(whereClause);
+    }
     psFree(stack2Where);
-  
+
     // don't queue for stacks that have already been diffed unless requested
     psString diffQuery0 = NULL;
     psString diffQuery1 = NULL;
     if (! (reRun || newTemplates) ) {
-	psStringAppend(&diffQuery0, "AND diffExp.diff_id IS NULL");
-	psStringAppend(&diffQuery1, "HAVING n_diff = 0");
-    } 
+        psStringAppend(&diffQuery0, "AND diffExp.diff_id IS NULL");
+        psStringAppend(&diffQuery1, "HAVING n_diff = 0");
+    }
 
     // find the distinct set of data_groups and filters
     psString query = pxDataGet("difftool_definestackstack_part0.sql");
     if (!query) {
-	psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-	return(false);
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+        return(false);
     }
     psTrace("difftool",1,query,stack2Query,stack1Query,diffQuery0,stack1Query);
 
     if (!psDBTransaction(config->dbh)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	return(false);
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return(false);
     }
 
@@ -2110,10 +2111,10 @@
 
     if (!p_psDBRunQuery(config->dbh, query)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	psFree(query);
-	if (!psDBRollback(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	}
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        return false;
     }
 
@@ -2122,41 +2123,41 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-	psErrorCode err = psErrorCodeLast();
-	switch (err) {
-	  case PS_ERR_DB_CLIENT:
-	    psError(PXTOOLS_ERR_SYS, false, "database error");
-	    break;
-	  case PS_ERR_DB_SERVER:
-	    psError(PXTOOLS_ERR_PROG, false, "database error");
-	    break;
-	  default:
-	    psError(PXTOOLS_ERR_PROG, false, "unknown error");
-	    break;
-	}
-	if (!psDBRollback(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	}
-	return false;
+        psErrorCode err = psErrorCodeLast();
+        switch (err) {
+          case PS_ERR_DB_CLIENT:
+            psError(PXTOOLS_ERR_SYS, false, "database error");
+            break;
+          case PS_ERR_DB_SERVER:
+            psError(PXTOOLS_ERR_PROG, false, "database error");
+            break;
+          default:
+            psError(PXTOOLS_ERR_PROG, false, "unknown error");
+            break;
+        }
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
+        return false;
     }
     if (!psArrayLength(output)) {
-	psTrace("difftool", PS_LOG_INFO, "no rows found");
-	psFree(output);
-	if (!psDBCommit(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	    return false;
-	}
-	return true;
-    }
-
-    
+        psTrace("difftool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        if (!psDBCommit(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+        return true;
+    }
+
+
     if (pretend) {
-	// negative simple so the default is true
-	if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) {
-	    psError(PS_ERR_UNKNOWN, false, "failed to print array");
-	    psFree(output);
-	    return false;
-	}
-	psFree(output);
-	return true;
+        // negative simple so the default is true
+        if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to print array");
+            psFree(output);
+            return false;
+        }
+        psFree(output);
+        return true;
     }
 
@@ -2165,168 +2166,168 @@
       query = pxDataGet("difftool_definestackstack_part1.sql");
 
-   
-	psMetadata *row = output->data[i]; // Output row from query
-	bool mdok;                      // Status of MD lookup
-
-	// psMetadataPrint(stderr, row, 1);
-
-	psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id");
-	psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group");
-	psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group");
-	psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label");
-
-	psString this_stack1Query = psStringCopy(stack1Query);
-
-	psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL);
-	psStringSubstitute(&thisWhere,"stackRun.","INPUT_");
-	psStringAppend(&this_stack1Query,"AND %s", thisWhere);
-	psFree(thisWhere);
-
-	psStringSubstitute(&query, this_stack1Query, "@STACK1_QUERY@");
-	psStringSubstitute(&query, stack2Query,      "@STACK2_QUERY@");
-	psStringSubstitute(&query, diffQuery1,       "@DIFF1_QUERY@");
-
-	psTrace("difftool", 1, "%s", query);
-	if (!psDBTransaction(config->dbh)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	    return(false);
-	}
-
-	if (!p_psDBRunQuery(config->dbh, query)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	    psFree(query);
-	    if (!psDBRollback(config->dbh)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return false;
-	}
-	psFree(this_stack1Query);
-
-	psArray *diff_id_output = p_psDBFetchResult(config->dbh);
-	if (!diff_id_output) {
-	    psErrorCode err = psErrorCodeLast();
-	    switch (err) {
-	      case PS_ERR_DB_CLIENT:
-		psError(PXTOOLS_ERR_SYS, false, "database error");
-		break;
-	      case PS_ERR_DB_SERVER:
-		psError(PXTOOLS_ERR_PROG, false, "database error");
-		break;
-	      default:
-		psError(PXTOOLS_ERR_PROG, false, "unknown error");
-		break;
-	    }
-	    if (!psDBRollback(config->dbh)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return false;
-	}
-	if (!psArrayLength(diff_id_output)) {
-	    psTrace("difftool", PS_LOG_INFO, "no rows found");
-	    psFree(diff_id_output);
-	    if (!psDBCommit(config->dbh)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-		return false;
-	    }
-	    return true;
-	}
-
-	// ok we've got one create the diffRun
-	diffRunRow *run = diffRunRowAlloc(
-	    0,          // ID
-	    "reg",      // state
-	    workdir,
-	    label ? label : this_label,
-	    data_group ? data_group : this_data_group,
-	    dist_group ? dist_group : this_dist_group,
-	    reduction,
-	    NULL,       // dvodb
-	    registered,
-	    tess_id,
-	    bothways,               // bothways
-	    false,                 // exposure
-	    0,       // magicked
-	    NULL, // software version
-	    0,    // mask stat npix
-	    NAN,    // static
-	    NAN,    // dynamic
-	    NAN,    // magic
-	    NAN,    // advisory				     
-	    IPP_DIFF_MODE_STACK_STACK, // diff_mode
-	    note
-	    );
-	// Commit to database
-	if (!diffRunInsertObject(config->dbh, run)) {
-	    psError(PS_ERR_UNKNOWN, false, "database error");
-	    psFree(run);
-	    if (!psDBRollback(config->dbh)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return false;
-	}
-	// diffRunPrintObject(stdout,run,1);
-	run->diff_id = psDBLastInsertID(config->dbh);
-
-	for (long j = 0; j < diff_id_output->n; j++) {
-	    psMetadata *input_row = diff_id_output->data[j]; // Output row from query
-	    bool mdok;
-	    psString in_skycell_id  = psMetadataLookupStr(&mdok,input_row,"skycell_id");
-	    psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id");
-	    psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id");
-	    psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id");
-	    psTrace("difftool",1,"%s %" PRId64 " %" PRId64 " %s\n",
-		    in_skycell_id, in_input_stack_id, in_template_stack_id, in_tess_id);
-	    diffInputSkyfileRow *input = diffInputSkyfileRowAlloc(
-		run->diff_id,   // ID
-		in_skycell_id,
-		PS_MAX_S64, // warp1_id -> NULL
-		in_input_stack_id, // stack1
-		PS_MAX_S64, // warp2_id -> NULL
-		in_template_stack_id, // stack2
-		in_tess_id,
-		0 // diff_skyfile_id
-		);
-
-	    // Commit to database the input
-	    if (!diffInputSkyfileInsertObject(config->dbh, input)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-		psFree(input);
-		if (!psDBRollback(config->dbh)) {
-		    psError(PS_ERR_UNKNOWN, false, "database error");
-		}
-		return false;
-	    }
+
+        psMetadata *row = output->data[i]; // Output row from query
+        bool mdok;                      // Status of MD lookup
+
+        // psMetadataPrint(stderr, row, 1);
+
+        psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id");
+        psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group");
+        psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group");
+        psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label");
+
+        psString this_stack1Query = psStringCopy(stack1Query);
+
+        psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL);
+        psStringSubstitute(&thisWhere,"stackRun.","INPUT_");
+        psStringAppend(&this_stack1Query,"AND %s", thisWhere);
+        psFree(thisWhere);
+
+        psStringSubstitute(&query, this_stack1Query, "@STACK1_QUERY@");
+        psStringSubstitute(&query, stack2Query,      "@STACK2_QUERY@");
+        psStringSubstitute(&query, diffQuery1,       "@DIFF1_QUERY@");
+
+        psTrace("difftool", 1, "%s", query);
+        if (!psDBTransaction(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return(false);
+        }
+
+        if (!p_psDBRunQuery(config->dbh, query)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(query);
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+        psFree(this_stack1Query);
+
+        psArray *diff_id_output = p_psDBFetchResult(config->dbh);
+        if (!diff_id_output) {
+            psErrorCode err = psErrorCodeLast();
+            switch (err) {
+              case PS_ERR_DB_CLIENT:
+                psError(PXTOOLS_ERR_SYS, false, "database error");
+                break;
+              case PS_ERR_DB_SERVER:
+                psError(PXTOOLS_ERR_PROG, false, "database error");
+                break;
+              default:
+                psError(PXTOOLS_ERR_PROG, false, "unknown error");
+                break;
+            }
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+        if (!psArrayLength(diff_id_output)) {
+            psTrace("difftool", PS_LOG_INFO, "no rows found");
+            psFree(diff_id_output);
+            if (!psDBCommit(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+                return false;
+            }
+            return true;
+        }
+
+        // ok we've got one create the diffRun
+        diffRunRow *run = diffRunRowAlloc(
+            0,          // ID
+            "reg",      // state
+            workdir,
+            label ? label : this_label,
+            data_group ? data_group : this_data_group,
+            dist_group ? dist_group : this_dist_group,
+            reduction,
+            NULL,       // dvodb
+            registered,
+            tess_id,
+            bothways,               // bothways
+            false,                 // exposure
+            0,       // magicked
+            NULL, // software version
+            0,    // mask stat npix
+            NAN,    // static
+            NAN,    // dynamic
+            NAN,    // magic
+            NAN,    // advisory
+            IPP_DIFF_MODE_STACK_STACK, // diff_mode
+            note
+            );
+        // Commit to database
+        if (!diffRunInsertObject(config->dbh, run)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            psFree(run);
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+        // diffRunPrintObject(stdout,run,1);
+        run->diff_id = psDBLastInsertID(config->dbh);
+
+        for (long j = 0; j < diff_id_output->n; j++) {
+            psMetadata *input_row = diff_id_output->data[j]; // Output row from query
+            bool mdok;
+            psString in_skycell_id  = psMetadataLookupStr(&mdok,input_row,"skycell_id");
+            psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id");
+            psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id");
+            psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id");
+            psTrace("difftool",1,"%s %" PRId64 " %" PRId64 " %s\n",
+                    in_skycell_id, in_input_stack_id, in_template_stack_id, in_tess_id);
+            diffInputSkyfileRow *input = diffInputSkyfileRowAlloc(
+                run->diff_id,   // ID
+                in_skycell_id,
+                PS_MAX_S64, // warp1_id -> NULL
+                in_input_stack_id, // stack1
+                PS_MAX_S64, // warp2_id -> NULL
+                in_template_stack_id, // stack2
+                in_tess_id,
+                0 // diff_skyfile_id
+                );
+
+            // Commit to database the input
+            if (!diffInputSkyfileInsertObject(config->dbh, input)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+                psFree(input);
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                return false;
+            }
 
 /*       diffInputSkyfilePrintObject(stdout,input,1); */
-	    psFree(input);
-	}
-
-	if (!setdiffRunState(config, run->diff_id, "new", false)) {
-	    psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, run->diff_id);
-	    psFree(stack1Query);
-	    psFree(stack2Query);
-	    psFree(diffQuery0);
-	    psFree(diffQuery1);
-	    psFree(run);
-	    psFree(list);
-	    if (!psDBRollback(config->dbh)) {
-		psError(PS_ERR_UNKNOWN, false, "database error");
-	    }
-	    return false;
-	}
-	psArrayAdd(list, list->n, run);
-	psFree(run);
+            psFree(input);
+        }
+
+        if (!setdiffRunState(config, run->diff_id, "new", false)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, run->diff_id);
+            psFree(stack1Query);
+            psFree(stack2Query);
+            psFree(diffQuery0);
+            psFree(diffQuery1);
+            psFree(run);
+            psFree(list);
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            return false;
+        }
+        psArrayAdd(list, list->n, run);
+        psFree(run);
     }
 
     if (!psDBCommit(config->dbh)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	psFree(list);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(list);
+        return false;
     }
 
     if (!diffRunPrintObjects(stdout, list, !simple)) {
-	psError(PS_ERR_UNKNOWN, false, "failed to print object");
-	psFree(list);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "failed to print object");
+        psFree(list);
+        return false;
     }
 
@@ -2340,7 +2341,7 @@
 
     if (!psDBCommit(config->dbh)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	psFree(list);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(list);
+        return false;
     }
 
@@ -2350,5 +2351,5 @@
 static bool tosummaryMode(pxConfig *config) {
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   psMetadata *where = psMetadataAlloc();
   PXOPT_COPY_S64(config->args, where, "-warp_id",    "diffSkyfile.warp_id", "==");
@@ -2366,5 +2367,5 @@
   PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-  
+
   // find all rawImfiles matching the default query
   psString query = pxDataGet("difftool_tosummary.sql");
@@ -2381,5 +2382,5 @@
     return false;
   }
-  
+
   if (psListLength(where->list)) {
     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
@@ -2390,5 +2391,5 @@
     return false;
   }
-  
+
   if (where2) {
     if (psListLength(where->list)) {
@@ -2406,5 +2407,5 @@
     psFree(limitString);
   }
-  
+
   if (!p_psDBRunQuery(config->dbh, query)) {
     psError(PS_ERR_UNKNOWN, false, "database error");
@@ -2425,5 +2426,5 @@
       psError(PXTOOLS_ERR_PROG, false, "unknown error");
     }
-    
+
     return false;
   }
@@ -2433,5 +2434,5 @@
     return true;
   }
-  
+
   if (psArrayLength(output)) {
     // negative simple so the default is true
@@ -2442,5 +2443,5 @@
     }
   }
-  
+
   psFree(output);
   return(true);
@@ -2464,5 +2465,5 @@
   }
   psS64 numUpdated = psDBAffectedRows(config->dbh);
-  
+
   if (numUpdated != 1) {
     psError(PS_ERR_UNKNOWN, false, "should have affected 1 row");
@@ -2470,9 +2471,9 @@
     return false;
   }
-  
+
   psFree(query);
 
   // Print anything here?
-  
+
   return(true);
 }
@@ -2514,5 +2515,5 @@
         psString limitString = psDBGenerateLimitSQL(limit);
         psStringAppend(&query, " %s", limitString);
-	psStringSubstitute(&query,limitString,"@INNERLIMITS@");
+        psStringSubstitute(&query,limitString,"@INNERLIMITS@");
         psFree(limitString);
 
@@ -3028,5 +3029,5 @@
 
     PXOPT_COPY_S64(config->args, where, "-template_exp_id", "rawTemplate.exp_id", "==");
-    
+
     PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
     if (!template) {
@@ -3083,5 +3084,5 @@
         }
     }
-            
+
     // treat limit == 0 as "no limit"
     if (limit) {
@@ -3148,5 +3149,5 @@
     PXOPT_LOOKUP_F64(mjd_obs_begin, config->args, "-mjd_obs_begin", false, false);
     PXOPT_LOOKUP_F64(mjd_obs_end, config->args, "-mjd_obs_end", false, false);
-    
+
     PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
 
@@ -3200,5 +3201,5 @@
         }
     }
-            
+
     // treat limit == 0 as "no limit"
     if (limit) {
Index: /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/stacktool.c	(revision 34566)
@@ -748,4 +748,5 @@
     PXOPT_COPY_STR(config->args, where, "-state",     "stackRun.state",     "==");
     PXOPT_COPY_S64(config->args, where, "-sass_id",   "stackAssociationMap.sass_id",  "==");
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     if (!psListLength(where->list)) {
         psFree(where);
@@ -756,4 +757,9 @@
     //CZW join against stackAssociationMap
     psString query = psStringCopy("UPDATE stackRun");
+
+    if (fault) {
+        psStringAppend(&query, " JOIN stackSumSkyfile USING(stack_id)");
+        PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
+    }
 
     // pxUpdateRun gets parameters from config->args and updates
Index: /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippTools/src/stacktoolConfig.c	(revision 34566)
@@ -121,5 +121,6 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "search by state", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0,            "search by label", 0);
-    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-sass_id", 0,           "search by stack association ID", 0);
+    psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-fault",  0,           "search by fault code", 0);
+    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-sass_id", 0,          "search by stack association ID", 0);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0,        "define new value for label", 0);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0,        "define new state", NULL);
Index: /branches/eam_branches/ipp-20120905/ippconfig/gpc1/psastro.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/gpc1/psastro.config	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/gpc1/psastro.config	(revision 34566)
@@ -408,9 +408,11 @@
    PSASTRO.GRID.NRAW.MAX                S32     2000
    PSASTRO.GRID.NREF.MAX  		S32     2000
-   PSASTRO.MIN.INST.MAG.RAW             F32     -20.0
-   PSASTRO.MAX.INST.MAG.RAW             F32     -15.0
-   PSASTRO.GRID.MIN.INST.MAG.RAW        F32     -20.0
+   PSASTRO.MIN.INST.MAG.RAW             F32     -19.0
+   PSASTRO.MAX.INST.MAG.RAW             F32     -14.0
+   PSASTRO.GRID.MIN.INST.MAG.RAW        F32     -19.0
    PSASTRO.GRID.MAX.INST.MAG.RAW        F32     -15.0
-   DVO.GETSTAR.MIN.MAG.INST             F32     -13.0
-END
-
+   DVO.GETSTAR.MIN.MAG.INST             F32     -19.0
+   DVO.GETSTAR.MIN.MAG			F32	16.0
+
+END
+
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-mef.mdc
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-mef.mdc	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-mef.mdc	(revision 34566)
@@ -88,4 +88,18 @@
 PSPHOT.INPUT.TEXT       INPUT    @FILES        CHIP       SRCTEXT       
 PSPHOT.EXPNUM           INPUT    @FILES        CHIP       MASK       
+
+## files used by psphotStack
+PSPHOT.STACK.INPUT.RAW    INPUT    @FILES        CHIP       IMAGE
+PSPHOT.STACK.MASK.RAW     INPUT    @FILES        CHIP       MASK     
+PSPHOT.STACK.VARIANCE.RAW INPUT    @FILES        CHIP       VARIANCE     
+PSPHOT.STACK.EXPNUM.RAW   INPUT    @FILES        CHIP       EXPNUM     
+PSPHOT.STACK.PSF.RAW      INPUT    @FILES        CHIP       PSF       
+PSPHOT.STACK.INPUT.CNV    INPUT    @FILES        CHIP       IMAGE
+PSPHOT.STACK.MASK.CNV     INPUT    @FILES        CHIP       MASK     
+PSPHOT.STACK.VARIANCE.CNV INPUT    @FILES        CHIP       VARIANCE     
+PSPHOT.STACK.EXPNUM.CNV   INPUT    @FILES        CHIP       EXPNUM     
+PSPHOT.STACK.PSF.CNV      INPUT    @FILES        CHIP       PSF       
+PSPHOT.STACK.SOURCES      INPUT    @FILES        FPA        CMF
+
 
 ## files used by psastro 
@@ -220,4 +234,5 @@
 PSPHOT.BACKSUB          OUTPUT {OUTPUT}.sub.fits                 IMAGE     NONE       CHIP       FALSE     MEF
 PSPHOT.BACKMDL          OUTPUT {OUTPUT}.mdl.fits                 IMAGE     NONE       CHIP       FALSE     MEF
+PSPHOT.BACKMDL.STDEV    OUTPUT {OUTPUT}.mdl.std.fits             IMAGE     NONE       CHIP       FALSE     MEF
 PSPHOT.BACKMDL.MEF      OUTPUT {OUTPUT}.mdl.fits                 IMAGE     NONE       CHIP       FALSE     MEF
                                                                                      
@@ -234,10 +249,28 @@
 PSPHOT.SKY.CONFIG       OUTPUT {OUTPUT}.psphot.mdc               TEXT      NONE       FPA        TRUE      NONE
 
-                                                                                     
 # outputs for psphotStack:
-PSPHOT.CHISQ.IMAGE      OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.im.fits IMAGE    NONE       FPA        TRUE      SIMPLE
-PSPHOT.CHISQ.MASK       OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.mk.fits MASK     NONE       FPA        TRUE      SIMPLE
-PSPHOT.CHISQ.VARIANCE   OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.wt.fits VARIANCE NONE       FPA        TRUE      SIMPLE
-PSPHOT.STACK.OUTPUT     OUTPUT {OUTPUT}.{CHIP.NAME}.sky.{FILE.ID}.cmf CMF      NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.IMAGE           OUTPUT {OUTPUT}.chisq.im.fits            IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.MASK            OUTPUT {OUTPUT}.chisq.mk.fits            MASK            NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.VARIANCE        OUTPUT {OUTPUT}.chisq.wt.fits            VARIANCE        NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT.IMAGE    OUTPUT {OUTPUT}.stk.{FILE.ID}.im.fits    IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT.MASK     OUTPUT {OUTPUT}.stk.{FILE.ID}.mk.fits    MASK            NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.stk.{FILE.ID}.wt.fits    VARIANCE        NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT          OUTPUT {OUTPUT}.stk.{FILE.ID}.cmf        CMF             NONE       FPA        TRUE      NONE
+PSPHOT.STACK.PSF.SAVE        OUTPUT {OUTPUT}.stk.{FILE.ID}.psf        PSF             NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKMDL         OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.fits   IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKMDL.STDEV   OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.sdv.fits IMAGE         NONE       FPA        TRUE      NONE
+
+PSPHOT.STACK.CONFIG          OUTPUT {OUTPUT}.psphotStack.mdc          TEXT            NONE       FPA        TRUE      NONE
+
+PSPHOT.STACK.RESID           OUTPUT {OUTPUT}.stk.{FILE.ID}.res.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
+PSPHOT.STACK.BACKGND         OUTPUT {OUTPUT}.stk.{FILE.ID}.bck.fits   IMAGE           COMP_IMG   FPA        TRUE      NONE
+PSPHOT.STACK.BACKSUB         OUTPUT {OUTPUT}.stk.{FILE.ID}.sub.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
+                                                     
+# old outputs for psphotStack:
+# I think these are wrong
+#PSPHOT.CHISQ.IMAGE      OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.im.fits IMAGE    NONE       FPA        TRUE      SIMPLE
+#PSPHOT.CHISQ.MASK       OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.mk.fits MASK     NONE       FPA        TRUE      SIMPLE
+#PSPHOT.CHISQ.VARIANCE   OUTPUT {OUTPUT}.{CHIP.NAME}.chisq.wt.fits VARIANCE NONE       FPA        TRUE      SIMPLE
+#PSPHOT.STACK.OUTPUT     OUTPUT {OUTPUT}.{CHIP.NAME}.sky.{FILE.ID}.cmf CMF      NONE       FPA        TRUE      NONE
                                                      
 SOURCE.PLOT.MOMENTS     OUTPUT {OUTPUT}.mnt.png                  KAPA      NONE       FPA        TRUE      NONE
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-simple.mdc
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-simple.mdc	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-simple.mdc	(revision 34566)
@@ -64,8 +64,10 @@
 PSPHOT.STACK.MASK.RAW     INPUT    @FILES        CHIP       MASK     
 PSPHOT.STACK.VARIANCE.RAW INPUT    @FILES        CHIP       VARIANCE     
+PSPHOT.STACK.EXPNUM.RAW   INPUT    @FILES        CHIP       MASK     
 PSPHOT.STACK.PSF.RAW      INPUT    @FILES        CHIP       PSF       
 PSPHOT.STACK.INPUT.CNV    INPUT    @FILES        CHIP       IMAGE
 PSPHOT.STACK.MASK.CNV     INPUT    @FILES        CHIP       MASK     
 PSPHOT.STACK.VARIANCE.CNV INPUT    @FILES        CHIP       VARIANCE     
+PSPHOT.STACK.EXPNUM.CNV   INPUT    @FILES        CHIP       MASK     
 PSPHOT.STACK.PSF.CNV      INPUT    @FILES        CHIP       PSF       
 PSPHOT.STACK.SOURCES      INPUT    @FILES        FPA        CMF
@@ -195,4 +197,5 @@
 PSPHOT.BACKMDL               OUTPUT {OUTPUT}.mdl.fits             IMAGE           NONE       FPA        TRUE      SIMPLE
 PSPHOT.BACKMDL.MEF           OUTPUT {OUTPUT}.mdl.fits             IMAGE           NONE       FPA        TRUE      SIMPLE
+PSPHOT.BACKMDL.STDEV         OUTPUT {OUTPUT}.mdl.std.fits         IMAGE           NONE       FPA        TRUE      SIMPLE
                                                      
 PSPHOT.OUTPUT.RAW            OUTPUT {OUTPUT}                      RAW             NONE       FPA        TRUE      NONE
@@ -213,11 +216,19 @@
 
 # outputs for psphotStack:
-PSPHOT.CHISQ.IMAGE           OUTPUT {OUTPUT}.chisq.im.fits        IMAGE           NONE       FPA        TRUE      NONE
-PSPHOT.CHISQ.MASK            OUTPUT {OUTPUT}.chisq.mk.fits        MASK            NONE       FPA        TRUE      NONE
-PSPHOT.CHISQ.VARIANCE        OUTPUT {OUTPUT}.chisq.wt.fits        VARIANCE        NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.IMAGE           OUTPUT {OUTPUT}.chisq.im.fits            IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.MASK            OUTPUT {OUTPUT}.chisq.mk.fits            MASK            NONE       FPA        TRUE      NONE
+PSPHOT.CHISQ.VARIANCE        OUTPUT {OUTPUT}.chisq.wt.fits            VARIANCE        NONE       FPA        TRUE      NONE
 PSPHOT.STACK.OUTPUT.IMAGE    OUTPUT {OUTPUT}.stk.{FILE.ID}.im.fits    IMAGE           NONE       FPA        TRUE      NONE
 PSPHOT.STACK.OUTPUT.MASK     OUTPUT {OUTPUT}.stk.{FILE.ID}.mk.fits    MASK            NONE       FPA        TRUE      NONE
 PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.stk.{FILE.ID}.wt.fits    VARIANCE        NONE       FPA        TRUE      NONE
 PSPHOT.STACK.OUTPUT          OUTPUT {OUTPUT}.stk.{FILE.ID}.cmf        CMF             NONE       FPA        TRUE      NONE
+PSPHOT.STACK.PSF.SAVE        OUTPUT {OUTPUT}.stk.{FILE.ID}.psf        PSF             NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKMDL         OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.fits   IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKMDL.STDEV   OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.sdv.fits IMAGE         NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKGND         OUTPUT {OUTPUT}.stk.{FILE.ID}.bck.fits   IMAGE           COMP_IMG   FPA        TRUE      NONE
+PSPHOT.STACK.BACKSUB         OUTPUT {OUTPUT}.stk.{FILE.ID}.sub.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
+PSPHOT.STACK.RESID           OUTPUT {OUTPUT}.stk.{FILE.ID}.res.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
+PSPHOT.STACK.CONFIG          OUTPUT {OUTPUT}.psphotStack.mdc          TEXT            NONE       FPA        TRUE      NONE
+                                                     
                                                      
 SOURCE.PLOT.MOMENTS          OUTPUT {OUTPUT}.mnt.png              KAPA            NONE       FPA        TRUE      NONE
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-split.mdc
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-split.mdc	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/filerules-split.mdc	(revision 34566)
@@ -131,4 +131,5 @@
 PPSTAMP.INPUT.MASK        INPUT    @FILES        CHIP       MASK
 PPSTAMP.INPUT.VARIANCE    INPUT    @FILES        CHIP       VARIANCE
+PPSTAMP.INPUT.SOURCES     INPUT    @FILES        CHIP       CMF
                           
 # files used by pparith   
@@ -214,4 +215,5 @@
 PSPHOT.BACKSUB               OUTPUT {OUTPUT}.{CHIP.NAME}.sub.fits     IMAGE           COMP_SUB   CHIP       TRUE      NONE
 PSPHOT.BACKMDL               OUTPUT {OUTPUT}.{CHIP.NAME}.mdl.fits     IMAGE           NONE       CHIP       TRUE      NONE
+PSPHOT.BACKMDL.STDEV         OUTPUT {OUTPUT}.{CHIP.NAME}.mdl.std.fits  IMAGE           NONE       CHIP       TRUE      NONE
 PSPHOT.BACKMDL.MEF           OUTPUT {OUTPUT}.mdl.fits                 IMAGE           NONE       CHIP       TRUE      NONE
                                                                                                               
@@ -235,8 +237,17 @@
 PSPHOT.CHISQ.MASK            OUTPUT {OUTPUT}.chisq.mk.fits            MASK            NONE       FPA        TRUE      NONE
 PSPHOT.CHISQ.VARIANCE        OUTPUT {OUTPUT}.chisq.wt.fits            VARIANCE        NONE       FPA        TRUE      NONE
-PSPHOT.STACK.OUTPUT.IMAGE    OUTPUT {OUTPUT}.stk.{FILE.ID}.im.fits        IMAGE           NONE       FPA        TRUE      NONE
-PSPHOT.STACK.OUTPUT.MASK     OUTPUT {OUTPUT}.stk.{FILE.ID}.mk.fits        MASK            NONE       FPA        TRUE      NONE
-PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.stk.{FILE.ID}.wt.fits        VARIANCE        NONE       FPA        TRUE      NONE
-PSPHOT.STACK.OUTPUT          OUTPUT {OUTPUT}.stk.{FILE.ID}.cmf            CMF             NONE       FPA        TRUE      NONE
+
+PSPHOT.STACK.OUTPUT.IMAGE    OUTPUT {OUTPUT}.stk.{FILE.ID}.im.fits    IMAGE           NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT.MASK     OUTPUT {OUTPUT}.stk.{FILE.ID}.mk.fits    MASK            NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT.VARIANCE OUTPUT {OUTPUT}.stk.{FILE.ID}.wt.fits    VARIANCE        NONE       FPA        TRUE      NONE
+PSPHOT.STACK.OUTPUT          OUTPUT {OUTPUT}.stk.{FILE.ID}.cmf        CMF             NONE       FPA        TRUE      NONE
+
+PSPHOT.STACK.PSF.SAVE        OUTPUT {OUTPUT}.stk.{FILE.ID}.psf        PSF             NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKMDL         OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.fits   IMAGE           NONE       FPA        TRUE      NONE
+
+PSPHOT.STACK.BACKMDL.STDEV   OUTPUT {OUTPUT}.stk.{FILE.ID}.mdl.sdv.fits IMAGE         NONE       FPA        TRUE      NONE
+PSPHOT.STACK.BACKGND         OUTPUT {OUTPUT}.stk.{FILE.ID}.bck.fits   IMAGE           COMP_IMG   FPA        TRUE      NONE
+PSPHOT.STACK.BACKSUB         OUTPUT {OUTPUT}.stk.{FILE.ID}.sub.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
+PSPHOT.STACK.RESID           OUTPUT {OUTPUT}.stk.{FILE.ID}.res.fits   IMAGE           COMP_SUB   FPA        TRUE      NONE
 PSPHOT.STACK.CONFIG          OUTPUT {OUTPUT}.psphotStack.mdc          TEXT            NONE       FPA        TRUE      NONE
                                                      
@@ -333,4 +344,5 @@
 PPSTAMP.OUTPUT.VARIANCE.NOCOMP OUTPUT {OUTPUT}.wt.fits                VARIANCE        NONE       FPA        TRUE      NONE
 PPSTAMP.OUTPUT.JPEG          OUTPUT {OUTPUT}.jpg                      JPEG            NONE       FPA        TRUE      NONE
+PPSTAMP.OUTPUT.SOURCES       OUTPUT {OUTPUT}.cmf                      CMF             NONE       FPA        TRUE      NONE
 # mosaic image used for making stamps of raw images. Not saved.
 PPSTAMP.CHIP                 OUTPUT {OUTPUT}.ch.fits                  IMAGE           NONE       CHIP       FALSE     MEF
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/nightly_science.config	(revision 34566)
@@ -7,6 +7,6 @@
 CLEAN_MODES METADATA
   MODE           STR WARP
-#  COMMAND        STR warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -label @LABEL@ -data_group @DATA_GROUP@
-  COMMAND        STR true
+  COMMAND        STR warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -label @LABEL@ -data_group @DATA_GROUP@
+#  COMMAND        STR true
   RETENTION_TIME U16 7
 END
Index: /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config
===================================================================
--- /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ippconfig/recipes/psphot.config	(revision 34566)
@@ -196,6 +196,4 @@
 
 KRON_ITERATIONS                     S32   2
-KRON_APPLY_WEIGHT                   BOOL  FALSE
-KRON_APPLY_WINDOW                   BOOL  FALSE
 KRON_SMOOTH                         BOOL  TRUE      # smooth pixels before measuring kron radii
 KRON_SMOOTH_SIGMA                   F32   1.7
@@ -289,5 +287,6 @@
 # psphotFitSourcesLinear has 3 options for the weighting: CONSTANT,
 # IMAGE_VAR, MODEL_VAR the first of these used to be folded into the
-# boolean CONSTANT_PHOTOMETRIC_WEIGHTS above.
+# boolean CONSTANT_PHOTOMETRIC_WEIGHTS above (so if _MODE set, then
+# it overrides).
 LINEAR_FIT_VARIANCE_MODE	    STR  CONSTANT
 
@@ -525,7 +524,13 @@
 
 STACKPHOT_SINGLE    METADATA
-  PSPHOT.STACK.USE.RAW                BOOL  F   # since false perform photometry & morphology analysis on the convolved images
+  # while not used by psphot directly, staticsky.pl uses to decide if single filter calls psphot with convolved or unconvolved/raw input. 
+  PSPHOT.STACK.USE.RAW                BOOL  T   # if false perform photometry & morphology analysis on the convolved images
+  # NOTE: if PSPHOT.STACK.USE.RAW is set to False, KRON.SMOOTH should be
+  #   set to false as well in order to get the best MOMENTS_R1 measurement.
+  KRON_SMOOTH                         BOOL  T    # smooth before kron radius measurement
+  # default is T and won't work here 
   SAVE.BACKMDL                        BOOL  F
 END
+
 
 # Recipe overrides for CHIP
Index: /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile	(revision 34566)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/Makefile	(revision 34566)
@@ -0,0 +1,15 @@
+SOURCE=PSDC-940-005
+
+RM=/bin/rm -f
+
+all:
+	latex $(SOURCE).tex
+	latex $(SOURCE).tex
+	dvipdf PSDC-940-005.dvi
+	@echo
+	@echo
+	@echo "IPP-MOPS documentation in pdf format has been succesfully built"
+	@echo 
+
+clean:
+	$(RM) *.aux *.dvi *.out *.pdf *.toc *.log *~
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 34566)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/documentation/ICD/PSDC-940-005.tex	(revision 34566)
@@ -0,0 +1,941 @@
+%%% $Id: PSDC-940-005.tex,v 1.9 2011/04/18 23:17:36 schastel Exp $
+\documentclass[panstarrs,spec]{panstarrs}
+\usepackage{nonfloat}
+
+\newcommand{\sccomment}[1]{%
+  \textcolor{green}{SC: #1}}
+\newcommand{\outformatversion}{%
+  \texttt{PS1\_DV3}}
+
+% basic document variables
+\title{IPP-MOPS ICD}
+\subtitle{Pan-STARRS IPP-MOPS ICD for PS-1}
+\shorttitle{IPP-MOPS ICD}
+\author{Eugene Magnier, Larry Denneau, Jr., Robert Jedicke}
+\audience{Pan-STARRS PMO}
+\group{Pan-STARRS IPP \& MOPS}
+\project{Pan-STARRS PS-1}
+\organization{Institute for Astronomy}
+\version{03}
+\docnumber{PSDC-940-005}
+
+\begin{document}
+\maketitle
+\sloppy
+
+\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
+\RevisionsEnd
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+\DocumentsInternal
+PSDC-230-001 & PS-1 Design Reference Mission \\ \hline
+PSDC-430-011 & Pan-STARRS PS-1 IPP System/Subsystem Design Description \\ \hline
+PSDC-510-001 & Pan-STARRS PS-1 MOPS System Concept Definition \\ \hline
+PSDC-530-003 & Pan-STARRS PS-1 MOPS Software Design Description \\ \hline
+\DocumentsExternal
+\DocumentsEnd
+
+\tableofcontents
+\pagebreak 
+\pagenumbering{arabic}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+\section{Scope}
+
+\subsection{Identification}
+
+This document defines the interface between the Image Processing
+Pipeline (IPP) and Moving Object Processing System (MOPS) for the
+Panoramic Survey Telescope and Rapid Response System (Pan-STARRS)
+for the prototype telescope PS-1, and is a System-level controlled
+specification/design description document in the official Pan-STARRS
+engineering specification tree.
+
+\subsection{System Overview}
+
+The Institute for Astronomy at the University of Hawai`i is developing
+a large optical synoptic survey telescope system, the Panoramic Survey
+Telescope and Rapid Response System (Pan-STARRS). The science goals,
+priorities, top-level concept of operations with associated
+operational requirements, and system performance drivers with
+associated system performance requirements are described in the
+Pan-STARRS Science Goals Statement (SGS).  As described in this
+document, The system conceptual design for Pan-STARRS utilizes an
+array of four 1.8m telescopes each with a 7 degree$^2$ field of view,
+giving the system an \'etendue larger than all existing survey
+instruments combined (defined as the product of the collecting area
+$A$ multiplied by the field-of-view solid angle $\Omega$).  Each
+telescope will be equipped with a 1 billion pixel CCD camera with low
+noise and rapid read-out, and the data will be reduced in near real
+time to produce both cumulative static sky and difference images from
+which transient, moving, and variable objects can be
+detected. Pan-STARRS will be able to survey up to $\approx 6,000$
+degree$^{2}$ per night to a detection limit of approximately 24$^{th}$
+magnitude.  This unique combination of sensitivity and sky coverage
+will open up many new possibilities in time domain astronomy including
+a major goal of surveying the Potentially Hazardous Object (PHO)
+population down to a diameter of $\approx 300$ meters.  In addition,
+the Pan-STARRS data will be used to investigate a broad range of
+astronomical problems of extreme current interest concerning the Solar
+System, the Galaxy, and the Cosmos at large.  A prototype single
+telescope system, PS-1, is being developed as a preliminary step
+before construction of the complete four telescope system.
+
+\begin{tabular}{ll}
+  Project sponsor:&	AFRL, United States Air Force \\
+  Acquirer:       &	University of Hawaii Institute for Astronomy \\
+  User: 	  &	Astronomical community \\
+  Developer:      &	University of Hawaii Institute for Astronomy, participating \\
+  &       institutions, and associated subcontractors	
+\end{tabular}
+
+\subsection{Document Overview}
+
+This document identifies the interface between the IPP and MOPS
+subsystems of the Pan-STARRS PS-1 Telescope.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+\DocumentsInternalSection
+PSDC-230-001  &   PS-1 Design Reference Mission \\ \hline
+PSDC-230-002  &   PS-1 System Concept Definition \\ \hline
+\DocumentsExternalSection
+POSIX Standard & Open Group Based Specifications Issue 6, IEEE Std 1003.1, 2003 \\
+FITS Standard & Definition of the Flexible Image Transport System (FITS),
+March 29, 1999, NOST 100-2.0 \\
+\DocumentsEnd
+
+\section{Interface Overview}
+
+\subsection{Pan-STARRS Software Interfaces}
+
+The Pan-STARRS PS-1 Telescope system has multiple
+subsystem-to-subsystem interfaces, illustrated in
+Figure~\ref{fig:overview}.  The subsystem-to-subsystem interfaces are
+each documented in separate documents.  The interface numbers refer to
+the Pan-STARRS Document Control numbering scheme for the interface
+documents.  All Interface Control Documents are numbered
+PSDC-940-XXX-VV, while all Interface Requirements Specifications are
+numbered PSDC-930-XXX-VV, where XXX is the number listed above and VV
+is a document version number.  Table~\ref{tab:overview} lists the
+organizational structure of all Pan-STARRS interfaces, giving the
+corresponding interface number listed in Figure~\ref{fig:overview},
+the group of data being transferred (the assembly), the method in
+which the data is formatted (packing), and the data transfer method
+(protocol).
+
+\begin{figure}
+  \begin{center}
+    \epsfig{file=figures/PSSWIF.eps}
+    \caption{Overview of Pan-STARRS Software Interfaces.}
+    \label{fig:overview}
+  \end{center}
+\end{figure}
+
+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
+addressed by this document are marked in the table.
+
+\begin{table}
+  \begin{center}
+    \caption{Pan-STARRS Interface Data Organization}
+    \label{tab:overview}
+    \begin{tabular}{|l|l|l|l|}
+      \hline
+      {\bf Interface \#} & {\bf Assembly} & {\bf Packaging} & {\bf Protocol} \\ \hline
+      001.2 & Telescope Commands     & EOST Command Language      & Command Socket \\
+      002.2 & Camera Commands        & Conductor Command Language & Command Socket \\
+      002.3 & Camera Status          & ???                        & Shared Name Space \\
+      002.4 & IQ Images              & FITS Images                & Data Store \\
+      003.2 & GPC Images \& Metadata & FITS Images \& Headers     & Data Store \\
+      \hline
+      004.2 & OTIS Metadata          & FITS Tables                & Data Store \\
+      004.3 & ISP Images \& Metadata & FITS Images \& Headers     & Data Store \\
+      004.4 & Reference Star Catalog & FITS Tables                & Data Store \\
+      004.5 & Focal Plane Layout     & FITS Tables                & Data Store \\
+      \hline
+      005.2 & Detections             & FITS Tables                & Data Store \\
+      005.3 & Test Positions         & FITS Tables                & Data Store \\
+      006.2 & Detections             & FITS Tables                & Data Store \\
+      006.3 & Metadata               & FITS Tables                & Data Store \\
+      006.4 & Images                 & FITS Tables                & Data Store \\
+      007.2 & Orbits \& Detections   & FITS Tables                & Data Store \\
+      008.2 & Detections             & FITS Tables                & Data Store \\
+      008.3 & Metadata               & FITS Tables                & Data Store \\
+      008.4 & Images                 & FITS Tables                & Data Store \\
+      \hline
+    \end{tabular}
+  \end{center}
+\end{table}
+
+Layers of network communications are often classified using the
+\htmladdnormallink{OSI Reference
+  Model}{http://en.wikipedia.org/wiki/OSI_reference_model}.  When addressing
+network connectivity between subsystem interfaces, this
+Interface Control Document is primarily concerned with two highest
+layers of the interface communication: the presentation layer, or how
+the data is packaged, and the application layer, or the high-level details of the
+data contents.  The lower layers of the network communication in the OSI model
+are addressed briefly below.
+
+The leased line between the IPP and MOPS is currently expected to have a practical
+maximum sustainable throughput of 50Mbits/s, since the systems will be connected
+through the University of Hawaii ITS network.  Higher and lower bit rates are available,
+and the cost diffferences are quite significant.
+
+\subsubsection{Physical Layer}
+
+MOPS and IPP will each be connected to local inbound and outbound hardware
+interfaces at rates of no less than 1Gbit/sec using fiber or twisted pair
+and onboard NICs where possible.
+
+\subsubsection{Data Link Layer}
+
+The endpoints of the route between IPP and MOPS will be Gigabit
+Ethernet with normal (1500 byte) max. transmission units (MTU).
+
+\subsubsection{Network Layer}
+
+Internet Protocol v4 will be used.  Data Store's HTTP
+server will have an IP address visible (routable) to IPP.
+
+\subsubsection{Transport Layer}
+
+TCP will be used on top of IPv4.
+
+\subsubsection{Session Layer}
+
+IPP-MOPS communication will take place entirely via the Data Store
+mechanism.
+
+\subsubsection{Presentation Layer}
+
+All data exchanged between IPP and MOPS will be in the form of FITS
+Tables and FITS images.
+
+The primary header will not contain any information beyond that
+written automatically by cfitsio, and is present only for compliance
+with the FITS standard.
+
+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.
+
+\subsection{IPP-MOPS Exchange}
+
+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.
+
+\subsubsection{Conventions}
+
+\begin{enumerate}
+\item Celestial coordinates are in ICRS;
+\item Magnitudes are AB magnitudes (flux zero point is 3631 Jy);
+\item Unless otherwise noted, error values are statistical only, and
+  include no contribution by systematic errors.
+\end{enumerate}
+
+\subsubsection{Transient Detection and Metadata Exchange}
+
+Transient detections and their metadata are assembled nightly into
+FITS files, one file per FPA.  IPP will submit outgoing data into the
+IPP-MOPS outbound datastore.  Metadata for the detections belonging to
+a FPA will be described in the file's FITS headers, and detection data
+will be listed in a subsequent FITS BINTABLE table in the same file.
+
+Each column in the FITS table shall correspond to a detection attribute.
+The data type of a FITS column shall be chosen to represent the attribute
+without loss of information.
+
+The FITS table will include all detections within an exposure.
+
+Duplicates from overlapping skycells will have been filtered out by
+IPP, with the measurements from the source closest to the centre of a
+skycell included (and all others discarded).
+
+\subsubsection{Detectability}
+
+MOPS will need to query the IPP periodically to inquire whether a
+particular elongated trailed detection specified by a ($RA_0$,
+$Dec_0$, $Time_0$, $RA_1$, $Dec_1$, $Time_1$) tuple was detectable by
+the PS-1 telescope.  This query is important in evaluating
+``non-detections,'' or failures of MOPS to locate predicted detections
+of a known object, and for accurate simulation of detections of
+synthetic objects that are injected into the MOPS pipeline to measure
+efficiency.
+
+MOPS will assemble a list of (RA, Dec, Time) tuples in a single FITS
+file and submit them to the MOPS-IPP outgoing datastore.  Later MOPS
+will poll the IPP datastore for results of this query.  If results of
+a query do not appear after a pre-configured timeout, an operator is
+notified.
+
+\subsubsection{Table Description Files}
+
+FITS tables generated by IPP or MOPS shall be described by table
+description files.  These files shall be controlled by CVS, with the
+authoritative versions of these files being the ones contained in
+Appendix A of this document. FITS header data units (HDUs) which do
+not conform to the corresponding table description files shall be
+rejected by the receiver, and the ingest software shall notify an
+operator about the error.
+
+In addition to the required keywords specified in the FITS standard
+for a BINTABLE extension, each FITS HDU shall have the following
+keywords:
+
+\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.
+\end{itemize}
+
+The format of the metadata tables is described in the following sections.
+
+\subsubsection{Fields in Table Description Files}
+
+The IPP software generating the FITS tables may change. Parameters,
+i.e. columns in FITS tables, may also be added requiring changes both
+in ICD and in software. To keep track of such changes, a Version will
+be assigned to each keyword in the tables descriptions.
+
+To improve the readability, keywords appearing only in the
+\outformatversion{} software version are shown. For previous releases
+of this documentation and learn about the former output format,
+checkout \htmladdnormallink{the older SVN revision
+  34506}{https://svn.pan-starrs.ifa.hawaii.edu/repo/ipp/trunk/ppTranslate/documentation/ICD}.
+
+The following conventions for the Version numbering is used: $X+$
+(where $X$ is the output format version in \texttt{PS1\_DV$X$}) means
+that the keyword appeared in software version X until the current
+version.
+
+\subsubsection{ICD/Software Versions}
+
+\begin{tabular}{|c|c|c|c|p{3in}|}
+  \hline
+  SW Version & ICD Version & Output Version & Software Tag & Comment \\
+  \hline
+  0 & 00 & 0 & n/a & Preliminary ICD. No sw tag \\
+  1 & 01 & \texttt{PS1\_DV1} & 20100823 & First software release \\
+  2 & 01 & \texttt{PS1\_DV2} & 20101029 & "V2" software version \\
+  2 & 02 & \texttt{PS1\_DV2} & 20110406 & Deletion of "ICD lite" wiki page (Documentation update only)\\
+  4 & 03 & \texttt{PS1\_DV3} & \emph{No tag yet} &  Extended parameters (fitted trails), warp-stack\\
+  \hline
+\end{tabular}
+
+\subsubsection{Transfer via Data Store}
+
+The FITS files containing metadata shall be tranferred using the protocol 
+described in [Data Store doc]. There will be one instance of a datastore 
+within IPP that will be used to submit transient detections and results 
+of detectability queries to MOPS, and
+another instance residing within MOPS to submit detectability requests to the IPP.
+
+During a datastore transaction, the ``sender'' places a file into the datastore with a unique
+transfer ID. The ``receiver'' must regularly poll the datastore to
+detect new FITS files. The receiver then downloads each file from a URL
+provided by the Data Store interface. The receiver is responsible for
+managing which files it has already downloaded. Files remain in
+the datastore for a preset period of time and then are deleted without
+warning. If a file transfer fails, the receiver may retry the transfer,
+If a retry fails, the failure must be resolved by operator intervention.
+
+The data transfers will have the following parameters:
+
+\begin{table}[htbp]
+  \begin{center}
+    \caption{Data transfer parameters}
+    \begin{tabular}{|l|l|l|}
+      \hline
+      \hline
+      {\bf Parameter} & {\bf IPP to MOPS} & {\bf MOPS to IPP} \\ 
+      \hline
+      Dump interval & Per FPA & Per FPA \\
+      Max polling Interval & 60s & 60s \\
+      File Lifetime & 30 days & 10 days \\
+      Datastore location & IPP & MOPS \\ \hline
+    \end{tabular}
+  \end{center}
+\end{table}
+
+\subsection{Transient Detection List}
+
+IPP will submit all transient detections per FPA and their associated
+metadata in a single FITS file.  The metadata will be placed in FITS
+header data unit (HDU) key-value pairs, and the detection attributes
+will be placed in the associated FITS table following the header.  All
+time-dependent table values shall be provided at the midpoint of the
+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
+    \hline
+  \end{longtable}
+}
+
+{\centering
+  \tabcaption{IPP-MOPS Transient Detection Table Columns\label{trans-table}}
+  \begin{longtable}{|lclp{3.5in}|}
+    \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 \\
+    \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 \\
+    \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
+  \end{longtable}
+}
+
+\subsection{MOPS Detectability Query}
+
+MOPS will query the IPP regarding the detectability of hypothetical
+elongated detections specified using ($RA_0$, $Dec_0$, $Time_0$,
+$RA_1$, $Dec_1$, $Time_1$) tuples by submitting all information
+required to construct a FPA PSF at the time of the detections.  It is
+the responsibility of MOPS to generate and manage unique query IDs.
+
+All MOPS detectability queries will occur with respect to an already-ingested
+FPA transient detection list.  The query being asked by MOPS is essentially
+whether a particular trail in an acquired FPA image was masked for any
+reason and to what degree.  Thus the originating IPP FPA\_ID is required.
+
+MOPS will simulate elongated (``trailed'') PSFs, relevant for
+fast-moving objects.  Since some or all of a trail may be masked, MOPS
+will for all detections provide starting and ending RA and Dec.  For
+most detections these two positions will be nearly coincident,
+appearing as a circular point-source PSF, but for fast-moving objects
+these positions may differ by many pixels in the FPA.
+
+In addition to the required BINTABLE extension header keywords
+described above, the FITS header for the detectability query shall
+include the following required keywords shown in table
+\ref{detquery-keywords}.  The subsequent FITS table, with EXTNAME of
+\code{MOPS_DETECTABILITY_QUERY}, shall include columns whose
+definitions are listed in table \ref{detquery-table}.
+
+% \begin{table}[htbp]
+% \begin{center}
+{\centering%
+\small
+    \tabcaption{MOPS-IPP Detectability Query Keywords\label{detquery-keywords}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Column}            & {\bf Precision} & {\bf Description} \\
+\hline
+QUERY\_ID  & char(20) & MOPS query ID for this batch query \\
+FPA\_ID    & char(20) & original FPA\_ID used at ingest \\
+MJD-OBS    & F64 & starting time of the exposure, MJD \\
+FILTER     & char(3) & effective filter used for the exposure as a string, allowed values of g, r, i, z, y, B, V, w \\
+OBSCODE    & char(3) & site identifier (MPC observatory code) \\
+\end{tabular}
+}
+% \end{center}
+% \end{table}
+
+
+% \begin{table}[htbp]
+% \begin{center}
+{\centering%
+\small
+\tabcaption{MOPS-IPP Detectability Query Table Columns\label{detquery-table}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Column}            & {\bf Precision} & {\bf Description} \\
+\hline
+ROWNUM      & char(20) & identifier for this row in the table \\
+RA1\_DEG    & F64 & coordinate at the start of exposure, in degrees \\
+DEC1\_DEG   & F64 & coordinate at the start of exposure, in degrees \\
+RA2\_DEG    & F64 & coordinate at the end of exposure, in degrees \\
+DEC2\_DEG   & F64 & coordinate at the end of exposure, in degrees \\
+MAG         & F64 & apparent magnitude \\
+\end{tabular}
+}
+% \end{center}
+% \end{table}
+
+\subsection{IPP Detectability Response}
+
+IPP will return a table listing the submitted query detections and a
+pair of values $(N, f)$ indicating the number of pixels relevant to the detection's PSF
+and a fraction of pixels detectable by IPP.
+
+For infrequent cases where a trail may completely traverse a masked area (due to chip gap, streak removal, or similar), the response may be erroneous or incomplete.  This error and its effects will be studied during PS-1 operations.
+
+In addition to the required BINTABLE extension header keywords
+described above, the FITS header for the detectability response shall include
+the following required keywords shown in table \ref{detresponse-keywords}.
+The subsequent FITS table, with EXTNAME of \code{MOPS_DETECTABILITY_RESPONSE}, shall include 
+columns whose definitions are listed in table \ref{detresponse-table}.
+
+{\centering%
+% \begin{table}[htbp]
+% \begin{center}
+\small
+\tabcaption{MOPS-IPP Detectability Response Keywords\label{detresponse-keywords}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Column}            & {\bf Precision} & {\bf Description} \\
+\hline
+QUERY\_ID   & char(20)    & originating MOPS query ID \\
+FPA\_ID     & char(20)    & IPP FPA ID used in detectability request \\
+\end{tabular}
+}
+% \end{center}
+% \end{table}
+
+% \begin{table}[htbp]
+% \begin{center}
+{\centering%
+\small
+\tabcaption{MOPS-IPP Detectability Response Table Columns\label{detresponse-table}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Column}            & {\bf Precision} & {\bf Description} \\
+\hline
+ROWNUM      & char(20) & matching rownum from original request \\
+DETECT\_N   & U32 & number of pixels used in the hypothetical PSF for the query detection \\
+DETECT\_F   & F64 & detectability, indicating the fraction of PSF pixels detectable by IPP \\
+\end{tabular}
+}
+% \end{center}
+% \end{table}
+
+\pagebreak
+\appendix
+
+\section{Appendix}
+
+\subsection{IPP to MOPS}
+
+\begin{table}[htbp]
+\begin{center}
+\small
+\caption{IPP-MOPS FITS Table Description Files\label{table-types-ipp-mops}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Table Name}            & {\bf EXTNAME} & {\bf Description} \\
+\hline
+Transient Detections        & \code{MOPS_TRANSIENT_DETECTIONS} & list of transient detections for an FPA \\
+Detectability Query Result  & \code{MOPS_DETECTABILITY_RESPONSE} & table of detectability values in response to query\\
+\end{tabular}
+\end{center}
+\end{table}
+
+\subsection{MOPS to IPP}
+
+\begin{table}[htbp]
+\begin{center}
+\small
+\caption{MOPS-IPP FITS Table Description Files\label{table-types-mops-ipp}}
+\begin{tabular}{lll}
+\hline
+\hline
+{\bf Table Name}            & {\bf EXTNAME} & {\bf Description} \\
+\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}
+\end{table}
+
+\subsection{Limitations}
+\label{sec-limitations}
+
+\begin{itemize}
+\item The IPP is not yet calculating detection efficiencies (it is
+  still being developed). Further, it is not yet clear how to merge
+  the detection efficiency measurements for different skycells. Until
+  these issues are resolved, the detection efficiency values will be
+  fake (Expected fields: DE\_MAGnn (F32): Magnitude (calibrated) for
+  detection efficiency; DE\_EFFnn (F32): Detection efficiency (0..1)).
+\item ANGLE, ANGLE\_SIG, LENGTH, LENGTH\_SIG removed; these can be
+  calculated from the moment;
+\item FLUX, FLUX\_SIG renamed MAG, MAG\_ERR since IPP writes
+  magnitudes;
+\item FLAGS added to allow additional weeding out of bad detections;
+\item DIFF\_SKYFILE\_ID added to allow trace back to IPP diff skyfile,
+  for postage stamps;
+\item STARPSF renamed EXT\_SIGNIFICANCE to be more clear
+\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/src/ppMops.h
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMops.h	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMops.h	(revision 34566)
@@ -28,4 +28,9 @@
   psString output;                    // Output filename
   psU16 version;                      // Version (for parameters)
+  psString comment;                   // Comment associated with the first argument of the diff
+  psString obsMode;                   // Observation mode
+  psString difftype;                  // WW (Warp-Warp Diff) or WS (Warp-Stack Diff) or SW (Stack-Warp Diff)
+  float sky;                          // Exposure avg sky background
+  psString shutoutc;                  // Camera exposure shutter open (UTC)
 } ppMopsArguments;
 
@@ -51,4 +56,6 @@
   psVector *ra, *dec;                 // Sky coordinates
   psVector *raErr, *decErr;           // Error in sky coordinates
+  psVector *raExt, *decExt;           // Sky coordinates for RA_EXT and DEC_EXT
+  psVector *raExtErr, *decExtErr;     // Error in sky coordinates for RA_EXT and DEC_EXT
   psVector *mask;                     // Mask for detections
 } ppMopsDetections;
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsArguments.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsArguments.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsArguments.c	(revision 34566)
@@ -44,5 +44,8 @@
     psFree(args->input);
     psFree(args->exp_name);
-    psFree(args->output);
+    psFree(args->comment);
+    psFree(args->obsMode);
+    psFree(args->difftype);
+    psFree(args->shutoutc);
     return;
 }
@@ -52,5 +55,4 @@
     ppMopsArguments *args = psAlloc(sizeof(ppMopsArguments)); // Data to return
     psMemSetDeallocator(args, (psFreeFunc)mopsArgumentsFree);
-
     args->input = NULL;
     args->exp_name = NULL;
@@ -67,5 +69,9 @@
     args->output = NULL;
     args->version = 1;
-
+    args->comment = NULL;
+    args->obsMode = NULL;
+    args->difftype = NULL;
+    args->sky = NAN;
+    args->shutoutc = NULL;
     return args;
 }
@@ -93,4 +99,9 @@
     psMetadataAddF32(arguments, PS_LIST_TAIL, "-astrom_rms", 0, "Astrometric solution RMS", NAN);
     psMetadataAddU16(arguments, PS_LIST_TAIL, "-version", 0, "CMF file version", 0);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-comment", 0, "Exposure comment", "No comment provided");
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-obsmode", 0, "Observation mode", "No obsmode provided");
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-difftype", 0, "Either WW (Warp-Warp Diff) or WS (Warp-Stack Diff)", "No difftype provided");
+    psMetadataAddF32(arguments, PS_LIST_TAIL, "-sky", 0, "Exposure avg sky background", NAN);
+    psMetadataAddStr(arguments, PS_LIST_TAIL, "-shutoutc", 0, "Camera exposure shutter open (UTC)", "No shutoutc provided");
     if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 3) {
         usage(argv[0], arguments);
@@ -120,4 +131,9 @@
     args->rmsAstrom = psMetadataLookupF32(NULL, arguments, "-astrom_rms");
     args->version = psMetadataLookupU16(NULL, arguments, "-version");
+    args->comment = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-comment"));
+    args->obsMode = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-obsmode"));
+    args->difftype = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-difftype"));
+    args->sky = psMetadataLookupF32(NULL, arguments, "-sky");
+    args->shutoutc = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-shutoutc"));
 
     psTrace("ppMops.args", 1, "Done parsing command-line arguments\n");
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsGetSkyChipPsfVersion.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsGetSkyChipPsfVersion.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsGetSkyChipPsfVersion.c	(revision 34566)
@@ -16,5 +16,5 @@
   } else if (strcmp(version, "PS1_DV3") == 0) {
     psFree(headerSkyChip);
-    return 2;
+    return 3;
   }
   psWarning("Unsupported EXTTYPE in SkyChip.psf table: [%s]", version);
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsMerge.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsMerge.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsMerge.c	(revision 34566)
@@ -301,6 +301,5 @@
                                                 vector->n, newLength);
             }
-                
-        }
+	}
         // XXX IS this safe? Perhaps save in numGood?
         det->num = newLength;
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsRead.c	(revision 34566)
@@ -1,2 +1,80 @@
+/*
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * 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
+/*
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -8,6 +86,11 @@
 #include "ppMops.h"
 
-static void addDummyValues(psMetadata* md, long size);
+static void addDummyValues(psMetadata* md, long size, int version);
 static void replaceDummyValuesF32(const char* colName, psMetadata* source, psMetadata* target, psVector* indexes);
+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
 
 /*
@@ -24,4 +107,5 @@
   for (int i = 0; i < num; i++) {
     const char *name = inNames->data[i];
+    printf("%s\n", name);
 
     psFits *fits = psFitsOpen(name,  "r"); // FITS file
@@ -95,11 +179,8 @@
     det->az = psMetadataLookupF64(NULL, header, "FPA.AZ");
     det->mjd = psMetadataLookupF64(NULL, header, "MJD-OBS") + det->exptime / 2.0 / 3600 / 24;
-
-    det->seeing = (float) 0.5 * (psMetadataLookupF32(NULL, header, "FWHM_MAJ") +
-				 psMetadataLookupF32(NULL, header, "FWHM_MIN"));
-
+    //The global SEEING is the mean of all defined FWHM_MAJ
+    det->seeing = psMetadataLookupF32(NULL, header, "FWHM_MAJ");
     det->naxis1 = psMetadataLookupS32(NULL, header, "IMNAXIS1"); // Number of columns
     det->naxis2 = psMetadataLookupS32(NULL, header, "IMNAXIS2"); // Number of rows
-
     psFree(header);
 
@@ -116,10 +197,12 @@
     if (skyChipPsfVersion >= 2) {
       //First: append all the new columns that we want to the existing table
-      addDummyValues(det->table, size);
+      addDummyValues(det->table, size, args->version);
       if (!psFitsMoveExtName(fits, "SkyChip.xfit")) {
 	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);
@@ -127,5 +210,7 @@
 	  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);
@@ -133,4 +218,5 @@
 	  }
 	  //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);
@@ -140,15 +226,38 @@
 	  replaceDummyValuesF32("EXT_INST_MAG",  fittedTrails, det->table, idet);
 	  replaceDummyValuesF32("EXT_INST_MAG_SIG",  fittedTrails, det->table, idet);
-	  replaceDummyValuesF32("NPARAMS",  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);
-	  replaceDummyValuesF32("EXT_WIDTH_MIN_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");
+	  }
 	}
       }
     }
-
     psFitsClose(fits);
 
@@ -161,7 +270,13 @@
     psVector *ra = psMetadataLookupVector(NULL, table, "RA_PSF");
     psVector *dec = psMetadataLookupVector(NULL, table, "DEC_PSF");
-
     det->raErr = psVectorAlloc(size, PS_TYPE_F64);
     det->decErr = psVectorAlloc(size, PS_TYPE_F64);
+    if (skyChipPsfVersion >= 3) {
+      det->raExtErr = psVectorAlloc(size, PS_TYPE_F64);
+      det->decExtErr = psVectorAlloc(size, PS_TYPE_F64);
+    } else {
+      det->raExtErr = NULL;
+      det->decExtErr = NULL;
+    }
     det->mask = psVectorAlloc(size, PS_TYPE_U8);
 
@@ -177,6 +292,10 @@
 
     // Add our new vectors to the table so that duplicates and masked items may be purged
+    psMetadataAddVector(table, PS_LIST_HEAD, "RA_ERR", 0, NULL, det->raErr);
     psMetadataAddVector(table, PS_LIST_HEAD, "DEC_ERR", 0, NULL, det->decErr);
-    psMetadataAddVector(table, PS_LIST_HEAD, "RA_ERR", 0, NULL, det->raErr);
+    if (skyChipPsfVersion >= 3) {
+      psMetadataAddVector(table, PS_LIST_HEAD, "RA_EXT_SIGMA", 0, NULL, det->raExtErr);
+      psMetadataAddVector(table, PS_LIST_HEAD, "DEC_EXT_SIGMA", 0, NULL, det->decExtErr);
+    }
 
     psTrace("ppMops.read", 2, "Read %ld rows from %s\n", det->num, det->component);
@@ -189,9 +308,18 @@
     psVector *angleV = psMetadataLookupVector(NULL, table, "POSANGLE");
     psVector *flagsV = psMetadataLookupVector(NULL, table, "FLAGS");
+    psVector *xExtErrV = NULL;
+    psVector *yExtErrV = NULL;
+    psVector *scaleExtV = NULL;
+    psVector *angleExtV = NULL;
+    if (skyChipPsfVersion >= 3) {
+      xExtErrV = psMetadataLookupVector(NULL, table, "X_EXT_SIG");
+      yExtErrV = psMetadataLookupVector(NULL, table, "Y_EXT_SIG");
+      scaleExtV = psMetadataLookupVector(NULL, table, "PLTSCALE_EXT");
+      angleExtV = psMetadataLookupVector(NULL, table, "POSANG_EXT");
+    }
 
     double plateScale = 0.0;        // Plate scale
     long numGood = 0;               // Number of good rows
     for (long row = 0; row < size; row++) {
-
       psU32 flags = flagsV->data.U32[row]; // psFitsTableGetU32(NULL, table, row, "FLAGS");
       if (flags & SOURCE_MASK) {
@@ -205,5 +333,9 @@
       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]) ||
@@ -233,8 +365,26 @@
       plateScale += scale;
       numGood++;
-    }
-    det->seeing *= ((float) plateScale) / ((float) numGood);
-
-    // Are we using numGood for anything outside of this function?
+
+      // 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);
+      }
+    }
     det->numGood = numGood;
 
@@ -256,6 +406,18 @@
   return dummy;
 }
-
-static void addDummyValues(psMetadata* md, long size) {
+#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);
+  return dummy;
+}
+
+static void addDummyValues(psMetadata* md, long size, int version) {
   psMetadataAdd(md, PS_LIST_TAIL, "X_EXT", PS_DATA_VECTOR, "EXT model x coordinate", createDummyF32(size));
   psMetadataAdd(md, PS_LIST_TAIL, "Y_EXT", PS_DATA_VECTOR, "EXT model y coordinate", createDummyF32(size));
@@ -264,5 +426,5 @@
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_INST_MAG",  PS_DATA_VECTOR, "EXT fit instrumental magnitude", createDummyF32(size));
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_INST_MAG_SIG",  PS_DATA_VECTOR, "Sigma of PSF instrumental magnitude", createDummyF32(size));
-  psMetadataAdd(md, PS_LIST_TAIL, "NPARAMS",  PS_DATA_VECTOR, "Number of model parameters", createDummyF32(size));
+  psMetadataAdd(md, PS_LIST_TAIL, "NPARAMS",  PS_DATA_VECTOR, "Number of model parameters", createDummyS32(size));
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_WIDTH_MAJ",  PS_DATA_VECTOR, "EXT width (major axis), length for trail", createDummyF32(size));
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_WIDTH_MIN",  PS_DATA_VECTOR, "EXT width (minor axis), sigma for trail", createDummyF32(size));
@@ -271,7 +433,26 @@
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_WIDTH_MIN_ERR",  PS_DATA_VECTOR, "EXT width error (minor axis)", createDummyF32(size));
   psMetadataAdd(md, PS_LIST_TAIL, "EXT_THETA_ERR",  PS_DATA_VECTOR, "EXT orientation angle (error)", createDummyF32(size));
+  if (version >= 3) {
+    psTrace("ppMops.read", 10, "Adding columns for version PS1_DV%d\n", version);
+    psMetadataAdd(md, PS_LIST_TAIL, "RA_EXT",  PS_DATA_VECTOR, "Fitted centroid RA", createDummyF32(size));
+/*     psMetadataAdd(md, PS_LIST_TAIL, "RA_EXT_SIGMA",  PS_DATA_VECTOR, "Fitted RA sigma", createDummyF32(size)); *\/ */
+    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));
+    psMetadataAdd(md, PS_LIST_TAIL, "EXT_CAL_MAG",  PS_DATA_VECTOR, "Calibrated mag", createDummyF32(size));
+    psMetadataAdd(md, PS_LIST_TAIL, "EXT_MAG_SIG",  PS_DATA_VECTOR, "Mag sigma", createDummyF32(size));
+    psMetadataAdd(md, PS_LIST_TAIL, "EXT_CHISQ",  PS_DATA_VECTOR, "Chi^2 of fit", createDummyF32(size));
+    psMetadataAdd(md, PS_LIST_TAIL, "EXT_NDOF",  PS_DATA_VECTOR, "Fit degrees of freedom", createDummyS32(size));
+  }
 }
 
 static void replaceDummyValuesF32(const char* colName, psMetadata* source, psMetadata* target, psVector* indexes) {
+  psTrace("ppMops.read", 10, "Trying to get column %s\n", colName);
   psVector* source_vector = psMetadataLookupVector(NULL, source, colName);
   psVector* target_vector = psMetadataLookupVector(NULL, target, colName);
@@ -279,3 +460,24 @@
     target_vector->data.F32[indexes->data.S64[index]] = source_vector->data.F32[index];
   }
-}
+  psTrace("ppMops.read", 10, "OK for %s\n", colName);
+}
+
+static void replaceDummyValuesS32(const char* colName, psMetadata* source, psMetadata* target, psVector* indexes) {
+  psTrace("ppMops.read", 10, "Trying to get column %s\n", colName);
+  psVector* source_vector = psMetadataLookupVector(NULL, source, colName);
+  psVector* target_vector = psMetadataLookupVector(NULL, target, colName);
+  for (long index = 0; index<indexes->n; ++index) {
+    target_vector->data.S32[indexes->data.S64[index]] = source_vector->data.S32[index];
+  }
+  psTrace("ppMops.read", 10, "OK for %s\n", colName);
+}
+
+static void renameDummyValuesF32(const char* colNameSource, psMetadata* source, const char* colNameTarget, psMetadata* target, psVector* indexes) {
+  psTrace("ppMops.read", 10, "Trying to rename column %s to %s\n", colNameSource, colNameTarget);
+  psVector* source_vector = psMetadataLookupVector(NULL, source, colNameSource);
+  psVector* target_vector = psMetadataLookupVector(NULL, target, colNameTarget);
+  for (long index = 0; index<indexes->n; ++index) {
+    target_vector->data.F32[indexes->data.S64[index]] = source_vector->data.F32[index];
+  }
+  psTrace("ppMops.read", 10, "OK for %s (renamed by %s)\n", colNameSource, colNameTarget);
+}
Index: /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c	(revision 34565)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/src/ppMopsWrite.c	(revision 34566)
@@ -41,5 +41,4 @@
   // seeings
   ppMopsDetections *det = NULL;
-  int validSeeingCount = 0;
   for (int d = 0; d < detections->n; d++) {
     if (detections->data[d] != NULL) {
@@ -47,21 +46,17 @@
         det = detections->data[d];
       }
-      if (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) {
-        validSeeingCount += 1;
-      }
-    }
-  }
+    }
+  }
+  //Get the SEEING weighted mean
+  float seeing = 0.;
+  int totalGood = 0;
+  for (int d = 0; d < detections->n; d++) {
+    if ( (detections->data[d] != NULL) && (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) ) {
+      seeing += ((ppMopsDetections*) detections->data[d])->seeing;
+      totalGood += 1;
+    }
+  }
+  seeing /= (float) totalGood;
   if (det != NULL) {
-    //Get the SEEING median
-    psVector* seeingValues = psVectorAlloc(validSeeingCount, PS_TYPE_F32);
-    psVectorInit(seeingValues, NAN);
-    validSeeingCount = 0;
-    for (int d = 0; d < detections->n; d++) {
-      if ( (detections->data[d] != NULL) && (isfinite(((ppMopsDetections*) detections->data[d])->seeing)) ){
-        seeingValues->data.F32[validSeeingCount++] = ((ppMopsDetections*) detections->data[d])->seeing;
-      }
-    }
-    psStats *seeingStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
-    psVectorStats(seeingStats, seeingValues, NULL, NULL, 0);
     psMetadataAddF64(header, PS_LIST_TAIL, "MJD-OBS", 0, "MJD of exposure midpoint", det->mjd);
     psMetadataAddStr(header, PS_LIST_TAIL, "RA", 0, "Right Ascension of boresight", det->raBoresight);
@@ -73,5 +68,7 @@
     psMetadataAddStr(header, PS_LIST_TAIL, "FILTER", 0, "Filter name", det->filter);
     psMetadataAddF32(header, PS_LIST_TAIL, "AIRMASS", 0, "Airmass of exposure", det->airmass);
-    psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", seeingStats->sampleMedian);
+    psMetadataAddF32(header, PS_LIST_TAIL, "SEEING", 0, "Mean seeing", seeing);
+    //MOPS want the name FWHM for SEEING
+    psMetadataAddF32(header, PS_LIST_TAIL, "FWHM", 0, "Mean seeing", seeing);
   } else {
     psWarning("no inputs with surviving detections. output header will be incomplete");
@@ -79,6 +76,13 @@
   psMetadataAddStr(header, PS_LIST_TAIL, "OBSCODE", 0, "IAU Observatory code", OBSERVATORY_CODE);
   psMetadataAddF32(header, PS_LIST_TAIL, "MAGZP", 0, "Magnitude zero point", args->zp);
+  //MOPS want the name ZEROPOINT for MAGZP
+  psMetadataAddF32(header, PS_LIST_TAIL, "ZEROPOINT", 0, "Magnitude zero point", args->zp);
   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, "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);
 
   //field in header that tells about the CMF version
@@ -187,5 +191,27 @@
                      0);
       if (args->version == 3) {
-        // TODO: Write data of version 3 (see ICD)
+	// 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);
       }
     }
@@ -276,4 +302,18 @@
       addColumn("EXT_THETA_ERR", NULL, 0);
     }
+    if (args->version >= 3) {
+      addColumn("RA_EXT", NULL, 0);
+      addColumn("RA_EXT_SIGMA", NULL, 0);
+      addColumn("DEC_EXT", NULL, 0);
+      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);
+      addColumn("EXT_MAG_SIG", NULL, 0);
+      addColumn("EXT_CHISQ", NULL, 0);
+      addColumn("EXT_NDOF", NULL, 0);
+    }
+
     if (!psFitsWriteTableAllColumns(fits, header, table, OUT_EXTNAME)) {
       psError(psErrorCodeLast(), false, "Unable to write table");
Index: /branches/eam_branches/ipp-20120905/ppTranslate/tests/integration/build_inputs_for_ppMops.sh
===================================================================
--- /branches/eam_branches/ipp-20120905/ppTranslate/tests/integration/build_inputs_for_ppMops.sh	(revision 34566)
+++ /branches/eam_branches/ipp-20120905/ppTranslate/tests/integration/build_inputs_for_ppMops.sh	(revision 34566)
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# This script creates the pos and neg files that the ppMops program
+# needs as input.
+#
+# Only one argument is required: the diff_id of the exposure
+#
+# e.g.:
+# $0 308413
+#
+DIFFID=$1
+if [ "$DIFFID" == "" ]; then
+  echo "$0 <diff_id>"
+  echo "  Create the pos and neg files that the ppMops program"
+  echo "  needs as input."
+  exit 1
+fi
+
+OUTPUTROOT=test.$DIFFID
+
+for f in `difftool -dbname gpc1 -diffskyfile -diff_id $DIFFID | grep path_base | sed 's/path_base//g' | sed 's/ STR //g' | tr -d ' '`; do
+  neb-ls -p $f.cmf >> $OUTPUTROOT.pos
+done
+
+for f in `difftool -dbname gpc1 -diffskyfile -diff_id $DIFFID | grep path_base | sed 's/path_base//g' | sed 's/ STR //g' | tr -d ' '`; do
+  neb-ls -p $f.inv.cmf >> $OUTPUTROOT.neg
+done
+
