#!/bin/sh
#
#      $HOME/.lcmodel/execution-scripts/ecc    (1 August 2000)

#      Does eddy-current correction (ECC) and outputs the results into $4/ecc.
# $4 is the Save Directory that you specify in the "Control Parameters" window.

#      If you want to modify $HOME/.lcmodel/execution-scripts/ecc:
#      Copy it to another file (e.g., my-ecc) in the directory 
# $HOME/.lcmodel/execution-scripts/.
#      Modify my-ecc.
#      Select my-ecc to be the default Execution Script using the "Advanced 
# Settings" menu in the "Control Parameters" window.
#      ecc will be overwritten during LCMgui updates, but my-ecc will be
# preserved. 

#      See the LCModel User's Manual.
#      For general documentation on Execution Scripts, see
# $HOME/.lcmodel/execution-scripts/standard. 
#===========================================================================

#      By default the ECC data are also plotted with your LCMgui print
# command.  You can prevent plotting by changing the following value from "1" 
# to "0" (zero):
DO_PLOT=1

#      You can modify the following values from "T" (true) to "F" (false) 
# and vice versa to specify whether the time-domain data, the frequency-domain 
# data or the absolute values of the frequency-domain data are to be plotted:
#
PLTIME=" pltime=F"
PLFREQ=" plfreq=T"
PLABSV=" plabsv=T"
#===========================================================================

#                          Run KECC.
#                          ========
#
#
NUNFIL=`awk '/nunfil=/'  $1/control`
FILH2O=`awk '/filh2o=/'  $1/control`
FILRAW=`awk '/filraw=/'  $1/control`
echo " \$NMKECC
$NUNFIL
$FILRAW
$FILH2O
 filout='$4/ecc'
 \$END"  |  $HOME/.lcmodel/bin/kecc

DO_PLOT=`echo $DO_PLOT`
if [ $DO_PLOT  -eq  0 ]
then
   mkdir $1/done
   exit 0
fi
#----------------------------------------------------------------------------

#                          Run PlotRaw
#                          ===========
#
HZPPPM=`awk '/hzpppm=/'  $1/control`
DELTAT=`awk '/deltat=/'  $1/control`
PPMST=`awk '/ppmst=/'  $1/control`
PPMEND=`awk '/ppmend=/'  $1/control`

echo " \$PLTRAW
 filraw='$4/ecc'
 filps='$1/ps'
$NUNFIL
$HZPPPM
$DELTAT
$PPMST
$PPMEND
$PLTIME
$PLFREQ
$PLABSV
 \$END"  |  $HOME/.lcmodel/bin/plotraw
#----------------------------------------------------------------------------

#			Output the Results
#			==================
#
#      The following "$3" plots your ECC data.

$3

#-----------------------------------------------------------------------------
#
#			Signal Completion
#			=================
#
#      The following signals LCMgui that LCModel is done, and that the 
# temporary files can be deleted.  So, DO NOT change the following:

mkdir $1/done

