#!/bin/sh
############################################################
# Script -- cdas2_getpentad.sh.sms
# Purpose: to retrieve the pentad data from CPC workstation
#          and convert it to GRIB format
# History: 2005-02-01 First implementation
############################################################

set -x

cd $DATA
/nwprod/util/ush/setup.sh

#########################################################
# Start retrieving the pentad file (in grads format)from 
# the CPC workstation
#########################################################
yyyy=`echo $PDYm5 |cut -c1-4`
remote_file=$REMOTEDIR/cmap_pen_rt_v0011_out.lnx.$yyyy
local_file=pingrain.$yyyy

#############################################################
# Use scp to copy Pingping's pentad file from CPC workstation
#############################################################

scp climprod@$cpc_workstation:$remote_file $local_file

#  end ftp instruction input ###
ftperror=$?
if [ $ftperror -ne 0 ] || [ ! -s $local_file ]
then
  echo "Transfer of file $REMOTEDSN from $1 failed."
  export err=$ftperror
  $DATA/err_chk
else
  echo "The pentad data is updated"
fi

###################################
# Convert the file into GRIB format
###################################
export pgm=cdas2_gribpentad

$EXECcdas2/cdas2_gribpentad $local_file pingrain.grb $yyyy

#####################################
# convert data to T62 gaussian grid
#####################################
rm pingrainT62.grb
/nwprod/util/exec/copygb -g98 -i3 -x pingrain.grb pingrainT62.grb

if [ $SENDCOM = "YES" ]
then
   cp pingrainT62.grb $COMOUT/.
   cp pingrainT62.grb $COMOUT/pingrainT62.grb.$yyyy
fi

msg="$job HAS COMPLETED NORMALLY."
echo $msg

postmsg "$jlogfile" "$msg"

############## END OF SCRIPT #######################

