Index: trunk/ippToPsps/scripts/ippToPsps_run.pl
===================================================================
--- trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28120)
+++ trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28205)
@@ -12,5 +12,5 @@
 
 # globals
-my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $label, $singleExpId, $no_publish, $force);
+my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $survey, $singleExpId, $no_publish, $force);
 
 # default values for certain globals
@@ -31,5 +31,5 @@
         'batch|b=s' => \$batchType,
         'dvodb|d=s' => \$dvodb,
-        'label|l=s' => \$label,
+        'survey|s=s' => \$survey,
         'expid|e=s' => \$singleExpId,
         'product|p=s' => \$datastoreProduct,
@@ -49,5 +49,5 @@
         "--batch <init|det|diff|stack>\n".
         "--output <path>\n".
-        "--label <label> or --expid <expid>\n" .
+        "--survey <ThreePi|MD01,2 etc|STS|SAS|SweetSpot> or --expid <expid>\n" .
         "--dvodb <path>\n".
         "\n   Optional:\n\n".
@@ -62,5 +62,5 @@
 defined $output and
 defined $dvodb and
-( defined $label or defined $singleExpId );
+( defined $survey or defined $singleExpId );
 
 # check we can run programs and get camera config
@@ -118,5 +118,5 @@
 #######################################################################################
 # 
-# Finds all exposures for the provided label and generates PSPS FITS data for them
+# Finds all exposures for the provided TODO and generates PSPS FITS data for them
 #
 #######################################################################################
@@ -132,15 +132,27 @@
     if (!$singleExpId) {
 
-        # query to retrieve all exposures with the provided label
         $query = $gpc1Db->prepare(<<SQL);
 
-        SELECT DISTINCT rawExp.exp_id, camRun.dist_group
-            FROM camRun, chipRun, rawExp
-            WHERE camRun.chip_id = chipRun.chip_id
-            AND chipRun.exp_id = rawExp.exp_id
-            AND camRun.dist_group LIKE 'ThreePi'
-            AND rawExp.exp_id > $lastExpId
-            ORDER BY rawExp.exp_id ASC
+        SELECT rawExp.exp_id, rawExp.exp_name, camRun.dist_group 
+            FROM camRun, chipRun, rawExp 
+            WHERE camRun.state = 'full' 
+            AND camRun.chip_id = chipRun.chip_id 
+            AND chipRun.exp_id = rawExp.exp_id 
+            AND camRun.dist_group = '$survey'   
+            AND rawExp.exp_id > 145986 
+            GROUP BY  rawExp.exp_id 
+            ORDER BY rawExp.exp_id ASC;
 SQL
+
+            #AND rawExp.dateobs <= '2010-03-12'
+
+  #      SELECT DISTINCT rawExp.exp_id, camRun.dist_group
+  #          FROM camRun, chipRun, rawExp
+  #          WHERE camRun.chip_id = chipRun.chip_id
+  #          AND chipRun.exp_id = rawExp.exp_id
+  #          AND camRun.dist_group LIKE 'ThreePi'
+  #          AND rawExp.exp_id > $lastExpId
+  #          ORDER BY rawExp.exp_id ASC
+#SQL
             #AND rawExp.exp_id > $lastExpId
             #AND camRun.label LIKE '%$label%'
@@ -153,5 +165,8 @@
         $query = $gpc1Db->prepare(<<SQL);
 
-        SELECT DISTINCT rawExp.exp_id, dist_group FROM rawExp, chipRun WHERE chipRun.exp_id = rawExp.exp_id AND rawExp.exp_id = $singleExpId
+        SELECT DISTINCT rawExp.exp_id,  rawExp.exp_name, dist_group 
+            FROM rawExp, chipRun 
+            WHERE chipRun.exp_id = rawExp.exp_id 
+            AND rawExp.exp_id = $singleExpId
 SQL
     }
@@ -168,5 +183,5 @@
     # loop round exposures
     while (my @row = $query->fetchrow_array()) {
-        my ($expId, $distGroup) = @row;
+        my ($expId, $expName, $distGroup) = @row;
 
         if (isExposureAlreadyProcessed($ippToPspsDb, $expId)) {
@@ -174,5 +189,5 @@
                 if ($force) {print "* Forcing....\n";} 
                 else {next};
-                }
+        }
 
         my $surveyType = getSurveyTypeFromDistGroup($distGroup);
@@ -181,5 +196,5 @@
         $jobId = getNewBatchId($ippToPspsDb, $expId, $surveyType);
 
-# TODO quit here if no sensible job ID
+        # TODO quit here if no sensible job ID
 
         # generate batch and job paths from job and batch IDs
@@ -188,5 +203,4 @@
         my $batchDir = sprintf("B%03d", $batchId);
         my $batchOutputPath = sprintf("$jobOutputPath/%s", $batchDir);
-
         print "* Preparing exposure $expId as job '$job'...\n";
 
@@ -196,5 +210,5 @@
 
         # run IppToPsps program
-        if (runIppToPsps($gpc1Db, $expId, $batchOutputPath, $batchType)) {
+        if (runIppToPsps($gpc1Db, $expId, $expName, $surveyType, $batchOutputPath, $batchType)) {
 
             # write batch manifest and tar and zip up
@@ -358,17 +372,16 @@
 #######################################################################################
 sub runIppToPsps {
-    my ($gpc1Db, $expId, $batchOutputPath, $batchType) = @_;
+    my ($gpc1Db, $expId, $expName, $surveyType, $batchOutputPath, $batchType) = @_;
 
     my $success = 0;
 
-    # before anything else, we can publish the init batch
     if ($batchType =~ /init/) {
         $success = produceInit($batchOutputPath);
     }
     elsif ($batchType =~ /det/) {
-        $success = produceDetections($gpc1Db, $expId, $batchOutputPath);
+        $success = produceDetections($gpc1Db, $expId, $expName, $surveyType, $batchOutputPath);
     }
     elsif ($batchType =~ /diff/) {
-        $success = produceDiffs($gpc1Db, $expId, $batchOutputPath);
+        $success = produceDiffs($gpc1Db, $expId, $expName, $surveyType, $batchOutputPath);
     }
 
@@ -673,5 +686,5 @@
 #######################################################################################
 sub produceDetections {
-    my ($gpc1Db,$expId,$outputPath) = @_;
+    my ($gpc1Db, $expId, $expName, $surveyType, $outputPath) = @_;
 
     # query to retrieve nebulous key of camera smf file for this exposure
@@ -709,5 +722,5 @@
         close $tempFile;
 
-        $success = runProgram($tempName, $outputPath, $expId, $batchType);
+        $success = runProgram($tempName, $outputPath, $expId, $expName, $surveyType, $batchType);
         return $success;
     }
@@ -720,5 +733,5 @@
 #######################################################################################
 sub produceDiffs {
-    my ($gpc1Db,$expId,$outputPath) = @_;
+    my ($gpc1Db, $expId, $expName, $surveyType, $outputPath) = @_;
 
     my $query = 
@@ -758,5 +771,5 @@
     }
 
-    my $ret = runProgram($tempName, $outputPath, $expId, $batchType);
+    my $ret = runProgram($tempName, $outputPath, $expId, $expName, $surveyType, $batchType);
 
     close $tempFile;
@@ -771,5 +784,5 @@
 #######################################################################################
 sub runProgram {
-    my ($input, $output, $expid, $batchType) = @_;
+    my ($input, $output, $expid, $expName, $surveyType, $batchType) = @_;
 
     # build command
@@ -780,4 +793,5 @@
     $command .= " -config config"; # TODO
     $command .= " -expid $expid";
+    $command .= " -expname $expName";
     $command .= " -batch $batchType";
     $command .= " -results $resultsFileName";
