Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 15035)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 15036)
@@ -58,5 +58,5 @@
 $(SRC)/greference.$(ARCH).o \
 $(SRC)/grefstars.$(ARCH).o \
-$(SRC)/gstars.$(ARCH).o \
+$(SRC)/LoadStars.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
@@ -73,6 +73,4 @@
 $(SRC)/ReadImageHeader.$(ARCH).o \
 $(SRC)/update_coords.$(ARCH).o
-
-# $(SRC)/gimages.$(ARCH).o \
 
 ADDSTARD = \
@@ -111,5 +109,4 @@
 $(SRC)/getusnob.$(ARCH).o \
 $(SRC)/ImageOptions.$(ARCH).o \
-$(SRC)/gimages.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
@@ -148,5 +145,4 @@
 $(SRC)/gettycho.$(ARCH).o \
 $(SRC)/greference.$(ARCH).o \
-$(SRC)/gimages.$(ARCH).o \
 $(SRC)/in_image.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
@@ -171,5 +167,5 @@
 $(SRC)/SocketOps.$(ARCH).o \
 $(SRC)/ConfigInit.$(ARCH).o \
-$(SRC)/gstars.$(ARCH).o \
+$(SRC)/LoadStars.$(ARCH).o \
 $(SRC)/grefstars.$(ARCH).o \
 $(SRC)/load_subpix.$(ARCH).o \
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 15035)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 15036)
@@ -102,5 +102,4 @@
 
 /* these globals are used separately by both client and server (KEEP) */
-double ZeroPt;  // double check for consistency
 double CAL_INSTMAG_MAX;
 double CAL_INSTMAG_MIN;
@@ -155,5 +154,5 @@
 Stars     *grefcat                PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
 Stars     *grefstars              PROTO((char *file, int photcode, int *Nstars));
-Stars     *gstars                 PROTO((char *file, int *Nstars, Image **images, int *Nimages, int photcode));
+Stars     *LoadStars              PROTO((char *file, int *Nstars, Image **images, int *Nimages, int photcode));
 int        in_image               PROTO((double r, double d, Image *image));
 int        load_pt_catalog        PROTO((Catalog *catalog, SkyRegion *region));  /*** choose new name ***/
@@ -199,6 +198,4 @@
 Measure   *sort_measure     	  PROTO((Average *average, int Naverage, Measure *measure, int Nmeasure, int *next));
 Missing   *sort_missing     	  PROTO((Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss));
-Stars     *ConvertSMPDATA	  PROTO((FTable *table, int *nstars));
-Stars     *ConvertPS1_DEV_0	  PROTO((FTable *table, int *nstars));
 int        ImageOptions		  PROTO((AddstarClientOptions *options, Image *images, int Nimages));
 int        GetFileMode		  PROTO((Header *header));
@@ -229,4 +226,8 @@
 int 	   NewReflist_Thread	  PROTO((int BindSocket));
 
+Stars     *Convert_SMPDATA	  PROTO((FTable *table, int *nstars));
+Stars     *Convert_PS1_DEV_0	  PROTO((FTable *table, int *nstars));
+Stars     *Convert_PS1_DEV_1	  PROTO((FTable *table, int *nstars));
+
 int args_skycells (int argc, char **argv);
 int ConfigInit_skycells (int *argc, char **argv);
Index: /trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 15036)
@@ -5,4 +5,5 @@
 AddstarClientOptions ConfigInit (int *argc, char **argv) {
 
+  double ZERO_POINT;
   char *config, *file;
   char RadiusWord[80];
@@ -95,4 +96,6 @@
     SKY_TABLE[0] = 0;
   }
+  GetConfig (config, "ZERO_PT",                "%lf", 0, &ZERO_POINT);
+  SetZeroPoint (ZERO_POINT);
 
   if (!ScanConfig (config, "IMAGE_TABLE",       "%s",  0, ImageCat)) {
Index: /trunk/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/LoadStars.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/LoadStars.c	(revision 15036)
@@ -1,132 +1,263 @@
-
-/* read an image header corresponding to a CMF / CMP data block */
-Image *ReadImageHeader (Header *header) {
-
+# include "addstar.h"
+
+Stars *LoadStars (char *filename, int *Nstars, Image **images, int *Nimages, int photcode) {
+
+  int i, j, N, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
+  int Nskip, Nhead, Ndata, done, status, mode, NinStars;
+  char **file, *name;
+  FILE *f;
+  glob_t globList;
+  char **exthead, **extdata, **exttype, tmpword[80];
+  int *extnum_head, *extnum_data, *extsize;
+  Header *header, **headers;
   Image *image;
-
-  ALLOCATE (image, Image, 1);
-
-  /* get astrometry information */
-  if (!GetCoords (&image[0].coords, &header)) {
-    fprintf (stderr, "ERROR: no astrometric solution in header\n");
+  Stars *inStars, *stars;
+
+  // parse the filename as a glob
+  globList.gl_offs = 0;
+  glob (filename, 0, NULL, &globList);
+
+  // if the glob does not match, save the literal word:
+  // otherwise save all glob matches
+  if (globList.gl_pathc == 0) {
+    Nfile = 1;
+    ALLOCATE (file, char *, Nfile);
+    file[0] = strcreate (filename);
+  } else {
+    Nfile = globList.gl_pathc;
+    ALLOCATE (file, char *, Nfile);
+    for (i = 0; i < Nfile; i++) {
+      file[i] = strcreate (globList.gl_pathv[i]);
+    }
+  }
+
+  // open the first file, read the PHU header
+  f = fopen (file[0], "r");
+  if (f == NULL) {
+    fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
     exit (1);
   }
-  itmp = 0;
-  gfits_scan (&header, "NASTRO",   "%d", 1, &itmp);
-  if ((itmp == 0) && !ACCEPT_ASTROM) {
-    fprintf (stderr, "ERROR: bad astrometric solution in header\n");
+  ALLOCATE (header, Header, 1);
+  gfits_fread_header (f, header);
+
+  mode = GetFileMode (header);
+
+  stars = NULL;
+  *Nstars = 0;
+
+  /*** load data from a single PHU or a collection of PHU files ***/
+  if ((mode != SIMPLE_MEF) && (mode != MOSAIC_MEF)) {
+    Nimage = Nfile;
+    ALLOCATE (image, Image, Nimage);
+    for (i = N = 0; i < Nfile; i++) {
+      // XXX we should not drop all input images if one fails
+      if (i > 0) {
+	f = fopen (file[i], "r");
+	if (f == NULL) {
+	  fprintf (stderr, "can't read header for %s, skipping\n", file[i]);
+	  continue;
+	}
+	gfits_fread_header (f, header);
+      }
+
+      if (!ReadImageHeader (header, &image[N], photcode)) {
+	fprintf (stderr, "skipping %s\n", file[i]);
+	continue;
+      }
+      
+      /* find image rootname */
+      name = filebasename (file[i]);
+      snprintf (image[N].name, 64, name);
+      free (name);
+    
+      switch (mode) {
+	case SIMPLE_CMP:
+	case MOSAIC_CMP:
+	  inStars = ReadStarsTEXT (f, &image[N].nstar);
+	  inStars = FilterStars (inStars, &image[N]);
+	  stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
+	  break;
+
+	case SIMPLE_CMF:
+	case MOSAIC_CMF:
+	  inStars = ReadStarsFITS (f, header, NULL, &image[N].nstar);
+	  inStars = FilterStars (inStars, &image[N]);
+	  stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
+	  break;
+
+	case MOSAIC_PHU:
+	  inStars = NULL;
+	  NinStars = 0;
+	  break;
+      }
+      fclose (f);
+      gfits_free_header (header);
+      N++;
+    }
+    *Nimages = N;
+    *images = image;
+    
+    if (N == 0) {
+      // XXX how do we track this error?
+      fprintf (stderr, "no valid image data in %s, giving up\n", filename);
+      exit (0);
+    }
+
+    return stars;
+  }
+    
+  /* we have a multi-chip image */
+
+  /* supplied photcode is incompatible with multi-chip images */
+  if (photcode) {
+    fprintf (stderr, "ERROR: photcode cannot be supplied to multi-chip images -- manually adjust the headers\n");
     exit (1);
   }
-  if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
-    if (MOSAIC == NULL) {
-      fprintf (stderr, "ERROR: no mosaic for WRP image (use -mosaic)\n");
-      exit (1);
-    }
-    RegisterMosaic (MOSAIC);
-  } else {
-    /* force image to lie in 0-360 range */
-    while (image[0].coords.crval1 < 0) image[0].coords.crval1 += 360.0;
-    while (image[0].coords.crval1 > 360.0) image[0].coords.crval1 -= 360.0;
-  }
-    
-  /* CERROR in data file is in arcsec */
-  if (!gfits_scan (&header, "CERROR",   "%lf", 1, &tmp)) tmp = 1.0;
-  image[0].cerror = tmp * 50.0;
-  gfits_scan (&header, "NAXIS1",   "%hd", 1, &image[0].NX); 
-  gfits_scan (&header, "NAXIS2",   "%hd", 1, &image[0].NY);
- 
-  /* get photcode from header */
-  if (photcode == 0) {
-    if (!gfits_scan (&header, "PHOTCODE", "%s", 1, photname)) {
-      fprintf (stderr, "ERROR: photcode not supplied in header\n");
-      exit (1);
-    }
-    photcode = GetPhotcodeCodebyName (photname);
-    if (photcode == 0) {
-      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", photname);
-      exit (1);
-    }
-  }
-  if (photcode == 0) {
-    fprintf (stderr, "ERROR: no valid photcode is supplied\n");
-    exit (1);
-  }
-  image[0].photcode = photcode;
-
-  image[0].NX -= XOVERSCAN;
-  image[0].NY -= YOVERSCAN;
-  gfits_scan (&header, ExptimeKeyword,  "%lf", 1, &tmp);
-  image[0].exptime = tmp;
-  
-  /*** why are we no longer using APMIFIT?? ***/
-  tmp = 0;
-  /* gfits_scan (&header, "APMIFIT",  "%lf", 1, &tmp); */
-  image[0].apmifit = tmp;
-
-  tmp = 0;
-  /* gfits_scan (&header, "dAPMIFIT", "%lf", 1, &tmp); */
-  image[0].dapmifit = tmp;
-
-  tmp = 0;
-  gfits_scan (&header, "FLIMIT",   "%lf", 1, &tmp);
-  image[0].detection_limit = tmp * 10.0;
-
-  tmp = 0;
-  gfits_scan (&header, "FSATUR",   "%lf", 1, &tmp);
-  image[0].saturation_limit = tmp * 10.0;
-
-  tmp = 0;
-  gfits_scan (&header, "FWHM_X",   "%lf", 1, &tmp);
-  image[0].fwhm_x = tmp * 25.0 * image[0].coords.cdelt1 * 3600.0;
-
-  tmp = 0;
-  gfits_scan (&header, "FWHM_Y",   "%lf", 1, &tmp);
-  image[0].fwhm_y = tmp * 25.0 * image[0].coords.cdelt1 * 3600.0;
-
-  if (!gfits_scan (&header, "TZERO",   "%d",  1, &image[0].tzero)) {
-    image[0].tzero = parse_time (&header);
-  }
-
-  if (STKeyword[0]) {
-    /* get ST (used for airmass calculation) */
-    gfits_scan (&header, STKeyword, "%s", 1, line);
-    /* remove ':' characters */
-    for (c = strchr (line, ':'); c != (char *) NULL; c = strchr (line, ':')) { *c = ' '; }
-    sscanf (line, "%d %d %lf", &hour, &min, &sec);
-    image[0].sidtime = hour + min/60.0 + sec/3600.0;
-  } else {
-    double jd;
-    jd = ohana_sec_to_jd (image[0].tzero);
-    image[0].sidtime  = ohana_lst (jd, Longitude);
-  }
-  image[0].latitude = Latitude;
-
-  tmp = 0;
-  gfits_scan (&header, "TRATE",   "%lf", 1, &tmp);
-  image[0].trate = 10000 * tmp;
-
-  tmp = 0;
-  gfits_scan (&header, AirmassKeyword, "%lf", 1, &tmp);
-  image[0].secz = MIN (NO_MAG, tmp);
-
-  if (!gfits_scan (&header, CCDNumKeyword, "%d", 1, &itmp)) {
-    image[0].ccdnum = 0xff;
-  } else {
-    image[0].ccdnum = itmp;
-  }
-
-  gfits_scan (&header, "ZERO_PT", "%lf", 1, &ZeroPt);
-  SetZeroPoint (ZeroPt);
-
-  /* secz is in units milli-airmass */
-  image[0].Mcal = 0.0;
-  image[0].Xm   = NO_MAG;
-  image[0].code = 0;
-  bzero (image[0].dummy, sizeof(image[0].dummy));
-
-  /* find expected number of stars */
-  if (!gfits_scan (&header, "NSTARS", "%d", 1, &image[0].nstar)) {
-    fprintf (stderr, "ERROR: can't get NSTARS from header\n");
-    exit (1);
-  }
-
+
+  /* we need to examine the extensions to determine the headers and the data */
+  NHEADER = 10;
+  ALLOCATE (headers, Header *, NHEADER);
+
+  // the first header is already loaded
+  headers[0] = header;
+  Nskip = gfits_matrix_size (header);
+  fseek (f, Nskip, SEEK_CUR); 
+
+  // load all headers into memory
+  done = FALSE;
+  for (i = 1; !done; i++) {
+      ALLOCATE (headers[i], Header, 1);
+      status = gfits_fread_header (f, headers[i]);
+      if (!status) { 
+	  done = TRUE;
+      } else {
+	  Nskip = gfits_matrix_size (headers[i]);
+	  fseek (f, Nskip, SEEK_CUR); 
+      }
+      if (i == NHEADER - 1) {
+	  NHEADER += 10;
+	  REALLOCATE (headers, Header *, NHEADER);
+      }
+  }
+  Nheader = i - 1; /* we failed on the last loop */
+    
+  // space to store the images, indexes to the matching headers
+  Nimage = 0;
+  NIMAGE = Nheader;
+  ALLOCATE (image, Image, NIMAGE);
+  ALLOCATE (exthead, char *, NIMAGE);
+  ALLOCATE (extdata, char *, NIMAGE);
+  ALLOCATE (exttype, char *, NIMAGE);
+  ALLOCATE (extnum_head, int, NIMAGE);
+  ALLOCATE (extnum_data, int, NIMAGE);
+  ALLOCATE (extsize, int, Nheader);
+
+  if (mode == MOSAIC_MEF) {
+      exthead[Nimage] = strcreate ("PHU");
+      extdata[Nimage] = strcreate ("NONE");
+      extnum_data[Nimage] = -1;
+      extnum_head[Nimage] = 0;
+      Nimage ++;
+  }
+
+  // now examine the headers, count the table entries, find corresponding headers
+  for (i = 0; i < Nheader; i++) {
+      extsize[i] = headers[i][0].size + gfits_matrix_size (headers[i]);
+      gfits_scan (headers[i], "EXTTYPE", "%s", 1, tmpword);
+
+      if (!strcmp (tmpword, "SMPDATA")   ||  
+	  !strcmp (tmpword, "PS1_DEV_0") ||  
+	  !strcmp (tmpword, "PS1_DEV_1")) {
+
+	  exttype[Nimage] = strcreate (tmpword);
+	  gfits_scan (headers[i], ExtnameKeyword, "%s", 1, tmpword);
+	  extdata[Nimage] = strcreate (tmpword);
+	  gfits_scan (headers[i], "EXTHEAD", "%s", 1, tmpword);
+	  exthead[Nimage] = strcreate (tmpword);
+	  extnum_data[Nimage] = i;
+	  extnum_head[Nimage] = -1;
+	  // find the matching exthead entry
+	  for (j = 0; j < Nheader; j++) {
+	    if (gfits_scan (headers[j], ExtnameKeyword, "%s", 1, tmpword)) {
+	      if (!strcmp (tmpword, exthead[Nimage])) {
+		extnum_head[Nimage] = j;
+	      }
+	    }
+	  }
+	  // skip or crash on table with missing matching header?
+	  if (extnum_head[Nimage] == -1) {
+	      fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
+	      exit (1);
+	  }
+	  Nimage ++;
+      }
+  }
+  // some old format files did not write EXTTYPE.  they have a single table in the first
+  // extension matched to the header in the PHU
+  if (Nimage == 0) {
+      extsize[0] = headers[0][0].size + gfits_matrix_size (headers[0]);
+      extsize[1] = headers[1][0].size + gfits_matrix_size (headers[1]);
+      gfits_scan (headers[1], ExtnameKeyword, "%s", 1, tmpword);
+      if (!strcmp (tmpword, "SMPFILE")) {
+	  extdata[Nimage] = strcreate (tmpword);
+	  exttype[Nimage] = strcreate ("SMPDATA");
+	  exthead[Nimage] = strcreate ("PHU");
+	  extnum_head[Nimage] = 0;
+	  extnum_data[Nimage] = 1;
+	  Nimage = 1;
+      }
+  }
+  if (Nimage == 0) Shutdown ("no object data in file");
+    
+  if (VERBOSE) fprintf (stderr, "file %s has %d headers, including %d images\n", file[0], Nheader, Nimage);
+
+  /* find image rootname */
+  name = filebasename (file[0]);
+
+  // now run through the images, interpret the headers and read the stars
+  for (i = N = 0; i < Nimage; i++) {
+      Nhead = extnum_head[i];
+
+      if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", exthead[i], extdata[i]);
+      if (!ReadImageHeader (headers[Nhead], &image[N], 0)) {
+	  fprintf (stderr, "skipping %s\n", exthead[i]);
+	  continue;
+      }
+
+      // XXX use something to set the chip name? EXTNAME?
+      if (!strcmp(exthead[i], "PHU") && (Nimage == 1)) {
+	snprintf (image[N].name, 64, "%s", name);
+      } else {
+	snprintf (image[N].name, 64, "%s[%s]", name, exthead[i]);
+      }
+
+      // skip the table if there is not data segment (eg, mosaic WRP image)
+      if (!strcmp(extdata[i], "NONE")) {
+	  N++;
+	  continue;
+      }
+
+      // advance the pointer to the start of the corresponding table block
+      Ndata = extnum_data[i];
+      Nskip = 0;
+      for (j = 0; j < Ndata; j++) {
+	  Nskip += extsize[j];
+      }
+      fseek (f, Nskip, SEEK_SET); 
+	 
+      inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &image[N].nstar);
+      inStars = FilterStars (inStars, &image[N]);
+      stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
+      N++;
+  }
+  free (name);
+  *Nimages = N;
+  *images = image;
+
+  if (N == 0) {
+    fprintf (stderr, "no valid image data in %s, giving up\n", filename);
+    exit (0);
+  }
+
+  return stars;
+}
Index: /trunk/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 15036)
@@ -6,5 +6,5 @@
 
   int Nastro, ccdnum, hour, min, Nx, Ny;
-  double tmp, sec, Cerror;
+  double tmp, sec, Cerror, ZeroPt;
   char *c, photname[64], line[80];
 
@@ -146,5 +146,8 @@
 
   gfits_scan (header, "ZERO_PT", "%lf", 1, &ZeroPt);
-  SetZeroPoint (ZeroPt);
+  if (ZeroPt != GetZeroPoint()) {
+      fprintf (stderr, "inconsistent zero point values: image: %f, config: %f\n", ZeroPt, GetZeroPoint()); 
+      return (FALSE);
+  }
 
   /* secz is in units milli-airmass */
@@ -152,5 +155,5 @@
   image[0].Xm   = NO_MAG;
   image[0].code = 0;
-  bzero (image[0].dummy, sizeof(image[0].dummy));
+  memset (image[0].dummy, 0, sizeof(image[0].dummy));
 
   /* find expected number of stars */
Index: /trunk/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 15036)
@@ -32,8 +32,11 @@
   stars = NULL;
   if (!strcmp (type, "SMPDATA")) {
-    stars = ConvertSMPDATA (&table, &Nstars);
+    stars = Convert_SMPDATA (&table, &Nstars);
   }
   if (!strcmp (type, "PS1_DEV_0")) {
-    stars = ConvertPS1_DEV_0 (&table, &Nstars);
+    stars = Convert_PS1_DEV_0 (&table, &Nstars);
+  }
+  if (!strcmp (type, "PS1_DEV_1")) {
+    stars = Convert_PS1_DEV_1 (&table, &Nstars);
   }
   if (stars == NULL) {
@@ -48,5 +51,5 @@
 }
 
-Stars *ConvertSMPDATA (FTable *table, int *nstars) {
+Stars *Convert_SMPDATA (FTable *table, int *nstars) {
 
   int i, Nstars, swapped;
@@ -77,13 +80,13 @@
 }
 
-// XXX I need to make the IPP I/O functions and these functions
-// consistent wrt ZERO_POINT....
-Stars *ConvertPS1_DEV_0 (FTable *table, int *nstars) {
+Stars *Convert_PS1_DEV_0 (FTable *table, int *nstars) {
 
   int i, Nstars;
+  double ZeroPt;
   Stars *stars;
   PS1_DEV_0 *ps1data;
 
   ps1data = gfits_table_get_PS1_DEV_0 (table, &Nstars, NULL);
+  ZeroPt = GetZeroPoint();
 
   ALLOCATE (stars, Stars, Nstars);
@@ -93,5 +96,5 @@
     stars[i].dX      = ps1data[i].dX;
     stars[i].dY      = ps1data[i].dY;
-    stars[i].M       = ps1data[i].M + 25.0;
+    stars[i].M       = ps1data[i].M + ZeroPt;
     stars[i].dM      = ps1data[i].dM;
     stars[i].Mpeak   = ps1data[i].Mpeak;
@@ -138,2 +141,68 @@
   return (stars);
 }
+
+// XXX I need to make the IPP I/O functions and these functions
+// consistent wrt ZERO_POINT....
+Stars *Convert_PS1_DEV_1 (FTable *table, int *nstars) {
+
+  int i, Nstars;
+  double ZeroPt;
+  Stars *stars;
+  PS1_DEV_1 *ps1data;
+
+  ps1data = gfits_table_get_PS1_DEV_1 (table, &Nstars, NULL);
+  ZeroPt = GetZeroPoint();
+
+  ALLOCATE (stars, Stars, Nstars);
+  for (i = 0; i < Nstars; i++) {
+    stars[i].X       = ps1data[i].X;
+    stars[i].Y       = ps1data[i].Y;
+    stars[i].dX      = ps1data[i].dX;
+    stars[i].dY      = ps1data[i].dY;
+    stars[i].M       = ps1data[i].M + ZeroPt;
+    stars[i].dM      = ps1data[i].dM;
+    stars[i].Mpeak   = ps1data[i].Mpeak;
+
+    stars[i].sky     = ps1data[i].sky;
+    stars[i].dsky    = ps1data[i].dSky;
+
+    stars[i].fx      = ps1data[i].fx;
+    stars[i].fy      = ps1data[i].fy;
+    stars[i].df      = ps1data[i].df;
+
+    stars[i].psfProb   = ps1data[i].psfProb;
+    stars[i].psfQual   = ps1data[i].psfQual;
+    stars[i].crNsigma  = ps1data[i].crNsigma;
+    stars[i].extNsigma = ps1data[i].extNsigma;
+
+    stars[i].detID   = ps1data[i].detID;
+
+    /* these are set elsewhere */
+    stars[i].R       = 0.0;
+    stars[i].D       = 0.0;
+    stars[i].dR      = 0.0;
+    stars[i].dD      = 0.0;
+
+    stars[i].uR      = 0.0;
+    stars[i].uD      = 0.0;
+    stars[i].duR     = 0.0;
+    stars[i].duD     = 0.0;
+
+    stars[i].P       = 0.0;
+    stars[i].dP      = 0.0;
+
+    stars[i].Mcal    = 0;
+    stars[i].t       = 0;
+    stars[i].dt      = 0;
+    stars[i].airmass = 0;
+    stars[i].code    = 0;
+    stars[i].found   = 0;
+
+    /* these are not used */
+    stars[i].Map     = NO_MAG;
+    stars[i].Mgal    = NO_MAG;
+    stars[i].dophot  = 0;
+  }    
+  *nstars = Nstars;
+  return (stars);
+}
Index: /trunk/Ohana/src/addstar/src/ReadStarsTEXT.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ReadStarsTEXT.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/ReadStarsTEXT.c	(revision 15036)
@@ -39,5 +39,5 @@
 	Nskip = c2 - c;
 	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
+	memset (buffer + nbytes, 0, Nskip);
 	if (VERBOSE) fprintf (stderr, "deleted %d extra return chars\n", Nskip);
       }
@@ -52,5 +52,5 @@
 	Nskip = c2 - c;
 	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
+	memset (buffer + nbytes, 0, Nskip);
 	if (VERBOSE) fprintf (stderr, "deleted line, %d extra chars\n", Nskip);
       } else {
Index: /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/SkyTableFromTychoIndex.c	(revision 15036)
@@ -34,5 +34,5 @@
     tycho[i].Dmax = atof (&line[36]);
 
-    bzero (tycho[i].name, 21);
+    memset (tycho[i].name, 0, 21);
     strncpy (tycho[i].name, line, 7);
     tycho[i].name[7] = 0;
@@ -56,5 +56,5 @@
   regions[Nr].child  	=  TRUE;
   regions[Nr].table  	=  FALSE;
-  bzero (regions[Nr].name, 21);
+  memset (regions[Nr].name, 0, 21);
   strcpy (regions[Nr].name, "fullsky");
   
@@ -75,5 +75,5 @@
     regions[Nr].child  	  =  TRUE;
     regions[Nr].table  	  =  FALSE;
-    bzero (regions[Nr].name, 21);
+    memset (regions[Nr].name, 0, 21);
     strcpy (regions[Nr].name, DecNames[i]);
   }
@@ -89,5 +89,5 @@
     regions[Nr].child  	  =  TRUE;
     regions[Nr].table  	  =  FALSE;
-    bzero (regions[Nr].name, 21);
+    memset (regions[Nr].name, 0, 21);
     strcpy (regions[Nr].name, DecNames[i+13]);
   }
Index: /trunk/Ohana/src/addstar/src/SocketOps.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SocketOps.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/SocketOps.c	(revision 15036)
@@ -13,5 +13,5 @@
 
   host = gethostbyname (hostname);
-  bzero (hostip, 80);
+  memset (hostip, 0, 80);
   for (i = 0; i < host[0].h_length; i++) {
     sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
@@ -125,5 +125,5 @@
 
   host = gethostbyname (hostname);
-  bzero (hostip, 80);
+  memset (hostip, 0, 80);
   for (i = 0; i < host[0].h_length; i++) {
     sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
@@ -170,5 +170,5 @@
 
   host = gethostbyname (hostname);
-  bzero (hostip, 80);
+  memset (hostip, 0, 80);
   for (i = 0; i < host[0].h_length; i++) {
     sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
Index: /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c
===================================================================
--- /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 15036)
@@ -96,5 +96,5 @@
     if (db.dbstate == LCK_EMPTY) {
       if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
-      dvo_image_create (&db, ZeroPt);
+      dvo_image_create (&db, GetZeroPoint());
     } else {
       if (!dvo_image_load (&db, VERBOSE, FORCE_READ)) {
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 15036)
@@ -37,5 +37,5 @@
   switch (options.mode) {
     case M_IMAGE:
-      stars = gstars (argv[1], &Nstars, &images, &Nimages, options.photcode);
+      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, options.photcode);
       if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
       for (i = 0; i < Nimages; i++) {
@@ -163,6 +163,7 @@
   /* load or create the image table */
   if (db.dbstate == LCK_EMPTY) {
+    double ZeroPt;
     if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
-    dvo_image_create (&db, ZeroPt);
+    dvo_image_create (&db, GetZeroPoint());
   } else {
     if (!dvo_image_load (&db, VERBOSE, FORCE_READ)) {
Index: /trunk/Ohana/src/addstar/src/addstarc.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstarc.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/addstarc.c	(revision 15036)
@@ -21,5 +21,5 @@
     case M_IMAGE:
       /* load data */
-      stars = gstars (argv[1], &Nstars, &images, &Nimages, options.photcode);
+      stars = LoadStars (argv[1], &Nstars, &images, &Nimages, options.photcode);
 
       /* send data to server */
Index: /trunk/Ohana/src/addstar/src/calibrate.c
===================================================================
--- /trunk/Ohana/src/addstar/src/calibrate.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/calibrate.c	(revision 15036)
@@ -113,5 +113,5 @@
     }
     if (found0 && found1 && found2) {
-      Mcal   = new[0].M + 0.001*mycode[0].C + mycode[0].K*(new[0].airmass - 1.0) - ZeroPt;
+      Mcal   = new[0].M + 0.001*mycode[0].C + mycode[0].K*(new[0].airmass - 1.0) - GetZeroPoint();
       color  = CalM1 - CalM2 - 0.001*mycode[0].dX;
       factor = color;
@@ -124,5 +124,5 @@
       }
       // if we want to apply a Mcal -> Mref color correction, we need the additional color term
-      Minst = new[0].M - ZeroPt - new[0].dt;
+      Minst = new[0].M - GetZeroPoint() - new[0].dt;
       SaveCalibration (Mcal, new[0].dM, CalM0, dCalM, Minst, Nstar);
       if ((DUMP != NULL) && !strcmp (DUMP, "cal")) {
@@ -156,5 +156,5 @@
   /* create a hash array from Nstar[] entries */
   ALLOCATE (Nlist, int, MaxN + 1);
-  bzero (Nlist, MAX (0, MaxN*sizeof(int)));
+  memset (Nlist, 0, MAX (0, MaxN*sizeof(int)));
   for (i = 0; i < Ncal; i++) {
     Nlist[Nstar[i]] ++;
Index: /trunk/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- /trunk/Ohana/src/addstar/src/fakeimage.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/fakeimage.c	(revision 15036)
@@ -130,5 +130,5 @@
     image[i+1].Xm   = NO_MAG;
     image[i+1].code = 0;
-    bzero (image[i+1].dummy, sizeof(image[i+1].dummy));
+    memset (image[i+1].dummy, 0, sizeof(image[i+1].dummy));
 
     image[i+1].nstar = 0;
@@ -189,5 +189,5 @@
   image[0].Xm   = NO_MAG;
   image[0].code = 0;
-  bzero (image[0].dummy, sizeof(image[0].dummy));
+  memset (image[0].dummy, 0, sizeof(image[0].dummy));
   image[0].nstar = 0;
   image[0].Myyyy = 0;
Index: /trunk/Ohana/src/addstar/src/find_proper.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_proper.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/find_proper.c	(revision 15036)
@@ -27,5 +27,5 @@
   /* no need to do this twice!! */
   ALLOCATE (usnodist, float, Nave);
-  bzero (usnodist, Nave*sizeof(float));
+  memset (usnodist, 0, Nave*sizeof(float));
 
   X2 = usnostats[0].X;
Index: /trunk/Ohana/src/addstar/src/getusno.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusno.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/getusno.c	(revision 15036)
@@ -110,5 +110,5 @@
       if (buf[1] > iDEC1) continue;
 
-      bzero (&stars[Nusno], sizeof(Stars));
+      memset (&stars[Nusno], 0, sizeof(Stars));
       stars[Nusno].R     = buf[0]/360000.0;
       stars[Nusno].D     = buf[1]/360000.0 - 90.0;
Index: /trunk/Ohana/src/addstar/src/getusnob.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusnob.c	(revision 15035)
+++ /trunk/Ohana/src/addstar/src/getusnob.c	(revision 15036)
@@ -120,5 +120,5 @@
       /* USNO coords are reported for J2000 / epoch 2000.0 */
       /* extract the basic stellar data */
-      bzero (&stars[Nusno], sizeof(Stars));
+      memset (&stars[Nusno], 0, sizeof(Stars));
       stars[Nusno].R   = buf[0]/360000.0;
       stars[Nusno].D   = buf[1]/360000.0 - 90.0;
Index: unk/Ohana/src/addstar/src/gimages.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gimages.c	(revision 15035)
+++ 	(revision )
@@ -1,170 +1,0 @@
-# include "addstar.h"
-void SetImageCorners (double *X, double *Y, Image *image);
-
-/* given image, find catalog images which overlap it */
-Image *gimages (FITS_DB *db, Image *image, Coords *mosaic, int *Npimage) {
-  
-  int i, j, k, addtolist;
-  int NPIMAGE, npimage, Ntimage;
-  Image *timage, *pimage;
-  Coords tcoords;
-  double r, d, x, y;
-  double Xb[5], Yb[5], Xi[5], Yi[5], Xo[5], Yo[5];  /* image and original corners */
-  double zeropt;
-
-  /* if image.db is opened successfully, f will not be NULL.
-     if image.db is empty, dbstate will be LCK_EMPTY 
-     if image.db is not locked & opened successfully, we will not reach here!
-  */
-  if (db[0].dbstate == LCK_EMPTY) {
-    *Npimage = 0;
-    return (NULL);
-  }
-
-  /* read entire db table (use block read eventually?) */
-  if (!dvo_image_load (db, VERBOSE, FORCE_READ)) {
-    Shutdown ("can't read image catalog %s", db[0].filename);
-  }
-  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
-
-  gfits_scan (&db[0].header, "ZERO_PT", "%lf", 1, &zeropt);
-  if (fabs (ZeroPt - zeropt) > 1e-4) {
-    Shutdown ("zero point in image (%f:%s) inconsistent with zero point in catalog (%f)",
-	     ZeroPt, image[0].name, zeropt);
-  }
-
-  /* project onto rectilinear grid with 1 arcsec pixels */
-  /* 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---TAN");
-    RegisterMosaic (mosaic);
-    /* register so image->sky conversions below have correct mosaic */
-  } 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;
-    strcpy (tcoords.ctype, "RA---TAN");
-  }
-
-  /* define original corners */
-  SetImageCorners (Xo, Yo, &image[0]);
-  Xo[4] = Xo[0]; Yo[4] = Yo[0];  /* so we can make a loop easily */
-
-  for (j = 0; j < 5; j++) {
-    /* XY-to_RD is two-level if ctype == WRP */
-    XY_to_RD (&r, &d, Xo[j], Yo[j], &image[0].coords);
-    RD_to_XY (&Xo[j], &Yo[j], r, d, &tcoords);
-  }
-  
-  /* pimage represents the subset of overlapping images */
-  npimage = 0;
-  NPIMAGE = 20;
-  ALLOCATE (pimage, Image, NPIMAGE);
-
-  /* setup links for mosaic WRP and DIS entries */
-  BuildChipMatch (timage, Ntimage);
-
-  /* run through image table and search for overlaps
-     also define the vtable entries for the images we keep  */
-
-  for (i = 0; i < Ntimage; i++) {
-
-    /* if any of these images are WRP images, need to find matching DIS */
-    if (!FindMosaicForImage (timage, Ntimage, i)) continue;
-
-    addtolist = FALSE;
-
-    /* define image corners */
-    SetImageCorners (Xi, Yi, &timage[i]);
-    Xi[4] = Xi[0]; Yi[4] = Yi[0];
-    /* transform to tcoords */
-    for (j = 0; j < 5; j++) {
-      XY_to_RD (&r, &d, Xi[j], Yi[j], &timage[i].coords);
-      RD_to_XY (&Xi[j], &Yi[j], r, d, &tcoords);
-    }
-    /* check if any edges cross */
-    for (j = 0; (j < 4) && !addtolist; j++) {
-      for (k = 0; (k < 4) && !addtolist; k++) {
-	addtolist |= edge_check (&Xi[j], &Yi[j], &Xo[k], &Yo[k]);
-      }
-    }
-    
-    /* note that 0,0 is a valid pixel for both DIS and !DIS */
-    /* if no edges cross, check if 0,0 pixel of timage[i] is inside image[0] */
-    SetImageCorners (Xb, Yb, &image[0]);
-    if (!addtolist) {
-      XY_to_RD (&r, &d, 0.0, 0.0, &timage[i].coords);
-      RD_to_XY (&x, &y, r, d, &image[0].coords);
-      addtolist = TRUE;
-      addtolist &= (x < Xb[0]);
-      addtolist &= (y < Yb[0]);
-      addtolist &= (x > Xb[2]);
-      addtolist &= (y > Yb[2]);
-    }
-
-    /* if no edges cross, check if one corner of image[0] is inside timage[i] */
-    SetImageCorners (Xb, Yb, &timage[i]);
-    if (!addtolist) {
-      XY_to_RD (&r, &d, 0.0, 0.0, &image[0].coords);
-      RD_to_XY (&x, &y, r, d, &timage[i].coords);
-      addtolist = TRUE;
-      addtolist &= (x < Xb[0]);
-      addtolist &= (y < Yb[0]);
-      addtolist &= (x > Xb[2]);
-      addtolist &= (y > Yb[2]);
-    }
-
-    if (addtolist) {
-      pimage[npimage] = timage[i];
-      npimage ++;
-      if (npimage == NPIMAGE) {
-	NPIMAGE += 20;
-	REALLOCATE (pimage, Image, NPIMAGE);
-      }
-    }
-  }
-
-  BuildChipMatch (pimage, npimage);
-  
-  if (VERBOSE) fprintf (stderr, "found %d overlapping images\n", npimage);
-
-  *Npimage = npimage;
-  return (pimage);
-}
-  
-/* this function tries to find overlapping images with the current image.
-   it loads the image table in blocks (up to 1000 at a time) and looks
-   for overlaps within the set.  the search is not very robust. in 
-   addition, it needs to look for mosaic DIS images matching any WRP images.
-   if the WRP image is loaded near the beginning of a block, then the corresponding DIS 
-   may be in the previous block, and thus missed 
-
-   we are not adding the matching DIS image to the table.
-
-   we are now loading in the entire image db table into memory.  
-
-*/
-
-# if (0)
-void SetImageCorners (double *X, double *Y, Image *image) {
-
-  if (!strcmp(&image[0].coords.ctype[4], "-DIS")) {
-    X[0] = -0.5*image[0].NX; Y[0] = -0.5*image[0].NY;
-    X[1] = +0.5*image[0].NX; Y[1] = -0.5*image[0].NY;
-    X[2] = +0.5*image[0].NX; Y[2] = +0.5*image[0].NY;
-    X[3] = -0.5*image[0].NX; Y[3] = +0.5*image[0].NY;
-  } else {
-    X[0] = 0;           Y[0] = 0;
-    X[1] = image[0].NX; Y[1] = 0;
-    X[2] = image[0].NX; Y[2] = image[0].NY;
-    X[3] = 0;           Y[3] = image[0].NY;
-  }
-}
-# endif
Index: unk/Ohana/src/addstar/src/gstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gstars.c	(revision 15035)
+++ 	(revision )
@@ -1,262 +1,0 @@
-# include "addstar.h"
-
-Stars *gstars (char *filename, int *Nstars, Image **images, int *Nimages, int photcode) {
-
-  int i, j, N, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
-  int Nskip, Nhead, Ndata, done, status, mode, NinStars;
-  char **file, *name;
-  FILE *f;
-  glob_t globList;
-  char **exthead, **extdata, **exttype, tmpword[80];
-  int *extnum_head, *extnum_data, *extsize;
-  Header *header, **headers;
-  Image *image;
-  Stars *inStars, *stars;
-
-  // parse the filename as a glob
-  globList.gl_offs = 0;
-  glob (filename, 0, NULL, &globList);
-
-  // if the glob does not match, save the literal word:
-  // otherwise save all glob matches
-  if (globList.gl_pathc == 0) {
-    Nfile = 1;
-    ALLOCATE (file, char *, Nfile);
-    file[0] = strcreate (filename);
-  } else {
-    Nfile = globList.gl_pathc;
-    ALLOCATE (file, char *, Nfile);
-    for (i = 0; i < Nfile; i++) {
-      file[i] = strcreate (globList.gl_pathv[i]);
-    }
-  }
-
-  // open the first file, read the PHU header
-  f = fopen (file[0], "r");
-  if (f == NULL) {
-    fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
-    exit (1);
-  }
-  ALLOCATE (header, Header, 1);
-  gfits_fread_header (f, header);
-
-  mode = GetFileMode (header);
-
-  stars = NULL;
-  *Nstars = 0;
-
-  /*** load data from a single PHU or a collection of PHU files ***/
-  if ((mode != SIMPLE_MEF) && (mode != MOSAIC_MEF)) {
-    Nimage = Nfile;
-    ALLOCATE (image, Image, Nimage);
-    for (i = N = 0; i < Nfile; i++) {
-      // XXX we should not drop all input images if one fails
-      if (i > 0) {
-	f = fopen (file[i], "r");
-	if (f == NULL) {
-	  fprintf (stderr, "can't read header for %s, skipping\n", file[i]);
-	  continue;
-	}
-	gfits_fread_header (f, header);
-      }
-
-      if (!ReadImageHeader (header, &image[N], photcode)) {
-	fprintf (stderr, "skipping %s\n", file[i]);
-	continue;
-      }
-      
-      /* find image rootname */
-      name = filebasename (file[i]);
-      snprintf (image[N].name, 64, name);
-      free (name);
-    
-      switch (mode) {
-	case SIMPLE_CMP:
-	case MOSAIC_CMP:
-	  inStars = ReadStarsTEXT (f, &image[N].nstar);
-	  inStars = FilterStars (inStars, &image[N]);
-	  stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
-	  break;
-
-	case SIMPLE_CMF:
-	case MOSAIC_CMF:
-	  inStars = ReadStarsFITS (f, header, NULL, &image[N].nstar);
-	  inStars = FilterStars (inStars, &image[N]);
-	  stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
-	  break;
-
-	case MOSAIC_PHU:
-	  inStars = NULL;
-	  NinStars = 0;
-	  break;
-      }
-      fclose (f);
-      gfits_free_header (header);
-      N++;
-    }
-    *Nimages = N;
-    *images = image;
-    
-    if (N == 0) {
-      // XXX how do we track this error?
-      fprintf (stderr, "no valid image data in %s, giving up\n", filename);
-      exit (0);
-    }
-
-    return stars;
-  }
-    
-  /* we have a multi-chip image */
-
-  /* supplied photcode is incompatible with multi-chip images */
-  if (photcode) {
-    fprintf (stderr, "ERROR: photcode cannot be supplied to multi-chip images -- manually adjust the headers\n");
-    exit (1);
-  }
-
-  /* we need to examine the extensions to determine the headers and the data */
-  NHEADER = 10;
-  ALLOCATE (headers, Header *, NHEADER);
-
-  // the first header is already loaded
-  headers[0] = header;
-  Nskip = gfits_matrix_size (header);
-  fseek (f, Nskip, SEEK_CUR); 
-
-  // load all headers into memory
-  done = FALSE;
-  for (i = 1; !done; i++) {
-      ALLOCATE (headers[i], Header, 1);
-      status = gfits_fread_header (f, headers[i]);
-      if (!status) { 
-	  done = TRUE;
-      } else {
-	  Nskip = gfits_matrix_size (headers[i]);
-	  fseek (f, Nskip, SEEK_CUR); 
-      }
-      if (i == NHEADER - 1) {
-	  NHEADER += 10;
-	  REALLOCATE (headers, Header *, NHEADER);
-      }
-  }
-  Nheader = i - 1; /* we failed on the last loop */
-    
-  // space to store the images, indexes to the matching headers
-  Nimage = 0;
-  NIMAGE = Nheader;
-  ALLOCATE (image, Image, NIMAGE);
-  ALLOCATE (exthead, char *, NIMAGE);
-  ALLOCATE (extdata, char *, NIMAGE);
-  ALLOCATE (exttype, char *, NIMAGE);
-  ALLOCATE (extnum_head, int, NIMAGE);
-  ALLOCATE (extnum_data, int, NIMAGE);
-  ALLOCATE (extsize, int, Nheader);
-
-  if (mode == MOSAIC_MEF) {
-      exthead[Nimage] = strcreate ("PHU");
-      extdata[Nimage] = strcreate ("NONE");
-      extnum_data[Nimage] = -1;
-      extnum_head[Nimage] = 0;
-      Nimage ++;
-  }
-
-  // now examine the headers, count the table entries, find corresponding headers
-  for (i = 0; i < Nheader; i++) {
-      extsize[i] = headers[i][0].size + gfits_matrix_size (headers[i]);
-      gfits_scan (headers[i], "EXTTYPE", "%s", 1, tmpword);
-
-      if (!strcmp (tmpword, "SMPDATA") ||  
-	  !strcmp (tmpword, "PS1_DEV_0")) {
-
-	  exttype[Nimage] = strcreate (tmpword);
-	  gfits_scan (headers[i], ExtnameKeyword, "%s", 1, tmpword);
-	  extdata[Nimage] = strcreate (tmpword);
-	  gfits_scan (headers[i], "EXTHEAD", "%s", 1, tmpword);
-	  exthead[Nimage] = strcreate (tmpword);
-	  extnum_data[Nimage] = i;
-	  extnum_head[Nimage] = -1;
-	  // find the matching exthead entry
-	  for (j = 0; j < Nheader; j++) {
-	    if (gfits_scan (headers[j], ExtnameKeyword, "%s", 1, tmpword)) {
-	      if (!strcmp (tmpword, exthead[Nimage])) {
-		extnum_head[Nimage] = j;
-	      }
-	    }
-	  }
-	  // skip or crash on table with missing matching header?
-	  if (extnum_head[Nimage] == -1) {
-	      fprintf (stderr, "ERROR: can't read header for %s\n", file[0]);
-	      exit (1);
-	  }
-	  Nimage ++;
-      }
-  }
-  // some old format files did not write EXTTYPE.  they have a single table in the first
-  // extension matched to the header in the PHU
-  if (Nimage == 0) {
-      extsize[0] = headers[0][0].size + gfits_matrix_size (headers[0]);
-      extsize[1] = headers[1][0].size + gfits_matrix_size (headers[1]);
-      gfits_scan (headers[1], ExtnameKeyword, "%s", 1, tmpword);
-      if (!strcmp (tmpword, "SMPFILE")) {
-	  extdata[Nimage] = strcreate (tmpword);
-	  exttype[Nimage] = strcreate ("SMPDATA");
-	  exthead[Nimage] = strcreate ("PHU");
-	  extnum_head[Nimage] = 0;
-	  extnum_data[Nimage] = 1;
-	  Nimage = 1;
-      }
-  }
-  if (Nimage == 0) Shutdown ("no object data in file");
-    
-  if (VERBOSE) fprintf (stderr, "file %s has %d headers, including %d images\n", file[0], Nheader, Nimage);
-
-  /* find image rootname */
-  name = filebasename (file[0]);
-
-  // now run through the images, interpret the headers and read the stars
-  for (i = N = 0; i < Nimage; i++) {
-      Nhead = extnum_head[i];
-
-      if (VERBOSE) fprintf (stderr, "reading header for %s (%s)\n", exthead[i], extdata[i]);
-      if (!ReadImageHeader (headers[Nhead], &image[N], 0)) {
-	  fprintf (stderr, "skipping %s\n", exthead[i]);
-	  continue;
-      }
-
-      // XXX use something to set the chip name? EXTNAME?
-      if (!strcmp(exthead[i], "PHU") && (Nimage == 1)) {
-	snprintf (image[N].name, 64, "%s", name);
-      } else {
-	snprintf (image[N].name, 64, "%s[%s]", name, exthead[i]);
-      }
-
-      // skip the table if there is not data segment (eg, mosaic WRP image)
-      if (!strcmp(extdata[i], "NONE")) {
-	  N++;
-	  continue;
-      }
-
-      // advance the pointer to the start of the corresponding table block
-      Ndata = extnum_data[i];
-      Nskip = 0;
-      for (j = 0; j < Ndata; j++) {
-	  Nskip += extsize[j];
-      }
-      fseek (f, Nskip, SEEK_SET); 
-	 
-      inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &image[N].nstar);
-      inStars = FilterStars (inStars, &image[N]);
-      stars = MergeStars (stars, Nstars, inStars, image[N].nstar);
-      N++;
-  }
-  free (name);
-  *Nimages = N;
-  *images = image;
-
-  if (N == 0) {
-    fprintf (stderr, "no valid image data in %s, giving up\n", filename);
-    exit (0);
-  }
-
-  return stars;
-}
Index: unk/Ohana/src/addstar/src/rfits.c
===================================================================
--- /trunk/Ohana/src/addstar/src/rfits.c	(revision 15035)
+++ 	(revision )
@@ -1,44 +1,0 @@
-# include "addstar.h"
-
-Stars *rfits (FILE *f, unsigned int *nstars) {
-
-  int i, Nstars;
-  Header theader;
-  FTable table;
-  Stars *stars;
-  SMPData *smpdata;
-
-  /* if no stars, no table */
-  if (*nstars == 0) return (NULL);
-
-  /* init & load in table data */
-  table.header   = &theader;
-  if (!gfits_fread_ftable (f, &table, "SMPFILE")) goto escape;
-
-  smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL);
-
-  ALLOCATE (stars, Stars, Nstars);
-  for (i = 0; i < Nstars; i++) {
-    stars[i].X      = smpdata[i].X;
-    stars[i].Y      = smpdata[i].Y;
-    stars[i].M      = smpdata[i].M;
-    stars[i].dM     = smpdata[i].dM;
-    stars[i].dophot = smpdata[i].dophot;
-
-    stars[i].Mgal   = smpdata[i].M;
-    stars[i].Map    = smpdata[i].dM;
-    stars[i].fx     = smpdata[i].fx;
-    stars[i].fy     = smpdata[i].fy;
-    stars[i].df     = smpdata[i].df;
-  }    
-  *nstars = Nstars;
-  return (stars);
-
-escape:
-  fprintf (stderr, "error reading file\n");
-  *nstars = 0;
-  return (NULL);
-}
-
-// **** this needs to be fixed to handle MEF smp files...
-// there will be multiple extension names, how will these get passed?
Index: unk/Ohana/src/addstar/src/rtext.c
===================================================================
--- /trunk/Ohana/src/addstar/src/rtext.c	(revision 15035)
+++ 	(revision )
@@ -1,85 +1,0 @@
-# include "addstar.h"
-# define D_NSTARS 1000
-# define BYTES_STAR 66
-# define BLOCK 1000
-
-Stars *rtext (FILE *f, unsigned int *nstars) {
-
-  int j, N, Nextra, Ninstar, Nskip, Nbytes, nbytes;
-  int done;
-  char *buffer, *c, *c2;
-  double tmp;
-  Stars *stars;
-  
-  /* load in stars by blocks of 1000 */
-  N = 0;
-  ALLOCATE (buffer, char, (BLOCK*BYTES_STAR) + 1);
-  buffer[BLOCK*BYTES_STAR] = 0;
-  Nextra = 0;
-
-  ALLOCATE (stars, Stars, *nstars);
-
-  while (N < *nstars) {
-    /* load next data block */
-    Nbytes = BYTES_STAR * BLOCK - Nextra;
-    nbytes = fread (&buffer[Nextra], 1, Nbytes, f);
-    if (nbytes == 0) {
-      *nstars = N;
-      return (stars);
-    }
-    nbytes += Nextra;
-
-    /* check line-by-line integrity */
-    c = buffer;
-    done = FALSE;
-    while ((c < buffer + nbytes) && (!done)) { 
-      for (c2 = c; *c2 == '\n'; c2++);
-      if (c2 > c) { /* extra return chars */
-	memmove (c, c2, (int)(buffer + nbytes - c2));
-	Nskip = c2 - c;
-	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
-	if (VERBOSE) fprintf (stderr, "deleted %d extra return chars\n", Nskip);
-      }
-      c2 = strchr (c, '\n');
-      if (c2 == (char *) NULL) {
-	done = TRUE;	
-	continue;
-      }
-      c2++;
-      if ((c2 - c) != BYTES_STAR) { /* bad line, delete it */
-	memmove (c, c2, (int)(buffer + nbytes - c2));
-	Nskip = c2 - c;
-	nbytes -= Nskip;
-	bzero (buffer + nbytes, Nskip);
-	if (VERBOSE) fprintf (stderr, "deleted line, %d extra chars\n", Nskip);
-      } else {
-	c = c2;
-      }
-    }
-
-    /* extract data for stars */
-    Ninstar = nbytes / BYTES_STAR;
-    Nextra = nbytes % BYTES_STAR;
-    for (j = 0; (j < Ninstar) && (N < *nstars); j++, N++) {
-      dparse (&stars[N].X,  1, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].Y,  2, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].M,  3, &buffer[j*BYTES_STAR]);
-
-      /* cmp files carry dM in millimags */
-      dparse (&tmp, 4, &buffer[j*BYTES_STAR]);
-      stars[N].dM = 0.001*tmp;
-
-      dparse (&tmp,         5, &buffer[j*BYTES_STAR]);
-      stars[N].dophot = tmp;
-
-      dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].Map,  8, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].fx,   9, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].fy,  10, &buffer[j*BYTES_STAR]);
-      dparse (&stars[N].df,  11, &buffer[j*BYTES_STAR]);
-    }
-  }
-  *nstars = N;
-  return (stars);
-}
