#!/bin/ksh +x
#********************************#
#                                #
#     Hough_Functions_Energy     #
#                                #
#********************************#
#
if [ "${1}" = "-h" ]
then
  echo " "
  echo " Generate a File with Frequency, Group Velocity, Zonal Kinetic Energy,"
  echo " Meridional Kinetic Energy, Available Potential Energy, Reinforciment"
  echo " Time Interval and Reinforciment Longitude Interval for the Horizontal"
  echo " Modes (Rossby + Mixed, Gravity East + Kelvin and Gravity West)"
  echo " "
  echo " Usage:"
  echo " ./Hough_Functions_Energy cs [Mmax]"
  echo " "
  echo " Default:"
  echo " cs = br ; Mmax = 126"
  echo " "
  echo " cs : br for Barotropic Mode or bc for the Baroclinic Mode Closest to Hn = 250 m"
  echo " Mmax : Rhomb+1 (even), Rhomb is the zonal wave truncation (Rhomb odd number)"
  echo "        is the total number of zonal waves plus the zonal mean (+1)"
  echo " "
  exit
fi
#
cs=${1}
if [ "${cs}" != "bc" ]
then
  if [ "${cs}" != "br" ]
  then
    cs="br"
  fi
fi
#
if [ -z "${2}" ]
then
  Mmax=126
else
  Mmax=${2}
fi
#
dircfg='../../../Config/'
. ${dircfg}Config_Dir
. ${dircfg}Reference_Case
#
typeset -Z3 hh
if [ "${cs}" = "br" ]
then
  hh=001
fi
if [ "${cs}" = "bc" ]
then
  hh=008
fi
#
typeset -Z3 kmx
let kmx=Kmax
typeset -Z4 mmx1
let mmx1=${Mmax}-1
Trunc=RB${mmx1}L${kmx}
ext=${Trunc}_${csvm}_h${hh}
hgf=Hough_Functions.${ext}
flo=HF_${ext}.dat
out=../../output/Hough_Functions_Energy_${ext}.out
#
rm -f ${out}
rm -f ./nml/Hough_Functions_Energy.nml
#
set -x
#
cat << eot > ./nml/Hough_Functions_Energy.nml
 &HFEnml
  Mmax=${Mmax}
  DirInp='${dirhgfcfg}', 
  DirOut='${dirhggcfg}', 
  HoughFunctions='${hgf}',
  FileOut='${flo}'
 / 
eot
#
time ../../bin/Hough_Functions_Energy.bin > ${out}
#
rm -f ./nml/Hough_Functions_Energy.nml
#
