Index: trunk/ippToPsps/jython/batch.py
===================================================================
--- trunk/ippToPsps/jython/batch.py	(revision 36720)
+++ trunk/ippToPsps/jython/batch.py	(revision 36721)
@@ -440,4 +440,74 @@
 
       return True
+    '''
+    Imports IPP tables from FITS file
+
+    Accepts a regular expression filter so not all tables need to be imported
+    '''
+    def importIppSTTables(self, columns="*", filter=""):
+
+      self.logger.infoPair("Importing ST tables with filter", filter)
+
+      # print "trying to read ", self.fits.getPath()
+
+      # ST has 5 cmf files - all with the same table names. To counter this we do it like this.
+
+      filters = ["g","r","i","z","y"]
+
+      for f in filters:
+          if (f == "g"):
+              fileName = self.gfits.getPath()
+          if (f == "r"):
+              fileName = self.rfits.getPath()
+          if (f == "i"):
+              fileName = self.ifits.getPath()
+          if (f == "z"):
+              fileName = self.zfits.getPath()
+          if (f == "y"):
+              fileName = self.yfits.getPath()
+
+
+          try:
+              tables = stilts.treads(fileName)
+          except:
+              self.logger.errorPair("STILTS could not import from", fileName)
+              return False
+              
+          count = 0
+          for table in tables:
+              
+              # print "import smf table ", table
+              match = re.match(filter, table.name)
+              
+              if not match: continue
+              self.logger.debugPair("Reading IPP table", table.name)
+              table = stilts.tpipe(table, cmd='addcol table_index $0')
+                  
+              table = stilts.tpipe(table, cmd='explodeall')
+                  
+              # print "read smf table ", table
+                  
+              # drop any previous tables before import
+              self.scratchDb.dropTable(f + table.name)
+                  
+              # IPP FITS files are littered with infinities, so remove these
+              self.logger.debug("Removing Infinity values from all columns")
+              table = stilts.tpipe(table, cmd='keepcols "' + columns + '"')
+              table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
+              table = stilts.tpipe(table, cmd='replaceval Infinity null *')
+              # print "cleaned up values ", table
+                  
+              try:
+                  table.write(self.scratchDb.url + '#' + f + table.name)
+                  # XXX this one is not needed
+                  # self.scratchDb.killLastConnectionID()
+                  count = count + 1
+              except:
+                  self.logger.exception("Problem writing table '" + f + table.name + "' to the database")
+                      
+              self.logger.infoPair("Done. Imported", "%d tables" % count)
+              self.indexIppTables()
+                      
+              return True
 
     '''
@@ -551,6 +621,11 @@
         # for P2/ST, this reads the detection tables from the CMF/SMF file(s)
         # for OB, this imports object data from DVO
-        if self.batchType != "ST":
-            # if not ST we do it 
+        if self.batchType = "ST":
+            if not self.importIppSTTables():
+                self.logger.errorPair("skipping this batch", "could not import ST IPP tables")
+                self.ippToPspsDb.updateProcessed(self.batchID, -1)
+                raise
+        else:    
+            # if not ST we do this 
             if not self.importIppTables():
                 if self.batchType == "OB":
