Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33227)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33228)
@@ -33,6 +33,6 @@
 $(SRC)/find_image_sgroups.$(ARCH).o \
 $(SRC)/fit_groups.$(ARCH).o	    \
-$(SRC)/update.$(ARCH).o		    \
-$(SRC)/update_catalog.$(ARCH).o	    \
+$(SRC)/update_dvo_uniphot.$(ARCH).o \
+$(SRC)/update_catalog_uniphot.$(ARCH).o \
 $(SRC)/convert.$(ARCH).o	    \
 $(SRC)/SetSignals.$(ARCH).o	    \
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h	(revision 33227)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h	(revision 33228)
@@ -114,5 +114,4 @@
 void          sortB               PROTO((double *X, double *Y, int N));
 void          sortD               PROTO((double *X, double *Y, double *Z, int N));
-void          update_dvo_catalog  PROTO((Catalog *catalog, Group *sgroup, int warn));
 void          wcatalog            PROTO((Catalog *catalog));
 void          wimages             PROTO((Image *image, int Nimage));
@@ -127,5 +126,6 @@
 int 	      SetSignals 	  PROTO((void));
 int 	      subset_images 	  PROTO((FITS_DB *db));
-void 	      update 		  PROTO((FITS_DB *db, Group *sgroup, int Nsgroup));
+void 	      update_dvo_uniphot  PROTO((FITS_DB *db, Group *sgroup, int Nsgroup));
+void          update_catalog_uniphot PROTO((Catalog *catalog, Group *sgroup, int warn));
 void 	      sort_time 	  PROTO((unsigned int *value, int N));
 
Index: anches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update.c	(revision 33227)
+++ 	(revision )
@@ -1,142 +1,0 @@
-# include "uniphot.h"
-# include <glob.h>
-
-// update images & catalogs for uniphot
-void update_dvo_uniphot (FITS_DB *db, Group *sgroup, int Nsgroup) {
-
-  off_t i, Nimage, Nkeep, *keep;
-  int j, status, Nmin;
-  char line[256];
-  glob_t pglob;
-  double Rmin, Rmax, Dmin, Dmax, x, y, radius;
-  Image *image;
-  Catalog catalog;
-  Coords coords;
-
-  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
-  if (!image) {
-      fprintf (stderr, "ERROR: failed to read images\n");
-      exit (2);
-  }
-
-  // create a subset list so we can make a vtable
-  Nkeep = 0;
-  ALLOCATE (keep, off_t, Nimage);
-
-  // identify the images used and clear the NOCAL flags on the rest
-  for (i = 0; i < Nimage; i++) {
-      if (image[i].flags & ID_IMAGE_PHOTOM_NOCAL) {
-	  image[i].flags &= ~ID_IMAGE_PHOTOM_NOCAL;
-	  continue;
-      }
-      keep[Nkeep] = i;
-      Nkeep ++;
-  }
-
-  /* apply calculated space-group offset to image Mcal values */
-  for (i = 0; i < Nsgroup; i++) {
-    for (j = 0; j < sgroup[i].Nimage; j++) {
-      sgroup[i].image[j][0].Mcal -= sgroup[i].M;
-    }
-  }
-
-  // save the rows in the image table which were used in this analysis
-  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, keep, Nkeep);
-
-  // write image table
-  dvo_image_update (db, VERBOSE);
-
-  // XXX need to fix the update for the catalog (or make it optional)
-  return;
-
-  // XXX this process uses the existence of the file to perform the update
-  // XXX convert this to an examination of the SkyTable
-  /** update catalog tables **/
-  pglob.gl_offs = 0;
-  sprintf (line, "%s/*/*.cpt", CATDIR);
-  status = glob (line, 0, NULL, &pglob);
-
-  coords.crpix1 = coords.crpix2 = 0.0;
-  coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
-  coords.pc1_1 = coords.pc2_2 = 1.0;
-  coords.pc1_2 = coords.pc2_1 = 0.0;
-  strcpy (coords.ctype, "RA---TAN");
-  
-  for (i = 0; i < pglob.gl_pathc; i++) {
-    catalog.filename = pglob.gl_pathv[i];
-    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
-
-    // an error exit status here is a significant error
-    if (!dvo_catalog_open (&catalog, NULL, VERBOSE, "a")) {
-      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
-      exit (2);
-    }
-    if (!catalog.Naves_disk) {
-      dvo_catalog_unlock (&catalog);
-      dvo_catalog_free (&catalog);
-      continue;
-    }
-
-    gfits_scan (&catalog.header, "RA0", "%lf",  1, &Rmin);
-    gfits_scan (&catalog.header, "RA1", "%lf",  1, &Rmax);
-    gfits_scan (&catalog.header, "DEC0", "%lf", 1, &Dmin);
-    gfits_scan (&catalog.header, "DEC1", "%lf", 1, &Dmax);
-
-    Rmin = ohana_normalize_angle (Rmin);
-    Rmax = ohana_normalize_angle (Rmax);
-
-    coords.crval1 = 0.5*(Rmin + Rmax);
-    coords.crval2 = 0.5*(Dmin + Dmax);
-
-    Nmin = 0;
-    Rmin = 1000;
-    /* primitive version: match catalog with closest sgroup */
-    for (j = 0; j < Nsgroup; j++) {
-      if (!RD_to_XY (&x, &y, sgroup[j].v1, sgroup[j].v2, &coords)) continue;
-      radius = hypot (x, y);
-      if ((j == 0) || (radius < Rmin)) {
-	Rmin = radius;
-	Nmin = j;
-      }
-    }
-
-    fprintf (stderr, "catalog: %s sgroup: %d %s %f\n", catalog.filename, Nmin, sgroup[Nmin].label, Rmin);
-    update_catalog_uniphot (&catalog, &sgroup[Nmin], (Rmin > 2*RADIUS)); 
-    dvo_catalog_save (&catalog, VERBOSE);
-    dvo_catalog_unlock (&catalog);
-    dvo_catalog_free (&catalog);
-  }
-}      
-
-/* loop over all average 
-
-   if (source equiv photcode)
-
-   loop over sgroups
-
-   if (radius < RADIUS) 
-      
-   average.M (+/-) source.M
-*/
-
-/* loop over all measure 
-
-   if (source equiv photcode)
-
-   loop over sgroups
-
-   if (radius < RADIUS) 
-      
-   measure.Mcal (+/-) source.M
-*/
-
-/* alternative (slower, more robust)
-
-   loop over all average
-   loop over all average.Nm
-   select measure with source equiv photcode
-   match measure to image, get Mcal & offset
-   if any offset for average[i] is different, give error
-   apply offset to average.M
-*/
Index: anches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog.c	(revision 33227)
+++ 	(revision )
@@ -1,35 +1,0 @@
-# include "uniphot.h"
-
-// update a single catalog for uniphot
-void update_catalog_uniphot (Catalog *catalog, Group *sgroup, int warn) {
-
-  int i, j, m, found;
-  int Nsec, Nsecfilt;
-  PhotCode *code;
-
-  Nsec = GetPhotcodeNsec (photcode[0].code);
-  Nsecfilt = GetPhotcodeNsecfilt ();
-
-  found = 0;    
-  for (i = 0; i < catalog[0].Naverage; i++) {
-    
-    if (!isnan(catalog[0].secfilt[i*Nsecfilt+Nsec].M)) {
-      catalog[0].secfilt[i*Nsecfilt+Nsec].M += sgroup[0].M;
-    }
-
-    m = catalog[0].average[i].measureOffset;
-    for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
-      code = GetPhotcodebyCode (catalog[0].measure[m].photcode);
-      if (code == NULL) continue;
-      if (code[0].type != PHOT_DEP) continue;
-      if (code[0].equiv != photcode[0].code) continue;
-      catalog[0].measure[m].Mcal -= sgroup[0].M;
-      found ++;
-    }
-  }
-
-  if (found) {
-    fprintf (stderr, "found %d matches\n", found);
-    if (warn) fprintf (stderr, "warning: updated values, perhaps out of range?\n");
-  }
-}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_uniphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_uniphot.c	(revision 33228)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_uniphot.c	(revision 33228)
@@ -0,0 +1,35 @@
+# include "uniphot.h"
+
+// update a single catalog for uniphot
+void update_catalog_uniphot (Catalog *catalog, Group *sgroup, int warn) {
+
+  int i, j, m, found;
+  int Nsec, Nsecfilt;
+  PhotCode *code;
+
+  Nsec = GetPhotcodeNsec (photcode[0].code);
+  Nsecfilt = GetPhotcodeNsecfilt ();
+
+  found = 0;    
+  for (i = 0; i < catalog[0].Naverage; i++) {
+    
+    if (!isnan(catalog[0].secfilt[i*Nsecfilt+Nsec].M)) {
+      catalog[0].secfilt[i*Nsecfilt+Nsec].M += sgroup[0].M;
+    }
+
+    m = catalog[0].average[i].measureOffset;
+    for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
+      code = GetPhotcodebyCode (catalog[0].measure[m].photcode);
+      if (code == NULL) continue;
+      if (code[0].type != PHOT_DEP) continue;
+      if (code[0].equiv != photcode[0].code) continue;
+      catalog[0].measure[m].Mcal -= sgroup[0].M;
+      found ++;
+    }
+  }
+
+  if (found) {
+    fprintf (stderr, "found %d matches\n", found);
+    if (warn) fprintf (stderr, "warning: updated values, perhaps out of range?\n");
+  }
+}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_uniphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_uniphot.c	(revision 33228)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_uniphot.c	(revision 33228)
@@ -0,0 +1,142 @@
+# include "uniphot.h"
+# include <glob.h>
+
+// update images & catalogs for uniphot
+void update_dvo_uniphot (FITS_DB *db, Group *sgroup, int Nsgroup) {
+
+  off_t i, Nimage, Nkeep, *keep;
+  int j, status, Nmin;
+  char line[256];
+  glob_t pglob;
+  double Rmin, Rmax, Dmin, Dmax, x, y, radius;
+  Image *image;
+  Catalog catalog;
+  Coords coords;
+
+  image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
+
+  // create a subset list so we can make a vtable
+  Nkeep = 0;
+  ALLOCATE (keep, off_t, Nimage);
+
+  // identify the images used and clear the NOCAL flags on the rest
+  for (i = 0; i < Nimage; i++) {
+      if (image[i].flags & ID_IMAGE_PHOTOM_NOCAL) {
+	  image[i].flags &= ~ID_IMAGE_PHOTOM_NOCAL;
+	  continue;
+      }
+      keep[Nkeep] = i;
+      Nkeep ++;
+  }
+
+  /* apply calculated space-group offset to image Mcal values */
+  for (i = 0; i < Nsgroup; i++) {
+    for (j = 0; j < sgroup[i].Nimage; j++) {
+      sgroup[i].image[j][0].Mcal -= sgroup[i].M;
+    }
+  }
+
+  // save the rows in the image table which were used in this analysis
+  gfits_vtable_from_ftable (&db[0].ftable, &db[0].vtable, keep, Nkeep);
+
+  // write image table
+  dvo_image_update (db, VERBOSE);
+
+  // XXX need to fix the update for the catalog (or make it optional)
+  return;
+
+  // XXX this process uses the existence of the file to perform the update
+  // XXX convert this to an examination of the SkyTable
+  /** update catalog tables **/
+  pglob.gl_offs = 0;
+  sprintf (line, "%s/*/*.cpt", CATDIR);
+  status = glob (line, 0, NULL, &pglob);
+
+  coords.crpix1 = coords.crpix2 = 0.0;
+  coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
+  coords.pc1_1 = coords.pc2_2 = 1.0;
+  coords.pc1_2 = coords.pc2_1 = 0.0;
+  strcpy (coords.ctype, "RA---TAN");
+  
+  for (i = 0; i < pglob.gl_pathc; i++) {
+    catalog.filename = pglob.gl_pathv[i];
+    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
+
+    // an error exit status here is a significant error
+    if (!dvo_catalog_open (&catalog, NULL, VERBOSE, "a")) {
+      fprintf (stderr, "ERROR: failure to open/create catalog file %s\n", catalog.filename);
+      exit (2);
+    }
+    if (!catalog.Naves_disk) {
+      dvo_catalog_unlock (&catalog);
+      dvo_catalog_free (&catalog);
+      continue;
+    }
+
+    gfits_scan (&catalog.header, "RA0", "%lf",  1, &Rmin);
+    gfits_scan (&catalog.header, "RA1", "%lf",  1, &Rmax);
+    gfits_scan (&catalog.header, "DEC0", "%lf", 1, &Dmin);
+    gfits_scan (&catalog.header, "DEC1", "%lf", 1, &Dmax);
+
+    Rmin = ohana_normalize_angle (Rmin);
+    Rmax = ohana_normalize_angle (Rmax);
+
+    coords.crval1 = 0.5*(Rmin + Rmax);
+    coords.crval2 = 0.5*(Dmin + Dmax);
+
+    Nmin = 0;
+    Rmin = 1000;
+    /* primitive version: match catalog with closest sgroup */
+    for (j = 0; j < Nsgroup; j++) {
+      if (!RD_to_XY (&x, &y, sgroup[j].v1, sgroup[j].v2, &coords)) continue;
+      radius = hypot (x, y);
+      if ((j == 0) || (radius < Rmin)) {
+	Rmin = radius;
+	Nmin = j;
+      }
+    }
+
+    fprintf (stderr, "catalog: %s sgroup: %d %s %f\n", catalog.filename, Nmin, sgroup[Nmin].label, Rmin);
+    update_catalog_uniphot (&catalog, &sgroup[Nmin], (Rmin > 2*RADIUS)); 
+    dvo_catalog_save (&catalog, VERBOSE);
+    dvo_catalog_unlock (&catalog);
+    dvo_catalog_free (&catalog);
+  }
+}      
+
+/* loop over all average 
+
+   if (source equiv photcode)
+
+   loop over sgroups
+
+   if (radius < RADIUS) 
+      
+   average.M (+/-) source.M
+*/
+
+/* loop over all measure 
+
+   if (source equiv photcode)
+
+   loop over sgroups
+
+   if (radius < RADIUS) 
+      
+   measure.Mcal (+/-) source.M
+*/
+
+/* alternative (slower, more robust)
+
+   loop over all average
+   loop over all average.Nm
+   select measure with source equiv photcode
+   match measure to image, get Mcal & offset
+   if any offset for average[i] is different, give error
+   apply offset to average.M
+*/
