#!/bin/csh -f

set dbuser = 'dvo'
set dbpass = '-pdvo'
# set dbuser = 'czw'
# set dbpass = '-pczw'

chmod +x mkgpc1data.dvo mkgpc1.sh

# a bit crude : get the datadir path by interpolation of the PATH element for psconfig
foreach f ( `echo $PATH | tr : ' '` )
  echo $f | grep $PSCONFDIR > /dev/null
  if ($status) continue
  set datadir = `echo $f | sed s/bin\$/share/`
  break
end
setenv IPPTOPSPS_DATA $datadir/ipptopsps

# before running this test, you must have a mysql user:
# mkgpc1.sh user localhost eam eam

set mkgpc1         = 1
set initdb         = 1
set initscratch    = 1
set initbatch      = 1
set camqueue       = 1
set cambatch       = 1
set stackqueue     = 1
set stackbatch     = 1
set forcequeue     = 1
set forcebatch     = 1
set objectqueue    = 1
set objectbatch    = 1
set forcedobjqueue = 1
set forcedobjbatch = 1
set diffqueue      = 1
set diffbatch      = 1
set diffobjqueue   = 1
set diffobjbatch   = 1

set options = "-test"

set targ = ($argv)
set args = ""

while ($#targ)
 switch ("$targ[1]")
  case -h
  case -help
    echo "USAGE: fulltest.sh [-XX] [+XX]"
    echo " -XX : turn off features"
    echo " +XX : turn on features"
    echo "  features: all, mkgpc1, initdb, initscratch, initbatch, camera, stack, forcedwarp, object, forcedobject, diff, diffobj"
    exit 2
  case -all
    set mkgpc1       = 0
    set initdb       = 0
    set initscratch  = 0
    set initbatch    = 0
    set camqueue     = 0
    set cambatch     = 0
    set stackqueue   = 0
    set stackbatch   = 0
    set forcequeue   = 0
    set forcebatch   = 0
    set objectqueue  = 0
    set objectbatch  = 0
    set forcedobjqueue = 0
    set forcedobjbatch = 0
    set diffqueue = 0
    set diffbatch = 0
    set diffobjqueue = 0
    set diffobjbatch = 0
    breaksw;
  case -mkgpc1
    set mkgpc1 = 0
    breaksw;
  case -initdb
    set initdb = 0
    breaksw;
  case -initscratch
    set initscratch = 0
    breaksw;
  case -initbatch
    set initbatch = 0
    breaksw;
  case -camera
    set camqueue = 0
    set cambatch = 0
    breaksw;
  case -stack
    set stackqueue = 0
    set stackbatch = 0
    breaksw;
  case -object
    set objectqueue = 0
    set objectbatch = 0
    breaksw;
  case -forcedwarp
    set forcequeue = 0
    set forcebatch = 0
    breaksw;
  case -forcedobject
    set forcedobjqueue = 0
    set forcedobjbatch = 0
    breaksw;
  case -diff
    set diffqueue = 0
    set diffbatch = 0
    breaksw;
  case -diffobj
    set diffobjqueue = 0
    set diffobjbatch = 0
    breaksw;
  case -debug
    set options = "$options -debug"
    breaksw;
  case -stilts
    set options = "$options -stilts"
    breaksw;
  default:
    set args=($args $targ[1]);
    breaksw;
  endsw
  shift targ
end

set targ = ($args)
set args = ""

while ($#targ)
 switch ("$targ[1]")
  case +all
    set mkgpc1       = 1
    set initdb       = 1
    set initscratch  = 1
    set initbatch    = 1
    set camqueue     = 1
    set cambatch     = 1
    set stackqueue   = 1
    set stackbatch   = 1
    set objectqueue  = 1
    set objectbatch  = 1
    set forcequeue   = 1
    set forcebatch   = 1
    set forcedobjqueue = 1
    set forcedobjbatch = 1
    set diffqueue = 1
    set diffbatch = 1
    set diffobjqueue = 1
    set diffobjbatch = 1
    breaksw;
  case +mkgpc1
    set mkgpc1 = 1
    breaksw;
  case +initdb
    set initdb = 1
    breaksw;
  case +initscratch
    set initscratch = 1
    breaksw;
  case +initbatch
    set initbatch = 1
    breaksw;
  case "+camera"
    set camqueue = 1
    set cambatch = 1
    breaksw;
  case +stack
    set stackqueue = 1
    set stackbatch = 1
    breaksw;
  case +object
    set objectqueue = 1
    set objectbatch = 1
    breaksw;
  case +forcedwarp
    set forcequeue = 1
    set forcebatch = 1
    breaksw;
  case +forcedobject
    set forcedobjqueue = 1
    set forcedobjbatch = 1
    breaksw;
  case +diff
    set diffqueue = 1
    set diffbatch = 1
    breaksw;
  case +diffobj
    set diffobjqueue = 1
    set diffobjbatch = 1
    breaksw;
  default:
    set args=($args $targ[1]);
    breaksw;
  endsw
  shift targ
end

if ($args[1] != "") then
    echo "USAGE: fulltest.sh [-XX] [+XX]"
    echo " -XX : turn off features"
    echo " +XX : turn on features"
    echo "  features: all, mkgpc1, initdb, initscratch, initbatch, camera, object, stack, forcedwarp, forcedobject, diff, diffobj"
    exit 2
endif

set OUTDIR = "testdata"
set queuename = "test"
set stackqueuename = $queuename\_stk
set objectqueuename = $queuename\_obj
set forcedwarpqueuename = $queuename\_wrp
set forcedobjqueuename = $queuename\_fwo
set diffqueuename = $queuename\_dif
set diffobjqueuename = $queuename\_dio

if ($mkgpc1) then
  echo ""
  echo " ---- mkgpc1data.dvo : creating the dvo & gpc1 database entries ----"
  mkgpc1data.dvo
  if ($status) then
    echo "failed to generate the data & dvo, quitting"
    exit 2
  endif
endif

# create the ipptopsps database
if ($initdb) then 
  echo ""
  echo " ---- init ipptopsps_test ----"

  # does the database already exist?
  # XXX this command will blow away an existing database!!
  mysql -h localhost -u $dbuser $dbpass -e "create database if not exists ipptopsps_test" || exit 3
  mysql -h localhost -u $dbuser $dbpass ipptopsps_test < $IPPTOPSPS_DATA/ippToPspsDbSchema.sql || exit 3
  echo " ---- init ipptopsps_test: done ----"
endif

# re-create the ipptopsps database
if ($initscratch) then 
  echo ""
  echo " ---- init ipptopsps_test_scratch ----"

  # create the database (ignore failure if it already exists)
  mysql -h localhost -u $dbuser $dbpass -e "drop database if exists ipptopsps_test_scratch"
  mysql -h localhost -u $dbuser $dbpass -e "create database ipptopsps_test_scratch"
  echo ippjython setupScratchDb.py $options
       ippjython setupScratchDb.py $options < /dev/null
  if ($status) exit 1
endif

# this is poor : we need to queue something in order to generate an init batch
# this is because a skychunk carries the info about the datastore used to publish
# the batch
if ($initbatch) then
  echo ""
  echo " ---- queue IN batch ----"

  echo "initbatch              " >  initbatch.dat # skychunk name
  echo "test_ds                " >> initbatch.dat # datastore_product
  echo "IPP_PSPS               " >> initbatch.dat # datastore_type
  echo "0                      " >> initbatch.dat # datastore_publish
  echo "init                   " >> initbatch.dat # dvo_label
  echo "none                   " >> initbatch.dat # dvo_location
  echo "0                      " >> initbatch.dat # min_ra
  echo "0                      " >> initbatch.dat # max_ra
  echo "0                      " >> initbatch.dat # min_dec
  echo "0                      " >> initbatch.dat # max_dec
  echo "2                      " >> initbatch.dat # box_size
  echo "$OUTDIR                " >> initbatch.dat # base_path
  echo "0                      " >> initbatch.dat # data_release
  echo "0                      " >> initbatch.dat # delete_local
  echo "1                      " >> initbatch.dat # delete_datastore
  echo "1                      " >> initbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0  " >> initbatch.dat # epoch
  echo "3PI                    " >> initbatch.dat # survey
  echo "3PI                    " >> initbatch.dat # psps_survey
  echo "0                      " >> initbatch.dat # queue_P2
  echo "0                      " >> initbatch.dat # queue_ST
  echo "0                      " >> initbatch.dat # queue_OB
  echo "0                      " >> initbatch.dat # queue_DF
  echo "0                      " >> initbatch.dat # queue_DO
  echo "0                      " >> initbatch.dat # queue_FW
  echo "0                      " >> initbatch.dat # queue_FO
  echo "1                      " >> initbatch.dat # active
  echo "0                      " >> initbatch.dat # parallel
  echo "use_new                " >> initbatch.dat # P2_smf_version
  echo "any                    " >> initbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0  " >> initbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0  " >> initbatch.dat # trange_end
  ippjython queue.py $options edit < initbatch.dat
  if ($status) exit 1

  echo ""
  echo " ---- create init batch ----"

  rm -rf $OUTDIR/IN

  ippjython loader.py $options initbatch init -simtest < /dev/null
  if ($status) exit 1
endif

############################ P2 batches ################################

# this code is sensitive to a previously existing database?
if ($camqueue) then
  echo ""
  echo " ---- queue P2 batches ----"

  echo "$queuename            " >  cambatch.dat # skychunk name
  echo "test_ds               " >> cambatch.dat # datastore_product
  echo "IPP_PSPS              " >> cambatch.dat # datastore_type
  echo "0                     " >> cambatch.dat # datastore_publish
  echo "catdir.cam            " >> cambatch.dat # dvo_label
  echo "$OUTDIR/catdir.cam    " >> cambatch.dat # dvo_location
  echo "9                     " >> cambatch.dat # min_ra
  echo "11                    " >> cambatch.dat # max_ra
  echo "19                    " >> cambatch.dat # min_dec
  echo "21                    " >> cambatch.dat # max_dec
  echo "2                     " >> cambatch.dat # box_size
  echo "$OUTDIR               " >> cambatch.dat # base_path
  echo "0                     " >> cambatch.dat # data_release
  echo "0                     " >> cambatch.dat # delete_local
  echo "1                     " >> cambatch.dat # delete_datastore
  echo "1                     " >> cambatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> cambatch.dat # epoch
  echo "3PI                   " >> cambatch.dat # survey
  echo "3PI                   " >> cambatch.dat # psps_survey
  echo "1                     " >> cambatch.dat # queue_P2
  echo "0                     " >> cambatch.dat # queue_ST
  echo "0                     " >> cambatch.dat # queue_OB
  echo "0                     " >> cambatch.dat # queue_DF
  echo "0                     " >> cambatch.dat # queue_DO
  echo "0                     " >> cambatch.dat # queue_FW
  echo "0                     " >> cambatch.dat # queue_FO
  echo "1                     " >> cambatch.dat # active
  echo "0                     " >> cambatch.dat # parallel
  echo "use_new               " >> cambatch.dat # P2_smf_version
  echo "any                   " >> cambatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> cambatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> cambatch.dat # trange_end
  ippjython queue.py $options edit -simtest < cambatch.dat
  if ($status) exit 1
endif

if ($cambatch) then
  echo ""
  echo " ---- load P2 batches ----"

  rm -rf $OUTDIR/P2

  ippjython loader.py $options $queuename once -simtest < /dev/null
  if ($status) exit 1
endif

############################ OB batches ################################

# this code is sensitive to a previously existing database?
if ($objectqueue) then
  echo ""
  echo " ---- queue OB batches ----"

  echo "$objectqueuename      " >  objectbatch.dat # skychunk name
  echo "test_ds               " >> objectbatch.dat # datastore_product
  echo "IPP_PSPS              " >> objectbatch.dat # datastore_type
  echo "0                     " >> objectbatch.dat # datastore_publish
  echo "catdir.cam            " >> objectbatch.dat # dvo_label
  echo "$OUTDIR/catdir.cam    " >> objectbatch.dat # dvo_location
  echo "9                     " >> objectbatch.dat # min_ra
  echo "11                    " >> objectbatch.dat # max_ra
  echo "19                    " >> objectbatch.dat # min_dec
  echo "21                    " >> objectbatch.dat # max_dec
  echo "2                     " >> objectbatch.dat # box_size
  echo "$OUTDIR               " >> objectbatch.dat # base_path
  echo "0                     " >> objectbatch.dat # data_release
  echo "0                     " >> objectbatch.dat # delete_local
  echo "1                     " >> objectbatch.dat # delete_datastore
  echo "1                     " >> objectbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> objectbatch.dat # epoch
  echo "3PI                   " >> objectbatch.dat # survey
  echo "3PI                   " >> objectbatch.dat # psps_survey
  echo "0                     " >> objectbatch.dat # queue_P2
  echo "0                     " >> objectbatch.dat # queue_ST
  echo "1                     " >> objectbatch.dat # queue_OB
  echo "0                     " >> objectbatch.dat # queue_DF
  echo "0                     " >> objectbatch.dat # queue_DO
  echo "0                     " >> objectbatch.dat # queue_FW
  echo "0                     " >> objectbatch.dat # queue_FO
  echo "1                     " >> objectbatch.dat # active
  echo "0                     " >> objectbatch.dat # parallel
  echo "use_new               " >> objectbatch.dat # P2_smf_version
  echo "any                   " >> objectbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> objectbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> objectbatch.dat # trange_end
  ippjython queue.py $options edit once -simtest < objectbatch.dat
  if ($status) exit
endif

if ($objectbatch) then
  echo ""
  echo " ---- load OB batches ----"

  rm -rf $OUTDIR/OB

  ippjython loader.py $options $objectqueuename once -simtest < /dev/null
  if ($status) exit
endif

############################ ST batches ################################

# this code is sensitive to a previously existing database?
if ($stackqueue) then
  echo ""
  echo " ---- queue ST batches ----"

  echo "$stackqueuename       " >  stackbatch.dat # skychunk name
  echo "test_ds               " >> stackbatch.dat # datastore_product
  echo "IPP_PSPS              " >> stackbatch.dat # datastore_type
  echo "0                     " >> stackbatch.dat # datastore_publish
  echo "catdir.stk            " >> stackbatch.dat # dvo_label
  echo "$OUTDIR/catdir.stk    " >> stackbatch.dat # dvo_location
  echo "9                     " >> stackbatch.dat # min_ra
  echo "11                    " >> stackbatch.dat # max_ra
  echo "19                    " >> stackbatch.dat # min_dec
  echo "21                    " >> stackbatch.dat # max_dec
  echo "2                     " >> stackbatch.dat # box_size
  echo "$OUTDIR               " >> stackbatch.dat # base_path
  echo "0                     " >> stackbatch.dat # data_release
  echo "0                     " >> stackbatch.dat # delete_local
  echo "1                     " >> stackbatch.dat # delete_datastore
  echo "1                     " >> stackbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> stackbatch.dat # epoch
  echo "3PI                   " >> stackbatch.dat # survey
  echo "3PI                   " >> stackbatch.dat # psps_survey
  echo "0                     " >> stackbatch.dat # queue_P2
  echo "1                     " >> stackbatch.dat # queue_ST
  echo "0                     " >> stackbatch.dat # queue_OB
  echo "0                     " >> stackbatch.dat # queue_DF
  echo "0                     " >> stackbatch.dat # queue_DO
  echo "0                     " >> stackbatch.dat # queue_FW
  echo "0                     " >> stackbatch.dat # queue_FO
  echo "1                     " >> stackbatch.dat # active
  echo "0                     " >> stackbatch.dat # parallel
  echo "use_new               " >> stackbatch.dat # P2_smf_version
  echo "any                   " >> stackbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> stackbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> stackbatch.dat # trange_end
  ippjython queue.py $options edit -simtest < stackbatch.dat
  if ($status) exit 1
endif

if ($stackbatch) then
  echo ""
  echo " ---- load ST batches ----"

  rm -rf $OUTDIR/ST

  ippjython loader.py $options $stackqueuename once -simtest < /dev/null
  if ($status) exit 1
endif

############################ FW batches ################################

# this code is sensitive to a previously existing database?
if ($forcequeue) then
  echo ""
  echo " ---- queue FW batches ----"

  echo "$forcedwarpqueuename  " >  forcebatch.dat # skychunk name
  echo "test_ds               " >> forcebatch.dat # datastore_product
  echo "IPP_PSPS              " >> forcebatch.dat # datastore_type
  echo "0                     " >> forcebatch.dat # datastore_publish
  echo "catdir.wrp            " >> forcebatch.dat # dvo_label
  echo "$OUTDIR/catdir.wrp    " >> forcebatch.dat # dvo_location
  echo "9                     " >> forcebatch.dat # min_ra
  echo "11                    " >> forcebatch.dat # max_ra
  echo "19                    " >> forcebatch.dat # min_dec
  echo "21                    " >> forcebatch.dat # max_dec
  echo "2                     " >> forcebatch.dat # box_size
  echo "$OUTDIR               " >> forcebatch.dat # base_path
  echo "0                     " >> forcebatch.dat # data_release
  echo "0                     " >> forcebatch.dat # delete_local
  echo "1                     " >> forcebatch.dat # delete_datastore
  echo "1                     " >> forcebatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> forcebatch.dat # epoch
  echo "3PI                   " >> forcebatch.dat # survey
  echo "3PI                   " >> forcebatch.dat # psps_survey
  echo "0                     " >> forcebatch.dat # queue_P2
  echo "0                     " >> forcebatch.dat # queue_ST
  echo "0                     " >> forcebatch.dat # queue_OB
  echo "0                     " >> forcebatch.dat # queue_DF
  echo "0                     " >> forcebatch.dat # queue_DO
  echo "1                     " >> forcebatch.dat # queue_FW
  echo "0                     " >> forcebatch.dat # queue_FO
  echo "1                     " >> forcebatch.dat # active
  echo "0                     " >> forcebatch.dat # parallel
  echo "use_new               " >> forcebatch.dat # P2_smf_version
  echo "any                   " >> forcebatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> forcebatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> forcebatch.dat # trange_end
  ippjython queue.py $options edit -simtest < forcebatch.dat
  if ($status) exit 1
endif

if ($forcebatch) then
  echo ""
  echo " ---- load FW batches ----"

  rm -rf $OUTDIR/FW

  ippjython loader.py $options $forcedwarpqueuename once -simtest < /dev/null
  if ($status) exit
endif

############################ FO batches ################################

# this code is sensitive to a previously existing database?
if ($forcedobjqueue) then
  echo ""
  echo " ---- queue FO batches ----"

  echo "$forcedobjqueuename   " >  forcedobjectbatch.dat # skychunk name
  echo "test_ds               " >> forcedobjectbatch.dat # datastore_product
  echo "IPP_PSPS              " >> forcedobjectbatch.dat # datastore_type
  echo "0                     " >> forcedobjectbatch.dat # datastore_publish
  echo "catdir.wrp            " >> forcedobjectbatch.dat # dvo_label
  echo "$OUTDIR/catdir.wrp    " >> forcedobjectbatch.dat # dvo_location
  echo "9                     " >> forcedobjectbatch.dat # min_ra
  echo "11                    " >> forcedobjectbatch.dat # max_ra
  echo "19                    " >> forcedobjectbatch.dat # min_dec
  echo "21                    " >> forcedobjectbatch.dat # max_dec
  echo "2                     " >> forcedobjectbatch.dat # box_size
  echo "$OUTDIR               " >> forcedobjectbatch.dat # base_path
  echo "0                     " >> forcedobjectbatch.dat # data_release
  echo "0                     " >> forcedobjectbatch.dat # delete_local
  echo "1                     " >> forcedobjectbatch.dat # delete_datastore
  echo "1                     " >> forcedobjectbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> forcedobjectbatch.dat # epoch
  echo "3PI                   " >> forcedobjectbatch.dat # survey
  echo "3PI                   " >> forcedobjectbatch.dat # psps_survey
  echo "0                     " >> forcedobjectbatch.dat # queue_P2
  echo "0                     " >> forcedobjectbatch.dat # queue_ST
  echo "0                     " >> forcedobjectbatch.dat # queue_OB
  echo "0                     " >> forcedobjectbatch.dat # queue_DF
  echo "0                     " >> forcedobjectbatch.dat # queue_DO
  echo "0                     " >> forcedobjectbatch.dat # queue_FW
  echo "1                     " >> forcedobjectbatch.dat # queue_FO
  echo "1                     " >> forcedobjectbatch.dat # active
  echo "0                     " >> forcedobjectbatch.dat # parallel
  echo "use_new               " >> forcedobjectbatch.dat # P2_smf_version
  echo "any                   " >> forcedobjectbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> forcedobjectbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> forcedobjectbatch.dat # trange_end
  ippjython queue.py $options edit once -simtest < forcedobjectbatch.dat
  if ($status) exit
endif

if ($forcedobjbatch) then
  echo ""
  echo " ---- load FO batches ----"

  rm -rf $OUTDIR/FO
  rm -rf $OUTDIR/FG

  ippjython loader.py $options $forcedobjqueuename once -simtest < /dev/null
  if ($status) exit
endif

############################ DF batches ################################

# this code is sensitive to a previously existing database?
if ($diffqueue) then
  echo ""
  echo " ---- queue DF batches ----"

  echo "$diffqueuename        " >  diffbatch.dat # skychunk name
  echo "test_ds               " >> diffbatch.dat # datastore_product
  echo "IPP_PSPS              " >> diffbatch.dat # datastore_type
  echo "0                     " >> diffbatch.dat # datastore_publish
  echo "catdir.dif            " >> diffbatch.dat # dvo_label
  echo "$OUTDIR/catdir.dif    " >> diffbatch.dat # dvo_location
  echo "9                     " >> diffbatch.dat # min_ra
  echo "11                    " >> diffbatch.dat # max_ra
  echo "19                    " >> diffbatch.dat # min_dec
  echo "21                    " >> diffbatch.dat # max_dec
  echo "2                     " >> diffbatch.dat # box_size
  echo "$OUTDIR               " >> diffbatch.dat # base_path
  echo "0                     " >> diffbatch.dat # data_release
  echo "0                     " >> diffbatch.dat # delete_local
  echo "1                     " >> diffbatch.dat # delete_datastore
  echo "1                     " >> diffbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> diffbatch.dat # epoch
  echo "3PI                   " >> diffbatch.dat # survey
  echo "3PI                   " >> diffbatch.dat # psps_survey
  echo "0                     " >> diffbatch.dat # queue_P2
  echo "0                     " >> diffbatch.dat # queue_ST
  echo "0                     " >> diffbatch.dat # queue_OB
  echo "1                     " >> diffbatch.dat # queue_DF
  echo "0                     " >> diffbatch.dat # queue_DO
  echo "0                     " >> diffbatch.dat # queue_FW
  echo "0                     " >> diffbatch.dat # queue_FO
  echo "1                     " >> diffbatch.dat # active
  echo "0                     " >> diffbatch.dat # parallel
  echo "use_new               " >> diffbatch.dat # P2_smf_version
  echo "any                   " >> diffbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> diffbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> diffbatch.dat # trange_end
  ippjython queue.py $options edit -simtest < diffbatch.dat
  if ($status) exit 1
endif

if ($diffbatch) then
  echo ""
  echo " ---- load DF batches ----"

  rm -rf $OUTDIR/DF
  ippjython loader.py $options $diffqueuename once -simtest < /dev/null
  if ($status) exit
endif

############################ DO batches ################################

# this code is sensitive to a previously existing database?
if ($diffobjqueue) then
  echo ""
  echo " ---- queue DO batches ----"

  echo "$diffobjqueuename     " >  diffobjbatch.dat # skychunk name
  echo "test_ds               " >> diffobjbatch.dat # datastore_product
  echo "IPP_PSPS              " >> diffobjbatch.dat # datastore_type
  echo "0                     " >> diffobjbatch.dat # datastore_publish
  echo "catdir.dif            " >> diffobjbatch.dat # dvo_label
  echo "$OUTDIR/catdir.dif    " >> diffobjbatch.dat # dvo_location
  echo "9                     " >> diffobjbatch.dat # min_ra
  echo "11                    " >> diffobjbatch.dat # max_ra
  echo "19                    " >> diffobjbatch.dat # min_dec
  echo "21                    " >> diffobjbatch.dat # max_dec
  echo "2                     " >> diffobjbatch.dat # box_size
  echo "$OUTDIR               " >> diffobjbatch.dat # base_path
  echo "0                     " >> diffobjbatch.dat # data_release
  echo "0                     " >> diffobjbatch.dat # delete_local
  echo "1                     " >> diffobjbatch.dat # delete_datastore
  echo "1                     " >> diffobjbatch.dat # delete_dxlayer
  echo "2012-12-10 00:00:00.0 " >> diffobjbatch.dat # epoch
  echo "3PI                   " >> diffobjbatch.dat # survey
  echo "3PI                   " >> diffobjbatch.dat # psps_survey
  echo "0                     " >> diffobjbatch.dat # queue_P2
  echo "0                     " >> diffobjbatch.dat # queue_ST
  echo "0                     " >> diffobjbatch.dat # queue_OB
  echo "0                     " >> diffobjbatch.dat # queue_DF
  echo "1                     " >> diffobjbatch.dat # queue_DO
  echo "0                     " >> diffobjbatch.dat # queue_FW
  echo "0                     " >> diffobjbatch.dat # queue_FO
  echo "1                     " >> diffobjbatch.dat # active
  echo "0                     " >> diffobjbatch.dat # parallel
  echo "use_new               " >> diffobjbatch.dat # P2_smf_version
  echo "any                   " >> diffobjbatch.dat # ST_cmf_version
  echo "2000-01-01 00:00:00.0 " >> diffobjbatch.dat # trange_start
  echo "2020-01-01 00:00:00.0 " >> diffobjbatch.dat # trange_end
  ippjython queue.py $options edit once -simtest < diffobjbatch.dat
  if ($status) exit
endif

if ($diffobjbatch) then
  echo ""
  echo " ---- load DO batches ----"

  rm -rf $OUTDIR/DO

  ippjython loader.py $options $diffobjqueuename once -simtest < /dev/null
  if ($status) exit
endif

