Index: /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.parallel.dvo
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.parallel.dvo	(revision 33287)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/addstar/test/relphot.parallel.dvo	(revision 33288)
@@ -11,4 +11,5 @@
 # set various global variables
 macro init
+  echo "starting init..."
   $RA_CENTER = 10.0
   $DEC_CENTER = 20.0
@@ -22,4 +23,5 @@
   $CHIP_DX = 1000
   $CHIP_DY = 1000
+  if (not($?VERBOSE)) set VERBOSE = 0
 
   # images are loaded into dvo with GPC1 photcodes, so we need to get the nominal zps for those filters
@@ -44,13 +46,14 @@
   # mjd and zpt values for not-ubercal'ed images
   $filt_nc:n = 9
-  $filt_nc:0 = g
-  $filt_nc:1 = g
-  $filt_nc:2 = g
-  $filt_nc:3 = r
-  $filt_nc:4 = r
-  $filt_nc:5 = r
-  $filt_nc:6 = i
-  $filt_nc:7 = i
-  $filt_nc:8 = i
+  create filtN_nc 0 $filt_nc:n
+  $filt_nc:0 = g;  filtN_nc[0] = 1
+  $filt_nc:1 = g;  filtN_nc[1] = 1
+  $filt_nc:2 = g;  filtN_nc[2] = 1
+  $filt_nc:3 = r;  filtN_nc[3] = 2
+  $filt_nc:4 = r;  filtN_nc[4] = 2
+  $filt_nc:5 = r;  filtN_nc[5] = 2
+  $filt_nc:6 = i;  filtN_nc[6] = 3
+  $filt_nc:7 = i;  filtN_nc[7] = 3
+  $filt_nc:8 = i;  filtN_nc[8] = 3
 
   # airmass slopes for these sequnece
@@ -66,4 +69,9 @@
   # ubercal zero points are defined as ZP_nominal + 2.5log(exptime) + K*(airmass - 1.0)
   set zpt_nc = 25.0 + 2.5*log(exptime_nc) + klam_nc*(airmass_nc - 1.0) - tmpseq*0.0050 + 0.0025
+
+  # without an ubercal or other tie, relphot should set zpts to the mean of the zpts for a filter
+  subset tmp = zpt_nc where filtN_nc == 1; vstat -q tmp; set zpt_nc_g = $MEAN
+  subset tmp = zpt_nc where filtN_nc == 2; vstat -q tmp; set zpt_nc_r = $MEAN
+  subset tmp = zpt_nc where filtN_nc == 3; vstat -q tmp; set zpt_nc_i = $MEAN
 
   set mjd_nc = zero(zpt_nc)
@@ -106,13 +114,27 @@
   end
 
-  # run relphot on the db and check that the images now match the expected values
-  exec relphot g,r,i -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 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& tmp.log
+  # parallel-ize the database
+  mkparallel $catdir
+
+  # run relphot on the serial db and check that the images now match the expected values
+  exec relphot g,r,i -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 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.s0
 
   for i 0 mjd_nc[]
-    # XXX this is a little ill-defined : if we run relphot with no tied down data, we should convert 
-    # on a solution with zero points matching the mean zp of photometric data (hence the choice of element
-    # 1 in the zpt_nc[] array below.
-    ckexposure $catdir mjd_nc[$i] zpt_nc[1] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
-    # ckexposure $catdir mjd_nc[$i] zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] $filt_nc:$i raw
+    # this is a little ill-defined : if we run relphot with no tied
+    # down data, we should convert on a solution with zero points
+    # matching the mean zp of photometric data, which we calculate in
+    # 'init'
+    ckexposure $catdir mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
+  end
+
+  # run relphot on the parallel db and check that the images now match the expected values
+  exec relphot -parallel-serial g,r,i -v -region 9.5 10.5 19.5 20.5 -D CATDIR $catdir.p0 -D STAR_TOOFEW 1 -D SIGMA_LIM 0.07 -statmode WT_MEAN -cloud-limit 0.5 -keep-ubercal -D IMAGE_OFFSET 0.5 -update >& log.relphot.p0
+
+  for i 0 mjd_nc[]
+    # this is a little ill-defined : if we run relphot with no tied
+    # down data, we should convert on a solution with zero points
+    # matching the mean zp of photometric data, which we calculate in
+    # 'init'
+    ckexposure $catdir.p0 mjd_nc[$i] $zpt_nc_$filt_nc:$i exptime_nc[$i] airmass_nc[$i] $filt_nc:$i relphot_nc
   end
 
@@ -206,5 +228,5 @@
 
   $ZPT_REAL_NORM = $ZPT_REAL - 2.5*log($EXPTIME) - $KLAM_NOMINAL*($AIRMASS - 1.0)
-  echo "$ZPT_REAL_NORM = $ZPT_REAL - 2.5*log($EXPTIME) - $KLAM_NOMINAL*($AIRMASS - 1.0)"
+  if ($VERBOSE) echo "$ZPT_REAL_NORM = $ZPT_REAL - 2.5*log($EXPTIME) - $KLAM_NOMINAL*($AIRMASS - 1.0)"
 
   if ("$MODE" == "raw") 
@@ -236,5 +258,5 @@
   if ("$MODE" == "relphot_nc") 
     vstat -q dm
-    tapOK {abs($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM) < 0.005} "setphot_nc  ZP $MJD_IMAGE $FILTER : $MEAN $ZPT_NOMINAL $ZPT_REAL_NORM {($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM)}"
+    tapOK {abs($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM) < 0.005} "relphot_nc  ZP $MJD_IMAGE $FILTER : $MEAN $ZPT_NOMINAL $ZPT_REAL_NORM {($MEAN - $ZPT_NOMINAL + $ZPT_REAL_NORM)}"
     return
   end
@@ -254,4 +276,5 @@
   end
 
+  echo "starting mksequence..."
   local i T1 T2
 
@@ -259,8 +282,9 @@
   # we have a second set of mjd and zero point values for non-ubercal'ed images
   for i 0 mjd_nc[]
+    echo -no-return "$i.. "
     mkexposure $1.nc.$i $RA_CENTER $DEC_CENTER zpt_nc[$i] exptime_nc[$i] airmass_nc[$i] mjd_nc[$i] $filt_nc:$i $2
   end
   ctimes -abs now -var T2
-  echo "elapsed: {86400*($T2 - $T1)}"
+  echo "done ({86400*($T2 - $T1)} sec)"
 end
 
@@ -293,5 +317,5 @@
     $dec = $DECo - $dy / 3600.0
     # echo $ra $dec $dx $dy
-    echo mkinput test.in.txt $ra $dec $ZPT 
+    if ($VERBOSE) echo mkinput test.in.txt $ra $dec $ZPT 
     mkinput test.in.txt $ra $dec $ZPT 
     # costs 7/36 sec / chip
@@ -309,10 +333,10 @@
     $options = $options -airmass $AIRMASS
     $options = $options -exptime $EXPTIME
+    if ($VERBOSE) echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options 
     exec mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options
-    echo mkcmf test.in.txt $ROOT.$ix.$iy.cmf $options 
     # costs 8/36 sec / chip
 
     # the fake images have inconsistent ra,dec and airmass,sidtime values
-    echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
+    if ($VERBOSE) echo addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass
     exec addstar $ROOT.$ix.$iy.cmf -D CATDIR $CATDIR -D CAMERA gpc1 -quick-airmass >& /dev/null
     # costs 10/36 sec / chip
@@ -373,4 +397,5 @@
   end
 
+  echo "starting mkstars..."
   local RA_RANGE DEC_RANGE
 
@@ -387,40 +412,30 @@
 end
 
-# create a populated catdir with a couple of cmf files
-macro test.relphot
-  if ($0 != 3)
-    echo "test.relphot (cmftype) (dvotype)"
-    break
-  end
-
-  tapPLAN 4
-
-  exec rm -rf catdir.test
-
-  $RA = 10.0
-  $DEC = 20.0
-
-  for i 0 $offset:n
-    mkinput test.in.txt $offset:$i
-    exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time $i\:00:00 -radec $RA $DEC -type $1
-    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2
-  end
-
-  exec relphot -D CATDIR catdir.test r -region {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} -update -nloop 10.0 >& /dev/null
-
-  catdir catdir.test
-  skyregion {$RA-1.0} {$RA+1.0} {$DEC-1.0} {$DEC+1.0} 
-
-  imextract time Mcal
-
-  for i 0 $offset:n
-    tapOK {abs(Mcal[$i] - Mcal[0] - $offset:$i) < 0.001} "Mcal $i"
-  end
-
-  exec rm test.cmf test.in.txt
-  exec rm -r catdir.test
-
-  tapDONE
-end
-
-# running setphot: setphot testzpt.fits -update -ubercal -D CATDIR catdir.test
+# copy the catdir to catdir.p0 and parallelize to local directories catdir.d1 - catdir.d3
+macro mkparallel
+  if ($0 != 2)
+    echo "USAGE: mkparallel (catdir)"
+    break
+  end
+
+  local hostname catdir
+ 
+  $hostname = `hostname -s`
+
+  $tmp1 = `dirname $1`
+  $tmp2 = `basename $1`
+  $catdir = $tmp1/$tmp2
+
+  exec rsync -auv $catdir/ $catdir.p0/
+  mkdir $catdir.d1
+  mkdir $catdir.d2
+  mkdir $catdir.d3
+  
+  exec rm -f $catdir.p0/HostTable.dat
+  exec echo "1 $hostname $catdir.d1" >  $catdir.p0/HostTable.dat
+  exec echo "2 $hostname $catdir.d2" >> $catdir.p0/HostTable.dat
+  exec echo "3 $hostname $catdir.d3" >> $catdir.p0/HostTable.dat
+
+  exec dvodist -out $catdir.p0
+end
+
