Index: /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libautocode/def/image.d	(revision 33241)
@@ -1,3 +1,3 @@
- STRUCT       Image
+STRUCT       Image
 EXTNAME      DVO_IMAGE
 TYPE         BINTABLE
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33241)
@@ -1,3 +1,3 @@
-default: uniphot setphot setfwhm
+default: uniphot setphot setphot_client setfwhm 
 help:
 @echo "make options: uniphot setphot setfwhm default help install default (uniphot setphot setfwhm)"
@@ -18,7 +18,9 @@
 
 uniphot: $(BIN)/uniphot.$(ARCH)
+setfwhm: $(BIN)/setfwhm.$(ARCH)
 setphot: $(BIN)/setphot.$(ARCH)
-setfwhm: $(BIN)/setfwhm.$(ARCH)
-install: $(DESTBIN)/uniphot $(DESTBIN)/setphot $(DESTBIN)/setfwhm
+setphot_client: $(BIN)/setphot_client.$(ARCH)
+
+install: $(DESTBIN)/uniphot $(DESTBIN)/setfwhm $(DESTBIN)/setphot $(DESTBIN)/setphot_client
 
 UNIPHOT = \
@@ -45,10 +47,8 @@
 SETPHOT = \
 $(SRC)/setphot.$(ARCH).o	    \
-$(SRC)/initialize.$(ARCH).o	    \
-$(SRC)/ConfigInit.$(ARCH).o	    \
-$(SRC)/args.$(ARCH).o               \
-$(SRC)/liststats.$(ARCH).o	    \
+$(SRC)/initialize_setphot.$(ARCH).o \
 $(SRC)/load_zpt_table.$(ARCH).o	    \
-$(SRC)/load_images.$(ARCH).o	    \
+$(SRC)/load_images_setphot.$(ARCH).o \
+$(SRC)/ImageSubset.$(ARCH).o	    \
 $(SRC)/match_zpts_to_images.$(ARCH).o	    \
 $(SRC)/match_flatcorr_to_images.$(ARCH).o	    \
@@ -58,6 +58,16 @@
 $(SRC)/Shutdown.$(ARCH).o	    
 
-$(SETPHOT): $(INC)/uniphot.h
+$(SETPHOT): $(INC)/setphot.h
 $(BIN)/setphot.$(ARCH): $(SETPHOT)
+
+SETPHOT_CLIENT = \
+$(SRC)/setphot_client.$(ARCH).o	    \
+$(SRC)/initialize_setphot_client.$(ARCH).o \
+$(SRC)/ImageSubset.$(ARCH).o	    \
+$(SRC)/update_dvo_setphot_client.$(ARCH).o \
+$(SRC)/update_catalog_setphot_client.$(ARCH).o
+
+$(SETPHOT_CLIENT): $(INC)/setphot.h
+$(BIN)/setphot_client.$(ARCH): $(SETPHOT_CLIENT)
 
 SETFWHM =                           \
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h	(revision 33241)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h	(revision 33241)
@@ -0,0 +1,65 @@
+# include <ohana.h>
+# include <dvo.h>
+# include <signal.h>
+
+typedef struct {
+    float zpt;
+    float zpt_err;
+    e_time time;
+    int found;
+} ZptTable;
+
+typedef struct {
+  float Mcal;
+  float dMcal;
+  unsigned int imageID;
+  unsigned int photom_map_id;
+  unsigned int flags;
+} ImageSubset;
+
+/* global variables set in parameter file */
+char         ImageCat[256];
+char         CATDIR[256];
+int          HOST_ID;
+char        *HOSTDIR;
+char        *IMAGES;
+int          VERBOSE;
+int          UBERCAL; // load the supplied ubercal zero point fits table (with flat-field corrections)
+int          NO_METADATA; // the supplied ubercal data has no descriptive metadata
+int          VERBOSE;
+int          UPDATE;
+
+/***** prototypes ****/
+int           main                PROTO((int argc, char **argv));
+
+void          ConfigInit          PROTO((int *argc, char **argv));
+void          initialize_setphot  PROTO((int argc, char **argv));
+int           args_setphot        PROTO((int argc, char **argv));
+
+void          initialize_setphot_client PROTO((int argc, char **argv));
+int           args_setphot_client       PROTO((int argc, char **argv));
+int           update_dvo_setphot_client PROTO((ImageSubset *image, off_t Nimage, FlatCorrectionTable *flatcorr));
+
+ImageSubset  *ImageSubsetLoad     PROTO((char *filename, off_t *nimage));
+int           ImageSubsetSave     PROTO((char *filename, Image *image, off_t Nimage));
+
+void 	      lock_image_db 	  PROTO((FITS_DB *db, char *filename));
+void	      unlock_image_db 	  PROTO((FITS_DB *db));
+void	      create_image_db 	  PROTO((FITS_DB *db));
+void	      set_db 		  PROTO((FITS_DB *in));
+int 	      Shutdown 		  PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
+void 	      TrapSignal 	  PROTO((int sig));
+void 	      SetProtect 	  PROTO((int mode));
+int 	      SetSignals 	  PROTO((void));
+
+// setphot-specific prototypes
+ZptTable     *load_zpt_table         PROTO((char *filename, int *nzpts));
+Image        *load_images_setphot    PROTO((FITS_DB *db, off_t *Nimage));
+int           match_zpts_to_images   PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts));
+int           update_dvo_setphot     PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorr));
+void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr));
+void          update_catalog_setphot_client PROTO((Catalog *catalog, ImageSubset *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr));
+
+ZptTable     *load_zpt_ubercal            PROTO((char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable));
+ZptTable     *load_zpt_ubercal_nometadata PROTO((char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable));
+int           match_flatcorr_to_images    PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable));
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot_client.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot_client.h	(revision 33241)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot_client.h	(revision 33241)
@@ -0,0 +1,168 @@
+# include <ohana.h>
+# include <dvo.h>
+# include <signal.h>
+
+# ifdef ANSI
+#   define F_SETFL      4   
+#   define O_NONBLOCK   0200000  
+#   define AF_UNIX      1          
+#   define SOCK_STREAM  1          
+#   define ENOENT       2       /* No such file or directory    */
+# endif /* ANSI */
+
+typedef struct {
+  double median;
+  double mean;
+  double sigma;
+  double error;
+  double chisq;
+  double min;
+  double max;
+  double total;
+  int    Nmeas;
+} StatType;
+
+typedef struct {
+  void *tgroup;
+  void *sgroup;
+} ImageLink;
+
+typedef struct {
+  char tstart[64];
+  char tstop[64];
+  char label[64];
+  float M;
+  float dM;
+  float dMsub;
+  double v1, v2;
+  Image **image;
+  ImageLink **imlink;
+  int Nimage, Ngood;
+} Group;
+
+typedef struct {
+    float zpt;
+    float zpt_err;
+    e_time time;
+    int found;
+} ZptTable;
+
+typedef struct {
+    float fwhm_major;
+    float fwhm_minor;
+    e_time time;
+    int found;
+    unsigned short photcode;
+} FWHMTable;
+
+/* global variables set in parameter file */
+char         ImageCat[256];
+char         CATDIR[256];
+char         CATMODE[16];    /* raw, mef, split, mysql */
+char         CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
+char         SKY_TABLE[256];
+int          SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
+char         GSCFILE[256];
+char         STATMODE[64];
+int          VERBOSE;
+int          UBERCAL; // load the supplied ubercal zero point fits table (with flat-field corrections)
+int          NO_METADATA; // the supplied ubercal data has no descriptive metadata
+int          NLOOP;
+int          TimeSelect;
+int          VERBOSE;
+int          UPDATE;
+int          IMAGE_BAD;
+double       RADIUS;
+double       TRANGE;
+time_t 	     TSTART;
+time_t 	     TSTOP;
+PhotCode    *photcode;
+
+enum {black, white, red, orange, yellow, green, blue, indigo, violet};
+
+typedef struct {
+  double xmin, xmax, ymin, ymax;
+  int style, ptype, ltype, etype, color;
+  double lweight, size;
+} UPGraphdata;
+
+/***** prototypes ****/
+void          ConfigInit          PROTO((int *argc, char **argv));
+void          DonePlotting        PROTO((UPGraphdata *graphmode, int N));
+void          JpegPlot            PROTO((UPGraphdata *graphmode, int N, char *filename));
+void          PSPlot              PROTO((UPGraphdata *graphmode, int N, char *filename));
+void          PlotLabel           PROTO((char *string, int N));
+void          PlotVector          PROTO((int Npts, double *vect, int mode, int N));
+void          PrepPlotting        PROTO((int Npts, UPGraphdata *graphmode, int N));
+void          XDead               PROTO((void));
+int           args_uniphot        PROTO((int argc, char **argv));
+int           args_setphot        PROTO((int argc, char **argv));
+void          dumpresult          PROTO((void));
+Group        *find_image_sgroups  PROTO((FITS_DB *db, ImageLink **imlink, int *Nsgroup));
+Group        *find_image_tgroups  PROTO((FITS_DB *db, ImageLink **imlink, int *Ntgroup));
+void          fit_sgroup          PROTO((Group *sgroup, int Nsgroup));
+void          fit_tgroup          PROTO((Group *tgroup, int Ntgroup));
+int           gcatalog            PROTO((Catalog *catalog));
+void          initialize_uniphot  PROTO((int argc, char **argv));
+void          initialize_setphot  PROTO((int argc, char **argv));
+void          initstats           PROTO((char *mode));
+int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
+int           load_images_uniphot PROTO((FITS_DB *db));
+int           main                PROTO((int argc, char **argv));
+int           open_graph          PROTO((int N));
+void          sort                PROTO((unsigned int *X, int N));
+void          sortB               PROTO((double *X, double *Y, int N));
+void          sortD               PROTO((double *X, double *Y, double *Z, int N));
+void          wcatalog            PROTO((Catalog *catalog));
+void          wimages             PROTO((Image *image, int Nimage));
+void 	      check_permissions   PROTO((char *basefile));
+void 	      lock_image_db 	  PROTO((FITS_DB *db, char *filename));
+void	      unlock_image_db 	  PROTO((FITS_DB *db));
+void	      create_image_db 	  PROTO((FITS_DB *db));
+void	      set_db 		  PROTO((FITS_DB *in));
+int 	      Shutdown 		  PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
+void 	      TrapSignal 	  PROTO((int sig));
+void 	      SetProtect 	  PROTO((int mode));
+int 	      SetSignals 	  PROTO((void));
+int 	      subset_images 	  PROTO((FITS_DB *db));
+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));
+
+// setphot-specific prototypes
+ZptTable     *load_zpt_table         PROTO((char *filename, int *nzpts));
+Image        *load_images_setphot    PROTO((FITS_DB *db, off_t *Nimage));
+int           match_zpts_to_images   PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts));
+int           update_dvo_setphot     PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorr));
+void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr));
+
+ZptTable *load_zpt_ubercal (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable);
+ZptTable *load_zpt_ubercal_nometadata (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable);
+int match_flatcorr_to_images (Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable);
+
+/*** time/coord conversion functions not supplied by libohana ***/
+time_t        TimeRef               PROTO((double time, time_t TimeReference, int TimeFormat));
+double        TimeValue             PROTO((time_t time, time_t TimeReference, int TimeFormat));
+
+int           hh_hms                PROTO((double hh, int *hr, int *mn, double *sc));
+int           dd_dms                PROTO((double dd, int *dg, int *mn, double *sc));
+int           hms_format            PROTO((char *line, double value));
+int           dms_format            PROTO((char *line, double value));
+int           hh_hm                 PROTO((double hh, int *hr, double *mn));
+int           day_to_sec            PROTO((char *string, time_t *second));
+int           hms_to_sec            PROTO((char *string, time_t *second));
+char         *ohana_sec_to_hms      PROTO((time_t second));
+char         *ohana_sec_to_day      PROTO((time_t second));
+
+char         *meade_deg_to_str      PROTO((double deg));
+char         *meade_ra_to_str       PROTO((double deg));
+char         *meade_dec_to_str      PROTO((double deg));
+char         *strptime              PROTO((const char *s, const char *format, struct tm *tm));
+time_t        GetTimeReference      PROTO((char *reference));
+int           GetTimeUnits          PROTO((char *name));
+
+void          initialize_setfwhm    PROTO((int argc, char **argv));
+int           args_setfwhm          PROTO((int argc, char **argv));
+FWHMTable    *load_fwhm_table       PROTO((char *filename, int *nfwhm));
+int           match_fwhm_to_images  PROTO((Image *image, off_t Nimage, FWHMTable *fwhm, int Nfwhm));
+
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/uniphot.h	(revision 33241)
@@ -97,5 +97,4 @@
 void          XDead               PROTO((void));
 int           args_uniphot        PROTO((int argc, char **argv));
-int           args_setphot        PROTO((int argc, char **argv));
 void          dumpresult          PROTO((void));
 Group        *find_image_sgroups  PROTO((FITS_DB *db, ImageLink **imlink, int *Nsgroup));
@@ -105,8 +104,8 @@
 int           gcatalog            PROTO((Catalog *catalog));
 void          initialize_uniphot  PROTO((int argc, char **argv));
-void          initialize_setphot  PROTO((int argc, char **argv));
 void          initstats           PROTO((char *mode));
 int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
 int           load_images_uniphot PROTO((FITS_DB *db));
+Image        *load_images_setfwhm PROTO((FITS_DB *db, off_t *Nimage));
 int           main                PROTO((int argc, char **argv));
 int           open_graph          PROTO((int N));
@@ -130,33 +129,4 @@
 void 	      sort_time 	  PROTO((unsigned int *value, int N));
 
-// setphot-specific prototypes
-ZptTable     *load_zpt_table         PROTO((char *filename, int *nzpts));
-Image        *load_images_setphot    PROTO((FITS_DB *db, off_t *Nimage));
-int           match_zpts_to_images   PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts));
-int           update_dvo_setphot     PROTO((Image *image, off_t Nimage, FlatCorrectionTable *flatcorr));
-void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr));
-
-ZptTable *load_zpt_ubercal (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable);
-ZptTable *load_zpt_ubercal_nometadata (char *filename, int *nzpts, FlatCorrectionTable *flatcorrTable);
-int match_flatcorr_to_images (Image *image, off_t Nimage, FlatCorrectionTable *flatcorrTable);
-
-/*** time/coord conversion functions not supplied by libohana ***/
-time_t        TimeRef               PROTO((double time, time_t TimeReference, int TimeFormat));
-double        TimeValue             PROTO((time_t time, time_t TimeReference, int TimeFormat));
-
-int           hh_hms                PROTO((double hh, int *hr, int *mn, double *sc));
-int           dd_dms                PROTO((double dd, int *dg, int *mn, double *sc));
-int           hms_format            PROTO((char *line, double value));
-int           dms_format            PROTO((char *line, double value));
-int           hh_hm                 PROTO((double hh, int *hr, double *mn));
-int           day_to_sec            PROTO((char *string, time_t *second));
-int           hms_to_sec            PROTO((char *string, time_t *second));
-char         *ohana_sec_to_hms      PROTO((time_t second));
-char         *ohana_sec_to_day      PROTO((time_t second));
-
-char         *meade_deg_to_str      PROTO((double deg));
-char         *meade_ra_to_str       PROTO((double deg));
-char         *meade_dec_to_str      PROTO((double deg));
-char         *strptime              PROTO((const char *s, const char *format, struct tm *tm));
 time_t        GetTimeReference      PROTO((char *reference));
 int           GetTimeUnits          PROTO((char *name));
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c	(revision 33241)
@@ -1,15 +1,7 @@
-# include "uniphot.h"
+# include "setphot.h"
 
-typedef struct {
-  float Mcal;
-  float dMcal;
-  unsigned int imageID;
-  unsigned int photom_map_id;
-  unsigned int flags;
-} ImageSubset;
+ImageSubset *ImageSubsetLoad(char *filename, off_t *nimage) {
 
-ImageSubset *ImageSubsetLoad(char *filename, int *nimage) {
-
-  int i, Ncol;
+  int i, Ncol, Ncol2;
   off_t Nrow;
   Header header;
@@ -53,4 +45,6 @@
   // this means I need 3 copies in memory at some point.  ugh.
 
+  char type[16];
+
   // need to create and assign to flat-field correction
   float *Mcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL", type, &Nrow, &Ncol);
@@ -58,18 +52,18 @@
 
   float *dMcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL_ERR", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "float"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
+  myAssert (!strcmp(type, "float"), "wrong column type");
+  myAssert (Ncol == Ncol2, "table length mismatch");
 
   unsigned int *imageID = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
+  myAssert (!strcmp(type, "int"), "wrong column type");
+  myAssert (Ncol == Ncol2, "table length mismatch");
 
   unsigned int *map = gfits_get_bintable_column_data (&theader, &ftable, "PHOTOM_MAP", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
+  myAssert (!strcmp(type, "int"), "wrong column type");
+  myAssert (Ncol == Ncol2, "table length mismatch");
 
   unsigned int *flags = gfits_get_bintable_column_data (&theader, &ftable, "FLAGS", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
+  myAssert (!strcmp(type, "int"), "wrong column type");
+  myAssert (Ncol == Ncol2, "table length mismatch");
 
   // XXX free the fits table data here 
@@ -95,8 +89,7 @@
 }
 
-int ImageSubsetSave(char *filename, Image *image, int Nimage) {
+int ImageSubsetSave(char *filename, Image *image, off_t Nimage) {
 
-  int i, Ncol;
-  off_t Nrow;
+  int i;
   Header header;
   Header theader;
@@ -109,5 +102,5 @@
   gfits_create_matrix (&header, &matrix);
 
-  gfits_create_table_header (&theader, "BINTABLE", FITS);
+  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
 
   gfits_define_bintable_column (&theader, "E", "MCAL", "zero point offset", "magnitudes", 1.0, 0.0);
@@ -122,80 +115,29 @@
   gfits_create_table (&theader, &ftable);
 
-  // add the vectors to the output array
-  ALLOCATE (Mcal, float, Nimage);
+  float *Mcal, *dMcal;
+  unsigned int *imageID, *map, *flags;
+
+  // create intermediate storage arrays
+  ALLOCATE (Mcal,  float, Nimage);
   ALLOCATE (dMcal, float, Nimage);
   ALLOCATE (imageID, unsigned int, Nimage);
-  ALLOCATE (imageID, unsigned int, Nimage);
+  ALLOCATE (map,     unsigned int, Nimage);
+  ALLOCATE (flags,   unsigned int, Nimage);
 
-  for 
-  gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements);
-    } else {
-      gfits_set_bintable_column_reformat (&theader, &ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements);
-      }
+  // assign the storage arrays
+  for (i = 0; i < Nimage; i++) {
+    imageID[i] = image[i].imageID;
+    map[i]     = image[i].photom_map_id;
+    flags[i]   = image[i].flags;
+    Mcal[i]    = image[i].Mcal;
+    dMcal[i]   = image[i].dMcal;
   }
 
-  FILE *f = fopen (filename, "w");
-  if (!f) {
-    fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", filename);
-    return NULL;
-  }
-
-  /* load in PHU segment (ignore) */
-  if (!gfits_fread_header (f, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
-    fclose (f);
-    return NULL;
-  }
-  if (!gfits_fread_matrix (f, &matrix, &header)) {
-    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
-    gfits_free_header (&header);
-    fclose (f);
-    return NULL;
-  }
-
-  ftable.header = &theader;
-
-  // load data for this header 
-  if (!gfits_load_header (f, &theader)) return (NULL);
-
-  // read the fits table bytes
-  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) return (NULL);
-  
-  // XXX close the fits file here
-
-  // a bit annoying : we read the entire block of data (180M), then extract the columns, then set the image structure values.
-  // this means I need 3 copies in memory at some point.  ugh.
-
-  // need to create and assign to flat-field correction
-  float *Mcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL", type, &Nrow, &Ncol);
-  myAssert (!strcmp(type, "float"), "wrong column type");
-
-  float *dMcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL_ERR", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "float"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
-
-  unsigned int *imageID = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
-
-  unsigned int *map = gfits_get_bintable_column_data (&theader, &ftable, "PHOTOM_MAP", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
-
-  unsigned int *flags = gfits_get_bintable_column_data (&theader, &ftable, "FLAGS", type, &Nrow, &Ncol2);
-  assert (!strcmp(type, "int"), "wrong column type");
-  assert (Ncol == Ncol2, "table length mismatch");
-
-  // XXX free the fits table data here 
-
-  ALLOCATE (image, ImageSubset, Ncol);
-  for (i = 0; i < Nrow; i++) {
-    image[i].imageID       = imageID[i];
-    image[i].photom_map_id = map[i];
-    image[i].flags         = flags[i];
-    image[i].Mcal          = Mcal[i];
-    image[i].dMcal         = dMcal[i];
-  }
-  fprintf (stderr, "loaded data for %d images\n", Ncol);
+  // add the columns to the output array
+  gfits_set_bintable_column (&theader, &ftable, "MCAL",       Mcal,    Nimage);
+  gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",   dMcal,   Nimage);
+  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",   imageID, Nimage);
+  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP", map,     Nimage);
+  gfits_set_bintable_column (&theader, &ftable, "FLAGS",      flags,   Nimage);
 
   free (Mcal);
@@ -205,5 +147,20 @@
   free (flags);
 
-  *nimage = Ncol;
-  return image;
+  FILE *f = fopen (filename, "w");
+  if (!f) {
+    fprintf (stderr, "ERROR: cannot open image subset file for output %s\n", filename);
+    return FALSE;
+  }
+
+  gfits_fwrite_header  (f, &header);
+  gfits_fwrite_matrix  (f, &matrix);
+  gfits_fwrite_Theader (f, &theader);
+  gfits_fwrite_table  (f, &ftable);
+
+  gfits_free_header (&header);
+  gfits_free_matrix (&matrix);
+  gfits_free_header (&theader);
+  gfits_free_table (&ftable);
+
+  return TRUE;
 }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/args.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/args.c	(revision 33241)
@@ -72,45 +72,4 @@
 }
 
-int args_setphot (int argc, char **argv) {
-
-  int N;
-
-  VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
-    VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
-  }
-
-  UBERCAL = FALSE;
-  if ((N = get_argument (argc, argv, "-ubercal"))) {
-    remove_argument (N, &argc, argv);
-    UBERCAL = TRUE;
-  }
-
-  NO_METADATA = FALSE;
-  if ((N = get_argument (argc, argv, "-no-metadata"))) {
-    remove_argument (N, &argc, argv);
-    NO_METADATA = TRUE;
-  }
-
-  UPDATE = FALSE;
-  if ((N = get_argument (argc, argv, "-update"))) {
-    remove_argument (N, &argc, argv);
-    UPDATE = TRUE;
-  }
-
-  if (argc != 2) {
-    fprintf (stderr, "USAGE: setphot (zptfile) [options]\n");
-    fprintf (stderr, "  options:\n");
-    fprintf (stderr, "    -v : verbose mode\n");
-    fprintf (stderr, "    -ubercal : interpret zpt file as a GPC1 ubercal FITS table\n");
-    fprintf (stderr, "    -update : actually write results to detections tables\n");
-    fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
-    exit (2);
-  } 
-
-  return (TRUE);
-}
-
 int args_setfwhm (int argc, char **argv) {
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/convert.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/convert.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/convert.c	(revision 33241)
@@ -1,7 +1,3 @@
 # include "uniphot.h"
-# define _XOPEN_SOURCE /* glibc2 (strptime) needs this */
-# include <time.h>
-
-/** additional time / coordinate conversions not supplied by libohana **/
 
 time_t GetTimeReference (char *reference) {
@@ -36,302 +32,2 @@
   return (Units);
 }
-
-int hh_hms (double hh, int *hr, int *mn, double *sc) {
-
-  int N, flag;
-
-  flag = SIGN(hh);
-  hh = fabs(hh);
-
-  // rationalize hh to range -24.0 < hh < 24.0
-  if (hh >= 24.0) {
-    N = (int)(hh/24.0);
-    hh -= 24.0*N;
-  }
-
-  *hr = (int) hh;
-  *mn = (int) 60*(hh - *hr);
-  *sc = 3600.0*(hh - *hr - *mn / 60.0);
-  if (*sc > 59.99) {
-    *sc = 0.0;
-    *mn += 1.0;
-  }
-  *hr *= flag;
-  return (TRUE);
-}
- 
-int dd_dms (double dd, int *dg, int *mn, double *sc) {
-
-  int flag;
-
-  flag = SIGN(dd);
-  dd = fabs (dd);
-  *dg = (int) dd;
-  *mn = (int) 60*(dd - *dg);
-  *sc = 3600.0*(dd - *dg - *mn/60.0);
-  if (*sc > 59.99) {
-    *sc = 0;
-    *mn += 1.0;
-  }
-  *dg *= flag;
-  return (TRUE);
-}
- 
-int hms_format (char *line, double value) {
-
-  int hr, mn;
-  double sc;
-
-  hh_hms (value, &hr, &mn, &sc);
-  hr = (int) value;
-  if (isnan (value))
-    sprintf (line, "xx:xx:xx.xx");
-  else {
-    if (value < 0) {
-      sprintf (line, "-%02d:%02d:%05.2f", abs(hr), mn, sc);
-    } else {
-      sprintf (line, "+%02d:%02d:%05.2f", hr, mn, sc);
-    }
-  }      
-  return (TRUE);
-}
-
-int dms_format (char *line, double value) {
-
-  int dg, mn;
-  double sc;
-
-  dd_dms (value, &dg, &mn, &sc);
-  if (value < 0) {
-    sprintf (line, "-%02d:%02d:%05.2f", abs(dg), mn, sc);
-  } else {
-    sprintf (line, "+%02d:%02d:%05.2f", dg, mn, sc);
-  }
-  return (TRUE);
-}
-
-/***** convert 00:00:00 or 00:00 to 0 - 86400 ****/
-int hms_to_sec (char *string, time_t *second) {
-  
-  char *p;
-  struct tm time;
-
-  p = strptime (string, "%H:%M:%S", &time);
-  if (p != NULL) goto valid;
-
-  p = strptime (string, "%H:%M", &time);
-  if (p != NULL) goto valid;
-
-  return (FALSE);
-    
-valid:
-  if (*p) return (FALSE);
-  *second = time.tm_hour*3600 + time.tm_min*60 + time.tm_sec;
-  return (TRUE);
-}
-
-/***** convert Mon[@00:00:00] or 00:00 to 0 - 86400*7 ****/
-int day_to_sec (char *string, time_t *second) {
-  
-  char *p;
-  struct tm time;
-
-  bzero (&time, sizeof(time));
-  p = strptime (string, "%A@%H:%M:%S", &time);
-  if (p != NULL) goto valid;
-
-  p = strptime (string, "%A@%H:%M", &time);
-  if (p != NULL) goto valid;
-
-  p = strptime (string, "%A@%H", &time);
-  if (p != NULL) goto valid;
-
-  p = strptime (string, "%A", &time);
-  if (p != NULL) goto valid;
-
-  return (FALSE);
-
-valid:
-  if (*p) return (FALSE);
-  *second = time.tm_wday*86400 + time.tm_hour*3600 + time.tm_min*60 + time.tm_sec;
-  return (TRUE);
-}
-
-/***** convert seconds to HH:MM:SS ****/
-char *ohana_sec_to_hms (time_t second) {
-  
-  struct tm *gmt;
-  char *line;
-
-  ALLOCATE (line, char, 64);
-  gmt   = gmtime (&second);
-  sprintf (line, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-  return (line);
-}
-
-/***** convert seconds to Day@HH:MM:SS ****/
-char *ohana_sec_to_day (time_t second) {
-  
-  struct tm *gmt;
-  char *line;
-
-  ALLOCATE (line, char, 64);
-  gmt   = gmtime (&second);
-  switch (gmt[0].tm_wday) {
-    case 0:
-      sprintf (line, "Sun@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 1:
-      sprintf (line, "Mon@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 2:
-      sprintf (line, "Tue@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 3:
-      sprintf (line, "Wed@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 4:
-      sprintf (line, "Thu@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 5:
-      sprintf (line, "Fri@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-    case 6:
-      sprintf (line, "Sat@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 
-      break;
-  }
-  return (line);
-}
-
-int hh_hm (double hh, int *hr, double *mn) {
-
-  int flag;
-
-  flag = SIGN(hh);
-  hh = fabs (hh);
-
-  *mn = 60.0*(hh - (int)hh);
-  *hr = (int) hh;
-  *hr *= flag;
-  return (TRUE);
-}
-
-char *meade_deg_to_str (double deg) {
-
-  int hr;
-  double mn;
-  char *line;
-
-  ALLOCATE (line, char, 16);
-
-  hh_hm (deg, &hr, &mn);
-
-  sprintf (line, "%03d:%04.1f", abs(hr), mn);
-  return (line);
-}
-
-char *meade_ra_to_str (double deg) {
-
-  int hr;
-  double mn;
-  char *line;
-
-  ALLOCATE (line, char, 16);
-
-  hh_hm (deg/15.0, &hr, &mn);
-
-  sprintf (line, "%02d:%04.1f", abs(hr), mn);
-  return (line);
-}
-
-char *meade_dec_to_str (double deg) {
-
-  int hr;
-  double mn;
-  char *line;
-
-  ALLOCATE (line, char, 16);
-
-  hh_hm (deg, &hr, &mn);
-
-  if (deg < 0) {
-    sprintf (line, "-%02d:%04.1f", abs(hr), mn);
-  } else {
-    sprintf (line, "+%02d:%04.1f", hr, mn);
-  }      
-  return (line);
-}
-
-/* convert UNIX time to a value referenced to the TimeReference in the given unit */
-double TimeValue (time_t time, time_t TimeReference, int TimeFormat) {
-
-  double value, dt;
-
-  dt = (time > TimeReference) ? (time - TimeReference) : -1 * (double)(TimeReference - time);
-  switch (TimeFormat) {
-  case TIME_JD:
-    value = time / 86400.0 + 2440587.5;
-    break;
-  case TIME_MJD:
-    value = time / 86400.0 + 40587.0;
-    break;
-  case TIME_DAYS:
-    value = dt / 86400.0;
-    break;
-  case TIME_HOURS:
-    value = dt / 3600.0;
-    break;
-  case TIME_MINUTES:
-    value = dt / 60.0;
-    break;
-  case TIME_SECONDS:
-  default:
-    value = dt;
-    break;
-  }
-  return (value);
-}
-  
-/* convert time value referenced to the TimeReference in the given unit to UNIX time */
-time_t TimeRef (double value, time_t TimeReference, int TimeFormat) {
-
-  int dt;
-  time_t time;
-
-  switch (TimeFormat) {
-  case TIME_JD:
-    time = (value -  2440587.5) * 86400.0;
-    return (time);
-    break;
-  case TIME_MJD:
-    time = (value -  40587.0) * 86400.0;
-    return (time);
-    break;
-  case TIME_DAYS:
-    dt = value * 86400.0;
-    break;
-  case TIME_HOURS:
-    dt = value * 3600.0;
-    break;
-  case TIME_MINUTES:
-    dt = value * 60.0;
-    break;
-  case TIME_SECONDS:
-  default:
-    dt = value;
-    break;
-  }
-
-  time = TimeReference + dt;
-  return (time);
-}
-
-/* times may be in forms as:
- * 20040200450s (N seconds since 1970.0)
- * 2440900.232j (julian date)
- * 99/02/23,03:22:18 (date string)
- * (separators may be anything except space, +, -)
- * 99:02:15:12:23:30
- * 99:02:15:12h23m30s
- */
-
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize.c	(revision 33241)
@@ -21,27 +21,4 @@
 }
 
-void initialize_setphot (int argc, char **argv) {
-
-  struct stat statbuffer;
-
-  char CatdirPhotcodeFile[256];
-
-  /* are these set correctly? */
-  ConfigInit (&argc, argv);
-  args_setphot (argc, argv);
-
-  if (stat (CATDIR, &statbuffer)) {
-    fprintf (stderr, "error accessing dvo database directory '%s'\n", CATDIR);
-    exit (1);
-  }
-
-  /* XXX this does not yet write out the master photcode table */
-  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
-  if (!LoadPhotcodes (CatdirPhotcodeFile, NULL, TRUE)) {
-    fprintf (stderr, "error loading photcode table %s\n", CatdirPhotcodeFile);
-    exit (1);
-  }
-}
-
 void initialize_setfwhm (int argc, char **argv) {
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot.c	(revision 33241)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot.c	(revision 33241)
@@ -0,0 +1,104 @@
+# include "setphot.h"
+
+void initialize_setphot (int argc, char **argv) {
+
+  struct stat statbuffer;
+
+  char CatdirPhotcodeFile[256];
+
+  /* are these set correctly? */
+  ConfigInit (&argc, argv);
+  args_setphot (argc, argv);
+
+  if (stat (CATDIR, &statbuffer)) {
+    fprintf (stderr, "error accessing dvo database directory '%s'\n", CATDIR);
+    exit (1);
+  }
+
+  // load the photcode table
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, NULL, TRUE)) {
+    fprintf (stderr, "error loading photcode table %s\n", CatdirPhotcodeFile);
+    exit (1);
+  }
+}
+
+int args_setphot (int argc, char **argv) {
+
+  int N;
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  UBERCAL = FALSE;
+  if ((N = get_argument (argc, argv, "-ubercal"))) {
+    remove_argument (N, &argc, argv);
+    UBERCAL = TRUE;
+  }
+
+  NO_METADATA = FALSE;
+  if ((N = get_argument (argc, argv, "-no-metadata"))) {
+    remove_argument (N, &argc, argv);
+    NO_METADATA = TRUE;
+  }
+
+  UPDATE = FALSE;
+  if ((N = get_argument (argc, argv, "-update"))) {
+    remove_argument (N, &argc, argv);
+    UPDATE = TRUE;
+  }
+
+  if (argc != 2) {
+    fprintf (stderr, "USAGE: setphot (zptfile) [options]\n");
+    fprintf (stderr, "  options:\n");
+    fprintf (stderr, "    -v : verbose mode\n");
+    fprintf (stderr, "    -ubercal : interpret zpt file as a GPC1 ubercal FITS table\n");
+    fprintf (stderr, "    -update : actually write results to detections tables\n");
+    fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
+    exit (2);
+  } 
+
+  return (TRUE);
+}
+
+void GetConfig (char *config, char *field, char *format, int N, void *ptr);
+
+void ConfigInit (int *argc, char **argv) {
+
+  double ZERO_POINT;
+  char  *config, *file;
+
+  /*** load configuration info ***/
+  file = SelectConfigFile (argc, argv, "ptolemy");
+  config = LoadConfigFile (file);
+  if (config == (char *) NULL) {
+    fprintf (stderr, "ERROR: can't find configuration file %s\n", file);
+    if (file != (char *) NULL) free (file);
+    exit (0);
+  }
+  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
+
+  GetConfig (config, "CATDIR",                 "%s",  0, CATDIR);
+  sprintf (ImageCat, "%s/Images.dat", CATDIR);
+
+  ScanConfig (config, "ZERO_PT",                "%lf", 0, &ZERO_POINT);
+  SetZeroPoint (ZERO_POINT);
+
+  free (config);
+  free (file);
+}
+
+void GetConfig (char *config, char *field, char *format, int N, void *ptr) {
+
+  char *status;
+
+  status = ScanConfig (config, field, format, N, ptr);
+  if (status == NULL) {
+    fprintf (stderr, "error in config, cannot find %s\n", field);
+    exit (1);
+  }
+  return;
+}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot_client.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot_client.c	(revision 33241)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/initialize_setphot_client.c	(revision 33241)
@@ -0,0 +1,90 @@
+# include "setphot.h"
+
+void initialize_setphot_client (int argc, char **argv) {
+
+  struct stat statbuffer;
+
+  char CatdirPhotcodeFile[256];
+
+  SetZeroPoint (25.0); // XXX is this needed?
+  args_setphot_client (argc, argv);
+
+  if (stat (CATDIR, &statbuffer)) {
+    fprintf (stderr, "error accessing dvo database directory '%s'\n", CATDIR);
+    exit (1);
+  }
+
+  // load the photcode table : XXX needed?
+  sprintf (CatdirPhotcodeFile, "%s/Photcodes.dat", CATDIR);
+  if (!LoadPhotcodes (CatdirPhotcodeFile, NULL, TRUE)) {
+    fprintf (stderr, "error loading photcode table %s\n", CatdirPhotcodeFile);
+    exit (1);
+  }
+}
+
+int args_setphot_client (int argc, char **argv) {
+
+  int N;
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  UBERCAL = FALSE;
+  if ((N = get_argument (argc, argv, "-ubercal"))) {
+    remove_argument (N, &argc, argv);
+    UBERCAL = TRUE;
+  }
+
+  UPDATE = FALSE;
+  if ((N = get_argument (argc, argv, "-update"))) {
+    remove_argument (N, &argc, argv);
+    UPDATE = TRUE;
+  }
+
+  HOST_ID = 0;
+  if ((N = get_argument (argc, argv, "-hostID"))) {
+    remove_argument (N, &argc, argv);
+    HOST_ID = atoi (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!HOST_ID) goto usage;
+
+  HOSTDIR = NULL;
+  if ((N = get_argument (argc, argv, "-hostdir"))) {
+    remove_argument (N, &argc, argv);
+    HOSTDIR = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!HOSTDIR) goto usage;
+
+  CATDIR[0] = 0;
+  if ((N = get_argument (argc, argv, "-catdir"))) {
+    remove_argument (N, &argc, argv);
+    strcpy (CATDIR, argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!CATDIR[0]) goto usage;
+
+  IMAGES = NULL;
+  if ((N = get_argument (argc, argv, "-images"))) {
+    remove_argument (N, &argc, argv);
+    IMAGES = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+  if (!IMAGES) goto usage;
+
+  if (argc != 1) goto usage;
+  return (TRUE);
+
+usage:
+  fprintf (stderr, "USAGE: setphot_client -hostname (hostname) -catdir (catdir) -hostdir (hostdir) -images (images) [options]\n");
+  fprintf (stderr, "  options:\n");
+  fprintf (stderr, "    -v : verbose mode\n");
+  fprintf (stderr, "    -ubercal : interpret zpt file as a GPC1 ubercal FITS table\n");
+  fprintf (stderr, "    -update : actually write results to detections tables\n");
+  exit (2);
+}
+
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images.c	(revision 33241)
@@ -11,5 +11,5 @@
 }
 
-Image *load_images_setphot (FITS_DB *db, off_t *Nimage) {
+Image *load_images_setfwhm (FITS_DB *db, off_t *Nimage) {
 
   Image *image;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images_setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images_setphot.c	(revision 33241)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_images_setphot.c	(revision 33241)
@@ -0,0 +1,22 @@
+# include "setphot.h"
+
+Image *load_images_setphot (FITS_DB *db, off_t *Nimage) {
+
+  Image *image;
+
+  if (VERBOSE) fprintf (stderr, "finding images\n");
+
+  /* read entire db table */
+  if (!dvo_image_load (db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db[0].filename);
+
+  /* use a vtable to keep the images to be calibrated */
+  image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
+
+  fprintf (stderr, "loaded "OFF_T_FMT" images\n", *Nimage);
+
+  return (image);
+}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/load_zpt_table.c	(revision 33241)
@@ -1,3 +1,3 @@
-# include "uniphot.h"
+# include "setphot.h"
 
 ZptTable *load_zpt_table (char *filename, int *nzpts) {
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_flatcorr_to_images.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_flatcorr_to_images.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_flatcorr_to_images.c	(revision 33241)
@@ -1,3 +1,3 @@
-# include "uniphot.h"
+# include "setphot.h"
 
 // the date/time of the image is used to find the 'season'
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_zpts_to_images.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_zpts_to_images.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/match_zpts_to_images.c	(revision 33241)
@@ -1,3 +1,3 @@
-# include "uniphot.h"
+# include "setphot.h"
 
 /* sort a coordinate pair (X,Y) and the associated index (S) */
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setfwhm.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setfwhm.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setfwhm.c	(revision 33241)
@@ -20,5 +20,5 @@
 
   // load images
-  image  = load_images_setphot (&db, &Nimage);
+  image  = load_images_setfwhm (&db, &Nimage);
   if (!UPDATE) dvo_image_unlock (&db); 
   
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot.c	(revision 33241)
@@ -1,3 +1,3 @@
-# include "uniphot.h"
+# include "setphot.h"
 
 int main (int argc, char **argv) {
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot_client.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot_client.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot_client.c	(revision 33241)
@@ -1,3 +1,3 @@
-# include "uniphot.h"
+# include "setphot.h"
 
 // setphot_client is run on a remote host and is responsible for updating the catalogs
@@ -12,15 +12,16 @@
 int main (int argc, char **argv) {
 
-  off_t Nimage;
-  ImageSubset *image;
-
-  /* get configuration info, args, lockfile */
+  /* get configuration info, args, lockfile (set CATDIR, HOSTDIR, HOSTNAME, IMAGES) */
+  /* XXX pass in both HOSTDIR and HOSTID or just HOSTNAME (and read the host table)? */
   initialize_setphot_client (argc, argv);
 
-  // need to pass in the CATDIR
-  ImageSubset *image = ImageSubsetLoad (imageFile, &Nimage);
+  // load the image subset table from the specified location
+  off_t Nimage;
+  ImageSubset *image = ImageSubsetLoad (IMAGES, &Nimage);
 
-  // just do this normally
-  FlatCorrectionTable *flatcorrTable = FlatCorrectionLoad (flatcorrFile);
+  // load the flat-field correction table from CATDIR
+  char flatcorrFile[1024];
+  snprintf (flatcorrFile, 1024, "%s/flatcorr.fits", CATDIR);
+  FlatCorrectionTable *flatcorrTable = FlatCorrectionLoad (flatcorrFile, VERBOSE);
 
   update_dvo_setphot_client (image, Nimage, flatcorrTable);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot.c	(revision 33241)
@@ -1,4 +1,3 @@
-# include "uniphot.h"
-# include <glob.h>
+# include "setphot.h"
 
 void update_catalog_setphot (Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr) {
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot_client.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot_client.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot_client.c	(revision 33241)
@@ -1,6 +1,5 @@
-# include "uniphot.h"
-# include <glob.h>
+# include "setphot.h"
 
-void update_catalog_setphot_client (Catalog *catalog, Image *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr) {
+void update_catalog_setphot_client (Catalog *catalog, ImageSubset *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr) {
 
   off_t i, j, found;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot.c	(revision 33241)
@@ -1,4 +1,4 @@
-# include "uniphot.h"
-# include <glob.h>
+# include "setphot.h"
+int update_dvo_setphot_parallel (SkyTable *sky, Image *image, off_t Nimage);
 
 int update_dvo_setphot (Image *image, off_t Nimage, FlatCorrectionTable *flatcorr) {
@@ -9,4 +9,14 @@
   Catalog catalog;
   off_t i, maxID, *index;
+
+  // load the current sky table (layout of all SkyRegions) 
+  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, FALSE, -1, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+  
+# define PARALLEL 1
+  if (PARALLEL) {
+    update_dvo_setphot_parallel (sky, image, Nimage);
+    exit (0);
+  }
 
   // create an index for the image IDs
@@ -20,10 +30,5 @@
     index[image[i].imageID] = i;
   }
-  
 
-  // load the current sky table (layout of all SkyRegions) 
-  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
-  SkyTableSetFilenames (sky, CATDIR, "cpt");
-  
   // determine the populated SkyRegions overlapping the requested area (default depth)
   UserPatch.Rmin = 0;
@@ -38,6 +43,6 @@
     // set up the basic catalog info
     catalog.filename  = skylist[0].filename[i];
-    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
-    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
+    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
+    catalog.catmode   = DVO_MODE_UNDEF;	  // not needed since we skip empty catalogs
     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
@@ -70,2 +75,47 @@
   return (TRUE);
 }      
+
+# define DEBUG 1
+
+int update_dvo_setphot_parallel (SkyTable *sky, Image *image, off_t Nimage) {
+
+  // write out the subset table of image information
+  char imageFile[512];
+  snprintf (imageFile, 512, "%s/Images.subset.dat", CATDIR);
+  if (!ImageSubsetSave (imageFile, image, Nimage)) {
+    fprintf (stderr, "failed to write image subset\n");
+    exit (1);
+  }
+
+  // now launch the setphot_client jobs to the parallel hosts
+
+  // load the list of hosts
+  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
+
+  int i;
+  for (i = 0; i < table->Nhosts; i++) {
+
+    char command[1024];
+    snprintf (command, 1024, "setphot_client -test -hostname %s -catdir %s -hostdir %s -images %s", 
+	      table->hosts[i].hostname, CATDIR, table->hosts[i].pathname, imageFile);
+
+    fprintf (stderr, "command: %s\n", command);
+
+    // launch the job on the remote machine (no handshake)
+    int errorInfo = 0;
+    int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
+    if (!pid) {
+      if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
+      exit (1);
+    }
+    table->hosts[i].pid = pid; // save for future reference
+
+    // check that all hosts started OK?
+  }
+
+  // watch for stdout / stderr from those jobs...
+  // wait for all of them to complete...
+
+  return (TRUE);
+}      
+
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot_client.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot_client.c	(revision 33240)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot_client.c	(revision 33241)
@@ -1,8 +1,7 @@
-# include "uniphot.h"
-# include <glob.h>
+# include "setphot.h"
 
 // we want to load a subset of image data for this operation.  we only need:
 // imageID, photom_map_id, Mcal, dMcal, flags.  
-int update_dvo_setphot_client (Image *image, off_t Nimage, FlatCorrectionTable *flatcorr) {
+int update_dvo_setphot_client (ImageSubset *image, off_t Nimage, FlatCorrectionTable *flatcorr) {
 
   SkyRegion UserPatch;
@@ -24,11 +23,6 @@
 
   // load the current sky table (layout of all SkyRegions) 
-  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
+  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
   SkyTableSetFilenames (sky, CATDIR, "cpt");
-  
-  // load the host table
-  hosts = HostTableLoad ();
-  int hostID = XX;
-  HostInfo *host = XX;
 
   // determine the populated SkyRegions overlapping the requested area (default depth)
@@ -42,13 +36,14 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
-    if (hostID != skylist->regions[i]->hostID) continue;
+    if (HOST_ID != skylist->regions[i]->hostID) continue;
     if (!(skylist->regions[i]->hostFlags & DATA_ON_TGT)) continue;
 
-    snprintf (localFilename, 1024, "%s/%s.cpt", host->pathname, skylist->regions[i].name);
+    char localFilename[1024];
+    snprintf (localFilename, 1024, "%s/%s.cpt", HOSTDIR, skylist->regions[i]->name);
 
     // set up the basic catalog info
     catalog.filename  = localFilename;
-    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
-    catalog.catmode   = dvo_catalog_catmode (CATMODE);        // set the default catmode from config data
+    catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
+    catalog.catmode   = DVO_MODE_UNDEF;	  // not needed since we skip empty catalogs
     catalog.catflags  = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
     catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
