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

# This script copies data from multiple NUCAPS granule files into an daily file

BEGIN
  {
  $ENV{LD_LIBRARY_PATH}="LD_LIBRARY_PATH:/data/starfs1/libs/netcdf-4.2/lib:/data/starfs1/libs/hdf5-1.8.7/lib";
  }



#-------------------------------------------------------------------------
# Variables that can be changed to affect the date to be processed, the location
# of the input data and the location of the output

# Uncomment $year, $mon and $mday to process a specific day. If they are
# commented, then yesterday's data will be processed.

# ***********************
# ***********************
# ***********************
$year = 2023;
$mon  = 4;
$mday = 22;
#$year = 0;
#$mon  = 0;
#$mday = 0;
# ***********************
# ***********************
# ***********************


$raw_data_dir = "/data/data065/nprovs/data/matchup/DailyFiles_incoming/raw_data/temp/noaa21";
$incoming_template = "NUCAPS-EDR_v3r0_n21_";
$nprovs_dir   = "/data/data065/nprovs/data/matchup/DailyFiles_incoming";
$archive_dir  = "/data/data599/orbital_archive/nucaps_noaa21";
$archive_dir2 = "/data/data215/nprovs/data/orbital_archive/nucaps_noaa21";

$source_dir = "/data/data065/nprovs/source/data_transfer/nucaps";

$ods_source_dir = "/data/data065/nprovs/source/graphics/ods_capture/nucaps/version2";
$ods_dir = "/data/data065/nprovs/data/ods/nucaps";
$ftp_dir = "/net/www/aftp/pub/smcd/opdb/nprovs/ods";



chdir $source_dir;


#-------------------------------------------------------------------------
# If $year, $mon or $mday are set, then that date will be that date
# that is processed. Otherwise, the date to process will be yesterday.

$process_specific_date = 0;

if (($year == 0) || ($mon == 0) || ($mday == 0))
  {
  $data_day = time();
  $data_day -= 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;

  $process_specific_date = 1;
  }

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

printf("Date to be processed:  %d\n\n", $data_date);




#-------------------------------------------------------------------------
# Copy the files for the selected date from SCDR to the incoming directory

printf("\nCopying the data from PDA...\n\n");

$file_string = sprintf("/data/scdr060/PDA_IT/NUCAPS/EDR/J02/%d/NUCAPS-EDR*.nc", $data_date);

system "cp " . $file_string . " " . $raw_data_dir;


# end of file
