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


BEGIN
  {
  #$ENV{LD_LIBRARY_PATH}="LD_LIBRARY_PATH:/opt/netcdf/4.6.1:/usr/local/Cellar/hdf5/1.10.2";
  $ENV{LD_LIBRARY_PATH}="LD_LIBRARY_PATH:/opt/homebrew/Cellar/netcdf/4.9.2_1:/opt/homebrew/Cellar/hdf5/1.14.1";
  }

$source_dir      = "/Users/mpettey/Develop/edge/source/Ozone/OzoneCollocationFileBuilder";
$work_dir        = "/Users/mpettey/Develop/edge/source/Ozone/OzoneCollocationFileBuilder";
$collocation_dir = "/Users/mpettey/Develop/edge/source/Ozone/collocations_binary";

# If the collocation directory does not exist

# This script copies data from multiple GOES ABI netCDF files into an GDDF

#print "\n\nProcessing the GOES data\n\n";

chdir($work_dir);




# Date range

$first_date = 20230401;
$last_date  = 20240601;
#$first_date = 20230508;
#$last_date  = 20230508;

$output_file = sprintf("/Users/mpettey/Develop/edge/source/Ozone/ozone_binary_collocations.nc");

unlink $output_file;

symlink $collocation_dir, "in.dir" or warn "Cannot link $collocation_dir to in.dir";
symlink $output_file, "out.file", or warn "Cannot link $output_file to out.file";

system $source_dir . "/OzoneCollocationFileBuilder.x " . $first_date . " " . $last_date;

unlink "out.file" or warn "Cannot unlink out.file";
unlink "in.dir" or warn "Cannot unlink in.dir";



# ===========================================================================
# ===========================================================================
# ===========================================================================
# The subroutine processHour extracts data for a specific hour from the
# ECMWF grib file and writes the data to a binary file

#sub processSite
#  {
#  my ($site, $file_name) = @_;
#
#  printf("\n\n==========================================================\n");
#  printf("==========================================================\n");
#  printf("==========================================================\n");
#  printf("Processing OzoneSonde site:  %s\n\n", $site);
#  printf("Using file name:             %s\n\n", $file_name);
#
#  # Loop through and process the files
#
#  my @sondefiles = glob $raw_data_dir . "/" . $site . "/*.nc";
#
#  foreach $file (@sondefiles)
#    {
#    print "\n-------------------------------\n";
#    print "Processing file: ". $file, "\n\n";
#
#    symlink $file, "in.file" or warn "Cannot link $file to in.file";
#
#    system $source_dir . "/OzoneCollocationFileBuilder.x " . $collocation_dir . " " . $file_name;
#
#    unlink "in.file" or warn "Cannot unlink in.file";
#    }  # foreach ($file...
#
#  }  # sub processSite...

# end of file
