#!/usr/bin/perl -w
#
# make-datalist-cruise-vars
#
# Use this script to isolate the cruise ids from paths in
# mbdata and mb_priv that are in datalists.  This script
# will pull uniq sorted cruise ID's from the datalists
# and associated them with variables of the form
# '$cruiseX where x is an integer.  These variables
# can "sourced" into map scripts and used in the legends
# to identify the MB used in the creation of a map
#
# usage:    cat <map-list>.mb-1 | make-datalist-cruise-vars > cruises
#
@list=<STDIN>;
#
foreach(@list) {
    chomp();
    @field=split(/\//,$_);
#    print "$field[3]\n";
    if ($field[3] ne "MB") {
        push(@cruises, $field[3]);
    }
}
#print "@cruises\n";
#
@sorted = sort @cruises;
#print "@sorted\n";
#
%seen = ();
foreach $item (@sorted) {
    push(@uniq, $item) unless $seen{$item}++;
}
#print "@uniq\n";

print "\#\!\/bin\/csh\n";
$count=0;
foreach(@uniq) {
   chomp();
   print "set cruise$count=$_,\n";
   $count++;
}
while($count <= 22) {
   print "set cruise$count=\n";
   $count++;
}
