#! /bin/csh -f -e

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

set usage = "$0 PARMFILE"

#
# The PARMFILE must be a csh script fragment that sets the following
# shell variables:
#
#   outfile = output file prefix
#
#   ofile =   ".top" file with the "origin" configuration
#   xfile =   ".top" file with the "(1,0)" configuration
#   yfile =   ".top" file with the "(0,1)" configuration
#
#   xmin =    min X coordinate to plot
#   xmax =    max X coordinate to plot
#   ymin =    min Y coordinate to plot
#   ymax =    max Y coordinate to plot
#   
#   nsteps  = number of steps in X and Y
#
#   wCurv   = weight of Curv   energy
#   wPArea  = weight of PArea  energy
#   wCorner = weight of Corner energy
#   wExcen  = weight of Excen  energy
#   wPoten  = weight of Poten  energy
#   wElect  = weight of Elect  energy
#


set parmfile = "$1"; shift;

if ( $#argv != 0 ) then
  echo "usage: ${usage}"; exit 1
endif

sorce "${parmfile}"

set outfile = "${parmfile:r}.plot"

set set ofile =   "${ofile:r}"
set set xfile =   "${xfile:r}"
set set yfile =   "${yfile:r}"

set d = "`date +%y-%m-%d-%H%M%S`"

echo "running in ${d}"

mkdir $d $d/src-save
cp -p ../src/EnergySlice.m3 ${d}/src-save
cp -p ../../libm3marcone/src/*Energy.?3 ${d}/src-save
cp -p ${parmfile} ${ofile}.top ${xfile}.top ${yfile}.top ${d}
cp -p run-test show-plot ${d}
echo "$0 $*" > ${d}/run-test-arguments
chmod -R a-w ${d}/*

cd ${d}

nice time \
  ../../SOLgnu/EnergySlice \
    -outFile ${outfile} \
    -nSteps ${nsteps} \
    -oFile ${ofile} \
    -xFile ${xfile} -range ${xmin} ${xmax} \
    -yFile ${yfile} -range ${ymin} ${ymax} \
    -energy ${wCurv} Curv \
    -energy ${wPArea} PArea area 1.5 \
    -energy ${wCorner} Corner \
    -energy ${wExcen} Excen \
    -energy ${wPoten} Poten \
    -energy ${wElect} Elect

show-plot ${outfile}