#!/usr/bin/perl -w
#
# The input file name will have a form similar to:
#  SSEC_AWIPS_COMP_GLOB_25KM_TPW_(MIMIC_20100827_0500.)7231
# This file arrives as a gzip-compressed netCDF file.
#
# Created by
# Jordan Gerth
# Last modified August 27, 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="/preProcessMIMIC.log";
open (LOGMIMIC, ">/data/logs/fxa/$datedir$logfile");

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

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

# Uncompress and place file into location for it to be viewed using the D-2D
my $lfina=substr($ofina,0,19);
my $sfina=substr($lfina,6);
print LOGMIMIC `gunzip /data/fxa/LDAD/tmp/$ofina`;
print LOGMIMIC `rm -f /data/fxa/sat/SSEC/NH/TPW/$sfina`;
print LOGMIMIC `mv /data/fxa/LDAD/tmp/$lfina /data/fxa/sat/SSEC/NH/TPW/$sfina`;

# Force the notificationServer to recognize the new file and
# update the time stamp for the image in the AWIPS menu system
print LOGMIMIC `testFileNotify k 7231 $sfina`;

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