Index: /branches/czw_branch/20110406/Ohana/src/addstar/include/skycells.h
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/addstar/include/skycells.h	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/addstar/include/skycells.h	(revision 31253)
@@ -65,4 +65,5 @@
 int    NMAX;
 int    NX_SUB, NY_SUB;
+int    X_PARITY;
 double SCALE;
 double PADDING;
Index: /branches/czw_branch/20110406/Ohana/src/addstar/src/args_skycells.c
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/addstar/src/args_skycells.c	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/addstar/src/args_skycells.c	(revision 31253)
@@ -188,4 +188,9 @@
     remove_argument (N, &argc, argv);
     OVERLAP_DEC  = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  X_PARITY = 1;
+  if ((N = get_argument (argc, argv, "-skyparity"))) {
+    X_PARITY = -1;
     remove_argument (N, &argc, argv);
   }
@@ -224,5 +229,7 @@
   fprintf (stderr, "  -nx Nx                      : subdivide skycell projection in x by Nx\n");
   fprintf (stderr, "  -ny Ny                      : subdivide skycell projection in y by Ny\n");
+  fprintf (stderr, "  -overlap Or Od              : overlap between skycells (arcseconds)\n");
   fprintf (stderr, "  -projection-number Np       : set projection-number (local mode only)\n");
+  fprintf (stderr, "  -skyparity                  : set wcs for skycells so that east is to the left\n");
   fprintf (stderr, "  -help                       : this list\n");
   fprintf (stderr, "  -h                          : this list\n\n");
Index: /branches/czw_branch/20110406/Ohana/src/addstar/src/sky_tessalation.c
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/addstar/src/sky_tessalation.c	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/addstar/src/sky_tessalation.c	(revision 31253)
@@ -318,5 +318,6 @@
   memset (image, 0, sizeof(Image));
   image[0].coords = *refcoords;
-  image[0].coords.pc1_1 = image[0].coords.pc2_2 = 1.0;
+  image[0].coords.pc1_1 = 1.0 * X_PARITY;
+  image[0].coords.pc2_2 = 1.0;
   image[0].coords.pc1_2 = image[0].coords.pc2_1 = 0.0;
 
@@ -468,5 +469,5 @@
 
   if (FIX_NS) {
-    rectangle[0].coords.pc1_1 = +1.0;
+    rectangle[0].coords.pc1_1 = +1.0 * X_PARITY;
     rectangle[0].coords.pc1_2 = +0.0;
     rectangle[0].coords.pc2_1 = -0.0;
@@ -475,7 +476,7 @@
     ycr = yc*cos(angle) + xc*sin(angle); 
   } else {
-    rectangle[0].coords.pc1_1 = +cos(angle);
+    rectangle[0].coords.pc1_1 = +cos(angle) * X_PARITY;
     rectangle[0].coords.pc1_2 = +sin(angle);
-    rectangle[0].coords.pc2_1 = -sin(angle);
+    rectangle[0].coords.pc2_1 = -sin(angle) * X_PARITY;
     rectangle[0].coords.pc2_2 = +cos(angle);
     xcr = xc;
@@ -514,12 +515,12 @@
   angle = 0.0;
   if (FIX_NS) {
-    rectangle[0].coords.pc1_1 = +1.0;
+    rectangle[0].coords.pc1_1 = +1.0 * X_PARITY;
     rectangle[0].coords.pc1_2 = +0.0;
     rectangle[0].coords.pc2_1 = -0.0;
     rectangle[0].coords.pc2_2 = +1.0;
   } else {
-    rectangle[0].coords.pc1_1 = +cos(angle);
+    rectangle[0].coords.pc1_1 = +cos(angle) * X_PARITY;
     rectangle[0].coords.pc1_2 = +sin(angle);
-    rectangle[0].coords.pc2_1 = -sin(angle);
+    rectangle[0].coords.pc2_1 = -sin(angle) * X_PARITY;
     rectangle[0].coords.pc2_2 = +cos(angle);
   }
@@ -626,5 +627,5 @@
     ring[i].coords.crval2 = dec;
 
-    ring[i].coords.pc1_1 = +1.0;
+    ring[i].coords.pc1_1 = +1.0 * X_PARITY;
     ring[i].coords.pc1_2 = +0.0;
     ring[i].coords.pc2_1 = -0.0;
Index: /branches/czw_branch/20110406/Ohana/src/getstar/include/dvoImagesAtCoords.h
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/getstar/include/dvoImagesAtCoords.h	(revision 31253)
@@ -7,4 +7,5 @@
 
 int       VERBOSE;
+int       LISTCHIPCOORDS;
 
 char OUTPUT[256];
@@ -19,9 +20,15 @@
 
 typedef struct {
+    int     n;
+    double  x;
+    double  y;
+} Match;
+
+typedef struct {
     int     id;
     double  ra;
     double  dec;
     int     Nmatches;
-    int     *matches;
+    Match   *matches;
     int     arrayLength;
 } Point;
Index: /branches/czw_branch/20110406/Ohana/src/getstar/src/MatchCoords.c
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/getstar/src/MatchCoords.c	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/getstar/src/MatchCoords.c	(revision 31253)
@@ -93,10 +93,12 @@
             totalMatches++;
 
-            pt->matches[pt->Nmatches] = i;
+            pt->matches[pt->Nmatches].n = i;
+            pt->matches[pt->Nmatches].x = x;
+            pt->matches[pt->Nmatches].y = y;
             pt->Nmatches ++;
 
             if (pt->Nmatches == pt->arrayLength) {
                 pt->arrayLength += 20;
-                REALLOCATE (pt->matches, int, pt->arrayLength);
+                REALLOCATE (pt->matches, Match, pt->arrayLength);
             }
         }
Index: /branches/czw_branch/20110406/Ohana/src/getstar/src/args_coords.c
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/getstar/src/args_coords.c	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/getstar/src/args_coords.c	(revision 31253)
@@ -41,4 +41,9 @@
 
   /* check for command line options */
+  LISTCHIPCOORDS = FALSE;
+  if ((N = get_argument (argc, argv, "-listchipcoords"))) {
+    LISTCHIPCOORDS = TRUE;
+    remove_argument (N, &argc, argv);
+  }
   WITH_PHU = FALSE;
   if ((N = get_argument (argc, argv, "+phu"))) {
Index: /branches/czw_branch/20110406/Ohana/src/getstar/src/dvoImagesAtCoords.c
===================================================================
--- /branches/czw_branch/20110406/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 31252)
+++ /branches/czw_branch/20110406/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 31253)
@@ -91,5 +91,5 @@
     while ((Nread = fscanf(f, "%d %lf %lf\n", &pts[Npoints].id, &pts[Npoints].ra, &pts[Npoints].dec)) == 3) {
         pts[Npoints].Nmatches = 0;
-        ALLOCATE(pts[Npoints].matches, int, 20);
+        ALLOCATE(pts[Npoints].matches, Match, 20);
         pts[Npoints].arrayLength = 20;
 
@@ -118,5 +118,5 @@
     pts[0].dec = dec;
     pts[0].Nmatches = 0;
-    ALLOCATE(pts[0].matches, int, 20);
+    ALLOCATE(pts[0].matches, Match, 20);
     pts[0].arrayLength = 20;
 
@@ -133,5 +133,7 @@
       Point *pt = points + j;
       for (i = 0; i < pt->Nmatches; i++) {
-        int N = pt->matches[i];
+        int N = pt->matches[i].n;
+        double x = pt->matches[i].x;
+        double y = pt->matches[i].y;
 
         char *name;
@@ -150,5 +152,9 @@
             name = dbImages[N].name;
         }
-        fprintf (stdout, "%d %lf %lf %s\n", pt->id, pt->ra, pt->dec, name);
+        if (LISTCHIPCOORDS) {
+            fprintf (stdout, "%d %lf %lf %s %8.2lf %8.2lf\n", pt->id, pt->ra, pt->dec, name, x, y);
+        } else {
+            fprintf (stdout, "%d %lf %lf %s\n", pt->id, pt->ra, pt->dec, name);
+        }
         if  (copy) {
             free(copy);
Index: /branches/czw_branch/20110406/ippScripts/scripts/stack_skycell.pl
===================================================================
--- /branches/czw_branch/20110406/ippScripts/scripts/stack_skycell.pl	(revision 31252)
+++ /branches/czw_branch/20110406/ippScripts/scripts/stack_skycell.pl	(revision 31253)
@@ -73,5 +73,4 @@
 PPSTACK.OUTPUT.EXPNUM       
 PPSTACK.OUTPUT.EXPWT
-PPSTACK.TARGET.PSF          
 PPSTACK.OUTPUT.JPEG1        
 PPSTACK.OUTPUT.JPEG2        
@@ -84,4 +83,5 @@
 # extra outputs when convolving
 my @outputListUnconv = qw(
+PPSTACK.TARGET.PSF          
 PPSTACK.UNCONV
 PPSTACK.UNCONV.MASK
Index: /branches/czw_branch/20110406/ippScripts/scripts/staticsky.pl
===================================================================
--- /branches/czw_branch/20110406/ippScripts/scripts/staticsky.pl	(revision 31252)
+++ /branches/czw_branch/20110406/ippScripts/scripts/staticsky.pl	(revision 31253)
@@ -32,5 +32,7 @@
 my $staticskytool = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1);
 my $psphotStack = can_run('psphotStack') or (warn "Can't find psphotStack" and $missing_tools = 1);
+my $psphot = can_run('psphot') or (warn "Can't find psphot" and $missing_tools = 1);
 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -96,54 +98,4 @@
 }
 
-# generate the input 
-print $listFile "INPUT   MULTI\n";
-my $nInputs = @$files;
-
-my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot);
-
-foreach my $file (@$files) {
-    print $listFile "INPUT   METADATA\n";
-
-    # XXX if we take the input from 'warp', we will need to make different selections here
-    my $path_base = $file->{path_base};
-    print "input: $path_base\n";
-
-    my $imageCnv  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
-    my $maskCnv   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
-    my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
-
-    my $imageRaw  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
-    my $maskRaw   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
-    my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
-
-    my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
-
-    # XXX is this the correct PSF file?
-    my $psfCnv    = $ipprc->filename("PPSTACK.TARGET.PSF",      $path_base ); # PSF name
-
-    # XXX we could make some different choices if some inputs do not exist...
-    &my_die("Couldn't find input: $imageRaw",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageRaw");
-    &my_die("Couldn't find input: $maskRaw",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskRaw");
-    &my_die("Couldn't find input: $weightRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightRaw");
-    &my_die("Couldn't find input: $imageCnv",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageCnv");
-    &my_die("Couldn't find input: $maskCnv",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskCnv");
-    &my_die("Couldn't find input: $weightCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightCnv");
-    &my_die("Couldn't find input: $psfCnv",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv");
-    &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
-
-    print $listFile "  RAW:IMAGE     STR  " . $imageRaw  . "\n";
-    print $listFile "  RAW:MASK      STR  " . $maskRaw   . "\n";
-    print $listFile "  RAW:VARIANCE  STR  " . $weightRaw . "\n";
-
-    print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
-    print $listFile "  CNV:MASK      STR  " . $maskCnv   . "\n";
-    print $listFile "  CNV:VARIANCE  STR  " . $weightCnv . "\n";
-    print $listFile "  CNV:PSF       STR  " . $psfCnv    . "\n";
-
-    print $listFile "  SOURCES       STR  " . $sources   . "\n";
-
-    print $listFile "END\n\n";
-}
-
 # Recipes to use based on reduction class
 $reduction = 'DEFAULT' unless defined $reduction;
@@ -160,79 +112,251 @@
 print "recipe_ppstack: $recipe_ppstack\n";
 
-# my $cmdflags;
-
-# Perform stack photometry analysis
-{
-    my $command = "$psphotStack $outroot";
-    $command .= " -input $listName";
-    $command .= " -threads $threads" if defined $threads;
-    $command .= " -recipe PSPHOT  $recipe_psphot";
-    $command .= " -recipe PPSUB   $recipe_ppsub";
-    $command .= " -recipe PPSTACK $recipe_ppstack";
-    $command .= " -dumpconfig $configuration";
-    $command .= " -tracedest $traceDest -log $logDest";
-    # $command .= " -dbname $dbname" if defined $dbname;
-    # $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
-    # $command .= " -source_id $source_id" if defined $source_id;
-
-    unless ($no_op) {
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code);
-	}
-
-        # my $outputStatsReal = $ipprc->file_resolve($outputStats);
-        # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
-
-        # measure chip stats
-        # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
-        # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        #     run(command => $command, verbose => $verbose);
-        # unless ($success) {
-        #     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-        #     &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code);
-        # }
-        # foreach my $line (@$stdout_buf) {
-        #     $cmdflags .= " $line";
-        # }
-        # chomp $cmdflags;
-
-        # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
-
-	my $quality = 0;
-        if (!$quality) {
-
-	    # Get the output filenames
-	    # we have one set of output files per input file set
-	    for (my $i = 0; $i < @$files; $i++) {
-		my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i);
-		my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i);
-		my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i);
-		my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i);
-
-		# XXX these are optional and not generated by default
-		# &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
-		# &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-		# &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
-		&my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-	    }
-
-	    #my $configuration  = $ipprc->filename("PPSUB.CONFIG", $outroot);
-	    #my $outputStats    = $ipprc->filename("SKYCELL.STATS", $outroot);
-	    #my $traceDest      = $ipprc->filename("TRACE.EXP", $outroot);
-
-	    my $chisqName     = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot);
-	    my $chisqMask     = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot);
-	    my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot);
-
-	    # XXX check the recipe -- should we expect these to exist?
-            # &my_die("Couldn't find expected output file: $chisqName", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
-            # &my_die("Couldn't find expected output file: $chisqMask", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
-            # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
-        }
-    } else {
-        print "Not executing: $command\n";
-    }
+
+# generate the input 
+print $listFile "INPUT   MULTI\n";
+my $nInputs = @$files;
+
+if ($nInputs > 1) {
+        my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot);
+
+        foreach my $file (@$files) {
+            print $listFile "INPUT   METADATA\n";
+
+            # XXX if we take the input from 'warp', we will need to make different selections here
+            my $path_base = $file->{path_base};
+            print "input: $path_base\n";
+
+            my $imageCnv  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
+            my $maskCnv   = $ipprc->filename("PPSTACK.OUTPUT.MASK",     $path_base ); # Mask name
+            my $weightCnv = $ipprc->filename("PPSTACK.OUTPUT.VARIANCE", $path_base ); # Weight name
+
+            my $imageRaw  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
+            my $maskRaw   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
+            my $weightRaw = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight name
+
+            my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
+
+            # XXX is this the correct PSF file?
+            my $psfCnv    = $ipprc->filename("PPSTACK.TARGET.PSF",      $path_base ); # PSF name
+
+            # XXX we could make some different choices if some inputs do not exist...
+            &my_die("Couldn't find input: $imageRaw",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageRaw");
+            &my_die("Couldn't find input: $maskRaw",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskRaw");
+            &my_die("Couldn't find input: $weightRaw", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightRaw");
+            &my_die("Couldn't find input: $imageCnv",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$imageCnv");
+            &my_die("Couldn't find input: $maskCnv",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$maskCnv");
+            &my_die("Couldn't find input: $weightCnv", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$weightCnv");
+            &my_die("Couldn't find input: $psfCnv",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv");
+            &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
+
+            print $listFile "  RAW:IMAGE     STR  " . $imageRaw  . "\n";
+            print $listFile "  RAW:MASK      STR  " . $maskRaw   . "\n";
+            print $listFile "  RAW:VARIANCE  STR  " . $weightRaw . "\n";
+
+            print $listFile "  CNV:IMAGE     STR  " . $imageCnv  . "\n";
+            print $listFile "  CNV:MASK      STR  " . $maskCnv   . "\n";
+            print $listFile "  CNV:VARIANCE  STR  " . $weightCnv . "\n";
+            print $listFile "  CNV:PSF       STR  " . $psfCnv    . "\n";
+
+            print $listFile "  SOURCES       STR  " . $sources   . "\n";
+
+            print $listFile "END\n\n";
+        }
+
+        # my $cmdflags;
+
+        # Perform stack photometry analysis
+        {
+            my $command = "$psphotStack $outroot";
+            $command .= " -input $listName";
+            $command .= " -threads $threads" if defined $threads;
+            $command .= " -recipe PSPHOT  $recipe_psphot";
+            $command .= " -recipe PPSUB   $recipe_ppsub";
+            $command .= " -recipe PPSTACK $recipe_ppstack";
+            $command .= " -dumpconfig $configuration";
+            $command .= " -tracedest $traceDest -log $logDest";
+            # $command .= " -dbname $dbname" if defined $dbname;
+            # $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
+            # $command .= " -source_id $source_id" if defined $source_id;
+
+            unless ($no_op) {
+                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+                unless ($success) {
+                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                    &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code);
+                }
+
+                # my $outputStatsReal = $ipprc->file_resolve($outputStats);
+                # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
+
+                # measure chip stats
+                # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
+                # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                #     run(command => $command, verbose => $verbose);
+                # unless ($success) {
+                #     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                #     &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code);
+                # }
+                # foreach my $line (@$stdout_buf) {
+                #     $cmdflags .= " $line";
+                # }
+                # chomp $cmdflags;
+
+                # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+
+                my $quality = 0;
+                if (!$quality) {
+
+                    # Get the output filenames
+                    # we have one set of output files per input file set
+                    for (my $i = 0; $i < @$files; $i++) {
+                        my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i);
+                        my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i);
+                        my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i);
+                        my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i);
+
+                        # XXX these are optional and not generated by default
+                        # &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
+                        # &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+                        # &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
+                        &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+                    }
+
+                    #my $configuration  = $ipprc->filename("PPSUB.CONFIG", $outroot);
+                    #my $outputStats    = $ipprc->filename("SKYCELL.STATS", $outroot);
+                    #my $traceDest      = $ipprc->filename("TRACE.EXP", $outroot);
+
+                    my $chisqName     = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot);
+                    my $chisqMask     = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot);
+                    my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot);
+
+                    # XXX check the recipe -- should we expect these to exist?
+                    # &my_die("Couldn't find expected output file: $chisqName", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
+                    # &my_die("Couldn't find expected output file: $chisqMask", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
+                    # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
+                }
+            } else {
+                print "Not executing: $command\n";
+            }
+        }
+} else {
+        # single input. Run psphot
+        my $configuration = $ipprc->filename("PSPHOT.STACK.CONFIG", $outroot);
+
+        my $file = $files->[0];
+
+        # XXX if we take the input from 'warp', we will need to make different selections here
+        my $path_base = $file->{path_base};
+        print "input: $path_base\n";
+
+        # examine the recipe to determine whether to analyze the "raw" or convolved images
+        my $command = "$ppConfigDump -camera $camera -dump-recipe PSPHOT -recipe PSPHOT $recipe_psphot -";
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => 0);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform ppConfigDump: $error_code", $sky_id, $PS_EXIT_SYS_ERROR);
+        }
+        my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+            &my_die("Unable to parse metadata config doc", $sky_id, $PS_EXIT_SYS_ERROR);
+
+        my $use_raw = metadataLookupBool($recipeData, 'PSPHOT.STACK.USE.RAW');
+
+        my ($image, $mask, $variance);
+        if ($use_raw) {
+            $image  = $ipprc->filename("PPSTACK.UNCONV",          $path_base ); # Image name
+            $mask   = $ipprc->filename("PPSTACK.UNCONV.MASK",     $path_base ); # Mask name
+            $variance = $ipprc->filename("PPSTACK.UNCONV.VARIANCE", $path_base ); # Weight 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
+        }
+
+        my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF",      $path_base ); # Sources name
+
+        # XXX is this the correct PSF file?
+        my $psfCnv    = $ipprc->filename("PPSTACK.TARGET.PSF",      $path_base ); # PSF name
+
+        # XXX we could make some different choices if some inputs do not exist...
+        &my_die("Couldn't find input: $image",  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$image");
+        &my_die("Couldn't find input: $mask",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$mask");
+        &my_die("Couldn't find input: $variance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$variance");
+        &my_die("Couldn't find input: $psfCnv",    $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$psfCnv");
+        &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
+
+        # my $cmdflags;
+
+        # Perform stack photometry analysis
+        {
+            my $command = "$psphot $outroot";
+            $command .= " -file $image";
+            $command .= " -mask $mask";
+            $command .= " -variance $variance";
+            $command .= " -threads $threads" if defined $threads;
+            $command .= " -recipe PSPHOT  $recipe_psphot";
+            $command .= " -dumpconfig $configuration" if $configuration;
+            $command .= " -tracedest $traceDest -log $logDest";
+
+            unless ($no_op) {
+                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
+                unless ($success) {
+                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                    &my_die("Unable to perform psphotStack: $error_code", $sky_id, $error_code);
+                }
+
+                # my $outputStatsReal = $ipprc->file_resolve($outputStats);
+                # &my_die("Couldn't find expected output file: $outputStats", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
+
+                # measure chip stats
+                # $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
+                # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                #     run(command => $command, verbose => $verbose);
+                # unless ($success) {
+                #     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                #     &my_die("Unable to perform ppStatsFromMetadata: $error_code", $sky_id, $error_code);
+                # }
+                # foreach my $line (@$stdout_buf) {
+                #     $cmdflags .= " $line";
+                # }
+                # chomp $cmdflags;
+
+                # my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+
+                my $quality = 0;
+                if (0 and !$quality) {
+
+                    # Get the output filenames
+                    # we have one set of output files per input file set
+                    for (my $i = 0; $i < @$files; $i++) {
+                        my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i);
+                        my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i);
+                        my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i);
+                        my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i);
+
+                        # XXX these are optional and not generated by default
+                        # &my_die("Couldn't find expected output file: $outputName", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
+                        # &my_die("Couldn't find expected output file: $outputMask", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+                        # &my_die("Couldn't find expected output file: $outputVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
+                        &my_die("Couldn't find expected output file: $outputSources", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+                    }
+
+                    #my $configuration  = $ipprc->filename("PPSUB.CONFIG", $outroot);
+                    #my $outputStats    = $ipprc->filename("SKYCELL.STATS", $outroot);
+                    #my $traceDest      = $ipprc->filename("TRACE.EXP", $outroot);
+
+                    my $chisqName     = $ipprc->filename("PSPHOT.CHISQ.IMAGE", $outroot);
+                    my $chisqMask     = $ipprc->filename("PSPHOT.CHISQ.MASK", $outroot);
+                    my $chisqVariance = $ipprc->filename("PSPHOT.CHISQ.VARIANCE", $outroot);
+
+                    # XXX check the recipe -- should we expect these to exist?
+                    # &my_die("Couldn't find expected output file: $chisqName", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
+                    # &my_die("Couldn't find expected output file: $chisqMask", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
+                    # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
+                }
+            } else {
+                print "Not executing: $command\n";
+            }
+        }
 }
 
Index: /branches/czw_branch/20110406/ippToPsps/jython/batch.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/batch.py	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/batch.py	(revision 31253)
@@ -7,5 +7,9 @@
 import os
 import md5
-
+import shutil
+import logging
+from subprocess import call, PIPE, Popen
+
+from datastore import Datastore
 from gpc1db import Gpc1Db
 from ipptopspsdb import IppToPspsDb
@@ -14,5 +18,4 @@
 from java.sql import *
 from xml.etree.ElementTree import ElementTree, Element, tostring
-from xml.dom import minidom
 
 '''
@@ -30,5 +33,9 @@
     "../config/2/tables.vot"
     '''
-    def __init__(self, batchType, inputFitsPath="", survey=""):
+    def __init__(self, logger, batchType, inputFitsPath="", survey=""):
+
+        # set up logging
+        self.logger = logger
+        self.logger.debug("Batch class constructor")
 
         # set up class variables
@@ -51,5 +58,5 @@
 
         # create Gpc1Db object
-        self.gpc1Db = Gpc1Db()
+        self.gpc1Db = Gpc1Db(self.logger)
 
         # get survey ID from init table
@@ -60,21 +67,30 @@
             self.surveyID = rs.getInt(1)
         except:
-            self.log("No survey ID found for this survey: '" + survey + "'")
+            self.logger.exception("No survey ID found for this survey: '" + survey + "'")
             self.surveyID = -1;
    
         # get dvo info from config
-        dvoName = doc.find(survey+"dvo/name").text
-        dvoLocation = doc.find(survey+"dvo/location").text
+        if survey != "":
+            dvoName = doc.find(survey+"dvo/name").text
+            dvoLocation = doc.find(survey+"dvo/location").text
+        else:
+            dvoName = ""
+            dvoLocation = ""
          
         # get datastore info from config
-        datastoreProduct = doc.find("datastore/product").text
+        self.datastore = Datastore(self.logger)
 
         # create IppToPspsDb object and create a new batch
-        self.ippToPspsDb = IppToPspsDb()
-        self.batchID = self.ippToPspsDb.createNewBatch(66, survey, self.getPspsBatchType(), dvoName, datastoreProduct)
+        self.ippToPspsDb = IppToPspsDb(logger)
+        self.batchID = self.ippToPspsDb.createNewBatch(66, 
+                survey, 
+                self.getPspsBatchType(), 
+                dvoName, 
+                self.datastore.product)
 
         # get local storage location from config
         self.batchName = "B%08d" % self.batchID
-        self.localOutPath = doc.find("localOutPath").text + "/" + self.getPspsBatchType() + "/" + dvoName + "/%s" % self.batchName 
+        self.subDir = doc.find("localOutPath").text + "/" + self.getPspsBatchType() + "/" + dvoName
+        self.localOutPath = self.subDir + "/" + self.batchName 
         if not os.path.exists(self.localOutPath): os.makedirs(self.localOutPath)
 
@@ -94,5 +110,5 @@
     def __del__(self):
 
-        self.log("Batch destructor")
+        self.logger.debug("Batch destructor")
         self.localStmt.close()
         self.localCon.close()
@@ -105,5 +121,5 @@
         outPath = self.localOutPath + "/BatchManifest.xml"
         tmpPath = "./tmp.xml"
-        self.log("Creating batch manifest file here: " + outPath)
+        self.logger.info("Creating batch manifest file here: " + outPath)
         root = Element('manifest')
 
@@ -117,6 +133,8 @@
 
         # get md5sum
-        fits=os.popen("md5sum " + self.outputFitsPath)
-        for f in fits.readlines(): md5sum = f[0:f.rfind(" ")]
+        p = Popen("md5sum " + self.outputFitsPath, shell=True, stdout=PIPE)
+        p.wait()
+        out = p.stdout.read()
+        md5sum = out[0:out.rfind(" ")]
 
         # get file size
@@ -136,7 +154,42 @@
 
         # clunky way to prettify XML
-        os.popen("xmllint --format " + tmpPath + " > " + outPath)
-#        os.remove(tmpPath)
-
+        p = Popen("xmllint --format " + tmpPath + " > " + outPath, shell=True, stdout=PIPE)
+        p.wait()
+        os.remove(tmpPath)
+
+
+    '''
+    tar and zips batch directory
+    '''
+    def createTarball(self):
+      
+        # set up filenams and paths
+        tarFile = self.batchName + ".tar"
+        tarPath = self.subDir + "/" + tarFile
+
+        self.tarballFile = tarFile + ".gz"
+        tarballPath = self.subDir + "/" + self.tarballFile
+
+        # tar directory
+        p = Popen("tar -cvf " + tarPath + "\
+                -C " + self.subDir + " \
+                " + self.batchName, shell=True, stdout=PIPE)
+        p.wait()
+
+        # zip tar archive
+        p = Popen("gzip -c " + tarPath + " > " + tarballPath, shell=True, stdout=PIPE)
+        p.wait()
+
+        # delete tar file and original directory
+        os.remove(tarPath)
+        shutil.rmtree(self.localOutPath)
+
+    '''
+    Publishes this batch to the datastore
+    '''
+    def publishToDatastore(self):
+
+        self.datastore.publish(self.batchName, self.subDir, self.tarballFile, "tgz")
+        # TODO update ippToPsps Db here
 
     '''
@@ -147,5 +200,5 @@
         if self.survey == "ThreePi": return "3PI"
         elif self.survey == "MD04": return "MD04"
-        else: self.log("ERROR: Don't know this survey: " + self.survey)
+        else: self.logger.error("Don't know this survey: " + self.survey)
 
     '''
@@ -157,5 +210,5 @@
         elif self.batchType == "detection": return "P2"
         elif self.batchType == "stack": return "ST"
-        else: self.log("ERROR: Don't know this batch type: " + self.survey)
+        else: self.logger.error("Don't know this batch type: " + self.survey)
 
 
@@ -244,5 +297,5 @@
          self.pspsTables = stilts.treads(self.pspsVoTableFilePath)
          for table in self.pspsTables:
-             self.log("Creating PSPS table: " + table.name)
+             self.logger.info("Creating PSPS table: " + table.name)
              table.write(self.localUrl + '#' + table.name)
 
@@ -253,5 +306,5 @@
     '''   
     def indexIppTables(self):
-        self.log("indexIppTables not implemented")
+        self.logger.warn("indexIppTables not implemented")
 
 
@@ -261,5 +314,5 @@
     def createIndex(self, table, column):
 
-        self.log("Creating index on column '"+column+"' for table '"+table+"'")
+        self.logger.info("Creating index on column '"+column+"' for table '"+table+"'")
 
         sql = "CREATE INDEX "+table+"_index ON "+table+" ("+column+")"
@@ -267,5 +320,5 @@
             self.localStmt.execute(sql)
         except:
-            self.log("Index already in place on '" + column + "' for table '" + table + "'")
+            self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
 
 
@@ -274,5 +327,5 @@
     '''   
     def indexPspsTables(self):
-        self.log("indexPspsTables not implemented")
+        self.logger.warn("indexPspsTables not implemented")
 
     '''
@@ -290,14 +343,14 @@
           match = re.match(filter, table.name)
           if not match: continue
-          self.log("Creating IPP table " + table.name)
+          self.logger.info("Creating IPP table " + table.name)
           table = stilts.tpipe(table, cmd='explodeall')
           try:
               table.write(self.localUrl + '#' + table.name)
           except:
-              self.log("ERROR problem writing table '" + table.name + "' to the database")
+              self.logger.exception("Problem writing table '" + table.name + "' to the database")
 
           count = count + 1
 
-      self.log("Imported %d tables from '%s' " % (count, self.inputFitsPath))
+      self.logger.info("Imported %d tables from '%s' " % (count, self.inputFitsPath))
 
       self.indexIppTables()
@@ -308,8 +361,8 @@
     def exportPspsTablesToFits(self):
 
-        self.log("Exporting all PSPS tables to FITS")
+        self.logger.info("Exporting all PSPS tables to FITS")
         _tables = []
 
-        self.log("    Selecting database tables")
+        self.logger.info("    Selecting database tables")
         for table in self.pspsTables:
            _table = stilts.tread(self.localUrl + '#SELECT * FROM ' + table.name)
@@ -317,7 +370,7 @@
            _tables.append(_table)
 
-        self.log("    Writing to FITS file '" + self.outputFitsPath + "'...")
+        self.logger.info("    Writing to FITS file '" + self.outputFitsPath + "'...")
         stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
-        self.log("    ...done")
+        self.logger.info("    ...done")
 
     '''
@@ -394,8 +447,8 @@
     def replaceAllPspsNulls(self, sub):
 
-        self.log("Replacing all NULL values in PSPS tables with '" + sub + "'...")
+        self.logger.info("Replacing all NULL values in PSPS tables with '" + sub + "'...")
         for table in self.pspsTables:
             self.replaceNulls(table.name, sub)
-        self.log("...done")
+        self.logger.info("...done")
 
     '''
@@ -403,5 +456,5 @@
     '''
     def populatePspsTables(self):
-        self.log("Not implemented yet")
+        self.logger.warn("Not implemented yet")
 
     '''
@@ -410,5 +463,5 @@
     def updateDvoIDs(self, table):
 
-        self.log("Updating table '" + table + "' with DVO IDs...")
+        self.logger.info("Updating table '" + table + "' with DVO IDs...")
         sql = "UPDATE " + table + " AS a, dvo AS b SET \
                a.ippObjID = b.ippObjID, \
@@ -416,5 +469,5 @@
                WHERE a.ippDetectID = b.ippDetectID"
         self.localStmt.execute(sql)
-        self.log("...done")
+        self.logger.info("...done")
 
 
@@ -424,5 +477,5 @@
     def createDvoTable(self):
 
-        self.log("Creating DVO table for ID matching")
+        self.logger.info("Creating DVO table for ID matching")
         sql = "DROP TABLE dvo"
         self.localStmt.execute(sql)
Index: /branches/czw_branch/20110406/ippToPsps/jython/config.xml
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/config.xml	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/config.xml	(revision 31253)
@@ -32,4 +32,5 @@
   <datastore>
     <product>PSPS_JHU</product>
+    <type>IPP_PSPS</type>
   </datastore>
 
Index: /branches/czw_branch/20110406/ippToPsps/jython/datastore.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/datastore.py	(revision 31253)
+++ /branches/czw_branch/20110406/ippToPsps/jython/datastore.py	(revision 31253)
@@ -0,0 +1,85 @@
+#!/usr/bin/env jython
+
+from subprocess import call, PIPE, Popen
+import tempfile
+import logging
+import sys
+from xml.etree.ElementTree import ElementTree, Element, tostring
+
+
+'''
+Class encapsulating the IPP datastore
+'''
+class Datastore(object):
+
+    '''
+        Constructor
+
+    '''
+    def __init__(self, logger):
+    
+        # setup logger
+        self.logger = logger
+        self.logger.debug("Datastore constructor")
+
+        # open config
+        doc = ElementTree(file="config.xml")
+        self.product = doc.find("datastore/product").text
+        self.type = doc.find("datastore/type").text
+
+        self.logger.debug("Using product: '" + self.product + "' and type: '" + self.type + "'")
+
+    '''
+    Publishes an item to the datastore
+    '''
+    def publish(self, name, path, file, fileType):
+
+        self.logger.info("Attempting to publish '" + path +"/" + file + "' to datastore product: '" + self.product + "', type: '" + self.type + "'")
+        tempFile = tempfile.NamedTemporaryFile(mode='w+b')
+        tempFile.write(file + "|||" + fileType)
+        tempFile.seek(0)
+
+        # build dsreg command command
+        command  = "dsreg --add " + name + "\
+                    --copy --datapath " + path + "\
+                    --type " + self.type + "\
+                    --product " + self.product + "\
+                    --list " + tempFile.name
+
+        p = Popen(command, shell=True, stdout=PIPE)
+        p.wait()
+
+        if p.returncode != 0:
+            self.logger.error("Datastore publish failed")
+            ret = False
+        else:
+            self.logger.info("Datastore publish successful")
+            ret = True
+            
+
+        tempFile.close()
+        return ret
+
+
+    '''
+    Removes an item to the datastore
+    '''
+    def remove(self, name):
+
+        command = "dsreg \
+                   --del " + name + " \
+                   --rm \
+                   --product " + self.product
+
+        p = Popen(command, shell=True, stdout=PIPE)
+        p.wait()
+
+        if p.returncode != 0:
+            self.logger.error("Datastore removal of " + name + " failed")
+            ret = False
+        else:
+            ret = True
+            self.logger.info("Datastore removal of " + name + " successful")
+            
+        return ret
+
Index: /branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py	(revision 31253)
@@ -5,4 +5,5 @@
 import glob
 import os
+import logging
 
 from java.sql import *
@@ -21,5 +22,9 @@
 
     '''
-    def __init__(self):
+    def __init__(self, logger):
+
+        # setup logging
+        self.logger = logger
+        self.logger.debug("Gpc1Db constructor")
 
         # open config
@@ -40,5 +45,5 @@
     def __del__(self):
 
-        print "Gpc1Db destructor"
+        self.logger.debug("Gpc1Db destructor")
         self.stmt.close()
         self.con.close()
@@ -49,4 +54,7 @@
     '''
     def getStackStageCmfs(self, skyID):
+
+        self.logger.debug("Querying for stack cmf files")
+
         sql = "SELECT path_base, num_inputs \
                FROM staticskyResult \
@@ -56,5 +64,5 @@
             rs.first()
         except:
-            print "No worky"
+            self.logger.exception("Can't query for stack cmfs")
 
         # get path to base dir of cmf files
Index: /branches/czw_branch/20110406/ippToPsps/jython/initbatch.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/initbatch.py	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/initbatch.py	(revision 31253)
@@ -2,4 +2,6 @@
 
 import stilts
+import logging
+import logging.config
 from java.lang import *
 from java.sql import *
@@ -14,11 +16,13 @@
     Constructor
     '''
-    def __init__(self):
-       super(InitBatch, self).__init__("init")
+    def __init__(self, logger):
+       super(InitBatch, self).__init__(logger, "init")
 
-       self.outputFitsPath = "00000000.FITS";
+       self.outputFitsFile = "00000000.FITS";
+       self.outputFitsPath = self.localOutPath + "/" + self.outputFitsFile
 
-
-initBatch = InitBatch()
+logging.config.fileConfig("logging.conf")
+logger = logging.getLogger("initbatch")
+initBatch = InitBatch(logger)
 initBatch.createEmptyPspsTables()
 initBatch.exportPspsTablesToFits()
Index: /branches/czw_branch/20110406/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/ipptopspsdb.py	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/ipptopspsdb.py	(revision 31253)
@@ -4,4 +4,5 @@
 import sys
 import os
+import logging
 
 from java.sql import *
@@ -19,6 +20,9 @@
 
     '''
-    def __init__(self):
+    def __init__(self, logger):
 
+        # setup logging
+        self.logger = logger
+        self.logger.debug("IppToPspsDb Constructor")
         # open config
         doc = ElementTree(file="config.xml")
@@ -38,5 +42,4 @@
     def createNewBatch(self, expID, surveyType, batchType, dvoDb, datastoreProduct):
 
-        print "Creating nw batch in ippToPsps database"
         sql = "SELECT batch_id FROM batches ORDER BY batch_id DESC LIMIT 1"
 
@@ -48,5 +51,5 @@
             batchID = rs.getInt(1)
         except:
-            print "Unable to get batch ID"
+            self.logger.exception("Unable to get batch ID")
 
         if batchID > 0:
@@ -70,4 +73,6 @@
             self.stmt.execute(sql)
 
+        self.logger.info("Creating new batch in ippToPsps database with batchID = %d" % batchID)
+
         return batchID;
 
@@ -77,5 +82,5 @@
     def __del__(self):
 
-        print "IppToPspsDb destructor"
+        self.logger.debug("IppToPspsDb Desstructor")
         self.stmt.close()
         self.con.close()
Index: /branches/czw_branch/20110406/ippToPsps/jython/logging.conf
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/logging.conf	(revision 31253)
+++ /branches/czw_branch/20110406/ippToPsps/jython/logging.conf	(revision 31253)
@@ -0,0 +1,28 @@
+[loggers]
+keys=root,simpleExample
+
+[handlers]
+keys=consoleHandler
+
+[formatters]
+keys=simpleFormatter
+
+[logger_root]
+level=DEBUG
+handlers=consoleHandler
+
+[logger_simpleExample]
+level=DEBUG
+handlers=consoleHandler
+qualname=simpleExample
+propagate=0
+
+[handler_consoleHandler]
+class=StreamHandler
+level=DEBUG
+formatter=simpleFormatter
+args=(sys.stdout,)
+
+[formatter_simpleFormatter]
+format=%(asctime)s | %(levelname)7s | %(message)s
+datefmt=%Y-%m-%d %H:%M:%S
Index: /branches/czw_branch/20110406/ippToPsps/jython/stackbatch.py
===================================================================
--- /branches/czw_branch/20110406/ippToPsps/jython/stackbatch.py	(revision 31252)
+++ /branches/czw_branch/20110406/ippToPsps/jython/stackbatch.py	(revision 31253)
@@ -7,4 +7,5 @@
 from gpc1db import Gpc1Db
 from batch import Batch
+import logging.config
 
 class StackBatch(Batch):
@@ -13,11 +14,12 @@
     Constructor
     '''
-    def __init__(self, skyID, inputFile):
+    def __init__(self, logger, skyID, inputFile):
        super(StackBatch, self).__init__(
+               logger,
                "stack", 
                inputFile, 
                "MD04") # TODO
 
-       self.log("StackBatch constructor. Creating batch from input file here: ''" + inputFile + "'")
+       self.logger.info("StackBatch constructor. Creating batch from: ''" + inputFile + "'")
 
        # obs time makes no sense except for nightly stacks
@@ -185,5 +187,5 @@
     '''
     def populateStackMeta(self):
-        self.log("Procesing StackMeta table")
+        self.logger.info("Procesing StackMeta table")
 
         sql = "INSERT INTO StackMeta (\
@@ -233,5 +235,5 @@
     '''
     def populateStackDetection(self):
-        self.log("Procesing StackDetection table")
+        self.logger.info("Procesing StackDetection table")
 
         # insert all the detections
@@ -297,5 +299,5 @@
     '''
     def populateStackApFlx(self):
-        self.log("Procesing StackApFlx table")
+        self.logger.info("Procesing StackApFlx table")
  
         sql = "INSERT INTO StackApFlx \
@@ -307,12 +309,12 @@
 
         # TODO temporarily loading 1st convolved fluxes into unconvolved fields
-        self.log("    Adding un-convolved fluxes")
+        self.logger.info("    Adding un-convolved fluxes")
         self.updateApFlxs("", "< 7.0")
-        self.log("    Adding 1st convolved fluxes")
+        self.logger.info("    Adding 1st convolved fluxes")
         self.updateApFlxs("c1", "< 7.0")
-        self.log("    Adding 2nd convolved fluxes")
+        self.logger.info("    Adding 2nd convolved fluxes")
         self.updateApFlxs("c2", "> 7.0")
 
-        self.log("    Adding petrosians for extended sources")
+        self.logger.info("    Adding petrosians for extended sources")
         sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET \
         petRadius=b.PETRO_RADIUS \
@@ -337,5 +339,5 @@
     '''
     def populateStackModelFit(self):
-        self.log("Procesing StackModelFit table")
+        self.logger.info("Procesing StackModelFit table")
 
         # insert all the detections
@@ -344,9 +346,9 @@
 
         # populate model parameters
-        self.log("    Adding deVaucouleurs fit")
+        self.logger.info("    Adding deVaucouleurs fit")
         self.updateModelFit("deV", "PS_MODEL_DEV")
-        self.log("    Adding exponential fit")
+        self.logger.info("    Adding exponential fit")
         self.updateModelFit("exp", "PS_MODEL_EXP")
-        self.log("    Adding sersic fit")
+        self.logger.info("    Adding sersic fit")
         self.updateModelFit("ser", "PS_MODEL_SERSIC")
 
@@ -361,5 +363,5 @@
     '''
     def populateStackToImage(self):
-        self.log("Procesing StackToImage table")
+        self.logger.info("Procesing StackToImage table")
 
         sql = "INSERT INTO StackToImage (stackMetaID) VALUES (" + self.header['STK_ID'] + ")"
@@ -371,5 +373,5 @@
     def indexPspsTables(self):
 
-        self.log("Creating indexes on PSPS tables")
+        self.logger.info("Creating indexes on PSPS tables")
         self.createIndex("StackDetection", "ippDetectID")
         self.createIndex("StackApFlx", "ippDetectID")
@@ -381,5 +383,5 @@
     def indexIppTables(self):
 
-        self.log("Creating indexes on IPP tables")
+        self.logger.info("Creating indexes on IPP tables")
         self.createIndex("SkyChip_psf", "IPP_IDET")
         self.createIndex("SkyChip_xfit", "IPP_IDET")
@@ -391,5 +393,5 @@
     def fudgeIDs(self):
 
-        self.log("Creating bogus IDs on all detections")
+        self.logger.info("Creating bogus IDs on all detections")
 
         sql = "INSERT INTO dvo (ippDetectID) SELECT IPP_IDET FROM SkyChip_psf";
@@ -430,6 +432,8 @@
 
 
-sky_id = 299
-gpc1Db = Gpc1Db()
+logging.config.fileConfig("logging.conf")
+logger = logging.getLogger("stackbatch")
+sky_id = 299 # TODO
+gpc1Db = Gpc1Db(logger)
 cmfFiles = gpc1Db.getStackStageCmfs(sky_id)
 
@@ -437,14 +441,16 @@
 for file in cmfFiles:
 
-    stackBatch = StackBatch(sky_id, file)
+    stackBatch = StackBatch(logger, sky_id, file)
     
     stackBatch.createEmptyPspsTables()
-    #stackBatch.importIppTables("")
-    stackBatch.populatePspsTables()
-    stackBatch.fudgeIDs()
-    #stackBatch.reportNullsInAllPspsTables(False)
-    #stackBatch.replaceAllPspsNulls("-999")  
-    stackBatch.exportPspsTablesToFits()
-    stackBatch.writeBatchManifest()
+    stackBatch.importIppTables("")
+#    stackBatch.populatePspsTables()
+ #   stackBatch.fudgeIDs()
+  #  stackBatch.reportNullsInAllPspsTables(False)
+  #  stackBatch.replaceAllPspsNulls("-999")  
+  #  stackBatch.exportPspsTablesToFits()
+  #  stackBatch.writeBatchManifest()
+  #  stackBatch.createTarball()
+  #  stackBatch.publishToDatastore()
 
     i = i + 1
Index: /branches/czw_branch/20110406/ippTools/share/Makefile.am
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/Makefile.am	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/Makefile.am	(revision 31253)
@@ -164,4 +164,5 @@
 	disttool_definebyquery_fake.sql \
 	disttool_definebyquery_raw.sql \
+	disttool_definebyquery_raw_no_magic.sql \
 	disttool_definebyquery_sky.sql \
 	disttool_definebyquery_stack.sql \
Index: /branches/czw_branch/20110406/ippTools/share/difftool_listrun.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/difftool_listrun.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/difftool_listrun.sql	(revision 31253)
@@ -20,4 +20,5 @@
     camProcessedInput.zpt_lq,
     camProcessedInput.zpt_uq,
+    camProcessedInput.fwhm_major,
     rawInput.comment,
     rawInput.exp_time,
@@ -25,4 +26,5 @@
     rawInput.exp_name AS exp_name_1,
     rawInput.exp_id AS exp_id_1,
+    rawInput.filter AS filter_1,
     rawInput.comment AS comment_1,
     rawInput.dateobs AS dateobs_1,
@@ -34,4 +36,5 @@
     rawTemplate.exp_name AS exp_name_2,
     rawTemplate.exp_id AS exp_id_2,
+    rawInput.filter AS filter_2,
     rawTemplate.comment AS comment_2,
     rawTemplate.dateobs AS dateobs_2,
Index: /branches/czw_branch/20110406/ippTools/share/difftool_skyfile.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/difftool_skyfile.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/difftool_skyfile.sql	(revision 31253)
@@ -24,4 +24,5 @@
     rawInput.exp_name AS exp_name_1,
     rawInput.exp_id AS exp_id_1,
+    rawInput.filter AS filter_1,
     chipInput.chip_id AS chip_id_1,
     camInput.cam_id AS cam_id_1,
@@ -31,4 +32,5 @@
     rawTemplate.exp_name AS exp_name_2,
     rawTemplate.exp_id AS exp_id_2,
+    rawTemplate.filter AS filter_2,
     chipTemplate.chip_id AS chip_id_2,
     camTemplate.cam_id AS cam_id_2,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_definebyquery_raw_no_magic.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_definebyquery_raw_no_magic.sql	(revision 31253)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_definebyquery_raw_no_magic.sql	(revision 31253)
@@ -0,0 +1,18 @@
+SELECT 
+    'raw' AS stage,
+    rawExp.exp_id AS stage_id,
+    rawExp.exp_name AS run_tag,
+    rawExp.magicked,
+    CAST(NULL AS CHAR(255)) AS label,
+    CAST(NULL AS CHAR(255)) AS data_group,
+    distTarget.dist_group,
+    distTarget.target_id,
+    distTarget.clean
+FROM rawExp
+JOIN distTarget ON distTarget.stage = 'raw'
+    AND rawExp.filter = distTarget.filter
+JOIN rcInterest USING(target_id)
+LEFT JOIN distRun ON distRun.stage_id = exp_id AND distRun.target_id = distTarget.target_id
+WHERE distRun.dist_id IS NULL           -- no existing distRun for this exposure
+    AND distTarget.state = 'enabled'    -- target and intrest are enabled
+    AND rcInterest.state = 'enabled'
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_SSdiff.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_SSdiff.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_SSdiff.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     diffSkyfile.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_camera.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_camera.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_camera.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     'exposure' AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     chipProcessedImfile.class_id AS component,
+    exp_type,
     distRun.clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip_bg.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip_bg.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_chip_bg.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     chipBackgroundImfile.class_id AS component,
+    exp_type,
     distRun.clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_diff.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_diff.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_diff.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     diffSkyfile.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_fake.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_fake.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_fake.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     fakeProcessedImfile.class_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_raw.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_raw.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_raw.sql	(revision 31253)
@@ -1,2 +1,4 @@
+SELECT * FROM (
+-- rawExp magicked with re_place
 SELECT
     distRun.dist_id,
@@ -6,4 +8,5 @@
     rawExp.exp_id AS stage_id,
     rawImfile.class_id AS component,
+    rawExp.exp_type,
     clean,
     rawExp.camera,
@@ -38,8 +41,49 @@
     AND distRun.stage = 'raw'
     AND distComponent.dist_id IS NULL
-    AND (rawExp.magicked OR distRun.no_magic)
+    -- AND (rawExp.magicked OR distRun.no_magic)
+    AND rawExp.magicked
     -- need to have magicked the chip image which makes the camera mask
     AND chipProcessedImfile.magicked != 0
     AND camRun.magicked > 0 
+    AND (Label.active OR Label.active IS NULL)
+UNION
+SELECT
+    -- raw images no_magic required
+    distRun.dist_id,
+    distRun.label,
+    distTarget.dist_group,
+    'raw' AS stage,
+    rawExp.exp_id AS stage_id,
+    rawImfile.class_id AS component,
+    rawExp.exp_type,
+    clean,
+    rawExp.camera,
+    CONCAT_WS('.', distRun.outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
+    -- XXX: replace this with rawImfile.path_base once it exists
+    TRIM(TRAILING '.fits' FROM rawImfile.uri) AS path_base,
+    CAST(NULL AS CHAR(255)) AS alt_path_base,
+    -- pass camera stage path base since we want the camera mask file. The script knows what to do
+    CAST(NULL AS CHAR(255)) AS chip_path_base,
+    CAST(NULL AS CHAR(255)) AS state,
+    CAST(NULL AS CHAR(255)) AS data_state,
+    0 as quality,
+    distRun.no_magic,
+    rawImfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
+FROM distRun
+JOIN distTarget USING(target_id, stage, clean)
+JOIN rawExp ON rawExp.exp_id = stage_id 
+            AND distTarget.stage = 'raw' AND distRun.alternate = 0
+JOIN rawImfile USING(exp_id)
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+    AND rawImfile.class_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
+WHERE
+    distRun.state = 'new'
+    AND distRun.clean = 0
+    AND distRun.stage = 'raw'
+    AND distComponent.dist_id IS NULL
+    AND (distRun.no_magic)
     AND (Label.active OR Label.active IS NULL)
 UNION
@@ -52,4 +96,5 @@
     rawExp.exp_id AS stage_id,
     rawImfile.class_id AS component,
+    rawExp.exp_type,
     clean,
     rawExp.camera,
@@ -96,4 +141,5 @@
     rawExp.exp_id AS stage_id,
     'exposure' AS component,
+    rawExp.exp_type,
     clean,
     rawExp.camera,
@@ -120,2 +166,4 @@
     AND distComponent.dist_id IS NULL
     AND (Label.active OR Label.active IS NULL)
+) AS distRun
+WHERE 1
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_sky.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_sky.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_sky.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     stackRun.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_stack.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_stack.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_stack.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     stackRun.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     warpSkyfile.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp_bg.sql
===================================================================
--- /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp_bg.sql	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/share/disttool_pending_warp_bg.sql	(revision 31253)
@@ -6,4 +6,5 @@
     stage_id,
     warpBackgroundSkyfile.skycell_id AS component,
+    exp_type,
     clean,
     rawExp.camera,
Index: /branches/czw_branch/20110406/ippTools/src/difftool.c
===================================================================
--- /branches/czw_branch/20110406/ippTools/src/difftool.c	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/src/difftool.c	(revision 31253)
@@ -2967,4 +2967,6 @@
     pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE");
     pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE");
+
+    PXOPT_COPY_S64(config->args, where, "-template_exp_id", "rawTemplate.exp_id", "==");
     
     PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
Index: /branches/czw_branch/20110406/ippTools/src/difftoolConfig.c
===================================================================
--- /branches/czw_branch/20110406/ippTools/src/difftoolConfig.c	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/src/difftoolConfig.c	(revision 31253)
@@ -182,4 +182,5 @@
     psMetadataAddTime(listrunArgs, PS_LIST_TAIL, "-dateobs_end", 0,      "search for exposures by time (<=)", NULL);
     psMetadataAddStr(listrunArgs, PS_LIST_TAIL,  "-filter", 0,           "search for filter", NULL);
+    psMetadataAddS64(listrunArgs, PS_LIST_TAIL,  "-template_exp_id",  0, "search by exposure ID of template", 0);
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by diffRun label (LIKE comparison)", NULL);
     psMetadataAddStr(listrunArgs,  PS_LIST_TAIL, "-data_group",  PS_META_DUPLICATE_OK, "search by diffRun data_group (LIKE comparison)", NULL);
Index: /branches/czw_branch/20110406/ippTools/src/stacktool.c
===================================================================
--- /branches/czw_branch/20110406/ippTools/src/stacktool.c	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/src/stacktool.c	(revision 31253)
@@ -243,5 +243,5 @@
     PXOPT_COPY_STR(config->args,  where, "-select_exp_type",           "rawExp.exp_type", "==");
     PXOPT_COPY_F32(config->args,  where, "-select_good_frac_min",      "warpSkyfile.good_frac", ">=");
-    PXOPT_COPY_STR(config->args,  where, "-select_skycell_id",         "warpSkyfile.skycell_id", "==");
+    PXOPT_COPY_STR(config->args,  where, "-select_skycell_id",         "warpSkyfile.skycell_id", "LIKE");
     PXOPT_COPY_STR(config->args,  where, "-select_data_group",         "warpRun.data_group", "==");
     pxAddLabelSearchArgs (config, where, "-select_label",              "warpRun.label", "LIKE"); // define using warp label
Index: /branches/czw_branch/20110406/ippTools/src/staticskytool.c
===================================================================
--- /branches/czw_branch/20110406/ippTools/src/staticskytool.c	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/src/staticskytool.c	(revision 31253)
@@ -123,9 +123,4 @@
     psAssert (filters->data.list->n, "-select_filter should at least have a place-holder");
     int num_filter = filters->data.list->n;
-    if (num_filter < 2) {
-        psError(PXTOOLS_ERR_CONFIG, false, "invalid request: only 1 filter selected");
-        psFree(whereMD);
-        return false;
-    }
 
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
Index: /branches/czw_branch/20110406/ippTools/src/staticskytoolConfig.c
===================================================================
--- /branches/czw_branch/20110406/ippTools/src/staticskytoolConfig.c	(revision 31252)
+++ /branches/czw_branch/20110406/ippTools/src/staticskytoolConfig.c	(revision 31253)
@@ -52,5 +52,5 @@
     psMetadataAddF32(definebyqueryArgs,  PS_LIST_TAIL, "-select_good_frac_min", 0, "define min good_frac", 0.0);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_label", PS_META_DUPLICATE_OK, "search by stackRun label (LIKE comparison, multiple OK)", NULL);
-    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_filter", PS_META_DUPLICATE_OK, "search by filter (LIKE comparison, multiple required)", NULL);
+    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_filter", PS_META_DUPLICATE_OK, "search by filter (LIKE comparison, multiplei OK)", NULL);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_label", 0, "define label", NULL);
Index: /branches/czw_branch/20110406/ippconfig/recipes/nightly_science.config
===================================================================
--- /branches/czw_branch/20110406/ippconfig/recipes/nightly_science.config	(revision 31252)
+++ /branches/czw_branch/20110406/ippconfig/recipes/nightly_science.config	(revision 31253)
@@ -203,5 +203,5 @@
   NAME      STR STS
   DISTRIBUTION STR STS
-  TESS      STR STS
+  TESS      STR STS.V3
   OBSMODE   STR STS%
   OBJECT    STR STS%
Index: /branches/czw_branch/20110406/ippconfig/recipes/ppStack.config
===================================================================
--- /branches/czw_branch/20110406/ippconfig/recipes/ppStack.config	(revision 31252)
+++ /branches/czw_branch/20110406/ippconfig/recipes/ppStack.config	(revision 31253)
@@ -123,4 +123,10 @@
 END
 
+QUICKSTACK    METADATA
+        CONVOLVE        BOOL   FALSE
+	COMBINE.REJ     F32    3.0
+        COMBINE.DISCARD F32    0.3
+        MASK.VAL	STR    MASK.VALUE,CONV.BAD,GHOST,BURNTOOL # Mask value of input bad pixels
+END
 
 # 
Index: /branches/czw_branch/20110406/ippconfig/recipes/psphot.config
===================================================================
--- /branches/czw_branch/20110406/ippconfig/recipes/psphot.config	(revision 31252)
+++ /branches/czw_branch/20110406/ippconfig/recipes/psphot.config	(revision 31253)
@@ -203,18 +203,18 @@
 
 # define the annuli (in pixels) for surface brightness measurements
-# @RADIAL.ANNULAR.BINS.LOWER           F32     0.0   5.0  10.0  20.0  40.0  80.0
-# @RADIAL.ANNULAR.BINS.UPPER           F32     5.0  10.0  20.0  40.0  80.0 160.0
+# @RADIAL.ANNULAR.BINS.LOWER           F32     0.0   5.0  10.0  20.0  40.0  80.0 # comment due to ticket #1476
+# @RADIAL.ANNULAR.BINS.UPPER           F32     5.0  10.0  20.0  40.0  80.0 160.0 #
 
 # SDSS values (in SDSS pixels)
-#@RADIAL.ANNULAR.BINS.LOWER           F32     0.00 0.56 1.69 2.59 4.41  7.51 11.58 18.58 28.55 45.50  70.51 110.53 172.49 269.52 420.51
-#@RADIAL.ANNULAR.BINS.UPPER           F32     0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 652.50
+#@RADIAL.ANNULAR.BINS.LOWER           F32     0.00 0.56 1.69 2.59 4.41  7.51 11.58 18.58 28.55 45.50  70.51 110.53 172.49 269.52 420.51 #
+#@RADIAL.ANNULAR.BINS.UPPER           F32     0.56 1.69 2.59 4.41 7.51 11.58 18.58 28.55 45.50 70.51 110.53 172.49 269.52 420.51 652.50 #
 
 # PS1 values? (all SDSS @ PS1 0.2 arcsec pixel scales)
-# @RADIAL.ANNULAR.BINS.LOWER           F32      0.0 1.2 3.4 5.2  8.8 15.0 23.2 37.2 57.1  91.0 141.0 221.1 345.0 539.1  841.0
-# @RADIAL.ANNULAR.BINS.UPPER           F32      1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 345.0 539.1 841.0 1305.0
+# @RADIAL.ANNULAR.BINS.LOWER           F32      0.0 1.2 3.4 5.2  8.8 15.0 23.2 37.2 57.1  91.0 141.0 221.1 345.0 539.1  841.0 #
+# @RADIAL.ANNULAR.BINS.UPPER           F32      1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 345.0 539.1 841.0 1305.0 #
 
 # PS1 values?
-@RADIAL.ANNULAR.BINS.LOWER           F32      0.0 1.2 3.4 5.2  8.8 15.0 23.2 37.2 57.1  91.0 141.0 
-@RADIAL.ANNULAR.BINS.UPPER           F32      1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1 
+@RADIAL.ANNULAR.BINS.LOWER           F32      0.0 1.2 3.4 5.2  8.8 15.0 23.2 37.2 57.1  91.0 141.0  # perl parser fails without a comment ticket #1476
+@RADIAL.ANNULAR.BINS.UPPER           F32      1.2 3.4 5.2 8.8 15.0 23.2 37.2 57.1 91.0 141.0 221.1  # perl parser fails without a comment ticket #1476
 
 # Extended source fit parameters
Index: /branches/czw_branch/20110406/ippconfig/recipes/reductionClasses.mdc
===================================================================
--- /branches/czw_branch/20110406/ippconfig/recipes/reductionClasses.mdc	(revision 31252)
+++ /branches/czw_branch/20110406/ippconfig/recipes/reductionClasses.mdc	(revision 31253)
@@ -239,4 +239,11 @@
 END
 
+# quick stacks
+QUICKSTACK            METADATA
+      STACK_PPSTACK   STR      QUICKSTACK
+      STACK_PPSUB     STR      STACK
+      STACK_PSPHOT    STR      STACK
+END
+
 # basic science analysis
 PHOTFEST.SINGLE1	METADATA
@@ -632,2 +639,19 @@
 END
 
+STS_DATASET METADATA
+   CHIP_PPIMAGE STR CHIP
+   CHIP_PSPHOT STR CHIP
+   WARP_PSWARP STR WARP
+   STACK_PPSTACK   STR STACK
+   STACK_PPSUB STR STACK
+   STACK_PSPHOT    STR STACK
+   DIFF_PPSUB  STR DIFF
+   DIFF_PSPHOT STR DIFF
+   JPEG_BIN1   STR PPIMAGE_J1
+   JPEG_BIN2   STR PPIMAGE_J2
+   FAKEPHOT    STR FAKEPHOT
+   ADDSTAR     STR ADDSTAR
+   PSASTRO    STR STS_DATASET
+   STACKPHOT       STR     STACKPHOT
+END
+
Index: /branches/czw_branch/20110406/ppSub/src/ppSub.c
===================================================================
--- /branches/czw_branch/20110406/ppSub/src/ppSub.c	(revision 31252)
+++ /branches/czw_branch/20110406/ppSub/src/ppSub.c	(revision 31253)
@@ -94,5 +94,5 @@
 
         if (data) {
-            psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
+            psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "DUMP_CONFIG");
             if (dump_file) {
                 if (!pmConfigDump(data->config, dump_file)) {
Index: /branches/czw_branch/20110406/psModules/src/camera/pmFPAWrite.c
===================================================================
--- /branches/czw_branch/20110406/psModules/src/camera/pmFPAWrite.c	(revision 31252)
+++ /branches/czw_branch/20110406/psModules/src/camera/pmFPAWrite.c	(revision 31253)
@@ -690,4 +690,5 @@
     pmHDU *hdu = pmHDUFromCell(cell);   // HDU for cell
     psMetadata *header = psMetadataCopy(NULL, hdu->header); // Header to write
+
     psMetadataAddS32(header, PS_LIST_TAIL, "COVARIANCE.CENTRE.X", PS_META_REPLACE,
                      "Centre of covariance matrix in x", -xMinCovar);
@@ -697,5 +698,9 @@
     // Turn off compression
     int bitpix = fits->options ? fits->options->bitpix : 0; // Desired bits per pixel
+    psFitsScaling scaling = fits->options ? fits->options->scaling : 0; // Current scaling method.
     psFitsCompression *compress = psFitsCompressionGet(fits); // Current compression options
+    
+/*     fprintf(stderr,"Attempting to write chip %s cell %s extension %s with scaling %d\n", */
+/* 	    chipName,cellName,extname,fits->options->scaling); */
     if (!psFitsSetCompression(fits, PS_FITS_COMPRESS_NONE, NULL, 0, 0, 0)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to set FITS compression to NONE");
@@ -708,4 +713,7 @@
     if (fits->options) {
         fits->options->bitpix = 0;
+    }
+    if (fits->options) {
+        fits->options->scaling = psFitsScalingFromString("STDEV_POSITIVE"); // This is a bit of a hack. We don't really have a default value.
     }
 
@@ -732,4 +740,7 @@
         fits->options->bitpix = bitpix;
     }
+    if (fits->options) {
+        fits->options->scaling = scaling;
+    }
     if (!psFitsCompressionApply(fits, compress)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to restore FITS compression");
Index: /branches/czw_branch/20110406/tools/mysql-dump/gpc1_dump.sh
===================================================================
--- /branches/czw_branch/20110406/tools/mysql-dump/gpc1_dump.sh	(revision 31252)
+++ /branches/czw_branch/20110406/tools/mysql-dump/gpc1_dump.sh	(revision 31253)
@@ -15,4 +15,6 @@
 . /home/panstarrs/ipp/mysql-dump/functions.sh
 . /home/panstarrs/ipp/mysql-dump/password.sh
+
+EMAILTO=schastel@ifa.hawaii.edu
 
 HOST=ippc02
@@ -43,5 +45,5 @@
 if [ "$dump_status" -ne "0" ]; then
 	log ERROR "Sending warning e-mail"
-	email "Gpc1 dump failed" schastel@ifa.hawaii.edu "Check log file: /export/$HOST.0/mysql-dumps/gpc1_dump.log"
+	email "Gpc1 dump failed" $EMAILTO "Check log file: /export/$HOST.0/mysql-dumps/gpc1_dump.log"
 	log INFO "End of gpc1 dump (Error)"
 	exit 1
Index: /branches/czw_branch/20110406/tools/mysql-dump/gpc1_install.sh
===================================================================
--- /branches/czw_branch/20110406/tools/mysql-dump/gpc1_install.sh	(revision 31252)
+++ /branches/czw_branch/20110406/tools/mysql-dump/gpc1_install.sh	(revision 31253)
@@ -9,8 +9,8 @@
 #      iterates up to $MAX_ITERATIONS times.
 # 2) Check the gpc1 dump file against its checksum.
-# 3) Import gpc1 into gpc1_0 or gpc1_1 (ensured by gpc1Import.py utility)
-# 4) Distribute the validated files, that is:
+# 3) Distribute the validated files, that is:
 #    - Hard-links the gzipped MySQL dump in the distribution directory
 #    - Moves the MD5 checksum to the distribution directory
+# 4) Import gpc1 into gpc1_0 or gpc1_1 (ensured by gpc1Import.py utility)
 . /home/panstarrs/ipp/mysql-dump/functions.sh
 
@@ -30,14 +30,20 @@
 
 ITERATION=1
-if [ ! -s $TARGET/$MD5FILE ]; then
-	log WARNING "MD5 file not found [$TARGET/$MD5FILE]. Waiting $SLEEPING_TIME seconds (Attempt: $ITERATION out of $MAX_ITERATIONS)"
-	sleep $SLEEPING_TIME
-	let ITERATION=ITERATION+1
-	if [ "$ITERATION" -ge "$MAX_ITERATIONS" ]; then
-		log ERROR "Copy of $TARGET/$MD5FILE failed after $ITERATION iterations. Giving up"
-		email "Too many failures when attempting to copy $TARGET/$MD5FILE" $EMAILTO "Check log"
-		exit 1
+MD5_STATUS=1
+while [ "$MD5_STATUS" -ne "0" ]; do
+	if [ ! -s $TARGET/$MD5FILE ]; then
+		log WARNING "MD5 file not found [$TARGET/$MD5FILE]. Waiting $SLEEPING_TIME seconds (Attempt: $ITERATION out of $MAX_ITERATIONS)"
+		sleep $SLEEPING_TIME
+		let ITERATION=ITERATION+1
+		if [ "$ITERATION" -ge "$MAX_ITERATIONS" ]; then
+			log ERROR "Copy of $TARGET/$MD5FILE failed after $ITERATION iterations. Giving up"
+			email "Too many failures when attempting to copy $TARGET/$MD5FILE" $EMAILTO "Check log"
+			log INFO "End of gpc1_install.sh (Failure)"
+			exit 1
+		fi
+	else
+		MD5_STATUS=0
 	fi
-fi
+done
 
 log INFO "Checking gpc1 backup file checksum"
@@ -45,14 +51,12 @@
 BACKUP_FILE=`cat $TARGET/$MD5FILE | sed 's/^.* \//\//'`
 BACKUP_FILE=`basename $BACKUP_FILE`
-
+log INFO "Backup file is [$TARGET/$BACKUP_FILE]"
 ACTUAL_MD5SUM=`/usr/bin/md5sum $TARGET/$BACKUP_FILE | sed 's/ .*$//'`
 if [ "$ACTUAL_MD5SUM" != "$EXPECTED_MD5SUM" ]; then
         log ERROR "Checksums are different: actual=[$ACTUAL_MD5SUM], expected=[$EXPECTED_MD5SUM]"
 	email "Invalid checksum for gpc1 backup" $EMAILTO "Checksums are different: actual=[$ACTUAL_MD5SUM], expected=[$EXPECTED_MD5SUM]"
+	log INFO "End of gpc1_install.sh (Failure)"
         exit 2
 fi
-
-log INFO "Importing gpc1 backup file to gpc1_0 or gpc1_1"
-/usr/bin/python /home/panstarrs/ipp/mysql-dump/gpc1Import.py
 
 log INFO "Symlinking backup file [$TARGET/$BACKUP_FILE] to distribution [$DISTRIBUTION_TARGET]"
@@ -60,2 +64,13 @@
 /usr/bin/mv -f $TARGET/$MD5FILE $DISTRIBUTION_MD5
 
+# if it is between 0 and 4, ingest into gpc1_0 or gpc1_1
+HOUR=`date +"%H"`
+if [ "$HOUR" -lt "4" ]; then
+	log INFO "Importing gpc1 backup file to gpc1_0 or gpc1_1"
+	/usr/bin/python /home/panstarrs/ipp/mysql-dump/gpc1Import.py
+else
+	log DEBUG "No gpc1 backup importation"
+fi
+
+log INFO "End of gpc1_install.sh (Success)"
+
Index: /branches/czw_branch/20110406/tools/mysql-dump/neb_dump.sh
===================================================================
--- /branches/czw_branch/20110406/tools/mysql-dump/neb_dump.sh	(revision 31252)
+++ /branches/czw_branch/20110406/tools/mysql-dump/neb_dump.sh	(revision 31253)
@@ -12,4 +12,5 @@
 . /home/panstarrs/ipp/mysql-dump/password.sh
 
+EMAILTO=schastel@ifa.hawaii.edu
 HOST=ippdb02
 
@@ -36,5 +37,5 @@
 if [ "$dump_status" -ne "0" ]; then
 	log ERROR "Sending warning e-mail"
-	email "Nebulous dump failed" schastel@ifa.hawaii.edu "Check log file: /export/ippdb02.0/mysql-dumps/neb-dump.log"
+	email "Nebulous dump failed" $EMAILTO "Check log file: /export/ippdb02.0/mysql-dumps/neb-dump.log"
 	log INFO "End of nebulous dump (Error)"
 	exit 1
Index: /branches/czw_branch/20110406/tools/mysql-dump/ops_dump.csh
===================================================================
--- /branches/czw_branch/20110406/tools/mysql-dump/ops_dump.csh	(revision 31252)
+++ /branches/czw_branch/20110406/tools/mysql-dump/ops_dump.csh	(revision 31253)
@@ -2,4 +2,6 @@
 
 echo "## `/bin/date +%FT%T`"
+
+set EMAILTO = schastel@ifa.hawaii.edu
 
 # dump ippRequestServer from ippc19
@@ -7,5 +9,5 @@
 mysqldump --compress -hippc19 -uipp -pipp --flush-logs --single-transaction --log-error=RS-err ippRequestServer | gzip -9 > $DUMP_PATH/mysql-RS-ippc19-`date +%FT%T`.dump.gz
 if ($status != 0) then
-   /bin/mail -s "Warning RS dump failed" schastel@ifa.hawaii.edu < msg
+   /bin/mail -s "Warning ippRequestServer/RS dump failed" $EMAILTO < msg
 endif
 
@@ -16,5 +18,5 @@
 mysqldump --compress -hippdb01 -uipp -pipp --flush-logs --single-transaction ippadmin | gzip -9 > $FILENAME
 if ($status != 0) then
-   /bin/mail -s "Warning ippadmin dump failed" schastel@ifa.hawaii.edu < msg  
+   /bin/mail -s "Warning ippadmin dump failed" $EMAILTO < msg  
 endif
 
@@ -31,5 +33,5 @@
 mysqldump --compress -hippdb01 -uipp -pipp --flush-logs --single-transaction isp | gzip -9 > $FILENAME
 if ($status != 0) then
-   /bin/mail -s "Warning isp dump failed" schastel@ifa.hawaii.edu < msg  
+   /bin/mail -s "Warning isp dump failed" $EMAILTO < msg  
 endif
 
@@ -39,40 +41,2 @@
 ln -f  ../mysql-isp-ippdb01-$DATEVAR.dump.gz ippdb01-isp.dump.gz
 
-# dump gpc1 from ippdb01
-#set DUMP_PATH = /data/ipp001.0/ipp/mysql-dumps               #path(SAB)
-#set DATEVAR=`date +%FT%T`                                    #date
-#set FILENAME = $DUMP_PATH/mysql-gpc1-ippc02-$DATEVAR.dump.gz #dump file name
-#mysqldump --compress -hippc -P3302 -uipp -pipp --flush-logs --single-transaction gpc1 | gzip -9 > $FILENAME
-#if ($status != 0) then
-#   /bin/mail -s "Warning gpc1 dump failed" schastel@ifa.hawaii.edu < msg  
-#endif
-
-# simlink to gpc1 ippdb01 dump
-#set DUMP_PATH = /data/ipp001.0/ipp/mysql-dumps       #path(SAB)
-#cd $DUMP_PATH/distribution/                          #link dir
-#ln -f  ../mysql-gpc1-ippc02-$DATEVAR.dump.gz ippdb01-gpc1.dump.gz   #hard link
-
-
-# dump the ippdb02 database
-#set DUMP_PATH = /data/ipp001.0/ipp/mysql-dumps             #path
-#set DATEVAR = `date +%FT%T`                                #date	
-#set FILENAME = $DUMP_PATH/mysql-neb-ippdb02-$DATEVAR.dump.gz   #dump file name
-#mysqldump --compress -hippdb02 -ujhipp -pjhipp --flush-logs --single-transaction nebulous | gzip -9 > $FILENAME
-#if ($status != 0) then
-#   /bin/mail -s "Warning nebulous dump failed" schastel@ifa.hawaii.edu < msg  
-#endif
-
-# simlink to latest ippdb02 dump
-#set DUMP_PATH = /data/ipp001.0/ipp/mysql-dumps	           #path (SAB)
-#cd $DUMP_PATH/distribution/                                #link dir
-#ln -f  ../mysql-neb-ippdb02-$DATEVAR.dump.gz ippdb02.dump.gz   #hard link
-
-# dump the ippdb00 database
-#set DUMP_PATH = /data/ipp001.0/ipp/mysql-dumps             #path
-#set DATEVAR = `date +%FT%T`                                #date	
-#set FILENAME = $DUMP_PATH/mysql-neb-ippdb00-$DATEVAR.dump.gz   #dump file name
-#mysqldump --compress -hippdb00 -ujhipp -pjhipp --flush-logs --single-transaction nebulous | gzip -9 > $FILENAME
-#if ($status != 0) then
-#   /bin/mail -s "Warning nebulous dump failed" schastel@ifa.hawaii.edu < msg  
-#endif
-
Index: /branches/czw_branch/20110406/tools/runcameraexp.pl
===================================================================
--- /branches/czw_branch/20110406/tools/runcameraexp.pl	(revision 31252)
+++ /branches/czw_branch/20110406/tools/runcameraexp.pl	(revision 31253)
@@ -16,4 +16,5 @@
 my $dbname = "gpc1";
 my ($cam_id, $update, $redirect, $save_temps, $pretend, $no_verbose);
+my ($outdir);
 
 GetOptions(
@@ -22,4 +23,5 @@
     'redirect-output'   => \$redirect,
     'save-temps'        => \$save_temps,
+    'outdir=s'          => \$outdir,
     'update'            => \$update,
     'dbname=s'          => \$dbname,
@@ -55,4 +57,11 @@
 
 die "Cannot update when run is not faulted\n" if $update and ! $fault;
+
+if ($outdir) {
+    my $base = basename($path_base);
+    $path_base = "$outdir/$base";
+    print STDERR "changing path_base to $path_base";
+    $update = 0;
+}
 
 my  $run_state;
