#!/bin/sh -vx

#
#  This script is EXECed directly by DBNet in order to run the
#  dchydr decoder on the data file given in the first argument.
#
#    Usage: ./run_dchydr.sh <hydro_filename>
#
#  Once this is done, the data file itself is then compressed
#  within its native directory for more efficient short-term
#  storage.
#

# The gzip line must be the first, noncomment line in this script
# so that stdin is processed correctly

gzip -d > ${1}/$$.${2}
madisfilename=${1}/`echo ${2} | cut -c1-13`
hhmm=`date -u +%H%M`
decoderfilename=${madisfilename}.${hhmm}
mv ${1}/$$.${2} ${decoderfilename}

. /iodprod/dbnet/.profile

export MADIS_STATIC=/nwprod/lib/sorc/madis/static
export MADIS_DATA=/dcom/us007003/ldmdata

ln -sf ${decoderfilename} ${madisfilename}

nice /nwprod/exec/decod_dchydr -v 2 \
  -d /dcom/us007003/decoder_logs/decod_dchydr.log \
  ${decoderfilename} /nwprod/fix/bufrtab.255

rm -f ${madisfilename}

#
#  Compress the decoder input file within its native directory,
#  in order to conserve disk space for these large files!
#

gzip ${decoderfilename}

#
#  Explicitly set the script return code to 0, in order to prevent
#  the "compress" return code from becoming the script return code
#  (and thereby prevent DBNet from re-running the script for this
#  particular data file if there is a problem with the compress!)
#

exit 0
