################################################################################################
# Script: cmcens_avgspr.sh
# Abstract: this script produces mean and spread of CMC ensemble forecast
# Author: Richard Wobus ---- March 2006 ( Ensemble Postprocessina Script, exgefs_ensstat.sh.sms )  
# Modified by: Bo Cui choose the mean and spread calculation part for CMC ensemble ---- May 2006
#################################################################################################


#######################################
# define control parameters
# no enspost files produced, nenspost=0
#######################################

lfm=66000
nenspost=0

######################################################
# start mean and spread calculation for each lead time
######################################################

for nfhrs in $HRLIST  
do

  echo " &namdim" >namin
  echo " lfdim=${lfm}," >>namin
  echo " /" >>namin
  echo " &namens" >>namin

  ifile=0
  for mem in $memberlist
  do
    (( ifile = ifile + 1 ))
    iskip=0
    if [ "$mem" = "c00" ]; then
      iskip=1
    fi
    echo " cfipg($ifile)='$COMOUTPGRBA/cmc_ge${mem}.t${cyc}z.pgrbaf${nfhrs}'," >>namin
    echo " iskip($ifile)=${iskip}," >>namin
  done

  echo " nfiles=${ifile}," >>namin
  echo " nenspost=${nenspost}," >>namin

  echo " cfoag='cmc_geavg.t${cyc}z.pgrbaf${nfhrs}'," >>namin
  echo " cfosg='cmc_gespr.t${cyc}z.pgrbaf${nfhrs}'," >>namin

  echo " inindxf=.false.," >>namin

  echo " /" >>namin

  startmsg
  $EXECGLOBAL/gefs_ensstat <namin > output_avgspr_$nfhrs   
  export err=$?;err_chk
  rm namin

done

set +x
echo " "
echo "Leaving sub script cmcens_avgspr.sh"
echo " "
set -x

