#!/bin/sh
set -x

#################################################################################
# Program Name: gtg_post
# Author(s):
# Abstract: Send the Graphical Turbulence Guidance (GTG)
#    (1)  Split and interpolate wrfmsl grids from native RAP 
# domain to the 130 grid 
#    (2)  Using TOCGRIB2, send into SBN
##################################################################
###
# export RAP based WGRIB2 for interpolation
#
export WGRIB2=/nwprod2/rap.v3.0.15/exec/rap_wgrib2

export grid_specs_130="lambert:265:25.000000 233.862000:451:13545.000000 16.281000:337:13545.000000"

###############
setpdy.sh
. PDY

grib_input=${COMINrap:-$(compath.py  rap/prod/rap).${PDY}}/rap.${cycle}.wrfmslf${fhr}.grib2

#################################################################################
#Run wgrib and set the output to a variable.  Then cut up that variable to set the
#wmotime, get the fcst_hr, and the z-level (later in the script).
#################################################################################
## CAT
grib_out=grib2.${fhr}

# Split out CAT gribs first
${WGRIB2} -for 52:97 ${grib_input} -grib tmp.grib2

# Interpolate the split values
 ${WGRIB2} tmp.grib2 -set_bitmap 1 -set_grib_type c3 -new_grid_winds grid -new_grid_interpolation bilinear -new_grid ${grid_specs_130} ${grib_out}

###################
nwstg_bull=${DATA}/gtg.${cycle}.nwstg.${fhr}.grib2

pgm=tocgrib2
. prep_step
export FORT11=${grib_out}
../gtg/gtg.

startmsg

$TOCGRIB2 < $PARMgtg/grib2_gtg_f${fhr} >>$pgmout 2>errfile
export err=$?; err_chk

if [ "$SENDCOM" = 'YES' ]; then
        cp $nwstg_bull ${COMOUT}/

if [ "$SENDDBN" = 'YES' ]; then
        ${DBNROOT}/bin/dbn_alert MODEL GTG_GB2 $job $COMOUT/$nwstg_bull
        fi
    fi
