Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/include/dvo.h	(revision 33475)
@@ -242,4 +242,10 @@
 } SkyTableDataFlags;
 
+typedef enum {
+  HOST_STDIN = 0,
+  HOST_STDOUT = 1,
+  HOST_STDERR = 2,
+} HostInfoIOfd;
+
 typedef struct {
   char *hostname;	      // name of remote machine
@@ -249,4 +255,6 @@
   int pid;		      // remote process ID
   int status;		      // job exit status
+  IOBuffer stdout;
+  IOBuffer stderr;
 } HostInfo;
 
@@ -614,4 +622,5 @@
 HostTable    *HostTableLoad (char *catdir, char *rootname);
 int HostTableWaitJobs (HostTable *table, char *file, int lineno);
+int HostTableWaitJobsGetIO (HostTable *table, char *file, int lineno);
 
 // functions to support tiny versions of Average and Measure
Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c	(revision 33475)
@@ -9,7 +9,7 @@
     hosts[i].hostname = NULL;
     hosts[i].pathname = NULL;
-    hosts[i].stdio[0] = -1;
-    hosts[i].stdio[1] = -1;
-    hosts[i].stdio[2] = -1;
+    hosts[i].stdio[HOST_STDIN] = -1;
+    hosts[i].stdio[HOST_STDOUT] = -1;
+    hosts[i].stdio[HOST_STDERR] = -1;
     hosts[i].pid = 0;
   }
@@ -91,4 +91,7 @@
     hosts[Nhosts].pathname = strcreate(tmppath);
     
+    InitIOBuffer (&hosts[Nhosts].stdout, 1000);
+    InitIOBuffer (&hosts[Nhosts].stderr, 1000);
+
     Nhosts ++;
     if (Nhosts >= NHOSTS) {
@@ -146,4 +149,6 @@
       }
     }
+
+    // when the host has finished, close the open sockets
 
     // find the host which has finished
@@ -158,5 +163,5 @@
       IOBuffer buffer;
       InitIOBuffer (&buffer, 100);
-      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[1]);
+      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[HOST_STDOUT]);
       fprintf (stderr, "--- stdout from %s ---\n", table->hosts[j].hostname);
       write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
@@ -164,5 +169,5 @@
 	  
       InitIOBuffer (&buffer, 100);
-      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[2]);
+      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[HOST_STDERR]);
       fprintf (stderr, "--- stderr from %s ---\n", table->hosts[j].hostname);
       write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
@@ -192,6 +197,4 @@
 int HostTableWaitJobsGetIO (HostTable *table, char *file, int lineno) {
 
-  int i;
-
   // we have launched table->Nhosts jobs; wait for all of them to complete...
   // if one (N) failed to launch, we will get an ECHILD error from the last (N) calls
@@ -201,66 +204,128 @@
   // timeouts for both
 
+  // add all hosts' sockets to the fd_sets
+  fd_set rdSet, wtSet;
+  FD_ZERO (&rdSet);
+  FD_ZERO (&wtSet);
+
+  // XXX can I set the fd_sets once, since I am not actually closing the fd's?
+
+  int i;
+  int Nmax = 0;
+  for (i = 0; i < table->Nhosts; i++) {
+    FD_SET (table->hosts[i].stdio[HOST_STDIN], &wtSet);
+    Nmax = MAX (Nmax, table->hosts[i].stdio[HOST_STDIN]);
+    FD_SET (table->hosts[i].stdio[HOST_STDOUT], &rdSet);
+    Nmax = MAX (Nmax, table->hosts[i].stdio[HOST_STDOUT]);
+    FD_SET (table->hosts[i].stdio[HOST_STDERR], &rdSet);
+    Nmax = MAX (Nmax, table->hosts[i].stdio[HOST_STDERR]);
+  }    
+  Nmax ++;
+
+  int Nfound = 0;
+
+  // this loop has 2 chunks: (a) check for I/O + (b) check for jobs done
   while (1) {
 
-    // is anyone done?
-    int status = 0;
-
-    // XXX we'll need to pass in WNOHANG and keep retrying if we want to have a timeout...
-    int pid = waitpid (-1, &status, WNOHANG);
-    if (pid) {
-      if (pid == -1) {
-	switch (errno) {
-	  case ECHILD:
-	    done = TRUE;
-	    // no more children, need to exit ...
-	    break;
-	  default:
-	    fprintf (stderr, "programming error (2)? %s %d", file, lineno);
-	    exit (2);
+    // Wait up to 0.5 second for host to provide I/O
+    // timeout gets mucked: need to reset before each select
+    struct timeval timeout;
+    timeout.tv_sec = 10;
+    timeout.tv_usec = 500000;
+
+    int status = select (Nmax, &rdSet, &wtSet, NULL, &timeout);
+    if (status == -1) {
+      perror("select()");
+      exit (2);
+    }
+
+    // we have some sockets to check, check sockets for all hosts
+    for (i = 0; (status > 0) && (i < table->Nhosts); i++) {
+      if (FALSE && FD_ISSET (table->hosts[i].stdio[HOST_STDIN], &wtSet)) {
+	// this host is waiting for input : this is an error, so exit
+	fprintf (stderr, "host %s is waiting for input\n", table->hosts[i].hostname);
+	abort();
+      }
+      
+      if (FD_ISSET (table->hosts[i].stdio[HOST_STDOUT], &rdSet)) {
+	// this host has waiting output : read to buffer, and dump if necessary
+	ReadtoIOBuffer (&table->hosts[i].stdout, table->hosts[i].stdio[HOST_STDOUT]);
+	if (table->hosts[i].stdout.Nbuffer > 0x10000) {
+	  fprintf (stdout, "--- stdout from %s ---\n", table->hosts[i].hostname);
+	  write (STDOUT_FILENO, table->hosts[i].stdout.buffer, table->hosts[i].stdout.Nbuffer);
+	  fprintf (stdout, "\n");
 	}
-      } else {
-	// handle
-      
-
-
-    // find the host which has finished
-    int j;
-    int found = FALSE;
-    for (j = 0; j < table->Nhosts; j++) {
-      if (table->hosts[j].pid != pid) continue;
-      found = TRUE;
-      // check on the status of this and report any output?
-      fprintf (stderr, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
-      // read the stderr and stdout
-      IOBuffer buffer;
-      InitIOBuffer (&buffer, 100);
-      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[1]);
-      fprintf (stderr, "--- stdout from %s ---\n", table->hosts[j].hostname);
-      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
-      fprintf (stderr, "\n");
-	  
-      InitIOBuffer (&buffer, 100);
-      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[2]);
-      fprintf (stderr, "--- stderr from %s ---\n", table->hosts[j].hostname);
-      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
-      fprintf (stderr, "\n");
-      if (WIFEXITED(status)) {
-	fprintf (stderr, "normal completion, exit status is %d\n", WEXITSTATUS(status));
-	table->hosts[j].status = WEXITSTATUS(status);
-	if (table->hosts[j].status) {
-	  fprintf (stderr, "job failed on %s\n", table->hosts[j].hostname);
+      }
+
+      if (FD_ISSET (table->hosts[i].stdio[HOST_STDERR], &rdSet)) {
+	// this host has waiting output : read to buffer, and dump if necessary
+	ReadtoIOBuffer (&table->hosts[i].stderr, table->hosts[i].stdio[HOST_STDERR]);
+	if (table->hosts[i].stderr.Nbuffer > 0x10000) {
+	  fprintf (stdout, "--- stderr from %s ---\n", table->hosts[i].hostname);
+	  write (STDOUT_FILENO, table->hosts[i].stderr.buffer, table->hosts[i].stderr.Nbuffer);
+	  fprintf (stdout, "\n");
+	}
+      }
+    }
+
+    // now check if any children have finished...
+    while (TRUE) {
+      int status = 0;
+      int pid = waitpid (-1, &status, WNOHANG);
+      if (!pid) {
+	break; // no outstanding jobs have finished 
+	fprintf (stderr, "no hosts to harvest\n");
+	usleep (500000);
+      }
+      if ((pid == -1) && (errno == ECHILD)) goto escape; // no more jobs on which to wait
+      if ((pid == -1) && (errno != ECHILD)) {
+	fprintf (stderr, "programming error (2)? %s %d", file, lineno);
+	exit (2);
+      }
+
+      // find the host which has finished
+      int j;
+      int found = FALSE;
+      for (j = 0; (j < table->Nhosts) && !found; j++) {
+	if (table->hosts[j].pid != pid) continue;
+	found = TRUE;
+
+	// check on the status of this and report any output?
+	fprintf (stdout, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
+
+	// read stdout
+	EmptyIOBuffer (&table->hosts[j].stdout, 100, table->hosts[j].stdio[HOST_STDOUT]);
+	fprintf (stdout, "--- stdout from %s ---\n", table->hosts[j].hostname);
+	write (STDOUT_FILENO, table->hosts[j].stdout.buffer, table->hosts[j].stdout.Nbuffer);
+	fprintf (stdout, "\n");
+	    
+	// read stderr
+	EmptyIOBuffer (&table->hosts[j].stderr, 100, table->hosts[j].stdio[HOST_STDERR]);
+	fprintf (stdout, "--- stderr from %s ---\n", table->hosts[j].hostname);
+	write (STDOUT_FILENO, table->hosts[j].stderr.buffer, table->hosts[j].stderr.Nbuffer);
+	fprintf (stdout, "\n");
+
+	if (WIFEXITED(status)) {
+	  fprintf (stdout, "normal completion, exit status is %d\n", WEXITSTATUS(status));
+	  table->hosts[j].status = WEXITSTATUS(status);
+	  if (table->hosts[j].status) {
+	    fprintf (stdout, "job failed on %s\n", table->hosts[j].hostname);
+	  }
+	} else {
+	  table->hosts[j].status = -1;
+	  fprintf (stdout, "job exited abnormally on %s\n", table->hosts[j].hostname);
 	  continue;
 	}
-      } else {
-	table->hosts[j].status = -1;
-	fprintf (stderr, "job exited abnormally on %s\n", table->hosts[j].hostname);
-	continue;
-      }
-    }
-    if (!found) {
-      fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
-      exit (2);
-    }
-  }
+      }
+      if (!found) {
+	fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
+	exit (2);
+      }
+      Nfound ++;
+      if (Nfound == table->Nhosts) goto escape; // we've harvested all jobs
+    }
+  }
+
+escape:
   return TRUE;
 }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/Makefile	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/Makefile	(revision 33475)
@@ -71,6 +71,6 @@
 #$(SRC)/write_coords.$(ARCH).o        \
 
-$(RELASTRO): $(INC)/relastro.h $(KAPA_INCS)
-$(BIN)/relastro.$(ARCH): $(RELASTRO) $(KAPA_LIBS)
+$(RELASTRO): $(INC)/relastro.h
+$(BIN)/relastro.$(ARCH): $(RELASTRO)
 
 RELASTRO_CLIENT = \
@@ -122,6 +122,6 @@
 #$(SRC)/StarMaps.$(ARCH).o    \
 
-$(RELASTRO_CLIENT): $(INC)/relastro.h $(KAPA_INCS)
-$(BIN)/relastro_client.$(ARCH): $(RELASTRO_CLIENT) $(KAPA_LIBS)
+$(RELASTRO_CLIENT): $(INC)/relastro.h
+$(BIN)/relastro_client.$(ARCH): $(RELASTRO_CLIENT)
 
 testparallax: $(BIN)/testparallax.$(ARCH)
@@ -134,4 +134,4 @@
 $(SRC)/testparallax.$(ARCH).o
 
-$(TESTPAR): $(INC)/relastro.h $(KAPA_INCS)
-$(BIN)/testparallax.$(ARCH): $(TESTPAR) $(KAPA_LIBS)
+$(TESTPAR): $(INC)/relastro.h
+$(BIN)/testparallax.$(ARCH): $(TESTPAR)
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/include/relastro.h	(revision 33475)
@@ -418,2 +418,4 @@
 int BrightCatalogSplit (CatalogSplitter *catalogs, BrightCatalog *bcatalog);
 int BrightCatalogSplitFree (CatalogSplitter *catalogs);
+
+PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/high_speed_catalogs.c	(revision 33475)
@@ -161,5 +161,5 @@
   }
   if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
-    HostTableWaitJobs (table, __FILE__, __LINE__);
+    HostTableWaitJobsGetIO (table, __FILE__, __LINE__);
   }
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/initialize.c	(revision 33474)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relastro/src/initialize.c	(revision 33475)
@@ -2,9 +2,4 @@
 
 void initialize (int argc, char **argv) {
-
-  int NPHOTCODES;
-  char *codename, *ptr, *list;
-
-  ptr = NULL;
 
   ConfigInit (&argc, argv);
@@ -48,9 +43,4 @@
 void initialize_client (int argc, char **argv) {
 
-  int NPHOTCODES;
-  char *codename, *ptr, *list;
-
-  ptr = NULL;
-
   ConfigInit (&argc, argv);
   args_client (argc, argv);
@@ -73,12 +63,12 @@
 }
 
-PhotCode *ParsePhotcodeList (char *rawlist, int *nphotcodes) {
+PhotCode **ParsePhotcodeList (char *rawlist, int *nphotcodes) {
 
   *nphotcodes = 0;
   if (!rawlist) return NULL;
 
-  Nphotcodes = 0;
-  photcodes = NULL;
+  int Nphotcodes = 0;
   int NPHOTCODES = 10;
+  PhotCode **photcodes = NULL;
   ALLOCATE (photcodes, PhotCode *, NPHOTCODES);
 
