Index: trunk/Ohana/src/uniphot/src/cam_zpt_correction.c
===================================================================
--- trunk/Ohana/src/uniphot/src/cam_zpt_correction.c	(revision 40487)
+++ trunk/Ohana/src/uniphot/src/cam_zpt_correction.c	(revision 40488)
@@ -100,9 +100,9 @@
     char field[256];
     double value;
-
+    
     snprintf (field, 256, "TS_%03d", i);
     if (!gfits_scan (phu, field, "%lf", 1, &value)) return FALSE;
     cam->tstart[i] = ohana_mjd_to_sec(value);
-
+    
     snprintf (field, 256, "TE_%03d", i);
     if (!gfits_scan (phu, field, "%lf", 1, &value)) return FALSE;
@@ -174,7 +174,8 @@
   if (!flat_id) return 0.0;
 
-  myAssert (flat_id > 0, "flat_id out of range");
-  myAssert (flat_id <= cam->Nvalues, "flat_id out of range");
-
+  //  myAssert (flat_id > 0, "flat_id out of range");
+  // myAssert (flat_id <= cam->Nvalues, "flat_id out of range");
+  if ((flat_id < 0)||(flat_id > cam->Nvalues)) { return 0.0; }
+  
   // validate the flat_id (not out of range?)
   // NOTE: we are setting the ID to be the sequence + 1 (match_camcorr_to_images.c:39)
@@ -285,4 +286,15 @@
   // table->offset[seq][ix][iy] with dM values for image[seq] 
 
+  // Set up HSC/GPC1 distinguishing limits
+
+  int minCodeGPC1 = 10000;
+  int maxCodeGPC1 = 10576;
+
+  int minCodeHSC  = 20000;
+  int maxCodeHSC  = 26111;
+
+  int isGPC1 = FALSE;
+  int isHSC  = FALSE;
+    
   // loop over the flatcorr images and match from image[seq] to newcorr:
   for (i = 0; i < flatcorr->Nimage; i++) {
@@ -301,8 +313,28 @@
     int photcode = flatcorr->image[i].photcode;
 
+    if ((photcode >= minCodeGPC1)&&(photcode <= maxCodeGPC1)) {
+      isGPC1 = TRUE;
+      isHSC  = FALSE;
+    }
+    else if ((photcode >= minCodeHSC)&&(photcode <= maxCodeHSC)) {
+      isGPC1 = FALSE;
+      isHSC  = TRUE;
+    }
+    if (!(isGPC1) && !(isHSC)) { continue; }
+
+    int iy, ix, filter;
+
+    
     // find the chip and filter from photcode:
-    int iy = photcode % 10;
-    int ix = (int)(photcode / 10) % 10;
-    int filter = (int)(photcode / 100) % 10;
+    if (isGPC1) {
+      iy = photcode % 10;
+      ix = (int)(photcode / 10) % 10;
+      filter = (int)(photcode / 100) % 10;
+    }
+    else if (isHSC) {
+      iy = 0;
+      ix = (int) photcode % 112;
+      filter = (int)(photcode / 1000) % 10;
+    }
 	      
     myAssert (ix     < newcorr->Nx, "oops");
Index: trunk/Ohana/src/uniphot/src/initialize_setphot.c
===================================================================
--- trunk/Ohana/src/uniphot/src/initialize_setphot.c	(revision 40487)
+++ trunk/Ohana/src/uniphot/src/initialize_setphot.c	(revision 40488)
@@ -217,5 +217,5 @@
   
 
-  if (argc != 2) {
+  if (argc > 2) {
     fprintf (stderr, "USAGE: setphot (zptfile) [options]\n");
     fprintf (stderr, "  options:\n");
Index: trunk/Ohana/src/uniphot/src/match_camcorr_to_images.c
===================================================================
--- trunk/Ohana/src/uniphot/src/match_camcorr_to_images.c	(revision 40487)
+++ trunk/Ohana/src/uniphot/src/match_camcorr_to_images.c	(revision 40488)
@@ -14,15 +14,29 @@
   // season comes from the date/time
 
-  int minCode = 10000;
-  int maxCode = 10576;
+  int minCodeGPC1 = 10000;
+  int maxCodeGPC1 = 10576;
+
+  int minCodeHSC  = 20000;
+  int maxCodeHSC  = 26111;
 
   int Nmissed = 0;
+
+  int isGPC1 = FALSE;
+  int isHSC  = FALSE;
   
   for (i = 0; i < Nimage; i++) {
     if (!image[i].photcode) continue; // skip PHU images
 
-    if (image[i].photcode < minCode) continue; // skip non-gpc1-chip images
-    if (image[i].photcode > maxCode) continue; // skip non-gpc1-chip images
+    if ((image[i].photcode >= minCodeGPC1)&&(image[i].photcode <= maxCodeGPC1)) {
+      isGPC1 = TRUE;
+      isHSC  = FALSE;
+    }
+    else if ((image[i].photcode >= minCodeHSC)&&(image[i].photcode <= maxCodeHSC)) {
+      isGPC1 = FALSE;
+      isHSC  = TRUE;
+    }
 
+    if (!(isGPC1) && !(isHSC)) { continue; }
+    
     int found = FALSE;
     for (j = 0; !found && (j < camcorr->Nseason); j++) {
@@ -30,11 +44,22 @@
       if (image[i].tzero > camcorr->tstop[j]) continue;
 
+      int seq;
       int photcode = image[i].photcode;
-      int iy =  photcode % 10;
-      int ix = (int)(photcode / 10) % 10;
-      int filter = (int)(photcode / 100) % 10;
+
+      if (isGPC1) { 
+	int iy =  photcode % 10;
+	int ix = (int)(photcode / 10) % 10;
+	int filter = (int)(photcode / 100) % 10;
+
+	seq = ix + iy * camcorr->Nx + filter * camcorr->Nchips + j * camcorr->Nflats;
+      }
+      else if (isHSC) {
+	int filter = (int)(photcode / 1000) % 10;
+	int ix = photcode - 20000 - filter * 1000;
+	
+	seq = ix + filter * camcorr->Nchips + j * camcorr->Nflats;
+      }
 
       // we add one so photom_map_id = 0 can mean no map
-      int seq = ix + iy * camcorr->Nx + filter * camcorr->Nchips + j * camcorr->Nflats;
       image[i].photom_map_id = seq + 1;
       found = TRUE;
Index: trunk/Ohana/src/uniphot/src/setphot.c
===================================================================
--- trunk/Ohana/src/uniphot/src/setphot.c	(revision 40487)
+++ trunk/Ohana/src/uniphot/src/setphot.c	(revision 40488)
@@ -21,4 +21,7 @@
   if (db.dbstate == LCK_EMPTY) Shutdown ("ERROR: No images in catalog %s (1)", db.filename);
 
+  fprintf (stderr, "this program needs to be fixed to allow a zpt lookup table\n");
+  exit (3);
+
   if (UBERCAL) {
     zpts = load_zpt_ubercal (argv[1], &Nzpts, &flatcorrTable);
@@ -37,5 +40,5 @@
     }
     camcorr = merge_flatcorr_and_camcorr (&flatcorrTable, rawcorr);
-
+    
     char newflatfile[DVO_MAX_PATH];
     size = snprintf (newflatfile, DVO_MAX_PATH, "%s/flatfield.fits", CATDIR);
@@ -43,8 +46,24 @@
     CamPhotomCorrectionSave (camcorr, newflatfile);
   } else {
-    zpts = load_zpt_table (argv[1], &Nzpts);
+    //    zpts = load_zpt_table (argv[1], &Nzpts);
   }
 
-  if (!zpts) Shutdown ("failed to load zero points, or empty table");
+  if ((CAM_PHOTOM_FILE)&&(!camcorr)) {
+    CamPhotomCorrection *rawcorr = CamPhotomCorrectionLoad(CAM_PHOTOM_FILE);
+    if (!rawcorr) {
+      fprintf (stderr, "failed to load camera-static flat-field correction\n");
+      exit (2);
+    }
+    camcorr = rawcorr;
+    char newflatfile[DVO_MAX_PATH];
+    int size = snprintf (newflatfile, DVO_MAX_PATH, "%s/flatfield.fits", CATDIR);
+    assert (size < DVO_MAX_PATH);
+    CamPhotomCorrectionSave (camcorr, newflatfile);
+
+    //    zpts = load_zpt_table (argv[1], &Nzpts);
+  }    
+
+  
+  //  if (!zpts) Shutdown ("failed to load zero points, or empty table");
 
   // load images 
@@ -52,11 +71,11 @@
   if (!UPDATE) dvo_image_unlock (&db); 
   
-  match_zpts_to_images (image, Nimage, zpts, Nzpts);
+  //  match_zpts_to_images (image, Nimage, zpts, Nzpts);
 
-  if (UBERCAL) {
+  //  if (UBERCAL) {
     // we are going to deprecate the flatcorr imaage lookup
     // match_flatcorr_to_images (image, Nimage, &flatcorrTable);
-    match_camcorr_to_images (image, Nimage, camcorr);
-  } 
+  match_camcorr_to_images (image, Nimage, camcorr);
+    //  } 
 
   if (!IMAGES_ONLY) {
