Index: /trunk/ippScripts/scripts/nightly_science.pl
===================================================================
--- /trunk/ippScripts/scripts/nightly_science.pl	(revision 41225)
+++ /trunk/ippScripts/scripts/nightly_science.pl	(revision 41226)
@@ -1494,6 +1494,6 @@
     my $db = init_gpc_db();
 
-    my $obj_sth = "select DISTINCT rawExp.object from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
-    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' ORDER BY rawExp.object";
+    my $obj_sth = "select rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment)) from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
+    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' GROUP BY rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment))";
 
     my $object_ref = $db->selectall_arrayref( $obj_sth );
@@ -1504,8 +1504,9 @@
     foreach my $object_row (@{ $object_ref }) {
 	my $this_object = shift @{ $object_row };	
+	my $this_chunk = shift @{ $object_row };
 	my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
 	$input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
 	$input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
-	$input_sth .=   " ORDER BY dateobs ";
+	$input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
 
 	my $warps = $db->selectall_arrayref( $input_sth );
@@ -1646,6 +1647,6 @@
     my $db = init_gpc_db();
 
-    my $obj_sth = "select DISTINCT rawExp.object from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
-    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' ORDER BY rawExp.object";
+    my $obj_sth = "select rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment)) from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
+    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' GROUP BY rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment))";
 
     my $object_ref = $db->selectall_arrayref( $obj_sth );
@@ -1692,9 +1693,10 @@
     foreach my $object_row (@{ $object_ref }) {
 	my $this_object = shift @{ $object_row };
+	my $this_chunk = shift @{ $object_row };
 	
 	my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality,substr(comment, 1, position(' ' in comment)) FROM ";
 	$input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
 	$input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
-	$input_sth .=   " ORDER BY dateobs ";
+	$input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
 
 	my $warps = $db->selectall_arrayref( $input_sth );
@@ -1861,6 +1863,6 @@
     my $db = init_gpc_db();
 
-    my $obj_sth = "select DISTINCT rawExp.object from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
-    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' ORDER BY rawExp.object";
+    my $obj_sth = "select rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment)) from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
+    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' GROUP BY rawExp.object,substr(rawExp.comment, 1, position(' ' in rawExp.comment))";
 
     my $object_ref = $db->selectall_arrayref( $obj_sth );
@@ -1907,9 +1909,10 @@
     foreach my $object_row (@{ $object_ref }) {
 	my $this_object = shift @{ $object_row };
+	my $this_chunk = shift @{ $object_row };
 	
 	my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state,camProcessedExp.quality FROM ";
 	$input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
 	$input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
-	$input_sth .=   " ORDER BY dateobs ";
+	$input_sth .=   " AND substr(rawExp.comment, 1, position(' ' in rawExp.comment)) = '$this_chunk' ORDER BY dateobs ";
 
 	my $warps = $db->selectall_arrayref( $input_sth );
