#! /usr/bin/perl -w

use File::Copy;
use strict;
use warnings;

# Storing command line arguments in an array
print "The following arguments were passed to this script:\n";
print "@ARGV\n";

if (! @ARGV) {
    print "No arguments given.\n";
    print "Call adcirc.pl as:\n";
    print"sl15_adcirc3.pl <path> <directory name> <output> \n";
    exit 1;
}

my $path=shift @ARGV;
my $dirname=shift @ARGV;
my $output=shift @ARGV;

#Location of the file to be created
my $archive="$path/$dirname/$output/archive";

#Location of input files
my $fort_61="$path/$dirname/$output/fort.61";
my $fort_62="$path/$dirname/$output/fort.62";
my $fort_63="$path/$dirname/$output/fort.63";
my $fort_64="$path/$dirname/$output/fort.64";
my $fort_71="$path/$dirname/$output/fort.71";
my $fort_72="$path/$dirname/$output/fort.72";
my $fort_73="$path/$dirname/$output/fort.73";
my $fort_74="$path/$dirname/$output/fort.74";
my $ele_63="$path/$dirname/$output/maxele.63";
my $rs_63="$path/$dirname/$output/maxrs.63";
my $vel_63="$path/$dirname/$output/maxvel.63";
my $wvel_63="$path/$dirname/$output/maxwvel.63";

#Append the files to be archived in 'archive' file
my @lines;
$lines[0] = $fort_61;
$lines[1] = $fort_62;
$lines[2] = $fort_63;
$lines[3] = $fort_64;
$lines[4] = $fort_71;
$lines[5] = $fort_72;
$lines[6] = $fort_73;
$lines[7] = $fort_74;
$lines[8] = $ele_63;
$lines[9] = $rs_63;
$lines[10] = $vel_63;
$lines[11] = $wvel_63;

#Write into archive file
open FILE, ">", $archive or die "Cannot open archive: $!";
print FILE join("\n",@lines);
close FILE;

#Archiving into Petashare
system "./CIGR_sync.sh -f $path/$dirname/$output/archive -V";

