Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/Makefile	(revision 33255)
@@ -63,8 +63,8 @@
 SETPHOT_CLIENT = \
 $(SRC)/setphot_client.$(ARCH).o	    \
+$(SRC)/update_dvo_setphot.$(ARCH).o \
+$(SRC)/update_catalog_setphot.$(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
+$(SRC)/ImageSubset.$(ARCH).o
 
 $(SETPHOT_CLIENT): $(INC)/setphot.h
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h	(revision 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/include/setphot.h	(revision 33255)
@@ -43,4 +43,5 @@
 ImageSubset  *ImageSubsetLoad     PROTO((char *filename, off_t *nimage));
 int           ImageSubsetSave     PROTO((char *filename, Image *image, off_t Nimage));
+Image        *ImagesFromSubset    PROTO((ImageSubset *subset, off_t N));
 
 void 	      lock_image_db 	  PROTO((FITS_DB *db, char *filename));
Index: /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c	(revision 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/ImageSubset.c	(revision 33255)
@@ -1,7 +1,11 @@
 # include "setphot.h"
+
+# define GET_COLUMN(OUT,NAME,TYPE) \
+  TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
+  myAssert (!strcmp(type, #TYPE), "wrong column type");
 
 ImageSubset *ImageSubsetLoad(char *filename, off_t *nimage) {
 
-  int i, Ncol, Ncol2;
+  int i, Ncol;
   off_t Nrow;
   Header header;
@@ -47,23 +51,9 @@
   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);
-  myAssert (!strcmp(type, "float"), "wrong column type");
-
-  float *dMcal = gfits_get_bintable_column_data (&theader, &ftable, "MCAL_ERR", type, &Nrow, &Ncol2);
-  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);
-  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);
-  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);
-  myAssert (!strcmp(type, "int"), "wrong column type");
-  myAssert (Ncol == Ncol2, "table length mismatch");
+  GET_COLUMN (Mcal,    "MCAL",       float);
+  GET_COLUMN (dMcal,   "MCAL_ERR",   float);
+  GET_COLUMN (imageID, "IMAGE_ID",   int);
+  GET_COLUMN (map,     "PHOTOM_MAP", int);
+  GET_COLUMN (flags,   "FLAGS",      int);
 
   // XXX free the fits table data here 
@@ -165,2 +155,21 @@
   return TRUE;
 }
+
+Image *ImagesFromSubset (ImageSubset *subset, off_t N) {
+
+  off_t i;
+
+  // we have been given an ImageSubset array, containing a reduced set of image fields
+  // create full a Image array and save the needed values
+  Image *image = NULL;
+  ALLOCATE (image, Image, N);
+  for (i = 0; i < N; i++) {
+    image[i].imageID       = subset[i].imageID      ;
+    image[i].photom_map_id = subset[i].photom_map_id;
+    image[i].flags         = subset[i].flags        ;
+    image[i].Mcal          = subset[i].Mcal         ;
+    image[i].dMcal         = subset[i].dMcal        ;
+  }
+  return image;
+}
+
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 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/setphot_client.c	(revision 33255)
@@ -12,11 +12,11 @@
 int main (int argc, char **argv) {
 
-  /* 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)? */
+  // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, IMAGES)
   initialize_setphot_client (argc, argv);
 
   // load the image subset table from the specified location
   off_t Nimage;
-  ImageSubset *image = ImageSubsetLoad (IMAGES, &Nimage);
+  ImageSubset *subset = ImageSubsetLoad (IMAGES, &Nimage);
+  Image *image = ImagesFromSubset (subset, Nimage);
 
   // load the flat-field correction table from CATDIR
@@ -25,5 +25,5 @@
   FlatCorrectionTable *flatcorrTable = FlatCorrectionLoad (flatcorrFile, VERBOSE);
 
-  update_dvo_setphot_client (image, Nimage, flatcorrTable);
+  update_dvo_setphot (image, Nimage, flatcorrTable);
 
   exit (0);
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 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_catalog_setphot_client.c	(revision 33255)
@@ -1,4 +1,5 @@
 # include "setphot.h"
 
+// XXX IF we pass in an array of Image not ImageSubset, this would be identical to update_catalog_setphot
 void update_catalog_setphot_client (Catalog *catalog, ImageSubset *image, off_t *index, off_t Nimage, FlatCorrectionTable *flatcorr) {
 
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 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot.c	(revision 33255)
@@ -15,5 +15,5 @@
   
 # define PARALLEL 1
-  if (PARALLEL) {
+  if (PARALLEL && !HOST_ID) {
     update_dvo_setphot_parallel (sky, image, Nimage);
     exit (0);
@@ -26,4 +26,7 @@
   }
   ALLOCATE (index, off_t, maxID + 1);
+  for (i = 0; i < maxID + 1; i++) {
+    index[i] = -1;
+  }
   for (i = 0; i < Nimage; i++) {
     if (!image[i].imageID) continue; // images with ID == 0 are virtual
@@ -41,6 +44,12 @@
   for (i = 0; i < skylist[0].Nregions; i++) {
 
+    if (HOST_ID && (HOST_ID != skylist->regions[i]->hostID)) continue;
+    if (HOST_ID && !(skylist->regions[i]->hostFlags & DATA_ON_TGT)) continue;
+
+    char localFilename[1024];
+    snprintf (localFilename, 1024, "%s/%s.cpt", HOSTDIR, skylist->regions[i]->name);
+
     // set up the basic catalog info
-    catalog.filename  = skylist[0].filename[i];
+    catalog.filename  = HOST_ID ? localFilename : skylist[0].filename[i];
     catalog.catformat = DVO_FORMAT_UNDEF; // not needed since we skip empty catalogs
     catalog.catmode   = DVO_MODE_UNDEF;	  // not needed since we skip empty catalogs
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 33254)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/uniphot/src/update_dvo_setphot_client.c	(revision 33255)
@@ -10,4 +10,15 @@
   Catalog catalog;
   off_t i, maxID, *index;
+
+  // load the current sky table (layout of all SkyRegions) 
+  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+# if (0)
+  if (PARALLEL) {
+    update_dvo_setphot_parallel (sky, image, Nimage);
+    exit (0);
+  }
+# endif
 
   // create an index for the image IDs
@@ -24,8 +35,4 @@
     index[image[i].imageID] = i;
   }
-
-  // load the current sky table (layout of all SkyRegions) 
-  sky = SkyTableLoadOptimal (CATDIR, NULL, NULL, TRUE, -1, VERBOSE);
-  SkyTableSetFilenames (sky, CATDIR, "cpt");
 
   // determine the populated SkyRegions overlapping the requested area (default depth)
