Index: trunk/Ohana/src/relastro/include/relastro.h
===================================================================
--- trunk/Ohana/src/relastro/include/relastro.h	(revision 40413)
+++ trunk/Ohana/src/relastro/include/relastro.h	(revision 40414)
@@ -33,5 +33,5 @@
 typedef enum {OP_NONE, OP_IMAGES, OP_HIGH_SPEED, OP_MERGE_SOURCE, OP_UPDATE_OBJECTS, OP_UPDATE_OFFSETS, OP_LOAD_OBJECTS, OP_HPM, OP_PARALLEL_REGIONS, OP_PARALLEL_IMAGES, OP_REPAIR_STACKS, OP_REPAIR_WARPS, OP_REPAIR_OBJECT_ID} RelastroOp;
 
-typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, SET_CHIPS, TARGET_MOSAICS} FitTarget;
+typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, SET_CHIPS, SET_STACKS, TARGET_MOSAICS} FitTarget;
 
 typedef enum {
Index: trunk/Ohana/src/relastro/src/BrightCatalog.c
===================================================================
--- trunk/Ohana/src/relastro/src/BrightCatalog.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/BrightCatalog.c	(revision 40414)
@@ -364,5 +364,6 @@
     gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degrees", 1.0, 0.0);
     gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
-    gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "magnitude (cal)",             NULL,    1.0, 0.0);
+    gfits_define_bintable_column (&theader, "E", "MCAL_APER","magnitude (cal)",             NULL,    1.0, 0.0);
     gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "magnitude (err)",             NULL,    1.0, 0.0);
     gfits_define_bintable_column (&theader, "E", "AIRMASS",  "airmass",                	    NULL,    1.0, 0.0);
Index: trunk/Ohana/src/relastro/src/UpdateMeasures.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/UpdateMeasures.c	(revision 40414)
@@ -47,5 +47,25 @@
       }
 
-      off_t im = getImageByID (measureT->imageID);
+      Average *average = &catalog[i].average[measureB->averef];
+      int FOUND_TEST = FALSE;
+      FOUND_TEST |= (average[0].objID == OBJ_ID_SRC) && (average[0].catID == CAT_ID_SRC);
+      FOUND_TEST |= (average[0].objID == OBJ_ID_DST) && (average[0].catID == CAT_ID_DST);
+      if (FOUND_TEST) {
+	fprintf (stderr, "found test object\n");
+      }
+
+      // we need this below but cannot declare it after the label update_this_measure:
+      off_t im;
+
+      // we have a few options to include/exclude specific types of measurements
+      if (UPDATE_ALL_MEASURE) goto update_this_measure;
+      if (isGPC1chip (measureT->photcode)  && UPDATE_PS1_CHIP_MEASURE) goto update_this_measure;
+      if (isGPC1stack (measureT->photcode) && UPDATE_PS1_STACK_MEASURE) goto update_this_measure;
+      if (isHSCchip (measureT->photcode)   && UPDATE_HSC_MEASURE) goto update_this_measure;
+      if (isCFHchip (measureT->photcode)   && UPDATE_CFH_MEASURE) goto update_this_measure;
+      continue; // skip all others
+
+      update_this_measure:
+      im = getImageByID (measureT->imageID);
       if (im < 0) continue; // detections without imageIDs are not associated with a known image (eg, refs)
 
@@ -114,58 +134,11 @@
       }
 
-      // XXX this stuff is rather hackish, added to do GSC/HSC/Megacam astrometry
-
-      // only modify the chip coordinates
-      if (UPDATE_ALL_MEASURE) {
-	measureT->R = R;
-	measureT->D = D;
-	if (measureB) {
-	  measureB->R = R;
-	  measureB->D = D;
-	}
-	goto set_measure_done;
+      // modify the measure coordinates
+      measureT->R = R;
+      measureT->D = D;
+      if (measureB) {
+	measureB->R = R;
+	measureB->D = D;
       }
-      // only modify the chip coordinates
-      if (UPDATE_PS1_STACK_MEASURE && isGPC1stack (measureT->photcode)) {
-	measureT->R = R;
-	measureT->D = D;
-	if (measureB) {
-	  measureB->R = R;
-	  measureB->D = D;
-	}
-	goto set_measure_done;
-      }
-      // only modify the chip coordinates
-      if (UPDATE_PS1_CHIP_MEASURE && isGPC1chip (measureT->photcode)) {
-	measureT->R = R;
-	measureT->D = D;
-	if (measureB) {
-	  measureB->R = R;
-	  measureB->D = D;
-	}
-	goto set_measure_done;
-      }
-      // only modify the chip coordinates
-      if (UPDATE_HSC_MEASURE && isHSCchip (measureT->photcode)) {
-	measureT->R = R;
-	measureT->D = D;
-	if (measureB) {
-	  measureB->R = R;
-	  measureB->D = D;
-	}
-	goto set_measure_done;
-      }
-      // only modify the chip coordinates
-      if (UPDATE_CFH_MEASURE && isCFHchip (measureT->photcode)) {
-	measureT->R = R;
-	measureT->D = D;
-	if (measureB) {
-	  measureB->R = R;
-	  measureB->D = D;
-	}
-	goto set_measure_done;
-      }
-    set_measure_done:
-      continue; // XXX this line is needed only to support the label above
     }
     if (VERBOSE) fprintf (stderr, "%s : Noff ori RA %d ( %d %d %d ), Noff ori DEC %d ( %d %d %d )\n", catalog[i].filename, NoffRAori, NoffRAchip, NoffRAstack, NoffRAwarp, NoffDECori, NoffDECchip, NoffDECstack, NoffDECwarp);
Index: trunk/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/UpdateObjects.c	(revision 40414)
@@ -127,6 +127,12 @@
   int k;
 
+  // we need to chose to do something here...
+  int valid = UPDATE_ALL_MEASURE;
+  valid |= UPDATE_PS1_CHIP_MEASURE;
+  valid |= UPDATE_HSC_MEASURE;
+  valid |= UPDATE_CFH_MEASURE;
+  if (!valid) return FALSE;
+
   /* calculate the average value of R,D for a single star */
-
   FitAstromResult fitPos, fitPM, fitPar;
   FitAstromResultInit (&fitPos);
@@ -583,4 +589,7 @@
   int status;
 
+  // we need to chose to do something here...
+  if (!UPDATE_PS1_STACK_MEASURE) return FALSE;
+
   // set the default values
   average[0].Rstk  = NAN; // RA in degrees
@@ -794,4 +803,5 @@
     Npoints++;
 
+    // NOTE: if 'isStack' is true, we will never see these photcode values
     hasGAIA  =  (measure[k].photcode == 1030);
     has2MASS = ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013));
@@ -808,7 +818,9 @@
   }
   
-  // XXX flag measurements from stars with 2MASS 
-  for (k = 0; k < average[0].Nmeasure; k++) {
-    // reset the bit to note that a detection was used (or not)
+  // flag measurements from stars with 2MASS, GAIA, TYCHO
+  // NOTE: if 'isStack' is TRUE, these will not be correctly set.
+  // ONLY do this loop if not(isStack) 
+  for (k = 0; !isStack && (k < average[0].Nmeasure); k++) {
+    // reset the bit to note that an object does or does not have the value
     if (has2MASS) {
       measure[k].dbFlags |=  ID_MEAS_OBJECT_HAS_2MASS;
Index: trunk/Ohana/src/relastro/src/UpdateStacksWithFit.c
===================================================================
--- trunk/Ohana/src/relastro/src/UpdateStacksWithFit.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/UpdateStacksWithFit.c	(revision 40414)
@@ -73,5 +73,5 @@
     // are all automatically updated in this block because they are re-generated from
     // image.coords on each pass.
-    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
+    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_SIMPLE);
 
     NnewFit ++;
Index: trunk/Ohana/src/relastro/src/args.c
===================================================================
--- trunk/Ohana/src/relastro/src/args.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/args.c	(revision 40414)
@@ -68,4 +68,11 @@
   }
 
+  // the default is to only measure the scatter for the stacks, not to perform a new fit
+  FIT_STACKS = FALSE;
+  if ((N = get_argument (argc, argv, "-fit-stacks"))) {
+    remove_argument (N, &argc, argv);
+    FIT_STACKS = TRUE;
+  }
+
   REPAIR_STACKS = FALSE;
   if ((N = get_argument (argc, argv, "-repair-stacks-on-update"))) {
@@ -189,5 +196,11 @@
     }
   }
-  if ((RELASTRO_OP == OP_PARALLEL_IMAGES) || (RELASTRO_OP == OP_IMAGES)) {
+  if (RELASTRO_OP == OP_UPDATE_OBJECTS) {
+    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
+      fprintf (stderr, "for -update-objects, need to select at least one of -update-all-cameras, -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
+      exit (2);
+    }
+  }
+  if ((RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES) || (RELASTRO_OP == OP_IMAGES)) {
     if (APPLY_OFFSETS && !UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
       fprintf (stderr, "for [-images or -parallel-images] with -apply-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
@@ -305,4 +318,8 @@
     remove_argument (N, &argc, argv);
     FIT_TARGET = SET_CHIPS;
+  }
+  if ((N = get_argument (argc, argv, "-set-stacks"))) {
+    remove_argument (N, &argc, argv);
+    FIT_TARGET = SET_STACKS;
   }
 
Index: trunk/Ohana/src/relastro/src/launch_region_hosts.c
===================================================================
--- trunk/Ohana/src/relastro/src/launch_region_hosts.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/launch_region_hosts.c	(revision 40414)
@@ -117,4 +117,7 @@
 	strextend (&command, "-set-chips");
 	break;
+      case SET_STACKS:
+	strextend (&command, "-set-stacks");
+	break;
       case TARGET_NONE:
 	abort();
@@ -151,4 +154,6 @@
     if (SKIP_CFH)            strextend (&command, "-skip-cfh");
 
+    if (FIT_STACKS)          strextend (&command, "-fit-stacks");
+
     strextend (&command, "-nloop %d", NLOOP);
     strextend (&command, "-threads %d", NTHREADS);
Index: trunk/Ohana/src/relastro/src/relastro_images.c
===================================================================
--- trunk/Ohana/src/relastro/src/relastro_images.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/relastro_images.c	(revision 40414)
@@ -104,5 +104,16 @@
       UpdateChips (catalog, Ncatalog, 0);   // measure.X,Y -> R,D, fit image.coords
       MARKTIME("update chips: %f sec\n", dtime);
-
+      break;
+
+    case SET_STACKS:
+      // we just want to fit the selected stacks to the mean positions
+      if (FIT_STACKS) {
+	// model astrometry for stacks
+	UpdateStacksWithFit (catalog, Ncatalog);
+      } else {
+	// measure scatter for stacks
+	UpdateStacks (catalog, Ncatalog);
+      }
+      MARKTIME("update stacks : %f sec\n", dtime);
       break;
 
Index: trunk/Ohana/src/relastro/src/relastro_parallel_images.c
===================================================================
--- trunk/Ohana/src/relastro/src/relastro_parallel_images.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/relastro_parallel_images.c	(revision 40414)
@@ -163,4 +163,20 @@
       break;
 
+    case SET_STACKS:
+      // we just want to fit the selected stacks to the mean positions
+      share_mean_pos (catalog, Ncatalog, regionHosts, 0);
+      slurp_mean_pos (catalog, Ncatalog, regionHosts, 0);
+      if (FIT_STACKS) {
+	// model astrometry for stacks
+	UpdateStacksWithFit (catalog, Ncatalog);
+      } else {
+	// measure scatter for stacks
+	UpdateStacks (catalog, Ncatalog);
+      }
+      share_image_pos (regionHosts, 0);
+      slurp_image_pos (catalog, Ncatalog, regionHosts, 0);
+      MARKTIME("update stacks : %f sec\n", dtime);
+      break;
+
     case TARGET_MOSAICS:
       for (i = 0; i < NLOOP; i++) {
Index: trunk/Ohana/src/relastro/src/select_images.c
===================================================================
--- trunk/Ohana/src/relastro/src/select_images.c	(revision 40413)
+++ trunk/Ohana/src/relastro/src/select_images.c	(revision 40414)
@@ -114,4 +114,9 @@
     }
     if (FALSE && !strncmp(timage[i].name, "o6227g0311o", 10)) {
+      fprintf (stderr, "test image 2\n");
+    }
+
+    // RINGS.V3.skycell.2634.034.stk.3411510.skycal.3811673.cmf[SkyChip.hdr]
+    if (!strncmp(timage[i].name, "RINGS.V3.skycell.2634.034.stk.3411510", strlen("RINGS.V3.skycell.2634.034.stk.3411510"))) {
       fprintf (stderr, "test image 2\n");
     }
