#!/usr/bin/perl -w
#
# The input file name will have a form similar to:
#  SSEC_AWIPS_CONVECT-HI_GRID196_3KM_ALL_GOES_20100702_1432.GRIB2.gz
# This file is formatted in GRIB2, and compressed with gzip for
#  transmission over the LDM.  This script moves the CONVECT files
#  from /data/fxa/LDAD/tmp to /data/fxa/Grid/SBN/rawGrib2 where
#  the AWIPS Grib2Decoder will process them.
#
# Created by
# Jordan Gerth
# Last modified July 1, 2010
# CIMSS/SSEC - Madison, Wisconsin
# http://www.ssec.wisc.edu/~jordang
# jordang@ssec.wisc.edu
#
# and
#
# Jerry Wiedenfeld
# Information Technology Officer
# NWS - Sullivan, Wisconsin
# http://www.crh.noaa.gov/mkx
# jerry.wiedenfeld@noaa.gov

# Create a system to log results of this script
$datedir=`date -u +%Y%m%d`;
chomp $datedir;
$logfile="/preProcessCONVECT.log";
open (LOGCONVECT, ">/data/logs/fxa/$datedir$logfile");

# Record initiation time
print LOGCONVECT "Started ";
print LOGCONVECT `date`;
print LOGCONVECT "\n";

# Remove directory structure from file name
use File::Basename;
$ofina = basename($ARGV[0],"");

# Move, uncompress, and prepare for the Grib2Decoder
my $lfina=substr($ofina,0,65);
my $sfina=substr($ofina,0,62);
print LOGCONVECT `mv /data/fxa/LDAD/tmp/$ofina /data/fxa/LDAD/tmp/$lfina`;
print LOGCONVECT `gunzip /data/fxa/LDAD/tmp/$lfina`;
print LOGCONVECT `mv /data/fxa/LDAD/tmp/$sfina /data/fxa/Grid/SBN/rawGrib2/.`;

# Signal Grib2Decoder
print LOGCONVECT `ssh fxa@dx3 '/awips/fxa/bin/sendPing GRID_ROUTER LTBA98KWBE'`;

# Close and exit
close (LOGCONVECT);
exit(0);
