Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/Makefile	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/Makefile	(revision 36990)
@@ -34,4 +34,5 @@
 $(SRC)/args.$(ARCH).o		 \
 $(SRC)/help.$(ARCH).o		 \
+$(SRC)/extra.$(ARCH).o		 \
 $(SRC)/bcatalog.$(ARCH).o	 \
 $(SRC)/global_stats.$(ARCH).o	 \
@@ -82,4 +83,5 @@
 $(SRC)/args.$(ARCH).o		 \
 $(SRC)/help.$(ARCH).o		 \
+$(SRC)/extra.$(ARCH).o		 \
 $(SRC)/synthetic_mags.$(ARCH).o	 \
 $(SRC)/plotstuff.$(ARCH).o	 \
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/doc/mosaic.txt
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/doc/mosaic.txt	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/doc/mosaic.txt	(revision 36990)
@@ -1,2 +1,26 @@
+
+
+2014.07.09
+
+* trying to make sense of mosaic.Mcal vs image.Mcal in the context of UBERCAL:
+
+  * relphot_images:
+    * load_images (convert raw FITS table to Image structure, select subset matching selection)
+      * initMosaics (associate mosaics to images (gpc1 photcodes only))
+      	* initMosaicGrid (define spatial range of mosaics [only used by grid analysis]; set Mcal to <image.Mcal> and image.Mcal to 0.0)
+    --- calculate image or mosaic Mcal values
+    * setMcalFinal (set image.Mcal = mosaicMcal)
+
+  * relphot_parallel_regions:
+    * assign_images
+      * makeMosaics (equivalent to initMosaics, but works on full image table, not subset)
+      * setMosaicCenters (set Mcal to <image.Mcal> and image.Mcal to 0.0) <--- this is wrong!
+      (sends images ONLY, not mosaics, to remote machines)
+      (slurps back new image values, applies to db)
+      
+  * relphot_parallel_images:
+    * makeMosaics (associate mosaics to images, gpc1 photcodes only)
+      * initMosaicGrid (needed in this one)
+---
 
 For 'mosaic' zero points, I define the mosaics by grouping the images
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/include/relphot.h	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/include/relphot.h	(revision 36990)
@@ -48,5 +48,5 @@
   float dMsys;
   unsigned short nFitPhotom;
-  float Xm;
+  short Xm;
   float secz;
   float ubercalDist;
@@ -317,5 +317,5 @@
 int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
 
-void makeMosaics (Image *image, off_t Nimage);
+void makeMosaics (Image *image, off_t Nimage, int mergeMcal);
 Mosaic *getMosaicForImage (off_t im);
 void setMosaicCenters (Image *image, off_t Nimage);
@@ -509,2 +509,9 @@
 int relphot_parallel_images ();
 int relphot_parallel_regions ();
+
+// in extra.c
+int isGPC1chip  (int photcode);
+int isGPC1stack (int photcode);
+int isGPC1warp  (int photcode);
+
+
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/ImageOps.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/ImageOps.c	(revision 36990)
@@ -532,7 +532,4 @@
 
   // FREEZE_IMAGES only applies to mosaic data (eg, gpc1)
-  // skip this function if photcode is gpc1 and FREEZE_IMAGES
-  // otherwise, allow image to be calibrated
-  // if (FREEZE_IMAGES) return;
 
   fprintf (stderr, "limiting negative clouds to %f\n", CLOUD_TOLERANCE);
@@ -565,6 +562,5 @@
     }      
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     // UBERCAL image: if this is an ubercal image, set minUbercalDist to 0:
@@ -713,6 +709,5 @@
     if (image[i].flags & IMAGE_BAD) continue;
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     mlist[N] = image[i].Mcal;
@@ -825,6 +820,5 @@
   for (i = 0; i < Nimage; i++) {
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     Mlist[Nplot] = image[i].Mcal;
@@ -873,6 +867,6 @@
 
   for (i = 0; i < Nimage; i++) {
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
+
     bin = image[i].dMcal / 0.00025;
     bin = MAX (0, MIN (NBIN - 1, bin));
@@ -910,6 +904,5 @@
     if (image[i].flags & IMAGE_BAD)  continue;
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     N = 0;
@@ -957,6 +950,5 @@
     if (image[i].flags & IMAGE_BAD)  continue;
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     list[n] = pow (10.0, 0.01*image[i].Xm);
@@ -990,6 +982,5 @@
     if (image[i].flags & IMAGE_BAD)  continue;
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     list[n] = image[i].Mcal;
@@ -1023,6 +1014,5 @@
     if (image[i].flags & IMAGE_BAD)  continue;
 
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (FREEZE_IMAGES && isGPC1cam) continue;
+    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
 
     list[n] = image[i].dMcal;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/MosaicOps.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/MosaicOps.c	(revision 36990)
@@ -1,4 +1,5 @@
 # include "relphot.h"
 void plot_setMcal (double *list, int Npts, StatType *stats, float clouds);
+off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
 
 // see discussion in ImagesOps.c re: IDX_T
@@ -36,4 +37,18 @@
 // MosaicN_image was 'Nimlist'
 // MosaicToImage was 'imlist'
+
+void sort_times (unsigned int *T, int N) {
+
+# define SWAPFUNC(A,B){ unsigned int tmp; \
+  tmp = T[A]; T[A] = T[B]; T[B] = tmp; \
+}
+# define COMPARE(A,B)(T[A] < T[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
 
 /* find mosaic frames (unique time periods & photcode name matches mosaic) */
@@ -136,20 +151,4 @@
 }
 
-off_t findMosaic (unsigned int *startTimes, off_t Nmosaic, unsigned int start);
-
-void sort_times (unsigned int *T, int N) {
-
-# define SWAPFUNC(A,B){ unsigned int tmp; \
-  tmp = T[A]; T[A] = T[B]; T[B] = tmp; \
-}
-# define COMPARE(A,B)(T[A] < T[B])
-
-  OHANA_SORT (N, COMPARE, SWAPFUNC);
-
-# undef SWAPFUNC
-# undef COMPARE
-
-}
-
 /* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes...)
    this function will also identify the images NOT in the subset which belong to a selected mosaic
@@ -157,7 +156,6 @@
 void initMosaics (Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage) {
 
-  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
+  off_t i, j, found, NMOSAIC, *MosaicN_IMAGE;
   unsigned int start, stop, *startTimes, *startTimesMosaic;
-  char *pname;
 
   if (!MOSAIC_ZEROPT) return;
@@ -174,8 +172,5 @@
   int Nmoschip = 0;
   for (i = 0; i < Nsubset; i++) {
-    int isGPC1cam = ((subset[i].photcode >= 10000) && (subset[i].photcode <= 10500));
-    if (!isGPC1cam) {
-      continue;
-    }
+    if (!isGPC1chip(subset[i].photcode)) continue;
     startTimes[Nmoschip] = subset[i].tzero;
     Nmoschip ++;
@@ -191,8 +186,5 @@
   // generate a list of the unique start times (these define the mosaics)
   for (i = 0; i < Nmoschip; i++) {
-    if (startTimes[i] < startTimesMosaic[Nmosaic]) {
-      fprintf (stderr, "error?\n");
-      abort();
-    }
+    myAssert (startTimes[i] >= startTimesMosaic[Nmosaic], "times out of order?");
     if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
     Nmosaic ++;
@@ -221,5 +213,5 @@
     mosaic[i].dMcal    = 0.0;
     mosaic[i].dMsys    = 0.0;
-    mosaic[i].Xm   = 0.0;
+    mosaic[i].Xm       = 0.0;
     mosaic[i].flags    = 0;
     mosaic[i].secz     = NAN;
@@ -244,18 +236,5 @@
     }
     
-    // this is gpc1-specific.  needs a more general solution
-    int isGPC1cam = ((image[i].photcode >= 10000) && (image[i].photcode <= 10500));
-    if (!isGPC1cam) {
-      continue;
-    }
-
-    if (0) {
-      // XXX this version fails if we have stack and fforce data: GPC1.g.SkyChip
-      /* select valid mosaic images by photcode */
-      pname = GetPhotcodeNamebyCode (image[i].photcode);
-      if (!pname) continue;
-      status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
-      if (status) continue;
-    }
+    if (!isGPC1chip(image[i].photcode)) continue;
 
     /* set image time range */
@@ -281,17 +260,7 @@
     ImageToMosaic[i] = -1;
 
-    // this is gpc1-specific.  needs a more general solution
-    int isGPC1cam = ((subset[i].photcode >= 10000) && (subset[i].photcode <= 10500));
-    if (!isGPC1cam) {
+    if (!isGPC1chip(subset[i].photcode)) {
       Nsimple ++;
       continue;
-    }
-
-    if (0) {
-      // XXX this version fails if we have stack and fforce data: GPC1.g.SkyChip
-      /* select valid mosaic images by photcode */
-      pname = GetPhotcodeNamebyCode (subset[i].photcode);
-      status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
-      if (status) continue;
     }
 
@@ -325,11 +294,11 @@
       abort();
     }
-    mosaic[j].stop  = stop;
-    mosaic[j].Mcal  = 0.0;
-    mosaic[j].dMcal = 0.0;
-    mosaic[j].Xm = 0.0;
-    mosaic[j].dMsys = subset[i].flags;
-    mosaic[j].flags = subset[i].flags;
-    mosaic[j].secz  = subset[i].secz;
+    mosaic[j].stop     = stop;
+    mosaic[j].Mcal     = 0.0;
+    mosaic[j].dMcal    = 0.0;
+    mosaic[j].Xm       = 0.0;
+    mosaic[j].dMsys    = subset[i].flags;
+    mosaic[j].flags    = subset[i].flags;
+    mosaic[j].secz     = subset[i].secz;
     mosaic[j].photcode = GetPhotcodeEquivCodebyCode (subset[i].photcode);
   }
@@ -346,13 +315,11 @@
 }
 
-/* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes but we 
-   match images by MOSAICNAME.  this last point is weak: it forces a single camera at a time.
-   we can extend the logic to multiple cameras if we make list of MOSAICNAMES (better to assign a camera ID)
+/* find mosaic frames (unique time periods) (NOTE : require gpc1 chips, which is pretty limiting)
+   if mergeMcal is TRUE, <image.Mcal> values will be saved on Mosaic.Mcal
  */
-void makeMosaics (Image *image, off_t Nimage) {
-
-  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
+void makeMosaics (Image *image, off_t Nimage, int mergeMcal) {
+
+  off_t i, j, found, NMOSAIC, *MosaicN_IMAGE;
   unsigned int start, stop, *startTimes, *startTimesMosaic;
-  char *pname;
 
   if (!MOSAIC_ZEROPT) return;
@@ -367,8 +334,11 @@
   // generate a list of all image start times
   ALLOCATE (startTimes, unsigned int, Nimage);
+  int Nmoschip = 0;
   for (i = 0; i < Nimage; i++) {
-    startTimes[i] = image[i].tzero;
-  }
-  sort_times (startTimes, Nimage);
+    if (!isGPC1chip(image[i].photcode)) continue;
+    startTimes[Nmoschip] = image[i].tzero;
+    Nmoschip ++;
+  }
+  sort_times (startTimes, Nmoschip);
   MARKTIME("create array of all image obstimes: %f sec\n", dtime);
   
@@ -379,9 +349,6 @@
 
   // generate a list of the unique start times (these define the mosaics)
-  for (i = 0; i < Nimage; i++) {
-    if (startTimes[i] < startTimesMosaic[Nmosaic]) {
-      fprintf (stderr, "error?\n");
-      abort();
-    }
+  for (i = 0; i < Nmoschip; i++) {
+    myAssert (startTimes[i] >= startTimesMosaic[Nmosaic], "times out of order?");
     if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
     Nmosaic ++;
@@ -405,14 +372,14 @@
   // init the mosaic array values
   for (i = 0; i < Nmosaic; i++) {
-    mosaic[i].start = startTimesMosaic[i];
-    mosaic[i].stop  = 0;
-    mosaic[i].Mcal  = 0.0;
-    mosaic[i].dMcal = 0.0;
-    mosaic[i].dMsys = 0.0;
-    mosaic[i].Xm    = 0.0;
-    mosaic[i].flags = 0;
-    mosaic[i].secz  = NAN;
+    mosaic[i].start    = startTimesMosaic[i];
+    mosaic[i].stop     = 0;
+    mosaic[i].Mcal     = 0.0;
+    mosaic[i].dMcal    = 0.0;
+    mosaic[i].dMsys    = 0.0;
+    mosaic[i].Xm       = 0.0;
+    mosaic[i].flags    = 0;
+    mosaic[i].secz     = NAN;
     mosaic[i].photcode = 0;
-    mosaic[i].skipCal = FALSE;
+    mosaic[i].skipCal  = FALSE;
     
     memset (&mosaic[i].coords, 0, sizeof(Coords));
@@ -427,13 +394,12 @@
 
   // assign each image to a mosaic
+  int Nsimple = 0;
   for (i = 0; i < Nimage; i++) {
     ImageToMosaic[i] = -1;
 
-    /* select valid mosaic images by photcode */
-    pname = GetPhotcodeNamebyCode (image[i].photcode);
-    if (!pname) continue;
-
-    status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
-    if (status) continue;
+    if (!isGPC1chip(image[i].photcode)) {
+      Nsimple ++;
+      continue;
+    }
 
     start = image[i].tzero;
@@ -466,11 +432,11 @@
       abort();
     }
-    mosaic[j].stop  = stop;
-    mosaic[j].Mcal  = 0.0;
-    mosaic[j].dMcal = 0.0;
-    mosaic[j].Xm    = 0.0;
-    mosaic[j].dMsys = image[i].flags;
-    mosaic[j].flags = image[i].flags;
-    mosaic[j].secz  = image[i].secz;
+    mosaic[j].stop     = stop;
+    mosaic[j].Mcal     = 0.0;
+    mosaic[j].dMcal    = 0.0;
+    mosaic[j].Xm       = 0.0;
+    mosaic[j].dMsys    = image[i].flags;
+    mosaic[j].flags    = image[i].flags;
+    mosaic[j].secz     = image[i].secz;
     mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
   }
@@ -482,6 +448,9 @@
   free (startTimesMosaic);
 
+  if (mergeMcal) {
+    initMosaicGrid (image, Nimage);
+  }
+
   fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
-
   return;
 }
@@ -539,5 +508,4 @@
   off_t i, j, m, NX, NY, NC, Nc;
   double R, D, Rmid, Dmid;
-  double Mcal, dMcal, Xm;
   double *Rc, *Dc;
 
@@ -549,5 +517,4 @@
     Nc = 0;
     Rmid = Dmid = NAN;
-    Mcal = dMcal = Xm = 0;
     for (j = 0; j < MosaicN_Image[i]; j++) {
       m = MosaicToImage[i][j];
@@ -589,15 +556,4 @@
 	REALLOCATE (Dc, double, NC);
       }
-
-      Mcal  += image[m].Mcal;
-      dMcal += image[m].dMcal;
-      Xm    += image[m].Xm;
-
-      // for ubercal images, we (elsewhere) keep Mcal frozen
-
-      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
-      image[m].Mcal  = 0.0;
-      image[m].dMcal = NAN;
-      image[m].Xm    = NAN_S_SHORT;
     }
 
@@ -643,7 +599,7 @@
     mosaic[i].coords.pc2_1  = 0.0;
 
-    mosaic[i].Mcal   = Mcal / MosaicN_Image[i];
-    mosaic[i].dMcal  = dMcal / MosaicN_Image[i];
-    mosaic[i].Xm = Xm / MosaicN_Image[i];
+    mosaic[i].Mcal   = 0.0;
+    mosaic[i].dMcal  = 0.0;
+    mosaic[i].Xm     = 0.0;
   }
   return;
@@ -661,4 +617,6 @@
   double R, D, Rmin, Rmax, Dmin, Dmax;
   double Mcal, dMcal, Xm;
+
+  fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n");
 
   dXmax = dYmax = 0.0;
@@ -693,19 +651,19 @@
       Dmin = MIN (Dmin, D);
       Dmax = MAX (Dmax, D);
+
+      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
+
+      // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but 
+      // solve for a single offset for each exposure (Mosaic.Mcal).  
+      // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
+      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
+
       Mcal  += image[m].Mcal;
       dMcal += image[m].dMcal;
       Xm    += image[m].Xm;
 
-      // XXX: how does this work with UBERCAL?  We want to keep the Mcal values supplied by ubercal, but 
-      // solve for a single offset for each exposure (Mosaic.Mcal).  
-
-      // we also want to keep the flat-field terms for each exposure (regardless of ubercal or not)
-
-      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
-
-      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
       image[m].Mcal   = 0.0;
       image[m].dMcal  = NAN;
-      image[m].Xm = NAN_S_SHORT;
+      image[m].Xm     = NAN_S_SHORT;
     }
     dS /= MosaicN_Image[i];
@@ -725,5 +683,5 @@
     mosaic[i].Mcal   = Mcal / MosaicN_Image[i];
     mosaic[i].dMcal  = dMcal / MosaicN_Image[i];
-    mosaic[i].Xm = Xm / MosaicN_Image[i];
+    mosaic[i].Xm     = Xm / MosaicN_Image[i];
   }
   if (!USE_GRID) return;
@@ -735,5 +693,4 @@
 }
 
-// XXX : what about mosaics with skipCal == TRUE?
 void setMcalFinal () {
 
@@ -745,6 +702,5 @@
   image = getimages (&Nimage, NULL);
 
-  // XXX I think this is OK in the ubercal context, but probably need to skip UBERCAL
-  // images? (no need to update them)
+  fprintf (stderr, "*** return Mcal from mosaic.Mcal to image.Mcal ***\n");
 
   // copy the mosaic results to the images.  set the mosaic Mcal to 0.0 since we have moved its
@@ -1267,5 +1223,5 @@
 
   if (testImage) {
-    fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].Mcal, myMosaic[0].dMsys, myMosaic[0].Xm);
+    fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].Mcal, myMosaic[0].dMsys, pow (10.0, 0.01*myMosaic[0].Xm));
   }
 
@@ -1620,4 +1576,6 @@
     if (mosaic[i].flags & IMAGE_BAD) continue;
     if (mosaic[i].skipCal) continue;
+    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
+
     list[n] = mosaic[i].Mcal;
     dlist[n] = 1;
@@ -1650,4 +1608,6 @@
     if (mosaic[i].flags & IMAGE_BAD) continue;
     if (mosaic[i].skipCal) continue;
+    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
+
     list[n] = mosaic[i].dMcal;
     dlist[n] = 1;
@@ -1681,4 +1641,5 @@
     if (mosaic[i].flags & IMAGE_BAD)  continue;
     if (mosaic[i].skipCal) continue;
+    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
 
     N = 0;
@@ -1727,4 +1688,6 @@
     if (mosaic[i].flags & IMAGE_BAD) continue;
     if (mosaic[i].skipCal) continue;
+    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
+
     list[n]  = pow (10.0, 0.01*mosaic[i].Xm);
     dlist[n] = 1;
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/Shutdown.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/Shutdown.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/Shutdown.c	(revision 36990)
@@ -23,5 +23,5 @@
   SetProtect (TRUE);
   if (db) gfits_db_close (db);
-  fprintf (stderr, "ERROR: addstar halted\n");
+  fprintf (stderr, "ERROR: relphot halted\n");
   exit (1);
 }
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/assign_images.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/assign_images.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/assign_images.c	(revision 36990)
@@ -25,5 +25,5 @@
 
   if (MOSAIC_ZEROPT) {
-    makeMosaics (image, Nimage);
+    makeMosaics (image, Nimage, FALSE);
 
     // center coords and Mcal, dMcal, Mchisq for the mosaics
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/extra.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/extra.c	(revision 36990)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/extra.c	(revision 36990)
@@ -0,0 +1,40 @@
+# include "relphot.h"
+
+// for now (20140710) I need to identify gpc1 chips explicitly.  generalize in the future
+int isGPC1chip (int photcode) {
+
+  if ((photcode > 10000) && (photcode < 10077)) return TRUE; // g-band
+  if ((photcode > 10100) && (photcode < 10177)) return TRUE; // r-band
+  if ((photcode > 10200) && (photcode < 10277)) return TRUE; // i-band
+  if ((photcode > 10300) && (photcode < 10377)) return TRUE; // z-band
+  if ((photcode > 10400) && (photcode < 10477)) return TRUE; // y-band
+  if ((photcode > 10500) && (photcode < 10577)) return TRUE; // w-band
+
+  return FALSE;
+}
+
+// for now (20140710) I need to identify gpc1 stacks explicitly.  generalize in the future
+int isGPC1stack (int photcode) {
+
+  if (photcode == 11000) return TRUE; // g-band
+  if (photcode == 11100) return TRUE; // r-band
+  if (photcode == 11200) return TRUE; // i-band
+  if (photcode == 11300) return TRUE; // z-band
+  if (photcode == 11400) return TRUE; // y-band
+  if (photcode == 11500) return TRUE; // w-band
+
+  return FALSE;
+}
+
+// for now (20140710) I need to identify gpc1 stacks explicitly.  generalize in the future
+int isGPC1warp (int photcode) {
+
+  if (photcode == 12000) return TRUE; // g-band
+  if (photcode == 12100) return TRUE; // r-band
+  if (photcode == 12200) return TRUE; // i-band
+  if (photcode == 12300) return TRUE; // z-band
+  if (photcode == 12400) return TRUE; // y-band
+  if (photcode == 12500) return TRUE; // w-band
+
+  return FALSE;
+}
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/launch_region_hosts.c	(revision 36990)
@@ -55,6 +55,15 @@
 
     char command[1024];
-    snprintf (command, 1024, "relphot %s -parallel-images %s -region-hosts %s -region-hostID %d -D CATDIR %s -region %f %f %f %f -statmode %s -D CAMERA %s -D STAR_TOOFEW %d -minerror %f", 
-	      PhotcodeList, filename, REGION_FILE, host->hostID, CATDIR, host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat, STATMODE, CAMERA, STAR_TOOFEW, MIN_ERROR);
+    snprintf (command, 1024, "relphot %s", PhotcodeList);
+    strextend (command, "-parallel-images %s", filename);
+    strextend (command, "-region-hosts %s", REGION_FILE);
+    strextend (command, "-region-hostID %d", host->hostID);
+    strextend (command, "-D CATDIR %s", CATDIR);
+    strextend (command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
+    strextend (command, "-statmode %s", STATMODE);
+    strextend (command, "-D CAMERA %s", CAMERA);
+    strextend (command, "-D STAR_TOOFEW %d", STAR_TOOFEW);
+    strextend (command, "-minerror %f", MIN_ERROR);
+    strextend (command, "-cloud-limit %f", CLOUD_TOLERANCE);
 
     if (VERBOSE)       	     strextend (command, "-v");
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/relphot_parallel_images.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/relphot_parallel_images.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/relphot_parallel_images.c	(revision 36990)
@@ -38,6 +38,5 @@
   // unlink (IMAGE_TABLE); // XXX a bit risky, add some protection?
 
-  // XXX need to deal with mosaic vs image...
-  makeMosaics (image, Nimage);
+  makeMosaics (image, Nimage, TRUE);
 
   initImages (image, NULL, Nimage);
Index: /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/setMrelCatalog.c	(revision 36989)
+++ /branches/eam_branches/ipp-20140610/Ohana/src/relphot/src/setMrelCatalog.c	(revision 36990)
@@ -159,17 +159,11 @@
 
       // are we a PS1 exposure photcode?
-      if ((measureT[k].photcode >= 10000) && (measureT[k].photcode <= 10500)) {
-	NexpPS1 ++;
-      }
+      if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++;
 
       // SKIP gpc1 stack data
-      if ((measureT[k].photcode >= 11000) && (measureT[k].photcode <= 11500)) {
-	continue;
-      }
+      if (isGPC1stack(measureT[k].photcode)) continue;
 
       // SKIP gpc1 forced-warp data
-      if ((measureT[k].photcode >= 12000) && (measureT[k].photcode <= 12500)) {
-	continue;
-      }
+      if (isGPC1warp(measureT[k].photcode)) continue;
 
       if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad); 
@@ -497,7 +491,5 @@
 
       // only examine gpc1 stack data
-      // XXX this is absurdly hardwired (along with several photcode tests)
-      if (measure[k].photcode < 11000) continue;
-      if (measure[k].photcode > 11400) continue;
+      if (!isGPC1stack(measure[k].photcode)) continue;
 
       haveStack = TRUE;
@@ -695,6 +687,6 @@
     for (k = 0; k < average[0].Nmeasure; k++, meas++) {
 
-      // skip measurements which are not ForcedWarp values
-      if ((measure[k].photcode < 12000) || (measure[k].photcode > 12500)) continue;
+      // only examine gpc1 forced-warp data
+      if (!isGPC1warp(measure[k].photcode)) continue;
 
       // skip measurements that do not match the current photcode
