Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38298)
@@ -496,5 +496,5 @@
 int setMrel_catalog_alt (Catalog *catalog, int Nc, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
-int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
+int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr);
 int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
 
@@ -565,5 +565,6 @@
 int magStatsByRanking (StatDataSet *dataset, StatType *stats);
 
-SynthZeroPoints *SynthZeroPointsLoad (char *filename);
+int SynthZeroPointsLoad (char *filename);
+SynthZeroPoints *SynthZeroPointsGet ();
 
 int relphot_synthphot (int hostID, char *hostpath);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38298)
@@ -253,16 +253,5 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    // pass == -1 for anything other than the final pass
-    switch (SET_MREL_VERSION) {
-      case 0:
-	setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
-	break;
-      case 1:
-	setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
-	break;
-      default:
-	fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
-	exit (2);
-    }
+    setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
     SetMrelInfoAccum (&summary, &results);
   }
@@ -274,11 +263,9 @@
 }
 
+// setMrelOutput is NOT threaded because we read/write catalogs one at a time (for now)
 int setMrelOutput (Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr) {
 
   int i;
 
-  // fprintf (stderr, "this version of setMrel is invalid for now\n");
-  // exit (1);
-	
   int Nsecfilt = GetPhotcodeNsecfilt ();
 
@@ -288,15 +275,5 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    switch (SET_MREL_VERSION) {
-      // case 0:
-      // setMrel_catalog (catalog, i, pass, flatcorr, &results, Nsecfilt);
-      // break;
-      case 1:
-	setMrel_catalog_alt (catalog, i, TRUE, flatcorr, &results, Nsecfilt);
-	break;
-      default:
-	fprintf (stderr, "invalid setMrel version %d (use 1)\n", SET_MREL_VERSION);
-	exit (2);
-    }
+    setMrel_catalog_alt (catalog, i, TRUE, flatcorr, &results, Nsecfilt);
     SetMrelInfoAccum (&summary, &results);
   }
@@ -384,5 +361,4 @@
 
   while (1) {
-
     off_t i = getNextCatalogForThread(threadinfo->Ncatalog);
     if (i == -1) {
@@ -394,16 +370,5 @@
     FlatCorrectionTable *flatcorr = threadinfo->flatcorr;
 
-    // pass == -1 for anything other than the final pass
-    switch (SET_MREL_VERSION) {
-      case 0:
-	setMrel_catalog (catalog, i, -1, flatcorr, &results, Nsecfilt);
-	break;
-      case 1:
-	setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
-	break;
-      default:
-	fprintf (stderr, "invalid setMrel version %d (use 0 or 1)\n", SET_MREL_VERSION);
-	exit (2);
-    }
+    setMrel_catalog_alt (catalog, i, FALSE, flatcorr, &results, Nsecfilt);
     SetMrelInfoAccum (&threadinfo->summary, &results);
   }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/args.c	(revision 38298)
@@ -331,4 +331,16 @@
   }
 
+  // if -synthphot_zpts is supplied, the map of corrections needed for the synthetic photometry is supplied
+  // and used to tie down the synthetic magnitudes
+  SYNTH_ZERO_POINTS = NULL;
+  if ((N = get_argument (argc, argv, "-synthphot_zpts"))) {
+    remove_argument (N, &argc, argv);
+    myAssert (N < argc, "missing argument to -synthphot_means");
+    SYNTH_ZERO_POINTS = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
+  // if -synthphot is chosen, an artificial w-band measurement is generated for each object 
+  // with r and i photometry.  this was used to apply the ubercal photometry to w-band images.
   SyntheticPhotometry = FALSE;
   if ((N = get_argument (argc, argv, "-synthphot"))) {
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/reload_catalogs.c	(revision 38298)
@@ -32,4 +32,7 @@
     return;
   }
+
+  // load the ZP corrections here
+  if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
 
   if (VERBOSE) fprintf (stderr, "re-loading catalog data\n");
@@ -230,4 +233,5 @@
     if (UPDATE_CATFORMAT) { snprintf (tmpline, 1024, "%s -update-catformat %s", command, UPDATE_CATFORMAT); 		          strcpy (command, tmpline); }
     if (BOUNDARY_TREE)    { snprintf (tmpline, 1024, "%s -boundary-tree %s",    command, BOUNDARY_TREE); 		          strcpy (command, tmpline); }
+    if (SYNTH_ZERO_POINTS) { snprintf (tmpline, 1024, "%s -synthphot-zpts %s", command, SYNTH_ZERO_POINTS); strcpy (command, tmpline); }
     if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION);                  strcpy (command, tmpline); }
     if (AreaSelect)       { snprintf (tmpline, 1024, "%s -area %f %f %f %f",    command, AreaXmin, AreaXmax, AreaYmin, AreaYmax); strcpy (command, tmpline); }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_objects.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_objects.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_objects.c	(revision 38298)
@@ -29,4 +29,7 @@
     return TRUE;
   }
+
+  // load the ZP corrections here
+  if (SYNTH_ZERO_POINTS) SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
 
   // load data from each region file, only use bright stars
@@ -165,4 +168,5 @@
     if (!KEEP_UBERCAL) { snprintf (tmpline, 1024, "%s -reset-ubercal",  command); 		     strcpy (command, tmpline); }
     if (SET_MREL_VERSION != 1) { snprintf (tmpline, 1024, "%s -set-mrel-version %d", command, SET_MREL_VERSION); strcpy (command, tmpline); }
+    if (SYNTH_ZERO_POINTS) { snprintf (tmpline, 1024, "%s -synthphot-zpts %s", command, SYNTH_ZERO_POINTS); strcpy (command, tmpline); }
 
     fprintf (stderr, "command: %s\n", command);
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_synthphot.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_synthphot.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/relphot_synthphot.c	(revision 38298)
@@ -28,5 +28,6 @@
 
   // load the ZP corrections here
-  SynthZeroPoints *zpts = SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
+  SynthZeroPointsLoad (SYNTH_ZERO_POINTS);
+  SynthZeroPoints *zpts = SynthZeroPointsGet ();
   if (!zpts) exit (2);
 
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38298)
@@ -4,13 +4,8 @@
 
 # define SKIP_THIS_MEAS(REASON) {			\
-    measureT[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;		\
-    if (measure) {					\
-      measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;	\
-    }							\
     results->REASON ++;					\
     continue; }
 
 # define SKIP_THIS_MEAS_STACK(REASON) {			\
-    measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;		\
     continue; }
 
@@ -57,5 +52,5 @@
     // only apply Stack operation on setMrelFinal in first pass 
     if (isSetMrelFinal && !IS_DIFF_DB) {
-      setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt, flatcorr, results);
+      setMrelAverageStack (&catalog[Nc], Nc, j, Nsecfilt, flatcorr);
     }
 
@@ -86,6 +81,4 @@
 // 4) some reference photcode of some kind can be specified as fixed and have a high weight
 
-static SynthZeroPoints *synthzpts = NULL;
-
 // set mean of chip measurements (selected by photcode range for now):
 int setMrelAverageExposure (Catalog *catalog, int cat, off_t ave, int Nsecfilt, int isSetMrelFinal, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
@@ -95,14 +88,14 @@
 
   // we are guaranteed to have averageT, but not average
-  AverageTiny *averageT = &catalog[cat].averageT[ave];
+  AverageTiny *averageT = &catalog[0].averageT[ave];
 
   off_t measureOffset = averageT->measureOffset;
-  MeasureTiny *measureT = &catalog[cat].measureT[measureOffset];
+  MeasureTiny *measureT = &catalog[0].measureT[measureOffset];
 
   // we are NOT guaranteed to have average, measure, secfilt
-  Average *average  = catalog[cat].average     ? &catalog[cat].average[ave]               : NULL;
-  Measure *measure  = catalog[cat].measure     ? &catalog[cat].measure[measureOffset]     : NULL;
-  SecFilt *secfilt  = catalog[cat].secfilt     ? &catalog[cat].secfilt[ave*Nsecfilt]      : NULL;
-  char *measureRank = catalog[cat].measureRank ? &catalog[cat].measureRank[measureOffset] : NULL;
+  Average *average  = catalog[0].average     ? &catalog[0].average[ave]               : NULL;
+  Measure *measure  = catalog[0].measure     ? &catalog[0].measure[measureOffset]     : NULL;
+  SecFilt *secfilt  = catalog[0].secfilt     ? &catalog[0].secfilt[ave*Nsecfilt]      : NULL;
+  char *measureRank = catalog[0].measureRank ? &catalog[0].measureRank[measureOffset] : NULL;
 
   // we are measuring means for 3 types of mags: psf, ap, kron.
@@ -159,5 +152,5 @@
 
     // force the use of SYN even if we have PS1 mags?
-    if (isGPC1synth(measureT[k].photcode)) {
+    if (isSetMrelFinal && isGPC1synth(measureT[k].photcode)) {
       results->haveSYN[Nsec] = TRUE;
       results->measSYN[Nsec] = k;
@@ -185,4 +178,5 @@
       Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
     } else {
+      // getMcal_alt returns image[].Mcal modified by flatcorr(image.photom_map_id,x,y)
       Mcal  = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd);
       if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
@@ -240,11 +234,7 @@
       results->psfData[Nsec].errlist[Npsf] = dMpsf;
       results->psfData[Nsec].wgtlist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
-      results->psfData[Nsec].ranking[Npsf] = measureRank[k];
+      results->psfData[Nsec].ranking[Npsf] = measureRank ? measureRank[k] : 0;
       results->psfData[Nsec].measSeq[Npsf] = k;
       results->psfData[Nsec].Nlist ++;
-    } else {
-      measureT[k].dbFlags |= ID_MEAS_SKIP_PHOTOM; // XXX is this used outside of relphot?
-      if (measure) measure[k].dbFlags |= ID_MEAS_SKIP_PHOTOM;
-      results->Nsys ++;
     }
 
@@ -264,4 +254,6 @@
     }
   }
+
+  SynthZeroPoints *synthzpts = SynthZeroPointsGet();
 
   // now calculate the mean stats for the Nsec bands.
@@ -325,10 +317,10 @@
     int minRank = (Nranking > 0) ? results->psfData[Nsec].ranking[0] : 10;
 
-    // when running -averages, we have no information about the images, so we cannot set this
-    if (results->minUbercalDist[Nsec] > -1) {
-      secfilt[Nsec].ubercalDist = results->minUbercalDist[Nsec];
-    }
-
     if (isSetMrelFinal) {
+      // when running -averages, we have no information about the images, so we cannot set this
+      if (results->minUbercalDist[Nsec] > -1) {
+	secfilt[Nsec].ubercalDist = results->minUbercalDist[Nsec];
+      }
+
       if (Nranking) {
 	secfilt[Nsec].Mstdev = psfstats->sigma;
@@ -412,379 +404,4 @@
 }
 
-# if (0)
-// set mean of chip measurements (selected by photcode range for now):
-int setMrelAverageExposure_old (off_t measureOffset, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found) {
-
-  off_t k;
-  float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
-
-  // we are measuring means for 3 types of mags: psf, ap, kron.  I am using the psf mag
-  // error for the ap mags, but krons have their own errors.  it is an open question if I
-  // should be doing weighted or unweighted fits (this is a user option)
-  double *Mpsflist  = results->Mpsflist;
-  double *dpsflist  = results->dpsflist;
-  double *wpsflist  = results->wpsflist;
-
-  double *Maplist   = results->Maplist;
-  double *daplist   = results->daplist;
-  double *waplist   = results->waplist;
-
-  double *Mkronlist = results->Mkronlist;
-  double *dkronlist = results->dkronlist;
-  double *wkronlist = results->wkronlist;
-
-  StatType *psfstats  = &results->psfstats;
-  StatType *apstats   = &results->apstats;
-  StatType *kronstats = &results->kronstats;
-
-  int isSetMrelFinal = (pass >= 0);
-
-  // option for a test print
-  if (FALSE && (average[0].objID == 0x7146) && (average[0].catID == 0x49d8)) {
-    fprintf (stderr, "test obj\n");
-    print_measure_set_alt (average, secfilt, measure);
-  }
-
-  int GoodPS1 = FALSE;
-  int Good2MASS = FALSE;
-  int Galaxy2MASS = FALSE;
-
-  int NextPS1 = 0;
-  int NpsfPS1 = 0;
-
-  int Ns;
-  for (Ns = 0; Ns < Nphotcodes; Ns++) {
-
-    int thisCode = photcodes[Ns][0].code;
-    int Nsec = GetPhotcodeNsec(thisCode);
-
-    /* calculate the average mag in this SEC photcode for a single star */
-
-    /* star/photcodes already calibrated */
-    if ( isSetMrelFinal && found[Nsec]) continue;  
-      
-    // skip bad stars
-    if (!isSetMrelFinal && (secfilt[Nsec].flags & STAR_BAD)) continue;
-
-    int NexpPS1 = 0;
-    int Ncode = 0;
-    int Next = 0;
-    int haveSynth = FALSE;
-    int havePS1   = FALSE;
-
-    int forceSynth = FALSE;
-    int forceSynthEntry = -1;
-
-    int haveUbercal = FALSE;
-
-    int minUbercalDist = 1000;
-    
-    off_t meas = measureOffset;
-
-    float psfQfMax = 0.0;
-    float psfQfPerfMax = 0.0;
-
-    int Nap = 0;
-    int Npsf = 0;
-    int Nkron = 0;
-    for (k = 0; k < averageT[0].Nmeasure; k++, meas++) {
-
-      // skip measurements that do not match the current photcode
-      PhotCode *code = GetPhotcodebyCode (measureT[k].photcode);
-      if (!code) continue;
-      if (code->equiv != thisCode) { continue; }
-      Ncode ++;
-
-      // are we a PS1 exposure photcode?
-      if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++;
-
-      // SKIP gpc1 stack data
-      if (isGPC1stack(measureT[k].photcode)) continue;
-
-      // SKIP gpc1 forced-warp data
-      if (isGPC1warp(measureT[k].photcode)) continue;
-
-      if (isSetMrelFinal) {
-	if (measure[k].psfQF     > psfQfMax)     psfQfMax     = measure[k].psfQF;
-	if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf;
-      }
-
-      if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad); 
-
-      if (getImageEntry (meas, cat) < 0) {
-	// measurements without an image are either external reference photometry or
-	// data for which the associated image has not been loaded (probably because of
-	// overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
-	Mmos = Mgrid = 0;
-	Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
-      } else {
-	Mcal  = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd);
-	if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
-	Mmos  = getMmos  (meas, cat);
-	if (isnan(Mmos))  SKIP_THIS_MEAS(Nmos);
-	Mgrid = getMgrid (meas, cat);
-	if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid);
-      }
-
-      // skip some absurd values NAN, < 0.0, > 30.0
-      Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF);
-      if (isnan(Msys)) SKIP_THIS_MEAS(Nsys);
-      if (Msys <  0.0) SKIP_THIS_MEAS(Nsys);
-      if (Msys > 30.0) SKIP_THIS_MEAS(Nsys);
-
-      int myUbercalDist = getUbercalDist(meas, cat);
-      minUbercalDist = MIN(minUbercalDist, myUbercalDist);
-
-      int isUbercal = (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL);
-      float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
-
-      if (isUbercal) haveUbercal = TRUE; // haveUbercal is set per secfilt, isUbercal is per measure
-
-      if (isSetMrelFinal) {
-	// special options for PS1 data
-	if ((measure[k].photcode >= 10000) && (measure[k].photcode <= 10500)) {
-	  // count the extended detections
-	  if (!isnan(measure[k].Map)) {
-	    float dMagAp = measure[k].M - measure[k].Map;
-	    float SigmaAp = hypot(0.1, 2.5*measure[k].dM);
-	    // XXX this is still quite ad hoc, but at least it:
-	    // (a) converges to 0.1 mag offset at the bright end
-	    // (b) converges to 0.5 mag offset at the faint end (dM = 0.2)
-	    if (dMagAp > SigmaAp) {
-	      Next ++;
-	      NextPS1 ++;
-	    } else {
-	      NpsfPS1 ++;
-	    }
-	  }
-	  havePS1 = TRUE;
-	}
-
-	// count extended detections for 2MASS (XXX NOTE hardwired photcodes 2011, 2012, 2013)
-	if ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013)) {
-	  if (measure[k].photFlags & 0x00c00000) {
-	    Next ++;
-	    Galaxy2MASS = TRUE;
-	  }
-	  if (pass == 0) {
-	    if (measure[k].photFlags & 0x00000007) {
-	      Good2MASS = TRUE;
-	    } else {
-	      // detections without one of these bits should only be used in PASS_1
-	      SKIP_THIS_MEAS(Nbad);
-	    }
-	  }
-	}
-
-	// Blindly accepth the SYNTH mags if we are above saturation, otherwise, 
-	// ignore SYNTH photcodes until PASS == 4 (where we also accept saturated stars)
-	if ((measure[k].photcode >= 3001) && (measure[k].photcode <= 3005)) {
-	  // something of a hack: force object to use synth values if synth mags >>
-	  // saturation (3pi instrumental mags < -15)
-	  float MaxMagForceSynth = NAN;
-	  switch (measure[k].photcode) {
-	    case 3001:
-	      MaxMagForceSynth = 13.64;
-	      break;
-	    case 3002:
-	      MaxMagForceSynth = 13.76;
-	      break;
-	    case 3003:
-	      MaxMagForceSynth = 13.74;
-	      break;
-	    case 3004:
-	      MaxMagForceSynth = 12.94;
-	      break;
-	    case 3005:
-	      MaxMagForceSynth = 12.01;
-	      break;
-	  }
-	  if (measureT[k].M < MaxMagForceSynth) {
-	    forceSynth = TRUE;
-	    forceSynthEntry = Npsf;
-	  } else {
-	    if (pass < 4) {
-	      SKIP_THIS_MEAS(Nbad);
-	    }
-	    haveSynth = TRUE;
-	  }
-	}
-
-	// Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter
-	float Map = PhotCat (&measure[k], MAG_CLASS_APER);
-	if (!isnan(Map)) {
-	    Maplist[Nap] = Map - Mcal - Mmos - Mgrid;
-	    daplist[Nap] = dMpsf;// XXX check on this...
-	    waplist[Nap] = isUbercal ? UBERCAL_WEIGHT : 1.0;
-	    Nap ++;
-	}
-
-	float Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
-	if (!isnan(Mkron)) {
-	  Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
-	  dkronlist[Nkron] = measure[k].dMkron;
-	  wkronlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
-	  Nkron ++;
-	}
-      } // if (isSetMrelFinal)
-
-      // dlist gives the error per measurement, wlist gives the weight
-      // we can modify the error and weight in a few ways:
-      // 1) MIN_ERROR guarantees a floor
-      // 2) photomErrSys is added in quadrature as a sytematic error, set per photcode
-      // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
-      // 4) some reference photcode of some kind can be specified as fixed and have a high weight
-      Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid;
-      dpsflist[Npsf] = dMpsf;
-      wpsflist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0;
-
-      // NOTE: 
-      // Msys is measure[i].M + zp corrections
-      // Mcal is image[j].Mcal
-      // Mmos and Mgrid are offsets for mosaic and grid
-
-      // tie down reference photometry if the -refcode (code) option is selected
-      // eg, -refcode g_SDSS
-      // this probably makes no sense in the context of multifilter analysis
-      // XXX probably need to use the photocde table to assign reference mag weights.
-      if (refPhotcode) {
-	if (code->code == refPhotcode->code) {
-	  wpsflist[Npsf] = UBERCAL_WEIGHT;
-	}
-      }
-      Npsf ++;
-    }
-
-    int Nminmeas = isSetMrelFinal ? 1 : STAR_TOOFEW + 1;
-
-    // XXX : ugh : another hard-wired photcode entry...
-    if (isSetMrelFinal && (pass == 0)) {
-      if ((thisCode < 6) || (thisCode == 9)) {
-	secfilt[Nsec].Ncode = NexpPS1; 
-      } else {
-	secfilt[Nsec].Ncode = Ncode; // 2MASS data if it exists
-      }
-    }
-
-    // when performing the grid analysis, STAR_TOOFEW should be set to 1;
-    if (Npsf < Nminmeas) { /* too few measurements */
-      // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, Npsf, STAR_TOOFEW); 
-      secfilt[Nsec].flags |= ID_STAR_FEW;
-      if (Ncode == 0) {
-	results->Ncode ++;
-      } else {
-	results->Nfew ++;
-      }
-      continue;
-    } else {
-      secfilt[Nsec].flags &= ~ID_STAR_FEW;
-    }	
-
-    if (forceSynth) {
-      // use the single SYNTH value instead of the other mags here
-      myAssert ((forceSynthEntry < Npsf) && (forceSynthEntry >= 0), "programming error");
-      Mpsflist[0] = Mpsflist[forceSynthEntry];
-      dpsflist[0] = dpsflist[forceSynthEntry];
-      wpsflist[0] = wpsflist[forceSynthEntry];
-      Npsf = 1;
-    }
-    liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats);
-
-    secfilt[Nsec].M  	 = psfstats->mean;
-    secfilt[Nsec].dM 	 = psfstats->error;
-    secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
-
-    // when running -averages, we have no information about the images, so we cannot set this
-    if (minUbercalDist > -1) {
-      secfilt[Nsec].ubercalDist = minUbercalDist;
-    }
-
-    if (isSetMrelFinal) {
-      found[Nsec] = TRUE;
-
-      secfilt[Nsec].Mstdev = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
-      // secfilt[Nsec].Ncode = Ncode;
-      secfilt[Nsec].Nused = psfstats->Nmeas;
-
-      secfilt[Nsec].Mmax = psfstats->max;
-      secfilt[Nsec].Mmin = psfstats->min;
-
-      secfilt[Nsec].psfQfMax     = psfQfMax;
-      secfilt[Nsec].psfQfPerfMax = psfQfPerfMax;
-
-      // NOTE : use the modified weight for apmags as well as psf mags
-      liststats (Maplist, daplist, waplist, Nap, apstats);
-      secfilt[Nsec].Map  = Nap > 0 ? apstats->mean : NAN; 
-      secfilt[Nsec].dMap  = Nap > 0 ? apstats->error : NAN; 
-      secfilt[Nsec].sMap  = Nap > 0 ? apstats->sigma : NAN; 
-      secfilt[Nsec].NusedAp  = Nap;
-
-      liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats);
-      secfilt[Nsec].Mkron  = Nkron > 0 ? kronstats->mean  : NAN; 
-      secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN; 
-      secfilt[Nsec].sMkron = Nkron > 0 ? kronstats->sigma : NAN; 
-      secfilt[Nsec].NusedKron  = Nkron;
-
-      // NOTE: for 2MASS measurements, Next should be 1, as should N
-      if ((Next > 0) && (Next > 0.5*Npsf)) {
-	secfilt[Nsec].flags |= ID_SECF_OBJ_EXT;
-      }
-
-      switch (pass) {
-	case 0:
-	  secfilt[Nsec].flags |= ID_PHOTOM_PASS_0;
-	  if (havePS1) GoodPS1 = TRUE;
-	  break;
-	case 1:
-	  secfilt[Nsec].flags |= ID_PHOTOM_PASS_1;
-	  if (havePS1) GoodPS1 = TRUE;
-	  break;
-	case 2:
-	  secfilt[Nsec].flags |= ID_PHOTOM_PASS_2;
-	  if (havePS1) GoodPS1 = TRUE;
-	  break;
-	case 3:
-	  secfilt[Nsec].flags |= ID_PHOTOM_PASS_3;
-	  break;
-	case 4:
-	  secfilt[Nsec].flags |= ID_PHOTOM_PASS_4;
-	  break;
-      }
-      if (haveSynth) {
-	secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;
-      }	
-      if (havePS1) {
-	secfilt[Nsec].flags |= ID_SECF_HAS_PS1;
-      }	
-      if (haveUbercal) {
-	secfilt[Nsec].flags |= ID_SECF_USE_UBERCAL;
-      }	
-    }
-  }
-
-  if (isSetMrelFinal) {
-    if (pass == 0) {
-      DVOAverageFlags flagBits = ID_OBJ_EXT | ID_OBJ_EXT_ALT | ID_OBJ_GOOD | ID_OBJ_GOOD_ALT;
-      // we attempt to set a few flags here; reset those bits before trying:
-      average[0].flags &= ~flagBits;
-    }
-
-    if (NextPS1 && (NextPS1 > NpsfPS1)) {
-      average[0].flags |= ID_OBJ_EXT;
-    }
-    if (GoodPS1) {
-      average[0].flags |= ID_OBJ_GOOD;
-    }
-    if (Galaxy2MASS) {
-      average[0].flags |= ID_OBJ_EXT_ALT;
-    }
-    if (Good2MASS) {
-      average[0].flags |= ID_OBJ_GOOD_ALT;
-    }
-  }
-  return (TRUE);
-}
-# endif
-
 // only apply Stack operation on setMrelFinal in first pass 
 // this function has 3 goals, not to be confused:
@@ -792,13 +409,13 @@
 // 2) select the BEST detections per filter (regardless of PRIMARY)
 // 3) apply the zero point and AB->Jy transformations
-int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
+int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr) {
 
   // we are guaranteed to have average, measure, secfilt
-  Average *average = &catalog[cat].average[ave];
+  Average *average = &catalog[0].average[ave];
   off_t measureOffset = average->measureOffset;
   int Nmeasure = average->Nmeasure;
 
-  Measure *measure = &catalog[cat].measure[measureOffset];
-  SecFilt *secfilt = &catalog[cat].secfilt[ave*Nsecfilt];
+  Measure *measure = &catalog[0].measure[measureOffset];
+  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
 
   off_t k;
@@ -900,5 +517,5 @@
       }
 
-      // NOTE: negative and insignificant vlues values are allowed, but not NAN flux values
+      // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
       Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF);
       if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
@@ -1028,7 +645,7 @@
 
   // we are guaranteed to have average, measure, secfilt
-  Average *average = &catalog[cat].average[ave];
-  Measure *measure = &catalog[cat].measure[measureOffset];
-  SecFilt *secfilt = &catalog[cat].secfilt[ave*Nsecfilt];
+  Average *average = &catalog[0].average[ave];
+  Measure *measure = &catalog[0].measure[measureOffset];
+  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
 
   off_t k;
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/synthetic_zpts.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/synthetic_zpts.c	(revision 38297)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/synthetic_zpts.c	(revision 38298)
@@ -7,10 +7,12 @@
 static char *extname[5] = {"map_g", "map_r", "map_i", "map_z", "map_y"};
 
-SynthZeroPoints *SynthZeroPointsLoad (char *filename) {
+static SynthZeroPoints *zpts = NULL;
+
+int SynthZeroPointsLoad (char *filename) {
 
   FILE *f = fopen (filename, "r");
   if (!f) {
     fprintf (stderr, "ERROR: cannot open file %s\n", filename);
-    return NULL;
+    return FALSE;
   }
 
@@ -23,5 +25,4 @@
   // map_y
 
-  SynthZeroPoints *zpts = NULL;
   ALLOCATE (zpts, SynthZeroPoints, 1);
   
@@ -29,5 +30,5 @@
     if (VERBOSE) fprintf (stderr, "can't read header\n");
     fclose (f);
-    return NULL;
+    return FALSE;
   }
 
@@ -49,5 +50,8 @@
   zpts->Ny = zpts->matrix[0].Naxis[1];
 
+  return TRUE;
+}
+
+SynthZeroPoints *SynthZeroPointsGet () {
   return zpts;
 }
-
