Index: /trunk/Ohana/src/opihi/cmd.astro/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.astro/Makefile	(revision 6642)
@@ -30,4 +30,5 @@
 $(SDIR)/drizzle.$(ARCH).o	   \
 $(SDIR)/flux.$(ARCH).o		   \
+$(SDIR)/fixwrap.$(ARCH).o	   \
 $(SDIR)/gauss.$(ARCH).o		   \
 $(SDIR)/getvel.$(ARCH).o	   \
Index: /trunk/Ohana/src/opihi/cmd.astro/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.astro/init.c	(revision 6642)
@@ -11,4 +11,5 @@
 int drizzle		    PROTO((int, char **));
 int flux		    PROTO((int, char **));
+int fixwrap		    PROTO((int, char **));
 int gauss		    PROTO((int, char **));
 int gaussfit		    PROTO((int, char **));
@@ -44,4 +45,5 @@
   {"drizzle", 	  drizzle,      "transform image to image"},
   {"flux",    	  flux,         "flux in a convex contour"},
+  {"fixwrap",  	  fixwrap,      "fix megacam over-wrapped pixels"},
   {"gauss",   	  gauss,        "get statistics on a star, assuming gaussian profile"},
   {"getvel",      getvel,       "rotcurve to velocities"},
Index: /trunk/Ohana/src/opihi/cmd.data/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.data/Makefile	(revision 6642)
@@ -68,4 +68,5 @@
 $(SDIR)/mset.$(ARCH).o		\
 $(SDIR)/peak.$(ARCH).o		\
+$(SDIR)/periodogram.$(ARCH).o	\
 $(SDIR)/plot.$(ARCH).o		\
 $(SDIR)/dot.$(ARCH).o		\
Index: /trunk/Ohana/src/opihi/cmd.data/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.data/init.c	(revision 6642)
@@ -53,4 +53,5 @@
 int mset             PROTO((int, char **));
 int peak             PROTO((int, char **));
+int periodogram      PROTO((int, char **));
 int plot             PROTO((int, char **));
 int dot              PROTO((int, char **));
@@ -160,4 +161,5 @@
   {"mset",    	   mset,	     "insert a vector in a matrix"},
   {"peak",	   peak,	     "find vector peak in range"},
+  {"periodogram",  periodogram,	     "measure periods in unevenly sampled data"},
   {"plot",    	   plot,	     "plot a pair of vectors"},
   {"dot",    	   dot,	             "plot a single point"},
Index: /trunk/Ohana/src/opihi/cmd.data/peak.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/peak.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.data/peak.c	(revision 6642)
@@ -3,11 +3,17 @@
 int peak (int argc, char **argv) {
   
-  int i, imax;
+  int i, N, imax, QUIET;
   double start, end, xmax, ymax;
   float *X, *Y;
   Vector *vecx, *vecy;
 
-  if (argc != 5) {
-    fprintf (stderr, "USAGE: peak <x> <y> start end\n");
+  QUIET = FALSE;
+  if ((N = get_argument (argc, argv, "-q"))) {
+    QUIET = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  if ((argc != 5) && (argc != 3)) {
+    fprintf (stderr, "USAGE: peak <x> <y> [start end]\n");
     return (FALSE);
   }
@@ -16,6 +22,11 @@
   if ((vecy = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
 
-  start = atof (argv[3]);
-  end   = atof (argv[4]);
+  if (argc == 5) {
+    start = atof (argv[3]);
+    end   = atof (argv[4]);
+  } else {
+    start = vecx[0].elements[0];
+    end   = vecx[0].elements[vecx[0].Nelements - 1];
+  }
 
   X = vecx[0].elements;
@@ -39,7 +50,6 @@
   set_variable ("peaknum", imax);
 
-  fprintf (stderr, "peak %f @ %f (%d)\n", ymax, xmax, imax);
+  if (!QUIET) fprintf (GetOutfile(), "peak %f @ %f (%d)\n", ymax, xmax, imax);
 
   return (TRUE);
 }
-
Index: /trunk/Ohana/src/opihi/cmd.data/periodogram.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/periodogram.c	(revision 6642)
+++ /trunk/Ohana/src/opihi/cmd.data/periodogram.c	(revision 6642)
@@ -0,0 +1,114 @@
+# include "data.h"
+
+int periodogram (int argc, char **argv) {
+  
+  int i, N, Npt, Np, NP, VERBOSE;
+  float *tv, *fv;
+  float minP, maxP, minT, maxT, dTime;
+  float mean, var, w, tau, P, Pc, Ps, Po;
+  float C, S, cs, sn, cs2, sn2, ratio;
+  Vector *time, *flux, *power, *period;
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    VERBOSE = TRUE;
+    remove_argument (N, &argc, argv);
+  }
+
+  if (argc != 7) {
+    fprintf (stderr, "USAGE: periodogram (time) (flux) (minP) (maxP) (period) (power)\n");
+    return (FALSE);
+  }
+  
+  if ((time = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((flux = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
+  minP = atof(argv[3]);
+  maxP = atof(argv[4]);
+  if ((period = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+  if ((power = SelectVector (argv[6], ANYVECTOR, TRUE)) == NULL) return (FALSE);
+
+  /* find the max baseline, mean, and variance */
+  minT = maxT = time[0].elements[0];
+  Npt = time[0].Nelements;
+  tv = time[0].elements;
+  fv = flux[0].elements;
+  mean = var = 0;
+  for (i = 0; i < Npt; i++, tv++, fv++) {
+    minT = MIN (minT, *tv);
+    maxT = MAX (maxT, *tv);
+    mean += *fv;
+  }
+  mean = mean / Npt;
+  fv = flux[0].elements;
+  for (i = 0; i < Npt; i++, fv++) {
+    var += SQ(*fv - mean);
+  }
+  var = var / (Npt - 1);
+
+  if (VERBOSE) fprintf (stderr, "mean: %f, var: %f, minT: %f, maxT: %f\n", mean, var, minT, maxT);
+
+  dTime = maxT - minT;
+  if (dTime == 0) {
+    fprintf (stderr, "ERROR: time range is zero\n");
+    return (FALSE);
+  }
+
+  Np = 0;
+  NP = 100;
+  REALLOCATE (power[0].elements, float, NP);
+  REALLOCATE (period[0].elements, float, NP);
+
+  P = minP;
+  while (P < maxP) {
+    w = 2*M_PI/P;
+    
+    /* find the period offset tau  */
+    tv = time[0].elements;
+    cs = sn = 0;
+    for (i = 0; i < Npt; i++, tv++) {
+      cs += cos (*tv*w*2);
+      sn += sin (*tv*2*2);
+    }
+    tau = 0.5*atan2 (sn, cs) / w;
+      
+    /* find the power at this period */
+    tv = time[0].elements;
+    fv = flux[0].elements;
+    cs = sn = cs2 = sn2 = 0;
+    for (i = 0; i < Npt; i++, tv++, fv++) {
+      C = cos (w*(*tv-tau));
+      S = sin (w*(*tv-tau));
+      // C = cos (w**tv);
+      // S = sin (w**tv);
+      cs += (*fv - mean) * C;
+      sn += (*fv - mean) * S;
+      cs2 += SQ(C);
+      sn2 += SQ(S);
+    }
+    Pc = SQ(cs) / cs2;
+    Ps = SQ(sn) / sn2;
+    Po = (Pc + Ps) / (2*var);
+
+    power[0].elements[Np] = Po;
+    period[0].elements[Np] = P;
+    Np ++;
+    if (Np >= NP) {
+      NP += 100;
+      REALLOCATE (power[0].elements, float, NP);
+      REALLOCATE (period[0].elements, float, NP);
+    }
+
+    ratio = 1 + 0.1*P/dTime;
+
+    if (VERBOSE) fprintf (stderr, "tau: %f, P: %f, ratio: %f, dTime: %f, nextP: %f\n", tau, P, ratio, dTime, P*ratio);
+
+    P *= ratio;
+  }
+
+  power[0].Nelements = Np;
+  period[0].Nelements = Np;
+  REALLOCATE (power[0].elements, float, Np);
+  REALLOCATE (period[0].elements, float, Np);
+ 
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/cmd.data/test/peak.sh
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/test/peak.sh	(revision 6642)
+++ /trunk/Ohana/src/opihi/cmd.data/test/peak.sh	(revision 6642)
@@ -0,0 +1,75 @@
+
+list tests
+ test1
+ test2
+ test3
+end
+
+# test using full range
+macro test1
+ $PASS = 1
+ break -auto off
+
+ create x 0 100
+ set y = zero (x)
+ y[50] = 1
+
+ peak -q x y 0 100
+
+ if ($peakpos != 50)
+   $PASS = 0
+ end
+ if ($peaknum != 51)
+   $PASS = 0
+ end
+ if ($peakval != 1)
+   $PASS = 0
+ end
+end
+
+# test using auto range
+macro test2
+ $PASS = 1
+ break -auto off
+
+ create x 0 100
+ set y = zero (x)
+ y[50] = 1
+
+ peak -q x y 
+
+ if ($peakpos != 50)
+   $PASS = 0
+ end
+ if ($peaknum != 51)
+   $PASS = 0
+ end
+ if ($peakval != 1)
+   $PASS = 0
+ end
+end
+
+# test using constrained range
+macro test3
+ $PASS = 1
+ break -auto off
+
+ create x 0 100
+ set y = zero (x)
+ y[60] = 2
+ y[50] = 1
+ y[40] = 2
+
+ peak -q x y 45 55
+
+ if ($peakpos != 50)
+   $PASS = 0
+ end
+ if ($peaknum != 51)
+   $PASS = 0
+ end
+ if ($peakval != 1)
+   $PASS = 0
+ end
+end
+
Index: /trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh	(revision 6642)
+++ /trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh	(revision 6642)
@@ -0,0 +1,100 @@
+
+list tests
+ test1
+ test2
+ test3
+end
+
+# test using even samples
+macro test1
+ $PASS = 1
+ break -auto off
+
+ local P PI
+ $PI = 3.14159265359
+ $P  = 15.0
+
+ create t 0 100
+ set f = sin(2*$PI*t/$P)
+ periodogram t f 5 50 period power
+
+ peak -q period power
+
+ if (abs ($peakpos - $P) > 0.5)
+   $PASS = 0
+ end
+end
+
+# test using random samples
+macro test2
+ $PASS = 1
+ break -auto off
+
+ local P PI
+ $PI = 3.14159265359
+ $P  = 15.0
+
+ create x 0 100
+ set t = 100 * rnd(x) 
+ set f = sin(2*$PI*t/$P)
+ periodogram t f 5 50 period power
+
+ # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
+ # lim -n 1 period power; clear; box; plot period power
+
+ peak -q period power
+
+ if (abs ($peakpos - $P) > 0.5)
+   $PASS = 0
+ end
+end
+
+# test using random samples, higher frequency
+macro test3
+ $PASS = 1
+ break -auto off
+
+ local P PI
+ $PI = 3.14159265359
+ $P  = 2.0
+
+ create x 0 100
+ set t = 100 * rnd(x) 
+ set f = sin(2*$PI*t/$P)
+
+ periodogram t f 1 10 period power
+
+ # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
+ # lim -n 1 period power; clear; box; plot period power
+
+ peak -q period power
+
+ if (abs ($peakpos - $P) > 0.05)
+   $PASS = 0
+ end
+end
+
+# test using random samples, offset start
+macro test4
+ $PASS = 1
+ break -auto off
+
+ local P PI
+ $PI = 3.14159265359
+ $P  = 15.0
+
+ create x 500 800
+ set t = 300 * rnd(x) + 500
+ set f = sin(2*$PI*t/$P)
+
+ periodogram t f 2 30 period power
+
+  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
+  lim -n 1 period power; clear; box; plot period power
+
+ peak -q period power
+
+ if (abs ($peakpos - $P) > 0.05)
+   $PASS = 0
+ end
+end
Index: /trunk/Ohana/src/opihi/cmd.data/write_vectors.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/cmd.data/write_vectors.c	(revision 6642)
@@ -41,4 +41,5 @@
   for (i = 0; i < Nvec; i++) {
     if ((vec[i] = SelectVector (argv[i + 2], OLDVECTOR, FALSE)) == NULL) {
+      fprintf (stderr, "unknown vector %s\n", argv[i+2]);
       fprintf (stderr, "USAGE: write (file) vector vector ...\n");
       free (vec);
Index: /trunk/Ohana/src/opihi/dvo/avextract.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/avextract.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/dvo/avextract.c	(revision 6642)
@@ -18,4 +18,5 @@
   RegionName = NULL;
   RegionList = NULL;
+  skylist = NULL;
   code = NULL;
   mode = MAG_AVE;
Index: /trunk/Ohana/src/opihi/dvo/gstar.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 6641)
+++ /trunk/Ohana/src/opihi/dvo/gstar.c	(revision 6642)
@@ -9,5 +9,5 @@
   double Mcat, Mrel;
   float *RA, *DEC;
-  int i, j, k, m, N, *N1, Nsec, NPTS;
+  int i, j, k, m, N, *N1, Nsec, NPTS, QUIET;
   int Nstars, found, GetMeasures, Nlo, Nhi;
   int SaveVectors;
@@ -17,7 +17,15 @@
   Catalog catalog;
   PhotCode *code;
+  int TimeFormat;
+  time_t TimeReference;
 
   if (!InitPhotcodes ()) return (FALSE);
   Nsec = GetPhotcodeNsecfilt ();
+
+  QUIET = FALSE;
+  if ((N = get_argument (argc, argv, "-q"))) {
+    QUIET = TRUE;
+    remove_argument (N, &argc, argv);
+  }
 
   NPTS = 0;
@@ -44,4 +52,6 @@
   }
   
+  GetTimeFormat (&TimeReference, &TimeFormat);
+
   Ra = atof (argv[1]);
   Dec = atof (argv[2]);
@@ -127,30 +137,32 @@
     if (r < Radius2) {
       k = N1[i];
-      fprintf (GetOutfile(), "star: %d\n", k);
-      fprintf (GetOutfile(), "%9.5f %9.5f %3d of %3d  %4.1f %5d\n", catalog.average[k].R_PS, catalog.average[k].D_PS, 
-	       catalog.average[k].Nm, catalog.average[k].Nn + catalog.average[k].Nm,
-	       0.01*catalog.average[k].Xp, catalog.average[k].code);
+      if (!QUIET) {
+	  fprintf (GetOutfile(), "star: %d\n", k);
+	  fprintf (GetOutfile(), "%9.5f %9.5f %3d of %3d  %4.1f %5d\n", catalog.average[k].R_PS, catalog.average[k].D_PS, 
+		   catalog.average[k].Nm, catalog.average[k].Nn + catalog.average[k].Nm,
+		   0.01*catalog.average[k].Xp, catalog.average[k].code);
       
-      /* filter names -- primary code is 0 in this function */
-      for (j = 0; j < Nsec + 1; j++) {
-	code = GetPhotcodebyNsec (j);
-	fprintf (GetOutfile (), "%s ", code[0].name);
+	  /* filter names -- primary code is 0 in this function */
+	  for (j = 0; j < Nsec + 1; j++) {
+	      code = GetPhotcodebyNsec (j);
+	      fprintf (GetOutfile (), "%s ", code[0].name);
+	  }
+	  fprintf (GetOutfile (), "\n");
+
+	  /* average mags */
+	  print_value (GetOutfile(), catalog.average[k].M_PS, catalog.average[k].M_PS);
+	  for (j = 0; j < Nsec; j++) print_value (GetOutfile(), catalog.secfilt[j + Nsec*k].M_PS, catalog.secfilt[j + Nsec*k].M_PS);
+	  fprintf (GetOutfile(), "\n");
+
+	  /* average mag errors */
+	  print_value (GetOutfile(), catalog.average[k].dM_PS, catalog.average[k].dM_PS);
+	  for (j = 0; j < Nsec; j++) print_value (GetOutfile(), catalog.secfilt[j + Nsec*k].dM_PS, catalog.secfilt[j + Nsec*k].dM_PS);
+	  fprintf (GetOutfile(), "\n");
+
+	  /* average mag chisq */
+	  print_value (GetOutfile(), pow (10.0, 0.01*catalog.average[k].Xm), catalog.average[k].Xm);
+	  for (j = 0; j < Nsec; j++) print_value (GetOutfile(), pow (10.0, 0.01*catalog.secfilt[j + Nsec*k].Xm), catalog.secfilt[j + Nsec*k].Xm);
+	  fprintf (GetOutfile(), "\n");
       }
-      fprintf (GetOutfile (), "\n");
-
-      /* average mags */
-      print_value (GetOutfile(), catalog.average[k].M_PS, catalog.average[k].M_PS);
-      for (j = 0; j < Nsec; j++) print_value (GetOutfile(), catalog.secfilt[j + Nsec*k].M_PS, catalog.secfilt[j + Nsec*k].M_PS);
-      fprintf (GetOutfile(), "\n");
-
-      /* average mag errors */
-      print_value (GetOutfile(), catalog.average[k].dM_PS, catalog.average[k].dM_PS);
-      for (j = 0; j < Nsec; j++) print_value (GetOutfile(), catalog.secfilt[j + Nsec*k].dM_PS, catalog.secfilt[j + Nsec*k].dM_PS);
-      fprintf (GetOutfile(), "\n");
-
-      /* average mag chisq */
-      print_value (GetOutfile(), pow (10.0, 0.01*catalog.average[k].Xm), catalog.average[k].Xm);
-      for (j = 0; j < Nsec; j++) print_value (GetOutfile(), pow (10.0, 0.01*catalog.secfilt[j + Nsec*k].Xm), catalog.secfilt[j + Nsec*k].Xm);
-      fprintf (GetOutfile(), "\n");
 
       if (GetMeasures || SaveVectors) {
@@ -161,5 +173,5 @@
 	  Mrel = PhotRel (&catalog.measure[m], &catalog.average[k], &catalog.secfilt[k*Nsec]);
 
-	  if (GetMeasures) {
+	  if (GetMeasures && !QUIET) {
 	    date = sec_to_date (catalog.measure[m].t);
 	    fprintf (GetOutfile(), "%6.3f %6.3f %5.3f  %20s  %5.2f %5.2f %2d %3x %3d %-20s\n", 
@@ -173,5 +185,5 @@
 	  if (SaveVectors) {
 	    vec1[0].elements[N] = Mcat;
-	    vec2[0].elements[N] = catalog.measure[m].t;
+	    vec2[0].elements[N] = TimeValue (catalog.measure[m].t, TimeReference, TimeFormat);
 	    vec3[0].elements[N] = catalog.measure[m].airmass_PS;
 	    vec4[0].elements[N] = catalog.measure[m].source;
Index: /trunk/Ohana/src/opihi/test/tests.sh
===================================================================
--- /trunk/Ohana/src/opihi/test/tests.sh	(revision 6641)
+++ /trunk/Ohana/src/opihi/test/tests.sh	(revision 6642)
@@ -1,6 +1,9 @@
 
 list testdir
+  cmd.data/test
   cmd.basic/test
 end
+
+$VERBOSE = 0
 
 macro fulltests
@@ -15,12 +18,20 @@
 
   for Ti 0 $testdir:n
+    if ($VERBOSE > 0)
+       echo "directory $testdir:$Ti"
+    end
     list testscripts -x "ls $testdir:$Ti/*.sh"
     for Tj 0 $testscripts:n
+      if ($VERBOSE > 1)
+         echo " running $testscripts:$Tj"
+      end
       input $testscripts:$Tj
       for Tk 0 $tests:n
-        # echo running $tests:$Tk
+        if ($VERBOSE > 2)
+          echo "   running $tests:$Tk"
+        end
         $tests:$Tk
         if ($PASS == 0)
-          echo "failed test $tests:$Tk"
+          echo "   ** failed test $tests:$Tk"
           $Nfail ++
           $n = $failtest:n
@@ -32,5 +43,4 @@
           $faildirs:n ++
         else
-          # echo "passed $tests:$Tk"
           $Npass ++
         end
