Index: /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/include/dvo.h	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/include/dvo.h	(revision 36520)
@@ -291,17 +291,24 @@
   double Dmin;
   double Dmax;
+
+  char *hostname;
+
   int hostID;		      // remove machine ID in SkyTable
   int stdio[3]; 	      // fd's for communication with the remote host
   int pid;		      // remote process ID
-  char *hostname;
-
-  int line_numbers;
+  int status;
 
   off_t Nimage;
   off_t NIMAGE;
   Image *image;
+  int line_numbers;
 } RegionHostInfo;
 
 typedef struct {
+  double Rmin;
+  double Rmax;
+  double Dmin;
+  double Dmax;
+
   int Nhosts;
   RegionHostInfo *hosts;
@@ -849,4 +856,5 @@
 void FreeRegionHostTable (RegionHostTable *table);
 RegionHostTable *RegionHostTableLoad (char *catdir, char *rootname);
+int RegionHostTableWaitJobs (RegionHostTable *regionHosts, char *file, int lineno);
 
 # endif // DVO_H
Index: /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/RegionHostTable.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/RegionHostTable.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/RegionHostTable.c	(revision 36520)
@@ -72,4 +72,11 @@
   int maxID = 0;
 
+  RegionHostTable *table = NULL;
+  ALLOCATE (table, RegionHostTable, 1);
+  table->Rmin = 360;
+  table->Rmax =   0;
+  table->Dmin = +90;
+  table->Dmax = -90;
+
   for (Nline = 0; TRUE; Nline ++) {
     int ID;
@@ -85,9 +92,4 @@
     if (line[i] == '#') continue;
     if (line[i] == 0) continue;
-
-    UserPatch.Rmin = 360;
-    UserPatch.Rmax =   0;
-    UserPatch.Dmin = +90;
-    UserPatch.Dmax = -90;
 
     double Rmin, Rmax, Dmin, Dmax;
@@ -121,8 +123,8 @@
     hosts[Nhosts].Dmax = Dmax;
     
-    UserPatch.Rmin = MIN(Rmin, UserPatch.Rmin);
-    UserPatch.Rmax = MIN(Rmax, UserPatch.Rmax);
-    UserPatch.Dmin = MIN(Dmin, UserPatch.Dmin);
-    UserPatch.Dmax = MIN(Dmax, UserPatch.Dmax);
+    table->Rmin = MIN(Rmin, table->Rmin);
+    table->Rmax = MIN(Rmax, table->Rmax);
+    table->Dmin = MIN(Dmin, table->Dmin);
+    table->Dmax = MIN(Dmax, table->Dmax);
 
     // InitIOBuffer (&hosts[Nhosts].stdout, 1000);
@@ -137,6 +139,4 @@
   }    
 
-  RegionHostTable *table = NULL;
-  ALLOCATE (table, RegionHostTable, 1);
   table->Nhosts = Nhosts;
   table->hosts = hosts;
Index: /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/dvo_photcode_ops.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/libdvo/src/dvo_photcode_ops.c	(revision 36520)
@@ -169,4 +169,5 @@
 }
 
+// returns Nsec if code is PRI/SEC, else -1
 int GetPhotcodeNsec (int code) {
   
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/include/relphot.h	(revision 36520)
@@ -118,4 +118,5 @@
   unsigned int objID;
   unsigned int catID;
+  int photcode;
 } MeanMag;
 
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MeanMagIO.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MeanMagIO.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/MeanMagIO.c	(revision 36520)
@@ -67,10 +67,10 @@
   ALLOCATE (meanmags, MeanMag, Nrow);
   for (i = 0; i < Nrow; i++) {
-    meanman[i].M              = M    [i];
-    meanman[i].dM             = dM   [i];
-    meanman[i].Xm             = Xm   [i];
-    meanman[i].Nsec           = Nsec [i];
-    meanman[i].objID          = objID[i];
-    meanman[i].catID          = catID[i];
+    meanmags[i].M              = M    [i];
+    meanmags[i].dM             = dM   [i];
+    meanmags[i].Xm             = Xm   [i];
+    meanmags[i].Nsec           = Nsec [i];
+    meanmags[i].objID          = objID[i];
+    meanmags[i].catID          = catID[i];
   }
   fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
@@ -83,6 +83,6 @@
   free (catID);
 
-  *nmeanmag = Nrow;
-  return meanman;
+  *nmeanmags = Nrow;
+  return meanmags;
 }
 
@@ -133,10 +133,10 @@
   // assign the storage arrays
   for (i = 0; i < Nmeanmags; i++) {
-    M    [i]   = meanmag[i].M    ;
-    dM   [i]   = meanmag[i].dM   ;
-    Xm   [i]   = meanmag[i].Xm   ;
-    Nsec [i]   = meanmag[i].Nsec ;
-    objID[i]   = meanmag[i].objID;
-    catID[i]   = meanmag[i].catID;
+    M    [i]   = meanmags[i].M    ;
+    dM   [i]   = meanmags[i].dM   ;
+    Xm   [i]   = meanmags[i].Xm   ;
+    Nsec [i]   = meanmags[i].Nsec ;
+    objID[i]   = meanmags[i].objID;
+    catID[i]   = meanmags[i].catID;
   }
 
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/assign_images.c	(revision 36520)
@@ -36,5 +36,6 @@
 int select_images_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage) {
 
-  int i, j, ecode, found;
+  int ecode, found;
+  off_t i, j;
 
   // INITTIME;
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/indexCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/indexCatalog.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/indexCatalog.c	(revision 36520)
@@ -8,4 +8,8 @@
   // find the max value of catID
   int catIDmax = 0;
+
+  int i;
+  off_t j;
+
   for (i = 0; i < Ncatalog; i++) {
     catIDmax = MAX (catalog[i].catID, catIDmax);
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_regions.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_regions.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/relphot_parallel_regions.c	(revision 36520)
@@ -10,4 +10,7 @@
   INITTIME;
 
+  // load the RegionTable (UserRegion should not be used at this level)
+  RegionHostTable *regionHosts = RegionHostTableLoad (CATDIR, REGION_FILE);
+
   // load the flat correction table (if defined)
   char flatcorrfile[256];
@@ -17,8 +20,5 @@
   SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
   SkyTableSetFilenames (sky, CATDIR, "cpt");
-  SkyList *skylist = SkyListByBounds (sky, -1, UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
-
-  // load the RegionTable (UserRegion should not be used at this level)
-  RegionHostTable *regionHosts = RegionHostTableLoad (CATDIR, REGION_FILE);
+  SkyList *skylist = SkyListByBounds (sky, -1, regionHosts->Rmin, regionHosts->Rmax, regionHosts->Dmin, regionHosts->Dmax);
 
   /* register database handle with shutdown procedure */
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_image_mags.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_image_mags.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_image_mags.c	(revision 36520)
@@ -48,5 +48,5 @@
 
   for (i = 0; i < regionHosts->Nhosts; i++) {
-    if (regionHosts->hosts.hostsID == REGION_HOST_ID) continue;
+    if (regionHosts->hosts[i].hostID == REGION_HOST_ID) continue;
     // XXX add neighbor check? : if (not_neighbor(host[i])) continue;
 
@@ -57,5 +57,5 @@
 
     off_t Nsubset;
-    ImageMag *image_mags_subset = ImageMagLoad (regionHosts->hosts[i], &Nsubset);
+    ImageMag *image_mags_subset = ImageMagLoad (regionHosts->hosts[i].hostname, &Nsubset);
 
     image_mags = merge_image_mags (image_mags, &Nimage_mags, image_mags_subset, Nsubset);
@@ -63,17 +63,18 @@
 
   for (i = 0; i < Nimage_mags; i++) {
-    off_t seq = getImageByID (image_mags[i].ID);
+    off_t seq = getImageByID (image_mags[i].imageID);
     if (seq < 0) {
       // XXX is this a problem? (no, other hosts don't know which images I own)
       continue;
     }
-    images[seq].Mcal  	   = image_mags[i].Mcal;
-    images[seq].dMcal  	   = image_mags[i].dMcal;
-    images[seq].dMagSys	   = image_mags[i].dMagSys;
-    images[seq].Xm  	   = image_mags[i].Xm;
+    images[seq].Mcal  	    = image_mags[i].Mcal;
+    images[seq].dMcal  	    = image_mags[i].dMcal;
+    images[seq].dMagSys	    = image_mags[i].dMagSys;
+    images[seq].Xm  	    = image_mags[i].Xm;
     images[seq].nFitPhotom  = image_mags[i].nFitPhotom;
-    images[seq].flags 	   = image_mags[i].flags;
+    images[seq].flags 	    = image_mags[i].flags;
     images[seq].ubercalDist = image_mags[i].ubercalDist;
   }
+  return TRUE;
 }
 
@@ -90,5 +91,5 @@
   while (TRUE) {
 
-    f = fopen (filename);
+    f = fopen (filename, "r");
     if (!f) {
       usleep (2000000);
@@ -106,5 +107,5 @@
     // message is of the form: NLOOP: %03d
     int loop;
-    sscanf (message, "%s %d", &loop);
+    sscanf (message, "%*s %d", &loop);
     if (loop != nloop) {
       usleep (2000000);
@@ -113,4 +114,5 @@
     return TRUE;
   }
+  return FALSE;
 }
 
@@ -147,8 +149,11 @@
 int set_image_mags (ImageMag *image_mags, Image *image) {
 
-  fprintf (stderr, "ERROR: need to fix this function\n");
-  exit (2);
-
-  image_mags->Mcal  = image->Mcal;
+  image_mags->Mcal  	  = image->Mcal;
+  image_mags->dMcal  	  = image->dMcal;
+  image_mags->dMagSys	  = image->dMagSys;
+  image_mags->Xm  	  = image->Xm;
+  image_mags->nFitPhotom  = image->nFitPhotom;
+  image_mags->flags 	  = image->flags;
+  image_mags->ubercalDist = image->ubercalDist;
 
   return TRUE;
Index: /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_mean_mags.c
===================================================================
--- /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_mean_mags.c	(revision 36519)
+++ /branches/eam_branches/ipp-20140206/Ohana/src/relphot/src/share_mean_mags.c	(revision 36520)
@@ -94,6 +94,10 @@
     }
 
-    int Nsec = photcode_to_secfilt (meanmags[i].photcode);
-    catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].mag = meanmags[i].mag;
+    int ecode = GetPhotcodeEquivCodebyCode (meanmags[i].photcode);
+    if (ecode < 0) continue;
+    int Nsec = GetPhotcodeNsec (ecode);
+    if (Nsec < 0) continue;
+
+    catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].M = meanmags[i].M;
   }
   return TRUE;
@@ -130,5 +134,5 @@
     // message is of the form: NLOOP: %03d
     int loop;
-    sscanf (message, "%s %d", &loop);
+    sscanf (message, "%*s %d", &loop);
     if (loop != nloop) {
       usleep (2000000);
