Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/include/relphot.h	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/include/relphot.h	(revision 31273)
@@ -234,2 +234,5 @@
 int rationalize_mosaics ();
 int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
+
+int populate_tiny_values (Catalog *catalog);
+int free_tiny_values (Catalog *catalog);
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/GridOps.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/GridOps.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/GridOps.c	(revision 31273)
@@ -366,5 +366,5 @@
       mx = mlist[i][j];
       c  = clist[i][j];
-      n  = catalog[c].measure[mx].averef;
+      n  = catalog[c].measureT[mx].averef;
       
       // if we have already visited this star, skip the stuff below
@@ -393,5 +393,5 @@
 
 	// skip measurements marked as BAD
-	if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
+	if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	  Nbad ++;
 	  continue;
@@ -414,5 +414,5 @@
 	// select the color- and airmass-corrected observed magnitude for this star
 	// XXX need to be able to turn off the color-correction until initial average mags are found
-	Msys = PhotCat (&catalog[c].measure[m]);
+	Msys = PhotCatTiny (&catalog[c].measureT[m]);
 	if (isnan(Msys)) {
 	  Nsys++;
@@ -421,5 +421,5 @@
 
 	// mag-error for this measurement
-	Merr =  MAX (catalog[c].measure[m].dM, MIN_ERROR);
+	Merr =  MAX (catalog[c].measureT[m].dM, MIN_ERROR);
 
 	// Wsys = 1.0 / SQ(Merr);
@@ -550,5 +550,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
+      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	Nbad ++;
 	continue;
@@ -570,6 +570,6 @@
       }
       
-      n = catalog[c].measure[m].averef;
-      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
+      n = catalog[c].measureT[m].averef;
+      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
       if (isnan(Msys)) {
 	Nsys++;
@@ -577,5 +577,5 @@
       }
       list[N] = Msys - Mrel - Mcal - Mmos;
-      dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
+      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
       N++;
     }
@@ -637,5 +637,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
+      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	Narea ++;
 	continue;
@@ -648,6 +648,6 @@
       if (isnan(Mrel)) continue;
 
-      n = catalog[c].measure[m].averef;
-      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
+      n = catalog[c].measureT[m].averef;
+      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
 
       xlist[N] = Xmeas[c][m];
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/ImageOps.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/ImageOps.c	(revision 31273)
@@ -1,5 +1,3 @@
 # include "relphot.h"
-
-# define USE_IMAGE_ID 1
 
 static off_t       **bin;     // link from catalog,measure to image	     
@@ -12,14 +10,7 @@
 static off_t        Nimage;   // number of available images
 
-// if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted
-// index
-
-# if USE_IMAGE_ID
+// to search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted index
 static off_t        *imageIDs; // list of all image IDs
 static off_t        *imageIdx; // list of index for image IDs 
-# else
-static unsigned int *start;
-static unsigned int *stop;
-# endif
 
 Image *getimages (off_t *N) {
@@ -40,5 +31,4 @@
   Nimage = N;
 
-# if USE_IMAGE_ID
   ALLOCATE (imageIDs, off_t, Nimage);
   ALLOCATE (imageIdx, off_t, Nimage);
@@ -49,13 +39,4 @@
   }
   llsortpair (imageIDs, imageIdx, Nimage);
-# else
-  ALLOCATE (start,   unsigned, Nimage);
-  ALLOCATE (stop,    unsigned, Nimage);
-
-  for (i = 0; i < Nimage; i++) {
-    start[i] = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1);
-    stop[i]  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
-  }
-# endif
 }
 
@@ -65,5 +46,4 @@
   // use bisection to find the specified image ID
 
-# if USE_IMAGE_ID
   off_t Nlo, Nhi, N;
 
@@ -82,5 +62,4 @@
       return (imageIdx[N]);
   }
-# endif
 
   return (-1);
@@ -137,5 +116,5 @@
  for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Nmeasure; j++) {
-      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
+      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
       found = FALSE;
       for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
@@ -150,5 +129,5 @@
 }
 
-int findCCD (off_t idx, off_t meas, int cat, Measure *measure) {
+int findCCD (off_t idx, off_t meas, int cat, MeasureTiny *measure) {
 
   int ccdnum, found, Ns, ecode;
@@ -186,7 +165,7 @@
 
   // old code to add this measurement to the grid cell for this chip 
-  // ave = measure[0].averef;
-  // ra  = catalog[cat].average[ave].R - measure[0].dR / 3600.0;
-  // dec = catalog[cat].average[ave].D - measure[0].dD / 3600.0;
+  // ave = measureT[0].averef;
+  // ra  = catalog[cat].averageT[ave].R - measureT[0].dR / 3600.0;
+  // dec = catalog[cat].averageT[ave].D - measureT[0].dD / 3600.0;
   // RD_to_XY (&X, &Y, ra, dec, &image[i].coords);
 
@@ -199,12 +178,11 @@
 }
 
-# if USE_IMAGE_ID
 void matchImage (Catalog *catalog, off_t meas, int cat) {
 
   off_t idx, ID;
   int status;
-  Measure *measure;
+  MeasureTiny *measure;
   
-  measure = &catalog[cat].measure[meas];
+  measure = &catalog[cat].measureT[meas];
 
   ID = measure[0].imageID;
@@ -241,45 +219,4 @@
   return;
 }
-
-# else
-// this is the time-based match
-void matchImage (Catalog *catalog, off_t meas, int cat) {
-
-  off_t i;
-  int status;
-  Measure *measure;
-  
-  measure = &catalog[cat].measure[meas];
-  for (i = 0; i < Nimage; i++) {
-    if (image[0].photcode == -1) continue;
-    if (measure[0].photcode != image[i].photcode) continue;
-    if (measure[0].t < start[i]) continue;
-    if (measure[0].t > stop[i]) continue;
-    
-    if (USE_GRID) {
-      status = findCCD(i, meas, cat);
-      if (!status) continue;
-    }
-
-    // index for (catalog, measure) -> image
-    bin[cat][meas] = i;
-
-    // index for image, Nentry -> catalog
-    clist[i][Nlist[i]] = cat;
-
-    // index for image, Nentry -> measure
-    mlist[i][Nlist[i]] = meas;
-    Nlist[i] ++;
-
-    if (Nlist[i] == NLIST[i]) {
-      NLIST[i] += 100;
-      REALLOCATE (clist[i], off_t, NLIST[i]);
-      REALLOCATE (mlist[i], off_t, NLIST[i]);
-    }	
-    return;
-  }
-  /*  fprintf (stderr, "can't find source image for this measurement: %d (%d)\n", measure[0].t, measure[0].photcode); */
-}
-# endif
 
 off_t getImageEntry (off_t meas, int cat) {
@@ -357,5 +294,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
+      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	  Nbad++;
 	  continue;
@@ -377,6 +314,6 @@
       }
       
-      n = catalog[c].measure[m].averef;
-      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
+      n = catalog[c].measureT[m].averef;
+      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
       if (isnan(Msys)) {
 	Nsys++;
@@ -384,6 +321,6 @@
       }
       list[N] = Msys - Mrel - Mmos - Mgrid;
-      dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
-      if (catalog[c].measure[m].dM < IMFIT_SYS_SIGMA_LIM) {
+      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
+      if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
 	McalBright += list[N];
 	McalBright2 += SQ(list[N]);
@@ -650,3 +587,2 @@
   return (stats);
 }
-
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/MosaicOps.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/MosaicOps.c	(revision 31273)
@@ -272,8 +272,8 @@
     for (j = 0; j < catalog[i].Nmeasure; j++) {
       if (TimeSelect) {
-	if (catalog[i].measure[j].t < TSTART) continue;
-	if (catalog[i].measure[j].t > TSTOP) continue;
-      }
-      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
+	if (catalog[i].measureT[j].t < TSTART) continue;
+	if (catalog[i].measureT[j].t > TSTOP) continue;
+      }
+      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
       found = FALSE;
       for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
@@ -289,13 +289,10 @@
 }
 
-# if 1
-// # if USE_IMAGE_ID
-
 void matchMosaics (Catalog *catalog, off_t meas, int cat) {
 
   off_t idx, ID, mosID;
-  Measure *measure;
-
-  measure = &catalog[cat].measure[meas];
+  MeasureTiny *measure;
+
+  measure = &catalog[cat].measureT[meas];
 
   ID = measure[0].imageID;
@@ -336,45 +333,4 @@
 }
 
-# else // USE_IMAGE_ID
-
-void matchMosaics (Catalog *catalog, off_t meas, int cat) {
-
-  int i;
-
-  for (i = 0; i < Nmosaic; i++) {
-    if (catalog[cat].measure[meas].t < mosaic[i].start) continue;
-    if (catalog[cat].measure[meas].t > mosaic[i].stop) continue;
-    
-# ifdef GRID_V1
-    if (USE_GRID) {
-      ave = catalog[cat].measure[meas].averef;
-      ra  = catalog[cat].average[ave].R - catalog[cat].measure[meas].dR / 3600.0;
-      dec = catalog[cat].average[ave].D - catalog[cat].measure[meas].dD / 3600.0;
-
-      /* X,Y always positive-definite in range 0,0 - dX, dY */
-      RD_to_XY (&X, &Y, ra, dec, &mosaic[i].coords);
-      setGridMeasure (meas, cat, X, Y);
-    }
-# endif // GRID_V1
-
-    bin[cat][meas] = i;
-
-    clist[i][Nlist[i]] = cat;
-    mlist[i][Nlist[i]] = meas;
-    Nlist[i] ++;
-    
-    if (Nlist[i] == NLIST[i]) {
-      NLIST[i] += 100;
-      REALLOCATE (clist[i], int,   NLIST[i]);
-      REALLOCATE (mlist[i], off_t, NLIST[i]);
-    }	
-    return;
-  }
-  // if we miss a measurement, it might be a REF type of value 
-  if (VERBOSE2) fprintf (stderr, "missed measurement "OFF_T_FMT", %d\n", meas, cat);
-  return;
-}
-# endif // USE_IMAGE_ID
-
 float getMmos (off_t meas, int cat) {
 
@@ -437,5 +393,5 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
+      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
 	  Nbad ++;
 	  continue;
@@ -457,6 +413,6 @@
       }
       
-      n = catalog[c].measure[m].averef;
-      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
+      n = catalog[c].measureT[m].averef;
+      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
       if (isnan(Msys)) {
 	Nsys++;
@@ -464,5 +420,5 @@
       }
       list[N]  = Msys - Mrel - Mcal - Mgrid;
-      dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
+      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
       Mlist[N] = Msys;
       dMlist[N] = list[N];
@@ -580,15 +536,15 @@
       memset (starNcount[Nstars], 0, Nphotcodes*sizeof(int));
       
-      m = catalog[i].average[j].measureOffset;
+      m = catalog[i].averageT[j].measureOffset;
 
       // determine the mosaic for each measurement
-      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 
 	// skip unused measurements
-	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
+	if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
 
 	// skip unused measurements
 	int Nsec;
-	int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	found = FALSE;
 	for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) { 
@@ -914,9 +870,9 @@
       c = clist[i][j];
       
-      if (catalog[c].measure[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
-
-      ave = catalog[c].measure[m].averef;
-      xlist[N] = catalog[c].average[ave].R - catalog[c].measure[m].dR / 3600.0;
-      ylist[N] = catalog[c].average[ave].D - catalog[c].measure[m].dD / 3600.0;
+      if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
+
+      ave = catalog[c].measureT[m].averef;
+      xlist[N] = catalog[c].averageT[ave].R - catalog[c].measureT[m].dR / 3600.0;
+      ylist[N] = catalog[c].averageT[ave].D - catalog[c].measureT[m].dD / 3600.0;
       N++;
     }
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/StarOps.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/StarOps.c	(revision 31273)
@@ -18,5 +18,5 @@
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Naverage; j++) {
-      Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
+      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
     }
   }
@@ -33,6 +33,6 @@
   float value;
 
-  ave = catalog[cat].measure[meas].averef;
-  photcode = catalog[cat].measure[meas].photcode;
+  ave = catalog[cat].measureT[meas].averef;
+  photcode = catalog[cat].measureT[meas].photcode;
 
   int ecode = GetPhotcodeEquivCodebyCode (photcode);
@@ -70,13 +70,13 @@
 	// skip bad stars
 	if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
-	m = catalog[i].average[j].measureOffset;
+	m = catalog[i].averageT[j].measureOffset;
 
 	N = 0;
-	for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+	for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 	  // skip measurements that do not match the current photcode
-	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	  if (ecode != thisCode) { continue; }
 
-	  if (catalog[i].measure[m].dbFlags & MEAS_BAD) {
+	  if (catalog[i].measureT[m].dbFlags & MEAS_BAD) {
 	    Nbad ++;
 	    continue;
@@ -105,5 +105,5 @@
 	  }
 
-	  Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
+	  Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
 	  if (isnan(Msys)) {
 	    Nsys++;
@@ -111,11 +111,11 @@
 	  }
 	  list[N] = Msys - Mcal - Mmos - Mgrid;
-	  dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
+	  dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
 
 	  // tie down reference photometry if the -refcode (code) option is selected
 	  if (refPhotcode) {
-	    if (GetPhotcodeEquivCodebyCode(catalog[i].measure[m].photcode) == refPhotcode[0].equiv) {
+	    if (GetPhotcodeEquivCodebyCode(catalog[i].measureT[m].photcode) == refPhotcode[0].equiv) {
 	      // increase the weight by a factor of 100:
-	      dlist[N] = 0.01*catalog[i].measure[m].dM;
+	      dlist[N] = 0.01*catalog[i].measureT[m].dM;
 	    }
 	  }
@@ -159,5 +159,5 @@
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Naverage; j++) {
-      Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
+      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
     }
   }
@@ -176,11 +176,11 @@
 
 	N = 0;
-	m = catalog[i].average[j].measureOffset;
-	for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+	m = catalog[i].averageT[j].measureOffset;
+	for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 	  // skip measurements that do not match the current photcode
-	  ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	  ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	  if (ecode != thisCode) { continue; }
 
-	  if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
+	  if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
 
 	  // XXX allow REF stars (no Image Entry) to be included in the calculation this
@@ -198,7 +198,7 @@
 	  }
 
-	  Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
+	  Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
 	  list[N] = Msys - Mcal - Mmos - Mgrid;
-	  dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
+	  dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
 	  N++;
 	}
@@ -221,5 +221,7 @@
 }
 
-// for each average object, set the average mags based on existing equiv photometry
+// For each average object, set the average mags based on existing equiv photometry.
+// NOTE: this function operates on the real Measure & Average structures, not the
+// MeasureTiny & AverageTiny structures
 int setMave (Catalog *catalog, int Ncatalog) {
 
@@ -363,7 +365,7 @@
     for (j = 0; j < catalog[i].Naverage; j++) {
 
-      m = catalog[i].average[j].measureOffset;
-      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
-	if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
+      m = catalog[i].averageT[j].measureOffset;
+      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
+	if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
 	Mcal  = getMcal  (m, i);
 	if (isnan(Mcal)) continue;
@@ -372,4 +374,6 @@
 	Mgrid = getMgrid (m, i);
 	if (isnan(Mgrid)) continue;
+
+	// set the output calibration
 	catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid;
       }
@@ -469,5 +473,5 @@
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Naverage; j++) {
-      Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
+      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
     }
   }
@@ -498,12 +502,12 @@
 
 	/* accumulate list of valid measurements */
-	m = catalog[i].average[j].measureOffset;
+	m = catalog[i].averageT[j].measureOffset;
 	N = 0;
-	for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+	for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 	  // skip measurements that do not match the current photcode
-	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	  if (ecode != thisCode) { continue; }
 
-	  /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
+	  /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */
 	  Mcal  = getMcal  (m, i);
 	  if (isnan(Mcal)) { Ncal ++; continue; }
@@ -513,7 +517,7 @@
 	  if (isnan(Mgrid)) { Ngrid ++; continue; }
 
-	  Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
+	  Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
 	  list[N] = Msys - Mcal - Mmos - Mgrid;
-	  dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
+	  dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
 	  N++;
 	}
@@ -542,12 +546,12 @@
 	image_bad = IMAGE_BAD;
 	IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
-	m = catalog[i].average[j].measureOffset;
+	m = catalog[i].averageT[j].measureOffset;
 	N = 0;
-	for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+	for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 	  // skip measurements that do not match the current photcode
-	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	  int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	  if (ecode != thisCode) { continue; }
 
-	  /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
+	  /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */
 	  Mcal  = getMcal  (m, i);
 	  if (isnan(Mcal)) continue;
@@ -557,7 +561,7 @@
 	  if (isnan(Mgrid)) continue;
 
-	  Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
+	  Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
 	  list[N] = Msys - Mcal - Mmos - Mgrid;
-	  dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
+	  dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
 	  ilist[N] = m;
 	  N++;
@@ -569,5 +573,9 @@
 	for (k = 0; k < N; k++) {
 	  if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) {
-	    catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
+	    catalog[i].measureT[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
+	    if (final) {
+	      // for the final pass, we have a duplicate set of values in measure and measureT
+	      catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
+	    }
 	    Ndel ++;
 	  }
@@ -609,9 +617,9 @@
       /* calculate the average value for a single star */
       if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) { N1++; continue;  }
-      m = catalog[i].average[j].measureOffset;
+      m = catalog[i].averageT[j].measureOffset;
 
       N = 0;
-      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
-	int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
+	int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	if (ecode != seccode) { N0++; continue;}
 	Mcal = getMcal  (m, i);
@@ -816,6 +824,6 @@
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Naverage; j++) {
-      xlist[N] = catalog[i].average[j].R;
-      ylist[N] = catalog[i].average[j].D;
+      xlist[N] = catalog[i].averageT[j].R;
+      ylist[N] = catalog[i].averageT[j].D;
       N++;
     }
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/bcatalog.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/bcatalog.c	(revision 31273)
@@ -2,4 +2,37 @@
 
 extern double drand48();
+
+int CopyAverageTiny (AverageTiny *averageT, Average *average) {
+
+  averageT[0].R     = average[0].R;
+  averageT[0].D     = average[0].D;
+  averageT[0].flags = average[0].flags;
+  averageT[0].Nmeasure      = average[0].Nmeasure;
+  averageT[0].measureOffset = average[0].measureOffset;
+
+  // make Nmeasure & measureOffset optional?
+
+  return (TRUE);
+}
+
+int CopyMeasureTiny (MeasureTiny *measureT, Measure *measure) {
+
+  measureT[0].dR       = measure[0].dR;
+  measureT[0].dD       = measure[0].dD;
+  measureT[0].M        = measure[0].M;
+  measureT[0].Mcal     = measure[0].Mcal;
+  measureT[0].dM       = measure[0].dM;
+  measureT[0].airmass  = measure[0].airmass;
+  measureT[0].Xccd     = measure[0].Xccd;
+  measureT[0].Yccd     = measure[0].Yccd;
+  measureT[0].t        = measure[0].t;
+  measureT[0].dt       = measure[0].dt;
+  measureT[0].averef   = measure[0].averef;
+  measureT[0].imageID  = measure[0].imageID;
+  measureT[0].dbFlags  = measure[0].dbFlags;
+  measureT[0].photcode = measure[0].photcode;
+
+  return (TRUE);
+}
 
 int bcatalog (Catalog *subcatalog, Catalog *catalog) {
@@ -18,7 +51,7 @@
   NAVERAGE = 50;
   NMEASURE = 1000;
-  ALLOCATE (subcatalog[0].average, Average, NAVERAGE);
+  ALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
+  ALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE);
   ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
-  ALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
   Nmeasure = Naverage = 0;
 
@@ -30,6 +63,7 @@
 
     /* start with all stars good */
-    subcatalog[0].average[Naverage] = catalog[0].average[i];
-    subcatalog[0].average[Naverage].measureOffset = Nmeasure;
+    CopyAverageTiny (&subcatalog[0].averageT[Naverage], &catalog[0].average[i]);
+    subcatalog[0].averageT[Naverage].measureOffset = Nmeasure;
+
     for (j = 0; j < Nsecfilt; j++) {
       subcatalog[0].secfilt[Nsecfilt*Naverage+j] = catalog[0].secfilt[Nsecfilt*i+j];
@@ -103,13 +137,13 @@
       }
 
-      subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
-      subcatalog[0].measure[Nmeasure]        = catalog[0].measure[offset];
-      subcatalog[0].measure[Nmeasure].averef = Naverage;
+      CopyMeasureTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
+      subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
+      subcatalog[0].measureT[Nmeasure].averef = Naverage;
       if (RESET) { 
-	subcatalog[0].measure[Nmeasure].Mcal = 0;
-	subcatalog[0].measure[Nmeasure].dbFlags &= 0xff00;
-	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
-	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
-	subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
+	subcatalog[0].measureT[Nmeasure].Mcal = 0;
+	subcatalog[0].measureT[Nmeasure].dbFlags &= 0xff00;
+	subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
+	subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
+	subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
       }
       Nmeasure ++;
@@ -117,5 +151,5 @@
       if (Nmeasure == NMEASURE) {
 	NMEASURE += 1000;
-	REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
+	REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
       }
     }
@@ -134,14 +168,14 @@
       continue; 
     }
-    subcatalog[0].average[Naverage].Nmeasure = Nm;
+    subcatalog[0].averageT[Naverage].Nmeasure = Nm;
     Naverage ++;
     if (Naverage == NAVERAGE) {
       NAVERAGE += 50;
-      REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
-      REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
-    }
-  }
-  REALLOCATE (subcatalog[0].average, Average, MAX (Naverage, 1));
-  REALLOCATE (subcatalog[0].measure, Measure, MAX (Nmeasure, 1));
+      REALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE);
+      REALLOCATE (subcatalog[0].secfilt,  SecFilt,     NAVERAGE*Nsecfilt);
+    }
+  }
+  REALLOCATE (subcatalog[0].averageT, AverageTiny, MAX (Naverage, 1));
+  REALLOCATE (subcatalog[0].measureT, MeasureTiny, MAX (Nmeasure, 1));
   REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1));
   subcatalog[0].Naverage = Naverage;
@@ -211,11 +245,11 @@
   for (i = 0; i < Nmax; i++) {
     ave = index[i];
-    NMEASURE += subcatalog[0].average[ave].Nmeasure;
+    NMEASURE += subcatalog[0].averageT[ave].Nmeasure;
   }
 
   // allocate the output data 
-  ALLOCATE (tmpcatalog.average, Average, Nmax);
-  ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt);
-  ALLOCATE (tmpcatalog.measure, Measure, NMEASURE);
+  ALLOCATE (tmpcatalog.averageT, AverageTiny, Nmax);
+  ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE);
+  ALLOCATE (tmpcatalog.secfilt,  SecFilt, Nmax * Nsecfilt);
 
   off_t Nmeasure = 0;
@@ -224,10 +258,10 @@
   for (i = 0; i < Nmax; i++) {
     ave = index[i];
-    tmpcatalog.average[i] = subcatalog[0].average[ave];
-    tmpcatalog.average[i].measureOffset = Nmeasure;
-    for (j = 0; j < tmpcatalog.average[i].Nmeasure; j++) {
-      off_t offset = subcatalog[0].average[ave].measureOffset + j;
-      tmpcatalog.measure[Nmeasure] = subcatalog[0].measure[offset];
-      tmpcatalog.measure[Nmeasure].averef = i;
+    tmpcatalog.averageT[i] = subcatalog[0].averageT[ave];
+    tmpcatalog.averageT[i].measureOffset = Nmeasure;
+    for (j = 0; j < tmpcatalog.averageT[i].Nmeasure; j++) {
+      off_t offset = subcatalog[0].averageT[ave].measureOffset + j;
+      tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset];
+      tmpcatalog.measureT[Nmeasure].averef = i;
       Nmeasure ++;
     }
@@ -239,10 +273,10 @@
   }
 
-  free (subcatalog[0].average);
-  free (subcatalog[0].measure);
+  free (subcatalog[0].averageT);
+  free (subcatalog[0].measureT);
   free (subcatalog[0].secfilt);
 
-  subcatalog[0].average = tmpcatalog.average;
-  subcatalog[0].measure = tmpcatalog.measure;
+  subcatalog[0].averageT = tmpcatalog.averageT;
+  subcatalog[0].measureT = tmpcatalog.measureT;
   subcatalog[0].secfilt = tmpcatalog.secfilt;
   subcatalog[0].Naverage = Nmax;
@@ -253,2 +287,29 @@
   return (TRUE);
 }
+
+// for the cases where we are not using a subset of the data, we still need to have a copy of these fields
+int populate_tiny_values (Catalog *catalog) {
+
+  off_t i;
+
+  ALLOCATE (catalog[0].measureT, MeasureTiny, catalog[0].Nmeasure);
+  ALLOCATE (catalog[0].averageT, AverageTiny, catalog[0].Naverage);
+
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    CopyAverageTiny (&catalog[0].averageT[i], &catalog[0].average[i]);
+  }
+
+  for (i = 0; i < catalog[0].Nmeasure; i++) {
+    CopyMeasureTiny (&catalog[0].measureT[i], &catalog[0].measure[i]);
+  }
+
+  return (TRUE);
+}
+
+int free_tiny_values (Catalog *catalog) {
+
+  free (catalog[0].averageT);
+  free (catalog[0].measureT);
+  return (TRUE);
+}
+
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/plot_scatter.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/plot_scatter.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/plot_scatter.c	(revision 31273)
@@ -36,8 +36,8 @@
 	    for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
 		// skip measurements that do not match the current photcode
-		int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+		int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 		if (ecode != thisCode) { continue; }
 
-		if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
+		if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
 		Mcal = getMcal  (m, i);
 		if (isnan(Mcal)) continue;
@@ -49,6 +49,6 @@
 		Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
 		xlist[N] = Mrel;
-		ylist[N] = PhotSys  (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel;
-		ilist[N] = PhotInst (&catalog[i].measure[m]);
+		ylist[N] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel;
+		ilist[N] = PhotInstTiny (&catalog[i].measureT[m]);
 		N++;
 	    }
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/reload_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/reload_catalogs.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/reload_catalogs.c	(revision 31273)
@@ -49,11 +49,13 @@
     TIMESTAMP(time2);
 
+    populate_tiny_values(&catalog);
+
     initImageBins  (&catalog, 1);
     initMosaicBins (&catalog, 1);
-    initGridBins   (&catalog, 1);
+    initGridBins   (&catalog, 1); 
     TIMESTAMP(time3);
 
-    findImages (&catalog, 1);
-    findMosaics (&catalog, 1);
+    findImages (&catalog, 1);  // FX
+    findMosaics (&catalog, 1); // 
     TIMESTAMP(time4);
 
@@ -63,4 +65,6 @@
     dvo_catalog_save (&catalog, VERBOSE); 
     dvo_catalog_unlock (&catalog);
+
+    free_tiny_values(&catalog);
     dvo_catalog_free (&catalog);
     TIMESTAMP(time6);
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/relphot.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/relphot.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/relphot.c	(revision 31273)
@@ -94,22 +94,4 @@
       int star_toofew;
 
-# if (USE_DIRECT)
-      // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW
-      // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel
-      star_toofew = STAR_TOOFEW;
-      STAR_TOOFEW = 0;
-      STAR_BAD  = ID_STAR_POOR;
-
-      showGridCount ();
-      setMgridDirect (catalog, Ncatalog);
-
-      STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
-      STAR_TOOFEW = star_toofew;
-
-      dump_grid ();
-      exit (0);
-
-# else
-
       // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW
       // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel
@@ -124,5 +106,4 @@
       STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
       STAR_TOOFEW = star_toofew;
-# endif
   }
 
@@ -175,5 +156,8 @@
 
   /* at this point, we have correct cal coeffs in the image/mosaic structures */
-  for (i = 0; i < Ncatalog; i++) dvo_catalog_free (&catalog[i]);
+  for (i = 0; i < Ncatalog; i++) {
+    free_tiny_values (&catalog[i]);
+    dvo_catalog_free (&catalog[i]);
+  }
   freeImageBins (Ncatalog);
   freeMosaicBins (Ncatalog);
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setExclusions.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setExclusions.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setExclusions.c	(revision 31273)
@@ -1,3 +1,8 @@
 # include "relphot.h"
+
+// this function sets the NOCAL and AREA dbFlags bits for the MeasureTiny elements these
+// are used elsewhere (StarOps.c, ImageOps.c, MosaicOps.c, GridOps.c, etc) to skip bad
+// measurements.  The only exception is 'setMave' which is called by 'relphot_objects',
+// and uses the bits read from disk as the test
 
 int setExclusions (Catalog *catalog, int Ncatalog) {
@@ -11,9 +16,9 @@
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Naverage; j++) {
-      m = catalog[i].average[j].measureOffset;
-      for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
+      m = catalog[i].averageT[j].measureOffset;
+      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
 
 	/* select measurements by photcode */
-	ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
 	found = FALSE;
 	for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
@@ -24,12 +29,12 @@
 	/* select measurements by time */
 	if (TimeSelect) {
-	  if (catalog[i].measure[m].t < TSTART) goto mark_nocal;
-	  if (catalog[i].measure[m].t > TSTOP) goto mark_nocal;
+	  if (catalog[i].measureT[m].t < TSTART) goto mark_nocal;
+	  if (catalog[i].measureT[m].t > TSTOP) goto mark_nocal;
 	}
 
 	/* select measurements by mag limit */
 	if (AreaSelect) {
-	  r = catalog[i].average[j].R + catalog[i].measure[m].dR / 3600.0;
-	  d = catalog[i].average[j].D + catalog[i].measure[m].dD / 3600.0;
+	  r = catalog[i].averageT[j].R + catalog[i].measureT[m].dR / 3600.0;
+	  d = catalog[i].averageT[j].D + catalog[i].measureT[m].dD / 3600.0;
 	  if ((coords = getCoords (m, i)) == NULL) goto markbad;
 	  RD_to_XY (&x, &y, r, d, coords);
@@ -43,10 +48,10 @@
 
       markbad:
-	catalog[i].measure[m].dbFlags |= ID_MEAS_AREA;
+	catalog[i].measureT[m].dbFlags |= ID_MEAS_AREA;
 	Narea ++;
 	continue;
 	
       mark_nocal:
-	catalog[i].measure[m].dbFlags |= ID_MEAS_NOCAL;
+	catalog[i].measureT[m].dbFlags |= ID_MEAS_NOCAL;
 	Nnocal ++;
 	continue;
Index: /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setMrelFinal.c	(revision 31272)
+++ /branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setMrelFinal.c	(revision 31273)
@@ -1,3 +1,7 @@
 # include "relphot.h"
+
+// we've just reloaded the data from disk; we now need to apply the Image/Mosaic/Grid
+// calibrations determined by the rest of the program.  We also need to set the final
+// output dbFlags values
 
 void setMrelFinal (Catalog *catalog) {
@@ -46,4 +50,5 @@
   }
 
+  // this sets flags in the measureT element, not the measure element
   setExclusions (catalog, 1);  /* mark by area */
 
@@ -64,5 +69,6 @@
   int Nsecfilt = GetPhotcodeNsecfilt ();
 
-  /* clear ID_STAR_POOR, ID_STAR_FEW, ID_MEAS_NOCAL values before writing ??? */
+  /* clear ID_STAR_POOR, ID_STAR_FEW values before writing ??? */
+  /* ID_MEAS_NOCAL is an internal bit, so it should be cleared */
   for (i = 0; i < catalog[0].Naverage; i++) {
     catalog[0].average[i].flags &= ~ID_STAR_FEW;
@@ -105,5 +111,5 @@
 
       /* clear SKIP for all measures at first */
-      catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
+      catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
 
       /** never use these measurements (wrong photcode, bad time range) */
@@ -153,5 +159,6 @@
 
     skip:
-      catalog[0].measure[m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
+      catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
+      catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
       Nskip ++;
     }
