Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/Makefile
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/Makefile	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/Makefile	(revision 12276)
@@ -15,5 +15,5 @@
 FULL_CFLAGS   = $(BASE_CFLAGS)
 FULL_CPPFLAGS = $(BASE_CPPFLAGS)
-FULL_LDFLAGS  = -ldvo -lFITS -lohana $(BASE_LDFLAGS)
+FULL_LDFLAGS  = -lkapa -ldvo -lFITS -lohana $(BASE_LDFLAGS)
 
 relastro: $(BIN)/relastro.$(ARCH)
@@ -32,5 +32,4 @@
 $(SRC)/SetSignals.$(ARCH).o 	 \
 $(SRC)/Shutdown.$(ARCH).o 	 \
-$(SRC)/StarOps.$(ARCH).o	 \
 $(SRC)/UpdateChips.$(ARCH).o     \
 $(SRC)/UpdateMosaic.$(ARCH).o    \
@@ -41,5 +40,4 @@
 $(SRC)/dvo_astrom_ops.$(ARCH).o  \
 $(SRC)/fitpoly.$(ARCH).o         \
-$(SRC)/global_stats.$(ARCH).o	 \
 $(SRC)/initialize.$(ARCH).o	 \
 $(SRC)/liststats.$(ARCH).o	 \
@@ -49,4 +47,6 @@
 $(SRC)/plot_scatter.$(ARCH).o	 \
 $(SRC)/plotstuff.$(ARCH).o	 \
+$(SRC)/select_images.$(ARCH).o	 \
+$(SRC)/sort.$(ARCH).o	         \
 $(SRC)/relastro.$(ARCH).o	 \
 $(SRC)/reload_catalogs.$(ARCH).o \
@@ -56,4 +56,5 @@
 DROP = \
 $(SRC)/setMrelFinal.$(ARCH).o 	 \
+$(SRC)/StarOps.$(ARCH).o	 
 
 
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/include/relastro.h	(revision 12276)
@@ -107,8 +107,9 @@
 int    RELPHOT_GRID_BINNING;
 
-PhotCode      *photcode;
+char          *PHOTCODE_LIST;
+int           Nphotcodes;
+PhotCode     **photcodes;
 int            PhotPrimary;
 int            PhotNsec;
-int            PhotSec;
 
 int AreaSelect;
@@ -129,5 +130,4 @@
 
 SkyRegion UserPatch;
-int UserPatchSelect;
 
 int DoUpdateObjects;
@@ -189,5 +189,5 @@
 int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
 Catalog      *load_catalogs       PROTO((SkyList *skylist, int *Ncatalog));
-SkyList      *load_images         PROTO((FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect));
+SkyList      *load_images         PROTO((FITS_DB *db, SkyRegion *region));
 Image        *select_images       PROTO((SkyList *skylist, Image *timage, int Ntimage, int **LineNumber, int *Nimage));
 
@@ -272,5 +272,5 @@
 int FitPMandPar (PMFit *fit, double *X, double *dX, double *Y, double *dY, time_t *T, double *pR, double *pD, int Npts);
 
-Coords *getMosaicForImage (int N);
+Image *getMosaicForImage (int N);
 
 StarData *getImageRef (Catalog *catalog, int Ncatalog, int im, int *Nstars, int isMosaic);
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/ImageOps.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/ImageOps.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/ImageOps.c	(revision 12276)
@@ -77,13 +77,11 @@
 }
 
-/* select all image equivalent to the current photcode */
+/* match measurements to images */
 void findImages (Catalog *catalog, int Ncatalog) {
 
-  int i, j, ecode;
+  int i, j;
 
   for (i = 0; i < Ncatalog; i++) {
     for (j = 0; j < catalog[i].Nmeasure; j++) {
-      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
-      if (photcode[0].code != ecode) continue;
       matchImage (catalog, j, i);
     }
@@ -181,5 +179,6 @@
   int i, m, c;
 
-  Coords *mosaic;
+  Image *mosaic;
+  Coords *moscoords;
   StarData *raw;
   
@@ -187,6 +186,8 @@
 
   mosaic = NULL;
+  moscoords = NULL;
   if (isMosaic) {
     mosaic = getMosaicForImage (im);
+    moscoords = &mosaic[0].coords;
   }
 
@@ -205,6 +206,6 @@
     XY_to_LM (&raw[i].L, &raw[i].M, raw[i].X, raw[i].Y, &image[im].coords);
     if (isMosaic) {
-      XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, mosaic);
-      LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, mosaic);
+      XY_to_LM (&raw[i].P, &raw[i].Q, raw[i].L, raw[i].M, moscoords);
+      LM_to_RD (&raw[i].R, &raw[i].D, raw[i].P, raw[i].Q, moscoords);
     } else {
       raw[i].P = raw[i].L;
@@ -222,5 +223,6 @@
   int i, m, c, n;
 
-  Coords *mosaic;
+  Image *mosaic;
+  Coords *moscoords;
   StarData *ref;
   
@@ -228,6 +230,8 @@
 
   mosaic = NULL;
+  moscoords = NULL;
   if (isMosaic) {
     mosaic = getMosaicForImage (im);
+    moscoords = &mosaic[0].coords;
   }
 
@@ -244,6 +248,6 @@
     RD_to_LM (&ref[i].P, &ref[i].Q, ref[i].R, ref[i].D, &image[im].coords);
     if (isMosaic) {
-      LM_to_XY (&ref[i].M, &ref[i].L, ref[i].P, ref[i].Q, mosaic);
-      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, mosaic);
+      LM_to_XY (&ref[i].M, &ref[i].L, ref[i].P, ref[i].Q, moscoords);
+      LM_to_XY (&ref[i].X, &ref[i].Y, ref[i].L, ref[i].M, moscoords);
     } else {
       ref[i].L = ref[i].P;
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/MosaicOps.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/MosaicOps.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/MosaicOps.c	(revision 12276)
@@ -16,4 +16,5 @@
 
 /* find mosaic frames (unique time periods & photcode name matches mosaic) */
+/* XXX what is a mosaic?  do we need to use the 'DIS/WRP' info to track? */
 void initMosaics (Image *image, int Nimage) {
 
@@ -86,104 +87,5 @@
     }
   }
-
-  initMosaicGrid (image, Nimage);
   return;
-}
-
-void initMosaicGrid (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 = image[m].Xm = NO_MAG;
-    }
-    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;
-}
-
-void setMcalFinal () {
-
-  int i, j, im, Nimage;
-  Image *image;
-
-  if (!MOSAICNAME[0]) return;
-
-  image = getimages (&Nimage);
-
-  for (i = 0; i < Nmosaic; i++) {
-    for (j = 0; j < Nimlist[i]; j++) {
-      im = imlist[i][j];
-      image[im].Mcal = mosaic[i].Mcal;
-      image[im].dMcal = mosaic[i].dMcal;
-      image[im].Xm = mosaic[i].Xm;
-      image[im].code |= (mosaic[i].code & ID_IMAGE_FEW);
-      image[im].code |= (mosaic[i].code & ID_IMAGE_POOR);
-    }
-  }      
 }
 
@@ -238,5 +140,5 @@
 int findMosaics (Catalog *catalog, int Ncatalog) {
   
-  int i, j, ecode;
+  int i, j;
 
   if (!MOSAICNAME[0]) return (FALSE);
@@ -247,6 +149,4 @@
 	if (catalog[i].measure[j].t > TSTOP) continue;
       }
-      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
-      if (photcode[0].code != ecode) continue;
       matchMosaics (catalog, j, i);
     }
@@ -255,4 +155,5 @@
 }
 
+/* modify this function to use the measure->imageID field ? */
 void matchMosaics (Catalog *catalog, int meas, int cat) {
 
@@ -263,16 +164,4 @@
     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
-
     bin[cat][meas] = i;
 
@@ -288,273 +177,5 @@
     return;
   }
-  fprintf (stderr, "missed measurement\n");
   return;
-}
-
-float getMmos (int meas, int cat) {
-
-  int i;
-  float value;
-
-  if (!MOSAICNAME[0]) return (0);
-  i = bin[cat][meas];
-  if (i == -1) return (NO_MAG);
-
-  if (mosaic[i].code & IMAGE_BAD) return (NO_MAG);  
-  value = mosaic[i].Mcal;
-  return (value);
-}
-
-int setMmos (Catalog *catalog, int PoorImages) {
-
-  int i, j, m, c, n, N, Nmax, mark, bad;
-  float Msys, Mrel, Mcal, Mgrid;
-  double *list, *dlist, *Mlist, *dMlist;
-  StatType stats;
-  Image *image;
-
-  if (!MOSAICNAME[0]) return (FALSE);
-
-  image = getimages (&N);
-
-  if (PoorImages) {
-    IMAGE_BAD = 0;
-  }
-
-  Nmax = 0;
-  for (i = 0; i < Nmosaic; i++) {
-    Nmax = MAX (Nmax, Nlist[i]);
-  }
-  ALLOCATE (list, double, Nmax);
-  ALLOCATE (dlist, double, Nmax);
-  ALLOCATE (Mlist, double, Nmax);
-  ALLOCATE (dMlist, double, Nmax);
-
-  for (i = 0; i < Nmosaic; i++) {
-    
-    /* on PoorImages run, skip good images */
-    if (PoorImages) {
-      bad = mosaic[i].code & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
-      if (!bad) continue;
-    }      
-
-    N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
-      
-      m = mlist[i][j];
-      c = clist[i][j];
-      
-      if (catalog[c].measure[m].flags & MEAS_BAD) continue;
-      if ((Mcal  = getMcal  (m, c)) == NO_MAG) continue;
-      if ((Mgrid = getMgrid (m, c)) == NO_MAG) continue;
-      if ((Mrel  = getMrel  (catalog, m, c)) == NO_MAG) continue;
-      
-      n = catalog[c].measure[m].averef;
-      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
-      list[N]  = Msys - Mrel - Mcal - Mgrid;
-      dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
-      Mlist[N] = Msys;
-      dMlist[N] = list[N];
-      N++;
-    }
-    /* Nlist[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]);
-      if (mark) {
-	fprintf (stderr, "marked image %s (%d), (%d < %d) || (%d < %f*%d)\n", image[imlist[i][0]].name, i, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, Nlist[i]);
-	mosaic[i].code |= ID_IMAGE_FEW;
-      } else {
-	mosaic[i].code &= ~ID_IMAGE_FEW;
-      }
-    }
-    liststats (list, dlist, N, &stats);
-    if (PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
-    mosaic[i].Mcal  = stats.mean;
-    mosaic[i].dMcal = stats.sigma;
-    mosaic[i].Xm    = 100.0*log10(stats.chisq);
-  }
-  free (list);
-  free (dlist);
-  free (Mlist);
-  free (dMlist);
-
-  if (PoorImages) {
-    IMAGE_BAD = ID_IMAGE_POOR | ID_IMAGE_FEW | ID_IMAGE_SKIP;
-    STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
-    MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR | ID_MEAS_SKIP | ID_MEAS_AREA;
-  }
-  return (TRUE);
-}
-  
-StatType statsMosaicM (Catalog *catalog) {
-
-  int i, n;
-  double *list, *dlist;
-  StatType stats;
-
-  bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
-
-  ALLOCATE (list, double, Nmosaic);
-  ALLOCATE (dlist, double, Nmosaic);
-
-  n = 0;
-  for (i = 0; i < Nmosaic; i++) {
-    if (mosaic[i].code & IMAGE_BAD) continue;
-    list[n] = mosaic[i].Mcal;
-    dlist[n] = 1;
-    n++;
-  }
-
-  liststats (list, dlist, n, &stats);
-  free (list);
-  free (dlist);
-  return (stats);
-}
-
-StatType statsMosaicdM (Catalog *catalog) {
-
-  int i, n;
-  double *list, *dlist;
-  StatType stats;
-
-  bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
-
-  ALLOCATE (list, double, Nmosaic);
-  ALLOCATE (dlist, double, Nmosaic);
-
-  n = 0;
-  for (i = 0; i < Nmosaic; i++) {
-
-    if (mosaic[i].code & IMAGE_BAD) continue;
-    list[n] = mosaic[i].dMcal;
-    dlist[n] = 1;
-    n++;
-  }
-
-  liststats (list, dlist, n, &stats);
-  free (list);
-  free (dlist);
-  return (stats);
-}
-
-StatType statsMosaicN (Catalog *catalog) {
-
-  int i, j, m, c, n, N;
-  double *list, *dlist;
-  StatType stats;
-
-  bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
-
-  ALLOCATE (list, double, Nmosaic);
-  ALLOCATE (dlist, double, Nmosaic);
-
-  n = 0;
-  for (i = 0; i < Nmosaic; i++) {
-    if (mosaic[i].code & IMAGE_BAD)  continue;
-
-    N = 0;
-    for (j = 0; j < Nlist[i]; j++) {
-
-      m = mlist[i][j];
-      c = clist[i][j];
-
-      if (getMcal  (m, c) == NO_MAG) continue;
-      if (getMgrid (m, c) == NO_MAG) continue;
-      if (getMrel  (catalog, m, c) == NO_MAG) continue;
-      N++;
-    }
-    list[n] = N;
-    dlist[n] = 1;
-    n++;
-  }
-  fprintf (stderr, "Nmosaic: %d, n: %d\n", Nmosaic, n);
-
-  liststats (list, dlist, n, &stats);
-  free (list);
-  free (dlist);
-  return (stats);
-}
-
-StatType statsMosaicX (Catalog *catalog) {
-
-  int i, n;
-  double *list, *dlist;
-  StatType stats;
-
-  bzero (&stats, sizeof (StatType));
-  if (!MOSAICNAME[0]) return (stats);
-
-  ALLOCATE (list, double, Nmosaic);
-  ALLOCATE (dlist, double, Nmosaic);
-
-  n = 0;
-  for (i = 0; i < Nmosaic; i++) {
-
-    if (mosaic[i].code & IMAGE_BAD) continue;
-    list[n] = pow(10.0, 0.01*mosaic[i].Xm);
-    dlist[n] = 1;
-    n++;
-  }
-
-  liststats (list, dlist, n, &stats);
-  free (list);
-  free (dlist);
-  return (stats);
-}
-
-/* mark mosaic if: abs(Mcal - <Mcal>) too large, dMcal too large */
-void clean_mosaics () {
-
-  int i, N, mark, Nmark;
-  double *mlist, *slist, *dlist;
-  double MaxOffset, MedOffset, MaxScatter;
-  StatType stats;
-
-  if (!MOSAICNAME[0]) return;
-
-  if (VERBOSE) fprintf (stderr, "marking poor mosaics\n");
-
-  ALLOCATE (mlist, double, Nmosaic);
-  ALLOCATE (slist, double, Nmosaic);
-  ALLOCATE (dlist, double, Nmosaic);
-
-  for (i = N = 0; i < Nmosaic; i++) {
-    if (mosaic[i].code & IMAGE_BAD) continue;
-    mlist[N] = mosaic[i].Mcal;
-    slist[N] = mosaic[i].dMcal;
-    dlist[N] = 1;
-    N++;
-  }
-  initstats ("MEAN");
-  liststats (mlist, dlist, N, &stats);
-  MaxOffset = MAX (IMAGE_OFFSET, 2*stats.sigma);
-  MedOffset = stats.median;
-  liststats (slist, dlist, N, &stats);
-  MaxScatter = MAX (IMAGE_SCATTER, 2*stats.median);
-  fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
-  
-  Nmark = 0;
-  for (i = 0; i < Nmosaic; i++) {
-    mark = FALSE;
-    mark = (mosaic[i].dMcal > MaxScatter) || (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset);
-    if (mark) { 
-      Nmark ++;
-      mosaic[i].code |= ID_IMAGE_POOR;
-    } else {
-      mosaic[i].code &= ~ID_IMAGE_POOR;
-    }
-  }
-
-  fprintf (stderr, "%d mosaics marked poor\n", Nmark);
-  initstats (STATMODE);
-  free (mlist);
-  free (slist);
-  free (dlist);
 }
 
@@ -655,4 +276,12 @@
 }
 
+Image *getMosaicForImage (int Nim) {
+
+    Image *mosaic;
+
+    mosaic = NULL;
+    return mosaic;
+}
+
 int *SelectRefMosaic (Mosaic **refmosaic, int *Nimage) {
 
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/Shutdown.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/Shutdown.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/Shutdown.c	(revision 12276)
@@ -27,2 +27,4 @@
 }
 
+
+/* XXX this is probably not needed anymore : just protect the write statements */
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/args.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/args.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/args.c	(revision 12276)
@@ -34,10 +34,9 @@
   }
 
-  /* specify portion of the sky */
+  /* specify portion of the sky : allow default of all sky? */
   UserPatch.Rmin = 0;
   UserPatch.Rmax = 360;
   UserPatch.Dmin = -90;
   UserPatch.Dmax = +90;
-  UserPatchSelect = FALSE;
   if ((N = get_argument (argc, argv, "-region"))) {
     remove_argument (N, &argc, argv);
@@ -50,5 +49,13 @@
     UserPatch.Dmax = atof (argv[N]);
     remove_argument (N, &argc, argv);
-    UserPatchSelect = TRUE;
+  } else {
+    usage ();
+  }
+
+  PHOTCODE_LIST = NULL;
+  if ((N = get_argument (argc, argv, "-photcode"))) {
+    remove_argument (N, &argc, argv);
+    PHOTCODE_LIST = strcreate(argv[N]);
+    remove_argument (N, &argc, argv);
   }
 
@@ -72,4 +79,6 @@
   }
 
+# if (0)
+  /* XXX is this still relevant?? */
   strcpy (STATMODE, "CHI_INNER_WTMEAN");
   if ((N = get_argument (argc, argv, "-statmode"))) {
@@ -78,11 +87,5 @@
     remove_argument (N, &argc, argv);
   }
-
-  NLOOP = 8;
-  if ((N = get_argument (argc, argv, "-n"))) {
-    remove_argument (N, &argc, argv);
-    NLOOP = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-  }
+# endif
 
   RESET = FALSE;
@@ -104,4 +107,5 @@
   }
 
+  /* XXX update these for relevant plots */
   PlotMmin = 10.0; PlotMmax = 20.0; PlotdMmin = -1.0; PlotdMmax = 1.0;
   if ((N = get_argument (argc, argv, "-plrange"))) {
@@ -117,28 +121,5 @@
   }
 
-  /* group images by mosaic, find Mmos */
-  MOSAICNAME[0] = 0;
-  if ((N = get_argument (argc, argv, "-mosaic"))) {
-    remove_argument (N, &argc, argv);
-    strcpy (MOSAICNAME, argv[N]);
-    remove_argument (N, &argc, argv);
-  }
-
-  FREEZE_IMAGES = FALSE;
-  if ((N = get_argument (argc, argv, "-imfreeze"))) {
-    remove_argument (N, &argc, argv);
-    FREEZE_IMAGES = TRUE;
-  }
-
-  USE_GRID = FALSE;
-  if ((N = get_argument (argc, argv, "-grid"))) {
-    remove_argument (N, &argc, argv);
-    USE_GRID = TRUE;
-    if (!MOSAICNAME[0]) {
-      fprintf (stderr, "-grid is only valid with -mosaic\n");
-      exit (2);
-    }
-  }
-
+  /* XXX update this */
   MIN_ERROR = 0.001;
   if ((N = get_argument (argc, argv, "-minerror"))) {
@@ -195,4 +176,5 @@
   }
 
+  /* XXX drop this? */
   DophotSelect = FALSE;
   if ((N = get_argument (argc, argv, "-dophot"))) {
@@ -203,28 +185,22 @@
   }
 
-  if ( UserPatchSelect && (argc != 2)) usage ();
-  if (!UserPatchSelect && (argc != 3)) usage ();
-
+  if (argc != 1) usage ();
   return TRUE;
 }
 
 void usage () {
-  fprintf (stderr, "ERROR: USAGE: relphot (region) (photcode)\n");
-  fprintf (stderr, "       or:    relphot (photcode) -region RA RA DEC DEC\n");
-  fprintf (stderr, "  options: \n");
+  fprintf (stderr, "ERROR: USAGE: relastro -region RA RA DEC DEC\n");
+  fprintf (stderr, "  working options: \n");
   fprintf (stderr, "  -time (start) (stop)\n");
   fprintf (stderr, "  -v\n");
   fprintf (stderr, "  -plot\n");
   fprintf (stderr, "  -plotdelay (seconds)\n");
-  fprintf (stderr, "  -statmode (mode)\n");
-  fprintf (stderr, "  -n (nloop)\n");
-  fprintf (stderr, "  -reset\n");
   fprintf (stderr, "  -update\n");
   fprintf (stderr, "  -params\n");
-  fprintf (stderr, "  -mosaic (mosaic)\n");
-  fprintf (stderr, "  -imfreeze\n");
-  fprintf (stderr, "  -grid\n");
+  fprintf (stderr, "  -reset\n");
   fprintf (stderr, "  -area Xmin Xmax Ymin Ymax\n");
-  fprintf (stderr, "  -instmag min max\n");
+  fprintf (stderr, "  -instmag min max\n\n");
+  fprintf (stderr, "  planned options: \n");
+  fprintf (stderr, "  -photcode code[,code,code,..]\n");
   fprintf (stderr, "  \n");
   exit (2);
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/bcatalog.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/bcatalog.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/bcatalog.c	(revision 12276)
@@ -3,5 +3,5 @@
 int bcatalog (Catalog *subcatalog, Catalog *catalog) {
   
-  int i, j, offset, ecode;
+  int i, j, k, offset, found;
   int NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
   float mag;
@@ -37,7 +37,12 @@
       offset = catalog[0].average[i].offset + j;
 
-      /* select measurements by photcode */
-      ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode);
-      if (ecode != photcode[0].code) continue;
+      /* select measurements by photcode, if specified */
+      if (Nphotcodes > 0) {
+	found = FALSE;
+	for (k = 0; (k < Nphotcodes) && !found; k++) {
+	  if (photcodes[k][0].code == catalog[0].measure[offset].photcode) found = TRUE;
+	}
+	if (!found) continue;
+      }
 
       /* select measurements by time */
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/initialize.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/initialize.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/initialize.c	(revision 12276)
@@ -3,21 +3,33 @@
 void initialize (int argc, char **argv) {
 
-  int N;
+  int NPHOTCODES;
+  char *codename, *ptr;
 
   ConfigInit (&argc, argv);
   args (argc, argv);
 
-  N = UserPatchSelect ? 1 : 2;
-  if ((photcode = GetPhotcodebyName (argv[N])) == NULL) {
-    fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
-    exit (1);
+  /* XXX we need to build a list of accepted photcodes. these will be used by bcatalog to accept or
+     reject loaded data */
+
+  Nphotcodes = 0;
+  photcodes = NULL;
+  if (PHOTCODE_LIST != NULL) {
+    NPHOTCODES = 10;
+    ALLOCATE (photcodes, PhotCode *, NPHOTCODES);
+
+    /* parse the comma-separated list of photcodes */
+    strtok_r (PHOTCODE_LIST, ",", &ptr);
+    while ((codename = strtok_r (NULL, ",", &ptr)) != NULL) {
+      fprintf (stderr, "PHOTCODE_LIST: %s\n", PHOTCODE_LIST);
+      fprintf (stderr, "codename: %s\n", codename);
+      if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) {
+	fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
+	exit (1);
+      }
+      Nphotcodes ++;
+      CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10);
+    }
   }
-  if (photcode[0].type != PHOT_SEC) {
-    fprintf (stderr, "photcode %s is not a primary or secondary filter\n", argv[N]);
-    exit (1);
-  }
-
   PhotNsec = GetPhotcodeNsecfilt ();
-  PhotSec = GetPhotcodeNsec (photcode[0].code);
 
   initstats (STATMODE);
@@ -27,4 +39,5 @@
   MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR | ID_MEAS_SKIP | ID_MEAS_AREA;
 
+  /* XXX drop irrelevant entries */
   if (SHOW_PARAMS) {
     fprintf (stderr, "current parameter settings:\n");
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/load_images.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/load_images.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/load_images.c	(revision 12276)
@@ -1,8 +1,8 @@
 # include "relastro.h"
 
-SkyList *load_images (FITS_DB *db, char *regionName, SkyRegion *region, int RegionSelect) {
+SkyList *load_images (FITS_DB *db, SkyRegion *region) {
 
   Image     *image, *subset;
-  int        Nimage, Nsubset, Nchar;
+  int        Nimage, Nsubset;
   int       *LineNumber;
 
@@ -15,11 +15,5 @@
   
   // determine the populated SkyRegions overlapping the requested area
-  if (RegionSelect) {
-    skylist = SkyListByPatch (sky, -1, region);
-  } else {
-    Nchar = strlen(regionName);
-    if (!strcmp (&regionName[Nchar-4], ".cpt")) regionName[Nchar-4] = 0;
-    skylist = SkyListByName (sky, regionName);
-  }
+  skylist = SkyListByPatch (sky, -1, region);
 
   // convert database table to internal structure
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/plot_scatter.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/plot_scatter.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/plot_scatter.c	(revision 12276)
@@ -3,4 +3,5 @@
 void plot_scatter (Catalog *catalog, int Ncatalog) {
 
+# if (0)   
   int i, j, k, m, N, Ntot;
   float Mrel, Mcal, Mmos, Mgrid;
@@ -28,7 +29,4 @@
       for (k = 0; k < catalog[i].average[j].Nm; k++, m++) {
 	if (catalog[i].measure[m].flags & MEAS_BAD) continue;
-	if ((Mcal  = getMcal  (m, i)) == NO_MAG) continue;
-	if ((Mmos  = getMmos  (m, i)) == NO_MAG) continue;
-	if ((Mgrid = getMgrid (m, i)) == NO_MAG) continue;
 
 	Mrel = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
@@ -55,3 +53,7 @@
   free (ylist);
   free (ilist);
+
+# endif
 }
+
+/* XXX this should become astrometrically relevant */
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/relastro.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/relastro.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/relastro.c	(revision 12276)
@@ -22,8 +22,5 @@
 
   /* load regions and images based on specified sky patch */
-  // XXX need to mimic old-style load by passing patch name
-  // XXX need to reduce number of global variables in use.
-  // XXX this is fairly lame: argv[1] is photcode if UserPatchSelect is true
-  skylist = load_images (&db, argv[1], &UserPatch, UserPatchSelect);
+  skylist = load_images (&db, &UserPatch);
 
   /* load catalog data from region files */
@@ -38,5 +35,5 @@
 
   if (PLOTSTUFF) {
-    plot_star_coords (catalog, Ncatalog);
+    // plot_star_coords (catalog, Ncatalog);
     plot_mosaic_fields (catalog);
   }
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/reload_catalogs.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/reload_catalogs.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/reload_catalogs.c	(revision 12276)
@@ -38,10 +38,8 @@
     initImageBins  (&catalog, 1);
     initMosaicBins (&catalog, 1);
-    initGridBins   (&catalog, 1);
 
     findImages (&catalog, 1);
     findMosaics (&catalog, 1);
 
-    setMrelFinal (&catalog);
     dvo_catalog_save (&catalog, VERBOSE); 
     dvo_catalog_unlock (&catalog);
@@ -50,5 +48,4 @@
     freeImageBins (1);
     freeMosaicBins (1);
-    freeGridBins (1);
   }
 }
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/select_images.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/select_images.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/select_images.c	(revision 12276)
@@ -17,5 +17,5 @@
   Image *image;
   int i, j, k, m, found, nimage, NIMAGE;
-  int InRange, ecode;
+  int InRange;
   double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
   int *line_number;
@@ -75,7 +75,12 @@
   for (i = 0; i < Ntimage; i++) {
       
-    /* exclude images by photcode */
-    ecode = GetPhotcodeEquivCodebyCode (timage[i].photcode);
-    if (ecode != photcode[0].code) continue;
+    /* exclude images by photcode, if selected */
+    if (Nphotcodes > 0) {
+      found = FALSE;
+      for (j = 0; (j < Nphotcodes) && !found; j++) {
+	if (photcodes[j][0].code == timage[i].photcode) found = TRUE;
+      }
+      if (!found) continue;
+    }
 
     /* exclude images by time */
Index: /branches/dvo-mods-2007-02/Ohana/src/relastro/src/setExclusions.c
===================================================================
--- /branches/dvo-mods-2007-02/Ohana/src/relastro/src/setExclusions.c	(revision 12275)
+++ /branches/dvo-mods-2007-02/Ohana/src/relastro/src/setExclusions.c	(revision 12276)
@@ -4,5 +4,5 @@
 int setExclusions (Catalog *catalog, int Ncatalog) {
 
-  int i, j, k, m, Narea, Nnocal, ecode;
+  int i, j, k, m, Narea, Nnocal;
   Coords *coords;
   double r, d, x, y;
@@ -15,6 +15,7 @@
 
 	/* select measurements by photcode */
-	ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
-	if (ecode != photcode[0].code) goto mark_nocal;
+	// XXXX is this done when loaded, or is it needed for reload?
+	// ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
+	// if (ecode != photcode[0].code) goto mark_nocal;
 	
 	/* select measurements by time */
