Index: /branches/eam_branches/ipp-20120405/Ohana/src/opihi/cmd.data/vgroup.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/opihi/cmd.data/vgroup.c	(revision 33736)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/opihi/cmd.data/vgroup.c	(revision 33737)
@@ -1,3 +1,5 @@
 # include "data.h"
+
+enum {USE_MEDIAN, USE_COUNT, USE_SUM, USE_MEAN};
 
 int vgroup (int argc, char **argv) {
@@ -23,14 +25,42 @@
   // }
 
+  int mode = USE_MEDIAN;
+  if ((N = get_argument (argc, argv, "-sum"))) {
+    remove_argument (N, &argc, argv);
+    mode = USE_SUM;
+  }
+  if ((N = get_argument (argc, argv, "-mean"))) {
+    remove_argument (N, &argc, argv);
+    mode = USE_MEAN;
+  }
+
+  float binsize = NAN;
+  if ((N = get_argument (argc, argv, "-binsize"))) {
+    remove_argument (N, &argc, argv);
+    binsize = atof(argv[N]);
+    remove_argument (N, &argc, argv);
+  }
+
   if (argc != 5) {
-    gprint (GP_ERR, "USAGE: vbin <xin> <yin> <xout> <yout>\n");
+    gprint (GP_ERR, "USAGE: vgroup <xin> <yin> <xout> <yout>\n");
     gprint (GP_ERR, " group x,y values in bins defined by <xout>\n");
+    gprint (GP_ERR, " by default, yout has the median of the associated input values\n");
+    gprint (GP_ERR, " use -sum to add values in the bin\n");
+    gprint (GP_ERR, " use <yin> = histogram count matching values\n");
+    gprint (GP_ERR, " use -binsize to specify a fixed bin width (<xout> will define the bin center)\n");
     return (FALSE);
   }
 
   if ((xin  = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
-  if ((yin  = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
   if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
   if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  yin = NULL;
+
+  // this should conflict with the -sum option...
+  if (!strcmp(argv[2], "histogram")) {
+    mode = USE_COUNT;
+  } else {
+    if ((yin  = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  }
 
   // re-binning creates a float vector
@@ -41,6 +71,11 @@
 
   for (i = 0; i < xout[0].Nelements - 1; i++) {
-    xmin = xout[0].elements.Flt[i];
-    xmax = xout[0].elements.Flt[i+1];
+    if (isnan(binsize)) {
+      xmin = xout[0].elements.Flt[i];
+      xmax = xout[0].elements.Flt[i+1];
+    } else {
+      xmin = xout[0].elements.Flt[i] - 0.5*binsize;
+      xmax = xout[0].elements.Flt[i] + 0.5*binsize;
+    }
 
     N = 0;
@@ -48,21 +83,40 @@
       if (xin[0].elements.Flt[j] < xmin) continue;
       if (xin[0].elements.Flt[j] > xmax) continue;
-      values[N] = yin[0].elements.Flt[j];
+      if (yin) {
+	values[N] = yin[0].elements.Flt[j];
+      }
       N++;
     }
     
-    dsort (values, N);
-    if (N > 1) {
-      sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]);
-    } else {
-      sum = values[0];
+    sum = NAN;
+    switch (mode) {
+      case USE_MEDIAN:
+	dsort (values, N);
+	if (N > 1) {
+	  sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]);
+	} else {
+	  sum = values[0];
+	}
+	break;
+
+      case USE_SUM:
+	sum = 0.0;
+	for (j = 0; j < N; j++) {
+	  sum += values[j];
+	}
+	break;
+	
+      case USE_COUNT:
+	sum = N;
+	break;
+
+      case USE_MEAN:
+	sum = 0.0;
+	for (j = 0; j < N; j++) {
+	  sum += values[j];
+	}
+	sum /= N;
+	break;
     }
-
-    // measure the stat for this bin
-    // sum = 0.0;
-    // for (j = 0; j < N; j++) {
-    //   sum += values[j];
-    // }
-    // sum /= N;
     yout[0].elements.Flt[i] = sum;
   }
Index: /branches/eam_branches/ipp-20120405/Ohana/src/opihi/dvo/skycoverage.c
===================================================================
--- /branches/eam_branches/ipp-20120405/Ohana/src/opihi/dvo/skycoverage.c	(revision 33736)
+++ /branches/eam_branches/ipp-20120405/Ohana/src/opihi/dvo/skycoverage.c	(revision 33737)
@@ -2,5 +2,5 @@
 
 // enum to define possible modes
-enum {COVERAGE, DENSITY, MIN_UBERCAL, MIN_DMAG_SYS, MIN_MCAL, MAX_MCAL};
+enum {COVERAGE, DENSITY, MIN_UBERCAL, MIN_DMAG_SYS, MIN_MCAL, MAX_MCAL, MIN_TIME, MAX_TIME};
 
 int wordhash (char *word);
@@ -23,4 +23,9 @@
   PhotCode *PhotcodeValue;
 
+  time_t TimeReference;
+  int TimeFormat;
+
+  GetTimeFormat (&TimeReference, &TimeFormat);
+
   WITH_MOSAIC = FALSE;
   if ((N = get_argument (argc, argv, "+mosaic"))) {
@@ -71,4 +76,12 @@
     remove_argument (N, &argc, argv);
     mode = MIN_UBERCAL;
+  }
+  if ((N = get_argument (argc, argv, "-min-time"))) {
+    remove_argument (N, &argc, argv);
+    mode = MIN_TIME;
+  }
+  if ((N = get_argument (argc, argv, "-max-time"))) {
+    remove_argument (N, &argc, argv);
+    mode = MAX_TIME;
   }
   if ((N = get_argument (argc, argv, "-min-dmag-sys"))) {
@@ -231,8 +244,10 @@
 	  case MIN_DMAG_SYS:
 	  case MIN_MCAL:
-	    V[ys*Nx + xs] = 1E6;
+	  case MIN_TIME:
+	    V[ys*Nx + xs] = 1E9;
 	    break;
 	  case MAX_MCAL:
-	    V[ys*Nx + xs] = -1E6;
+	  case MAX_TIME:
+	    V[ys*Nx + xs] = -1E9;
 	    break;
 	}
@@ -247,4 +262,6 @@
 	  case MIN_MCAL:
 	  case MAX_MCAL:
+	  case MIN_TIME:
+	  case MAX_TIME:
 	    V[ys*Nx + xs] = NAN;
 	    break;
@@ -323,4 +340,12 @@
 	      V[ys*Nx + xs] = MAX(V[ys*Nx + xs], image[i].Mcal);
 	      break;
+	    case MIN_TIME: {
+	      double timeVal = TimeValue (image[i].tzero, TimeReference, TimeFormat);
+	      V[ys*Nx + xs] = MIN(V[ys*Nx + xs], timeVal);
+	      break; }
+	    case MAX_TIME: {
+	      double timeVal = TimeValue (image[i].tzero, TimeReference, TimeFormat);
+	      V[ys*Nx + xs] = MAX(V[ys*Nx + xs], timeVal);
+	      break; }
 	  }
 	}
