#!/usr/bin/perl -w
#

# This script captures data from MIRS operational daily data files and writes
# the data to ODS files.

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


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



# 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;



# =============================================================================
# Operational M2

symlink "/data/smcd/nprovs/data/matchup/DailyFiles_incoming/mirs_oper_m2.mddf", "in.file" or warn "Cannot link to in.file";
symlink "/data/smcd/nprovs/data/ods/mirs_oper_metopb.ods", "out.file" or warn "Cannot link to out.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/mirs_capture.xml", "parm.file" or warn "Cannot link to parm.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/edgeparm_mirs_mddf.txt", "fileparm.file" or warn "Cannot link to fileparm.file";

system "/data/smcd/nprovs/source/ods_capture/mirs/createODSFromMirs.x \"MIRS Oper MetOp-B\"";

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

# Build the command line executable an then run it

$input_file   = sprintf("file:/data/smcd/nprovs/data/ods/mirs_oper_metopb.ods");
$parm_file    = sprintf("parmfile:/data/smcd/nprovs/source/graphics/imagemaker/defaults/mirs.xml");
$output_file  = sprintf("output:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_metopb_%d.png", $wday);
$thumb_file   = sprintf("thumbnail:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_metopb_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;



# =============================================================================
# Operational NN

symlink "/data/smcd/nprovs/data/matchup/DailyFiles_incoming/mirs_oper_nn.mddf", "in.file" or warn "Cannot link to in.file";
symlink "/data/smcd/nprovs/data/ods/mirs_oper_noaa.ods", "out.file" or warn "Cannot link to out.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/mirs_capture.xml", "parm.file" or warn "Cannot link to parm.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/edgeparm_mirs_mddf.txt", "fileparm.file" or warn "Cannot link to fileparm.file";

system "/data/smcd/nprovs/source/ods_capture/mirs/createODSFromMirs.x \"MIRS Oper NOAA\"";

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

# Build the command line executable an then run it

$input_file   = sprintf("file:/data/smcd/nprovs/data/ods/mirs_oper_noaa.ods");
$parm_file    = sprintf("parmfile:/data/smcd/nprovs/source/graphics/imagemaker/defaults/mirs.xml");
$output_file  = sprintf("output:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_noaa_%d.png", $wday);
$thumb_file   = sprintf("thumbnail:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_noaa_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;



# =============================================================================
# Operational NPP

symlink "/data/smcd/nprovs/data/matchup/DailyFiles_incoming/mirs_oper_np.mddf", "in.file" or warn "Cannot link to in.file";
symlink "/data/smcd/nprovs/data/ods/mirs_oper_npp.ods", "out.file" or warn "Cannot link to out.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/mirs_capture.xml", "parm.file" or warn "Cannot link to parm.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/edgeparm_mirs_mddf.txt", "fileparm.file" or warn "Cannot link to fileparm.file";

system "/data/smcd/nprovs/source/ods_capture/mirs/createODSFromMirs.x \"MIRS Oper NPP\"";

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

# Build the command line executable an then run it

$input_file   = sprintf("file:/data/smcd/nprovs/data/ods/mirs_oper_npp.ods");
$parm_file    = sprintf("parmfile:/data/smcd/nprovs/source/graphics/imagemaker/defaults/mirs.xml");
$output_file  = sprintf("output:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_npp_%d.png", $wday);
$thumb_file   = sprintf("thumbnail:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_npp_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;



# =============================================================================
# Operational SSMIS

symlink "/data/smcd/nprovs/data/matchup/DailyFiles_incoming/mirs_oper_ssmis.mddf", "in.file" or warn "Cannot link to in.file";
symlink "/data/smcd/nprovs/data/ods/mirs_oper_ssmis.ods", "out.file" or warn "Cannot link to out.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/mirs_capture.xml", "parm.file" or warn "Cannot link to parm.file";
symlink "/data/smcd/nprovs/source/ods_capture/mirs/edgeparm_mirs_mddf.txt", "fileparm.file" or warn "Cannot link to fileparm.file";

system "/data/smcd/nprovs/source/ods_capture/mirs/createODSFromMirs.x \"MIRS Oper SSMIS\"";

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

# Build the command line executable an then run it

$input_file   = sprintf("file:/data/smcd/nprovs/data/ods/mirs_oper_ssmis.ods");
$parm_file    = sprintf("parmfile:/data/smcd/nprovs/source/graphics/imagemaker/defaults/mirs.xml");
$output_file  = sprintf("output:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_ssmis_%d.png", $wday);
$thumb_file   = sprintf("thumbnail:/net/www/www/smcd/opdb/poes/monitor/images/mirs_oper_ssmis_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
