#!/usr/bin/perl -w
#
use File::Copy;
use Time::Local;



#$work_dir     = "/data/data065/nprovs/source/data_transfer/cosmic2_ucar";
#$source_dir   = "/data/data065/nprovs/source/data_transfer/cosmic2_ucar";


printf("==============================================================\n");
printf("Running the script that will copy the latest daily collocation\n");
printf("file, run NarcsArchiveBuilder, and run DailyToNetCDF\n");
printf("\n");
system "date";
printf("\n");


# ----------------------------------------------------------
# Determine the date of the data that will be transfered
# (default is yesterday)

my $now = time();
#my $data_date = $now - (15 * 86400);
my $data_date = $now - (16 * 86400);

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($data_date);

$year = 1900 + $year;
$yday = $yday + 1;

my $date_to_process = sprintf "%04d%02d%02d", $year, ($mon+1), $mday;

printf("Date to process: %d/%02d/%04d\n", ($mon+1), $mday, $year);


# ----------------------------------------------------------
# Copy the most recent daily collocation file

$from_file = sprintf("/data/data065/nprovs/data/matchup/nprovs_RD_daily_files/NPROVS_RD_%4d%02d%02d", $year, ($mon+1), $mday);

$to_file = sprintf("/data/data065/nprovs/data/narcs/nprovs_special/NPROVS_RD_%4d%02d%02d", $year, ($mon+1), $mday);

printf("\nCopy from:  %s\n", $from_file);
printf("       to:  %s\n", $to_file);

copy($from_file, $to_file);


# ----------------------------------------------------------
# Run the NarcsArchiveBuilder

system "/data/data065/nprovs/source/narcs/NarcsArchiveBuilder/run_daily_nprovs_special";


# ----------------------------------------------------------
# Run DailyToNetCDF (all platforms)

system "/data/data065/nprovs/source/netcdf/NPROVStoNetCDF/run_nprovs_special_to_netcdf";


# ----------------------------------------------------------
# Run DailyToNetCDF (no test platforms)

system "/data/data065/nprovs/source/netcdf/NPROVStoNetCDF/run_nprovs_special_to_netcdf_notest";


# end of file
