Index: /trunk/ippToPsps/scripts/ippToPsps_run.pl
===================================================================
--- /trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28259)
+++ /trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28260)
@@ -12,5 +12,5 @@
 
 # globals
-my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $survey, $singleExpId, $no_publish, $force);
+my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $survey, $singleExpId, $no_publish, $force, $initBatch);
 
 # default values for certain globals
@@ -25,4 +25,5 @@
 $datastoreProduct = "PSPS_test";
 $force = 0;
+$initBatch = 0;
 
 # get user args
@@ -62,5 +63,7 @@
 defined $output and
 defined $dvodb and
-( defined $survey or defined $singleExpId );
+(( defined $survey or defined $singleExpId ) or ( $batchType eq "init"));
+
+if ($batchType eq "init") {$initBatch = 1;}
 
 # check we can run programs and get camera config
@@ -130,5 +133,22 @@
 
     my $query;
-    if (!$singleExpId) {
+    if ($initBatch) {
+    
+        $query = $gpc1Db->prepare(<<SQL);
+
+        SELECT 0, 'NULL', 'ThreePi';
+SQL
+    }
+    elsif ($singleExpId) {
+
+        $query = $gpc1Db->prepare(<<SQL);
+
+        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
+    }
+    else {
 
         $query = $gpc1Db->prepare(<<SQL);
@@ -145,13 +165,4 @@
 
             #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%'
@@ -160,14 +171,4 @@
             #AND rawExp.decl >= '-0.157079633' AND rawExp.decl <= '0.157079633' Jims Dec range
     }
-    else {
-
-        $query = $gpc1Db->prepare(<<SQL);
-
-        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
-    }
 
     my $batchId = 0;
@@ -184,5 +185,5 @@
         my ($expId, $expName, $distGroup) = @row;
 
-        if (isExposureAlreadyProcessed($ippToPspsDb, $expId)) {
+        if (!$initBatch && isExposureAlreadyProcessed($ippToPspsDb, $expId)) {
                 
                 if ($force) {print "* Forcing....\n";} 
@@ -202,9 +203,8 @@
         my $batchDir = sprintf("B%03d", $batchId);
         my $batchOutputPath = sprintf("$jobOutputPath/%s", $batchDir);
-        print "* Preparing exposure $expId as job '$job'...\n";
-
-        # make directories
         mkdir($jobOutputPath, 0777);
         mkdir($batchOutputPath, 0777);
+
+        print "* Preparing exposure $expId as job '$job'...\n";
 
         # run IppToPsps program
@@ -245,6 +245,5 @@
         }
 
-        if ($batchType eq "init" ) {print "* Wrote initialisation batch\n"; last;}
-
+        if ($initBatch) {print "* Wrote initialisation batch\n";}
 
         print "*\n*******************************************************************************\n\n";
@@ -676,5 +675,5 @@
     my ($outputPath) = @_;
 
-    my $success = runProgram( "NULL", $outputPath, 0, $batchType);
+    my $success = runProgram("NULL", $outputPath, 0, "NULL", "NULL", $batchType);
     return $success;
 }
