Index: /branches/eam_branches/ipp-20150419/Ohana/src/addstar/test/relphot.flatcorr.dvo
===================================================================
--- /branches/eam_branches/ipp-20150419/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 38309)
+++ /branches/eam_branches/ipp-20150419/Ohana/src/addstar/test/relphot.flatcorr.dvo	(revision 38310)
@@ -21,7 +21,9 @@
 if (not($?PLOT)) set PLOT = 0
 
-$USE_CELL_OFFSETS = 1; # turn on non-zero cell offsets
+$USE_CELL_OFFSETS = 0; # turn on non-zero cell offsets
 $SET_UC_RESID = 1; # write a non-zero resid value to the ubercal table (should not have an impact)
-
+$DO_2MASS = 0
+$DO_SYNTH = 0
+$DO_TYCHO = 0
 
 # set various global variables
@@ -68,4 +70,5 @@
     echo "2011  2MASS_J              ref   0.000  0.000 0.000     -     - 0.0000     0     6   0.080 0.000 2.000  0.000   0x0000 0x0000  0x0000 0x0000"
     echo "3001  SYNTH.g              ref   0.000  0.000 0.000     -     - 0.0000     0     1     nan 0.000 2.000  0.600   0x0000 0x0000  0x0000 0x0000"
+    echo "2020  TYCHO_B              ref   0.000  0.000 0.000     -     - 0.0000     0     -   0.000 0.000 0.000  0.000   0x0000 0x0000  0x0000 0x0000"
   output stdout      
 
@@ -162,5 +165,5 @@
   mk2mass $fileroot $catdir
   ck2mass addstar
-
+  
   mksynth $fileroot $catdir
   cksynth addstar
@@ -169,5 +172,4 @@
   mktycho $fileroot $catdir
   cktycho addstar
-  break
 
   tapPLAN {((mjd_uc[]*4 + mjd_nc[]*4) + (mjd_uc[] + mjd_nc[]) + (mjd_uc[] + mjd_nc[])) / 3}
@@ -192,5 +194,5 @@
 
   # run relphot on the db and check that the images now match the expected values
-  tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update
+  tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update -synthphot_zpts $fileroot.synthzpts.fits
   for i 0 mjd_uc[]
     ckexposure $catdir mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot
@@ -202,4 +204,16 @@
 
   tapDONE
+end
+
+macro try.relphot
+  # run relphot on the db and check that the images now match the expected values
+  # tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $1 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update -synthphot_zpts $fileroot.synthzpts.fits
+  tapEXEC relphot -images g,r -v -region 9.5 10.5 19.5 20.5 -D CATDIR $1 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -D IMAGE_OFFSET 0.5 -update
+  for i 0 mjd_uc[]
+    ckexposure $1 mjd_uc[$i] zpt_uc[$i] exptime_uc[$i] airmass_uc[$i] $filt_uc:$i relphot
+  end
+  for i 0 mjd_nc[]
+    ckexposure $1 mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot
+  end
 end
 
@@ -281,4 +295,8 @@
     dev -n 1
     lim mag dm; clear; box; plot mag dm; plot -c red -pt 7 mag dm where (photflags & 0x00000002)
+    dev -n 2
+    lim xccd dm; clear; box; plot xccd dm; plot -c red -pt 7 xccd dm where (photflags & 0x00000002)
+    dev -n 3
+    lim ra dm; clear; box; plot ra dm; plot -c red -pt 7 ra dm where (photflags & 0x00000002)
     echo "red points are known bad photometry"
   end
@@ -357,5 +375,6 @@
     vstat -q dm_good
     sprintf line "relphot     ZP %8.2f $FILTER %6.3f %6.3f %6.3f: %7.4f %7.4f : %3d" $MJD_IMAGE $ZPT_REAL $ZPT_REAL_NORM $ZPT_NOMINAL $MEAN $SIGMA dm_good[]
-    tapOK {abs($MEAN) < 0.005} "$line"
+    tapOK {abs($MEAN) < 0.001} "$line"
+    tapOK {abs($SIGMA) < 0.001} "$line"
 
     mextract ra dec dbflags
@@ -558,4 +577,6 @@
   end
 
+  if (not($DO_2MASS)) return
+
   local ROOT CATDIR
 
@@ -580,4 +601,6 @@
     break
   end
+
+  if (not($DO_2MASS)) return
 
   if ("$1" == "addstar") 
@@ -612,4 +635,6 @@
   end
 
+  if (not($DO_SYNTH)) return
+
   local ROOT CATDIR
 
@@ -634,4 +659,6 @@
   end
 
+  if (not($DO_SYNTH)) return
+
   if ("$1" == "addstar") 
     skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2} 
@@ -659,4 +686,6 @@
   end
 
+  if (not($DO_TYCHO)) return
+
   local ROOT CATDIR
 
@@ -672,15 +701,17 @@
   write $ROOT.tycho.dat -f "%10.6f %10.6f %6.3f %6.3f 0x%x" r_tycho d_tycho m_tycho dm_tycho fl_tycho
 
-  tapEXEC addstar -ref $ROOT.tycho.dat -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass -photcode TYCHO.g
-
-  $KAPA = kapa -noX
+  tapEXEC addstar -ref $ROOT.tycho.dat -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass -photcode TYCHO_B
+
+  # $KAPA = kapa -noX
   dev -n tmpdev
-  section default -imtool none
+  # resize 100 100
   resize 50 50
   region $RA_CENTER $DEC_CENTER 0.2
+  section default -imtool none
+  # causes trouble for this to come before region...
   create tmp 0 1
   cdensify tmpmap tmp tmp
   set map = zero(tmpmap) + 0.2
-  close
+  # close
   $KAPA = kapa
 
@@ -701,7 +732,9 @@
   end
 
+  if (not($DO_TYCHO)) return
+
   if ("$1" == "addstar") 
     skyregion {$RA_CENTER - 0.2/dcos($DEC_CENTER)} {$RA_CENTER + 0.2/dcos($DEC_CENTER)} {$DEC_CENTER - 0.2} {$DEC_CENTER + 0.2} 
-    mextract ra dec mag xccd yccd dbflags photflags where (photcode == 3001)
+    mextract ra dec mag xccd yccd dbflags photflags where (photcode == 2020)
     tapOK {ra[] == r_tycho[]} "read in as many tycho stars as we generated"
     
@@ -712,6 +745,6 @@
 
   if ("$1" == "relphot")
-    subset rs = r_tycho if (m_tycho < 13.5)
-    subset ds = d_tycho if (m_tycho < 13.5)
+    subset rs = r_tycho if (m_tycho < 12)
+    subset ds = d_tycho if (m_tycho < 12)
     avmatch rs ds 0.1 g:flags
     subset tmp = rs if (g:flags & 0x04); # tycho used for photometry
