Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 10938)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 10939)
@@ -41,4 +41,5 @@
 $(SRC)/fakeimage.$(ARCH).o \
 $(SRC)/find_matches.$(ARCH).o \
+$(SRC)/find_matches_closest.$(ARCH).o \
 $(SRC)/find_matches_refstars.$(ARCH).o \
 $(SRC)/find_subset.$(ARCH).o \
@@ -71,5 +72,4 @@
 
 # $(SRC)/gimages.$(ARCH).o \
-# $(SRC)/find_matches_closest.$(ARCH).o \
 
 ADDSTARD = \
@@ -107,4 +107,5 @@
 $(SRC)/getusno.$(ARCH).o \
 $(SRC)/getusnob.$(ARCH).o \
+$(SRC)/ImageOptions.$(ARCH).o \
 $(SRC)/gimages.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
@@ -118,4 +119,5 @@
 ADDSTART = \
 $(SRC)/addstart.$(ARCH).o \
+$(SRC)/ImageOptions.$(ARCH).o \
 $(SRC)/DatasetOps.$(ARCH).o \
 $(SRC)/SocketOps.$(ARCH).o \
@@ -163,4 +165,5 @@
 ADDSTARC = \
 $(SRC)/addstarc.$(ARCH).o \
+$(SRC)/airmass.$(ARCH).o \
 $(SRC)/SocketOps.$(ARCH).o \
 $(SRC)/ConfigInit.$(ARCH).o \
@@ -168,7 +171,10 @@
 $(SRC)/grefstars.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
-$(SRC)/rfits.$(ARCH).o \
 $(SRC)/parse_time.$(ARCH).o \
-$(SRC)/rtext.$(ARCH).o \
+$(SRC)/ReadStarsFITS.$(ARCH).o \
+$(SRC)/GetFileMode.$(ARCH).o \
+$(SRC)/ReadImageHeader.$(ARCH).o \
+$(SRC)/ReadStarsTEXT.$(ARCH).o \
+$(SRC)/FilterStars.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
 $(SRC)/SetSignals.$(ARCH).o \
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 10938)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 10939)
@@ -25,5 +25,6 @@
   int Nstars;
   Stars *stars;
-  Image *image;
+  int Nimages;
+  Image *images;
   Coords *mosaic;
   SkyRegion *patch;
@@ -202,5 +203,5 @@
 int 	   WaitServerSocket	  PROTO((int InitSocket, SockAddress *Address, int *validIP, int Nvalid));
 int 	   GetClientSocket	  PROTO((char *hostname));
-int 	   UpdateDatabase_Image	  PROTO((AddstarClientOptions *options, Image *image, Coords *mosaic, Stars *stars, int Nstars));
+int 	   UpdateDatabase_Image	  PROTO((AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, int Nstars));
 int 	   UpdateDatabase_Reflist PROTO((AddstarClientOptions *options, Stars *stars, int Nstars));
 int 	   UpdateDatabase_Refcat  PROTO((AddstarClientOptions *options, SkyRegion *UserPatch, char *refcat));
Index: /trunk/Ohana/src/addstar/src/NewImage.c
===================================================================
--- /trunk/Ohana/src/addstar/src/NewImage.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/NewImage.c	(revision 10939)
@@ -3,7 +3,7 @@
 int NewImage (int BindSocket) {
 
-  int N, Nstars;
+  int N, Nstars, Nimages;
   Stars *stars;
-  Image *image;
+  Image *images;
   Coords *mosaic;
   AddstarClientOptions *options;
@@ -19,10 +19,6 @@
   }
 
-  if (!Recv_Image (BindSocket, &image, &N)) {
+  if (!Recv_Image (BindSocket, &images, &Nimages)) {
     fprintf (stderr, "error: problem receiving image data\n");
-    goto reject;
-  }
-  if (N != 1) {
-    fprintf (stderr, "error: invalid number of images (%d)\n", N);
     goto reject;
   }
@@ -43,8 +39,8 @@
     goto reject;
   }
-  fprintf (stderr, "accepted %s, %d stars\n", image[0].name, Nstars);
+  fprintf (stderr, "accepted %d images, %d stars\n", Nimages, Nstars);
 
   /* add to db */
-  UpdateDatabase_Image (options, image, mosaic, stars, Nstars);
+  UpdateDatabase_Image (options, images, Nimages, mosaic, stars, Nstars);
 
   close (BindSocket);
Index: /trunk/Ohana/src/addstar/src/NewImage_Thread.c
===================================================================
--- /trunk/Ohana/src/addstar/src/NewImage_Thread.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/NewImage_Thread.c	(revision 10939)
@@ -3,7 +3,7 @@
 int NewImage_Thread (int BindSocket) {
 
-  int N, Nstars;
+  int N, Nstars, Nimages;
   Stars *stars;
-  Image *image;
+  Image *images;
   Coords *mosaic;
   AddstarClientOptions *options;
@@ -20,10 +20,6 @@
   }
 
-  if (!Recv_Image (BindSocket, &image, &N)) {
+  if (!Recv_Image (BindSocket, &images, &Nimages)) {
     fprintf (stderr, "error: problem receiving image data\n");
-    goto reject;
-  }
-  if (N != 1) {
-    fprintf (stderr, "error: invalid number of images (%d)\n", N);
     goto reject;
   }
@@ -44,5 +40,5 @@
     goto reject;
   }
-  fprintf (stderr, "accepted %s, %d stars\n", image[0].name, Nstars);
+  fprintf (stderr, "accepted %d, %d stars\n", Nimages, Nstars);
 
   /* create new dataset to store the incoming data */
@@ -51,5 +47,6 @@
   dataset[0].patch   = NULL;
   dataset[0].refcat  = NULL;
-  dataset[0].image   = image;
+  dataset[0].images  = images;
+  dataset[0].Nimages = Nimages;
   dataset[0].mosaic  = mosaic;
   dataset[0].stars   = stars;
Index: /trunk/Ohana/src/addstar/src/NewRefcat_Thread.c
===================================================================
--- /trunk/Ohana/src/addstar/src/NewRefcat_Thread.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/NewRefcat_Thread.c	(revision 10939)
@@ -43,5 +43,5 @@
   dataset[0].patch   = patch;
   dataset[0].refcat  = message.buffer;
-  dataset[0].image   = NULL;
+  dataset[0].images  = NULL;
   dataset[0].mosaic  = NULL;
   dataset[0].stars   = NULL;
Index: /trunk/Ohana/src/addstar/src/NewReflist_Thread.c
===================================================================
--- /trunk/Ohana/src/addstar/src/NewReflist_Thread.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/NewReflist_Thread.c	(revision 10939)
@@ -29,5 +29,5 @@
   dataset[0].patch   = NULL;
   dataset[0].refcat  = NULL;
-  dataset[0].image   = NULL;
+  dataset[0].images  = NULL;
   dataset[0].mosaic  = NULL;
   dataset[0].stars   = stars;
Index: /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c
===================================================================
--- /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 10939)
@@ -1,10 +1,10 @@
 # include "addstar.h"
 
-int UpdateDatabase_Image (AddstarClientOptions *options, Image *image, Coords *mosaic, Stars *stars, int Nstars) {
+int UpdateDatabase_Image (AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, int Nstars) {
 
   int i, Noverlap, status;
   Image *overlap;
   Catalog catalog;
-  SkyList *skylist;
+  SkyList *skylist, *newlist;
 
   if (options[0].mode != M_IMAGE) {
@@ -16,20 +16,6 @@
   if (options[0].update) catalog.catflags = LOAD_AVES | LOAD_MEAS_META | LOAD_MISS | LOAD_SECF;
   
+  // XXX this is probably not needed anymore
   SetAirmassQuality (options[0].quality_airmass);
-
-  /*** find image overlaps, if needed ***/
-  Noverlap = 0;
-  overlap = NULL;
-  if (!options[0].skip_missed) { 
-    FITS_DB db;
-
-    set_db (&db);
-    status = dvo_image_lock (&db, ImageCat, 60.0, LCK_SOFT);
-    if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
-
-    /* load images / build overlap : XXX EAM : split into two functions? */
-    overlap = gimages (&db, image, mosaic, &Noverlap);
-    dvo_image_unlock (&db);
-  }
 
   /*** update catalog: average, measure, etc ***/
@@ -37,5 +23,13 @@
   /* find correpsonding regions for image */
   RegisterMosaic (mosaic);
-  skylist = SkyListByImage (ServerSky, -1, image);
+  skylist = NULL;
+  newlist = NULL;
+  for (i = 0; i < Nimages; i++) {
+      newlist = SkyListByImage (ServerSky, -1, &images[i]);
+      SkyListMerge (&skylist, newlist);
+      SkyListFree (newlist, FALSE);
+  }
+
+  ImageOptions (options, images, Nimages);
 
   /* reduce regions to existing subset, if necessary */
@@ -73,7 +67,7 @@
 
     if (options[0].closest) {
-      find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, image, overlap, Noverlap, mosaic, options[0]);
+      find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, options[0]);
     } else {
-      find_matches (skylist[0].regions[i], stars, Nstars, &catalog, image, overlap, Noverlap, mosaic, options[0]);
+      find_matches (skylist[0].regions[i], stars, Nstars, &catalog, options[0]);
     }
 
@@ -87,5 +81,5 @@
   }
 
-  if (options[0].calibrate) { FindCalibration (image); }
+  if (options[0].calibrate) { FindCalibration (&images[0]); }
   
   /*** load image db, save new image ***/
@@ -93,16 +87,23 @@
     FITS_DB db;
 
-    set_db (&db);
-
+    /*** update the image table ***/
+    /* setup image table format and lock */
+    db.mode   = dvo_catalog_catmode (CATMODE);
+    db.format = dvo_catalog_catformat (CATFORMAT);
     status = dvo_image_lock (&db, ImageCat, 60.0, LCK_XCLD);
     if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
 
-    /* load images / build overlap : XXX EAM : split into two functions? */
-    overlap = gimages (&db, image, mosaic, &Noverlap);
+    /* load or create the image table */
+    if (db.dbstate == LCK_EMPTY) {
+      if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
+      dvo_image_create (&db, ZeroPt);
+    } else {
+      if (!dvo_image_load (&db, VERBOSE, FORCE_READ)) {
+	Shutdown ("can't read image catalog %s", db.filename);
+      }
+    }
 
-    if (db.dbstate == LCK_EMPTY) dvo_image_create (&db, ZeroPt);
-  
     /* write out new image */
-    dvo_image_addrows (&db, image, 1);
+    dvo_image_addrows (&db, images, Nimages);
     SetProtect (TRUE);
     dvo_image_update (&db, VERBOSE);
@@ -111,5 +112,5 @@
   }
   free (mosaic);
-  free (image);
+  free (images);
   free (stars);
   return (TRUE);
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 10939)
@@ -103,5 +103,5 @@
 	Nsubset = Nstars;
 	if (options.closest) {
-	  // Nmatch += find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, options);
+	  Nmatch += find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, options);
 	} else {
 	  Nmatch += find_matches (skylist[0].regions[i], stars, Nstars, &catalog, options);
Index: /trunk/Ohana/src/addstar/src/addstarc.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstarc.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/addstarc.c	(revision 10939)
@@ -3,9 +3,9 @@
 int main (int argc, char **argv) {
 
-  int Nstars;
+  int Nstars, Nimages;
   int BindSocket;
   AddstarClientOptions options;
   Stars *stars;
-  Image image;
+  Image *images;
 
   /* load config and options */
@@ -21,10 +21,10 @@
     case M_IMAGE:
       /* load data */
-      stars = gstars (argv[1], &Nstars, options.photcode, &image);
+      stars = gstars (argv[1], &Nstars, &images, &Nimages, options.photcode);
 
       /* send data to server */
       SendCommand (BindSocket, 5, "IMAGE");
       Send_AddstarClientOptions (BindSocket, &options, 1, TRUE);
-      Send_Image (BindSocket, &image, 1, FALSE);
+      Send_Image (BindSocket, images, Nimages, FALSE);
       if (options.mosaic) {
 	Send_Coords (BindSocket, MOSAIC, 1, FALSE);
Index: /trunk/Ohana/src/addstar/src/addstart.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstart.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/addstart.c	(revision 10939)
@@ -32,5 +32,5 @@
     switch (dataset[0].options[0].mode) {
       case M_IMAGE:
-	UpdateDatabase_Image (dataset[0].options, dataset[0].image, dataset[0].mosaic, dataset[0].stars, dataset[0].Nstars);
+	UpdateDatabase_Image (dataset[0].options, dataset[0].images, dataset[0].Nimages, dataset[0].mosaic, dataset[0].stars, dataset[0].Nstars);
 	continue;
 
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 10939)
@@ -10,5 +10,5 @@
   int Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt, Nsec;
-  float Mcat, *Mval, MTIME;
+  float Mcat, *Mval;
   PhotCode *code;
   Coords tcoords;
@@ -98,5 +98,13 @@
   /** find matched stars **/
   for (i = j = 0; (i < Nstars) && (j < Nave); ) {
-    
+        if (!finite(X1[i]) || !finite(Y1[i])) { 
+      i++; 
+      continue;
+    }
+    if (!finite(X2[j]) || !finite(Y2[j])) { 
+      j++; 
+      continue;
+    }
+
     /* negative dX: j is too large */
     dX = X1[i] - X2[j];
@@ -273,5 +281,5 @@
     catalog[0].measure[Nmeas].airmass_PS  = stars[N].airmass;
 
-    catalog[0].measure[Nmeas].Mgal_PS  	  = MIN (stars[N].Mgal + MTIME, NO_MAG);
+    catalog[0].measure[Nmeas].Mgal_PS  	  = stars[N].Mgal;
     catalog[0].measure[Nmeas].FWx      	  = MIN (100*stars[N].fx, NO_MAG);
     catalog[0].measure[Nmeas].FWy      	  = MIN (100*stars[N].fy, NO_MAG);
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 10938)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 10939)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-int find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
+int find_matches_closest (SkyRegion *region, Stars *stars, int NstarsIn, Catalog *catalog, AddstarClientOptions options) {
 
   int i, j, n, N, J, Jmin, status, Nstars;
@@ -14,11 +14,8 @@
   PhotCode *code;
 
-  /* XXX EAM : options.photcode overridden by image.source.... */
-  code = GetPhotcodebyCode (image[0].source);
-
-  /* photcode data - must by of type DEP, (PRI, SEC) - probably should restrict to DEP */
+  /* photcode data - must by of type DEP; options.photcode is equiv PRI/SEC photcode */
+  /* this function requires incoming stars to have the same photcode.equiv value */
   Nsecfilt = GetPhotcodeNsecfilt ();
-  Nsec = (code[0].type == PHOT_DEP) ? GetPhotcodeNsec (code[0].equiv) : GetPhotcodeNsec (code[0].code);
-  /* this function requires incoming stars to have the same photcode */
+  Nsec     = GetPhotcodeNsec (options.photcode);
 
   /** allocate local arrays (stars) **/
@@ -41,25 +38,22 @@
 
   /* project onto rectilinear grid with 1 arcsec pixels. the choice of ZEA projection has the
-     advantage that every point in R,D has a mapping to a unique X,Y.  However, note that not all
-     possible X,Y points map back to R,D and the local plate scale changes substantially far from
-     the projection pole.  a better mapping might be ARC, not yet implemented (see
-     coordops.update.c).  We keep the original crpix1,2 and crref1,2.  For mosaic astrometry, the
-     grid should be w.r.t. the tangent-plane, not chip coords */
-
-  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
-    tcoords = mosaic[0];
-    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
-    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
-    tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---ZEA");
+   * advantage that every point in R,D has a mapping to a unique X,Y.  However, note that not all
+   * possible X,Y points map back to R,D and the local plate scale changes substantially far from
+   * the projection pole.  a better mapping might be ARC, not yet implemented (see
+   * coordops.update.c).  We use the center of the region (catalog) for crval1,2. 
+   */
+  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
+  if (region[0].Rmax < 90) {
+    tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
   } else {
-    tcoords = image[0].coords;
-    tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
-    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
-    tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "RA---ZEA");
-  }
+    tcoords.crval2 = 90.0;
+  }
+  tcoords.crpix1 = 0;
+  tcoords.crpix2 = 0;
+  tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
+  tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
+  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
+  tcoords.Npolyterms = 1;
+  strcpy (tcoords.ctype, "RA---ZEA");
 
   /* build spatial index (RA sort) referencing input array sequence */
@@ -80,5 +74,5 @@
     free (Y2);
     free (N2);
-    return;
+    return (0);
   }
   if (Nstars > 1) sort_lists (X1, Y1, N1, Nstars);
@@ -102,13 +96,6 @@
 
   /* choose a radius for matches */
-  if (options.radius == 0) {
-    RADIUS = options.Nsigma * 0.02 * image[0].cerror;  /* 0.02 corrects cerror to arcsec from storage units */
-  } else {
-    RADIUS = options.radius; /* provided by config */
-  }
+  RADIUS = options.radius; /* provided by config */
   RADIUS2 = RADIUS*RADIUS;
-
-  /* correct instrumental mags for exposure time */
-  MTIME = (image[0].exptime > 0) ? 2.500*log10(image[0].exptime) : 0.0;
 
   /** find matched stars **/
@@ -170,9 +157,5 @@
     /* add to end of measurement list */
     add_meas_link (&catalog[0].average[n], next_meas, Nmeas, NMEAS);
-    ohana_memcheck (0);
 	
-    /* calculate accurate per-star airmass, if required */
-    secz = airmass (image[0].secz_PS, stars[N].R, stars[N].D, image[0].sidtime, image[0].latitude);
-      
     /** add measurements for this star **/
     /** dR,dD now represent arcsec **/
@@ -196,16 +179,16 @@
     }
     catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N].D);
-    catalog[0].measure[Nmeas].M_PS        = MIN (stars[N].M + MTIME, NO_MAG);
-    catalog[0].measure[Nmeas].dM_PS       = MIN (stars[N].dM, NO_ERR);  /* error in input files stored in thousandths of mag */
-    catalog[0].measure[Nmeas].Mcal_PS     = image[0].Mcal_PS;
-    catalog[0].measure[Nmeas].t           = image[0].tzero + 1e-4*stars[N].Y*image[0].trate;  /* trate is in 0.1 msec / row */
+    catalog[0].measure[Nmeas].M_PS        = stars[N].M;
+    catalog[0].measure[Nmeas].dM_PS       = stars[N].dM;  /* error in input files stored in thousandths of mag */
+    catalog[0].measure[Nmeas].Mcal_PS     = stars[N].Mcal;
+    catalog[0].measure[Nmeas].t           = stars[N].t;
     catalog[0].measure[Nmeas].averef      = n;
     catalog[0].measure[Nmeas].source      = stars[N].code;  /* photcode */
     catalog[0].measure[Nmeas].dophot      = stars[N].dophot;  
     catalog[0].measure[Nmeas].flags       = 0;
-    catalog[0].measure[Nmeas].dt_PS       = MTIME;
-    catalog[0].measure[Nmeas].airmass_PS  = secz;
-
-    catalog[0].measure[Nmeas].Mgal_PS     = MIN (stars[N].Mgal + MTIME, NO_MAG);
+    catalog[0].measure[Nmeas].dt_PS       = stars[N].dt;
+    catalog[0].measure[Nmeas].airmass_PS  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].Mgal_PS     = stars[N].Mgal;
     catalog[0].measure[Nmeas].FWx         = MIN (100*stars[N].fx, NO_MAG);
     catalog[0].measure[Nmeas].FWy         = MIN (100*stars[N].fy, NO_MAG);
@@ -234,30 +217,4 @@
     Nmeas ++;
     i++;
-    ohana_memcheck (0);
-  }
-  ohana_memcheck (0);
-
-  /** add reference for undetected catalog stars **/
-  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) RegisterMosaic (mosaic);
-  for (j = 0; (j < Nave) && !options.skip_missed; j++) {
-    n = N2[j];
-    if (catalog[0].found[n] < 0) { 
-      /* make sure there is space for next entry */
-      if (Nmiss >= NMISS) {
-	NMISS = Nmiss + 1000;
-	REALLOCATE (next_miss, int, NMISS);
-	REALLOCATE (catalog[0].missing, Missing, NMISS);
-      }
-
-      /* should the catalog star be on this image? project into image coords */
-      if (!in_image (catalog[0].average[n].R, catalog[0].average[n].D, image)) continue;
-      add_miss_link (&catalog[0].average[n], next_miss, Nmiss);
-
-      /* calculate time of exposure for this coordinate in the image */
-      RD_to_XY (&X, &Y, catalog[0].average[n].R, catalog[0].average[n].D, &image[0].coords);	  
-      catalog[0].missing[Nmiss].t  = image[0].tzero + 1e-4*Y*image[0].trate;  /* trate is in 0.1 msec / row */
-      catalog[0].average[n].Nn ++;
-      Nmiss ++;
-    }
   }
 
@@ -279,7 +236,5 @@
     N = N1[i];
     if (stars[N].found >= 0) continue;
-    if (!IN_CATALOG (stars[N].R, stars[N].D)) continue;
-
-    secz = airmass (image[0].secz_PS, stars[N].R, stars[N].D, image[0].sidtime, image[0].latitude);
+    if (!IN_REGION (stars[N].R, stars[N].D)) continue;
 
     catalog[0].average[Nave].R         = stars[N].R;
@@ -313,16 +268,16 @@
     catalog[0].measure[Nmeas].dR_PS       = 0.0;
     catalog[0].measure[Nmeas].dD_PS       = 0.0;
-    catalog[0].measure[Nmeas].M_PS        = MIN (stars[N].M + MTIME, NO_MAG);
-    catalog[0].measure[Nmeas].dM_PS       = MIN (stars[N].dM, NO_ERR);
-    catalog[0].measure[Nmeas].Mcal_PS  	  = image[0].Mcal_PS;
-    catalog[0].measure[Nmeas].t        	  = image[0].tzero + 1e-4*stars[N].Y*image[0].trate; /* trate is in 0.1 msec / row */
+    catalog[0].measure[Nmeas].M_PS        = stars[N].M;
+    catalog[0].measure[Nmeas].dM_PS       = stars[N].dM;
+    catalog[0].measure[Nmeas].Mcal_PS  	  = stars[N].Mcal;
+    catalog[0].measure[Nmeas].t        	  = stars[N].t;
     catalog[0].measure[Nmeas].averef   	  = Nave;
     catalog[0].measure[Nmeas].source   	  = stars[N].code;  /* photcode */
     catalog[0].measure[Nmeas].dophot   	  = stars[N].dophot;  
     catalog[0].measure[Nmeas].flags    	  = 0;
-    catalog[0].measure[Nmeas].dt_PS    	  = MTIME;
-    catalog[0].measure[Nmeas].airmass_PS  = secz;
-
-    catalog[0].measure[Nmeas].Mgal_PS  	  = MIN (stars[N].Mgal + MTIME, NO_MAG);
+    catalog[0].measure[Nmeas].dt_PS    	  = stars[N].dt;
+    catalog[0].measure[Nmeas].airmass_PS  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].Mgal_PS  	  = stars[N].Mgal;
     catalog[0].measure[Nmeas].FWx      	  = MIN (100*stars[N].fx, NO_MAG);
     catalog[0].measure[Nmeas].FWy      	  = MIN (100*stars[N].fy, NO_MAG);
@@ -332,23 +287,4 @@
     Mval = (Nsec == -1) ? &catalog[0].average[Nave].M : &catalog[0].secfilt[Nave*Nsecfilt+Nsec].M_PS;
     if (*Mval == NO_MAG) *Mval = Mcat;
-
-    /** now add references from all previous non-detection observations of this spot on the sky */
-    for (j = 0; (j < Noverlap) && !options.skip_missed; j++) {
-      /* make sure there is space for next entry */
-      if (Nmiss >= NMISS) {
-	NMISS = Nmiss + 1000;
-	REALLOCATE (next_miss, int, NMISS);
-	REALLOCATE (catalog[0].missing, Missing, NMISS);
-      }
-      if (!FindMosaicForImage (overlap, Noverlap, j)) continue;
-      if (!in_image (catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j])) continue;
-      add_miss_link (&catalog[0].average[Nave], next_miss, Nmiss);
-
-      /* get time of exposure of this portion of the image */
-      RD_to_XY (&X, &Y, catalog[0].average[Nave].R, catalog[0].average[Nave].D, &overlap[j].coords);	  
-      catalog[0].missing[Nmiss].t  = overlap[j].tzero + 1e-4*Y*overlap[j].trate;  /* rough guess at time */
-      catalog[0].average[Nave].Nn ++;
-      Nmiss ++;
-    }
 
     /* next[Nmeas] should always be -1 in this context (it is always the only
@@ -362,5 +298,4 @@
   REALLOCATE (catalog[0].average, Average, Nave);
   REALLOCATE (catalog[0].measure, Measure, Nmeas);
-  REALLOCATE (catalog[0].missing, Missing, Nmiss);
  
   if (options.nosort) {
@@ -370,6 +305,4 @@
     catalog[0].measure = sort_measure (catalog[0].average, Nave, catalog[0].measure, Nmeas, next_meas);
   }
-  catalog[0].missing = sort_missing (catalog[0].average, Nave, catalog[0].missing, Nmiss, next_miss);
-  /* missing is REQUIRED to be sorted */
 
   /* note stars which have been found in this catalog */
@@ -385,6 +318,5 @@
   catalog[0].Naverage = Nave;
   catalog[0].Nmeasure = Nmeas;
-  catalog[0].Nmissing = Nmiss;
-  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nmiss: %d %d %d %d, (%d matches)\n", NstarsIn, Nave, Nmeas, Nmiss, Nmatch);
+  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas: %d %d %d, (%d matches)\n", Nstars, Nave, Nmeas, Nmatch);
 
   free (catalog[0].found);
