Index: /branches/czw_branch/20100519/dbconfig/changes.txt
===================================================================
--- /branches/czw_branch/20100519/dbconfig/changes.txt	(revision 28244)
+++ /branches/czw_branch/20100519/dbconfig/changes.txt	(revision 28245)
@@ -1716,8 +1716,8 @@
 CREATE TABLE warpSummary (
     warp_id     BIGINT,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     path_base   VARCHAR(255) NOT NULL,
     PRIMARY KEY(warp_id),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1725,8 +1725,8 @@
 CREATE TABLE diffSummary (
     diff_id     BIGINT,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     path_base   VARCHAR(255) NOT NULL,
     PRIMARY KEY(diff_id),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1734,8 +1734,8 @@
 CREATE TABLE stackSummary (
     stack_id     BIGINT,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     path_base   VARCHAR(255) NOT NULL,
     PRIMARY KEY(stack_id),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     FOREIGN KEY(stack_id) REFERENCES stackRun(stack_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1744,10 +1744,10 @@
     sass_id      BIGINT AUTO_INCREMENT,
     data_group   VARCHAR(64) NOT NULL,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     tess_id       VARCHAR(64) NOT NULL,
     filter        VARCHAR(64) NOT NULL,
     PRIMARY KEY(sass_id),
     KEY(data_group),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     KEY(tess_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
Index: /branches/czw_branch/20100519/dbconfig/diff.md
===================================================================
--- /branches/czw_branch/20100519/dbconfig/diff.md	(revision 28244)
+++ /branches/czw_branch/20100519/dbconfig/diff.md	(revision 28245)
@@ -77,6 +77,6 @@
 
 diffSummary METADATA
-    diff_id	   S64      0       # Primary Key fkey(diff_id) ref diffRun(diff_id)
-    tangent_plane  STR	    32	    # Primary Key
-    path_base 	   STR	    255
+    diff_id	    S64      0       # Primary Key fkey(diff_id) ref diffRun(diff_id)
+    projection_cell STR	    32	    # Primary Key
+    path_base 	    STR	    255
 END
Index: /branches/czw_branch/20100519/dbconfig/stack.md
===================================================================
--- /branches/czw_branch/20100519/dbconfig/stack.md	(revision 28244)
+++ /branches/czw_branch/20100519/dbconfig/stack.md	(revision 28245)
@@ -56,5 +56,5 @@
 stackSummary METADATA
     stack_id	   S64      0       # Primary Key fkey(stack_id) ref stackRun(stack_id)
-    tangent_plane  STR	    32	    # Primary Key
+    projection_cell  STR	    32	    # Primary Key
     path_base 	   STR	    255
 END
@@ -63,5 +63,5 @@
     sass_id        S64      0       # Primary Key AUTO_INCREMENT
     data_group     STR      64      # Key
-    tangent_plane  STR      64      # Key
+    projection_cell  STR      64      # Key
     tess_id        STR      64      # Key
     filter         STR      64
Index: /branches/czw_branch/20100519/dbconfig/warp.md
===================================================================
--- /branches/czw_branch/20100519/dbconfig/warp.md	(revision 28244)
+++ /branches/czw_branch/20100519/dbconfig/warp.md	(revision 28245)
@@ -82,5 +82,5 @@
 warpSummary METADATA
     warp_id	   S64      0       # Primary Key fkey(warp_id) ref warpRun(warp_id)
-    tangent_plane  STR	    32	    # Primary Key
+    projection_cell  STR	    32	    # Primary Key
     path_base 	   STR	    255
 END
Index: /branches/czw_branch/20100519/ippScripts/scripts/skycell_jpeg.pl
===================================================================
--- /branches/czw_branch/20100519/ippScripts/scripts/skycell_jpeg.pl	(revision 28244)
+++ /branches/czw_branch/20100519/ippScripts/scripts/skycell_jpeg.pl	(revision 28245)
@@ -32,11 +32,11 @@
     'save_temps'      => \$save_temps,
     'masks'           => \$masks,
-    'no-op'           => \$no_op,
-    'no-update'       => \$no_update,
+#    'no-op'           => \$no_op,
+#    'no-update'       => \$no_update,
     ) or pod2usage ( 2 );
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2) if @ARGV;
 pod2usage(
-    -msg => "Required options: --stage --stage_id --outroot",
+    -msg => "Required options: --stage --stage_id --outroot\nHelpful options: --camera --dbname",
     -exitval => 3,
     ) unless
@@ -80,42 +80,42 @@
 	my $quality    = $imfile->{quality};
 	my $state      = $imfile->{data_state};
-	my $tangent_base = $skycell_id;
+	my $projection_cell = $skycell_id;
 	if ($quality == 8007 or $state ne 'full') {
 	    next;
 	}
 
-	$tangent_base =~ s/^(.*)\..*$/$1/;
-	
-	unless (exists($tangents{$tangent_base})) {
+	$projection_cell =~ s/^(.*)\..*$/$1/;
+	
+	unless (exists($tangents{$projection_cell})) {
 	    # Make a temp file and fill, but be sure to save 
-	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$tangent_base.XXXX",
+	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.XXXX",
 						 UNLINK => !$save_temps);
-	    $tangents{$tangent_base}{FILE} = $tempFile;
-	    $tangents{$tangent_base}{NAME} = $tempName;
+	    $tangents{$projection_cell}{FILE} = $tempFile;
+	    $tangents{$projection_cell}{NAME} = $tempName;
 	    if ($masks) {
-		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$tangent_base.masks.XXXX",
+		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$projection_cell.masks.XXXX",
 						     UNLINK => !$save_temps);
-		$tangents{$tangent_base}{MFILE} = $maskFile;
-		$tangents{$tangent_base}{MNAME} = $maskName;
+		$tangents{$projection_cell}{MFILE} = $maskFile;
+		$tangents{$projection_cell}{MNAME} = $maskName;
 	    }		
 	}
-	print "$skycell_id $tangent_base\n";	
+	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PSWARP.OUTPUT", $path_base, $skycell_id);
 	print "$file $state $quality\n";
-	my $f_fh = $tangents{$tangent_base}{FILE};
+	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base, $skycell_id);
 	    print "$mask\n";
-	    my $m_fh = $tangents{$tangent_base}{MFILE};
+	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
 	}
     }
-    foreach my $tangent_base (keys %tangents) {
-	$command = "$ppSkycell -images $tangents{$tangent_base}{NAME}";
-	if ($masks) {
-	    $command .= " -masks $tangents{$tangent_base}{MNAME} ";
-	}
-	$command .= " ${outroot}.${tangent_base} ";
+    foreach my $projection_cell (keys %tangents) {
+	$command = "$ppSkycell -images $tangents{$projection_cell}{NAME}";
+	if ($masks) {
+	    $command .= " -masks $tangents{$projection_cell}{MNAME} ";
+	}
+	$command .= " ${outroot}.${projection_cell} ";
 	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
@@ -125,5 +125,5 @@
 	}
 	# Update database:
-	$command = "$warptool -addsummary -warp_id $stage_id -tangent_base $tangent_base -outroot $outroot";
+	$command = "$warptool -addsummary -warp_id $stage_id -projection_cell $projection_cell -outroot $outroot";
 	if (defined($dbname)) {
 	    $command .= " -dbname $dbname";
@@ -164,42 +164,42 @@
 	my $quality    = $imfile->{quality};
 	my $state      = $imfile->{data_state};
-	my $tangent_base = $skycell_id;
+	my $projection_cell = $skycell_id;
 	if ($quality == 8007 or $state ne 'full') {
 	    next;
 	}
 
-	$tangent_base =~ s/^(.*)\..*$/$1/;
-	
-	unless (exists($tangents{$tangent_base})) {
+	$projection_cell =~ s/^(.*)\..*$/$1/;
+	
+	unless (exists($tangents{$projection_cell})) {
 	    # Make a temp file and fill, but be sure to save 
-	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$tangent_base.XXXX",
+	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.XXXX",
 						 UNLINK => !$save_temps);
-	    $tangents{$tangent_base}{FILE} = $tempFile;
-	    $tangents{$tangent_base}{NAME} = $tempName;
+	    $tangents{$projection_cell}{FILE} = $tempFile;
+	    $tangents{$projection_cell}{NAME} = $tempName;
 	    if ($masks) {
-		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$tangent_base.masks.XXXX",
+		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$projection_cell.masks.XXXX",
 						     UNLINK => !$save_temps);
-		$tangents{$tangent_base}{MFILE} = $maskFile;
-		$tangents{$tangent_base}{MNAME} = $maskName;
+		$tangents{$projection_cell}{MFILE} = $maskFile;
+		$tangents{$projection_cell}{MNAME} = $maskName;
 	    }		
 	}
-	print "$skycell_id $tangent_base\n";	
+	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PPSUB.OUTPUT", $path_base, $skycell_id);
 	print "$file $state $quality\n";
-	my $f_fh = $tangents{$tangent_base}{FILE};
+	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PPSUB.OUTPUT.MASK", $path_base, $skycell_id);
 	    print "$mask\n";
-	    my $m_fh = $tangents{$tangent_base}{MFILE};
+	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
 	}
     }
-    foreach my $tangent_base (keys %tangents) {
-	$command = "$ppSkycell -images $tangents{$tangent_base}{NAME}";
-	if ($masks) {
-	    $command .= " -masks $tangents{$tangent_base}{MNAME} ";
-	}
-	$command .= " ${outroot}.${tangent_base} ";
+    foreach my $projection_cell (keys %tangents) {
+	$command = "$ppSkycell -images $tangents{$projection_cell}{NAME}";
+	if ($masks) {
+	    $command .= " -masks $tangents{$projection_cell}{MNAME} ";
+	}
+	$command .= " ${outroot}.${projection_cell} ";
 	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
@@ -209,5 +209,5 @@
 	}
 	# Update database:
-	$command = "$difftool -addsummary -diff_id $stage_id -tangent_base $tangent_base -outroot $outroot";
+	$command = "$difftool -addsummary -diff_id $stage_id -projection_cell $projection_cell -outroot $outroot";
 	if (defined($dbname)) {
 	    $command .= " -dbname $dbname";
@@ -248,42 +248,42 @@
 	my $quality    = $imfile->{quality};
 	my $state      = $imfile->{data_state};
-	my $tangent_base = $skycell_id;
+	my $projection_cell = $skycell_id;
 	if ($quality == 8007 or $state ne 'full') {
 	    next;
 	}
 
-	$tangent_base =~ s/^(.*)\..*$/$1/;
-	
-	unless (exists($tangents{$tangent_base})) {
+	$projection_cell =~ s/^(.*)\..*$/$1/;
+	
+	unless (exists($tangents{$projection_cell})) {
 	    # Make a temp file and fill, but be sure to save 
-	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$tangent_base.XXXX",
+	    ($tempFile, $tempName) = tempfile("/tmp/skycell.$projection_cell.XXXX",
 						 UNLINK => !$save_temps);
-	    $tangents{$tangent_base}{FILE} = $tempFile;
-	    $tangents{$tangent_base}{NAME} = $tempName;
+	    $tangents{$projection_cell}{FILE} = $tempFile;
+	    $tangents{$projection_cell}{NAME} = $tempName;
 	    if ($masks) {
-		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$tangent_base.masks.XXXX",
+		my ($maskFile, $maskName) = tempfile("/tmp/skycell.$projection_cell.masks.XXXX",
 						     UNLINK => !$save_temps);
-		$tangents{$tangent_base}{MFILE} = $maskFile;
-		$tangents{$tangent_base}{MNAME} = $maskName;
+		$tangents{$projection_cell}{MFILE} = $maskFile;
+		$tangents{$projection_cell}{MNAME} = $maskName;
 	    }		
 	}
-	print "$skycell_id $tangent_base\n";	
+	print "$skycell_id $projection_cell\n";	
 	my $file = $ipprc->filename("PPSTACK.OUTPUT", $path_base, $skycell_id);
 	print "$file $state $quality\n";
-	my $f_fh = $tangents{$tangent_base}{FILE};
+	my $f_fh = $tangents{$projection_cell}{FILE};
 	print $f_fh "$file\n";
 	if ($masks) {
 	    my $mask = $ipprc->filename("PPSTACK.OUTPUT.MASK", $path_base, $skycell_id);
 	    print "$mask\n";
-	    my $m_fh = $tangents{$tangent_base}{MFILE};
+	    my $m_fh = $tangents{$projection_cell}{MFILE};
 	    print $m_fh "$mask\n";
 	}
     }
-    foreach my $tangent_base (keys %tangents) {
-	$command = "$ppSkycell -images $tangents{$tangent_base}{NAME}";
-	if ($masks) {
-	    $command .= " -masks $tangents{$tangent_base}{MNAME} ";
-	}
-	$command .= " ${outroot}.${tangent_base} ";
+    foreach my $projection_cell (keys %tangents) {
+	$command = "$ppSkycell -images $tangents{$projection_cell}{NAME}";
+	if ($masks) {
+	    $command .= " -masks $tangents{$projection_cell}{MNAME} ";
+	}
+	$command .= " ${outroot}.${projection_cell} ";
 	print "$command\n";
 	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
@@ -293,5 +293,5 @@
 	}
 	# Update database:
-	$command = "$stacktool -addsummary -stack_id $stage_id -tangent_base $tangent_base -outroot $outroot";
+	$command = "$stacktool -addsummary -stack_id $stage_id -projection_cell $projection_cell -outroot $outroot";
 	if (defined($dbname)) {
 	    $command .= " -dbname $dbname";
Index: /branches/czw_branch/20100519/ippTools/share/Makefile.am
===================================================================
--- /branches/czw_branch/20100519/ippTools/share/Makefile.am	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/share/Makefile.am	(revision 28245)
@@ -121,4 +121,6 @@
      difftool_skyfile.sql \
      difftool_todiffskyfile.sql \
+     difftool_tosummary.sql \
+     difftool_addsummary.sql \
      disttool_definebyquery_camera.sql \
      disttool_definebyquery_chip.sql \
@@ -289,4 +291,6 @@
      stacktool_sumskyfile.sql \
      stacktool_tosum.sql \
+     stacktool_tosummary.sql \
+     stacktool_addsummary.sql \
      staticskytool_definebyquery_select.sql \
      staticskytool_definebyquery_inputs.sql \
@@ -319,3 +323,5 @@
      warptool_towarped.sql \
      warptool_updateskyfile.sql \
-     warptool_warped.sql
+     warptool_warped.sql \
+     warptool_tosummary.sql \
+     warptool_addsummary.sql
Index: /branches/czw_branch/20100519/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- /branches/czw_branch/20100519/ippTools/share/pxadmin_create_tables.sql	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/share/pxadmin_create_tables.sql	(revision 28245)
@@ -983,8 +983,8 @@
 CREATE TABLE warpSummary (
        warp_id BIGINT,
-       tangent_plane VARCHAR(64) NOT NULL,
+       projection_cell VARCHAR(64) NOT NULL,
        path_base     VARCHAR(255) NOT NULL,
        PRIMARY KEY(warp_id),
-       KEY(tangent_plane),
+       KEY(projection_cell),
        FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1062,8 +1062,8 @@
 CREATE TABLE stackSummary (
     stack_id     BIGINT,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     path_base   VARCHAR(255) NOT NULL,
     PRIMARY KEY(stack_id),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     FOREIGN KEY(stack_id) REFERENCES stackRun(stack_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1072,10 +1072,10 @@
     sass_id      BIGINT AUTO_INCREMENT,
     data_group   VARCHAR(64) NOT NULL,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     tess_id       VARCHAR(64) NOT NULL,
     filter        VARCHAR(64) NOT NULL,
     PRIMARY KEY(sass_id),
     KEY(data_group),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     KEY(tess_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1187,8 +1187,8 @@
 CREATE TABLE diffSummary (
     diff_id     BIGINT,
-    tangent_plane VARCHAR(64) NOT NULL,
+    projection_cell VARCHAR(64) NOT NULL,
     path_base   VARCHAR(255) NOT NULL,
     PRIMARY KEY(diff_id),
-    KEY(tangent_plane),
+    KEY(projection_cell),
     FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
Index: /branches/czw_branch/20100519/ippTools/src/difftool.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/difftool.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/difftool.c	(revision 28245)
@@ -2356,5 +2356,5 @@
 
   PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
-  PXOPT_LOOKUP_STR(tangent_plane, config->args, "-tangent_plane", true, false);
+  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
   PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
 
@@ -2364,5 +2364,5 @@
     return(false);
   }
-  if (!p_psDBRunQueryF(config->dbh, query, diff_id, tangent_plane, path_base)) {
+  if (!p_psDBRunQueryF(config->dbh, query, diff_id, projection_cell, path_base)) {
     psError(PS_ERR_UNKNOWN, false, "database error");
     psFree(query);
Index: /branches/czw_branch/20100519/ippTools/src/difftoolConfig.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/difftoolConfig.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/difftoolConfig.c	(revision 28245)
@@ -327,15 +327,19 @@
     psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL,  "-diff_id", 0,           "search by diff ID", 0);
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL,  "-tess_id",  0,          "search by tessellation ID", NULL);
-    psMetadataAddStr(tosummaryArgs , PS_LIST_TAIL, "-warp_id",  0,         "search by warp_id", NULL);
-    psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL, "-template",  0,        "apply exposure args to template of bothways diff", false);
+    psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL, "-state",  0,            "search by state", NULL);
     psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL,  "-exp_id",  0,           "search by exposure ID", 0);
     psMetadataAddStr(tosummaryArgs , PS_LIST_TAIL, "-exp_name",  0,        "search by exposure name", NULL);
+    psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL, "-warp_id", 0,         "search by warp ID", 0);
+    
     psMetadataAddTime(tosummaryArgs, PS_LIST_TAIL, "-dateobs_begin", 0,    "search for exposures by time (>=)", NULL);
     psMetadataAddTime(tosummaryArgs, PS_LIST_TAIL, "-dateobs_end", 0,      "search for exposures by time (<=)", NULL);
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL,  "-filter", 0,           "search for filter", NULL);
+    psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL,  "-magicked", 0,         "search by magic id", 0);
     psMetadataAddStr(tosummaryArgs,  PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by diffRun label (LIKE comparison)", NULL);
     psMetadataAddStr(tosummaryArgs,  PS_LIST_TAIL, "-data_group",  PS_META_DUPLICATE_OK, "search by diffRun data_group (LIKE comparison)", NULL);
     psMetadataAddStr(tosummaryArgs,  PS_LIST_TAIL, "-dist_group",  PS_META_DUPLICATE_OK, "search by diffRun dist_group (LIKE comparison)", NULL);
-
+    psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL,  "-destreaked", 0, "search for runs that have been destreaked", false);
+    psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL,  "-not_destreaked", 0, "search for runs that have not been destreaked", false);
+    
     psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL, "-all",  0,             "search without arguments", false);
     psMetadataAddU64(tosummaryArgs, PS_LIST_TAIL,  "-limit",  0,            "limit result set to N items", 0);
@@ -345,5 +349,5 @@
     psMetadata *addsummaryArgs = psMetadataAlloc();
     psMetadataAddS64(addsummaryArgs, PS_LIST_TAIL,  "-diff_id", 0,           "search by diff ID", 0);
-    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-tangent_plane", 0, "set tangent plane", NULL);
+    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-projection_cell", 0, "set projection cell", NULL);
     psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-path_base", 0, "set summary path base", NULL);
 
Index: /branches/czw_branch/20100519/ippTools/src/stacktool.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/stacktool.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/stacktool.c	(revision 28245)
@@ -106,4 +106,58 @@
     exit(exit_status);
 }
+//stackAssociationRow *association = pxStackAssociationDefine(data_group,tess_id,filter,skycell_id);
+stackAssociationRow *pxStackAssociationDefine(pxConfig *config, psS64 stack_id) {
+  psString select = pxDataGet("stacktool_associationdefine_select.sql");
+  if (!select) {
+    psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+    return false;
+  }
+
+  psString idString = NULL;
+  psStringAppend(&idString, "%" PRId64, stack_id);
+  psStringSubstitute(&select,idString, "@STACK_ID@");
+  psFree(idString);
+
+  if (!p_psDBRunQuery(config->dbh, select)) {
+    psError(PS_ERR_UNKNOWN,false, "database error");
+    psFree(select);
+    return(NULL);
+  }
+  psFree(select);
+  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");
+    case PS_ERR_DB_SERVER:
+      psError(PXTOOLS_ERR_PROG, false, "database error");
+    default:
+      psError(PXTOOLS_ERR_PROG, false, "unknown error");
+    }
+    return(NULL);
+  }
+  if (psArrayLength(output) != 1) {
+    psWarning("stacktool: incorrect number of rows found");
+    psFree(output);
+    return(NULL);
+  }
+  psMetadata *outrow = NULL;
+  for (long i = 0; i < output->n; i++) {
+    psMetadata *row = output->data[i];
+    if (!psMetadataCopy(row,outrow)) {
+      psError(PS_ERR_UNKNOWN, false, "Failed to copy row to return");
+      return(NULL);
+    }
+  }
+  psFree(output);
+  stackAssociationRow *sassRow = stackAssociationObjectFromMetadata(outrow);
+  psFree(outrow);
+  return(sassRow);
+}
+      
+      
+  
+					      
 
 
@@ -399,4 +453,48 @@
         psFree(run);
 
+	//CZW Add an association entry here.
+	// Define the requested association, and insert it if it doesn't already exist
+	stackAssociationRow *association = pxStackAssociationDefine(config,stack_id);
+	psS64 sass_id;
+	if (!association->sass_id) {
+	  psTrace("stacktool.association",2,"No required Association found. Adding.");
+
+	  if (!stackAssociationInsertObject(config->dbh,association)) {
+	    if (!psDBRollback(config->dbh)) {
+	      psError(PS_ERR_UNKNOWN, false, "database error");
+	    }
+	    psError(PS_ERR_UNKNOWN, false, "database error");
+	    psFree(output);
+	    psFree(run);
+	    psFree(insert);
+	    psFree(list);
+	    psFree(association);
+	    if (!psDBRollback(config->dbh)) {
+	      psError(PS_ERR_UNKNOWN, false, "database error");
+	    }
+	    return(false);
+	  }
+	  sass_id = psDBLastInsertID(config->dbh);
+	  association->sass_id = sass_id;
+	}
+	// Insert the map entry for this row.
+	stackAssociationMapRow *maprow = stackAssociationMapRowAlloc(sass_id,stack_id);
+	if (!stackAssociationMapInsertObject(config->dbh,maprow)) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error");
+	  }
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	  psFree(output);
+	  psFree(run);
+	  psFree(insert);
+	  psFree(list);
+	  psFree(association);
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error");
+	  }
+	  return(false);
+	}
+	
+	
         // Create a suitable insertion query for this run
         psString thisInsert = psStringCopy(insert);
@@ -556,4 +654,6 @@
     run->stack_id = psDBLastInsertID(config->dbh);
 
+    //CZW Add an association entry here.
+    
     // insert the stackInputSkyfile rows
     psListIterator *iter = psListIteratorAlloc(warp_ids->data.list, 0, false);
@@ -607,7 +707,8 @@
 #endif
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-stack_id",  "stack_id",   "==");
-    PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
-    PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
+    PXOPT_COPY_S64(config->args, where, "-stack_id",  "stackRun.stack_id",   "==");
+    PXOPT_COPY_STR(config->args, where, "-label",     "stackRun.label",     "==");
+    PXOPT_COPY_STR(config->args, where, "-state",     "stackRun.state",     "==");
+    PXOPT_COPY_STR(config->args, where, "-sass_id",   "stackAssociationMap.sass_id",  "==");
     if (!psListLength(where->list)) {
         psFree(where);
@@ -616,4 +717,5 @@
     }
 
+    //CZW join against stackAssociationMap
     psString query = psStringCopy("UPDATE stackRun");
 
@@ -961,4 +1063,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "==");
     PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "==");
     PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "==");
@@ -1134,4 +1237,5 @@
   psMetadata *where = psMetadataAlloc();
   PXOPT_COPY_S64(config->args, where, "-stack_id",    "stackSumSkyfile.warp_id", "==");
+  PXOPT_COPY_S64(config->args, where, "-sass_id",     "stackAssociationMap.sass_id", "==");
   PXOPT_COPY_STR(config->args, where, "-tess_id",    "stackSumSkyfile.tess_id", "==");
   PXOPT_COPY_STR(config->args, where, "-state",      "stackRun.state", "==");
@@ -1215,5 +1319,5 @@
 
   PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", true, false);
-  PXOPT_LOOKUP_STR(tangent_plane, config->args, "-tangent_plane", true, false);
+  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
   PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
 
@@ -1223,5 +1327,5 @@
     return(false);
   }
-  if (!p_psDBRunQueryF(config->dbh, query, stack_id, tangent_plane, path_base)) {
+  if (!p_psDBRunQueryF(config->dbh, query, stack_id, projection_cell, path_base)) {
     psError(PS_ERR_UNKNOWN, false, "database error");
     psFree(query);
@@ -1251,4 +1355,7 @@
 
     psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_S64(config->args, where, "-stack_id", "stackRun.stack_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "==");
+    
     pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
 
@@ -1377,4 +1484,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    PXOPT_COPY_STR(config->args, where, "-sass_id", "sass_id", "==");
 
     psString query = pxDataGet("stacktool_donecleanup.sql");
@@ -1446,4 +1554,5 @@
 }
 
+//CZW I have not added sass information to the export/import run modes yet.
 bool exportrunMode(pxConfig *config)
 {
Index: /branches/czw_branch/20100519/ippTools/src/stacktoolConfig.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/stacktoolConfig.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/stacktoolConfig.c	(revision 28245)
@@ -207,4 +207,5 @@
     psMetadata *tosummaryArgs = psMetadataAlloc();
     psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL, "-stack_id", 0,  "search by stack ID", 0);
+    psMetadataAddS64(tosummaryArgs, PS_LIST_TAIL, "-sass_id", 0,  "search by stack association ID", 0);
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL, "-tess_id", 0,   "search by tessellation ID", NULL);
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL, "-state", 0,     "search by state", NULL);
@@ -221,5 +222,5 @@
     psMetadata *addsummaryArgs = psMetadataAlloc();
     psMetadataAddS64(addsummaryArgs, PS_LIST_TAIL, "-stack_id", 0,      "set stack ID", 0);
-    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-tangent_plane", 0, "set tangent plane", NULL);
+    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-projection_cell", 0, "set projection cell", NULL);
     psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-path_base", 0,     "set summary path base", NULL);		     
     
Index: /branches/czw_branch/20100519/ippTools/src/warptool.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/warptool.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/warptool.c	(revision 28245)
@@ -1653,5 +1653,5 @@
 
   PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
-  PXOPT_LOOKUP_STR(tangent_plane, config->args, "-tangent_plane", true, false);
+  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
   PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
 
@@ -1661,5 +1661,5 @@
     return(false);
   }
-  if (!p_psDBRunQueryF(config->dbh, query, warp_id, tangent_plane, path_base)) {
+  if (!p_psDBRunQueryF(config->dbh, query, warp_id, projection_cell, path_base)) {
     psError(PS_ERR_UNKNOWN, false, "database error");
     psFree(query);
Index: /branches/czw_branch/20100519/ippTools/src/warptoolConfig.c
===================================================================
--- /branches/czw_branch/20100519/ippTools/src/warptoolConfig.c	(revision 28244)
+++ /branches/czw_branch/20100519/ippTools/src/warptoolConfig.c	(revision 28245)
@@ -336,6 +336,6 @@
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL,  "-data_group",  PS_META_DUPLICATE_OK, "search by warpRun data_group", NULL);
     psMetadataAddStr(tosummaryArgs, PS_LIST_TAIL,  "-dist_group",  PS_META_DUPLICATE_OK, "search by warpRun dist_group", NULL);
-    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-destreaked", 0, "search for runs that have been destreaked", false);
-    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-not_destreaked", 0, "search for runs that have not been destreaked", false);
+    psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL, "-destreaked", 0, "search for runs that have been destreaked", false);
+    psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL, "-not_destreaked", 0, "search for runs that have not been destreaked", false);
     
     psMetadataAddBool(tosummaryArgs, PS_LIST_TAIL, "-all",  0,             "search without arguments", false);
@@ -346,5 +346,5 @@
     psMetadata *addsummaryArgs = psMetadataAlloc();
     psMetadataAddS64(addsummaryArgs, PS_LIST_TAIL, "-warp_id", 0,         "set warp ID", 0);
-    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-tangent_plane", 0,   "set tangent plane", NULL);
+    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-projection_cell", 0,   "set projection cell", NULL);
     psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-path_base", 0,       "set summary path base", NULL);
     
Index: /branches/czw_branch/20100519/ppSkycell/src/ppSkycellLoop.c
===================================================================
--- /branches/czw_branch/20100519/ppSkycell/src/ppSkycellLoop.c	(revision 28244)
+++ /branches/czw_branch/20100519/ppSkycell/src/ppSkycellLoop.c	(revision 28245)
@@ -315,4 +315,5 @@
 	  pmCell *Fcell1 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN1"); // Rebinned cell 1
 	  pmCell *Fcell2 = pmFPAfileThisCell(data->config->files, view, "PPSKYCELL.BIN2"); // Rebinned cell 2
+
 	  // This is a hack to get a functioning header created so the fits images can be written out.
 	  psMetadataAddS32(Fcell1->concepts,PS_LIST_TAIL,"CELL.XPARITY", PS_META_REPLACE,"",1);
@@ -327,5 +328,5 @@
 	  psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.XPARITY", PS_META_REPLACE,"",1);
 	  psMetadataAddS32(Fcell2->parent->concepts,PS_LIST_TAIL,"CHIP.YPARITY", PS_META_REPLACE,"",1);
-	  
+
 	  pmReadout *Fro1 = pmReadoutAlloc(Fcell1), *Fro2 = pmReadoutAlloc(Fcell2); // Binned readouts
 	  
