Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38291)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/include/relphot.h	(revision 38292)
@@ -96,4 +96,10 @@
 
 typedef struct {
+  double *flxlist;           // list of measure.mag values for a given star
+  double *errlist;	      // mag errors for a star
+  double *wgtlist;	      // weights to use for mean mags
+} StatDataSet;
+
+typedef struct {
   int Nfew;
   int Ncode;
@@ -105,18 +111,10 @@
 
   // NOTE: the following arrays are (possibly) pre-allocated and carried down to each
-  // thread.  The first 3 (list, dlist, wlist) are used in all relphot analyses; the
-  // others are only used on the final output steps.
-
-  double *Mpsflist;           // list of measure.mag values for a given star
-  double *dpsflist;	      // mag errors for a star
-  double *wpsflist;	      // weights to use for mean mags
-
-  double *Maplist;	      // ap mags for a star
-  double *daplist;	      // ap mags for a star
-  double *waplist;	      // ap mags for a star
-
-  double *Mkronlist;	      // kron mags for a star
-  double *dkronlist;	      // kron mag errors 
-  double *wkronlist;	      // kron mag errors 
+  // thread.  The psfData are used in all relphot analyses; the others are only used on
+  // the final output steps.
+
+  StatDataSet  *psfData; // one is allocated for each primary (average) photcode
+  StatDataSet *aperData;
+  StatDataSet *kronData;
 
   double *psfqf_list;	      // psfqf for all filters
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38291)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/StarOps.c	(revision 38292)
@@ -1,5 +1,3 @@
 # include "relphot.h"
-
-static int Nmax;
 
 enum {THREAD_RUN, THREAD_DONE};
@@ -20,6 +18,8 @@
 int print_measure_set (Average *average, SecFilt *secfilt, Measure *measure);
 
-// we want to allocate the stats list,dlist arrays only once (or once per thread).
-// this function finds the largest array so we can allocate that max size when needed
+// we want to allocate the StatDataSet arrays only once (or once per thread).  this
+// function finds the largest value of Nmeasure so we can allocate that max size when
+// needed
+static int Nmax; 
 void initMrel (Catalog *catalog, int Ncatalog) {
 
@@ -54,5 +54,31 @@
 }
 
-void SetMrelInfoInit (SetMrelInfo *results, int allocLists) {
+StatDataSet *StatDataSetAlloc (int Nsecfilt, int Nmax) {
+
+  int i;
+
+  StatDataSet *dataset = NULL;
+  ALLOCATE (dataset, StatDataSet, Nsecfilt);
+  for (i = 0; i < Nsecfilt; i++) {
+    ALLOCATE (dataset[i].flxlist, double, Nmax);
+    ALLOCATE (dataset[i].wgtlist, double, Nmax);
+    ALLOCATE (dataset[i].errlist, double, Nmax);
+  }  
+  return dataset;
+}
+
+void StatDataSetFree (StatDataSet *, int Nsecfilt) {
+
+  int i;
+
+  for (i = 0; i < Nsecfilt; i++) {
+    FREE (dataset[i].flxlist);
+    FREE (dataset[i].wgtlist);
+    FREE (dataset[i].errlist);
+  }  
+  FREE (dataset);
+}
+
+void SetMrelInfoReset (SetMrelInfo *results) {
   results->Nfew  = 0;
   results->Ncode  = 0;
@@ -62,15 +88,34 @@
   results->Nmos  = 0;
   results->Ngrid = 0;
+}
+
+void SetMrelInfoInit (SetMrelInfo *results, int allocLists) {
+  SetMrelInfoReset (results);
   if (allocLists) {
-    ALLOCATE (results->Mpsflist, double, Nmax);
-    ALLOCATE (results->dpsflist, double, Nmax);
-    ALLOCATE (results->wpsflist, double, Nmax);
+    results->Nsecfilt = GetPhotcodeNsecfilt ();
+    results->psfData  = StatDataSetAlloc (results->Nsecfilt, Nmax);
+    results->aperData = StatDataSetAlloc (results->Nsecfilt, Nmax);
+    results->kronData = StatDataSetAlloc (results->Nsecfilt, Nmax);
+    ALLOCATE (results->psfqf_list,     double, Nmax);
+    ALLOCATE (results->psfqfperf_list, double, Nmax);
+    ALLOCATE (results->stargal_list,   double, Nmax);
+  } else {
+    results->Nsecfilt = 0;
+    results->psfData  = NULL;
+    results->aperData = NULL;
+    results->kronData = NULL;
+    results->psfqf_list     = NULL;
+    results->psfqfperf_list = NULL;
+    results->stargal_list   = NULL;
   }
 }
 
 void SetMrelInfoFree (SetMrelInfo *results) {
-  free (results->Mpsflist);
-  free (results->dpsflist);
-  free (results->wpsflist);
+  StatDataSetFree (results->psfdata,  results->Nsecfilt);
+  StatDataSetFree (results->aperdata, results->Nsecfilt);
+  StatDataSetFree (results->krondata, results->Nsecfilt);
+  FREE (results.psfqf_list);
+  FREE (results.psfqfperf_list);
+  FREE (results.stargal_list);
 }
 
@@ -162,16 +207,4 @@
   SetMrelInfoInit (&results, TRUE); // allocates results->list,dlist,wlist
 
-  ALLOCATE (results.Maplist,  double, Nmax);
-  ALLOCATE (results.daplist,  double, Nmax);
-  ALLOCATE (results.waplist,  double, Nmax);
-
-  ALLOCATE (results.Mkronlist, double, Nmax);
-  ALLOCATE (results.dkronlist, double, Nmax);
-  ALLOCATE (results.wkronlist, double, Nmax);
-
-  ALLOCATE (results.psfqf_list, double, Nmax);
-  ALLOCATE (results.psfqfperf_list, double, Nmax);
-  ALLOCATE (results.stargal_list, double, Nmax);
-
   for (i = 0; i < Ncatalog; i++) {
     switch (SET_MREL_VERSION) {
@@ -191,15 +224,4 @@
 
   SetMrelInfoFree (&results);
-  free (results.Maplist);
-  free (results.daplist);
-  free (results.waplist);
-
-  free (results.Mkronlist);
-  free (results.dkronlist);
-  free (results.wkronlist);
-
-  free (results.psfqf_list);
-  free (results.psfqfperf_list);
-  free (results.stargal_list);
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38291)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c	(revision 38292)
@@ -40,16 +40,11 @@
   off_t j;
 
-  liststats_setmode (&results->psfstats, STATMODE);
-  liststats_setmode (&results->apstats, STATMODE);
+  liststats_setmode (&results->psfstats,  STATMODE);
+  liststats_setmode (&results->apstats,   STATMODE);
   liststats_setmode (&results->kronstats, STATMODE);
 
-  SetMrelInfoInit (results, FALSE); // do not allocate list,dlist,wlist arrays
+  SetMrelInfoReset (results); // reset the countesrs
 
   int isSetMrelFinal = (pass >= 0);
-
-  // XX char *primaryCell = NULL;
-  // XX if (isSetMrelFinal) {
-  // XX   ALLOCATE (primaryCell, char, DVO_MAX_PATH);
-  // XX }
 
   for (j = 0; j < catalog[Nc].Naverage; j++) {
