#!/usr/bin/env perl

# Call generate-orbits.pl for the purpose of generating orbits for multiple input files.

use strict;

our $PATH_TO_OBSERVATIONS="/fill-in-a-path/miti.mops";
our $PATH_TO_ORBITS="/fill-in-a-path/orbits.iod";

my $start=1; # Orbit file to start from.
my $file_cnt=368; # Orbit file to end at.

##############################################################################

# Force removal of all log files prior to running.

if(-e "mpc-orbits.bad"){
    die "mpc-orbits.bad exists.";
}

if(-e "mpc-orbits.log"){
    die "mpc-orbits.log exists.";
}

if(-e "mpc-orbits.success"){
    die "mpc-orbits.success exists.";
}

for(my $i=$start;$i<=$file_cnt;$i++){
    print "Iteration $i\n";

    # Don't allow processing if serialized data files exist.
    if(-e "detections.$i.stor" || -e "initial_orbits.$i.stor" || -e "diffcor-orbits.$i.stor"){
        die "ERROR: Serialized data file already exists.";
    }
    `time ./generate-orbits.pl $PATH_TO_OBSERVATIONS/mpc-observations.$i.miti $PATH_TO_ORBITS/mpc-numbered-objects-orbits.iod $i 2>&1 | tee --append mpc-orbits.log`;
}
