Index: /trunk/Ohana/src/relphot/doc/notes.txt
===================================================================
--- /trunk/Ohana/src/relphot/doc/notes.txt	(revision 19896)
+++ /trunk/Ohana/src/relphot/doc/notes.txt	(revision 19897)
@@ -1,2 +1,27 @@
+
+2008.09.20
+
+  I am working on the flat-field correction analysis.  This is
+  currently triggered by the -grid flag.  This analysis needs to
+  require a single camera. 
+
+  * need to define the relationship between image and ccdnum
+    (currently it uses as regex, effectively, to match the ccdnum to
+    the number portion of the photcode).  make an explicit entry in
+    the dvo.config table.
+    
+  * clean up the output files (make the output files have names
+    supplied by the user, etc)
+
+  * I use the string MOSAICNAME to determine the relationship between
+    chips.  this allows me to do the relphot grid process on mosaic
+    images for which I don't have bilevel astrometry, but where we do,
+    we could link the mosaic together via the mosaic reference image.
+    Maybe this is a future upgrade.
+
+  * I think mosaic name can be replaced with camera name: we need to
+    supply CAMERA in any case, and the photcodes have names of the
+    form CAMERA.XXX.  This is all very ad hoc, but can be effective
+    for the near term.  
 
 2006.10.17
Index: /trunk/Ohana/src/relphot/include/relphot.h
===================================================================
--- /trunk/Ohana/src/relphot/include/relphot.h	(revision 19896)
+++ /trunk/Ohana/src/relphot/include/relphot.h	(revision 19897)
@@ -60,4 +60,5 @@
 
 int    VERBOSE;
+int    MOSAIC_ZEROPT;
 
 int    NLOOP;
Index: /trunk/Ohana/src/relphot/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/relphot/src/ConfigInit.c	(revision 19896)
+++ /trunk/Ohana/src/relphot/src/ConfigInit.c	(revision 19897)
@@ -50,4 +50,5 @@
   GetConfig (config, "RELPHOT_GRID_BINNING",   "%d",  0, &RELPHOT_GRID_BINNING);
   GetConfig (config, "CAMERA_CONFIG",          "%s",  0, CameraConfig);
+  GetConfig (config, "MOSAICNAME",             "%s",  0, MOSAICNAME);
 
   if (*CATMODE == 0) strcpy (CATMODE, "RAW");
Index: /trunk/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 19896)
+++ /trunk/Ohana/src/relphot/src/ImageOps.c	(revision 19897)
@@ -67,4 +67,84 @@
   free (mlist);
 }
+
+/* **** use this to mimic the Mosaic version ***/
+# if (0)
+void initImageGrid (Image *image, int Nimage) {
+
+  /* find max dR, dD range for all mosaics */
+  /* define mosaic.coords to cover dR, dD */
+  /* send results to initGridBins */
+
+  int i, j, m, NX, NY;
+  int dXmax, dYmax;
+  double dS, dX, dY;
+  double R, D, Rmin, Rmax, Dmin, Dmax;
+  double Mcal, dMcal, Xm;
+
+  dXmax = dYmax = 0.0;
+  for (i = 0; i < Nmosaic; i++) {
+    Dmin = Rmin =  360.0;
+    Dmax = Rmax = -360.0;
+    dS = 0.0;
+    Mcal = dMcal = Xm = 0;
+    for (j = 0; j < Nimlist[i]; j++) {
+      m = imlist[i][j];
+      NX = image[m].NX;
+      NY = image[m].NY;
+      dS += hypot (image[m].coords.cdelt1*image[m].coords.pc1_1, image[m].coords.cdelt1*image[m].coords.pc2_1);
+      XY_to_RD (&R, &D, 0.0, 0.0, &image[m].coords);
+      Rmin = MIN (Rmin, R);
+      Rmax = MAX (Rmax, R);
+      Dmin = MIN (Dmin, D);
+      Dmax = MAX (Dmax, D);
+      XY_to_RD (&R, &D, (double) NX, 0.0, &image[m].coords);
+      Rmin = MIN (Rmin, R);
+      Rmax = MAX (Rmax, R);
+      Dmin = MIN (Dmin, D);
+      Dmax = MAX (Dmax, D);
+      XY_to_RD (&R, &D, (double) NX, (double) NY, &image[m].coords);
+      Rmin = MIN (Rmin, R);
+      Rmax = MAX (Rmax, R);
+      Dmin = MIN (Dmin, D);
+      Dmax = MAX (Dmax, D);
+      XY_to_RD (&R, &D, 0.0, (double) NY, &image[m].coords);
+      Rmin = MIN (Rmin, R);
+      Rmax = MAX (Rmax, R);
+      Dmin = MIN (Dmin, D);
+      Dmax = MAX (Dmax, D);
+      Mcal  += image[m].Mcal;
+      dMcal += image[m].dMcal;
+      Xm    += image[m].Xm;
+      /* 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;
+    }
+    dS /= Nimlist[i];
+    strcpy (mosaic[i].coords.ctype, "RA---TAN");
+    mosaic[i].coords.crval1 = Rmin;
+    mosaic[i].coords.crval2 = Dmin;
+    mosaic[i].coords.crpix1 = 0.0;
+    mosaic[i].coords.crpix2 = 0.0;
+    mosaic[i].coords.cdelt1 = dS;
+    mosaic[i].coords.cdelt2 = dS;
+    mosaic[i].coords.pc1_1  = 1.0;
+    mosaic[i].coords.pc2_2  = 1.0;
+    mosaic[i].coords.pc1_2  = 0.0;
+    mosaic[i].coords.pc2_1  = 0.0;
+    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
+
+    mosaic[i].Mcal  = Mcal / Nimlist[i];
+    mosaic[i].dMcal = dMcal / Nimlist[i];
+    mosaic[i].Xm    = Xm / Nimlist[i];
+  }
+  if (!USE_GRID) return;
+
+  dXmax = MAX (dXmax, dX);
+  dYmax = MAX (dYmax, dY);
+  initGrid (dXmax, dYmax);
+  return;
+}
+# endif
 
 /* select all image equivalent to the current photcode */
Index: /trunk/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 19896)
+++ /trunk/Ohana/src/relphot/src/MosaicOps.c	(revision 19897)
@@ -22,5 +22,5 @@
   char *pname;
 
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
 
   Nmosaic = 0;
@@ -173,5 +173,5 @@
   Image *image;
 
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
 
   image = getimages (&Nimage);
@@ -194,5 +194,6 @@
 
   /* measure -> mosaic */
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
+
   ALLOCATE (bin, int *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
@@ -220,5 +221,6 @@
 
   /* measure -> mosaic */
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
+
   for (i = 0; i < Ncatalog; i++) {
     free (bin[i]);
@@ -241,5 +243,6 @@
   int i, j, ecode;
 
-  if (!MOSAICNAME[0]) return (FALSE);
+  if (!MOSAIC_ZEROPT) return (FALSE);
+
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Nmeasure; j++) {
@@ -298,5 +301,6 @@
   float value;
 
-  if (!MOSAICNAME[0]) return (0);
+  if (!MOSAIC_ZEROPT) return (0);
+
   i = bin[cat][meas];
   if (i == -1) return (NAN);
@@ -315,5 +319,5 @@
   Image *image;
 
-  if (!MOSAICNAME[0]) return (FALSE);
+  if (!MOSAIC_ZEROPT) return (FALSE);
 
   image = getimages (&N);
@@ -401,5 +405,5 @@
 
   bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
+  if (!MOSAIC_ZEROPT) return (stats);
 
   ALLOCATE (list, double, Nmosaic);
@@ -427,5 +431,5 @@
 
   bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
+  if (!MOSAIC_ZEROPT) return (stats);
 
   ALLOCATE (list, double, Nmosaic);
@@ -455,5 +459,5 @@
 
   bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
+  if (!MOSAIC_ZEROPT) return (stats);
 
   ALLOCATE (list, double, Nmosaic);
@@ -497,5 +501,5 @@
 
   bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
+  if (!MOSAIC_ZEROPT) return (stats);
 
   ALLOCATE (list, double, Nmosaic);
@@ -525,5 +529,5 @@
   StatType stats;
 
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
 
   if (VERBOSE) fprintf (stderr, "marking poor mosaics\n");
@@ -576,5 +580,5 @@
   Graphdata graphdata;
 
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
 
   image = getimages (&Nimage);
@@ -619,5 +623,5 @@
   Graphdata graphdata;
 
-  if (!MOSAICNAME[0]) return;
+  if (!MOSAIC_ZEROPT) return;
 
   ALLOCATE (xlist, double, Nmosaic);
Index: /trunk/Ohana/src/relphot/src/args.c
===================================================================
--- /trunk/Ohana/src/relphot/src/args.c	(revision 19896)
+++ /trunk/Ohana/src/relphot/src/args.c	(revision 19897)
@@ -117,10 +117,12 @@
   }
 
-  /* group images by mosaic, find Mmos */
-  MOSAICNAME[0] = 0;
+  /* XXX this argument used to do two things: specify the camera name and tell the analysis to
+     calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
+     config system, but need to use this argument to specify that the mosaic zeropoints should be
+     calculated. */
+  MOSAIC_ZEROPT = FALSE;
   if ((N = get_argument (argc, argv, "-mosaic"))) {
     remove_argument (N, &argc, argv);
-    strcpy (MOSAICNAME, argv[N]);
-    remove_argument (N, &argc, argv);
+    MOSAIC_ZEROPT = TRUE;
   }
 
@@ -135,8 +137,4 @@
     remove_argument (N, &argc, argv);
     USE_GRID = TRUE;
-    if (!MOSAICNAME[0]) {
-      fprintf (stderr, "-grid is only valid with -mosaic\n");
-      exit (2);
-    }
   }
 
