Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 33138)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 33139)
@@ -85,15 +85,25 @@
 
 macro ckexposure
+  if ($0 != 3)
+    echo "ckexposure (catdir) (zpt)"
+    break
+  end
+
+  local ZPT_REAL ZPT_NOMINAL
+  
+  $ZPT_REAL = $2
+  $ZPT_NOMINAL = 24.58
+  # XXX need a function to extract the nominal zpt for a given filter / photcode
 
   # assume we still have stars_ra, stars_dec, stars_mag in hand
-  catdir catdir.test
+  catdir $1
   region $RA_CENTER $DEC_CENTER 0.2
   images
   pmeasure -all -m 15 20
-  mextract -region ra dec mag
+  mextract -region ra dec mag xccd yccd
  
   match2d -closest ra dec stars_ra stars_dec 0.001 -index1 index1 -index2 index2
 
-  reindex stars_ra_m = stars_ra using index1
+  reindex stars_ra_m  = stars_ra  using index1
   reindex stars_dec_m = stars_dec using index1
   reindex stars_mag_m = stars_mag using index1
@@ -102,4 +112,27 @@
   set dm = mag - stars_mag_m
   lim mag dm; clear; box; plot mag dm
+
+  set cell_xbin = int(xccd / ($CHIP_DX / $NCELL_X))
+  set cell_ybin = int(yccd / ($CHIP_DY / $NCELL_Y))
+  subset dm00 = dm if (cell_xbin == 0) && (cell_ybin == 0)
+  subset dm01 = dm if (cell_xbin == 0) && (cell_ybin == 1)
+  subset dm10 = dm if (cell_xbin == 1) && (cell_ybin == 0)
+  subset dm11 = dm if (cell_xbin == 1) && (cell_ybin == 1)
+
+  # mag_DVO  = m_inst + zpt_nominal
+  # mag_real = m_inst + zpt_real + cell_offset
+  # dm = mag_DVO - mag_real = zpt_nominal - zpt_real - cell_offset
+  # <dm> - zpt_nominal + zpt_real + cell_offset ~ 0.0
+  # zpt_real (in this case) = 25.0 (actually, it is the value in the vector 'zpt' for this entry
+  # zpt_nominal = 24.58
+  for ix 0 $NCELL_X
+    for iy 0 $NCELL_Y
+      # vstat -q dm$ix\$iy
+      # echo cell_off[$ix][$iy] {$MEDIAN - $ZPT_NOMINAL + $ZPT_REAL + cell_off[$ix][$iy]} $MEDIAN $MEAN $SIGMA 
+
+      set dm_adjust = dm$ix\$iy - $ZPT_NOMINAL + $ZPT_REAL + cell_off[$ix][$iy]
+      vstat dm_adjust
+    end
+  end
 end
 
@@ -154,5 +187,6 @@
     echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf -mjd $MJD -radec $ra $dec -type PS1_V2 -coords -photcode GPC1.$FILTER.XY$ix\$iy -no-noise -size $CHIP_DX $CHIP_DY -crpix {0.5*$CHIP_DX} {0.5*$CHIP_DY} 
     
-    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $7 -D CAMERA gpc1
+    # the fake images have inconsistent ra,dec and airmass,sidtime values
+    exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $7 -D CAMERA gpc1 -quick-airmass
   end
  end
@@ -224,5 +258,5 @@
   keyword phu NFILTER -wd $NFILTER
   keyword phu NCHIP_X -wd $NCHIP_X
-  keyword phu NCHIP_y -wd $NCHIP_Y
+  keyword phu NCHIP_Y -wd $NCHIP_Y
   keyword phu NCELL_X -wd $NCELL_X
   keyword phu NCELL_Y -wd $NCELL_Y
