#!/bin/ksh +x
#
if [ "${1}" = "-h" ]
then
  echo " "
  echo " Performs the Horizontal Modal Decomposition and Generate Files with"
  echo " Modal Horizontal Energy and Normalized Zonal Wind, Meridional Wind"
  echo " and Geopotential Height for the RainRS Case"
  echo " "
  echo " Usage:"
  echo " ./run_RainRS caso [Mmax]"
  echo " "
  echo " Default:"
  echo " caso = MONAN ; Mmax = 126"
  echo " "
  echo " caso : five letters case identifier"
  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
#
caso=${1}
if [ -z "${caso}" ]
then
  caso=MONAN
fi
if [ ${caso} != "MONAN" ]
then
  if [ ${caso} != "ERA_5" ]
  then
    if [ ${caso} != "CFSV2" ]
    then
      if [ ${caso} != "NCEPF" ]
      then
        caso=MONAN
      fi
    fi
  fi
fi
if [ -z "${2}" ]
then
  Mmax=126
else
  Mmax=${2}
fi
#
if [ ${caso} = "MONAN" ]
then
#
  ep=1
  while [ ep -le 12 ]
  do
    echo "./Run_HDecomp ${caso} ${ep} RainRS no"
    ./Run_HDecomp ${caso} ${ep} RainRS no ${Mmax}
    let ep=ep+1
  done
  ep=16
  while [ ep -le 27 ]
  do
    echo "./Run_HDecomp ${caso} ${ep} RainRS no"
    ./Run_HDecomp ${caso} ${ep} RainRS no ${Mmax}
  let ep=ep+1
  done
#
else
#
ep=1
while [ ep -le 15 ]
do
  echo "./Run_HDecomp ${caso} ${ep} RainRS no"
  ./Run_HDecomp ${caso} ${ep} RainRS no ${Mmax}
  let ep=ep+1
done
#
fi
#
