Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/BrightCatalog.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/BrightCatalog.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/BrightCatalog.c	(revision 33270)
@@ -474,14 +474,19 @@
   }
     
+  // XXX this prevents different catalogs from having different Nsecfilt values
+  int Nsecfilt = GetPhotcodeNsecfilt();
+
   ALLOCATE (bcatalog[0].measure, MeasureTiny, Nmeas);
   ALLOCATE (bcatalog[0].average, AverageTiny, Naves);
+  ALLOCATE (bcatalog[0].secfilt, SecFilt, Naves*Nsecfilt);
 
   int Nm = 0;
   int Na = 0;
   for (i = 0; i < Ncatalog; i++) {
+    if (!catalog[i].Naverage) continue;
     for (j = 0; j < catalog[i].Naverage; j++) {
-      CopyAverageTiny (&bcatalog[0].average[Na], &catalog[i].average[j]);
+      // CopyAverageTiny (&bcatalog[0].average[Na], &catalog[i].average[j]);
+      bcatalog[0].average[Na] = catalog[i].averageT[j];
       bcatalog[0].average[Na].catID = catalog[i].catID;
-      int Nsecfilt = catalog[i].Nsecfilt;
       for (k = 0; k < Nsecfilt; k++) {
 	bcatalog[0].secfilt[Nsecfilt*Na + k] = catalog[i].secfilt[Nsecfilt*j + k];
@@ -491,5 +496,6 @@
     }
     for (j = 0; j < catalog[i].Nmeasure; j++) {
-      CopyMeasureTiny (&bcatalog[0].measure[Nm], &catalog[i].measure[j]);
+      // CopyMeasureTiny (&bcatalog[0].measure[Nm], &catalog[i].measure[j]);
+      bcatalog[0].measure[Nm] = catalog[i].measureT[j];
       bcatalog[0].measure[Nm].catID = catalog[i].catID;
       Nm++;
@@ -497,4 +503,6 @@
     }
   }
+  bcatalog->Naverage = Na;
+  bcatalog->Nmeasure = Nm;
   return bcatalog;
 }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/Shutdown.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/Shutdown.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/Shutdown.c	(revision 33270)
@@ -1,5 +1,5 @@
 # include "relphot.h"
 
-static FITS_DB *db;
+static FITS_DB *db = NULL;
 
 void set_db (FITS_DB *in) {
@@ -22,5 +22,5 @@
 
   SetProtect (TRUE);
-  gfits_db_close (db);
+  if (db) gfits_db_close (db);
   fprintf (stderr, "ERROR: addstar halted\n");
   exit (1);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/args.c	(revision 33270)
@@ -291,11 +291,11 @@
   if (!HOSTDIR) relphot_client_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]) relphot_client_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]) relphot_client_usage();
 
   IMAGES = NULL; // used in -update mode
@@ -320,5 +320,24 @@
   if (!MODE) relphot_client_usage();
 
-  if (argc != 1) relphot_client_usage ();
+  /* specify portion of the sky */
+  UserPatch.Rmin = 0;
+  UserPatch.Rmax = 360;
+  UserPatch.Dmin = -90;
+  UserPatch.Dmax = +90;
+  UserPatchSelect = FALSE;
+  if ((N = get_argument (argc, argv, "-region"))) {
+    remove_argument (N, &argc, argv);
+    UserPatch.Rmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Rmax = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmax = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatchSelect = TRUE;
+  }
+
+  if (argc != 2) relphot_client_usage ();
 
   return TRUE;
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/help.c	(revision 33270)
@@ -45,6 +45,6 @@
 
 void relphot_client_usage (void) {
-  fprintf (stderr, "ERROR: USAGE: relphot -load -bcatalog (filename) -hostID (hostID) -hostdir (hostdir) -catdir (catdir)\n");
-  fprintf (stderr, "       or:    relphot -update -images (filename) -hostID (hostID) -hostdir (hostdir) -catdir (catdir)\n");
+  fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -load (filename) -hostID (hostID) -hostdir (hostdir) [options]\n");
+  fprintf (stderr, "       or:    relphot -update (filename) -hostID (hostID) -hostdir (hostdir) [options]\n");
   fprintf (stderr, "  use -h for more usage information\n");
   exit (2);
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/initialize.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/initialize.c	(revision 33270)
@@ -1,3 +1,32 @@
 # include "relphot.h"
+
+void ParsePhotcodeList (char *word) {
+
+  Nphotcodes = 0;
+  photcodes = NULL;
+  int NPHOTCODES = 10;
+  ALLOCATE (photcodes, PhotCode *, NPHOTCODES);
+
+  /* parse the comma-separated list of photcodesKeep */
+  char *myList = strcreate(word);
+  char *list = myList;
+  char *codename = NULL;
+  char *ptr = NULL;
+  while ((codename = strtok_r (list, ",", &ptr)) != NULL) {
+    list = NULL; // pass NULL on successive strtok_r calls
+    fprintf (stderr, "PHOTCODE LIST: %s\n", myList);
+    fprintf (stderr, "codename: %s\n", codename);
+    if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) {
+      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
+      exit (1);
+    }
+    if (photcodes[Nphotcodes][0].type != PHOT_SEC) {
+      fprintf (stderr, "photcode %s is not an filter type (SEC)\n", codename);
+      exit (1);
+    }
+    Nphotcodes ++;
+    CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10);
+  }
+}
 
 void initialize (int argc, char **argv) {
@@ -27,29 +56,6 @@
 # endif
 
-    Nphotcodes = 0;
-    photcodes = NULL;
-    int NPHOTCODES = 10;
-    ALLOCATE (photcodes, PhotCode *, NPHOTCODES);
-
-    /* parse the comma-separated list of photcodesKeep */
-    char *myList = strcreate(argv[N]);
-    char *list = myList;
-    char *codename = NULL;
-    char *ptr = NULL;
-    while ((codename = strtok_r (list, ",", &ptr)) != NULL) {
-      list = NULL; // pass NULL on successive strtok_r calls
-      fprintf (stderr, "PHOTCODE LIST: %s\n", myList);
-      fprintf (stderr, "codename: %s\n", codename);
-      if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) {
-        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
-        exit (1);
-      }
-      if (photcodes[Nphotcodes][0].type != PHOT_SEC) {
-	  fprintf (stderr, "photcode %s is not an filter type (SEC)\n", codename);
-	  exit (1);
-      }
-      Nphotcodes ++;
-      CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10);
-    }
+    // load the list of photcodes into the globals (photcodes, Nphotcodes)
+    ParsePhotcodeList (argv[N]);
   }
   // XXX DEP PhotNsec = GetPhotcodeNsecfilt ();
@@ -99,5 +105,8 @@
 
   relphot_client_help (argc, argv);
-  // ConfigInit (&argc, argv); XXX not sure if we need anything in here (maybe photcode table)
+  ConfigInit (&argc, argv);
   args_client (argc, argv);
+
+  // load the list of photcodes into the globals (photcodes, Nphotcodes)
+  ParsePhotcodeList (argv[1]);
 }
Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c	(revision 33269)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/relphot.c	(revision 33270)
@@ -58,4 +58,5 @@
   // XXX need to reduce number of global variables in use.
   // XXX this is fairly lame: argv[1] is photcode if UserPatchSelect is true
+  // XXX clean this up: deprecate region-name here (can be optional if desired)
   skylist = load_images (&db, argv[1], &UserPatch, UserPatchSelect);
   MARKTIME("-- load images: %f sec\n", dtime);
