Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/WISE.h
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/WISE.h	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/WISE.h	(revision 42166)
@@ -21,8 +21,8 @@
 short WISE_W1, WISE_W2, WISE_W3, WISE_W4;
 
-enum {MODE_NONE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
+enum {MODE_NONE, MODE_CATWISE, MODE_ALLWISE, MODE_ALLSKY, MODE_PRELIM};
 int MODE;
 
-AddstarClientOptions args_loadwise (int argc, char **argv, AddstarClientOptions options);
+AddstarClientOptions args_loadwise (int *argc, char **argv, AddstarClientOptions options);
 
 int loadwise_rawdata (SkyList *skytable, char *filename, AddstarClientOptions options);
@@ -38,5 +38,5 @@
 int loadwise_star_allsky  (Measure *measure, char *line, int Nmax);
 int loadwise_star_allwise (Measure *measure, char *line, int Nmax);
-
+int loadwise_star_catwise (Measure *measure, char *line, int Nmax, double Rs, double Ds);
 
 char *nextWISEfield (char *line);
@@ -49,4 +49,12 @@
 int setWISE_dup_flag (Measure *measure, char qual);
 int setWISE_use_flag (Measure *measure, char qual);
+int setWISE_sat_flag (Measure *measure, char *ptr);
+
+int setCatWISE_sat_flag (Measure *measure, char *ptr, int start, int end);
+int setCatWISE_blend_flag (Measure *measure, char *line);
 
 char *skipNbounds (char *line, char bound, int Nbound, int Nbyte);
+
+char *getLineSegment (char *line, int start, int end);
+double getDoubleRAW (char *line, int start, int end);
+double getDoubleNAN (char *line, int start, int end);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/ukirt_uhs.h
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/ukirt_uhs.h	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/include/ukirt_uhs.h	(revision 42166)
@@ -3,4 +3,5 @@
 
 # define NSTARS_MAX 10000000
+//# define NSTARS_MAX 5000
 // # define NSTARS_MAX 10
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/args_loadwise.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/args_loadwise.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/args_loadwise.c	(revision 42166)
@@ -3,11 +3,11 @@
 static void help (void);
 
-AddstarClientOptions args_loadwise (int argc, char **argv, AddstarClientOptions options) {
+AddstarClientOptions args_loadwise (int *argc, char **argv, AddstarClientOptions options) {
   
   int N;
 
   /* check for help request */
-  if (get_argument (argc, argv, "-help") ||
-      get_argument (argc, argv, "-h")) {
+  if (get_argument (*argc, argv, "-help") ||
+      get_argument (*argc, argv, "-h")) {
     help ();
   }
@@ -29,33 +29,33 @@
   /* only add to existing regions */
   options.existing_regions = FALSE;
-  if ((N = get_argument (argc, argv, "-existing-regions"))) {
+  if ((N = get_argument (*argc, argv, "-existing-regions"))) {
     options.existing_regions = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* only add to existing objects */
   options.only_match = FALSE;
-  if ((N = get_argument (argc, argv, "-only-match"))) {
+  if ((N = get_argument (*argc, argv, "-only-match"))) {
     options.only_match = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
   /* replace measurement, don't duplicate (ref/cat only) */
   options.replace = FALSE;
-  if ((N = get_argument (argc, argv, "-replace"))) {
+  if ((N = get_argument (*argc, argv, "-replace"))) {
     options.replace = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
   /* extra error messages */
   VERBOSE = FALSE;
-  if ((N = get_argument (argc, argv, "-v"))) {
+  if ((N = get_argument (*argc, argv, "-v"))) {
     VERBOSE = TRUE;
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
   /* load the prelim data dump */
-  MODE = MODE_ALLWISE;
-  if ((N = get_argument (argc, argv, "-mode"))) {
-    MODE = MODE_NONE;
-    remove_argument (N, &argc, argv);
+  MODE = MODE_NONE;
+  if ((N = get_argument (*argc, argv, "-mode"))) {
+    remove_argument (N, argc, argv);
+    if (!strcasecmp(argv[N], "catwise")) MODE = MODE_CATWISE;
     if (!strcasecmp(argv[N], "allwise")) MODE = MODE_ALLWISE;
     if (!strcasecmp(argv[N], "allsky"))  MODE = MODE_ALLSKY;
@@ -65,5 +65,5 @@
       exit (2);
     }
-    remove_argument (N, &argc, argv);
+    remove_argument (N, argc, argv);
   }
 
@@ -85,5 +85,5 @@
   DUMP = NULL;
 
-  if (argc < 2) {
+  if (*argc < 2) {
     fprintf (stderr, "USAGE: loadwise [options] (wisefile) [..more files]\n");
     exit (2);
@@ -94,6 +94,8 @@
 static void help () {
 
-  fprintf (stderr, "USAGE: loadwise [options] (wisefile) [..more files]\n");
+  fprintf (stderr, "USAGE: loadwise [-mode MODE] [options] (wisefile) [..more files]\n");
   fprintf (stderr, "  add data from WISE catalog to DVO\n\n");
+
+  fprintf (stderr, "  MODE may be : catwise, allwise, allsky, prelim\n");
 
   fprintf (stderr, "  optional flags:\n");
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugcs.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugcs.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugcs.c	(revision 42166)
@@ -467,12 +467,14 @@
 	NELEM += 1000;
 
-	REALLOCATE (sourceID,     uint64_t, NELEM);
+	REALLOCATE (sourceID,     uint64_t, NELEM);  
 	REALLOCATE (frameSetID,   uint64_t, NELEM);
 	REALLOCATE (ra,           double,   NELEM);
 	REALLOCATE (dec,          double,   NELEM);
+	REALLOCATE (epoch,        double,   NELEM);
 	REALLOCATE (priOrSec,     uint64_t, NELEM);
 	REALLOCATE (mergedClass,  int,      NELEM);
 	REALLOCATE (pStar,        double,   NELEM);
 	REALLOCATE (pGalaxy,      double,   NELEM);
+
 	REALLOCATE (zHallMag,     double,   NELEM);
 	REALLOCATE (zHallMagErr,  double,   NELEM);
@@ -485,4 +487,5 @@
 	REALLOCATE (zppErrBits,   int,      NELEM);
 	REALLOCATE (zSeqNum,      int,      NELEM);
+
 	REALLOCATE (yHallMag,     double,   NELEM);
 	REALLOCATE (yHallMagErr,  double,   NELEM);
@@ -495,4 +498,5 @@
 	REALLOCATE (yppErrBits,   int,      NELEM);
 	REALLOCATE (ySeqNum,      int,      NELEM);
+
 	REALLOCATE (jHallMag,     double,   NELEM);
 	REALLOCATE (jHallMagErr,  double,   NELEM);
@@ -505,4 +509,5 @@
 	REALLOCATE (jppErrBits,   int,      NELEM);
 	REALLOCATE (jSeqNum,      int,      NELEM);
+
 	REALLOCATE (hHallMag,     double,   NELEM);
 	REALLOCATE (hHallMagErr,  double,   NELEM);
@@ -515,4 +520,5 @@
 	REALLOCATE (hppErrBits,   int,      NELEM);
 	REALLOCATE (hSeqNum,      int,      NELEM);
+
 	REALLOCATE (k1HallMag,     double,   NELEM);
 	REALLOCATE (k1HallMagErr,  double,   NELEM);
@@ -525,4 +531,5 @@
 	REALLOCATE (k1ppErrBits,   int,      NELEM);
 	REALLOCATE (k1SeqNum,      int,      NELEM);
+
 	REALLOCATE (k2HallMag,     double,   NELEM);
 	REALLOCATE (k2HallMagErr,  double,   NELEM);
@@ -541,4 +548,5 @@
     }
   }
+  fprintf (stderr, " DONE: Nelem: %d, *nstars: %d\n", Nelem, *nstars);
 
   // Nelem is now the number of items (objects,stars) read from the Gaia CSV file
@@ -715,5 +723,5 @@
     Nstars ++;
 
-    if (NSTARS >= Nstars) {
+    if (Nstars >= NSTARS) {
       NSTARS += 10000;
       REALLOCATE (stars, UKIRT_Stars, NSTARS);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugps.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugps.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ugps.c	(revision 42166)
@@ -388,12 +388,14 @@
 	NELEM += 1000;
 
-	REALLOCATE (sourceID,     uint64_t, NELEM);
+	REALLOCATE (sourceID,     uint64_t, NELEM);    
 	REALLOCATE (frameSetID,   uint64_t, NELEM);
 	REALLOCATE (ra,           double,   NELEM);
 	REALLOCATE (dec,          double,   NELEM);
+	REALLOCATE (epoch,        double,   NELEM);
 	REALLOCATE (priOrSec,     uint64_t, NELEM);
 	REALLOCATE (mergedClass,  int,      NELEM);
 	REALLOCATE (pStar,        double,   NELEM);
 	REALLOCATE (pGalaxy,      double,   NELEM);
+
 	REALLOCATE (jAperMag1,     double,   NELEM);
 	REALLOCATE (jAperMag1Err,  double,   NELEM);
@@ -406,4 +408,5 @@
 	REALLOCATE (jppErrBits,   int,      NELEM);
 	REALLOCATE (jSeqNum,      int,      NELEM);
+
 	REALLOCATE (hAperMag1,     double,   NELEM);
 	REALLOCATE (hAperMag1Err,  double,   NELEM);
@@ -416,4 +419,5 @@
 	REALLOCATE (hppErrBits,   int,      NELEM);
 	REALLOCATE (hSeqNum,      int,      NELEM);
+
 	REALLOCATE (k1AperMag1,     double,   NELEM);
 	REALLOCATE (k1AperMag1Err,  double,   NELEM);
@@ -426,4 +430,5 @@
 	REALLOCATE (k1ppErrBits,   int,      NELEM);
 	REALLOCATE (k1SeqNum,      int,      NELEM);
+
 	REALLOCATE (k2AperMag1,     double,   NELEM);
 	REALLOCATE (k2AperMag1Err,  double,   NELEM);
@@ -436,4 +441,5 @@
 	REALLOCATE (k2ppErrBits,   int,      NELEM);
 	REALLOCATE (k2SeqNum,      int,      NELEM);
+
 	REALLOCATE (h2AperMag1,     double,   NELEM);
 	REALLOCATE (h2AperMag1Err,  double,   NELEM);
@@ -452,4 +458,5 @@
     }
   }
+  fprintf (stderr, " DONE: Nelem: %d, *nstars: %d\n", Nelem, *nstars);
 
   // Nelem is now the number of items (objects,stars) read from the Gaia CSV file
@@ -606,5 +613,5 @@
     Nstars ++;
 
-    if (NSTARS >= Nstars) {
+    if (Nstars >= NSTARS) {
       NSTARS += 10000;
       REALLOCATE (stars, UKIRT_Stars, NSTARS);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_uhs.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_uhs.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_uhs.c	(revision 42166)
@@ -234,4 +234,5 @@
     }
   }
+  fprintf (stderr, " DONE: Nelem: %d, *nstars: %d\n", Nelem, *nstars);
 
   // Nelem is now the number of items (objects,stars) read from the Gaia CSV file
@@ -307,5 +308,5 @@
     Nstars ++;
 
-    if (NSTARS >= Nstars) {
+    if (Nstars >= NSTARS) {
       NSTARS += 10000;
       REALLOCATE (stars, UKIRT_Stars, NSTARS);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ulas.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ulas.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadukirt_uhs_readstars_ulas.c	(revision 42166)
@@ -415,12 +415,14 @@
 	NELEM += 1000;
 
-	REALLOCATE (sourceID,     uint64_t, NELEM);
+	REALLOCATE (sourceID,     uint64_t, NELEM);    
 	REALLOCATE (frameSetID,   uint64_t, NELEM);
 	REALLOCATE (ra,           double,   NELEM);
 	REALLOCATE (dec,          double,   NELEM);
+	REALLOCATE (epoch,        double,   NELEM);
 	REALLOCATE (priOrSec,     uint64_t, NELEM);
 	REALLOCATE (mergedClass,  int,      NELEM);
 	REALLOCATE (pStar,        double,   NELEM);
 	REALLOCATE (pGalaxy,      double,   NELEM);
+
 	REALLOCATE (yHallMag,     double,   NELEM);
 	REALLOCATE (yHallMagErr,  double,   NELEM);
@@ -433,4 +435,5 @@
 	REALLOCATE (yppErrBits,   int,      NELEM);
 	REALLOCATE (ySeqNum,      int,      NELEM);
+
 	REALLOCATE (j1HallMag,     double,   NELEM);
 	REALLOCATE (j1HallMagErr,  double,   NELEM);
@@ -443,4 +446,5 @@
 	REALLOCATE (j1ppErrBits,   int,      NELEM);
 	REALLOCATE (j1SeqNum,      int,      NELEM);
+
 	REALLOCATE (j2HallMag,     double,   NELEM);
 	REALLOCATE (j2HallMagErr,  double,   NELEM);
@@ -453,4 +457,5 @@
 	REALLOCATE (j2ppErrBits,   int,      NELEM);
 	REALLOCATE (j2SeqNum,      int,      NELEM);
+
 	REALLOCATE (hHallMag,     double,   NELEM);
 	REALLOCATE (hHallMagErr,  double,   NELEM);
@@ -463,4 +468,5 @@
 	REALLOCATE (hppErrBits,   int,      NELEM);
 	REALLOCATE (hSeqNum,      int,      NELEM);
+
 	REALLOCATE (kHallMag,     double,   NELEM);
 	REALLOCATE (kHallMagErr,  double,   NELEM);
@@ -479,4 +485,5 @@
     }
   }
+  fprintf (stderr, " DONE: Nelem: %d, *nstars: %d\n", Nelem, *nstars);
 
   // Nelem is now the number of items (objects,stars) read from the Gaia CSV file
@@ -633,5 +640,5 @@
     Nstars ++;
 
-    if (NSTARS >= Nstars) {
+    if (Nstars >= NSTARS) {
       NSTARS += 10000;
       REALLOCATE (stars, UKIRT_Stars, NSTARS);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise.c	(revision 42166)
@@ -22,5 +22,5 @@
   SetSignals ();
   options = ConfigInit (&argc, argv);
-  options = args_loadwise (argc, argv, options);
+  options = args_loadwise (&argc, argv, options);
 
   // load the full sky description table:
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_ops.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_ops.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_ops.c	(revision 42166)
@@ -17,8 +17,14 @@
   char *ptr = line;
 
-  ptr = skipNbounds (ptr, '|', 1, Nmax);
-  *R = strtod (ptr, NULL);
-  ptr = skipNbounds (ptr, '|', 1, Nmax);
-  *D = strtod (ptr, NULL);
+  if (MODE == MODE_CATWISE) {
+      // copy the string ranges and then use strtod (not necessary?)
+      *R = strtod (&ptr[47], NULL); // safe to use the strtod on the line because it is white-space separated
+      *D = strtod (&ptr[59], NULL);
+  } else {
+      ptr = skipNbounds (ptr, '|', 1, Nmax);
+      *R = strtod (ptr, NULL);
+      ptr = skipNbounds (ptr, '|', 1, Nmax);
+      *D = strtod (ptr, NULL);
+  }
   if (*D > 90) Shutdown ("weird DEC value: something is wrong");
 
@@ -91,4 +97,27 @@
 }
   
+/* return a pointer to the first char after Nbound of value bound */
+char *getLineSegment (char *line, int start, int end) {
+
+  // do NOT damage the buffer by seting the end byte to NULL
+  if (0) { line[end] = 0; }
+  char *ptr = &line[start];
+  return (ptr);
+}
+  
+double getDoubleRAW (char *line, int start, int end) {
+    char *ptr = getLineSegment(line, start, end);
+    double value = strtod (ptr, NULL);
+    return value;
+}
+
+double getDoubleNAN (char *line, int start, int end) {
+    char *endpoint = NULL;
+    char *ptr = getLineSegment(line, start, end);
+    double value = strtod (ptr, &endpoint);
+    if (endpoint == ptr) { value = NAN; }
+    return value;
+}
+
 /* watch for patches which cross 0,360 boundary */
 SkyTable *loadWISE_acc (char *path, char *accel) {
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_rawdata.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_rawdata.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_rawdata.c	(revision 42166)
@@ -28,4 +28,6 @@
   getWISE_setup ();
 
+  int NMeasPerStar = (MODE == MODE_CATWISE) ? 2 : 4;
+
   ALLOCATE (buffer, char, NBYTE);
 
@@ -34,4 +36,6 @@
   if (f == NULL) Shutdown ("can't read WISE data file: %s", filename);
   // test if this is a raw datafile or gzipped...
+
+  int skipHeader = TRUE;
 
   Nextra = 0;  // number excess bytes from lsat partial row
@@ -59,6 +63,18 @@
     Dmax = -90.0;
 
+    // XXX buffer is being reread instead of continuing.
+
     // scan through entire buffer for star coords
     while (1) {
+
+      if (skipHeader && (MODE == MODE_CATWISE)) {
+	if (*p == '\\') goto skip_header;
+	if (*p == '|') goto skip_header;
+      }
+      if (skipHeader && (MODE == MODE_CATWISE)) {
+	// once we get past the header, do not skip any more
+	skipHeader = FALSE;
+      }
+
       getWISE_coords (p, &tstars[Ntstars].R, &tstars[Ntstars].D, Nbyte - offset);
       tstars[Ntstars].offset = offset; // offset within scan
@@ -74,4 +90,6 @@
       Ntstars ++;
       CHECK_REALLOCATE (tstars, WISE_Stars, NTSTARS, Ntstars, 10000);
+
+    skip_header:
 
       /* start of the next line */
@@ -143,8 +161,9 @@
 	if (tstars[j].D > UserPatch.Dmax) continue;
 	  
+	// offset is bytes to start of line from start of buffer
 	offset = tstars[j].offset;
 
 	dvo_average_init (&newcat->average[Nave]);
-	for (k = 0; k < 4; k++) {
+	for (k = 0; k < NMeasPerStar; k++) {
 	  dvo_measure_init (&newcat->measure[Nmeas+k]);
 	}
@@ -163,4 +182,7 @@
 	    loadwise_star_allwise (&newcat->measure[Nmeas], &buffer[offset], Nbyte - offset);
 	    break;
+	  case MODE_CATWISE:
+	    loadwise_star_catwise (&newcat->measure[Nmeas], &buffer[offset], Nbyte - offset, tstars[j].R, tstars[j].D);
+	    break;
 	  default:
 	    break;
@@ -169,9 +191,9 @@
 	tstars[j].flag = TRUE;
 
-	newcat->average[Nave].Nmeasure = 4;
+	newcat->average[Nave].Nmeasure = NMeasPerStar;
 	newcat->average[Nave].measureOffset = Nmeas;
 
 	Nave ++;
-	Nmeas += 4;
+	Nmeas += NMeasPerStar;
 
 	CHECK_REALLOCATE (newcat->average, Average, NAVE,  Nave,  1000);
Index: branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_star_full.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_star_full.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/addstar/src/loadwise_star_full.c	(revision 42166)
@@ -2,12 +2,95 @@
 # include "WISE.h"
 
-int setWISE_ph_qual (Measure *measure, char qual);
 int setWISE_var_flag_allsky (Measure *measure, char qual);
 int setWISE_ext_flag_allsky (Measure *measure, char ptr);
 int setWISE_var_flag_prelim (Measure *measure, char qual);
 int setWISE_ext_flag_prelim (Measure *measure, char ptr);
-int setWISE_cc_flag (Measure *measure, char qual);
-int setWISE_sat_flag (Measure *measure, char *ptr);
 int setWISE_blend_flag (Measure *measure, char *ptr);
+
+// fill in the data for a CatWISE double star.  takes a pointer to the start of the line the
+// RA and DEC have already been set
+int loadwise_star_catwise (Measure *measure, char *line, int Nmax, double Rs, double Ds) {
+
+  if (line == NULL) Shutdown ("format error in WISE");
+
+  /*** CATWISE has fixed width data, not pipe-separated, etc ***/
+
+  // https://irsa.ipac.caltech.edu/data/WISE/CatWISE/gator_docs/catwise_colDescriptions.html
+
+  // We are supplied a pointer (line) to the start of a full line of data.  The CatWISE
+  // format uses fixed-width fields with white-space separators.  The ra & dec values have
+  // already been extracted.
+
+  measure[0].R    = Rs;
+  measure[0].D    = Ds;
+  measure[1].R    = Rs;
+  measure[1].D    = Ds;
+
+  // I can assign dRA and dDEC to dX and dY if I can consistently set posangle and pltscale
+  measure[0].dXccd = ToShortPixels(getDoubleRAW (line, 71, 79) + 0.005); // sig_ra -- add 5/1000 to avoid truncation
+  measure[0].dYccd = ToShortPixels(getDoubleRAW (line, 80, 88) + 0.005); // sig_dec
+  measure[0].posangle = 0.0;
+  measure[0].pltscale = 1.0;
+
+  // we only know a single set of values for both bands 
+  measure[1].dXccd    = measure[0].dXccd;
+  measure[1].dYccd    = measure[0].dYccd;
+  measure[1].posangle = measure[0].posangle;
+  measure[1].pltscale = measure[0].pltscale;
+
+  measure[0].Xccd = getDoubleRAW (line,  98, 106); // wx
+  measure[0].Yccd = getDoubleRAW (line, 107, 115); // wy
+  measure[1].Xccd = measure[0].Xccd;
+  measure[1].Yccd = measure[0].Yccd;
+
+  // W1
+  measure[0].M         = getDoubleNAN (line, 248, 254); // w1mpro
+  measure[0].dM        = getDoubleNAN (line, 255, 264); // w1sigmpro
+  measure[0].psfChisq  = getDoubleRAW (line, 265, 275); // w1rchi2
+  measure[0].psfQF     = measure[0].psfChisq;
+  measure[0].photFlags = 0;
+
+  // W2
+  measure[1].M         = getDoubleNAN (line, 276, 282); // w2mpro
+  measure[1].dM        = getDoubleNAN (line, 283, 292); // w2sigmpro
+  measure[1].psfChisq  = getDoubleRAW (line, 293, 303); // w2rchi2
+  measure[1].psfQF     = measure[1].psfChisq;
+  measure[1].photFlags = 0;
+
+  setCatWISE_blend_flag (measure, line); // w1sat
+
+  setCatWISE_sat_flag (&measure[0], line, 323, 330); // w1sat
+  setCatWISE_sat_flag (&measure[1], line, 331, 338); // w2sat
+
+  // cc_flags? 1642 - 1657
+  // setWISE_cc_flag (&measure[0], ptr[i]); // cc_flags
+
+  // set ext flags for all 4 measures
+  // setCatWISE_ext_flag_allsky (measure, ptr[0]); // ext_flg
+
+  // setWISE_var_flag_allsky (&measure[0], ptr[i]); // var_flg
+
+  // setWISE_ph_qual (&measure[i], ptr[i]); // ph_qual
+
+  double mjdmean = getDoubleRAW (line, 1126, 1138); // MeanObsMJD
+  
+  // the release is based on data taken in the period 14 January 2010 to 29 April 2010
+  if (mjdmean == 0.0) {
+    measure[0].t = 0;
+  } else {
+    measure[0].t = ohana_mjd_to_sec (mjdmean);
+  }
+  measure[1].t = measure[0].t;
+
+  measure[0].photcode  = WISE_W1;
+  measure[0].detID   = 0;
+  measure[0].imageID = 0;
+
+  measure[1].photcode  = WISE_W2;
+  measure[1].detID   = 0;
+  measure[1].imageID = 0;
+
+  return TRUE;
+}
 
 // fill in the data for a WISE quad star.  takes a pointer to the start of the line the
@@ -458,4 +541,22 @@
 }
 
+int setCatWISE_blend_flag (Measure *measure, char *line) {
+
+  // na
+  int nb = atoi(getLineSegment(line, 315, 318)); // nb
+  int na = atoi(getLineSegment(line, 319, 322)); // na
+
+  if (nb != 1) {
+    if (na == 0) {
+      measure[0].photFlags |= FLAG_BLEND_ACTIVE;
+      measure[1].photFlags |= FLAG_BLEND_ACTIVE;
+    } else {
+      measure[0].photFlags |= FLAG_BLEND_PASSIVE;
+      measure[1].photFlags |= FLAG_BLEND_PASSIVE;
+    }
+  }
+  return TRUE;
+}
+
 int setWISE_sat_flag (Measure *measure, char *ptr) {
 
@@ -465,4 +566,13 @@
     }
     return TRUE;
+}
+
+int setCatWISE_sat_flag (Measure *measure, char *ptr, int start, int end) {
+
+  float sat = getDoubleRAW (ptr, start, end);
+  if (sat > 0.0) {
+    measure[0].photFlags |= FLAG_SATURATED_PIX;
+  }
+  return TRUE;
 }
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/include/dvomerge.h
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/include/dvomerge.h	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/include/dvomerge.h	(revision 42166)
@@ -65,4 +65,5 @@
 int    RESET_LENSING;
 
+int    SKIP_IMAGES; 
 int    SKIP_MEASURE;
 int    SKIP_MISSING;
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/args.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/args.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/args.c	(revision 42166)
@@ -39,9 +39,18 @@
     remove_argument (N, argc, argv);
   }
-
-  /* extra error messages */
-  MATCHED_TABLES = FALSE;
+  SKIP_IMAGES = FALSE;
+  if ((N = get_argument (*argc, argv, "-skip-images"))) {
+    SKIP_IMAGES = TRUE;
+    remove_argument (N, argc, argv);
+  }
+
+  /* extra error messages */
+  MATCHED_TABLES = TRUE;
   if ((N = get_argument (*argc, argv, "-matched-tables"))) {
     MATCHED_TABLES = TRUE;
+    remove_argument (N, argc, argv);
+  }
+  if ((N = get_argument (*argc, argv, "-unmatched-tables"))) {
+    MATCHED_TABLES = FALSE;
     remove_argument (N, argc, argv);
   }
@@ -77,4 +86,14 @@
     SKIP_GALPHOT = TRUE;
     remove_argument (N, argc, argv);
+  }
+
+  if (SKIP_IMAGES && !(SKIP_MEASURE || SKIP_LENSING)) {
+    fprintf (stderr, "WARNING: skipping images but merging measure and lensing tables: imageIDs will not be correct\n");
+    fprintf (stderr, "type Ctrl-C within 5 seconds to cancel\n");
+    for (int i = 5; i > 0; i--) {
+      fprintf (stderr, "%d.. ", i);
+      usleep (1000000);
+    }
+    fprintf (stderr, "\n");
   }
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 42166)
@@ -404,9 +404,9 @@
   off_t i;
 
-  for (i = 0; i < IDmap->oldIDmax + 1; i++) {
+  for (i = 0; IDmap->notFoundMeasure && (i < IDmap->oldIDmax + 1); i++) {
     if (!IDmap->notFoundMeasure[i]) continue;
     fprintf (stderr, "SKIP IMAGE MEASURE: "OFF_T_FMT", %d measures\n", i, IDmap->notFoundMeasure[i]);
   }
-  for (i = 0; i < IDmap->oldIDmax + 1; i++) {
+  for (i = 0; IDmap->notFoundLensing && (i < IDmap->oldIDmax + 1); i++) {
     if (!IDmap->notFoundLensing[i]) continue;
     fprintf (stderr, "SKIP IMAGE LENSING: "OFF_T_FMT", %d lensings\n", i, IDmap->notFoundLensing[i]);
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 42166)
@@ -81,12 +81,15 @@
   }
 
-  if (CONTINUE) {
-    // need to determine the mapping from the input to the output images
-    dvomergeImagesGetMap (&IDmap, input, output);
-  } else {
-    dvomergeImagesUpdate (&IDmap, input, output);
-    if (IMAGES_ONLY) exit (0);
+  // do not merge the images unless requested
+  if (!SKIP_IMAGES) {
+    if (CONTINUE) {
+      // need to determine the mapping from the input to the output images
+      dvomergeImagesGetMap (&IDmap, input, output);
+    } else {
+      dvomergeImagesUpdate (&IDmap, input, output);
+      if (IMAGES_ONLY) exit (0);
+    }
   }
-
+    
   // load the sky table for the existing database
   insky = SkyTableLoadOptimal (input, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE);
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c	(revision 42166)
@@ -163,4 +163,5 @@
     }
 
+    // for SKIP_IMAGES, this is a NO-OP
     dvo_update_image_IDs (IDmap, &incatalog);
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c	(revision 42166)
@@ -69,4 +69,5 @@
       LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w", threadData->NsecfiltOutput);
 
+      // for SKIP_IMAGES, this is a NO-OP
       dvo_update_image_IDs (threadData->IDmap, &incatalog);
       merge_catalogs_old (&threadData->outsky->regions[j], &outcatalog, &incatalog, RADIUS, threadData->secfiltMap);
@@ -183,10 +184,12 @@
   }
 
-  if (CONTINUE) {
-    // need to determine the mapping from the input to the output images
-    dvomergeImagesGetMap (&IDmap, input, output);
-  } else {
-    dvomergeImagesUpdate (&IDmap, input, output);
-    if (IMAGES_ONLY) exit (0);
+  if (!SKIP_IMAGES) {
+    if (CONTINUE) {
+      // need to determine the mapping from the input to the output images
+      dvomergeImagesGetMap (&IDmap, input, output);
+    } else {
+      dvomergeImagesUpdate (&IDmap, input, output);
+      if (IMAGES_ONLY) exit (0);
+    }
   }
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/libohana/src/errors.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/libohana/src/errors.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/libohana/src/errors.c	(revision 42166)
@@ -26,4 +26,12 @@
 
 int push_error (char *line) {
+
+  if (!errorlines) {
+    NLINE = 10;
+    ALLOCATE (errorlines, char *, NLINE);
+    for (int i = 0; i < NLINE; i++) {
+      errorlines[i] = NULL;
+    }
+  }
 
   errorlines[Nline] = strcreate (line);
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/Makefile	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/Makefile	(revision 42166)
@@ -106,4 +106,5 @@
 $(SRC)/mget3d.$(ARCH).o		\
 $(SRC)/mslice.$(ARCH).o		\
+$(SRC)/mlayer.$(ARCH).o		\
 $(SRC)/minterpolate.$(ARCH).o	\
 $(SRC)/medimage.$(ARCH).o	\
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/create.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/create.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/create.c	(revision 42166)
@@ -3,5 +3,5 @@
 int create (int argc, char **argv) {
   
-  int i, N, INT;
+  int i, N;
   opihi_flt start, end, delta;
   Vector *vec;
@@ -34,5 +34,5 @@
   }
 
-  INT = FALSE;
+  int INT = FALSE;
   if ((N = get_argument (argc, argv, "-int"))) {
     INT = TRUE;
@@ -40,12 +40,18 @@
   }
 
-  if ((argc != 5) && (argc != 4)) {
-    gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n");
-    gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n");
-    gprint (GP_ERR, " -str : resulting vector is string type (only give number of elements)\n");
-    return (FALSE);
+  int EMPTY = FALSE;
+  if ((N = get_argument (argc, argv, "-empty"))) {
+    EMPTY = TRUE;
+    remove_argument (N, &argc, argv);
   }
 
+  if (!EMPTY && (argc != 5) && (argc != 4)) goto usage;
+  if (EMPTY && (argc != 2)) goto usage;
+
   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if (EMPTY) {
+    ResetVector (vec, (INT ? OPIHI_INT : OPIHI_FLT), 0);
+    return TRUE;
+  }
 
   delta = 1;
@@ -91,3 +97,10 @@
 
   return (TRUE);
+
+ usage:
+  gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n");
+  gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n");
+  gprint (GP_ERR, " -str : resulting vector is string type (only give number of elements)\n");
+  gprint (GP_ERR, "OR: create vector -empty (creates vector of length zero)\n");
+  return (FALSE);
 }
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/init.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/init.c	(revision 42166)
@@ -97,4 +97,5 @@
 int mget3d           PROTO((int, char **));
 int mslice           PROTO((int, char **));
+int mlayer           PROTO((int, char **));
 int minterp          PROTO((int, char **));
 int medimage_command PROTO((int, char **));
@@ -296,4 +297,5 @@
   {1, "mget3d",       mget3d,           "extract a vector from a 3D image"},
   {1, "mslice",       mslice,           "extract an image plane from a 3D image"},
+  {1, "mlayer",       mlayer,           "insert an image plane into a 3D image"},
   {1, "imget",        mget,             "extract a vector from an image"},
   {1, "minterp",      minterp,          "interpolate image pixels"},
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mlayer.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mlayer.c	(revision 42166)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mlayer.c	(revision 42166)
@@ -0,0 +1,118 @@
+# include "data.h"
+
+int mlayer (int argc, char **argv) {
+  
+  int N;
+  Buffer *src, *tgt;
+
+  int Dir = 0;
+  if ((N = get_argument (argc, argv, "-x"))) {
+    remove_argument (N, &argc, argv);
+    Dir = 1;    
+  }
+  if ((N = get_argument (argc, argv, "-y"))) {
+    remove_argument (N, &argc, argv);
+    if (Dir) {
+      gprint (GP_ERR, "ERROR: multiple -x,-y,-z options are not allowed\n");
+      return FALSE;
+    }
+    Dir = 2;    
+  }
+  if ((N = get_argument (argc, argv, "-z"))) {
+    remove_argument (N, &argc, argv);
+    if (Dir) {
+      gprint (GP_ERR, "ERROR: multiple -x,-y,-z options are not allowed\n");
+      return FALSE;
+    }
+    Dir = 3;    
+  }
+  if (!Dir) Dir = 3;
+
+  if (argc != 4) {
+    gprint (GP_ERR, "USAGE: mlayer <output> <input> plane [-x,-y,-z]\n");
+    gprint (GP_ERR, "  insert 2D image into 3D cube (opposite of mslice)\n");
+    gprint (GP_ERR, "  -z is default\n");
+    return (FALSE);
+  }
+
+  int plane = atoi(argv[3]);
+
+  if ((tgt = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+  if (tgt[0].matrix.Naxes < 3) {
+    gprint (GP_ERR, "buffer is not 3D\n");
+    return FALSE;
+  }
+  if ((src = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE);
+
+  int Nx = tgt[0].matrix.Naxis[0];
+  int Ny = tgt[0].matrix.Naxis[1];
+  int Nz = tgt[0].matrix.Naxis[2];
+
+  int NplaneMax = 0;
+  int Nsrc1 = 0;
+  int Nsrc2 = 0;
+
+  switch (Dir) {
+    case 1: NplaneMax = Nx; Nsrc1 = Ny; Nsrc2 = Nz; break;
+    case 2: NplaneMax = Ny; Nsrc1 = Nx; Nsrc2 = Nz; break;
+    case 3: NplaneMax = Nz; Nsrc1 = Nx; Nsrc2 = Ny; break;
+    default: myAbort ("impossible");
+  }
+
+  int invalid = FALSE;
+  invalid = invalid || (plane < 0);
+  invalid = invalid || (plane >= NplaneMax);
+  if (invalid) {
+    gprint (GP_ERR, "plane %d out of range (max = %d)\n", plane, NplaneMax);
+    return (FALSE);
+  }
+  if (Nsrc1 != src->matrix.Naxis[0]) {
+    gprint (GP_ERR, "source image does not match output cube dimensions (%d vs %ld)\n", Nsrc1, src->matrix.Naxis[0]);
+    return (FALSE);
+  }
+  if (Nsrc2 != src->matrix.Naxis[1]) {
+    gprint (GP_ERR, "source image does not match output cube dimensions (%d vs %ld)\n", Nsrc2, src->matrix.Naxis[1]);
+    return (FALSE);
+  }
+
+  // pixel (ix, iy, iz) : tgt[0].matrix.buffer + ix + iy*Nx + iz*Nx*Ny
+
+  switch (Dir) {
+    case 1: {
+      float *srcF = (float *) src[0].matrix.buffer;
+      
+      // pixel (ix, iy, iz) : tgt[0].matrix.buffer + ix + iy*Nx + iz*Nx*Ny
+
+      for (int iz = 0; iz < Nz; iz++) {
+	float *tgtF  = (float *) tgt[0].matrix.buffer + plane + iz*Nx*Ny;
+	for (int iy = 0; iy < Ny; iy++, tgtF += Nx, srcF++) {
+	  *tgtF = *srcF;
+	}
+      }
+      break;
+    }
+    case 2: {
+
+      float *srcF = (float *) src[0].matrix.buffer;
+
+      for (int iz = 0; iz < Nz; iz++) {
+	float *tgtF  = (float *) tgt[0].matrix.buffer + plane*Nx + iz*Nx*Ny;
+	for (int ix = 0; ix < Nx; ix++, tgtF++, srcF++) {
+	   *tgtF = *srcF;
+	}
+      }
+      break;
+    }
+    case 3: {
+      float *tgtF  = (float *) tgt[0].matrix.buffer + plane*Nx*Ny;
+      float *srcF = (float *) src[0].matrix.buffer;
+      
+      for (int i = 0; i < Nx*Ny; i++, tgtF ++, srcF++) {
+	*tgtF = *srcF;
+      }
+      break;
+    }
+    default: myAbort ("impossible");
+  }
+  return (TRUE);
+}
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mslice.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mslice.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/mslice.c	(revision 42166)
@@ -31,4 +31,5 @@
   if (argc != 4) {
     gprint (GP_ERR, "USAGE: mslice <input> <output> plane [-x,-y,-z]\n");
+    gprint (GP_ERR, "  extract 2D image from 3D cube (opposite of mlayer)\n");
     gprint (GP_ERR, "  -z is default\n");
     return (FALSE);
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/write_vectors.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 42166)
@@ -102,5 +102,5 @@
   if (argc < 3) {
     gprint (GP_ERR, "USAGE: write [options] file vector vector ...\n");
-    gprint (GP_ERR, "OPTIONS: [-header] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n");
+    gprint (GP_ERR, "OPTIONS: [-header [buf]] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n");
     return (FALSE);
   }
@@ -289,8 +289,8 @@
  usage:
     gprint (GP_ERR, "USAGE: write [options] file vector vector ...\n");
-    gprint (GP_ERR, "OPTIONS: [-header] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n\n");
+    gprint (GP_ERR, "OPTIONS: [-header [buf]] [-append] [-f \"format\"] [-fits NAME] [-csv] [-h,--help]\n\n");
 
     gprint (GP_ERR, "OPTIONS: \n");
-    gprint (GP_ERR, "  -header : add a descriptive header line to ascii or csv output\n");
+    gprint (GP_ERR, "  -header : add a descriptive header line to ascii or csv output (see below for FITS)\n");
     gprint (GP_ERR, "  -append : write to the end of the existing file\n");
     gprint (GP_ERR, "  -fits NAME : write a fits table (extention name is NAME, column names match vector names)\n");
Index: branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/VectorIO.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/VectorIO.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/VectorIO.c	(revision 42166)
@@ -267,5 +267,5 @@
 }
   
-static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TZERO", "TSCAL", "        ", NULL};
+static char *rawkeywords[] = {"SIMPLE", "BITPIX", "NAXIS", "PCOUNT", "GCOUNT", "EXTEND", "EXTNAME", "BSCALE", "BZERO", "TFIELDS", "TFORM", "TTYPE", "TZERO", "TSCAL", "        ", NULL};
 
 // write a set of vectors to a FITS file (vectors names become fits column names)
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/include/relphot.h
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/include/relphot.h	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/include/relphot.h	(revision 42166)
@@ -721,5 +721,5 @@
 int relphot_images (SkyList *skylist);
 
-void relphot_usage (void);
+void relphot_usage (int argc, char **argv);
 void relphot_help (int argc, char **argv);
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/ResetOps.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/ResetOps.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/ResetOps.c	(revision 42166)
@@ -123,10 +123,15 @@
 
   for (off_t i = 0; i < catalog->Naverage; i++) {
-    catalog->average[i].psfQF     = NAN;	// force recalculation in setMrelCatalog
-    catalog->average[i].psfQFperf = NAN;	// force recalculation in setMrelCatalog
-    catalog->average[i].stargal   = NAN;	// force recalculation in setMrelCatalog
-    catalog->average[i].photFlagsUpper = 0;	// reset (will be re-calculated)
-    catalog->average[i].photFlagsLower = 0;	// reset (will be re-calculated)
-    catalog->average[i].NwarpOK        = 0;	// reset (will be re-calculated)
+    if (STAGES & STAGE_CHIP) {
+      catalog->average[i].psfQF     = NAN;	// force recalculation in setMrelCatalog
+      catalog->average[i].psfQFperf = NAN;	// force recalculation in setMrelCatalog
+      catalog->average[i].stargal   = NAN;	// force recalculation in setMrelCatalog
+      catalog->average[i].photFlagsUpper = 0;	// reset (will be re-calculated)
+      catalog->average[i].photFlagsLower = 0;	// reset (will be re-calculated)
+    }
+    
+    if (STAGES & STAGE_WARP) {
+      catalog->average[i].NwarpOK        = 0;	// reset (will be re-calculated)
+    }
 
     // RESET_FLATCORR independent of RESET?
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/args.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/args.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/args.c	(revision 42166)
@@ -203,5 +203,5 @@
     remove_argument (N, &argc, argv);
     TEST_IMAGE1 = strtol(argv[N], &endptr, 0);
-    if (*endptr) relphot_usage (); 
+    if (*endptr) relphot_usage (argc, argv); 
     remove_argument (N, &argc, argv);
   }
@@ -211,5 +211,5 @@
     remove_argument (N, &argc, argv);
     TEST_IMAGE2 = strtol(argv[N], &endptr, 0);
-    if (*endptr) relphot_usage (); 
+    if (*endptr) relphot_usage (argc, argv); 
     remove_argument (N, &argc, argv);
   }
@@ -584,8 +584,8 @@
     remove_argument (N, &argc, argv);
     mode = PARALLEL_IMAGES;
-    if (N >= argc) relphot_usage();
+    if (N >= argc) relphot_usage(argc, argv);
     IMAGE_TABLE = strcreate (argv[N]);
     remove_argument (N, &argc, argv);
-    if (!REGION_FILE) relphot_usage();
+    if (!REGION_FILE) relphot_usage(argc, argv);
   }
 
@@ -594,5 +594,5 @@
     remove_argument (N, &argc, argv);
     mode = PARALLEL_REGIONS;
-    if (!REGION_FILE) relphot_usage();
+    if (!REGION_FILE) relphot_usage(argc, argv);
     if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
       remove_argument (N, &argc, argv);
@@ -609,7 +609,9 @@
       // note: initialize sets PhotcodeList to the full set of average photcodes
       // if the mode is UPDATE_AVERAGES
-      if (argc != 1) relphot_usage();
-      break;
+      // if (argc != 1) relphot_usage(argc, argv);
+      // break;
       
+      if (argc == 1) break; // if no photcodes are given, use them all?
+
     case UPDATE_IMAGES:
     case PARALLEL_IMAGES:
@@ -623,8 +625,8 @@
     default:
       fprintf (stderr, "no valid mode selected\n");
-      relphot_usage();
+      relphot_usage(argc, argv);
       break;
   }
-  if (argc != 1) relphot_usage ();
+  if (argc != 1) relphot_usage (argc, argv);
 
   // if we supplied a file, we need to load it now
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/help.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/help.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/help.c	(revision 42166)
@@ -1,5 +1,5 @@
 # include "relphot.h"
 
-void relphot_usage (void) {
+void relphot_usage (int argc, char **argv) {
   fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -images\n");
   fprintf (stderr, "       or:    relphot -averages\n");
@@ -11,4 +11,11 @@
   fprintf (stderr, "       or:    -catalog (name)\n");
   fprintf (stderr, "  use -h for more usage information\n");
+
+  fprintf (stderr, "unparsed arguments: ");
+  for (int i = 0; i < argc; i++) {
+    fprintf (stderr, "%s ", argv[i]);
+  }
+  fprintf (stderr, "\n");
+
   exit (2);
 } 
@@ -19,5 +26,5 @@
   if (get_argument (argc, argv, "-help")) goto show_help;
   if (get_argument (argc, argv, "-h"))    goto show_help;
-  if (argc == 1) relphot_usage();
+  if (argc == 1) relphot_usage(0, NULL);
   return;
 
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/initialize.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/initialize.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/initialize.c	(revision 42166)
@@ -9,6 +9,8 @@
   if (!mode) exit (2);
 
-  // UPDATE_AVERAGES always operates on all photcodes? 
-  if (mode == UPDATE_AVERAGES) {
+  // UPDATE_AVERAGES used to always operate on all photcodes
+  // now, if a list of photcodes are given that is used, otherwise
+  // all will be used
+  if (!photcodes) {
     char tmpline1[256];
     int Ns;
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/relphot_images.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/relphot_images.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/relphot_images.c	(revision 42166)
@@ -132,4 +132,7 @@
   
     // if (GRID_ZEROPT) dump_grid ();
+    setMcal  (catalog);
+    setMmos  (catalog);
+    setMgrp  (catalog);
 
     setMcal  (catalog);
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelCatalog.c	(revision 42166)
@@ -266,4 +266,6 @@
       // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
       Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value
+      // but external reference photometry might not have Mcal set, so set to 0.0 in that case.
+      if (isnan(Mcal)) Mcal = 0.0;
     } else {
       // getMcal returns image[].Mcal
@@ -412,5 +414,5 @@
 
     // XXX hardwired grizy = (01234) JHK = (567) w = (8)
-    if ((Nsec < 5) || (Nsec == 8)) {
+    if (Nsec < 5) {
       secfilt[Nsec].Ncode = results->NexpPS1[Nsec]; 
     } else {
Index: branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelFinal.c	(revision 42165)
+++ branches/eam_branches/ipp-20220316/Ohana/src/relphot/src/setMrelFinal.c	(revision 42166)
@@ -11,4 +11,5 @@
   int Nsecfilt = GetPhotcodeNsecfilt ();
 
+  // this resets values only if -reset is used
   ResetAverageAndMeasure (catalog);
   
