Index: trunk/ippToPsps/src/ippToPspsBatchDetection.c
===================================================================
--- trunk/ippToPsps/src/ippToPspsBatchDetection.c	(revision 28589)
+++ trunk/ippToPsps/src/ippToPspsBatchDetection.c	(revision 28698)
@@ -14,7 +14,9 @@
 
 // Gets uncalibrated instrumental flux from magnitude
-static __inline bool ippToPsps_getFlux(const float zeroPoint, const float exposureTime, const float magnitude, float* flux) {
+static __inline bool ippToPsps_getFlux(const float exposureTime, const float magnitude, float* flux, const float magnitudeErr, float* fluxErr) {
 
     *flux = powf(10.0, -0.4*magnitude) / exposureTime;
+    if (fluxErr) *fluxErr = (magnitudeErr * *flux)/1.085736;
+//if (fluxErr)    printf("Mag = %03.03f, Flux = %03.03f, Mag err = %03.03f, Flux Err = %03.03f\n", magnitude, *flux, magnitudeErr, *fluxErr);
     return (!isfinite(*flux) || *flux < 0.000001) ? false : true;
 }
@@ -46,5 +48,5 @@
     fits_get_hdrspace(fitsIn, &nKeys, NULL, &status);
 
-    float zptObs, zeroPoint, exposureTime;
+    float zptObs, exposureTime;
     char filterType[20];
     double obsTime;
@@ -52,5 +54,4 @@
     double expTime;
     status=0; fits_read_key(fitsIn, TFLOAT, "ZPT_OBS", &zptObs, NULL, &status);
-    status=0; fits_read_key(fitsIn, TFLOAT, "ZPT_REF", &zeroPoint, NULL, &status);
     status=0; fits_read_key(fitsIn, TFLOAT, "EXPREQ", &exposureTime, NULL, &status);
     status=0; fits_read_key(fitsIn, TSTRING, "FILTERID", filterType, NULL, &status);
@@ -138,10 +139,10 @@
     long removeList[MAXDETECT];
     long thisObjId;
-    bool firstTimeIn = true;
+    bool firstTimeIn = true, peakFluxOk, instFluxOk;
     int ippIDetNum, instMagNum, instMagErrNum, peakMagNum;
 
     // loop round all 60 chips
-    for (int x=0; x<8; x++) {
-        for (int y=0; y<8; y++) {
+    for (int x=3; x<4; x++) {
+        for (int y=3; y<4; y++) {
 
             // dodge the corners
@@ -293,9 +294,12 @@
                     obsTimes[s] = obsTime;
 
-                    ippToPsps_getFlux(zeroPoint, exposureTime, instMagErr[s], &instFluxErr[s]);
+//                    ippToPsps_getFlux(exposureTime, instMagErr[s], &instFluxErr[s]);
+
+                    // calculate flux and flux errors from magnitudes
+                    peakFluxOk = ippToPsps_getFlux(exposureTime, peakMag[s], &peakFlux[s], 0.0, NULL);
+                    instFluxOk = ippToPsps_getFlux(exposureTime, instMag[s], &instFlux[s], instMagErr[s], &instFluxErr[s]);
 
                     // check for invalid flux values (if not already labelled as a duplicate)
-                    if ((!ippToPsps_getFlux(zeroPoint, exposureTime, peakMag[s], &peakFlux[s]) ||
-                                !ippToPsps_getFlux(zeroPoint, exposureTime, instMag[s], &instFlux[s])) && !isDuplicate) {
+                    if ( (!peakFluxOk || !instFluxOk) && !isDuplicate) {
                         removeList[numOfDuplicates+numInvalidFlux] = s+1;
                         numInvalidFlux++;
