#!/bin/ksh +x
#*************************#
#                         #
#     Get_Rhomb_ResGL     #
#                         #
#*************************#
#
if [ "${1}" = "-h" ]
then
  echo " "
  echo " This procedure is hardwired for odd Rhomboidal quadratic grid truncation"
  echo " Given the total number of zonal waves Mmax (Jmax=0) calculates the"
  echo " rhomboidal resolution Mmax-1 for the number of longitudes (Imax),"
  echo " the number of latitudes (Jmax) and the Gaussian latitudes for Jmax or"
  echo " given the number of latitudes Jmax (Mmax any) calculates only the"
  echo " Gaussian latitudes for the given Jmax"
  echo " "
  echo " Usage :"
  echo " ./Run_GRhoResGL Mmax [Jmax]"
  echo " "
  echo " Default:"
  echo " Mmax = 126 ; Jmax = 0"
  echo " "
  echo " Mmax : four digits number of zonal waves (Rhomb+1) to run"
  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 " Jmax : four digits number of latitudes for only GLats.JJmax or"
  echo "        = 0 for normal run"
  echo " Obs:"
  echo "    1 - The available Mmax are : 32 40 48 64 126 132 198 264 296 328 396"
  echo "    2 - It is necessary to run:"
  echo "        ./Run_GRhoResGL 126 450"
  echo "        to generate GLats.J0450 for use in the case of the time mean of ZCAS for SMNAH"
  echo " "
exit
fi
#
if [ -z "${1}" ]
then
  mmx=126
else
  mmx=${1}
fi
#
if [ -z "${2}" ]
then
  jmx=0
else
  jmx=${2}
fi
#
if [ ${jmx} -eq 0 ]
then
  set -A lMmax 00 32 40 48 64 126 132 198 264 296 328 396
  m=1
  while [ m -le 11 ]
  do
    mmy=lMmax[m]
    if [ ${mmx} -eq ${mmy} ]
    then
      ex=0
      break
    else
      ex=1
    fi
    let m=m+1
  done
  if [ ex -eq 1 ]
  then
    echo " Mmax is not available"
    exit 1
  fi
fi
#
set -x
rm -f ./NameList
cat << eot > ./NameList
 &GetRhoResGL
  Mmax=${mmx}
  Jmax=${jmx}
 /
eot
#
typeset -Z4 mmx1
let mmx1=${mmx}-1
ext=RB${mmx1}.out
out=../output/Get_Rhomb_Res_GLats.${ext}
#
rm -f ${out}
../bin/Get_Rhomb_Res_GLats.bin > ${out}
#
rm -f ./NameList
#
