10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-23 12:56:14 +01:00
quantum_package/scripts/qpackage

150 lines
2.3 KiB
Plaintext
Raw Normal View History

2014-06-27 01:26:46 +02:00
#!/bin/bash
#
# Runs the programs.
# Thu Jun 26 23:40:20 CEST 2014
# Check environment
###################
if [[ -z $QPACKAGE_ROOT ]]
then
echo "Error:"
echo "QPACKAGE_ROOT environment variable is not set."
echo "source quantum_package.rc"
exit 1
fi
# List of executables
#####################
declare -A EXECUTABLES
2014-06-27 10:36:40 +02:00
for EXE in $(find $QPACKAGE_ROOT/src -type f -executable | grep -e "$QPACKAGE_ROOT/src/[^/]*/[^/]*$")
2014-06-27 01:26:46 +02:00
do
2014-06-27 10:36:40 +02:00
EXECUTABLES[$(basename ${EXE})]="${EXE}"
2014-06-27 01:26:46 +02:00
done
function print_list()
{
echo
echo "Available programs:"
echo
for EXE in ${!EXECUTABLES[@]}
do
printf " * %-30s [ %s ]\n" $EXE ${EXECUTABLES[$EXE]}
done | sort
echo
}
# Help message
##############
function print_help()
{
cat << EOF
Usage:
qpackage -h | --help
qpackage -l | --list
qpackage run <program> <EZFIO_input>
qpackage reset <EZFIO_input>
Options:
-h --help Print help message
-l --list List executables
EOF
}
ARGS=$(getopt -o "hl" -l "help,list" -n $0 -- "$@")
[[ $? -eq 0 ]] || exit 1
eval set -- "$ARGS"
while true
do
case "$1" in
-h|--help)
print_help
exit 0
shift ;;
-l|--list)
print_list
exit 0
shift ;;
--)
shift
break;;
esac
done
# Run commands
##############
function run()
{
# run $EXE $EZFIO
# Starts the executable in one process and
# displays the output files in stdout
2014-10-08 22:56:35 +02:00
if [[ -z $1 ]] ; then
echo "Please specify which executable to run"
print_list
exit 1
fi
2014-06-27 01:26:46 +02:00
EXE=${EXECUTABLES[$1]}
EZFIO=$2
2014-10-08 22:56:35 +02:00
if [[ -z $EXE ]] ; then
echo "Executable $1 not found"
exit 1
fi
if [[ -z $EZFIO ]] ; then
echo "Please specify an EZFIO directory"
exit 1
fi
2014-06-27 01:26:46 +02:00
date
2014-10-08 22:56:35 +02:00
rm -rf -- ${EZFIO}/output
2014-06-27 01:26:46 +02:00
${QPACKAGE_ROOT}/scripts/follow_output.py ${EZFIO} &
2014-10-08 22:56:35 +02:00
PID=$!
2014-06-27 01:26:46 +02:00
${EXE} ${EZFIO}
2014-10-08 22:56:35 +02:00
kill -2 $PID
if [[ $(jobs | wc -l) -gt 0 ]]
then
sleep 1
kill -9 $PID
fi
2014-06-27 01:26:46 +02:00
wait
date
}
function reset()
{
# reset $EZFIO
2014-10-08 22:56:35 +02:00
EZFIO=$1
if [[ -z ${EZFIO} ]] ; then
echo "Please specify an EZFIO directory"
exit 1
fi
rm -rf -- ${EZFIO}/output/*.rst
rm -rf -- ${EZFIO}/determinants/{n_det,psi_det.gz,psi_coef.gz}
2014-06-27 01:26:46 +02:00
}
COMMAND=$1
shift
case "${COMMAND}" in
run)
run $1 $2
;;
reset)
reset $1
;;
*)
print_help
;;
esac