Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c	(revision 33155)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c	(revision 33156)
@@ -73,7 +73,7 @@
   int CHIP_DY;
 
-  FILE *f;
-
-  f = fopen (filename, "r");
+  *nzpts = 0;
+
+  FILE *f = fopen (filename, "r");
   if (!f) {
     fprintf (stderr, "ERROR: cannot open zpt table file %s\n", filename);
@@ -178,4 +178,6 @@
   ftable.header = &theader;
   for (nfilter = 0; nfilter < NFILTER; nfilter++) {
+    // *** load the ZERO POINT table ***
+
     // load data for this header 
     if (!gfits_load_header (f, &theader)) return (NULL);
@@ -202,7 +204,10 @@
       zpts[i+Nzpts].time = ohana_mjd_to_sec(mjd[i]);
       zpts[i+Nzpts].zpt = zp[i];
-      // zpts[i+Nzpts].zpt_err = zperr[i];
+      zpts[i+Nzpts].zpt_err = 0.0;
+      zpts[i+Nzpts].found = FALSE;
     }
     Nzpts += Nrow;
+
+    // *** load the flat-field correction image ***
 
     // the image contains the flat-field corrections for a specific filter
@@ -211,5 +216,5 @@
     if (!gfits_load_header (f, &header)) return (NULL);
 
-    if (!gfits_scan (&theader, "FILTER", "%s", 1, filter)) { 
+    if (!gfits_scan (&header, "FILTER", "%s", 1, filter)) { 
       fprintf (stderr, "cannot find FILTER in header of %s\n", filename);
       fclose (f);
@@ -218,7 +223,22 @@
 
     // read the fits table bytes
+    double *offset64 = NULL;
+    float *offset32 = NULL;
+    int use32 = TRUE;
+
     if (!gfits_fread_matrix (f, &matrix, &header)) return (NULL);
-    assert (header.bitpix == -64); // hardwired as a double
-    double *offset = (double *) matrix.buffer;
+    switch (header.bitpix) {
+      case -32: // float
+	offset32 = (float *) matrix.buffer;
+	use32 = TRUE;
+	break;
+      case -64: // double
+	offset64 = (double *) matrix.buffer;
+	use32 = FALSE;
+	break;
+      default:
+	fprintf (stderr, "invalid bitpix for flat-field correction image: %d\n", header.bitpix);
+	exit (2);
+    }
 
     for (nseason = 0; nseason < NSEASON; nseason++) { // seasons
@@ -244,4 +264,5 @@
 	    for (ixc = 0; ixc < NCELL_X; ixc++) {
 	      if (ix > 3) {
+		// XXX I think this is backwards : chips ix < 4 should be flipped
 		seq = nfilter*NSEASON*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + nseason*NCHIP_X*NCHIP_Y*NCELL_X*NCELL_Y + (iy*NCELL_Y + NCELL_Y - 1 - iyc)*NCHIP_X*NCELL_X + (ix*NCELL_X + NCELL_X - 1 - ixc);
 	      } else {
@@ -251,5 +272,9 @@
 	      flatcorrTable->corr[seq].x = ixc;
 	      flatcorrTable->corr[seq].y = iyc;
-	      flatcorrTable->corr[seq].offset = offset[seq];
+	      if (use32) {
+		flatcorrTable->corr[seq].offset = offset32[seq];
+	      } else {
+		flatcorrTable->corr[seq].offset = offset64[seq];
+	      }
 	      flatcorrTable->corr[seq].ID = corrID;
 	    }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c	(revision 33155)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c	(revision 33156)
@@ -34,4 +34,6 @@
     zpts = load_zpt_table (argv[1], &Nzpts);
   }
+
+  if (!zpts) Shutdown ("failed to load zero points, or empty table");
 
   // load images 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c	(revision 33155)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c	(revision 33156)
@@ -94,5 +94,5 @@
       }
 
-      catalog[0].measure[m].Mcal = Mcal + Mcal_offset;
+      catalog[0].measure[m].Mcal = Mcal - Mcal_offset;
       catalog[0].measure[m].dMcal = dMcal;
 
