Index: trunk/ippToPsps/jython/batch.py
===================================================================
--- trunk/ippToPsps/jython/batch.py	(revision 31291)
+++ trunk/ippToPsps/jython/batch.py	(revision 31299)
@@ -62,6 +62,6 @@
         if self.survey != "":
 
-        # get survey ID from init table
-            sql = "SELECT surveyID from Survey WHERE name = '" + self.getPspsSurveyType() + "'"
+            # get survey ID from init table
+            sql = "SELECT surveyID from Survey WHERE name = '" + self.survey + "'"
             try:
                 rs = self.localStmt.executeQuery(sql)  
@@ -69,8 +69,8 @@
                 self.surveyID = rs.getInt(1)
             except:
-                self.logger.exception("No survey ID found for this survey: '" + self.getPspsSurveyType() + "'")
+                self.logger.exception("No survey ID found for this survey: '" + self.survey + "'")
                 self.surveyID = -1;
    
-        # get dvo info from config
+            # get dvo info from config
             dvoName = doc.find(survey+"dvo/name").text
             self.dvoLocation = doc.find(survey+"dvo/location").text
@@ -109,4 +109,5 @@
         # create DVO table
         self.createDvoTable()
+        header = self.findAndReadFITSHeader("XY86.hdr")
 
     '''
@@ -171,5 +172,5 @@
         root.attrib['timestamp'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 
         if self.survey != "":
-            root.attrib['survey'] = self.getPspsSurveyType()
+            root.attrib['survey'] = self.getBatchFriendlySurveyType()
         try: self.minObjID
         except: pass
@@ -243,5 +244,5 @@
     Gets PSPS-friendly survey type
     '''
-    def getPspsSurveyType(self):
+    def getBatchFriendlySurveyType(self):
 
         try:
@@ -287,4 +288,13 @@
 
     '''
+    Drops a table
+    '''
+    def dropTable(self, table):
+
+        sql = "DROP TABLE " + table
+        try: self.localStmt.execute(sql)
+        except: return
+
+    '''
     Updates a table with surveyID
     '''
@@ -413,10 +423,17 @@
         self.logger.info("    Selecting database tables")
         for table in self.pspsTables:
+
+           # check for an empty table
+           if self.getRowCount(table.name) < 1: continue
+
+           # get everything from table
            _table = stilts.tread(self.localUrl + '#SELECT * FROM ' + table.name)
-           #           if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
 
            self.logger.info("   Replacing NULLs with weird PSPS -999 constant for " + table.name)
-           _table = stilts.tpipe(_table, cmd='replaceval "" -999 *') # TODO doesn't work
-           #if table.name == "StackDetection": _table.cmd_keepcols('stackDetectID projectionCellID').cmd_head(4).write()
+
+           # replace nulls and empty fields with weird PSPS -999 pseudo-null
+           _table = stilts.tpipe(_table, cmd='replaceval "" -999 *')
+
+           # change table names
            _table = stilts.tpipe(_table, cmd='tablename ' + table.name)
            _tables.append(_table)
@@ -425,4 +442,5 @@
         stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
         self.logger.info("    ...done")
+
 
     '''
@@ -537,4 +555,19 @@
 
     '''
+    Returns a row count for this table
+    '''
+    def getRowCount(self, table):
+
+        sql = "SELECT COUNT(*) FROM " + table
+        try:
+            rs = self.localStmt.executeQuery(sql)  
+            rs.first()
+            return rs.getInt(1)
+        except:
+            self.logger.exception("Could not count rows for table: '" + table + "'")
+            return -1
+
+
+    '''
     Calls DVO program to 'query' DVO database and populate results to local MySQL Db table
     '''
