Index: trunk/ippToPsps/jython/batch.py
===================================================================
--- trunk/ippToPsps/jython/batch.py	(revision 31109)
+++ trunk/ippToPsps/jython/batch.py	(revision 31112)
@@ -35,7 +35,11 @@
         # get survey ID from init table
         sql = "SELECT surveyID from Survey WHERE name = '" + survey + "'"
-        rs = self.stmt.executeQuery(sql)  
-        rs.first()
-        self.surveyID = rs.getInt(1)
+        try:
+            rs = self.stmt.executeQuery(sql)  
+            rs.first()
+            self.surveyID = rs.getInt(1)
+        except:
+            self.log("No survey ID found for this survey: '" + survey + "'")
+            self.surveyID = -1;
     
         # store today's date
@@ -51,9 +55,16 @@
     def __del__(self):
 
-        print "Batch destructor"
+        self.log("Batch destructor")
         self.stmt.close()
         self.con.close()
 
     '''
+    Prints a log message with the current time
+    '''
+    def log(self, msg):
+
+        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " | " + msg
+
+    '''
     Updates a table with surveyID
     '''
@@ -82,27 +93,32 @@
         while (True):
            record = fitsFile.read(80)
+
+           # quit when we reach 'END'
            if record.startswith("END"): break
+
+           # ignore comments
            if record.startswith("COMMENT"): continue
            match = re.match('(.*)=(.*)', record)
            if match:
 
+               # remove HIERARCH prefix
                param = match.group(1).replace("HIERARCH", "")
                param = param.strip()
 
                value = match.group(2)
-               #print value
+               # remove trailing comment after / char, if there is one
                index = value.find("/")
-               if index != -1:
-                   value = value[0:index]
-               #print value
+               if index != -1: value = value[0:index]
+
+               # remove ' chars around content
                value = value.replace("'", "")
+
+               # remove leading and trailing whitespace
                value = value.strip()
 
+               # store in out dictionary object
                self.header[param] = value
 
                #print param + "|" + value + "|"
-        
-        print "Fields in FITS header: ", len(self.header)
-        print "NINPUTS = ", self.header['NINPUTS']
 
     '''
@@ -113,5 +129,5 @@
          self.pspsTables = stilts.treads(self.pspsVoTableFilePath)
          for table in self.pspsTables:
-             print "Creating PSPS table: " + table.name
+             self.log("Creating PSPS table: " + table.name)
              table.write(self.url + '#' + table.name)
 
@@ -122,5 +138,5 @@
     '''   
     def indexIppTables(self):
-        print "indexIppTables not implemented"
+        self.log("indexIppTables not implemented")
 
 
@@ -130,5 +146,5 @@
     def createIndex(self, table, column):
 
-        print "Creating index on column '"+column+"' for table '"+table+"'"
+        self.log("Creating index on column '"+column+"' for table '"+table+"'")
 
         sql = "CREATE INDEX "+table+"_index ON "+table+" ("+column+")"
@@ -136,5 +152,5 @@
             self.stmt.execute(sql)
         except:
-            print "Index already in place on '" + column + "' for table '" + table + "'"
+            self.log("Index already in place on '" + column + "' for table '" + table + "'")
 
 
@@ -143,6 +159,5 @@
     '''   
     def indexPspsTables(self):
-        print "indexPspsTables not implemented"
-
+        self.log("indexPspsTables not implemented")
 
     '''
@@ -154,12 +169,12 @@
 
       for table in tables:
-          print "Creating IPP table " + table.name
+          self.log("Creating IPP table " + table.name)
           table = stilts.tpipe(table, cmd='explodeall')
           try:
               table.write(self.url + '#' + table.name)
           except:
-              print "ERROR table " + table.name + " is busted"
-
-          self.indexIppTables()
+              self.log("ERROR problem writing table '" + table.name + "' to the database")
+
+      self.indexIppTables()
 
     '''
@@ -168,8 +183,8 @@
     def exportPspsTablesToFits(self):
 
-        print "Exporting all PSPS tables to FITS"
+        self.log("Exporting all PSPS tables to FITS")
         _tables = []
 
-        print "    Selecting database tables"
+        self.log("    Selecting database tables")
         for table in self.pspsTables:
            _table = stilts.tread(self.url + '#SELECT * FROM ' + table.name)
@@ -177,5 +192,5 @@
            _tables.append(_table)
 
-        print "    Writing to FITS file " + self.outputFitsPath
+        self.log("    Writing to FITS file " + self.outputFitsPath)
         stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
 
@@ -184,5 +199,5 @@
     Main processing method - must be implemented by subclasses
     '''
-    def process(self):
-        print "Not implemented yet"
-
+    def populatePspsTables(self):
+        self.log("Not implemented yet")
+
