#!/bin/sh

#############################################################
# Script: excdccdas_prep.sh.sms
# Purpose: to obtain the observation and model precipitation
#          analysis from CDAS and DCOM
# Auther: Wesley Ebisuzaki
# Log:   2004-06-09 Initial script from Wesley Ebisuzaki
#        2004-06-10 Modified for production--Julia Zhu
#        2004-07-04 took excdas2_prep.sh and used for early CDAS
#                   Wesley Ebisuzaki
#############################################################
set -x

cd $DATA

###################################################################
# get needed files from GDAS: prepbufr, snow, sst, ice
###################################################################
#export wgrib=${wgrib:-/nw${envir}/util/exec/wgrib}
export wgrib=${wgrib:-/nwprod/util/exec/wgrib}

ierr=0
cp $COMCDAS/gdas1.t${cyc}z.snogrb $COMOUT/${RUN}.t${cyc}z.snogrb
ierr=$(( $ierr + $? ))
cp $COMCDAS/gdas1.t${cyc}z.sstgrb $COMOUT/${RUN}.t${cyc}z.sstgrb
ierr=$(( $ierr + $? ))
cp $COMCDAS/gdas1.t${cyc}z.engicegrb $COMOUT/${RUN}.t${cyc}z.engicegrb
ierr=$(( $ierr + $? ))
for f in $COMCDAS/gdas1.t${cyc}z.*bufr_d
do
   ff=`basename $f | sed "s/^gdas1/$RUN/"`
   cp $f $COMOUT/$ff
   ierr=$(( $ierr + $? ))
done

if [ $ierr -ne 0 ]; then
   echo "early CDAS files are not available" 
   exit 8
fi

if [ "$CHGRP_RSTPROD" = 'YES' ]; then
   chgrp rstprod $COMOUT/${RUN}.t${cyc}z.prepbufr_pre-qc
   errch=$?
   if [ $errch -eq 0 ]; then
      chmod 640 $COMOUT/${RUN}.t${cyc}z.prepbufr_pre-qc
   else
      cp /dev/null $COMOUT/${RUN}.t${cyc}z.prepbufr_pre-qc
      warning=yes
   fi
fi

echo "Completee the early CDAS PREP job"
exit
