Index: trunk/ippToPsps/jython/stackbatch.py
===================================================================
--- trunk/ippToPsps/jython/stackbatch.py	(revision 34832)
+++ trunk/ippToPsps/jython/stackbatch.py	(revision 34833)
@@ -5,4 +5,5 @@
 
 import stilts
+import re
 from java.lang import *
 from java.sql import *
@@ -143,49 +144,134 @@
     '''
     def updateApFlxs(self, prefix, psfCondition):
+        #properly -999 these to start with:
 
         sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
-        "+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
-        "+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
-        "+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
-        "+prefix+"flxR1Fill=b.APER_FILL_1, \
-        "+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
-        "+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
-        "+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
-        "+prefix+"flxR2Fill=b.APER_FILL_2, \
-        "+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
-        "+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
-        "+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
-        "+prefix+"flxR3Fill=b.APER_FILL_3, \
-        "+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
-        "+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
-        "+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
-        "+prefix+"flxR4Fill=b.APER_FILL_4, \
-        "+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
-        "+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
-        "+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
-        "+prefix+"flxR5Fill=b.APER_FILL_5, \
-        "+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
-        "+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
-        "+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
-        "+prefix+"flxR6Fill=b.APER_FILL_6, \
-        "+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
-        "+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
-        "+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
-        "+prefix+"flxR7Fill=b.APER_FILL_7, \
-        "+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
-        "+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
-        "+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
-        "+prefix+"flxR8Fill=b.APER_FILL_8, \
-        "+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
-        "+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
-        "+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
-        "+prefix+"flxR9Fill=b.APER_FILL_9, \
-        "+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
-        "+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
-        "+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
-        "+prefix+"flxR10Fill=b.APER_FILL_10 \
-        WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
-
-        self.scratchDb.execute(sql)
+        "+prefix+"flxR1=-999, \
+        "+prefix+"flxR1Err=-999, \
+        "+prefix+"flxR1Std=-999, \
+        "+prefix+"flxR1Fill=-999, \
+        "+prefix+"flxR2=-999, \
+        "+prefix+"flxR2Err=-999, \
+        "+prefix+"flxR2Std=-999, \
+        "+prefix+"flxR2Fill=-999, \
+        "+prefix+"flxR3=-999, \
+        "+prefix+"flxR3Err=-999, \
+        "+prefix+"flxR3Std=-999, \
+        "+prefix+"flxR3Fill=-999, \
+        "+prefix+"flxR4=-999, \
+        "+prefix+"flxR4Err=-999, \
+        "+prefix+"flxR4Std=-999, \
+        "+prefix+"flxR4Fill=-999, \
+        "+prefix+"flxR5=-999, \
+        "+prefix+"flxR5Err=-999, \
+        "+prefix+"flxR5Std=-999, \
+        "+prefix+"flxR5Fill=-999, \
+        "+prefix+"flxR6=-999, \
+        "+prefix+"flxR6Err=-999, \
+        "+prefix+"flxR6Std=-999, \
+        "+prefix+"flxR6Fill=-999, \
+        "+prefix+"flxR7=-999, \
+        "+prefix+"flxR7Err=-999, \
+        "+prefix+"flxR7Std=-999, \
+        "+prefix+"flxR7Fill=-999, \
+        "+prefix+"flxR8=-999, \
+        "+prefix+"flxR8Err=-999, \
+        "+prefix+"flxR8Std=-999, \
+        "+prefix+"flxR8Fill=-999, \
+        "+prefix+"flxR9=-999, \
+        "+prefix+"flxR9Err=-999, \
+        "+prefix+"flxR9Std=-999, \
+        "+prefix+"flxR9Fill=-999, \
+        "+prefix+"flxR10=-999, \
+        "+prefix+"flxR10Err=-999, \
+        "+prefix+"flxR10Std=-999, \
+        "+prefix+"flxR10Fill=-999 \
+        WHERE a.ippDetectID=b.IPP_IDET "
+        #self.logger.infoPair("sql", sql)
+        self.scratchDb.execute(sql)
+
+
+        #we have variable numbers of these columns. find out which are in use
+        sql = "DESCRIBE SkyChip_xrad 'aper_fill_%'"
+        rs = self.scratchDb.executeQuery(sql)
+        rs.first()
+        columns = []
+        column = rs.getString(1)
+        columns.append(column)
+        while (rs.next()):
+            column = rs.getString(1)
+            columns.append(column)
+        rs.close()
+
+        #use regex to leave just the numbers
+
+        numbers = []
+        for column in columns: 
+            number = re.sub("APER_FILL_","",column)
+            if (int(number) >= 1 and int(number) <=10):
+                numbers.append(number)
+                self.logger.infoPair("Aperture Numbers",number)
+
+        #generate the sql to do the necessary ops on the columns    
+        sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET "
+        cnt =0
+        for number in numbers:
+            if (cnt>0):
+                sql=sql+" , "
+            sql=sql+prefix+"flxR"+number+"=b.APER_FLUX_"+number +" / " + str(self.expTime) + ", "
+            sql=sql+prefix+"flxR"+number+"Err=b.APER_FLUX_ERR_"+number +" / " + str(self.expTime) + ", "
+            sql=sql+prefix+"flxR"+number+"Std=b.APER_FLUX_STDEV_"+number +" / " + str(self.expTime) + ", "
+            sql=sql+prefix+"flxR"+number+"Fill=b.APER_FILL_"+number + " "
+            cnt=cnt+1
+            
+        sql=sql+"WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition     
+        self.scratchDb.execute(sql)
+
+        #self.logger.infoPair("sql",sql)
+
+        #sql = "UPDATE StackApFlx AS a, SkyChip_xrad AS b SET \
+        #"+prefix+"flxR1=b.APER_FLUX_1 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR1Err=b.APER_FLUX_ERR_1 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR1Std=b.APER_FLUX_STDEV_1 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR1Fill=b.APER_FILL_1, \
+        #"+prefix+"flxR2=b.APER_FLUX_2 / " + str(self.expTime) + ", \
+        ##"+prefix+"flxR2Err=b.APER_FLUX_ERR_2 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR2Std=b.APER_FLUX_STDEV_2 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR2Fill=b.APER_FILL_2, \
+        #"+prefix+"flxR3=b.APER_FLUX_3 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR3Err=b.APER_FLUX_ERR_3 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR3Std=b.APER_FLUX_STDEV_3 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR3Fill=b.APER_FILL_3, \
+        #"+prefix+"flxR4=b.APER_FLUX_4 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR4Err=b.APER_FLUX_ERR_4 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR4Std=b.APER_FLUX_STDEV_4 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR4Fill=b.APER_FILL_4, \
+        #"+prefix+"flxR5=b.APER_FLUX_5 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR5Err=b.APER_FLUX_ERR_5 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR5Std=b.APER_FLUX_STDEV_5 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR5Fill=b.APER_FILL_5, \
+        #"+prefix+"flxR6=b.APER_FLUX_6 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR6Err=b.APER_FLUX_ERR_6 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR6Std=b.APER_FLUX_STDEV_6 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR6Fill=b.APER_FILL_6, \
+        #"+prefix+"flxR7=b.APER_FLUX_7 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR7Err=b.APER_FLUX_ERR_7 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR7Std=b.APER_FLUX_STDEV_7 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR7Fill=b.APER_FILL_7, \
+        #"+prefix+"flxR8=b.APER_FLUX_8 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR8Err=b.APER_FLUX_ERR_8 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR8Std=b.APER_FLUX_STDEV_8 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR8Fill=b.APER_FILL_8, \
+        #"+prefix+"flxR9=b.APER_FLUX_9 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR9Err=b.APER_FLUX_ERR_9 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR9Std=b.APER_FLUX_STDEV_9 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR9Fill=b.APER_FILL_9, \
+        #"+prefix+"flxR10=b.APER_FLUX_10 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR10Err=b.APER_FLUX_ERR_10 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR10Std=b.APER_FLUX_STDEV_10 / " + str(self.expTime) + ", \
+        #"+prefix+"flxR10Fill=b.APER_FILL_10 \
+        #WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
+
+        #self.scratchDb.execute(sql)
 
     '''
