#!/usr/bin/perl -w use strict; use File::Path; use Getopt::Long; # no_info col is redundant. FIXME # WTF is dl compact? ((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0 # Parse options my $no_verbose_progress = 0; my $usage = 0; GetOptions('quiet' => \$no_verbose_progress, # be quiet 'help' => \$usage # help! ); # Print usage if ($usage) { usage(); } unless ($ARGV[0]) { print "Specify a CSV file name as the program's argument(e.g. CAVETAB2.CSV)\n"; usage(); } open (CSV, "< $ARGV[0]"); # Start writing index file open IDXALL, ">..\/indxal.htm" or die $!; print IDXALL << "END";
"; if ($kat_num) { print FILE "$kat_num"; } if ($ents) { print FILE " - $ents"; } if ($other_number) { print FILE " $other_number"; } print FILE " | "; print FILE "$name"; if ($unofficial_name) { print FILE " ($unofficial_name)"; } print FILE " | "; if ($kat_status) { print FILE "$kat_status | "; } print FILE "
---|
"; } if ($length) { print FILE "Length: $length "; } if ($depth) { print FILE "Depth: $depth "; } if ($extent) { print FILE "Extent: $extent "; } # Entrance specific bit unless ($mult_ents eq "yes") { # If there is only one entrance if ($tag_punkt or $other_punkt or $exact_punkt or $gpspostsa or $gpspresa or $easting or $northing or $altitude or $fix_type or $desc_other_punkt or $ent_name) { print FILE "\n\n
";
unless ($ent_name) {
print FILE "Entrance:\n
\n";
}
}
# Process the location data for the entrance
do_ent($tag_punkt,$other_punkt,$exact_punkt,$gpspostsa,$gpspresa,$easting,$northing,$altitude,$ent_name,$fix_type,$desc_other_punkt);
} else {
# If there are multiple entrances
multi_ents($file, $kat_num, $other_number, $other_number_no_brackets, $toroot);
}
# Cave general bit
if ($location) {
print FILE "\n\n
Location: $location"; } if ($bearings) { print FILE "\n\n
Bearings: $bearings"; } if ($approach) { print FILE "\n\n
Approach: $approach"; } if ($map) { print FILE "\n\n
Map: $map"; } if ($ent_desc) { print FILE "\n\n
Entrance Description: $ent_desc"; } if ($ent_photo) { print FILE "\n\n
Entrance Photo: $ent_photo"; } if ($marking and $marking ne "\r" and $marking ne "\r\n") { # bodgelicious. print FILE "\n\n
Marking: $marking"; } if ($references) { print FILE "\n\n
References: $references"; } if ($u_description) { print FILE "\n\n
Underground Description: $u_description"; } if ($equipment) { print FILE "\n\n
Equipment: $equipment"; } if ($qmlist) { print FILE "\n\n
QM list: $qmlist"; } if ($u_drawn_survey) { print FILE "\n\n
Survey: $u_drawn_survey"; } if ($notes) { print FILE "\n\n
Notes: $notes"; } if ($explorers) { print FILE "\n\n
Explorers: $explorers"; } if ($katstatus) { print FILE "\n\n
Kataster Status: $katstatus"; } if ($u_centre_line) { print FILE "\n\n
Centre Line: $u_centre_line"; } if ($survex_file) { print FILE "\n\n
Survex file: $survex_file"; } print FILE "\n
$footer";
}
# Find the area the cave is in, and add appropriate links
if ($area =~ /(1a|1b|1c|1d)/) {
print FILE "\n";
print FILE "\nPlateau area index and description
";
}
if ($area =~ /(2a|2b)/) {
# we repeat this each time due to cave 39
print FILE "\n";
print FILE "\nSchwarzmooskogel ridge area index and description
";
}
if ($area =~ /3/) {
print FILE "\n";
print FILE "\nBräuning Alm area index and description
";
}
if ($area =~ /4/) {
print FILE "\n";
print FILE "\nKratzer valley index and description
";
}
if ($area =~ /5/) {
print FILE "\n";
print FILE "\nSchwarzmoos-Wildensee area index and description
";
}
if ($area =~ /6/) {
print FILE "\n";
print FILE "\nFar plateau area index and description
";
}
if ($area =~ /7/) {
print FILE "\n";
print FILE "\nEgglgrube area index and description
";
}
if ($area =~ /(8a|8b|8c|8d)/) {
print FILE "\n";
print FILE "\nLoser/Augst See area index and description
";
}
if ($area =~ /9/) {
print FILE "\n";
print FILE "\nGschwandt area index and description
";
}
if ($area =~ /10/) {
print FILE "\n";
print FILE "\nN & NE shore of Altauseer See
";
}
if ($area =~ /11/) {
print FILE "\n";
print FILE "\nAugstbach area index and description
";
}
unless ($area) {
print FILE "\n";
print FILE "\nGo Back (Javascript)
"; # ACCK! ACCK! Evil JavaScript!
}
# Finish writing to file
print FILE << "END";
Full Index
Other Areas
Back to Expedition Intro page
END
close FILE;
}
# Parse a line of CSV data
# Argument is the line of data to be processed
# Returns array of the separated variables
sub parse_csv {
my $line = $_[0];
my @parsedline = ();
my $field = '';
while ($line =~ m{ \G(?:^|,)
(?: "((?> [^"]*) (?> "" [^"]*)*)" | ([^",]*)) }gx) {
if ($2) {
$field = $2;
} elsif ($1) {
$field = $1;
$field =~ s/""/"/g;
} else {
$field = '';
}
push(@parsedline, $field);
}
return(@parsedline);
}
# Process the location data for the entrance
# Returns nothing
sub do_ent {
my $punkt;
my $calc_easting;
my $calc_northing;
my $calc_altitude;
my $desc;
my $tag_punkt = $_[0];
my $other_punkt = $_[1];
my $exact_punkt = $_[2];
my $gpspostsa = $_[3];
my $gpspresa = $_[4];
my $easting = $_[5];
my $northing = $_[6];
my $altitude = $_[7];
my $ent_name = $_[8];
my $fix_type = $_[9];
my $desc_other_punkt = $_[10];
# Write out info for entrance
if ($ent_name) {
print FILE "Entrance Name: $ent_name\n\n
";
}
if ($altitude) {
print FILE "Recorded Alt: $altitude ";
}
if ($northing) {
print FILE "Recorded as N$northing ";
}
if ($easting) {
print FILE "Recorded as E$easting ";
}
if ($fix_type) {
print FILE "Fix type: $fix_type ";
}
if ($tag_punkt) {
print FILE "Tag point: $tag_punkt ";
}
if ($other_punkt) {
print FILE "Point: $other_punkt ";
if ($desc_other_punkt) {
print FILE "Point description: $desc_other_punkt ";
} else {
print FILE "Point description: none ";
}
}
if ($exact_punkt) {
print FILE "Exact entrance: $exact_punkt ";
}
if ($gpspresa) {
print FILE "GPS pre sa: $gpspresa ";
}
if ($gpspostsa) {
print FILE "GPS post sa: $gpspostsa ";
}
# Decide which punkt to lookup
if ($tag_punkt) {
$punkt=$tag_punkt;
$desc = "tag point";
} elsif ($other_punkt) {
$punkt = $other_punkt;
$desc = "point";
} elsif ($exact_punkt) {
$punkt = $exact_punkt;
$desc = "exact point";
} elsif ($gpspostsa) {
$punkt = $gpspostsa;
$desc = "GPS (pre SA)";
} elsif ($gpspresa) {
$punkt = $gpspresa;
$desc = "GPS (post SA)";
}
# Find the position of that punkt
if ($punkt) {
for my $surveypoint (@pos) {
if ($surveypoint =~ m/\( *([0-9\.\-]*), *([0-9\.\-]*), *([0-9\.\-]*) \) $punkt(\r\n|\n|\r)/){
$calc_easting=$1;
$calc_northing=$2;
$calc_altitude=$3;
}
}
if ($calc_easting) {
print FILE "
Lookup values for $desc data: ";
print FILE "Alt: $calc_altitude ";
print FILE "N$calc_northing ";
print FILE "E$calc_easting ";
} else
{ print "Warning: Lookup point for $desc data not found: $punkt\n"; }
}
}
# Handle multiple entrances
# 1st arg is the file name of the cave to which the entrance belongs
# 2nd arg is the Kataster number of the cave
# 3rd arg is the Other number of the cave (which may have been put in brackets)
# 4th arg is the Other number of the cave without any brackets
# 5th arg is the path to return to the root from the cave
sub multi_ents {
my $file = $_[0];
my $kat_num = $_[1];
my $other_number = $_[2];
my $other_number_no_brackets = $_[3];
my $toroot = $_[4];
print FILE "\n\n