#! /bin/csh -f -e

# Runs Optshape and saves all data in a sub-directory.
# Usage: run-test

if ( $#argv != 10 ) then
  echo "usage: $0 <cmplx> <topin> <topout> <method> <maxevals> <wCurv> <wPArea> <wCorner> <wEcen> <wPoten> <wElect>"
  exit 1
endif

oset cmplx = "$1"
set topin = "$2"; set topin = "${topin:r}"
set topout = "$3"; set topout = "${topout:r}"
set method = "$4"; set method = "`echo ${method} | tr '.' ' '`"
set maxevals = "$5"

set wCurv = "$6"
set wPArea = "$7"
set wCorner = "$8"
set wExcen = "$9"
set wPoten = "$10"
set wElect = "$11"

set d = "${cmplx}/`date +%y-%m-%d-%H%M%S`"

echo "running in ${d}"

mkdir -p $d $d/src-save
cp -p ../src/OptShape.m3 ${d}/src-save
cp -p ../../libm3marcone/src/*Energy.?3 ${d}/src-save
cp -p ${topin}.top ${d}
cp -p run-test show-plots monotone-energy-plot.nawk ${d}
echo "$0 $*" > ${d}/run-test-arguments
chmod -R a-w ${d}/*

cd ${d}

nice time ../../../SOLgnu/OptShape \
  -inFile ${topin:t} \
  -outFile ${topout} \
  -showEvery 100 \
  -maxEvals ${maxevals} \
  -energy ${wCurv} Curv \
  -energy ${wPArea} PArea area 1.5 \
  -energy ${wCorner} Corner \
  -energy ${wExcen} Excen \
  -energy ${wPoten} Poten \
  -energy ${wElect} Elect \
  -minimizer ${method}

show-plots ${topout} &
x3d-show-top ${topout}-final &

