#!/bin/ksh +x
#*****************************#
#                             #
#     Hough_Functions_uvh     #
#                             #
#*****************************#
#
if [ "${1}" = "-h" ]
then
  echo " "
  echo " Generate a File with Normalized Zonal Wind, Meridional Wind,"
  echo " Geopotential Height, Vorticity and Divergence for the Horizontal Modes:"
  echo " Rossby (rb), Kelvin(kv), Mixed (mx), Gravity West (gw) and Gravity East (ge)"
  echo " "
  echo " Usage:"
  echo " ./Hough_Functions_uvh cs wv sp lp is [Mmax]"
  echo " "
  echo " Default:"
  echo " cs = br ; wv = rb ; sp = 2 ; lp = Mmax+1 (rb) ; is = 1 ; Mmax = 126"
  echo " "
  echo " cs : br for Barotropic Mode or bc for the Baroclinic Mode Closest to Hn = 250 m"
  echo " wv : Wave Kind:"
  echo "      rb for Rossby"
  echo "      kv for Kelvin"
  echo "      mx for Mixed"
  echo "      gw for Gravity West"
  echo "      ge for Gravity East"
  echo " sp : Wave Number Plus 1"
  echo " lp : Meridional Index"
  echo " is : Symmetry 1 for Symmetric ; 2 for Antisymmetric Case"
  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}" != "br" ]
then
  if [ "${cs}" != "bc" ]
  then
    cs="br"
  fi
fi
#
wv=${2}
if [ "${wv}" =  "" ]
then
  wv='rb'
fi
#
sp=${3}
if [ "${sp}" =  "" ]
then
  sp=2
fi
#
if [ -z "${6}" ]
then
  Mmax=126
else
  Mmax=${6}
fi
#
lp=${4}
if [ "${lp}" =  "" ]
then
  let lp=${Mmax}+1
fi
#
is=${5}
if [ "${is}" =  "" ]
then
is=1
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}
out=../../output/Hough_Functions_uvh_${wv}_${sp}_${lp}_${is}_${ext}.out
#
rm -f ${out}
rm -f ./nml/Hough_Functions_uvh.nml
#
set -x
#
cat << eot > ./nml/Hough_Functions_uvh.nml
 &Hough_Function_nml
  Mmax=${Mmax},
  Hough_Functions='${hgf}',
  ExtHF='${ext}',
  Wave='${wv}',
  splt=${sp},
  lplt=${lp},
  isiplt=${is}
  DirInp='${dirhgfcfg}'
  DirOut='${dirhggcfg}'
 /
eot
#
time ../../bin/Hough_Functions_uvh.bin > ${out}
#
rm -f ./nml/Hough_Functions_uvh.nml
#
