#! /bin/sh

#
# Metafile Script : gempak_gif.sh.sms
#
# Log :
# D.W.Plummer/NCEP   2/97   Add log header
# D.W.Plummer/NCEP  12/97   Added NGM v. ETA plot comparison if NGM precedes ETA
# J. Carr/HPC        8/98   Changed map to medium resolution
# J. Carr/HPC        1/99   Changed contur from 1 to 2 per OM request
# J. Carr/HPC        2/99   Changed skip to 0 per OM request
# B. Gordon/NCO      5/00   Ported to IBM-SP, Standardized for production,
#                           changed gdplot_nc -> gdplot2_nc
# B. Gordon/NCO      4/01   Modified to make individual GIF images.
#
# Shirey/NCO         2/02   Modified to create web tree in /com
# Magee/NCO         12/07   Added error checking post-update call.

export PS4='bld_html:$SECONDS + '

cd $DATA

set -xa

sh $utilscript/setup.sh
for RUN in storm_1 storm_2 storm_3 storm_4 ; do
  for lst in `ls /com/web/${envir}/bldhtml_flags/hur/bld_html_*${RUN}*` ; do
    export RSHPDY=`cat $lst`
    rm $lst
    export REGION=`echo $lst |awk -F_ '{print $4}'`
    export str=`echo $lst |awk -F_ '{print $5}'`
    if [ $str = "nested" ]; then
      export REGION=`echo $lst |awk -F_ '{print $4"_"$5}`
      export MAPAREA=`echo $lst |awk -F_ '{print $4"_"$5}'`
      export cyc=`echo $lst |awk -F_ '{print $8}'`
    else
      export MAPAREA=`echo $lst |awk -F_ '{print $4}'`
      cyc=`echo $lst |awk -F_ '{print $7}'`
    fi
      
    export MODELDATES=${BASEDIR}/$MAPAREA/$RUN/$cyc/mdates
    export pgm=update
    $USHgempak/update ${RUN} ${cyc} ${RSHPDY}
    export err=$?
    if [ $err -eq 0 ] ; then
      echo "1" > ${BASEDIR}/../checkpoint_analysis_${MAPAREA}_${RUN}
#    else
#      msg='Error return from $USHgempak/update'
#      echo $msg $err ${MAPAREA} ${RUN} ${cyc}
#      postmsg "$jlogfile" "$msg"
    fi
#   err_chk
  done
done
