Index: /trunk/ippToPsps/jython/scratchdb.py
===================================================================
--- /trunk/ippToPsps/jython/scratchdb.py	(revision 32294)
+++ /trunk/ippToPsps/jython/scratchdb.py	(revision 32295)
@@ -39,4 +39,37 @@
 
         self.logger.debug("ScratchDb destructor")
+
+
+    '''
+    Creates stored procedure for psfLikelihood
+    '''
+    def createPsfLikelihoodFunction(self):
+        sql = "DELIMITER $$ \
+               DROP FUNCTION IF EXISTS `psfLikelihood` $$ \
+               CREATE FUNCTION `psfLikelihood`(x REAL) RETURNS REAL \
+               DETERMINISTIC \
+               COMMENT 'Returns the psfLikelihood using the complimentary error function with fractional error everywhere less than 1.2 x 10-7. From Numerical Recipes in C' \
+               BEGIN \
+               DECLARE ans REAL; \
+               DECLARE t REAL; \
+               DECLARE z REAL; \
+               SET x = ABS(x) / 1.4142135623731; \
+               SET z=ABS(x); \
+               SET t=1.0 / (1.0 + 0.5*z); \
+               SET ans = t * EXP(-z*z-1.26551223+t*(1.00002368+t*(.37409196+t*(.09678418+t*(-.18628806+t*(.27886807+t*(-1.13520398+t*(1.48851587+t*(-.82215223+t*.17087277))))))))); \
+               IF x < 0.0 THEN \
+               SET ans = 2.0 - ans; \
+               END IF; \
+               RETURN ans; \
+               END $$ \
+               DELIMITER ;"
+
+        try:
+            self.execute(sql)
+            self.logger.debugPair("Installed stored procedure", "psfLikelihood")
+            return True
+        except:
+            self.logger.errorPair("Could not install stored procedure", "psfLikelihood")
+            return False
 
     '''
