#!/bin/ksh +x
#**************************************#
#                                      #
#     Hough Functions calculation      #
#                                      #
#**************************************#
#
if [ "${1}" = "-h" ]
then
  echo " "
  echo " Generate Files with the Hough Functions and Its Derivatives"
  echo " for the Reference Case "
  echo " "
  echo " Usage:"
  echo " ./Run_Hough nHn [Mmax]"
  echo " "
  echo " Default:"
  echo " nhn = 1 ; Mmax = 126"
  echo " "
  echo " nHn : three digits number of the mode to be calculated, maximum = Kmax"
  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
#
if [ -z "${1}" ]
then
  nHn=1
else
  nHn=${1}
fi
if [ -z "${2}" ]
then
  Mmax=126
else
  Mmax=${2}
fi
#
dircfg='../../Config/'
. ${dircfg}Config_Dir
. ${dircfg}Reference_Case
#
set -x
cat <<eot > ./NameList
 &hgfnml
  csvm=${csvm},
  Kmax=${Kmax},
  nHn=${nHn},
  Mmax=${Mmax},
  cutcft=0.001,
  Test=.FALSE.,
  ipr=0,
  dirhgf='${dirhgfcfg}',
  dirvmd='${dirvmdcfg}'
 /
eot
#
typeset -Z3 kmx nn
kmx=${Kmax}
nn=${nHn}
typeset -Z4 mmx1
let mmx1=${Mmax}-1
Trunc=RB${mmx1}L${kmx}
ext=${Trunc}_${csvm}_h${nn}.out
out=../output/Hough_Functions_${ext}
#
rm -f out
time ../bin/Hough_Functions.bin > ${out}
#
rm -f ./NameList
#
