Index: /trunk/Ohana/src/opihi/dvo/ccd.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/ccd.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/ccd.c	(revision 4679)
@@ -8,5 +8,5 @@
   int i, m, k, Npts, NPTS, N;
   int N1, N2, i1, i2, mode[4];
-  int Ngraph, Nsec, Nregions;
+  int Ngraph, Nsec, Nregions, KeepNulls;
 
   Catalog catalog;
@@ -33,4 +33,10 @@
   if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
   if (!SetPhotSelections (&argc, argv, 4)) goto usage;
+
+  KeepNulls = FALSE;
+  if (N = get_argument (argc, argv, "-nulls")) {
+    KeepNulls = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   /* interpret command-line options */
@@ -82,5 +88,13 @@
       SetSelectionParam (2);
       M2 = ExtractDMag (&code[2], &mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N2);
-      if (N2 == 0) goto skip;
+      if (N2 == 0) {
+	if (KeepNulls) {
+	  ALLOCATE (M2, double, 1);
+	  N2 = 1;
+	  M2[0] = NO_MAG;
+	} else {
+	  goto skip;
+	}
+      }
 
       for (i1 = 0; i1 < N1; i1++) {
Index: /trunk/Ohana/src/opihi/dvo/cmd.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/cmd.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/cmd.c	(revision 4679)
@@ -7,5 +7,5 @@
   int i, j, m, i1, i3, N1, N3, N;
   int Npts, NPTS, mode[3];
-  int Ngraph, Nsec, Nregions;
+  int Ngraph, Nsec, Nregions, KeepNulls;
 
   Catalog catalog;
@@ -33,4 +33,10 @@
   if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
   if (!SetPhotSelections (&argc, argv, 3)) goto usage;
+
+  KeepNulls = FALSE;
+  if (N = get_argument (argc, argv, "-nulls")) {
+    KeepNulls = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   /* interpret command-line options */
@@ -80,5 +86,13 @@
       SetSelectionParam (2);
       M3 = ExtractMagnitudes (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3);
-      if (N3 == 0) goto skip;
+      if (N3 == 0) {
+	if (KeepNulls) {
+	  ALLOCATE (M3, double, 1);
+	  N3 = 1;
+	  M3[0] = NO_MAG;
+	} else {
+	  goto skip;
+	}
+      }
 
       for (i1 = 0; i1 < N1; i1++) {
Index: /trunk/Ohana/src/opihi/dvo/ddmags.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/ddmags.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/ddmags.c	(revision 4679)
@@ -6,7 +6,7 @@
   double Radius;
   double *M1, *M2;
-  int i, m, k, Npts, NPTS;
+  int i, m, k, N, Npts, NPTS;
   int N1, N2, i1, i2, mode[4];
-  int Ngraph, Nsec, Nregions;
+  int Ngraph, Nsec, Nregions, KeepNulls;
 
   Catalog catalog;
@@ -33,4 +33,10 @@
   if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
   if (!SetPhotSelections (&argc, argv, 4)) goto usage;
+
+  KeepNulls = FALSE;
+  if (N = get_argument (argc, argv, "-nulls")) {
+    KeepNulls = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   /* interpret command-line options */
@@ -82,5 +88,13 @@
       SetSelectionParam (2);
       M2 = ExtractDMag (&code[2], &mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N2);
-      if (N2 == 0) goto skip;
+      if (N2 == 0) {
+	if (KeepNulls) {
+	  ALLOCATE (M2, double, 1);
+	  N2 = 1;
+	  M2[0] = NO_MAG;
+	} else {
+	  goto skip;
+	}
+      }
 
       for (i1 = 0; i1 < N1; i1++) {
Index: /trunk/Ohana/src/opihi/dvo/dmagaves.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmagaves.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/dmagaves.c	(revision 4679)
@@ -21,4 +21,5 @@
   RegionName = NULL;
   RegionList = NULL;
+  code[2] = NULL;
 
   /* load photcode information */
Index: /trunk/Ohana/src/opihi/dvo/dmagmeas.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmagmeas.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/dmagmeas.c	(revision 4679)
@@ -7,5 +7,5 @@
   int i, j, k, m, i1, i3, N1, N3, N;
   int Npts, NPTS, param, mode[3];
-  int Ngraph, Nsec, Nregions;
+  int Ngraph, Nsec, Nregions, KeepNulls;
 
   Catalog catalog;
@@ -33,4 +33,10 @@
   if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
   if (!SetPhotSelections (&argc, argv, 3)) goto usage;
+
+  KeepNulls = FALSE;
+  if (N = get_argument (argc, argv, "-nulls")) {
+    KeepNulls = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   /* interpret command-line arguments: dmagmeas F1 - F2 : (value) */
@@ -81,5 +87,13 @@
       SetSelectionParam (2);
       M3 = ExtractMeasures (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3, param);
-      if (N3 == 0) goto skip;
+      if (N3 == 0) {
+	if (KeepNulls) {
+	  ALLOCATE (M3, double, 1);
+	  N3 = 1;
+	  M3[0] = NO_MAG;
+	} else {
+	  goto skip;
+	}
+      }
 
       for (i1 = 0; i1 < N1; i1++) {
Index: /trunk/Ohana/src/opihi/dvo/dmags.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/dmags.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/dmags.c	(revision 4679)
@@ -7,5 +7,5 @@
   int i, j, m, i1, i3, N1, N3, N;
   int Npts, NPTS, mode[3];
-  int Nsec, Nregions;
+  int Nsec, Nregions, KeepNulls;
 
   PhotCode *code[3];
@@ -33,4 +33,10 @@
   if (!SetPhotSelections (&argc, argv, 3)) goto usage;
 
+  KeepNulls = FALSE;
+  if (N = get_argument (argc, argv, "-nulls")) {
+    KeepNulls = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
   /* interpret required command-line arguments: dmags F1 - F2 : F3 */
   if (argc != 6) { goto usage; }
@@ -40,5 +46,5 @@
   if (!GetPhotcodeInfo (argv[3], &code[1], &mode[1])) goto usage;
   if (!GetPhotcodeInfo (argv[5], &code[2], &mode[2])) goto usage;
-  if (!TestPhotSelections (&code[0], MEAS_ZERO)) goto escape;
+  if (!TestPhotSelections (&code[0], &mode[0], MEAS_ZERO)) goto escape;
 
   /* load region corresponding to selection above */
@@ -79,5 +85,13 @@
       SetSelectionParam (2);
       M3 = ExtractMagnitudes (code[2], mode[2], &catalog.average[i], &catalog.secfilt[i*Nsec], &catalog.measure[m], &N3);
-      if (N3 == 0) goto skip;
+      if (N3 == 0) {
+	if (KeepNulls) {
+	  ALLOCATE (M3, double, 1);
+	  N3 = 1;
+	  M3[0] = NO_MAG;
+	} else {
+	  goto skip;
+	}
+      }
 
       for (i1 = 0; i1 < N1; i1++) {
Index: /trunk/Ohana/src/opihi/dvo/photometry.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/photometry.c	(revision 4678)
+++ /trunk/Ohana/src/opihi/dvo/photometry.c	(revision 4679)
@@ -244,4 +244,5 @@
   if (!strcasecmp (parname, "Nphot")) param = AVE_NPHOT;
   if (!strcasecmp (parname, "Ncode")) param = AVE_NCODE;
+  if (!strcasecmp (parname, "Ncrit")) param = AVE_NCRIT;
   return (param);
 }
@@ -250,5 +251,5 @@
 int TestPhotSelections (PhotCode **code, int *mode, int param) {
 
-  int NeedPhotcode;
+  int NeedPhotcode, Needcode;
 
   /* if i've supplied a photcode (code != NULL), i'm not allowed to restrict it */
@@ -262,14 +263,14 @@
   }
 
-  /* if I have an average or ensemble restriction, I must have a photcode */
+  /* for measure tests, supply MEAS_ZERO */
+
+  /* if I have an average or ensemble restriction, I must have a PRI/SEC photcode */
   NeedPhotcode = FALSE;
   NeedPhotcode |= ChiSelect;
   NeedPhotcode |= NphotSelect;
-  NeedPhotcode |= NcodeSelect;
   NeedPhotcode |= ErrSelect;
   NeedPhotcode |= TypeSelect;
   NeedPhotcode |= TypefracSelect;
   
-  /* for measure tests, supply MEAS_ZERO */
   NeedPhotcode |= (param == AVE_Xm);
   NeedPhotcode |= (param == AVE_MAG);
@@ -277,12 +278,19 @@
   NeedPhotcode |= (param == AVE_TYPE);
   NeedPhotcode |= (param == AVE_NPHOT);
-  NeedPhotcode |= (param == AVE_NCODE);
-
-  if (NeedPhotcode || PhotcodeSelect) {
-    if (!PhotcodeSelect) return (FALSE);
+  Needcode = (param == AVE_NCODE);
+
+  if (NeedPhotcode || Needcode || NcodeSelect || PhotcodeSelect) {
+    if (!PhotcodeSelect) {
+      fprintf (stderr, "photcode selection problem: value requires photcode\n");
+      return (FALSE);
+    }
     code[0] = PhotcodeValue;
     mode[0] = PhotcodeMode;
-    if (code[0][0].type == PHOT_DEP) return (FALSE);
-    if (code[0][0].type == PHOT_REF) return (FALSE);
+  }
+  if (NeedPhotcode) {
+    if (code[0][0].type == PHOT_PRI) return (TRUE);
+    if (code[0][0].type == PHOT_SEC) return (TRUE);
+    fprintf (stderr, "photcode selection problem: average value requires PRI/SEC photcode\n");
+    return (FALSE);
   }
   return (TRUE);
@@ -615,5 +623,5 @@
       value = 0;
       for (i = 0; i < average[0].Nm; i++) {
-	if (code[0].code != GetPhotcodeEquivCodebyCode (measure[i].source)) continue;
+	if ((code != NULL) && (code[0].code != GetPhotcodeEquivCodebyCode (measure[i].source))) continue;
 	if (ErrSelect && (measure[i].dM > ErrValue)) continue;
 	if (FlagSelect && (measure[i].flags != FlagValue)) continue;
@@ -738,21 +746,4 @@
   if (code == NULL) return (FALSE);
 
-  /* only PRI/SEC photcodes apply the filter */
-  if (code[0].type == PHOT_DEP) return (TRUE);
-  if (code[0].type == PHOT_REF) return (TRUE);
-
-  /* exclusions based on average.params  */
-  if (ChiSelect) {
-    Xm = PhotXm (code, average, secfilt);
-    if (Xm == -1) return (FALSE);
-    if (Xm > ChiLimit) return (FALSE);
-  }
-  
-  /* for ErrSelect, check average errors */
-  if (ErrSelect) {
-    dM = iPhotdM (code, average, secfilt);
-    if (dM > ErrValue) return (NO_MAG);
-  }
-  
   /* for NcodeSelect, count Nmeas for appropriate photcode */
   if (NcodeSelect) {
@@ -777,4 +768,21 @@
   }
 
+  /* only PRI/SEC photcodes apply the filter */
+  if (code[0].type == PHOT_DEP) return (TRUE);
+  if (code[0].type == PHOT_REF) return (TRUE);
+
+  /* exclusions based on average.params  */
+  if (ChiSelect) {
+    Xm = PhotXm (code, average, secfilt);
+    if (Xm == -1) return (FALSE);
+    if (Xm > ChiLimit) return (FALSE);
+  }
+  
+  /* for ErrSelect, check average errors */
+  if (ErrSelect) {
+    dM = iPhotdM (code, average, secfilt);
+    if (dM > ErrValue) return (NO_MAG);
+  }
+  
   /* for NphotSelect, count Nmeas for appropriate photcode */
   if (NphotSelect) {
