Index: trunk/ippToPsps/test/mksasdata.dvo
===================================================================
--- trunk/ippToPsps/test/mksasdata.dvo	(revision 35097)
+++ trunk/ippToPsps/test/mksasdata.dvo	(revision 37246)
@@ -4,10 +4,24 @@
 
 if (not($?VERBOSE)) set VERBOSE = 0
+if (not($?PARALLEL)) set PARALLEL = 0
 
-$OUTDIR = sas12
+$OUTDIR = sasdata
+
+if (not($?KEEPDVO)) set KEEPDVO = 0
+
+list expfiles
+  sasdata/o5745g0495o.356867.cm.982612
+  sasdata/o5745g0507o.356882.cm.982626
+  sasdata/o5745g0517o.356892.cm.982636
+  sasdata/o5745g0527o.356909.cm.982650
+end
 
 macro mkfull
   init.db
-  mkcatdir
+  mkcatdir.cam
+  mkcatdir.stk
+  mkcal
+  mkgpc1.cam
+  mkgpc1.stk
 end
 
@@ -18,12 +32,8 @@
   $dbpass = dvo
 
-  # exposure center
-  $RA = 333.8
-  $DEC = 1.6
-
-  # stack center
-  # XXX the selected stack centers come from the input exposures, so I should use a gpc1 db with stacks associated with real exposures
-  $RA = 331.6
-  $DEC = -6.0
+  # are these used to find the exposures in any way?
+  # center of the test skycell
+  $RA = 333.5
+  $DEC = -5.0
 
   break -auto off
@@ -36,9 +46,9 @@
   # system-wide info
   dbinsert ippToPspsFake (my_id) values (2)
-  dbinsert skycell (radeg, decdeg, skycell_id) values ($RA, $DEC, "skycell.0000.000")
+  dbinsert skycell (radeg, decdeg, skycell_id) values ($RA, $DEC, "skycell.1225.070")
 end
 
 # create a populated catdir with a set of cmf files, save the filenames in list for use by insert.exp
-macro mkcatdir
+macro mkcatdir.cam
   if ($0 != 1)
     echo "mkcatdir"
@@ -49,44 +59,122 @@
 
   local catdir
-  $catdirbase = catdir.sas12
+  $catdirbase = catdir.sas.cam
+  $catdir = $OUTDIR/$catdirbase
+
+  exec rm -rf $catdir
+
+  for i 0 $expfiles:n
+    $expfile = $expfiles:$i
+
+    exec addstar -D CAMERA gpc1 -D CATDIR $catdir -D CATFORMAT PS1_V5 $expfile.smf -update
+  end
+  exec addstar -D CATDIR $catdir -region 330 340 -10 0 -resort
+end
+
+# create a populated catdir with a set of cmf files, save the filenames in list for use by insert.exp
+macro mkcatdir.stk
+  if ($0 != 1)
+    echo "mkcatdir"
+    break
+  end
+
+  mkdir $OUTDIR
+
+  local catdir
+  $catdirbase = catdir.sas.stk
   $catdir = $OUTDIR/$catdirbase
   exec rm -rf $catdir
 
-  $expfile = sas12.test.psps/o5745g0620o.356996.cm.473458
-  exec addstar -D CAMERA gpc1 -D CATDIR $catdir $expfile.smf
+  # a single stack
+  $stkfile = sasdata/RINGS.V3.skycell.1225.070.stk.3366216.skycal.1589960
+  exec addstar -D CAMERA gpc1 -D CATFORMAT PS1_V5 -D CATDIR $catdir $stkfile.cmf
+end
 
-  # are these used to find the exposures in any way?
-  $RA = 333.8
-  $DEC = 1.6
+macro mkcal
 
-  # a single exposure
-  $expID = 1
-  dbinsert rawExp (exp_id, exp_name, exp_time, bg, bg_stdev, ra, decl) values ($expID, "o5745g0620o", 10.0, 100.0, 2.0, {$RA*3.1415/180.0}, {$DEC*3.1415/180.0})
-  dbinsert chipRun (exp_id, chip_id) values ($expID, $expID)
-  dbinsert camRun (chip_id, cam_id, dist_group, software_ver) values ($expID, $expID, "testgroup", "testsoft")
-  dbinsert camProcessedExp (cam_id, path_base) values ($expID, "$expfile")
-  dbinsert fakeRun (fake_id, cam_id) values ($expID, $expID)
-  dbinsert warpRun (warp_id, fake_id) values ($expID, $expID)
-  dbinsert warpSkyCellMap (warp_id, skycell_id, class_id) values ($expID, "skycell.0000.000", "XY00")
-  dbinsert addRun (stage, state, stage_id, minidvodb_name) values ("cam", "full", $expID, "$catdirbase")
+  local catdir
+  $catdir = $OUTDIR/catdir.sas.cam
+
+  # merge the cam and stk databases together:
+  exec dvomerge $OUTDIR/catdir.sas.stk into $catdir
+
+  # run relphot
+  echo relphot -D CATDIR $catdir -region 330 340 -10 0 -images g,r,i,z,y -update -boundary-tree tess.3pi.fits
+  exec relphot -D CATDIR $catdir -region 330 340 -10 0 -images g,r,i,z,y -update -boundary-tree tess.3pi.fits
+
+  echo relastro -v -D CATDIR $catdir -images -update-chips -region 330 340 -10 0 -update
+  exec relastro -v -D CATDIR $catdir -images -update-chips -region 330 340 -10 0 -update
+end
+
+# create a populated catdir with a set of cmf files, save the filenames in list for use by insert.exp
+macro mkgpc1.cam
+  if ($0 != 1)
+    echo "mkgpc1.cam"
+    break
+  end
+
+  local catdirbase
+  $catdirbase = catdir.sas.cam
+
+  for i 0 $expfiles:n
+    $expfile = $expfiles:$i
+
+    # are these used to find the exposures in any way?
+    $RA = 333.9
+    $DEC = -3.8
+
+    # a single exposure
+    $expID = $i + 1
+    substr $expfile 8 11 expname
+
+    dbinsert rawExp (exp_id, exp_name, exp_time, bg, bg_stdev, ra, decl, dateobs) values ($expID, "$expname", 10.0, 100.0, 2.0, {$RA*3.1415/180.0}, {$DEC*3.1415/180.0}, "2010/01/01 00:00:00")
+    dbinsert chipRun (exp_id, chip_id) values ($expID, $expID)
+    dbinsert camRun (chip_id, cam_id, dist_group, software_ver) values ($expID, $expID, "testgroup", "38000M")
+    dbinsert camProcessedExp (cam_id, path_base, fault) values ($expID, "$expfile", 0)
+    dbinsert fakeRun (fake_id, cam_id) values ($expID, $expID)
+    dbinsert warpRun (warp_id, fake_id) values ($expID, $expID)
+    dbinsert warpSkyCellMap (warp_id, skycell_id, class_id) values ($expID, "skycell.1225.070", "XY00")
+    dbinsert addRun (add_id, stage, state, stage_id, minidvodb_name) values ($expID, "cam", "full", $expID, "$catdirbase")
+    dbinsert addProcessedExp (add_id, fault) values ($expID, 0)
+    
+    # catdirs for the exposures
+    dbinsert minidvodbRun (minidvodb_name, minidvodb_id, state) values ("$catdirbase", 1, "merged")
+    dbinsert minidvodbProcessed (minidvodb_id, fault) values (1, 0)
+    
+    dbinsert mergedvodbRun (minidvodb_id, merge_id, state, mergedvodb) values (1, 1, "full", "$catdirbase")
+    dbinsert mergedvodbProcessed (merge_id, fault) values (1, 0)
+  end
+end
+
+# create a populated catdir with a set of cmf files, save the filenames in list for use by insert.exp
+macro mkgpc1.stk
+  if ($0 != 1)
+    echo "mkgpc1.stk"
+    break
+  end
+
+  local catdirbase
+  $catdirbase = catdir.sas.cam
+
+  $TIMEFORMAT = mjd
+  $TIMEREF = 2001/01/01,00:00:00
+  ctimes -abs 2010/01/01,00:00:00 -var mjd
 
   # a single stack
-  $stkfile = sas12.test.psps/RINGS.V3.skycell.1225.070.stk.1032983.skycal.40531
-  exec addstar -D CAMERA gpc1 -D CATDIR $catdir $stkfile.cmf
+  $stkfile = sasdata/RINGS.V3.skycell.1225.070.stk.3366216.skycal.1589960
 
-  $stkID = 1
-  dbinsert stackRun (stack_id, skycell_id, filter, software_ver) values ($stkID, "skycell.0000.000", "g.00000", "testsoft")
+  break -auto off
+  $tmpline = `echo $stkfile.cmf | fields IMAGEID`
+  list words -split $tmpline
+  $stkID = $words:1
+  break -auto on
+
+  $expID = 1
+  dbinsert stackRun (stack_id, skycell_id, filter, software_ver) values ($stkID, "skycell.1225.070", "i.00000", "37500M")
   dbinsert stackInputSkyfile (stack_id, warp_id) values ($stkID, $expID)
-  dbinsert stackSumSkyfile (stack_id) values ($stkID)
-  dbinsert skycalRun (skycal_id, stack_id) values ($stkID, $stkID)
+  dbinsert stackSumSkyfile (stack_id, mjd_obs) values ($stkID, $mjd)
+  dbinsert skycalRun (sky_id, skycal_id, stack_id) values ($stkID, $stkID, $stkID)
   dbinsert skycalResult (skycal_id, path_base) values ($stkID, "$stkfile")
   dbinsert addRun (stage, state, stage_id, minidvodb_name) values ("skycal", "full", $stkID, "$catdirbase")
-
-  # catdirs for the exposures
-  dbinsert minidvodbRun (minidvodb_name, minidvodb_id, state) values ("$catdirbase", 1, "merged")
-  dbinsert minidvodbProcessed (minidvodb_id, fault) values (1, 0)
-  
-  dbinsert mergedvodbRun (minidvodb_id, merge_id, state, mergedvodb) values (1, 1, "full", "$catdirbase")
-  dbinsert mergedvodbProcessed (merge_id, fault) values (1, 0)
 
   # catdirs for the stack
