#!/bin/csh

date
set rundir = `dirname $PWD`
set bsdir = $PWD
set scenario = SCEN_NAME
set vicNl = /home/disk/columbia2/marketa/SRC/VIC_4.0.7_w_spatial_pert_staticlinks/vicNl

rm -f ./cluster.??/log

# distribute conf files:
set Np = 12
foreach n ( `seq -f%02g 2 $Np` )
  echo "${n}of${Np}"
  sed 's/01of'${Np}'/'${n}'of'${Np}'/g' ./cluster.01/VIC.conf >! ./cluster.${n}/VIC.conf
  cp -p ./cluster.01/pertfile ./cluster.${n}/
end

# run vic in parallel:
foreach n ( `seq -f%02g 1 $Np` )
  cd ${bsdir}/cluster.${n}
  $vicNl -g VIC.conf >& log &
end

# zip results:
wait
cd ${bsdir}/output/fluxes
cd ..
set dnm = `basename $PWD`
cd ..
tar czf ${dnm}/${scenario}_fluxes.tar.gz ${dnm}/fluxes/

wait
date
echo "DONE -- $rundir / $scenario"
exit

