Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/Makefile	(revision 38542)
@@ -37,11 +37,28 @@
 mkcmf        : $(BIN)/mkcmf.$(ARCH)
 
-all: addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
-
-INSTALL = addstar addstar_client sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
+old: addstar_client
+all: addstar sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
+
+INSTALL = addstar sedstar load2mass loadstarpar loadstarpar_client loadICRF loadICRF_client skycells mkcmf loadwise loadtycho loadsupercos dumpskycells findskycell
 
 # I need to fix the client/server version of addstar now that I have dropped Stars
 # as an autocode type and have converted to carrying average and measure
 # all: addstar addstarc addstard addstart sedstar load2mass skycells
+
+# $(SRC)/find_matches.$(ARCH).o \
+# $(SRC)/find_matches_closest.$(ARCH).o \
+# $(SRC)/find_matches_refstars.$(ARCH).o \
+# $(SRC)/find_matches_closest_refstars.$(ARCH).o \
+# $(SRC)/find_subset.$(ARCH).o \
+# $(SRC)/getgsc.$(ARCH).o \
+# $(SRC)/getusno.$(ARCH).o \
+# $(SRC)/getusnob.$(ARCH).o \
+# $(SRC)/greference.$(ARCH).o \
+# $(SRC)/grefstars.$(ARCH).o \
+# $(SRC)/dump.$(ARCH).o \
+# $(SRC)/ReadStarsTEXT.$(ARCH).o \
+# $(SRC)/StarOps.$(ARCH).o \
+# $(SRC)/replace_match.$(ARCH).o \
+# 
 
 ADDSTAR = \
@@ -57,17 +74,7 @@
 $(SRC)/build_links.$(ARCH).o \
 $(SRC)/calibrate.$(ARCH).o \
-$(SRC)/dump.$(ARCH).o \
 $(SRC)/edge_check.$(ARCH).o \
 $(SRC)/fakeimage.$(ARCH).o \
-$(SRC)/find_matches.$(ARCH).o \
 $(SRC)/find_matches_closest.$(ARCH).o \
-$(SRC)/find_matches_refstars.$(ARCH).o \
-$(SRC)/find_matches_closest_refstars.$(ARCH).o \
-$(SRC)/find_subset.$(ARCH).o \
-$(SRC)/getgsc.$(ARCH).o \
-$(SRC)/getusno.$(ARCH).o \
-$(SRC)/getusnob.$(ARCH).o \
-$(SRC)/greference.$(ARCH).o \
-$(SRC)/grefstars.$(ARCH).o \
 $(SRC)/GetZeroPointExposure.$(ARCH).o \
 $(SRC)/LoadFilenames.$(ARCH).o \
@@ -76,16 +83,16 @@
 $(SRC)/MatchHeaders.$(ARCH).o \
 $(SRC)/LoadData.$(ARCH).o \
+$(SRC)/LoadDataSDSS.$(ARCH).o \
+$(SRC)/LoadDataUKIRT.$(ARCH).o \
+$(SRC)/LoadDataPMM.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/parse_time.$(ARCH).o \
-$(SRC)/replace_match.$(ARCH).o \
 $(SRC)/resort_catalogs.$(ARCH).o \
 $(SRC)/resort_threaded.$(ARCH).o \
 $(SRC)/resort_unthreaded.$(ARCH).o \
 $(SRC)/resort_catalog.$(ARCH).o \
-$(SRC)/StarOps.$(ARCH).o \
 $(SRC)/ReadStarsFITS.$(ARCH).o \
-$(SRC)/ReadStarsTEXT.$(ARCH).o \
 $(SRC)/ReadStarsSDSS.$(ARCH).o \
 $(SRC)/ReadStarsUKIRT.$(ARCH).o \
@@ -100,7 +107,4 @@
 $(SRC)/psps_ids.$(ARCH).o
 
-## $(SRC)/LoadDataSDSS.$(ARCH).o \
-## $(SRC)/LoadDataUKIRT.$(ARCH).o \
-## $(SRC)/LoadDataPMM.$(ARCH).o \
 ##
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/include/addstar.h	(revision 38542)
@@ -50,4 +50,5 @@
 } HeaderSet;
 
+# if (0)
 typedef struct {
   Average  average;
@@ -67,4 +68,5 @@
   char *refcat;
 } DVO_DATA;
+# endif
 
 # define IDTYPE int
@@ -212,19 +214,21 @@
 SkyTable  *SkyTableFromTychoIndex PROTO((char *filename, int VERBOSE));
 void       check_permissions      PROTO((char *basefile));
-int        dump_rawstars          PROTO((Stars *stars, unsigned int Nstars));
 int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
 Image     *fakeimage              PROTO((char *rootname, off_t *Nimage, int photcode));
 
-int        find_matches_closest   	 PROTO((SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options));
-
+double     get_subpix             PROTO((double x, double y));
+
+int        find_matches_closest   PROTO((SkyRegion *region, Catalog *newcat, Catalog *catalog, AddstarClientOptions options));
+
+# if (0)
 int        find_matches           	 PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
-// int        find_matches_closest   	 PROTO((SkyRegion *region, Stars *stars,  unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
 int        find_matches_refstars  	 PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
 int        find_matches_closest_refstars PROTO((SkyRegion *region, Stars **stars, unsigned int Nstars, Catalog *catalog, AddstarClientOptions options));
+
+int        dump_rawstars          PROTO((Stars *stars, unsigned int Nstars));
 
 Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, unsigned int Nstars, unsigned int *NSTARS));
 int        gcatalog               PROTO((Catalog *catalog));
 Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, unsigned int *NSTARS));
-double     get_subpix             PROTO((double x, double y));
 
 Stars     *greference             PROTO((char *Refcat, SkyRegion *catstats, int photcode, unsigned int *nstars));
@@ -235,4 +239,9 @@
 // load text-based stars (REF only in the sense of REF photcodes)
 Stars     *grefstars              PROTO((char *file, int photcode, unsigned int *Nstars));
+
+Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
+
+int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
+# endif
 
 Catalog   *LoadStars              PROTO((char *file, Image **images, off_t *Nimages, AddstarClientOptions *options));
@@ -250,6 +259,4 @@
 double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 int        parse_time             PROTO((Header *header));
-Stars     *rd_gsc                 PROTO((char *filename, unsigned int *nstars));
-int        replace_match          PROTO((Average *average, Measure *measure, Stars *star));
 int        resort_catalogs        PROTO((AddstarClientOptions *options, SkyTable *sky));
 int        resort_catalogs_parallel PROTO((AddstarClientOptions *options, SkyList *sky));
@@ -259,12 +266,14 @@
 void       resort_catalog_old     PROTO((Catalog *catalog));
 
+// Stars  *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
+
+int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
+
 Catalog   *ReadStarsFITS          PROTO((FILE *f, Header *header, Header *in_theader));
-Stars     *ReadStarsTEXT          PROTO((FILE *f, unsigned int *nstars));
-Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars));
-int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
 Catalog   *FilterStars            PROTO((Catalog *newcat, Image *image, unsigned int imageID, const AddstarClientOptions *options));
-// Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
-
 int        ReadXradFITS           PROTO((FILE *f, Header *theader, Catalog *catalog));
+
+Catalog   *LoadDataSDSS           PROTO((FILE *f, char *file, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages));
+Catalog   *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages));
 
 double     scat_subpix            PROTO((double x, double y));
@@ -286,4 +295,9 @@
 AddstarClientOptions args_load2mass PROTO((int argc, char **argv, AddstarClientOptions options));
 AddstarClientOptions args_sedstar PROTO((int argc, char **argv, AddstarClientOptions options));
+
+SkyList   *SkyListExistingSubset  PROTO((SkyList *input, char *path));
+
+// these are all for the addstar client/server which has not been maintained
+# if (0)
 void	   args_server		  PROTO((int argc, char **argv));
 int 	   CheckPassword	  PROTO((int BindSocket));
@@ -298,5 +312,4 @@
 int 	   UpdateDatabase_Refcat  PROTO((AddstarClientOptions *options, SkyRegion *UserPatch, char *refcat));
 SkyList   *SkyListForStars	  PROTO((SkyTable *table, int depth, Stars *stars, unsigned int Nstars));
-SkyList   *SkyListExistingSubset  PROTO((SkyList *input, char *path));
 int        SkyListSetPath	  PROTO((SkyList *list, char *path));
 int 	   InitDataset		  PROTO((void));
@@ -307,6 +320,5 @@
 int 	   NewRefcat_Thread	  PROTO((int BindSocket));
 int 	   NewReflist_Thread	  PROTO((int BindSocket));
-
-int        InitStar               PROTO((Stars *star));
+# endif
 
 int args_skycells (int argc, char **argv);
@@ -317,6 +329,5 @@
 int ImageIndexFileInit ();
 
-int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages);
-int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars);
+Catalog *LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid);
 
 PhotCode *LoadMetadataPMM (char *datafile, Image *image);
@@ -340,6 +351,6 @@
 void saveMosaicCoords (Coords *input);
 
-Stars *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages, unsigned int *nstars);
-int LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
+Catalog *ReadStarsUKIRT (FILE *f, char *name, Header *header, Image *images, off_t *nimages);
+Catalog *LoadDataUKIRT (FILE *f, char *file, Image **images, off_t *nimages, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets);
 
 AddstarFile *LoadFilenames (int *nfile, char *filename, AddstarClientOptions *options);
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadData.c	(revision 38542)
@@ -82,8 +82,6 @@
     // ReadStarsFITS populates catalog->measure,Nmeasure 
     Catalog *newcat = ReadStarsFITS (f, headers[Nhead], headers[Ndata]);
-    if (!newcat) {
-      dvo_catalog_free (newcat);
-      continue;
-    }
+    if (!newcat) continue;
+
     images[0][Nvalid].nstar = newcat->Nmeasure;
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataPMM.c	(revision 38542)
@@ -15,5 +15,5 @@
 # define MAG_INDEX_ASC 22
 
-int LoadDataPMM (FILE *f, char *imagename, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars) {
+Catalog *LoadDataPMM (FILE *f, char *imagename, Image **images, off_t *nvalid) {
 
   off_t Nvalid, NVALID;
@@ -22,5 +22,4 @@
   double ra, dec, mag, airmass, az, ZeroPoint, ZeroPt;
   unsigned int Ninstars, NINSTARS;
-  Stars *inStars;
   PhotCode *photcode;
   gzFile gz;
@@ -58,5 +57,10 @@
 
   NINSTARS = 10000;
-  ALLOCATE (inStars, Stars, NINSTARS);
+  Catalog *catalog = addstar_catalog_init (NINSTARS);
+  ALLOCATE (catalog->average, Average, NINSTARS);
+  for (i = 0; i < NINSTARS; i++) {
+    dvo_measure_init (&catalog->measure[i]);
+    dvo_average_init (&catalog->average[i]);
+  }
 
   minR0 = minR1 = 360.0;
@@ -82,6 +86,4 @@
       dparse (&dec, 2, &buffer[i*NBYTE_ASC_TABLE]);
       dparse (&mag, 3, &buffer[i*NBYTE_ASC_TABLE]);
-
-      InitStar (&inStars[Ninstars]);
 
       if (ra > 180) {
@@ -95,18 +97,34 @@
       maxD = MAX(maxD, dec);
 
-      inStars[Ninstars].average.R        = ra;
-      inStars[Ninstars].average.D        = dec;
-
-      inStars[Ninstars].measure.M        = mag - ZeroPoint + ZeroPt;
-      inStars[Ninstars].measure.t        = images[0][0].tzero;
-      inStars[Ninstars].measure.dt       = images[0][0].exptime;
-      inStars[Ninstars].measure.photcode = code;
-      inStars[Ninstars].measure.airmass  = airmass;
-      inStars[Ninstars].measure.az       = az;
+      catalog->average[Ninstars].R        = ra;
+      catalog->average[Ninstars].D        = dec;
+      catalog->average[Ninstars].Nmeasure = 1;
+      catalog->average[Ninstars].measureOffset = Ninstars;
+
+      catalog->measure[Ninstars].R        = ra;
+      catalog->measure[Ninstars].D        = dec;
+      catalog->measure[Ninstars].M        = mag - ZeroPoint + ZeroPt;
+      catalog->measure[Ninstars].t        = images[0][0].tzero;
+      catalog->measure[Ninstars].dt       = images[0][0].exptime;
+      catalog->measure[Ninstars].photcode = code;
+      catalog->measure[Ninstars].airmass  = airmass;
+      catalog->measure[Ninstars].az       = az;
+
+      // imageID, detID ?
 
       Ninstars++;
-      CHECK_REALLOCATE (inStars, Stars, NINSTARS, Ninstars, 10000);
+      if (Ninstars == NINSTARS) {
+	NINSTARS += 10000;
+	REALLOCATE (catalog->measure, Measure, NINSTARS);
+	REALLOCATE (catalog->average, Average, NINSTARS);
+	for (i = Ninstars; i < NINSTARS; i++) {
+	  dvo_measure_init (&catalog->measure[i]);
+	  dvo_average_init (&catalog->average[i]);
+	}
+      }
     }
   }
+  catalog->Nmeasure = Ninstars;
+  catalog->Naverage = Ninstars;
 
   fprintf (stderr, "ra ranges: %f - %f, %f - %f; dec ranges: %f - %f\n", minR0, maxR0, minR1, maxR1, minD, maxD);
@@ -115,12 +133,10 @@
   images[0][0].imageID = 0;
 
-  *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
-
-  free (inStars);
   *nvalid = Nvalid + 1;
 
   gzclose (gz);
   free (buffer);
-  return (TRUE);
+
+  return (catalog);
 }
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataSDSS.c	(revision 38542)
@@ -4,10 +4,8 @@
 // there should only be a single data set (phu + table) in this file
 // each SDSS data set corresponds to 5 images (ugriz)
-int LoadDataSDSS (FILE *f, char *imagename, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
+Catalog *LoadDataSDSS (FILE *f, char *imagename, Image **images, off_t *nvalid, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages) {
 
   off_t Nskip, Nvalid, NVALID;
   int j, Nhead, Ndata;
-  unsigned int Ninstars;
-  Stars *inStars;
 
   if (images[0] == NULL) {
@@ -35,10 +33,9 @@
   fseeko (f, Nskip, SEEK_SET); 
 	 
-  // XXX I think this is an error?  should this be &images[0][Nvalid] ??
-  inStars = ReadStarsSDSS (f, imagename, headers[Nhead], headers[Ndata], images[0], &Nvalid, &Ninstars);
-  *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
+  // we pass in images[0] so the function updates the end of the array
+  Catalog *catalog = ReadStarsSDSS (f, imagename, headers[Nhead], headers[Ndata], images[0], &Nvalid);
 
   *nvalid = Nvalid;
-  return (TRUE);
+  return (catalog);
 }
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadDataUKIRT.c	(revision 38542)
@@ -4,10 +4,16 @@
 // UKIRT data has the WCS/image metadata header intermixed with the bintable header
 
-int LoadDataUKIRT (FILE *f, char *imagename, Image **images, off_t *nimages, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
+int MergeCatalogs (Catalog *tgt, Catalog *src);
+
+Catalog *LoadDataUKIRT (FILE *f, char *imagename, Image **images, off_t *nimages, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t NheaderSets) {
 
   off_t Nskip, Nvalid, NVALID;
   int i, j, Nhead, Ndata;
-  unsigned int Ninstars;
-  Stars *inStars;
+
+  Catalog *catalog = NULL;
+  ALLOCATE (catalog, Catalog, 1);
+  dvo_catalog_init (catalog, TRUE);
+  ALLOCATE (catalog->average, Average, 1);
+  ALLOCATE (catalog->measure, Measure, 1);
 
   // create or update image table 
@@ -35,10 +41,38 @@
     fseeko (f, Nskip, SEEK_SET); 
 
-    inStars = ReadStarsUKIRT (f, imagename, headers[Nhead], images[0], &Nvalid, &Ninstars);
-    *stars = MergeStars (*stars, Nstars, inStars, Ninstars);
+    Catalog *newcat = ReadStarsUKIRT (f, imagename, headers[Nhead], images[0], &Nvalid);
+    MergeCatalogs (catalog, newcat);
+
+    dvo_catalog_free (newcat);
+    free (newcat);
 
     *nimages = Nvalid;
   }    
-  return (TRUE);
+  return (catalog);
 }
 
+int MergeCatalogs (Catalog *tgt, Catalog *src) {
+
+  // this function assumes the src and tgt catalog do NOT overlap (otherwise just use find_match_closest) 
+
+  off_t Naverage_tgt = tgt->Naverage;
+  off_t Nmeasure_tgt = tgt->Nmeasure;
+
+  tgt->Naverage += src->Naverage;
+  tgt->Nmeasure += src->Nmeasure;
+
+  REALLOCATE (tgt->average, Average, tgt->Naverage);
+  REALLOCATE (tgt->measure, Measure, tgt->Nmeasure);
+
+  off_t i;
+  for (i = 0; i < src->Naverage; i++) {
+    tgt->average[i+Naverage_tgt] = src->average[i];
+    tgt->average[i+Naverage_tgt].measureOffset += Nmeasure_tgt;
+  }
+
+  for (i = 0; i < src->Nmeasure; i++) {
+    tgt->measure[i+Nmeasure_tgt] = src->measure[i];
+  }
+
+  return TRUE;
+}
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/LoadStars.c	(revision 38542)
@@ -25,14 +25,17 @@
     }
 
-    // load PMM data if specified (these are not stored as FITS-tables)
-    if (PMM_CCD_TABLE != NULL) {
-      // XXX catalog = LoadDataPMM (f, file[i].imagename, images, Nimages);
-      continue;
-    }
-
     int Nheaders = 0;
     Header **headers = NULL;
     off_t NheaderSets = 0;
     HeaderSet *headerSets = NULL;
+
+    off_t NimagesStart = *Nimages;
+    Catalog *newcat = NULL;
+
+    // load PMM data if specified (these are not stored as FITS-tables)
+    if (PMM_CCD_TABLE != NULL) {
+      newcat = LoadDataPMM (f, file[i].imagename, images, Nimages);
+      goto next_file;
+    }
 
     // otherwise, we have FITS-table files: parse their headers to determine the contents
@@ -62,5 +65,5 @@
     // if these are SDSS data, load with SDSS-specific wrapper
     if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
-      // XXX catalog = LoadDataSDSS (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
+      newcat = LoadDataSDSS (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
       goto next_file;
     }
@@ -68,10 +71,11 @@
     // if these are SDSS data, load with SDSS-specific wrapper
     if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "UKIRT_OBJ")) {
-      // XXX catalog = LoadDataUKIRT (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
+      newcat = LoadDataUKIRT (f, file[i].imagename, images, Nimages, headers, extsize, headerSets, NheaderSets);
       goto next_file;
     }
 
-    off_t NimagesStart = *Nimages;
-    Catalog *newcat = LoadData (f, &file[i], images, Nimages, headers, extsize, headerSets, NheaderSets, options);
+    newcat = LoadData (f, &file[i], images, Nimages, headers, extsize, headerSets, NheaderSets, options);
+
+  next_file:
 
     // if we added data from an image, then we can merge it in
@@ -94,8 +98,10 @@
       find_matches_closest (&region, newcat, catalog, matchOptions);
     }
-    dvo_catalog_free (newcat);
-    free (newcat);
 
-  next_file:
+    if (newcat) {
+      dvo_catalog_free (newcat);
+      free (newcat);
+    }
+
     HeaderSetFree (headerSets, NheaderSets);
     int j;
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 38542)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-int SetSDSSFlags (Stars *star, unsigned int flags1, unsigned int flags2);
+int SetSDSSFlags (Measure *measure, unsigned int flags1, unsigned int flags2);
 
 # define NFILTER 5
@@ -33,5 +33,5 @@
 // given a file with the pointer at the start of the table block and the 
 // corresponding image header, load the stars from the table
-Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars) {
+Catalog *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages) {
 
   off_t Nskip, Nrow;
@@ -40,5 +40,4 @@
   Header theader;
   FTable table;
-  Stars *stars;
   double clockRate, mjd[5], jd, sidtime, alt, az;
   float seeing[5], photErr[5], zeropt[5], ZeroPt;
@@ -113,5 +112,18 @@
   // create a Star entry for each filter and detection
   Nstars = table.header[0].Naxis[1];
-  ALLOCATE (stars, Stars, NFILTER*Nstars);
+
+  Catalog *catalog = NULL;
+  ALLOCATE (catalog, Catalog, 1);
+  dvo_catalog_init (catalog, TRUE);
+
+  ALLOCATE (catalog->average, Average, Nstars);
+  ALLOCATE (catalog->measure, Measure, NFILTER*Nstars);
+
+  for (i = 0; i < Nstars; i++) {
+    for (j = 0; j < NFILTER; j++) {
+      dvo_measure_init (&catalog->measure[i*NFILTER + j]);
+    }
+    dvo_average_init (&catalog->average[i]);
+  }
 
   GET_COLUMN_5 (rowc, float);
@@ -145,37 +157,38 @@
 
   for (i = 0; i < Nstars; i++) {
+    // any values not explicitly set are left at 0.0
+    catalog->average[i].R             = ra[i] + dCOS(dec[i]) * offsetRa[i*NFILTER] / 3600.0;
+    catalog->average[i].D             = dec[i] + offsetDec[i*NFILTER] / 3600.0;
+    catalog->average[i].dR            = NAN;
+    catalog->average[i].dD            = NAN;
+    catalog->average[i].Nmeasure      = NFILTER;
+    catalog->average[i].measureOffset = i*NFILTER;
+
     for (j = 0; j < NFILTER; j++) {
       N = NFILTER*i + j;
-      InitStar (&stars[N]);
       
-      // any values not explicitly set are left at 0.0
-      stars[N].average.R         = ra[i] + dCOS(dec[i]) * offsetRa[N] / 3600.0;
-      stars[N].average.D         = dec[i] + offsetDec[N] / 3600.0;
-      stars[N].average.dR        = NAN;
-      stars[N].average.dD        = NAN;
-
-      stars[N].measure.R         = stars[N].average.R;
-      stars[N].measure.D         = stars[N].average.D;
-      stars[N].measure.Xccd      = colc[N];
-      stars[N].measure.Yccd      = rowc[N];
-      stars[N].measure.dXccd     = ToShortPixels(colcErr[N]);
-      stars[N].measure.dYccd     = ToShortPixels(rowcErr[N]);
-      stars[N].measure.M         = psfCounts[N] + ZeroPt - zeropt[j];
-      stars[N].measure.dM        = psfCountsErr[N];
-      stars[N].measure.Map       = fiberCounts[N] + ZeroPt - zeropt[j];
-      stars[N].measure.Sky       = sky[N]; // adjust this to counts?
-      stars[N].measure.dSky      = skyErr[N];
-      stars[N].measure.FWx       = ToShortPixels(seeing[j]); // reported in arcsec?
-      stars[N].measure.FWy       = ToShortPixels(seeing[j]);
+      catalog->measure[N].R         = catalog->average[i].R;
+      catalog->measure[N].D         = catalog->average[i].D;
+      catalog->measure[N].Xccd      = colc[N];
+      catalog->measure[N].Yccd      = rowc[N];
+      catalog->measure[N].dXccd     = ToShortPixels(colcErr[N]);
+      catalog->measure[N].dYccd     = ToShortPixels(rowcErr[N]);
+      catalog->measure[N].M         = psfCounts[N] + ZeroPt - zeropt[j];
+      catalog->measure[N].dM        = psfCountsErr[N];
+      catalog->measure[N].Map       = fiberCounts[N] + ZeroPt - zeropt[j];
+      catalog->measure[N].Sky       = sky[N]; // adjust this to counts?
+      catalog->measure[N].dSky      = skyErr[N];
+      catalog->measure[N].FWx       = ToShortPixels(seeing[j]); // reported in arcsec?
+      catalog->measure[N].FWy       = ToShortPixels(seeing[j]);
       if (prob_psf) {
-          stars[N].measure.psfChisq  = prob_psf[N]; // XXX not really the correct value...
+          catalog->measure[N].psfChisq  = prob_psf[N]; // XXX not really the correct value...
       } else {
-          stars[N].measure.psfChisq  = NAN;
+          catalog->measure[N].psfChisq  = NAN;
       }
-      stars[N].measure.detID     = N;
-      stars[N].measure.t         = tzero[j] + clockRate*rowc[N]; // time since row 0
-      stars[N].measure.dt        = 4.32912209; // 2.5 * log(53.907456) the sdss exposure time // old comment is 53907456 is this 2048*clockRate ?
-
-      SetSDSSFlags (&stars[N], flags[N], flags2[N]);
+      catalog->measure[N].detID     = N;
+      catalog->measure[N].t         = tzero[j] + clockRate*rowc[N]; // time since row 0
+      catalog->measure[N].dt        = 4.32912209; // 2.5 * log(53.907456) the sdss exposure time // old comment is 53907456 is this 2048*clockRate ?
+
+      SetSDSSFlags (&catalog->measure[N], flags[N], flags2[N]);
 
       // longitude and latitude for SDSS:
@@ -187,12 +200,12 @@
       double Latitude = 32.7803611755; // degrees
 
-      jd = ohana_sec_to_jd (stars[N].measure.t);
+      jd = ohana_sec_to_jd (catalog->measure[N].t);
       sidtime  = 15.0*ohana_lst (jd, Longitude); // sidtime in degrees
-      altaz (&alt, &az, sidtime - stars[N].average.R, stars[N].average.D, Latitude);
-
-      stars[N].measure.airmass   = 1.0 / dCOS(90.0 - alt);
-      stars[N].measure.az        = az;
-      stars[N].measure.photcode  = photcode[j];
-      stars[N].measure.imageID   = j + *nimages; // set imageID to entry for this filter
+      altaz (&alt, &az, sidtime - catalog->average[i].R, catalog->average[i].D, Latitude);
+
+      catalog->measure[N].airmass   = 1.0 / dCOS(90.0 - alt);
+      catalog->measure[N].az        = az;
+      catalog->measure[N].photcode  = photcode[j];
+      catalog->measure[N].imageID   = j + *nimages; // set imageID to entry for this filter
     }
   }    
@@ -204,8 +217,8 @@
     // XXX for now, we define a totally fake coordinate system centered on the first listed star
     InitCoords (&images[N].coords, "DEC--TAN");
-    images[N].coords.crval1 = stars[0].average.R;
-    images[N].coords.crval2 = stars[0].average.D;
-    images[N].coords.crpix1 = stars[0].measure.Xccd;
-    images[N].coords.crpix2 = stars[0].measure.Yccd;
+    images[N].coords.crval1 = catalog->average[0].R;
+    images[N].coords.crval2 = catalog->average[0].D;
+    images[N].coords.crpix1 = catalog->measure[0].Xccd;
+    images[N].coords.crpix2 = catalog->measure[0].Yccd;
     images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
 
@@ -244,5 +257,5 @@
 
     images[N].trate = clockRate * 1e-4;
-    images[N].secz = stars[0].measure.airmass;
+    images[N].secz = catalog->measure[0].airmass;
     images[N].ccdnum = camcol;
 
@@ -263,28 +276,26 @@
   }
 
-  NSTAR_GROUP = NFILTER;
   *nimages += NFILTER;
-  *nstars = Nstars*NFILTER;
-  return (stars);
+  return (catalog);
 }
 
-int SetSDSSFlags (Stars *star, unsigned int flags1, unsigned int flags2) {
+int SetSDSSFlags (Measure *measure, unsigned int flags1, unsigned int flags2) {
 
   // XXX this is wrong, need to roll left to set the correct bit 
-  if (flags1 & 0x00000002) star[0].measure.photFlags |= 0x0001; // BRIGHT            - 1  1
-  if (flags1 & 0x00000004) star[0].measure.photFlags |= 0x0002; // EDGE              - 1  2
-  if (flags1 & 0x00000008) star[0].measure.photFlags |= 0x0004; // BLENDED           - 1  3
-  if (flags1 & 0x00000010) star[0].measure.photFlags |= 0x0008; // CHILD             - 1  4
-  if (flags1 & 0x00000020) star[0].measure.photFlags |= 0x0010; // PEAKCENTER        - 1  5
-  if (flags1 & 0x00000040) star[0].measure.photFlags |= 0x0020; // NODEBLEND         - 1  6
-  if (flags1 & 0x00040000) star[0].measure.photFlags |= 0x0040; // SATUR             - 1 18
-  if (flags1 & 0x00080000) star[0].measure.photFlags |= 0x0080; // NOTCHECKED        - 1 19
-  if (flags1 & 0x10000000) star[0].measure.photFlags |= 0x0100; // BINNED1           - 1 28
-  if (flags1 & 0x20000000) star[0].measure.photFlags |= 0x0200; // BINNED2           - 1 29
-  if (flags1 & 0x40000000) star[0].measure.photFlags |= 0x0400; // BINNED4           - 1 30
-  if (flags2 & 0x00000040) star[0].measure.photFlags |= 0x0800; // LOCAL_EDGE        - 2  7
-  if (flags2 & 0x00000800) star[0].measure.photFlags |= 0x1000; // INTERP_CENTER     - 2 12
-  if (flags2 & 0x00002000) star[0].measure.photFlags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
-  if (flags2 & 0x02000000) star[0].measure.photFlags |= 0x4000; // NOTCHECKED_CENTER - 2 26
+  if (flags1 & 0x00000002) measure->photFlags |= 0x0001; // BRIGHT            - 1  1
+  if (flags1 & 0x00000004) measure->photFlags |= 0x0002; // EDGE              - 1  2
+  if (flags1 & 0x00000008) measure->photFlags |= 0x0004; // BLENDED           - 1  3
+  if (flags1 & 0x00000010) measure->photFlags |= 0x0008; // CHILD             - 1  4
+  if (flags1 & 0x00000020) measure->photFlags |= 0x0010; // PEAKCENTER        - 1  5
+  if (flags1 & 0x00000040) measure->photFlags |= 0x0020; // NODEBLEND         - 1  6
+  if (flags1 & 0x00040000) measure->photFlags |= 0x0040; // SATUR             - 1 18
+  if (flags1 & 0x00080000) measure->photFlags |= 0x0080; // NOTCHECKED        - 1 19
+  if (flags1 & 0x10000000) measure->photFlags |= 0x0100; // BINNED1           - 1 28
+  if (flags1 & 0x20000000) measure->photFlags |= 0x0200; // BINNED2           - 1 29
+  if (flags1 & 0x40000000) measure->photFlags |= 0x0400; // BINNED4           - 1 30
+  if (flags2 & 0x00000040) measure->photFlags |= 0x0800; // LOCAL_EDGE        - 2  7
+  if (flags2 & 0x00000800) measure->photFlags |= 0x1000; // INTERP_CENTER     - 2 12
+  if (flags2 & 0x00002000) measure->photFlags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
+  if (flags2 & 0x02000000) measure->photFlags |= 0x4000; // NOTCHECKED_CENTER - 2 26
   return (TRUE);
 
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/ReadStarsUKIRT.c	(revision 38542)
@@ -8,5 +8,5 @@
 // given a file with the pointer at the start of the table block and the 
 // corresponding image header, load the stars from the table
-Stars *ReadStarsUKIRT (FILE *f, char *imagename, Header *header, Image *images, off_t *nimages, unsigned int *nstars) {
+Catalog *ReadStarsUKIRT (FILE *f, char *imagename, Header *header, Image *images, off_t *nimages) {
 
   off_t Nrow;
@@ -14,5 +14,4 @@
   char type[80];
   FTable table;
-  Stars *stars;
   
   // the FITS binary table header is the same as the image header
@@ -129,5 +128,17 @@
   // create a Star entry for each filter and detection
   int Nstars = table.header[0].Naxis[1];
-  ALLOCATE (stars, Stars, Nstars);
+
+  Catalog *catalog = NULL;
+  ALLOCATE (catalog, Catalog, 1);
+  dvo_catalog_init (catalog, TRUE);
+
+  ALLOCATE (catalog->average, Average, Nstars);
+  ALLOCATE (catalog->measure, Measure, Nstars);
+
+  int i;
+  for (i = 0; i < Nstars; i++) {
+    dvo_measure_init (&catalog->measure[i]);
+    dvo_average_init (&catalog->average[i]);
+  }
 
   GET_COLUMN (X_coordinate, float);
@@ -153,46 +164,46 @@
   // ohana_memcheck (TRUE);
 
-  int i;
   for (i = 0; i < Nstars; i++) {
-    InitStar (&stars[i]);
-      
+
     // any values not explicitly set are left at 0.0
     XY_to_RD (&R, &D, X_coordinate[i], Y_coordinate[i], &coords);
 
-    stars[i].average.R         = R;
-    stars[i].average.D         = D;
-    stars[i].average.dR        = NAN;
-    stars[i].average.dD        = NAN;
-
-    stars[i].measure.R         = stars[i].average.R;
-    stars[i].measure.D         = stars[i].average.D;
-    stars[i].measure.Xccd      = X_coordinate[i];
-    stars[i].measure.Yccd      = Y_coordinate[i];
-    stars[i].measure.dXccd     = ToShortPixels(X_coordinate_err[i]);
-    stars[i].measure.dYccd     = ToShortPixels(Y_coordinate_err[i]);
-
-    stars[i].measure.M         = -2.5*log10(Aper_flux_4[i]) + ZeroPt + magtime + ApCor4;
-    stars[i].measure.dM        = Aper_flux_4_err[i] / Aper_flux_4[i];
-    stars[i].measure.Map       = -2.5*log10(Aper_flux_7[i]) + ZeroPt + magtime + ApCor7;
-    stars[i].measure.dMap      = Aper_flux_7_err[i] / Aper_flux_7[i];
-    stars[i].measure.Mkron     = -2.5*log10(Kron_flux[i]) + ZeroPt + magtime;
-    stars[i].measure.dMkron    = Kron_flux_err[i] / Kron_flux[i];
-    stars[i].measure.Sky       = Sky_level[i]; // adjust this to counts?
-    stars[i].measure.dSky      = Sky_rms[i];
-    stars[i].measure.FWx       = ToShortPixels(seeing); // reported in arcsec?
-    stars[i].measure.FWy       = ToShortPixels(seeing);
-
-    stars[i].measure.Mcal      = Mcal;
-
-    stars[i].measure.detID     = i;
-    stars[i].measure.t         = tzero; // time since row 0
-    stars[i].measure.dt        = magtime; // 2.5 * log(exptime) 
-
-    altaz (&alt, &az, sidtime_deg - stars[i].average.R, stars[i].average.D, Latitude);
-
-    stars[i].measure.airmass   = 1.0 / dCOS(90.0 - alt);
-    stars[i].measure.az        = az;
-    stars[i].measure.photcode  = photcode;
-    stars[i].measure.imageID   = *nimages; // set imageID to entry for this filter
+    catalog->average[i].R             = R;
+    catalog->average[i].D             = D;
+    catalog->average[i].dR            = NAN;
+    catalog->average[i].dD            = NAN;
+    catalog->average[i].Nmeasure      = 1;
+    catalog->average[i].measureOffset = i;
+
+    catalog->measure[i].R         = catalog->average[i].R;
+    catalog->measure[i].D         = catalog->average[i].D;
+    catalog->measure[i].Xccd      = X_coordinate[i];
+    catalog->measure[i].Yccd      = Y_coordinate[i];
+    catalog->measure[i].dXccd     = ToShortPixels(X_coordinate_err[i]);
+    catalog->measure[i].dYccd     = ToShortPixels(Y_coordinate_err[i]);
+
+    catalog->measure[i].M         = -2.5*log10(Aper_flux_4[i]) + ZeroPt + magtime + ApCor4;
+    catalog->measure[i].dM        = Aper_flux_4_err[i] / Aper_flux_4[i];
+    catalog->measure[i].Map       = -2.5*log10(Aper_flux_7[i]) + ZeroPt + magtime + ApCor7;
+    catalog->measure[i].dMap      = Aper_flux_7_err[i] / Aper_flux_7[i];
+    catalog->measure[i].Mkron     = -2.5*log10(Kron_flux[i]) + ZeroPt + magtime;
+    catalog->measure[i].dMkron    = Kron_flux_err[i] / Kron_flux[i];
+    catalog->measure[i].Sky       = Sky_level[i]; // adjust this to counts?
+    catalog->measure[i].dSky      = Sky_rms[i];
+    catalog->measure[i].FWx       = ToShortPixels(seeing); // reported in arcsec?
+    catalog->measure[i].FWy       = ToShortPixels(seeing);
+
+    catalog->measure[i].Mcal      = Mcal;
+
+    catalog->measure[i].detID     = i;
+    catalog->measure[i].t         = tzero; // time since row 0
+    catalog->measure[i].dt        = magtime; // 2.5 * log(exptime) 
+
+    altaz (&alt, &az, sidtime_deg - catalog->average[i].R, catalog->average[i].D, Latitude);
+
+    catalog->measure[i].airmass   = 1.0 / dCOS(90.0 - alt);
+    catalog->measure[i].az        = az;
+    catalog->measure[i].photcode  = photcode;
+    catalog->measure[i].imageID   = *nimages; // set imageID to entry for this filter
   }
 
@@ -256,5 +267,4 @@
   // ohana_memcheck (TRUE);
 
-  *nstars = Nstars;
-  return (stars);
+  return (catalog);
 }
Index: /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/SkyListForStars.c
===================================================================
--- /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/SkyListForStars.c	(revision 38541)
+++ /branches/eam_branches/ipp-20150616/Ohana/src/addstar/src/SkyListForStars.c	(revision 38542)
@@ -1,4 +1,5 @@
 # include "addstar.h"
 
+# if (0)
 void sort_stars_ra (Stars *stars, int N) {
 
@@ -69,2 +70,3 @@
 
 */
+# endif
