Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/ImageOps.c	(revision 33100)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/ImageOps.c	(revision 33101)
@@ -1,12 +1,10 @@
 # include "relphot.h"
 
-static off_t       **bin;     // link from catalog,measure to image	     
-static off_t       **clist;   // catalog which supplied measurement on image 
-static off_t       **mlist;   // measure reference for measurement on image  
-static off_t        *Nlist;   // number of measurements on image	     
-static off_t        *NLIST;   // allocated number of measurements on image   
-
-static Image        *image;   // list of available images  
+// we have an array of images: image[ImageIndex] (ImageIndex : 0 < Nimage)
 static off_t        Nimage;   // number of available images
+static Image        *image;   // array of available images  
+
+// if we read only a subset of the rows from the Image FITS, LineNumber tells us to which row
+// each image belongs
 static off_t       *LineNumber; // match of subset to full image table
 
@@ -14,4 +12,21 @@
 static off_t        *imageIDs; // list of all image IDs
 static off_t        *imageIdx; // list of index for image IDs 
+
+// elsewhere, we have loaded a set of catalogs with measures (catalog[cat].measure[meas])
+// each image has N_onImage[ImageIndex] measurements
+static off_t        *N_onImage;   // actual number of measurements on image	     
+static off_t        *N_ONIMAGE;   // allocated number of measurements on image   
+
+// relationships between the measure,catalog set and the images:
+static off_t       **MeasureToImage; // image index from measure,catalog   : MeasureToImage[cat][meas] = ImageIndex
+static off_t       **ImageToCatalog; // catalog for given measure on image : ImageCatalog[ImageIndex][i] = cat (i : 0 < NonImage[ImageIndex])
+static off_t       **ImageToMeasure; // measure for given measure on image : ImageMeasure[ImageIndex][i] = cat (i : 0 < NonImage[ImageIndex])
+
+// MeasureToImage was 'bin'
+// ImageToCatalog was 'clist'
+// ImageToMeasure was 'mlist'
+
+// N_onImage was 'Nlist'
+// N_ONIMAGE was 'NLIST'
 
 Image *getimages (off_t *N, off_t **line_number) {
@@ -73,21 +88,21 @@
   off_t i, j;
 
-  ALLOCATE (bin, off_t *, Ncatalog);
+  ALLOCATE (MeasureToImage, off_t *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1));
-    for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;
+    ALLOCATE (MeasureToImage[i], off_t, MAX (catalog[i].Nmeasure, 1));
+    for (j = 0; j < catalog[i].Nmeasure; j++) MeasureToImage[i][j] = -1;
   }
 
   if (doImageList) {
-    ALLOCATE (Nlist, off_t, Nimage);
-    ALLOCATE (NLIST, off_t, Nimage);
-    ALLOCATE (clist, off_t *, Nimage);
-    ALLOCATE (mlist, off_t *, Nimage);
+    ALLOCATE (N_onImage, off_t, Nimage);
+    ALLOCATE (N_ONIMAGE, off_t, Nimage);
+    ALLOCATE (ImageToCatalog, off_t *, Nimage);
+    ALLOCATE (ImageToMeasure, off_t *, Nimage);
 
     for (i = 0; i < Nimage; i++) {
-      Nlist[i] = 0;
-      NLIST[i] = 100;
-      ALLOCATE (clist[i], off_t, NLIST[i]);
-      ALLOCATE (mlist[i], off_t, NLIST[i]);
+      N_onImage[i] = 0;
+      N_ONIMAGE[i] = 100;
+      ALLOCATE (ImageToCatalog[i], off_t, N_ONIMAGE[i]);
+      ALLOCATE (ImageToMeasure[i], off_t, N_ONIMAGE[i]);
     }
   }
@@ -99,17 +114,17 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    free (bin[i]);
-  }
-  free (bin);
+    free (MeasureToImage[i]);
+  }
+  free (MeasureToImage);
 
   if (doImageList) {
     for (i = 0; i < Nimage; i++) {
-      free (clist[i]);
-      free (mlist[i]);
-    }
-    free (clist);
-    free (mlist);
-    free (Nlist);
-    free (NLIST);
+      free (ImageToCatalog[i]);
+      free (ImageToMeasure[i]);
+    }
+    free (ImageToCatalog);
+    free (ImageToMeasure);
+    free (N_onImage);
+    free (N_ONIMAGE);
   }
 }
@@ -210,18 +225,18 @@
 
   // index for (catalog, measure) -> image
-  bin[cat][meas] = idx;
+  MeasureToImage[cat][meas] = idx;
 
   if (doImageList) {
     // index for image, Nentry -> catalog
-    clist[idx][Nlist[idx]] = cat;
+    ImageToCatalog[idx][N_onImage[idx]] = cat;
 
     // index for image, Nentry -> measure
-    mlist[idx][Nlist[idx]] = meas;
-    Nlist[idx] ++;
-
-    if (Nlist[idx] == NLIST[idx]) {
-      NLIST[idx] += 100;
-      REALLOCATE (clist[idx], off_t, NLIST[idx]);
-      REALLOCATE (mlist[idx], off_t, NLIST[idx]);
+    ImageToMeasure[idx][N_onImage[idx]] = meas;
+    N_onImage[idx] ++;
+
+    if (N_onImage[idx] == N_ONIMAGE[idx]) {
+      N_ONIMAGE[idx] += 100;
+      REALLOCATE (ImageToCatalog[idx], off_t, N_ONIMAGE[idx]);
+      REALLOCATE (ImageToMeasure[idx], off_t, N_ONIMAGE[idx]);
     }	
   }
@@ -234,5 +249,5 @@
   off_t i;
 
-  i = bin[cat][meas];
+  i = MeasureToImage[cat][meas];
   return (i);
 }
@@ -243,5 +258,5 @@
   float value;
 
-  i = bin[cat][meas];
+  i = MeasureToImage[cat][meas];
   if (i == -1) return (NAN);
 
@@ -255,5 +270,5 @@
   off_t i;
 
-  i = bin[cat][meas];
+  i = MeasureToImage[cat][meas];
   if (i == -1) return (NULL);
   return (&image[i].coords);
@@ -279,5 +294,5 @@
   Nmax = 0;
   for (i = 0; i < Nimage; i++) {
-    Nmax = MAX (Nmax, Nlist[i]);
+    Nmax = MAX (Nmax, N_onImage[i]);
   }
   ALLOCATE (list, double, Nmax);
@@ -299,8 +314,8 @@
 
     N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
+    for (j = 0; j < N_onImage[i]; j++) {
       
-      m = mlist[i][j];
-      c = clist[i][j];
+      m = ImageToMeasure[i][j];
+      c = ImageToCatalog[i][j];
       
       if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
@@ -339,9 +354,9 @@
       N++;
     }
-    /* Nlist[i] is all measurements, N is good measurements */
+    /* N_onImage[i] is all measurements, N is good measurements */
 
     /* too few good measurements or too many bad measurements */
     if (!PoorImages) {
-      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
+      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onImage[i]);
       if (mark) {
 	image[i].flags |= ID_IMAGE_PHOTOM_FEW;
@@ -383,5 +398,5 @@
   int mark, Nmark;
   off_t i, N;
-  double *mlist, *slist, *dlist;
+  double *ImageToMeasure, *slist, *dlist;
   double MaxOffset, MaxScatter, MedOffset;
   StatType stats;
@@ -391,5 +406,5 @@
   if (VERBOSE) fprintf (stderr, "marking poor images\n");
 
-  ALLOCATE (mlist, double, Nimage);
+  ALLOCATE (ImageToMeasure, double, Nimage);
   ALLOCATE (slist, double, Nimage);
   ALLOCATE (dlist, double, Nimage);
@@ -397,5 +412,5 @@
   for (i = N = 0; i < Nimage; i++) {
     if (image[i].flags & IMAGE_BAD) continue;
-    mlist[N] = fabs (image[i].Mcal);
+    ImageToMeasure[N] = fabs (image[i].Mcal);
     slist[N] = image[i].dMcal;
     dlist[N] = 1;
@@ -403,5 +418,5 @@
   }
   initstats ("MEAN");
-  liststats (mlist, dlist, N, &stats);
+  liststats (ImageToMeasure, dlist, N, &stats);
   MaxOffset = MAX (IMAGE_OFFSET, 3*stats.sigma);
   MedOffset = stats.median;
@@ -425,5 +440,5 @@
   fprintf (stderr, "%d images marked poor\n", Nmark);
   initstats (STATMODE);
-  free (mlist);
+  free (ImageToMeasure);
   free (slist);
   free (dlist);
@@ -496,8 +511,8 @@
 
     N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
-
-      m = mlist[i][j];
-      c = clist[i][j];
+    for (j = 0; j < N_onImage[i]; j++) {
+
+      m = ImageToMeasure[i][j];
+      c = ImageToCatalog[i][j];
 
       Mcal  = getMcal  (m, c);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/MosaicOps.c	(revision 33100)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/MosaicOps.c	(revision 33101)
@@ -5,22 +5,37 @@
 static Mosaic *mosaic;
 
-// list of all images associated with a mosaic
-static off_t   *Nimlist;
-static off_t   **imlist; /* mosaic -> image[] */
-static off_t   **bin;    /* catalog, measure -> mosaic */
-
-// list of mosaics associated with an image
-static off_t   *mosimage;
-
-// list of mosaic associated with each image  
-static int     **clist;  /* mosaic -> catalog[] */
-static off_t   **mlist;  /* mosiac -> measure[] */
-static off_t    *Nlist;
-static off_t    *NLIST;
+// relationships between the mosaics and their associated images
+static off_t   *MosaicN_Image; // number of images associated with the given mosaic
+static off_t  **MosaicToImage; // list of imagesa associated with the given mosaic
+
+// mosaic index for given image : ImageToMosaic[ImageIndex] = MosaicIndex (ImageIndex : 0 < Nimage)
+static off_t   *ImageToMosaic;
+
+// elsewhere, we have loaded a set of catalogs with measures (catalog[cat].measure[meas])
+// each mosaic has N_onMosaic[MosaicIndex] measurements
+static off_t    *N_onMosaic;   // actual number of measurements on mosaic	 
+static off_t    *N_ONMOSAIC;   // allocated number of measurements on mosaic   
+
+// relationships between the measure,catalog set and the mosaics:
+static off_t   **MeasureToMosaic; // Mosaic index from measure,catalog  : MeasureToMosaic[cat][meas] = MosaicIndex 
+static off_t   **MosaicToCatalog; // catalog for given measure on mosaic : MosaicCatalog[MosaicIndex][i] = cat (i : 0 < NonMosaic[MosaicIndex])
+static off_t   **MosaicToMeasure; // measure for given measure on mosaic : MosaicMeasure[MosaicIndex][i] = cat (i : 0 < NonMosaic[MosaicIndex])
+
+// MeasureToMosaic was 'bin'
+// MosaicToCatalog was 'clist'
+// MosaicToMeasure was 'mlist'
+
+// N_onMosaic was 'Nlist'
+// N_ONMOSAIC was 'NLIST'
+
+// ImageToMosaic was 'mosimage'
+
+// MosaicN_image was 'Nimlist'
+// MosaicToImage was 'imlist'
 
 /* find mosaic frames (unique time periods & photcode name matches mosaic) */
 void initMosaics (Image *image, off_t Nimage) {
 
-  off_t i, j, status, found, NMOSAIC, *NIMLIST;
+  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
   unsigned int start, stop;
   char *pname;
@@ -32,9 +47,9 @@
   ALLOCATE (mosaic, Mosaic, NMOSAIC);
 
-  ALLOCATE (imlist,  off_t *, NMOSAIC);
-  ALLOCATE (Nimlist, off_t,   NMOSAIC);
-  ALLOCATE (NIMLIST, off_t,   NMOSAIC);
-
-  ALLOCATE (mosimage, off_t, Nimage); // mosaic to which image belongs
+  ALLOCATE (MosaicToImage,  off_t *, NMOSAIC);
+  ALLOCATE (MosaicN_Image, off_t,   NMOSAIC);
+  ALLOCATE (MosaicN_IMAGE, off_t,   NMOSAIC);
+
+  ALLOCATE (ImageToMosaic, off_t, Nimage); // mosaic to which image belongs
 
   /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no 
@@ -45,5 +60,5 @@
   /* generate list of unique mosaics */
   for (i = 0; i < Nimage; i++) {
-    mosimage[i] = -1;
+    ImageToMosaic[i] = -1;
 
     /* select valid mosaic images by photcode */
@@ -64,12 +79,12 @@
 
       // add reference from image to mosaic
-      mosimage[i] = j;
+      ImageToMosaic[i] = j;
 
       /* add image to mosaic image list */
-      imlist[j][Nimlist[j]] = i;
-      Nimlist[j] ++;
-      if (Nimlist[j] == NIMLIST[j]) {
-	NIMLIST[j] += 10;
-	REALLOCATE (imlist[j], off_t, NIMLIST[j]);
+      MosaicToImage[j][MosaicN_Image[j]] = i;
+      MosaicN_Image[j] ++;
+      if (MosaicN_Image[j] == MosaicN_IMAGE[j]) {
+	MosaicN_IMAGE[j] += 10;
+	REALLOCATE (MosaicToImage[j], off_t, MosaicN_IMAGE[j]);
       }
 
@@ -89,11 +104,11 @@
 
     /* add image to mosaic image list */
-    NIMLIST[Nmosaic] = 10;
-    Nimlist[Nmosaic] = 1;
-    ALLOCATE (imlist[Nmosaic], off_t, NIMLIST[Nmosaic]);
-    imlist[Nmosaic][0] = i;
+    MosaicN_IMAGE[Nmosaic] = 10;
+    MosaicN_Image[Nmosaic] = 1;
+    ALLOCATE (MosaicToImage[Nmosaic], off_t, MosaicN_IMAGE[Nmosaic]);
+    MosaicToImage[Nmosaic][0] = i;
 
     // add reference from image to mosaic
-    mosimage[i] = Nmosaic;
+    ImageToMosaic[i] = Nmosaic;
     
     Nmosaic ++;
@@ -101,9 +116,12 @@
       NMOSAIC += 10;
       REALLOCATE (mosaic,  Mosaic,  NMOSAIC);
-      REALLOCATE (imlist,  off_t *, NMOSAIC);
-      REALLOCATE (Nimlist, off_t,   NMOSAIC);
-      REALLOCATE (NIMLIST, off_t,   NMOSAIC);
-    }
-  }
+      REALLOCATE (MosaicToImage,  off_t *, NMOSAIC);
+      REALLOCATE (MosaicN_Image, off_t,   NMOSAIC);
+      REALLOCATE (MosaicN_IMAGE, off_t,   NMOSAIC);
+    }
+  }
+
+  // free this or not?
+  free (MosaicN_IMAGE);
 
   initMosaicGrid (image, Nimage);
@@ -129,6 +147,6 @@
     dS = 0.0;
     Mcal = dMcal = Xm = 0;
-    for (j = 0; j < Nimlist[i]; j++) {
-      m = imlist[i][j];
+    for (j = 0; j < MosaicN_Image[i]; j++) {
+      m = MosaicToImage[i][j];
       NX = image[m].NX;
       NY = image[m].NY;
@@ -162,5 +180,5 @@
       image[m].Xm    = NAN_S_SHORT;
     }
-    dS /= Nimlist[i];
+    dS /= MosaicN_Image[i];
     strcpy (mosaic[i].coords.ctype, "RA---TAN");
     mosaic[i].coords.crval1 = Rmin;
@@ -176,7 +194,7 @@
     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];
+    mosaic[i].Mcal  = Mcal / MosaicN_Image[i];
+    mosaic[i].dMcal = dMcal / MosaicN_Image[i];
+    mosaic[i].Xm    = Xm / MosaicN_Image[i];
   }
   if (!USE_GRID) return;
@@ -200,6 +218,6 @@
   // impact to the images
   for (i = 0; i < Nmosaic; i++) {
-    for (j = 0; j < Nimlist[i]; j++) {
-      im = imlist[i][j];
+    for (j = 0; j < MosaicN_Image[i]; j++) {
+      im = MosaicToImage[i][j];
       image[im].Mcal += mosaic[i].Mcal;
       image[im].dMcal = mosaic[i].dMcal;
@@ -221,22 +239,22 @@
   if (!MOSAIC_ZEROPT) return;
 
-  ALLOCATE (bin, off_t *, Ncatalog);
+  ALLOCATE (MeasureToMosaic, off_t *, Ncatalog);
   for (i = 0; i < Ncatalog; i++) {
-    ALLOCATE (bin[i], off_t, MAX (catalog[i].Nmeasure, 1));
-    for (j = 0; j < catalog[i].Nmeasure; j++) bin[i][j] = -1;
+    ALLOCATE (MeasureToMosaic[i], off_t, MAX (catalog[i].Nmeasure, 1));
+    for (j = 0; j < catalog[i].Nmeasure; j++) MeasureToMosaic[i][j] = -1;
   }
 
   if (doMosaicList) {
     /* mosaic -> measure */
-    ALLOCATE (Nlist, off_t,   Nmosaic);
-    ALLOCATE (NLIST, off_t,   Nmosaic);
-    ALLOCATE (clist, int *,   Nmosaic);
-    ALLOCATE (mlist, off_t *, Nmosaic);
+    ALLOCATE (N_onMosaic, off_t,   Nmosaic);
+    ALLOCATE (N_ONMOSAIC, off_t,   Nmosaic);
+    ALLOCATE (MosaicToCatalog, off_t *, Nmosaic);
+    ALLOCATE (MosaicToMeasure, off_t *, Nmosaic);
 
     for (i = 0; i < Nmosaic; i++) {
-      Nlist[i] = 0;
-      NLIST[i] = 100;
-      ALLOCATE (clist[i], int,   NLIST[i]);
-      ALLOCATE (mlist[i], off_t, NLIST[i]);
+      N_onMosaic[i] = 0;
+      N_ONMOSAIC[i] = 100;
+      ALLOCATE (MosaicToCatalog[i], off_t, N_ONMOSAIC[i]);
+      ALLOCATE (MosaicToMeasure[i], off_t, N_ONMOSAIC[i]);
     }
   }
@@ -251,18 +269,18 @@
 
   for (i = 0; i < Ncatalog; i++) {
-    free (bin[i]);
-  }
-  free (bin);
+    free (MeasureToMosaic[i]);
+  }
+  free (MeasureToMosaic);
 
   if (doMosaicList) {
     /* mosaic -> measure */
     for (i = 0; i < Nmosaic; i++) {
-      free (clist[i]);
-      free (mlist[i]);
-    }
-    free (Nlist);
-    free (NLIST);
-    free (clist);
-    free (mlist);
+      free (MosaicToCatalog[i]);
+      free (MosaicToMeasure[i]);
+    }
+    free (N_onMosaic);
+    free (N_ONMOSAIC);
+    free (MosaicToCatalog);
+    free (MosaicToMeasure);
   }
 }
@@ -310,5 +328,5 @@
   }
 
-  mosID = mosimage[idx];
+  mosID = ImageToMosaic[idx];
   if (mosID < 0) {
     Image *image = getimage(idx);
@@ -327,15 +345,15 @@
   }
 
-  bin[cat][meas] = mosID;
+  MeasureToMosaic[cat][meas] = mosID;
 
   if (doMosaicList) {
-    clist[mosID][Nlist[mosID]] = cat;
-    mlist[mosID][Nlist[mosID]] = meas;
-    Nlist[mosID] ++;
+    MosaicToCatalog[mosID][N_onMosaic[mosID]] = cat;
+    MosaicToMeasure[mosID][N_onMosaic[mosID]] = meas;
+    N_onMosaic[mosID] ++;
     
-    if (Nlist[mosID] == NLIST[mosID]) {
-      NLIST[mosID] += 100;
-      REALLOCATE (clist[mosID], int,   NLIST[mosID]);
-      REALLOCATE (mlist[mosID], off_t, NLIST[mosID]);
+    if (N_onMosaic[mosID] == N_ONMOSAIC[mosID]) {
+      N_ONMOSAIC[mosID] += 100;
+      REALLOCATE (MosaicToCatalog[mosID], off_t, N_ONMOSAIC[mosID]);
+      REALLOCATE (MosaicToMeasure[mosID], off_t, N_ONMOSAIC[mosID]);
     }	
   }
@@ -350,5 +368,5 @@
   if (!MOSAIC_ZEROPT) return (0);
 
-  i = bin[cat][meas];
+  i = MeasureToMosaic[cat][meas];
   if (i == -1) return (NAN);
 
@@ -380,5 +398,5 @@
   Nmax = 0;
   for (i = 0; i < Nmosaic; i++) {
-    Nmax = MAX (Nmax, Nlist[i]);
+    Nmax = MAX (Nmax, N_onMosaic[i]);
   }
   ALLOCATE (list, double, Nmax);
@@ -398,8 +416,8 @@
 
     N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
+    for (j = 0; j < N_onMosaic[i]; j++) {
       
-      m = mlist[i][j];
-      c = clist[i][j];
+      m = MosaicToMeasure[i][j];
+      c = MosaicToCatalog[i][j];
       
       if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
@@ -435,12 +453,12 @@
       N++;
     }
-    /* Nlist[i] is all measurements, N is good measurements */
+    /* N_onMosaic[i] is all measurements, N is good measurements */
 
     /* too few good measurements or too many bad measurements (skip in PoorImages run) */
 
     if (!PoorImages) {
-      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
+      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*N_onMosaic[i]);
       if (mark) {
-	if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]); }
+	if (VERBOSE2) { fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[MosaicToImage[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  N_onMosaic[i]); }
 	mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW;
 	Nfew ++;
@@ -515,5 +533,5 @@
 
     if (VERBOSE2 && (fabs(mosaic[i].Mcal) < CLOUD_TOLERANCE)) {
-      fprintf (stderr, "cloud-free: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
+      fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     } 
     if (VERBOSE2 && (mosaic[i].Mcal < -CLOUD_TOLERANCE)) {
@@ -521,8 +539,8 @@
       // NOTE the negative sign: down below, we are going to add in the negative of Mcal
       // to this image, and the propagated mean values for other images
-      fprintf (stderr, "anti-clouds: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
+      fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     } 
     if (VERBOSE2 && (mosaic[i].Mcal > CLOUD_TOLERANCE)) {
-      fprintf (stderr, "cloudy    : %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
+      fprintf (stderr, "cloudy    : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     } 
   }
@@ -579,5 +597,5 @@
 
 	// find the source of this measurement (skip unassigned measurements)
-	nMos = bin[i][m];
+	nMos = MeasureToMosaic[i][m];
 	if (nMos == -1) continue;
 
@@ -641,9 +659,9 @@
     }
     imageOffset[i] = dM / NSlist[i];
-    // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[imlist[i][0]].name, dM, NSlist[i], imageOffset[i]);
+    // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[MosaicToImage[i][0]].name, dM, NSlist[i], imageOffset[i]);
   }
 
   // for (i = 0; i < Nmosaic; i++) {
-  //   fprintf (stderr, "correction: %s : %f\n", image[imlist[i][0]].name, imageOffset[i]);
+  //   fprintf (stderr, "correction: %s : %f\n", image[MosaicToImage[i][0]].name, imageOffset[i]);
   // } 
 
@@ -746,8 +764,8 @@
 
     N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
-
-      m = mlist[i][j];
-      c = clist[i][j];
+    for (j = 0; j < N_onMosaic[i]; j++) {
+
+      m = MosaicToMeasure[i][j];
+      c = MosaicToCatalog[i][j];
 
       Mcal = getMcal  (m, c);
@@ -872,5 +890,5 @@
   N = 0;
   for (i = 0; i < Nmosaic; i++) 
-    N = MAX (N, Nlist[i]);
+    N = MAX (N, N_onMosaic[i]);
 
   ALLOCATE (xlist, double, N);
@@ -881,8 +899,8 @@
     Xmin = Ymin = +360.0;
     Xmax = Ymax = -360.0;
-    for (j = 0; j < Nlist[i]; j++) {
+    for (j = 0; j < N_onMosaic[i]; j++) {
       
-      m = mlist[i][j];
-      c = clist[i][j];
+      m = MosaicToMeasure[i][j];
+      c = MosaicToCatalog[i][j];
       
       if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
@@ -959,9 +977,9 @@
 
   Imax = 0;
-  Nmax = Nimlist[0];
-  for (i = 0; i < Nmosaic; i++) {
-    if (Nimlist[i] > Nmax) {
+  Nmax = MosaicN_Image[0];
+  for (i = 0; i < Nmosaic; i++) {
+    if (MosaicN_Image[i] > Nmax) {
       Imax = i;
-      Nmax = Nimlist[i];
+      Nmax = MosaicN_Image[i];
     }
   }
@@ -969,4 +987,4 @@
   *refmosaic = &mosaic[Imax];
   *Nimage = Nmax;
-  return (imlist[Imax]);
-}
+  return (MosaicToImage[Imax]);
+}
