#!/usr/bin/perl -w
#
# The input file name will have a form similar to:
#  SSEC_AWIPS_CGINI_TITE64_KNES_012309.N16.gz
# This file is formatted in GINI, and compressed with gzip for
#  transmission over the LDM.  This script moves the CGINI files
#  from /data/fxa/LDAD/tmp to /data/fxa/sat/SBN/Raw where the
#  AWIPS Satdecoder will process them via a signal from sendPing.
#
# Created by
# Jordan Gerth
# Last modified July 2, 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="/preProcessAVHRR.log";
open (LOGAVHRR, ">/awips2/edex/logs/$datedir$logfile");

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

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

## Move, uncompress, and prepare for the Satdecoder
#my $lfina=substr($ofina,0,42);
#my $sfina=substr($ofina,0,39);
#print LOGAVHRR `mv /data/fxa/LDAD/tmp/$ofina /data/fxa/LDAD/tmp/$lfina`;
#print LOGAVHRR `gunzip /data/fxa/LDAD/tmp/$lfina`;
#print LOGAVHRR `mv /data/fxa/LDAD/tmp/$sfina /data/fxa/sat/SBN/Raw/.`;

# Move, uncompress, and prepare for the Satdecoder
my $lfina=substr($ofina,0,42);
my $sfina=substr($ofina,0,39);
print LOGAVHRR `mv /data/fxa/LDAD/tmp/$ofina /data/fxa/LDAD/tmp/$lfina`;
print LOGAVHRR `gunzip /data/fxa/LDAD/tmp/$lfina`;
print LOGAVHRR `mv /data/fxa/LDAD/tmp/$sfina /awips2/edex/data/manual/.`;




# Signal to the Satdecoder that a new file is available
print LOGAVHRR `ssh dx3 sendPing COMMS_ROUTER TIGE01`;

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