#!/usr/bin/perl -w
#

# This script captures data from an AIRS daily data files and writes
# the data to ODS files.

print " ";
print "Capturing AIRS data into ODS format";
print " ";
system "date";
print "\n\n";


chdir "/data/smcd/nprovs/source/ods_capture/airs";



# =============================================================================
# Create an ODS file

symlink "/data/smcd/nprovs/data/matchup/DailyFiles_incoming/airs.addf", "in.file" or warn "Cannot link to in.file";
symlink "/data/smcd/nprovs/data/ods/airs.ods", "out.file" or warn "Cannot link to out.file";
symlink "/data/smcd/nprovs/source/ods_capture/airs/airs.xml", "parm.file" or warn "Cannot link to parm.file";
symlink "/data/smcd/nprovs/source/ods_capture/airs/edgeparm_airs_addf.txt", "fileparm.file" or warn "Cannot link to fileparm.file";

system "/data/smcd/nprovs/source/ods_capture/airs/createODSFromAirs.x \"AIRS\"";

unlink "in.file" or warn "Cannot unlink in.file";
unlink "out.file" or warn "Cannot unlink out.file";
unlink "parm.file" or warn "Cannot unlink parm.file";
unlink "fileparm.file" or warn "Cannot unlink fileparm.file";




# =============================================================================
# Create an image from the ODS file and send the image to the STAR web site
# for routine monitoring

# Determine the date of the data to process

$data_day = time();

#$data_day -= (2 * 86400);
$data_day -= (1 * 86400);

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($data_day);
$year += 1900;
$mon++;
$sec = 0;
$min = 0;
$hour = 12;
#$wday = 0;
$yday = 0;
$isdst = 0;

my $day_of_data = ($year * 10000) + ($mon * 100) + $mday;


# Build the command line executable an then run it

$input_file   = sprintf("file:/data/smcd/nprovs/data/ods/airs.ods");
$parm_file    = sprintf("parmfile:/data/smcd/nprovs/source/graphics/imagemaker/defaults/airs.xml");
$output_file  = sprintf("output:/net/www/www/smcd/opdb/poes/monitor/images/airs_%d.png", $wday);
$thumb_file   = sprintf("thumbnail:/net/www/www/smcd/opdb/poes/monitor/images/airs_thumb_%d.png", $wday);
$thumb_width  = sprintf("thumbwidth:150");
$thumb_height = sprintf("thumbheight:100");
$verbose      = sprintf("verbose:no");
$file_info    = sprintf("file_info:no");


$exec = sprintf("/usr/bin/java -Djava.awt.headless=true -jar /data/smcd/nprovs/source/graphics/imagemaker/ImageMaker.jar %s %s %s %s %s %s %s %s", $input_file, $parm_file, $output_file, $thumb_file, $thumb_width, $thumb_height, $verbose, $file_info);

system $exec;


# end of file
