Index: trunk/Ohana/src/addstar/Makefile
===================================================================
--- trunk/Ohana/src/addstar/Makefile	(revision 11880)
+++ trunk/Ohana/src/addstar/Makefile	(revision 12332)
@@ -240,3 +240,3 @@
 
 install:
-	for i in $(INSTALL); do make $$i.install; done
+	for i in $(INSTALL); do make $$i.install || exit; done
Index: trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 12332)
@@ -7,5 +7,6 @@
   char *config, *file;
   char RadiusWord[80];
-  char PhotCodeFile[256];
+  char CatdirPhotcodeFile[256];
+  char MasterPhotcodeFile[256];
   AddstarClientOptions options;
 
@@ -61,6 +62,6 @@
   CAL_INSTMAG_MAX =  -9.0;
   CAL_INSTMAG_MIN = -13.0;
-  ScanConfig (config, "CAL_INSTMAG_MAX",   "%lf", 0, &CAL_INSTMAG_MAX);
-  ScanConfig (config, "CAL_INSTMAG_MIN",   "%lf", 0, &CAL_INSTMAG_MIN);
+  ScanConfig (config, "CAL_INSTMAG_MAX",        "%lf", 0, &CAL_INSTMAG_MAX);
+  ScanConfig (config, "CAL_INSTMAG_MIN",        "%lf", 0, &CAL_INSTMAG_MIN);
 
   /* location of needed data sources */
@@ -69,14 +70,14 @@
   ScanConfig (config, "GSCDIR",                 "%s",  0, GSCDIR);
 
-  if (!ScanConfig (config, "USNO_A_DIR",             "%s",  0, USNO_A_DIR)) {
-    ScanConfig (config, "USNO_CDROM",             "%s",  0, USNO_A_DIR);
+  if (!ScanConfig (config, "USNO_A_DIR",        "%s",  0, USNO_A_DIR)) {
+    ScanConfig (config, "USNO_CDROM",           "%s",  0, USNO_A_DIR);
   }
   ScanConfig (config, "USNO_B_DIR",             "%s",  0, USNO_B_DIR);
 
-  ScanConfig (config, "TYCHO_DIR",             "%s",  0, TYCHO_DIR);
+  ScanConfig (config, "TYCHO_DIR",             	"%s",  0, TYCHO_DIR);
 
-  GetConfig (config, "GSCFILE",                "%s",  0, GSCFILE);
-  GetConfig (config, "CATDIR",                 "%s",  0, CATDIR);
-  GetConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
+  GetConfig (config, "GSCFILE",                	"%s",  0, GSCFILE);
+  GetConfig (config, "CATDIR",                 	"%s",  0, CATDIR);
+  GetConfig (config, "PHOTCODE_FILE",          	"%s",  0, MasterPhotcodeFile);
   ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
@@ -147,6 +148,8 @@
   if (*CATFORMAT == 0) strcpy (CATFORMAT, "ELIXIR");
 
-  if (!LoadPhotcodes (PhotCodeFile)) {
-    fprintf (stderr, "error loading photcode file %s\n", PhotCodeFile);
+  /* XXX this does not yet write out the master photcode table */
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
+    fprintf (stderr, "error loading photcode table %s or master file %s\n", CatdirPhotcodeFile, MasterPhotcodeFile);
     exit (1);
   }
Index: trunk/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/FilterStars.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/FilterStars.c	(revision 12332)
@@ -25,11 +25,11 @@
     while (stars[N].R >= 360.0) stars[N].R -= 360.0;
     stars[N].found = -1;
-    stars[N].code = image[0].source;
+    stars[N].code = image[0].photcode;
 
     /** additional quantities to supply to Stars based on the image data **/
 
     /* calculate accurate per-star airmass */
-    stars[N].airmass = airmass (image[0].secz_PS, stars[N].R, stars[N].D, image[0].sidtime, image[0].latitude);
-    stars[N].Mcal    = image[0].Mcal_PS;
+    stars[N].airmass = airmass (image[0].secz, stars[N].R, stars[N].D, image[0].sidtime, image[0].latitude);
+    stars[N].Mcal    = image[0].Mcal;
     stars[N].t       = image[0].tzero + 1e-4*stars[N].Y*image[0].trate;  /* trate is in 0.1 msec / row */
 
Index: trunk/Ohana/src/addstar/src/ImageOptions.c
===================================================================
--- trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/ImageOptions.c	(revision 12332)
@@ -24,5 +24,5 @@
     if (!strcmp (&images[0].coords.ctype[4], "-DIS")) continue;
 
-    photcode = GetPhotcodebyCode (images[i].source);
+    photcode = GetPhotcodebyCode (images[i].photcode);
 
     if (equivPhotcode) {
Index: trunk/Ohana/src/addstar/src/LoadStars.c
===================================================================
--- trunk/Ohana/src/addstar/src/LoadStars.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/LoadStars.c	(revision 12332)
@@ -52,5 +52,5 @@
     exit (1);
   }
-  image[0].source = photcode;
+  image[0].photcode = photcode;
 
   image[0].NX -= XOVERSCAN;
@@ -62,9 +62,9 @@
   tmp = 0;
   /* gfits_scan (&header, "APMIFIT",  "%lf", 1, &tmp); */
-  image[0].apmifit_PS = tmp;
+  image[0].apmifit = tmp;
 
   tmp = 0;
   /* gfits_scan (&header, "dAPMIFIT", "%lf", 1, &tmp); */
-  image[0].dapmifit_PS = tmp;
+  image[0].dapmifit = tmp;
 
   tmp = 0;
@@ -108,5 +108,5 @@
   tmp = 0;
   gfits_scan (&header, AirmassKeyword, "%lf", 1, &tmp);
-  image[0].secz_PS = MIN (NO_MAG, tmp);
+  image[0].secz = MIN (NO_MAG, tmp);
 
   if (!gfits_scan (&header, CCDNumKeyword, "%d", 1, &itmp)) {
@@ -120,5 +120,5 @@
 
   /* secz is in units milli-airmass */
-  image[0].Mcal_PS = 0.0;
+  image[0].Mcal = 0.0;
   image[0].Xm   = NO_MAG;
   image[0].code = 0;
Index: trunk/Ohana/src/addstar/src/ReadImageHeader.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/ReadImageHeader.c	(revision 12332)
@@ -5,7 +5,7 @@
 int ReadImageHeader (Header *header, Image *image, int photcode) {
 
-  int Nastro, ccdnum, hour, min, simple;
-  double tmp, sec, dMs;
-  char *name, *c, photname[64], line[80];
+  int Nastro, ccdnum, hour, min;
+  double tmp, sec;
+  char *c, photname[64], line[80];
 
   /* get astrometry information */
@@ -66,5 +66,5 @@
     exit (1);
   }
-  image[0].source = photcode;
+  image[0].photcode = photcode;
 
   image[0].NX -= XOVERSCAN;
@@ -76,9 +76,9 @@
   tmp = 0;
   /* gfits_scan (header, "APMIFIT",  "%lf", 1, &tmp); */
-  image[0].apmifit_PS = tmp;
+  image[0].apmifit = tmp;
 
   tmp = 0;
   /* gfits_scan (header, "dAPMIFIT", "%lf", 1, &tmp); */
-  image[0].dapmifit_PS = tmp;
+  image[0].dapmifit = tmp;
 
   tmp = 0;
@@ -118,5 +118,5 @@
   tmp = 0;
   gfits_scan (header, AirmassKeyword, "%lf", 1, &tmp);
-  image[0].secz_PS = MIN (NO_MAG, tmp);
+  image[0].secz = MIN (NO_MAG, tmp);
 
   if (!gfits_scan (header, CCDNumKeyword, "%d", 1, &ccdnum)) {
@@ -130,5 +130,5 @@
 
   /* secz is in units milli-airmass */
-  image[0].Mcal_PS = 0.0;
+  image[0].Mcal = 0.0;
   image[0].Xm   = NO_MAG;
   image[0].code = 0;
Index: trunk/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 12332)
@@ -5,5 +5,5 @@
 Stars *ReadStarsFITS (FILE *f, Header *header, Header *in_theader, unsigned int *nstars) {
 
-  int i, Nskip, Nstars;
+  int Nskip, Nstars;
   char type[80];
   Header theader;
@@ -13,15 +13,7 @@
   if (in_theader == NULL) {
     table.header = &theader;
+    if (!gfits_fread_header (f, table.header)) Shutdown ("ERROR: can't read table header");
   } else {
     table.header = in_theader;
-  }
-
-  /* load the table header (skip this?) */
-  if (in_theader == NULL) {
-    if (!gfits_fread_header (f, &theader)) {
-      fprintf (stderr, "ERROR: can't read table header\n");
-      exit (1);
-    }
-  } else {
     Nskip = in_theader[0].size;
     fseek (f, Nskip, SEEK_CUR); 
@@ -34,5 +26,5 @@
   }
 
-  if (!gfits_scan (&theader, "EXTTYPE", "%s", 1, type)) {
+  if (!gfits_scan (table.header, "EXTTYPE", "%s", 1, type)) {
     strcpy (type, "SMPDATA");
   }
@@ -93,5 +85,5 @@
   PS1Data *ps1data;
 
-  ps1data = gfits_table_get_PS1Data (table, &Nstars, NULL);
+  ps1data = gfits_table_get1Data (table, &Nstars, NULL);
 
   ALLOCATE (stars, Stars, Nstars);
Index: trunk/Ohana/src/addstar/src/SEDfit.c
===================================================================
--- trunk/Ohana/src/addstar/src/SEDfit.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/SEDfit.c	(revision 12332)
@@ -80,5 +80,5 @@
     Nphot = 0;
     for (j = 0; j < incat[0].average[i].Nm; j++) {
-      idx = table[0].hashcode[incat[0].measure[m+j].source];
+      idx = table[0].hashcode[incat[0].measure[m+j].photcode];
       if (idx == -1) continue;
       // only fit the selected photcodes (mode == "fit")
@@ -86,8 +86,8 @@
       if (table[0].mode[idx] == SED_SAMPLE) continue; 
       // XXX do something more clever if more than one value exists per photcode
-      sourceValue.mags[idx] = incat[0].measure[m+j].M_PS + table[0].vegaToAB[idx];
-      sourceError.mags[idx] = incat[0].measure[m+j].dM_PS;
-      if (incat[0].measure[m+j].source == USNOred) sourceError.mags[idx] = 0.3;
-      if (incat[0].measure[m+j].source == USNOblu) sourceError.mags[idx] = 0.3;
+      sourceValue.mags[idx] = incat[0].measure[m+j].M + table[0].vegaToAB[idx];
+      sourceError.mags[idx] = incat[0].measure[m+j].dM;
+      if (incat[0].measure[m+j].photcode == USNOred) sourceError.mags[idx] = 0.3;
+      if (incat[0].measure[m+j].photcode == USNOblu) sourceError.mags[idx] = 0.3;
       found[idx] = TRUE;
       Nphot ++;
@@ -159,11 +159,7 @@
 
     // XXX for now, set the average mag data to NULL
-    outcat[0].average[Nave].M         = NO_MAG;
-    outcat[0].average[Nave].dM        = NO_MAG;
     outcat[0].average[Nave].Nm        = 0;
     outcat[0].average[Nave].Nn        = 0;
     outcat[0].average[Nave].Xp        = NO_MAG;
-    outcat[0].average[Nave].Xm        = NO_MAG;
-    outcat[0].average[Nave].Xg        = NO_MAG;
     outcat[0].average[Nave].offset    = Nmeas;
     outcat[0].average[Nave].missing   = -1;
@@ -171,6 +167,6 @@
 
     for (j = 0; j < Nsec; j++) {
-      outcat[0].secfilt[Nave*Nsec+j].M_PS  = NO_MAG;
-      outcat[0].secfilt[Nave*Nsec+j].dM_PS = NO_MAG;
+      outcat[0].secfilt[Nave*Nsec+j].M  = NO_MAG;
+      outcat[0].secfilt[Nave*Nsec+j].dM = NO_MAG;
       outcat[0].secfilt[Nave*Nsec+j].Xm    = NO_MAG;
     }
@@ -185,18 +181,18 @@
     for (j = 0; valid && (j < Nmodel); j++) {
       n = modelRow[j];
-      outcat[0].measure[Nmeas].dR_PS       = 0.0;
-      outcat[0].measure[Nmeas].dD_PS       = 0.0;
-      outcat[0].measure[Nmeas].M_PS        = MIN (table[0].row[minFit.row][0].mags[n] + minFit.Md,  NO_MAG);
-      outcat[0].measure[Nmeas].dM_PS       = 0.0;
-      outcat[0].measure[Nmeas].Mcal_PS     = 0;
+      outcat[0].measure[Nmeas].dR       = 0.0;
+      outcat[0].measure[Nmeas].dD       = 0.0;
+      outcat[0].measure[Nmeas].M        = MIN (table[0].row[minFit.row][0].mags[n] + minFit.Md,  NO_MAG);
+      outcat[0].measure[Nmeas].dM       = 0.0;
+      outcat[0].measure[Nmeas].Mcal     = 0;
       outcat[0].measure[Nmeas].t           = TIMEREF;
       outcat[0].measure[Nmeas].averef      = Nave;
-      outcat[0].measure[Nmeas].source      = table[0].code[n];
+      outcat[0].measure[Nmeas].photcode      = table[0].code[n];
       outcat[0].measure[Nmeas].dophot      = 0;
       outcat[0].measure[Nmeas].flags       = 0;
-      outcat[0].measure[Nmeas].dt_PS       = 0xffff;
-
-      outcat[0].measure[Nmeas].Mgal_PS     = NO_MAG;
-      outcat[0].measure[Nmeas].airmass_PS  = 0;
+      outcat[0].measure[Nmeas].dt       = 0xffff;
+
+      outcat[0].measure[Nmeas].Mgal     = NO_MAG;
+      outcat[0].measure[Nmeas].airmass  = 0;
       outcat[0].measure[Nmeas].FWx         = NO_MAG;
       outcat[0].measure[Nmeas].FWy         = NO_ERR;
Index: trunk/Ohana/src/addstar/src/SocketOps.c
===================================================================
--- trunk/Ohana/src/addstar/src/SocketOps.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/SocketOps.c	(revision 12332)
@@ -60,5 +60,6 @@
 int WaitServerSocket (int InitSocket, SockAddress *Address, int *validIP, int Nvalid) {
 
-  int i, BindSocket, length;
+  int i, BindSocket;
+  socklen_t length;
   SockAddress Address_in;
   u_int32_t addr;
Index: trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c
===================================================================
--- trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/UpdateDatabase_Image.c	(revision 12332)
@@ -3,6 +3,5 @@
 int UpdateDatabase_Image (AddstarClientOptions *options, Image *images, int Nimages, Coords *mosaic, Stars *stars, int Nstars) {
 
-  int i, Noverlap, status;
-  Image *overlap;
+  int i, status;
   Catalog catalog;
   SkyList *skylist, *newlist;
Index: trunk/Ohana/src/addstar/src/calibrate.c
===================================================================
--- trunk/Ohana/src/addstar/src/calibrate.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/calibrate.c	(revision 12332)
@@ -60,5 +60,5 @@
   //  - calibrate to external system (Mref)
 
-  mycode = GetPhotcodebyCode (new[0].source);
+  mycode = GetPhotcodebyCode (new[0].photcode);
   incode = GetPhotcodebyCode (mycode[0].equiv);
   excode = GetPhotcodebyCode (incode[0].equiv);
@@ -74,19 +74,19 @@
   m = average[0].offset;
   for (i = 0; i < average[0].Nm; i++) {
-    if (measure[m].source == CalC0) { 
+    if (measure[m].photcode == CalC0) { 
       found0 = TRUE; 
-      CalM0  = measure[m].M_PS; 
-      dCalM  = measure[m].dM_PS; 
+      CalM0  = measure[m].M; 
+      dCalM  = measure[m].dM; 
     }
-    if (measure[m].source == CalC1) { 
+    if (measure[m].photcode == CalC1) { 
       found1 = TRUE; 
-      CalM1  = measure[m].M_PS; 
+      CalM1  = measure[m].M; 
     }
-    if (measure[m].source == CalC2) { 
+    if (measure[m].photcode == CalC2) { 
       found2 = TRUE; 
-      CalM2  = measure[m].M_PS; 
+      CalM2  = measure[m].M; 
     }
     if (found0 && found1 && found2) {
-      Mcal   = new[0].M_PS + 0.001*mycode[0].C + mycode[0].K*(new[0].airmass_PS - 1.0) - ZeroPt;
+      Mcal   = new[0].M + 0.001*mycode[0].C + mycode[0].K*(new[0].airmass - 1.0) - ZeroPt;
       color  = CalM1 - CalM2 - 0.001*mycode[0].dX;
       factor = color;
@@ -99,5 +99,5 @@
       }
       // if we want to apply a Mcal -> Mref color correction, we need the additional color term
-      SaveCalibration (Mcal, new[0].dM_PS, CalM0, dCalM, new[0].M_PS - ZeroPt - new[0].dt_PS, Nstar);
+      SaveCalibration (Mcal, new[0].dM, CalM0, dCalM, new[0].M - ZeroPt - new[0].dt, Nstar);
       return;
     }
@@ -121,6 +121,6 @@
   if (MaxN == -1) {
     fprintf (stderr, "no clean stars\n");
-    image[0].Mcal_PS = 10.000;
-    image[0].dMcal_PS = 10.000;
+    image[0].Mcal = 10.000;
+    image[0].dMcal = 10.000;
     return;
   }
@@ -155,6 +155,6 @@
   if (Nkeep < 5) {
     fprintf (stderr, "too few stars\n");
-    image[0].Mcal_PS = 10.000;
-    image[0].dMcal_PS = 10.000;
+    image[0].Mcal = 10.000;
+    image[0].dMcal = 10.000;
     return;
   }
@@ -187,11 +187,11 @@
     Mw = W1 / W2;
     fprintf (stderr, "N: %.0f, mean: %f, wt mean: %f, stdev: %f, precision: %f\n", N, M1, Mw, M2, M2 / sqrt (N));
-    image[0].Mcal_PS = M1;
-    image[0].dMcal_PS = M2 / sqrt (N);
+    image[0].Mcal = M1;
+    image[0].dMcal = M2 / sqrt (N);
     image[0].Mxxxx = N;
   } else {
     fprintf (stderr, "too few stars\n");
-    image[0].Mcal_PS = 10.000;
-    image[0].dMcal_PS = 10.000;
+    image[0].Mcal = 10.000;
+    image[0].dMcal = 10.000;
     image[0].Mxxxx = 0;
   }
Index: trunk/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- trunk/Ohana/src/addstar/src/fakeimage.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/fakeimage.c	(revision 12332)
@@ -111,10 +111,10 @@
     image[i+1].NY = Ny;
 
-    image[i+1].source = photcode;
+    image[i+1].photcode = photcode;
 
     image[i+1].exptime = 0.0;
   
-    image[i+1].apmifit_PS = 0.0;
-    image[i+1].dapmifit_PS = 0.0;
+    image[i+1].apmifit = 0.0;
+    image[i+1].dapmifit = 0.0;
 
     image[i+1].detection_limit = 0.0;
@@ -124,8 +124,8 @@
     image[i+1].tzero = MosaicTime;
     image[i+1].trate = 0;
-    image[i+1].secz_PS = 1.0;
+    image[i+1].secz = 1.0;
     image[i+1].ccdnum = 0xff;
 
-    image[i+1].Mcal_PS = 0.0;
+    image[i+1].Mcal = 0.0;
     image[i+1].Xm   = NO_MAG;
     image[i+1].code = 0;
@@ -173,9 +173,9 @@
   image[0].NY = Dmax - Dmin;
 
-  image[0].source = photcode;
+  image[0].photcode = photcode;
 
   image[0].exptime = 0.0;
-  image[0].apmifit_PS = 0.0;
-  image[0].dapmifit_PS = 0.0;
+  image[0].apmifit = 0.0;
+  image[0].dapmifit = 0.0;
   image[0].detection_limit = 0.0;
   image[0].saturation_limit = 0.0;
@@ -184,7 +184,7 @@
   image[0].tzero = MosaicTime;
   image[0].trate = 0;
-  image[0].secz_PS = 1.0;
+  image[0].secz = 1.0;
   image[0].ccdnum = 0xff;
-  image[0].Mcal_PS = 0.0;
+  image[0].Mcal = 0.0;
   image[0].Xm   = NO_MAG;
   image[0].code = 0;
Index: trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/find_matches.c	(revision 12332)
@@ -4,5 +4,5 @@
 
   int i, j, n, N, J, status, Nstars;
-  double X, Y, RADIUS, RADIUS2;
+  double RADIUS, RADIUS2;
   float *X1, *Y1, *X2, *Y2;
   float dX, dY, dR;
@@ -10,10 +10,11 @@
   int Nave, NAVE, Nmeas, NMEAS, Nmatch;
   int Nsecfilt, Nsec;
-  float Mcat, *Mval;
-  PhotCode *code;
   Coords tcoords;
 
-  /* 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 */
+  /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
+     images this function requires incoming stars to have the same photcode.equiv value.  if
+     this value is not a valid photcode (ie, 0), then no modification is made to the average 
+     magnitudes (Nsec will be -1) */
+
   Nsecfilt = GetPhotcodeNsecfilt ();
   Nsec     = GetPhotcodeNsec (options.photcode);
@@ -142,16 +143,16 @@
       /** add measurements for this star **/
       /** dR,dD now represent arcsec **/
-      catalog[0].measure[Nmeas].dR_PS       = 3600.0*(catalog[0].average[n].R - stars[N].R);
-      if (catalog[0].measure[Nmeas].dR_PS > +180.0*3600.0) {
+      catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
 	  // average on high end of boundary, move star up
 	  stars[N].R += 360.0;
-	  catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
-      }
-      if (catalog[0].measure[Nmeas].dR_PS < -180.0*3600.0) {
+	  catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      }
+      if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
 	  // average on low end of boundary, move star down
 	  stars[N].R -= 360.0;
-	  catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
-      }
-      if (fabs(catalog[0].measure[Nmeas].dR_PS) > 10*RADIUS) {
+	  catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
+      }
+      if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
 	  fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
 		   catalog[0].average[n].R, catalog[0].average[n].D, 
@@ -160,27 +161,34 @@
 		   Y1[i], Y2[J]);
       }
-      catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N].D);
-      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;              /* this must be an absolute sequence number, if partial average is loaded */
-      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       = 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);
-      catalog[0].measure[Nmeas].theta       = MIN ((255/360)*stars[N].df, NO_ERR);
+      catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].D);
+
+      /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+      /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+      catalog[0].measure[Nmeas].Xccd     = stars[N].X;
+      catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
+
+      catalog[0].measure[Nmeas].M        = stars[N].M;
+      catalog[0].measure[Nmeas].dM       = stars[N].dM;  /* error in input files stored in thousandths of mag */
+      catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
+      catalog[0].measure[Nmeas].t        = stars[N].t;
+      catalog[0].measure[Nmeas].averef   = n;              /* this must be an absolute sequence number, if partial average is loaded */
+      catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
+      catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
+      catalog[0].measure[Nmeas].flags    = 0;
+      catalog[0].measure[Nmeas].dt       = stars[N].dt;
+      catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+      catalog[0].measure[Nmeas].Mgal     = 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);
+      catalog[0].measure[Nmeas].theta    = MIN ((0xffff/360.0)*stars[N].df, NO_MAG);
 	
-      /* it is not valid to pass PRI/SEC/REF photcodes to this routine */
-      /* check for entries in the secfilt lists */
-      Mcat = PhotCat (&catalog[0].measure[Nmeas]);
-      Mval = (Nsec == -1) ? &catalog[0].average[n].M : &catalog[0].secfilt[n*Nsecfilt+Nsec].M_PS;
-      if (*Mval == NO_MAG) *Mval = Mcat;
+      /* set the average magnitude if not already set and if photcode.equiv is not 0 */
       /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+      if (Nsec > -1) { 
+	  if (catalog[0].secfilt[n*Nsecfilt+Nsec].M != NO_MAG) {
+	      catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+	  }
+      }
 
       /* adds the measurement to the calibration if appropriate color terms are found */
@@ -242,11 +250,7 @@
     catalog[0].average[Nave].R         = stars[N].R;
     catalog[0].average[Nave].D         = stars[N].D;
-    catalog[0].average[Nave].M         = NO_MAG;
-    catalog[0].average[Nave].dM        = NO_MAG;
+    catalog[0].average[Nave].Xp        = 0;
     catalog[0].average[Nave].Nm        = 1;
     catalog[0].average[Nave].Nn        = 0;
-    catalog[0].average[Nave].Xp        = NO_MAG;
-    catalog[0].average[Nave].Xm        = NO_MAG;
-    catalog[0].average[Nave].Xg        = NO_MAG;
     catalog[0].average[Nave].offset    = Nmeas;
     catalog[0].average[Nave].missing   = -1;
@@ -263,30 +267,38 @@
 
     for (j = 0; j < Nsecfilt; j++) {
-      catalog[0].secfilt[Nave*Nsecfilt+j].M_PS  = NO_MAG;
-      catalog[0].secfilt[Nave*Nsecfilt+j].dM_PS = NO_MAG;
-      catalog[0].secfilt[Nave*Nsecfilt+j].Xm    = NO_MAG;
-    }
-
-    catalog[0].measure[Nmeas].dR_PS       = 0.0;
-    catalog[0].measure[Nmeas].dD_PS       = 0.0;
-    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;           /* XXX EAM : must be absolute Nave if partial read */
-    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    	  = 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);
-    catalog[0].measure[Nmeas].theta    	  = MIN ((255/360)*stars[N].df, NO_ERR);
-
-    Mcat = PhotCat (&catalog[0].measure[Nmeas]);
-    Mval = (Nsec == -1) ? &catalog[0].average[Nave].M : &catalog[0].secfilt[Nave*Nsecfilt+Nsec].M_PS;
-    if (*Mval == NO_MAG) *Mval = Mcat;
+      catalog[0].secfilt[Nave*Nsecfilt+j].M  = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].dM = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].Xm = NO_MAG;
+    }
+
+    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+    catalog[0].measure[Nmeas].Xccd     = stars[N].X;
+    catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
+
+    catalog[0].measure[Nmeas].dR       	= 0.0;
+    catalog[0].measure[Nmeas].dD       	= 0.0;
+    catalog[0].measure[Nmeas].M        	= stars[N].M;
+    catalog[0].measure[Nmeas].dM       	= stars[N].dM;
+    catalog[0].measure[Nmeas].Mcal  	= stars[N].Mcal;
+    catalog[0].measure[Nmeas].t        	= stars[N].t;
+    catalog[0].measure[Nmeas].averef   	= Nave;           /* XXX EAM : must be absolute Nave if partial read */
+    catalog[0].measure[Nmeas].photcode  = stars[N].code;  /* photcode */
+    catalog[0].measure[Nmeas].dophot   	= stars[N].dophot;  
+    catalog[0].measure[Nmeas].flags    	= 0;
+    catalog[0].measure[Nmeas].dt    	= stars[N].dt;
+    catalog[0].measure[Nmeas].airmass   = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].Mgal  	= 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);
+    catalog[0].measure[Nmeas].theta    	= MIN ((0xffff/360.0)*stars[N].df, NO_MAG);
+    /* XXX replace df here with theta, right? */
+
+    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
+    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+    if (Nsec > -1) { 
+	catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+    }
 
     /* next[Nmeas] should always be -1 in this context (it is always the only
Index: trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 12332)
@@ -4,5 +4,5 @@
 
   int i, j, n, N, J, Jmin, status, Nstars;
-  double X, Y, RADIUS, RADIUS2, Rmin, secz;
+  double RADIUS, RADIUS2, Rmin;
   float *X1, *Y1, *X2, *Y2;
   float dX, dY, dR;
@@ -11,9 +11,10 @@
   Coords tcoords;
   int Nsecfilt, Nsec;
-  float Mcat, *Mval, MTIME;
-  PhotCode *code;
-
-  /* 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 */
+
+  /* photcode data - must by of type DEP; options.photcode is equiv photcode for all input
+     images this function requires incoming stars to have the same photcode.equiv value.  if
+     this value is not a valid photcode (ie, 0), then no modification is made to the average 
+     magnitudes (Nsec will be -1) */
+
   Nsecfilt = GetPhotcodeNsecfilt ();
   Nsec     = GetPhotcodeNsec (options.photcode);
@@ -160,16 +161,16 @@
     /** add measurements for this star **/
     /** dR,dD now represent arcsec **/
-    catalog[0].measure[Nmeas].dR_PS       = 3600.0*(catalog[0].average[n].R - stars[N].R);
-    if (catalog[0].measure[Nmeas].dR_PS > +180.0*3600.0) {
+    catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
       // average on high end of boundary, move star up
       stars[N].R += 360.0;
-      catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
-    }
-    if (catalog[0].measure[Nmeas].dR_PS < -180.0*3600.0) {
+      catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    }
+    if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
       // average on low end of boundary, move star down
       stars[N].R -= 360.0;
-      catalog[0].measure[Nmeas].dR_PS = 3600.0*(catalog[0].average[n].R - stars[N].R);
-    }
-    if (fabs(catalog[0].measure[Nmeas].dR_PS) > 10*RADIUS) {
+      catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
+    }
+    if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
       fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n", 
 	       catalog[0].average[n].R, catalog[0].average[n].D, 
@@ -178,27 +179,34 @@
 	       Y1[i], Y2[Jmin]);
     }
-    catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N].D);
-    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       = 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);
-    catalog[0].measure[Nmeas].theta       = MIN ((255/360)*stars[N].df, NO_ERR);
+    catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].D);
+
+    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+    catalog[0].measure[Nmeas].Xccd     = stars[N].X;
+    catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
+
+    catalog[0].measure[Nmeas].M        = stars[N].M;
+    catalog[0].measure[Nmeas].dM       = stars[N].dM;  /* error in input files stored in thousandths of mag */
+    catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
+    catalog[0].measure[Nmeas].t        = stars[N].t;
+    catalog[0].measure[Nmeas].averef   = n;
+    catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
+    catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
+    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dt       = stars[N].dt;
+    catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].Mgal     = 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);
+    catalog[0].measure[Nmeas].theta    = MIN ((0xffff/360.0)*stars[N].df, NO_MAG);
 	
-    /* it is not valid to pass PRI/SEC/REF photcodes to this routine */
-    /* check for entries in the secfilt lists */
-    Mcat = PhotCat (&catalog[0].measure[Nmeas]);
-    Mval = (Nsec == -1) ? &catalog[0].average[n].M : &catalog[0].secfilt[n*Nsecfilt+Nsec].M_PS;
-    if (*Mval == NO_MAG) *Mval = Mcat;
+    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
     /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+    if (Nsec > -1) { 
+	if (catalog[0].secfilt[n*Nsecfilt+Nsec].M != NO_MAG) {
+	    catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+	}
+    }
 
     /* adds the measurement to the calibration if appropriate color terms are found */
@@ -240,11 +248,7 @@
     catalog[0].average[Nave].R         = stars[N].R;
     catalog[0].average[Nave].D         = stars[N].D;
-    catalog[0].average[Nave].M         = NO_MAG;
-    catalog[0].average[Nave].dM        = NO_MAG;
+    catalog[0].average[Nave].Xp        = 0;
     catalog[0].average[Nave].Nm        = 1;
     catalog[0].average[Nave].Nn        = 0;
-    catalog[0].average[Nave].Xp        = NO_MAG;
-    catalog[0].average[Nave].Xm        = NO_MAG;
-    catalog[0].average[Nave].Xg        = NO_MAG;
     catalog[0].average[Nave].offset    = Nmeas;
     catalog[0].average[Nave].missing   = -1;
@@ -261,30 +265,37 @@
 
     for (j = 0; j < Nsecfilt; j++) {
-      catalog[0].secfilt[Nave*Nsecfilt+j].M_PS  = NO_MAG;
-      catalog[0].secfilt[Nave*Nsecfilt+j].dM_PS = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].M  = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].dM = NO_MAG;
       catalog[0].secfilt[Nave*Nsecfilt+j].Xm    = NO_MAG;
     }
 
-    catalog[0].measure[Nmeas].dR_PS       = 0.0;
-    catalog[0].measure[Nmeas].dD_PS       = 0.0;
-    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    	  = 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);
-    catalog[0].measure[Nmeas].theta    	  = MIN ((255/360)*stars[N].df, NO_ERR);
-
-    Mcat = PhotCat (&catalog[0].measure[Nmeas]);
-    Mval = (Nsec == -1) ? &catalog[0].average[Nave].M : &catalog[0].secfilt[Nave*Nsecfilt+Nsec].M_PS;
-    if (*Mval == NO_MAG) *Mval = Mcat;
+    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+    catalog[0].measure[Nmeas].Xccd     = stars[N].X;
+    catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
+
+    catalog[0].measure[Nmeas].dR       = 0.0;
+    catalog[0].measure[Nmeas].dD       = 0.0;
+    catalog[0].measure[Nmeas].M        = stars[N].M;
+    catalog[0].measure[Nmeas].dM       = stars[N].dM;
+    catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
+    catalog[0].measure[Nmeas].t        = stars[N].t;
+    catalog[0].measure[Nmeas].averef   = Nave;
+    catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
+    catalog[0].measure[Nmeas].dophot   = stars[N].dophot;  
+    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dt       = stars[N].dt;
+    catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
+
+    catalog[0].measure[Nmeas].Mgal     = 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);
+    catalog[0].measure[Nmeas].theta    = MIN ((0xffff/360.0)*stars[N].df, NO_ERR);
+
+    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
+    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
+    if (Nsec > -1) { 
+	catalog[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
+    }
 
     /* next[Nmeas] should always be -1 in this context (it is always the only
Index: trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 12332)
@@ -131,29 +131,34 @@
       /** add measurements for this star **/
       /** *** dR,dD now in arcsec *** **/
-      catalog[0].measure[Nmeas].dR_PS       = 3600.0*(catalog[0].average[n].R - stars[N][0].R);
-      catalog[0].measure[Nmeas].dD_PS       = 3600.0*(catalog[0].average[n].D - stars[N][0].D);
-      catalog[0].measure[Nmeas].M_PS        = MIN (stars[N][0].M,  NO_MAG);
-      catalog[0].measure[Nmeas].dM_PS       = MIN (stars[N][0].dM, NO_ERR);
-      catalog[0].measure[Nmeas].Mcal_PS     = 0;
-      catalog[0].measure[Nmeas].t           = (TIMEREF == 0) ? stars[N][0].t : TIMEREF; /** careful : time_t vs e_time **/
-      catalog[0].measure[Nmeas].averef      = n;
-      catalog[0].measure[Nmeas].source      = stars[N][0].code;
-      catalog[0].measure[Nmeas].dophot      = 0;
-      catalog[0].measure[Nmeas].flags       = 0;
-      catalog[0].measure[Nmeas].dt_PS       = 0xffff;
-
-      catalog[0].measure[Nmeas].Mgal_PS     = NO_MAG;
-      catalog[0].measure[Nmeas].airmass_PS  = 0;
-      catalog[0].measure[Nmeas].FWx         = NO_MAG;
-      catalog[0].measure[Nmeas].FWy         = NO_MAG;
-      catalog[0].measure[Nmeas].theta       = NO_ERR;
+      catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].R);
+      catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].D);
+      catalog[0].measure[Nmeas].M        = MIN (stars[N][0].M,  NO_MAG);
+      catalog[0].measure[Nmeas].dM       = MIN (stars[N][0].dM, NO_ERR);
+      catalog[0].measure[Nmeas].Mcal     = 0;
+      catalog[0].measure[Nmeas].t        = (TIMEREF == 0) ? stars[N][0].t : TIMEREF; /** careful : time_t vs e_time **/
+      catalog[0].measure[Nmeas].averef   = n;
+      catalog[0].measure[Nmeas].photcode = stars[N][0].code;
+      catalog[0].measure[Nmeas].dophot   = 0;
+      catalog[0].measure[Nmeas].flags    = 0;
+      catalog[0].measure[Nmeas].dt       = 0xffff;
+
+      catalog[0].measure[Nmeas].Mgal     = NO_MAG;
+      catalog[0].measure[Nmeas].airmass  = 0;
+      catalog[0].measure[Nmeas].FWx      = NO_MAG;
+      catalog[0].measure[Nmeas].FWy      = NO_MAG;
+      catalog[0].measure[Nmeas].theta    = NO_MAG;
 	
+      /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+      /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+      catalog[0].measure[Nmeas].Xccd     = 0.0;
+      catalog[0].measure[Nmeas].Yccd     = 0.0;
+
       if (ACCEPT_MOTION) {
-	catalog[0].average[n].uR          = stars[N][0].uR;
-	catalog[0].average[n].uD          = stars[N][0].uD;
-	catalog[0].average[n].duR         = stars[N][0].duR;
-	catalog[0].average[n].duD         = stars[N][0].duD;
-	catalog[0].average[n].P           = stars[N][0].P;
-	catalog[0].average[n].dP          = stars[N][0].dP;
+	catalog[0].average[n].uR         = stars[N][0].uR;
+	catalog[0].average[n].uD         = stars[N][0].uD;
+	catalog[0].average[n].duR        = stars[N][0].duR;
+	catalog[0].average[n].duD        = stars[N][0].duD;
+	catalog[0].average[n].P          = stars[N][0].P;
+	catalog[0].average[n].dP         = stars[N][0].dP;
       }
 
@@ -207,4 +212,10 @@
     catalog[0].average[Nave].R         = stars[N][0].R;
     catalog[0].average[Nave].D         = stars[N][0].D;
+    catalog[0].average[Nave].Xp        = 0;
+    catalog[0].average[Nave].Nm        = 1;
+    catalog[0].average[Nave].Nn        = 0;
+    catalog[0].average[Nave].offset    = Nmeas;
+    catalog[0].average[Nave].missing   = -1;
+    catalog[0].average[Nave].code      = 0;
 
     if (ACCEPT_MOTION) {
@@ -228,38 +239,32 @@
     }
 
-    catalog[0].average[Nave].M         = NO_MAG;
-    catalog[0].average[Nave].dM        = NO_MAG;
-    catalog[0].average[Nave].Nm        = 1;
-    catalog[0].average[Nave].Nn        = 0;
-    catalog[0].average[Nave].Xp        = NO_MAG;
-    catalog[0].average[Nave].Xm        = NO_MAG;
-    catalog[0].average[Nave].Xg        = NO_MAG;
-    catalog[0].average[Nave].offset    = Nmeas;
-    catalog[0].average[Nave].missing   = -1;
-    catalog[0].average[Nave].code      = 0;
-
     for (j = 0; j < Nsecfilt; j++) {
-      catalog[0].secfilt[Nave*Nsecfilt+j].M_PS  = NO_MAG;
-      catalog[0].secfilt[Nave*Nsecfilt+j].dM_PS = NO_MAG;
-      catalog[0].secfilt[Nave*Nsecfilt+j].Xm    = NO_MAG;
-    }
-
-    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][0].M,  NO_MAG);
-    catalog[0].measure[Nmeas].dM_PS       = MIN (stars[N][0].dM, NO_ERR);
-    catalog[0].measure[Nmeas].Mcal_PS     = 0;
-    catalog[0].measure[Nmeas].t        	  = (stars[N][0].t == 0) ? TIMEREF : stars[N][0].t; /** careful : time_t vs e_time **/
-    catalog[0].measure[Nmeas].averef   	  = Nave;
-    catalog[0].measure[Nmeas].source   	  = stars[N][0].code;
-    catalog[0].measure[Nmeas].dophot   	  = 0;
-    catalog[0].measure[Nmeas].flags    	  = 0;
-    catalog[0].measure[Nmeas].dt_PS       = 0xffff;
-
-    catalog[0].measure[Nmeas].Mgal_PS     = NO_MAG;
-    catalog[0].measure[Nmeas].airmass_PS  = 0;
-    catalog[0].measure[Nmeas].FWx      	  = NO_MAG;
-    catalog[0].measure[Nmeas].FWy      	  = NO_ERR;
-    catalog[0].measure[Nmeas].theta    	  = NO_ERR;
+      catalog[0].secfilt[Nave*Nsecfilt+j].M  = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].dM = NO_MAG;
+      catalog[0].secfilt[Nave*Nsecfilt+j].Xm = NO_MAG;
+    }
+
+    catalog[0].measure[Nmeas].dR       = 0.0;
+    catalog[0].measure[Nmeas].dD       = 0.0;
+    catalog[0].measure[Nmeas].M        = MIN (stars[N][0].M,  NO_MAG);
+    catalog[0].measure[Nmeas].dM       = MIN (stars[N][0].dM, NO_ERR);
+    catalog[0].measure[Nmeas].Mcal     = 0;
+    catalog[0].measure[Nmeas].t        = (stars[N][0].t == 0) ? TIMEREF : stars[N][0].t; /** careful : time_t vs e_time **/
+    catalog[0].measure[Nmeas].averef   = Nave;
+    catalog[0].measure[Nmeas].photcode = stars[N][0].code;
+    catalog[0].measure[Nmeas].dophot   = 0;
+    catalog[0].measure[Nmeas].flags    = 0;
+    catalog[0].measure[Nmeas].dt       = 0xffff;
+
+    catalog[0].measure[Nmeas].airmass  = 0;
+    catalog[0].measure[Nmeas].Mgal     = NO_MAG;
+    catalog[0].measure[Nmeas].FWx      = NO_MAG;
+    catalog[0].measure[Nmeas].FWy      = NO_MAG;
+    catalog[0].measure[Nmeas].theta    = NO_MAG;
+
+    /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
+    /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
+    catalog[0].measure[Nmeas].Xccd     = 0.0;
+    catalog[0].measure[Nmeas].Yccd     = 0.0;
 
     stars[N][0].found = Nmeas;
Index: trunk/Ohana/src/addstar/src/find_proper.c
===================================================================
--- trunk/Ohana/src/addstar/src/find_proper.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/find_proper.c	(revision 12332)
@@ -111,5 +111,5 @@
 	catalog[0].measure[Nmeas].t   = 0;    /* a flag: if 0, image is not in database */
 	catalog[0].measure[Nmeas].averef  = n;
-	catalog[0].measure[Nmeas].source = USNO_RED; 
+	catalog[0].measure[Nmeas].photcode = USNO_RED; 
 	catalog[0].measure[Nmeas+1].dR  = catalog[0].measure[Nmeas].dR;
 	catalog[0].measure[Nmeas+1].dD  = catalog[0].measure[Nmeas].dD;
@@ -119,5 +119,5 @@
 	catalog[0].measure[Nmeas+1].t   = 0;    /* a flag: if 0, image is not in database */
 	catalog[0].measure[Nmeas+1].averef  = n;
-	catalog[0].measure[Nmeas+1].source = USNO_BLUE; 
+	catalog[0].measure[Nmeas+1].photcode = USNO_BLUE; 
 	/* add flag in average to mark as matched with the USNO catalog */
 	catalog[0].average[n].code |= (ID_PROPER | ID_USNO);
Index: trunk/Ohana/src/addstar/src/gstars.c
===================================================================
--- trunk/Ohana/src/addstar/src/gstars.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/gstars.c	(revision 12332)
@@ -7,5 +7,5 @@
   int i, j, Nfile, Nheader, NHEADER, Nimage, NIMAGE;
   int Nskip, Nhead, Ndata, done, status, mode, NinStars;
-  char **file;
+  char **file, *name;
   FILE *f;
   glob_t globList;
@@ -63,4 +63,9 @@
 
       ReadImageHeader (header, &image[i], photcode);
+      
+      /* find image rootname */
+      name = filebasename (file[i]);
+      snprintf (image[i].name, 32, name);
+      free (name);
     
       switch (mode) {
@@ -176,5 +181,25 @@
       }
   }
+  // 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], "EXTNAME", "%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
@@ -185,5 +210,13 @@
       ReadImageHeader (headers[Nhead], &image[i], 0);
 
-      if (!strcmp(exthead[i], "PHU")) continue;
+      // XXX use something to set the chip name? EXTNAME?
+      if (!strcmp(exthead[i], "PHU") && (Nimage == 1)) {
+	snprintf (image[i].name, 32, "%s", name);
+      } else {
+	snprintf (image[i].name, 32, "%s.%s", name, exthead[i]);
+      }
+
+      // this is an error we should not encounter
+      if (!strcmp(extdata[i], "PHU")) Shutdown ("error in data segment: PHU cannot be table");
 
       // advance the pointer to the start of the corresponding table block
@@ -199,4 +232,5 @@
       stars = MergeStars (stars, Nstars, inStars, image[i].nstar);
   }
+  free (name);
   *Nimages = Nimage;
   *images = image;
Index: trunk/Ohana/src/addstar/src/load2mass_catalog.c
===================================================================
--- trunk/Ohana/src/addstar/src/load2mass_catalog.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/load2mass_catalog.c	(revision 12332)
@@ -32,11 +32,7 @@
 
     // XXX for now, set the average mag data to NULL
-    catalog[0].average[Nave].M         = NO_MAG;
-    catalog[0].average[Nave].dM        = NO_MAG;
     catalog[0].average[Nave].Nm        = 0;
     catalog[0].average[Nave].Nn        = 0;
     catalog[0].average[Nave].Xp        = NO_MAG;
-    catalog[0].average[Nave].Xm        = NO_MAG;
-    catalog[0].average[Nave].Xg        = NO_MAG;
     catalog[0].average[Nave].offset    = Nmeas;
     catalog[0].average[Nave].missing   = -1;
@@ -44,6 +40,6 @@
 
     for (j = 0; j < Nsec; j++) {
-      catalog[0].secfilt[Nave*Nsec+j].M_PS  = NO_MAG;
-      catalog[0].secfilt[Nave*Nsec+j].dM_PS = NO_MAG;
+      catalog[0].secfilt[Nave*Nsec+j].M  = NO_MAG;
+      catalog[0].secfilt[Nave*Nsec+j].dM = NO_MAG;
       catalog[0].secfilt[Nave*Nsec+j].Xm    = NO_MAG;
     }
@@ -51,18 +47,18 @@
     // we now have the min chisq row. use this to supply the other filter values....
     for (j = 0; j < 3; j++) {
-      catalog[0].measure[Nmeas].dR_PS       = 0.0;
-      catalog[0].measure[Nmeas].dD_PS       = 0.0;
-      catalog[0].measure[Nmeas].M_PS        = MIN (stars[i+j].M,  NO_MAG);
-      catalog[0].measure[Nmeas].dM_PS       = MIN (stars[i+j].dM,  NO_ERR);
-      catalog[0].measure[Nmeas].Mcal_PS     = 0;
+      catalog[0].measure[Nmeas].dR       = 0.0;
+      catalog[0].measure[Nmeas].dD       = 0.0;
+      catalog[0].measure[Nmeas].M        = MIN (stars[i+j].M,  NO_MAG);
+      catalog[0].measure[Nmeas].dM       = MIN (stars[i+j].dM,  NO_ERR);
+      catalog[0].measure[Nmeas].Mcal     = 0;
       catalog[0].measure[Nmeas].t           = stars[i+j].t;
       catalog[0].measure[Nmeas].averef      = Nave;
-      catalog[0].measure[Nmeas].source      = stars[i+j].code;
+      catalog[0].measure[Nmeas].photcode      = stars[i+j].code;
       catalog[0].measure[Nmeas].dophot      = 0;
       catalog[0].measure[Nmeas].flags       = 0;
-      catalog[0].measure[Nmeas].dt_PS       = 0xffff;
+      catalog[0].measure[Nmeas].dt       = 0xffff;
 
-      catalog[0].measure[Nmeas].Mgal_PS     = NO_MAG;
-      catalog[0].measure[Nmeas].airmass_PS  = 0;
+      catalog[0].measure[Nmeas].Mgal     = NO_MAG;
+      catalog[0].measure[Nmeas].airmass  = 0;
       catalog[0].measure[Nmeas].FWx         = NO_MAG;
       catalog[0].measure[Nmeas].FWy         = NO_ERR;
Index: trunk/Ohana/src/addstar/src/replace_match.c
===================================================================
--- trunk/Ohana/src/addstar/src/replace_match.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/replace_match.c	(revision 12332)
@@ -7,9 +7,9 @@
   /* search for entry and replace values M, dM, R, D */
   for (i = 0; i < average[0].Nm; i++) {
-    if (measure[i].source != star[0].code) continue;
-    measure[i].dR_PS       = 3600.0*(average[0].R - star[0].R);
-    measure[i].dD_PS       = 3600.0*(average[0].D - star[0].D);
-    measure[i].M_PS        = MIN (star[0].M,  NO_MAG);
-    measure[i].dM_PS       = MIN (star[0].dM, NO_ERR);
+    if (measure[i].photcode != star[0].code) continue;
+    measure[i].dR       = 3600.0*(average[0].R - star[0].R);
+    measure[i].dD       = 3600.0*(average[0].D - star[0].D);
+    measure[i].M        = MIN (star[0].M,  NO_MAG);
+    measure[i].dM       = MIN (star[0].dM, NO_ERR);
     star[0].found          = average[0].offset + i;
     return (TRUE);
Index: trunk/Ohana/src/addstar/src/update_coords.c
===================================================================
--- trunk/Ohana/src/addstar/src/update_coords.c	(revision 11880)
+++ trunk/Ohana/src/addstar/src/update_coords.c	(revision 12332)
@@ -19,6 +19,6 @@
       continue;
     }
-    R = measure[m].dR_PS;
-    D = measure[m].dD_PS;
+    R = measure[m].dR;
+    D = measure[m].dD;
     r += R;
     d += D;
@@ -37,6 +37,6 @@
   m = average[0].offset;  /* first measurement of this star */
   for (i = 0; i < average[0].Nm; i++) {
-    measure[m].dR_PS -= r;
-    measure[m].dD_PS -= d;
+    measure[m].dR -= r;
+    measure[m].dD -= d;
     m = next[m];
   }
