Index: trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- trunk/Ohana/src/relphot/include/relphot.h	(revision 38441)
+++ trunk/Ohana/src/relphot/include/relphot.h	(revision 38466)
@@ -96,4 +96,13 @@
 
 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
+  int    *ranking;	      // weights to use for mean mags
+  int    *measSeq;	      // weights to use for mean mags
+  int     Nlist;
+} StatDataSet;
+
+typedef struct {
   int Nfew;
   int Ncode;
@@ -105,22 +114,37 @@
 
   // 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.
+
+  int Nsecfilt;
+
+  StatDataSet  *psfData; // one is allocated for each primary (average) photcode
+  StatDataSet *aperData;
+  StatDataSet *kronData;
 
   double *psfqf_list;	      // psfqf for all filters
   double *psfqfperf_list;     // psfqfperf for all filters
   double *stargal_list;	      // stargal for all filters
+
+  int 	*havePS1;	   // this secfilt has synthetic mags
+  int 	*haveSYN;	   // this secfilt has synthetic mags
+  int 	*measSYN;	   // this measurement is the synthetic mag for this secfilt
+  int 	*needSYN;	   // this secfilt mag should use synthetic mags
+  float *minSYN;	   // minimum synthetic mag below which synthetic should be forced
+  
+  float *psfQfMax;	      // max psfQf value for this secfilt
+  float *psfQfPerfMax;	      // max psfQfperf value for this secfilt 
+
+  int *Nmeas;		      // count of PS1 exposure (chip) measurements for this secfilt
+  int *NmeasGood;	      // count of PS1 exposure (chip) measurements for this secfilt
+  int *Next;		      // count of PS1 exposure (chip) measurements for this secfilt
+  int *NexpPS1;		      // count of PS1 exposure (chip) measurements for this secfilt
+  int *haveUbercal;	      // does this secfilt have any ubercal data?
+
+  int *tessID;		      // tess,proj,skycell to use for warp and diff analysis
+  int *projID;
+  int *skycellID;
+
+  float *minUbercalDist;
 
   StatType psfstats;
@@ -375,4 +399,5 @@
 void          liststats_setmode   PROTO((StatType *stats, char *strmode));
 int           liststats           PROTO((double *value, double *dvalue, double *wvalue, int N, StatType *stats));
+int           liststats_init      PROTO((StatType *stats));
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog, int hostID, char *hostpath, char *syncfile));
 Catalog      *load_catalogs_parallel PROTO((SkyList *sky, int *Ncatalog, char *syncfile));
@@ -412,5 +437,5 @@
 int           setMrel             PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
 void          setMrelFinal        PROTO((Catalog *catalog, FlatCorrectionTable *flatcorr, int simpleAverage));
-int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, int pass, FlatCorrectionTable *flatcorr));
+int           setMrelOutput       PROTO((Catalog *catalog, int Ncatalog, FlatCorrectionTable *flatcorr));
 int           setMave             PROTO((Catalog *catalog, int Ncatalog));
 void          set_ZP              PROTO((double ZERO));
@@ -474,12 +499,18 @@
 
 int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
-int setMrel_catalog_alt (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt);
-int setMrelAverageExposure (off_t meas, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found);
-int setMrelAverageStack (off_t measureOffset, int cat, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t Nmeasure);
-int setMrelAverageForcedWarp (off_t measureOffset, int cat, int pass, SetMrelInfo *results, Average *average, SecFilt *secfilt, Measure *measure, off_t *found, off_t Nmeasure);
+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);
+int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results);
 
 int setGlobalObjStats (Average *average, Measure *measure);
 
 void SetMrelInfoInit (SetMrelInfo *results, int allocLists);
+void SetMrelInfoFree (SetMrelInfo *results);
+void SetMrelInfoReset (SetMrelInfo *results);
+void SetMrelInfoResetObject (SetMrelInfo *results);
+
+void StatDataSetFree (StatDataSet *dataset, int Nsecfilt);
+StatDataSet *StatDataSetAlloc (int Nsecfilt, int Nmax);
 
 int init_synthetic_mags ();
@@ -533,7 +564,11 @@
 int isGPC1synth (int photcode);
 int whichGPC1filter (int photcode);
-
-
-SynthZeroPoints *SynthZeroPointsLoad (char *filename);
+int is2MASS (int photcode);
+int isTYCHO (int photcode);
+
+int magStatsByRanking (StatDataSet *dataset, StatType *stats);
+
+int SynthZeroPointsLoad (char *filename);
+SynthZeroPoints *SynthZeroPointsGet ();
 
 int relphot_synthphot (int hostID, char *hostpath);
@@ -542,2 +577,7 @@
 int relphot_synthphot_catalog (Catalog *catalog, SynthZeroPoints *zpts);
 int relphot_synthphot_average (Average *average, SecFilt *secfilt, Measure *measure, SynthZeroPoints *zpts);
+
+void setMeasureRank (Catalog *catalog);
+int getImageFlags (off_t meas, int cat);
+int getMosaicFlags (off_t meas, int cat);
+
