Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/Makefile
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/Makefile	(revision 33403)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/Makefile	(revision 33404)
@@ -43,4 +43,5 @@
 $(SRC)/CopyToHostLocation.$(ARCH).o     \
 $(SRC)/CopyFromHostLocation.$(ARCH).o   \
+$(SRC)/FixSkyForHost.$(ARCH).o   \
 $(SRC)/PclientCommands.$(ARCH).o
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h	(revision 33403)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/include/dvodist.h	(revision 33404)
@@ -14,4 +14,5 @@
     MODE_OUT  = 1,
     MODE_IN   = 2,
+    MODE_FIX  = 3,
 } ModeType;
 
@@ -44,2 +45,4 @@
 int PclientResponse (HostInfo *host, char *response, IOBuffer *buffer);
 int PclientCommand (HostInfo *host, char *command, IOBuffer *buffer);
+
+int FixSkyForHost (char *catdir, SkyList *skylist, HostTable *table);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/FixSkyForHost.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/FixSkyForHost.c	(revision 33404)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/FixSkyForHost.c	(revision 33404)
@@ -0,0 +1,50 @@
+# include "dvodist.h"
+# define DEBUG 1
+
+// examine all of the filenames in the catdir directories and update the host table to note the correct locations
+int FixSkyForHost (char *catdir, SkyList *skylist, HostTable *table) {
+
+  int i, j;
+
+  for (i = 0; i < skylist->Nregions; i++) {
+    
+    struct stat filestat;
+
+    // filename of copy at CATDIR
+    char rawfile[1024];
+    snprintf (rawfile, 1024, "%s/%s.cpt", catdir, skylist[0].regions[i]->name);
+    
+    int status = stat (rawfile, &filestat);
+    if (status == -1) {
+      if (errno == ENOENT) continue;
+      fprintf (stderr, "failed to STAT file %s\n", rawfile);
+      continue;
+    }
+
+    if (!S_ISLNK(filestat.st_mode)) continue;
+
+    char linkfile[1024];
+    ssize_t Nbytes = readlink (rawfile, linkfile, 1024);
+    if  (Nbytes == -1) {
+      fprintf (stderr, "error reading link %s\n", rawfile);
+      continue;
+    }
+       
+    int found = FALSE;
+    for (j = 0; !found && (j < table->Nhosts); j++) {
+      if (strncmp (linkfile, table->hosts[j].pathname, strlen(table->hosts[j].pathname))) continue;
+      // found the host
+      HostInfo *host = &table->hosts[j];
+      skylist->regions[i]->hostID = host->hostID;
+      skylist->regions[i]->hostFlags |= DATA_ON_TGT;
+      found = TRUE;
+
+      if (DEBUG) fprintf (stderr, "found %s on %s\n", rawfile, host->hostname);
+    }  
+      
+    if (!found) {
+      fprintf (stderr, "failed to find host for %s (%s)\n", rawfile, linkfile);
+    }
+  }      
+  return (TRUE);
+}
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c	(revision 33403)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/dvodist.c	(revision 33404)
@@ -43,4 +43,7 @@
       CopyFromHostLocation (catdir, skylist, hosts);
       break;
+    case MODE_FIX:
+      FixSkyForHost (catdir, skylist, hosts);
+      break;
     default:
       fprintf (stderr, "impossible!");
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c	(revision 33403)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/initialize_dvodist.c	(revision 33404)
@@ -73,4 +73,12 @@
     remove_argument (N, &argc, argv);
   }
+  if ((N = get_argument (argc, argv, "-fix"))) {
+    if (MODE) {
+      fprintf (stderr, "ERROR: cannot use -fix with -in or -out options!\n");
+      usage();
+    }
+    MODE = MODE_FIX;
+    remove_argument (N, &argc, argv);
+  }
   if (!MODE) usage();
 
