#!/bin/ksh -x
#
# Script to send hourly and daily gauge data to the 40-day rotating archive,
#   /dcom/us007003/gaugeqc/
#
# Hourly data: copied from /com/ingest/prod/shf.yyyymmdd/hrly.prcp.day.mmdd
#   and re-named to hrly.prcp.day.yyyymmdd
# Daily data: processed from /com/ingest/prod/shf.yyyymmdd/rfc24-* 
#   using sub-script gaugeqc_load_qual_prcp.pl (Michaud), which emulates 
#   Sid Katz's processing on sgi109.
#   
# This job is to be run at 03:40 UTC each day.
#
set -x

export RUN_ENVIR=prod

if [ $RUN_ENVIR = dev ]; then
  userid=`whoami`
  export PARMFILE=/u/$userid/gaugeqc/parm/fileloc.ref
else
  export PARMFILE=/nw${envir}/parm/gaugeqc_fileloc.ref
fi
 
#run=cold
run=warm

export PERLLIB=/usrx/local/Date-Calc.5.3/lib/site_perl/5.8.0/aix-thread-multi

USHgauge=`grep srcloc  $PARMFILE | nawk '{print $2}'`
  WRKDIR=`grep testloc $PARMFILE | nawk '{print $2}'`
 DATADIR=`grep dataloc $PARMFILE | nawk '{print $2}'`

if [ -d $WRKDIR ]; then
  rm -rf $WRKDIR
fi
mkdir -p $WRKDIR

cd $WRKDIR

cp $DATADIR/*.eval .
cp $DATADIR/*.good .
cp $DATADIR/*.precip .
cp $DATADIR/*.neigh .

# testonly - check for timing; rename cron output file
today=`date -u +%Y%m%d`
date
yday=`/nwprod/util/exec/ndate -24 ${today}12 | cut -c 1-8`
#mv /ptmp/wx22yl/gaugeqc.out/outfile /ptmp/wx22yl/gaugeqc.out/out.${yday}
# testonly

# For coldstart, if argument is 20070717, QC would go from 07/17 to 08/14 (29
#   days total)
# For warm start, if argument is 20070816, QC would be done for 20070815
#   (i.e. ${today-1}

if [ $run = cold ]; then
  $USHgauge/gaugeqc_run_qc_cold.pl 20071009
else
  $USHgauge/gaugeqc_precip_qc.pl $today 
fi

# testonly
date
# testonly

# Note to SPA: please send /com/hourly/prod/current.* to ftpprd:
#
 if [ $SENDDBN = YES ]
 then
    $DBNROOT/bin/dbn_alert MODEL VERIF_PRECIP $job $COMOUT/current.eval 
    $DBNROOT/bin/dbn_alert MODEL VERIF_PRECIP $job $COMOUT/current.good 
    $DBNROOT/bin/dbn_alert MODEL VERIF_PRECIP $job $COMOUT/current.evalH 
    $DBNROOT/bin/dbn_alert MODEL VERIF_PRECIP $job $COMOUT/current.goodH 
 fi
#

exit
