#! /usr/bin/ksh


#set -e

if [[ ($# -lt 2) || ($# -gt 3) ]]; then
   print "$0 requires two or three arguments: "
   print "   #1: OUTPUT-DIR of the run"
   print "   #2: SUB-DIRECTORY at ECFS (will be created below ec:/${USER})"
   print "   #3: (optional) RESTART DIR"
   print ""
   print " To use this script, set in your rc file:"
   print ""
   print "   output.user.scripts.condition : True"
   print "   output.user.scripts : <bindir>/store.ksh ${output.dir}  TM5/bench/exp  ${restart.write.dir}"
   print ""
   print " This would archive output in your ec:~/TM5/bench/exp/. Change as fit."
   exit 1
fi


# Backup output
emkdir -p ec:/${USER}/$2 || true

emv -po $1/TM5*    ec:/${USER}/$2/
emv -po $1/budget* ec:/${USER}/$2/
emv -po $1/mmix*   ec:/${USER}/$2/
emv -po $1/j_statistics*   ec:/${USER}/$2/


# Backup restart files
if [[ $# -eq 3 ]]; then

    emkdir -p ec:/${USER}/$2/restart || true

    ecp -p -t $3/* ec:/${USER}/$2/restart/
fi





exit 0