Index: /trunk/ippTests/ippCheck/camstats.pro
===================================================================
--- /trunk/ippTests/ippCheck/camstats.pro	(revision 42627)
+++ /trunk/ippTests/ippCheck/camstats.pro	(revision 42628)
@@ -216,6 +216,15 @@
  vstat -q numFound; $Nfound = $TOTAL
  vstat -q numGood;  $Ngood  = $TOTAL
- 
- fprintf "%d of %d total sources detected, %d unmasked" $Nfound $Ntotal $Ngood
+ vstat -q numPoss;  $Nposs  = $TOTAL
+ 
+ fprintf "%d of %d total sources detected, %d unmasked and %d possible" $Nfound $Ntotal $Ngood $Nposs
+
+ subset tmp = numTotal  where (magBin > 15) && (magBin < 20); vstat -q tmp; $numBrightTotal  = $TOTAL
+ subset tmp = numPoss  where (magBin > 15) && (magBin < 20); vstat -q tmp; $numBrightPoss  = $TOTAL
+ subset tmp = numFound where (magBin > 15) && (magBin < 20); vstat -q tmp; $numBrightFound = $TOTAL
+ subset tmp = numGood  where (magBin > 15) && (magBin < 20); vstat -q tmp; $numBrightGood  = $TOTAL
+
+ fprintf "%d of %d total bright sources detected, %d unmasked and %d possible" $numBrightFound $numBrightTotal $numBrightGood $numBrightPoss
+
 
  legend.init 0.02 0.95 0.03 0.02
Index: /trunk/ippTests/ippCheck/ippCheck
===================================================================
--- /trunk/ippTests/ippCheck/ippCheck	(revision 42627)
+++ /trunk/ippTests/ippCheck/ippCheck	(revision 42628)
@@ -77,4 +77,5 @@
   $MATCH_RADIUS = 8.0; # XXX add option to set the radius?
   $OUTVERSION = MPC
+  $REFMODE = MPC;    # used by plot.exposure.user for input
   $COPYMASKS = 0
 
@@ -169,6 +170,7 @@
   
   if (not($SKIP_WARP))
-    load.warpstats $expname.stats/$expname.$REFMODE.wrp.stf
-    plot.warpstats.fracs; png -name  $expname.stats/$expname.$REFMODE.wrpfracs.png
+    load.camstats $expname.stats/$expname.$REFMODE.wrp.stf
+    plot.camstats.fracs; png -name  $expname.stats/$expname.$REFMODE.wrpfracs.png
+    plot.camstats.resid; png -name  $expname.stats/$expname.$REFMODE.wrpresid.png
   end
 
@@ -213,6 +215,7 @@
   
   if (not($SKIP_WARP))
-    load.warpstats $expglob.$REFMODE.wrp.stf
-    plot.warpstats.fracs; png -name  $outroot.$REFMODE.wrpfracs.png
+    load.camstats $expglob.$REFMODE.wrp.stf
+    plot.camstats.fracs; png -name  $outroot.$REFMODE.wrpfracs.png
+    plot.camstats.resid; png -name  $outroot.$REFMODE.wrpresid.png
   end
 
Index: /trunk/ippTests/ippCheck/warpmask.pro
===================================================================
--- /trunk/ippTests/ippCheck/warpmask.pro	(revision 42627)
+++ /trunk/ippTests/ippCheck/warpmask.pro	(revision 42628)
@@ -8,4 +8,5 @@
 if (not($?USE_CAMSOURCE)) set USE_CAMSOURCE = 0
 
+$SMF_FIELDS_WRP = X_PSF Y_PSF RA_PSF DEC_PSF CAL_PSF_MAG PSF_QF PSF_QF_PERFECT
 $REF_FIELDS_WRP = Rref Dref Mref 
 $XTR_FIELDS_WRP = Xref Yref Nref Q1ref
@@ -76,5 +77,5 @@
 
   # delete any existing output vectors
-  foreach field $REF_FIELDS_WRP $XTR_FIELDS_WRP
+  foreach field $SMF_FIELDS_WRP $REF_FIELDS_WRP $XTR_FIELDS_WRP
     delete -q $field\_out
   end
@@ -82,6 +83,27 @@
   # find matching entries in smf file 
   for i 0 $warpMask:n
-    get.warp.mask.stats $warpMask:$i
-
+    if ("$warpCMF:$i" == "") 
+      echo "no CMF file found for $i, skipping" 
+      continue
+    end
+    get.warp.detect.stats $warpCMF:$i
+  
+    if ("c" == "") 
+      echo "no mask file found for $i, skipping maskstats" 
+      set Q1ref_onchp = zero(Xref_onchp) + NAN
+    else
+      get.warp.mask.stats $warpMask:$i
+    end
+
+    # only append if the FITS table has any entries
+    data $warpCMF:$i
+    read -fits SkyChip.psf -sizes
+    if ($table:Ny >= 1) 
+      foreach field $SMF_FIELDS_WRP
+        concat $field\_found $field\_out
+        delete $field\_found
+      end
+    end
+    
     foreach field $REF_FIELDS_WRP $XTR_FIELDS_WRP
       concat $field\_onchp $field\_out
@@ -91,5 +113,5 @@
 
   $OUT_FIELDS = 
-  foreach field $REF_FIELDS_WRP $XTR_FIELDS_WRP
+  foreach field $SMF_FIELDS_WRP $REF_FIELDS_WRP $XTR_FIELDS_WRP
     $OUT_FIELDS = $OUT_FIELDS $field\_out
   end
@@ -97,4 +119,67 @@
   sprintf output "%s/%s.%s.wrp.stf" $OUTDIR $expname $OUTVERSION
   write -fits DATA $output $OUT_FIELDS
+end
+
+macro get.warp.detect.stats
+  if ($0 != 2) 
+   echo "USAGE: get.warp.detect.stats (cmffile)"
+   echo "  assumes existence of vectors (Rref, Dref, Mref)"
+   echo "  matches known sources to detections in the cmf file"
+   echo "  calculates detection fraction as a function of magnitude"
+   echo "  also astrometric and photometric scatter vs magnitude for good detections"
+   break
+  end
+
+  local filename NAXIS1 NAXIS2
+  $filename = $1
+  if ("$filename" == "") 
+    echo "missing CMF file $filename, skipping"
+    return
+  end
+
+  # read in the image header portion
+  # rd -n SkyChip.hdr hdr $filename
+  # XXX apparently the warp cmf files have the hdr as the PHU?
+  rd hdr $filename
+  keyword hdr IMNAXIS1 NAXIS1
+  keyword hdr IMNAXIS2 NAXIS2
+
+  coords -q hdr -p       0       0; init.radec.range
+  coords -q hdr -p $NAXIS1       0; set.radec.range
+  coords -q hdr -p $NAXIS1 $NAXIS2; set.radec.range
+  coords -q hdr -p       0 $NAXIS2; set.radec.range
+
+  # generate a subset which could be on this skycell
+  # do we need to grow the range at all?
+  set keep = (Rref >= $minR) && (Rref <= $maxR) && (Dref >= $minD) && (Dref <= $maxD) 
+  foreach field $REF_FIELDS_WRP Nref
+    subset $field\_tmp = $field if keep
+  end
+
+  # convert the subset coordinates to pixels
+  set Xref_tmp = Rref_tmp
+  set Yref_tmp = Dref_tmp
+  coords -q hdr -c Xref_tmp Yref_tmp
+
+  # generate a subset of sources which are within the boundaries of the skycell
+  set keep = (Xref_tmp >= 0) && (Xref_tmp <= $NAXIS1) && (Yref_tmp >= 0) && (Yref_tmp <= $NAXIS2)
+  foreach field $REF_FIELDS_WRP Nref Xref Yref
+    subset $field\_onchp = $field\_tmp if keep
+    delete $field\_tmp
+  end
+
+  # now read the smf detections
+  data $filename
+  # first check if the FITS table has any entries
+  read -fits SkyChip.psf -sizes
+  if ($table:Ny >= 1) 
+    read -fits SkyChip.psf $SMF_FIELDS_WRP
+
+    match2d Xref_onchp Yref_onchp X_PSF Y_PSF $MATCH_RADIUS -closest
+    foreach field $SMF_FIELDS_WRP
+      reindex $field\_found = $field using index1 -keep-unmatched
+    end
+  end
+
 end
 
@@ -187,4 +272,5 @@
   echo "USAGE: get.warp.mask.files"
   echo " uses warpPath:0 - warpPath:n"
+  echo " sets warpCMF:0  - warpCMF:n"
   break
  end
@@ -194,6 +280,15 @@
    sprintf filename "%s.mask.fits" $warpPath:$i
    $warpMask:$i = `neb-locate -p $filename`
-   if ($VERBOSE) echo "found warpPath $warpMask:$i"
-   if ($COPYMASKS) exec neb-copy $filename $OUTDIR
+   break -auto on
+   if ("$warpMask:$i" == "")
+     echo "skipping $filename"
+   else 
+     if ($COPYMASKS) exec neb-copy $filename $OUTDIR
+   end
+
+   sprintf filename "%s.cmf" $warpPath:$i
+   $warpCMF:$i  = `neb-locate -p $filename`
+   
+   if ($VERBOSE) echo "found mask: $warpMask:$i CMF: $warpCMF:$i"
  end
  $warpMask:n = $warpPath:n
