expoweb/noinfo/make-indxal4.pl

599 lines
18 KiB
Perl
Raw Normal View History

#!/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
2004-04-20 01:11:21 +01:00
'help' => \$usage # help!
);
# Print usage
if ($usage) {
2004-04-20 01:11:21 +01:00
usage();
}
unless ($ARGV[0]) {
2004-04-20 01:11:21 +01:00
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 INDXAL, ">..\/indxal.htm" or die $!;
print INDXAL << "END";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Loser Plateau area : Cave description index</title>
<link rel="stylesheet" type="text/css" href="css/main2.css">
</head>
<body>
<h1>Kataster Gruppe 1623:<br>Loser Augst-Eck - INDEX</h1>
<table border="0" frame="void">
END
<CSV>; # starting to read in csv file, eat header line
# Read in pos file to @pos now rather than later so we don't repeat it n times
open INPUT2, "< all.pos" or print "Could not find all.pos in the current directory\n" and die $!;
my @pos = <INPUT2>;
close INPUT2;
# Go down a directory
chdir "..";
# While loop which reads in each line of csv file
while (<CSV>) {
chomp;
do_this_line($_, "cave");
}
# Finish writing index file
print INDXAL << "END";
</table>
<!-- LINKS -->
<hr>
<p>
<img alt="&gt;" src="../icons/lists/0.png">
Back to <a href="../index.htm">CUCC Home page</a><br>
<img alt="&gt;" src="../icons/lists/0.png">
Back to <a href="index.htm">Expedition Intro page</a><br>
<h3><img alt="&gt;" src="../icons/lists/0.png"> Main Indices:</h3>
<p>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="infodx.htm"><b>Index</b> to Expo</a> information pages<br>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="areas.htm">Description of CUCC's area</a> and split to subareas<br>
<img alt="---&gt;" src="../icons/lists/1.png">
List of (links to) <a href="pubs.htm">published reports and logbooks</a><br>
<h3><img alt="&gt;" src="../icons/lists/0.png"> Pictures:</h3>
<p>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="gall0.htm">Text only Index</a><br>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="gallery/0.htm">Index pages (with thumbnails)</a><br>
<h3><img alt="&gt;" src="../icons/lists/0.png"> Other info:</h3>
<p>
<img alt="---&gt;" src="../icons/lists/1.png">
Table of <a href="folk/index.htm">members of CUCC expeditions</a> 1976-99<br>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="others/index.htm">Other groups</a> who have worked in the area.<br>
<img alt="---&gt;" src="../icons/lists/1.png">
<a href="1626/index.htm">Adjacent area 1626</a>
<!-- /LINKS -->
</body>
</html>
END
close INDXAL;
print "Information: Done\n";
# Process a line of the CSV file
# First argument is contents of line to process
# Second argument is "cave" or "entrance"
# 3rd arg is the Kataster number of the cave an entrance belongs to (optional)
# 4th arg is the Other number of the cave an entrance belongs to (optional)
# Returns nothing
sub do_this_line {
# Split single line into all the fields
my ($kat_num, $kat_status, $ents, $other_number, $mult_ents, $file, $linkfile, $name, $unofficial_name, $comment, $area, $no_info, $explorers, $u_description, $equipment, $qmlist, $katstatus, $references, $u_centre_line, $u_drawn_survey, $survex_file, $length, $depth, $extent, $header, $footer, $notes, $ent_name, $tag_punkt, $other_punkt, $desc_other_punkt, $exact_punkt, $fix_type, $gpspresa, $gpspostsa, $northing, $easting, $altitude, $bearings, $map, $location, $approach, $ent_desc, $ent_photo, $marking) = &parse_csv($_[0]);
# If we have been called to process an entrance, we may have been given the cave's Kataster number or Other number
if ($_[2] and ! $kat_num) {
$kat_num = $_[2];
}
if ($_[3] and ! $other_number) {
$other_number = $_[3];
}
# Generate $number variable to hold kataster no. or other no. if no kataster no. present
my $number = $kat_num;
my $other_number_no_brackets = $other_number;
if ($kat_num and $other_number) {
$other_number = "($other_number)"; # wrap it in brackets, so it doesn't appear to be official
} elsif ($other_number and ! $kat_num) {
$number = $other_number;
}
# Determine the number of directorys deep the caves main page is at in order to link to area descriptions and indxal
my $toroot = 'Q'; # hey; it's magic
my $counter = ($file =~ tr/\///);
while ($counter) {
$toroot = join('', $toroot, "/..");
$counter--;
}
$toroot =~ s/Q\///;
# If it's a cave, then insert it in the index file
if ($_[1] eq "cave") {
my $e = $ents;
$e =~ s/ +/&nbsp;/g;
print INDXAL "<tr><td><a name=\"$number\">$kat_num $other_number";
if ($e) {
print INDXAL "<small> - $e</small>";
}
print INDXAL "</a></td><td>";
if ($file) {
print INDXAL "<a href=\"$file\">";
} elsif ($linkfile) {
print INDXAL "<a href=\"$linkfile\">";
}
if ($name) {
print INDXAL $name;
} else {
print INDXAL "?";
}
if ($unofficial_name) {
print INDXAL " ($unofficial_name)";
}
if ($file or $linkfile) {
print INDXAL "</a>";
}
if ($comment) {
print INDXAL " - $comment";
}
print INDXAL "</td></tr>\n";
}
# If the cave does not have a filename allocated, but does have multiple entrances, keep going through the CSV file until we are at the last entrance, before we return
unless ($file) { # this IS necessary
if ($mult_ents eq "yes") {
my $e_mult_ents;
do {
my $e = <CSV>;
chomp;
my (undef, undef, undef, undef, $emult_ents) = &parse_csv($e);
$e_mult_ents = $emult_ents;
} while ($e_mult_ents ne "last entrance");
}
return;
}
# If command line option is set, then be quiet
unless ($no_verbose_progress) {
print "Progress: $file\n";
}
# Magic number processing
$number =~ s/\//-/g;
$number =~ s/\?/q/;
# Make the directory that the file is in, in case it doesn't exist yet
my $fn = $file;
$fn =~ s/^.*\///g;
my $path = $file;
$path =~ s/\/$fn//g;
mkpath($path);
# Open the file and start writing to it
open FILE, "> $file" or die $!;
print FILE << "END";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
<html lang=en>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="$toroot/css/main2.css">
END
if ($kat_num) {
print FILE "<title>1623:$kat_num";
} else {
print FILE "<title>$number";
}
print FILE << "END";
</title>
</head>
<body>
<center>
END
if ($header) {
print FILE "$header\n";
}
print FILE "<table border=\"0\" width=\"100%\">\n";
print FILE "<tr><th align=\"left\"><font size=\"+2\">";
if ($kat_num) {
print FILE "$kat_num";
}
if ($ents) {
print FILE " - $ents";
}
if ($other_number) {
print FILE " $other_number";
}
print FILE "</font></th>";
print FILE "<th align=\"center\"><font size=\"+2\">$name";
if ($unofficial_name) {
print FILE " ($unofficial_name)";
}
print FILE "</font></th>";
if ($kat_status) {
print FILE "<th align=\"right\"><font size=\"+2\">$kat_status</font></th>";
}
print FILE "</tr>\n</table>\n</center>";
if ($length or $depth or $extent) {
print FILE "\n\n<p>";
}
if ($length) {
print FILE "<b>Length:</b> $length ";
}
if ($depth) {
print FILE "<b>Depth:</b> $depth ";
}
if ($extent) {
print FILE "<b>Extent:</b> $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<p>";
unless ($ent_name) {
print FILE "<b>Entrance:</b>\n<br>\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<p><b>Location:</b> $location";
}
if ($bearings) {
print FILE "\n\n<p><b>Bearings:</b> $bearings";
}
if ($approach) {
print FILE "\n\n<p><b>Approach:</b> $approach";
}
if ($map) {
print FILE "\n\n<p><b>Map:</b> $map";
}
if ($ent_desc) {
print FILE "\n\n<p><b>Entrance Description:</b> $ent_desc";
}
if ($ent_photo) {
print FILE "\n\n<p><b>Entrance Photo:</b> $ent_photo";
}
if ($marking and $marking ne "\r" and $marking ne "\r\n" and $marking ne "\n") { # bodgelicious.
print FILE "\n\n<p><b>Marking:</b> $marking";
}
if ($references) {
print FILE "\n\n<p><b>References:</b> $references";
}
if ($u_description) {
print FILE "\n\n<p><b>Underground Description:</b> $u_description";
}
if ($equipment) {
print FILE "\n\n<p><b>Equipment:</b> $equipment";
}
if ($qmlist) {
print FILE "\n\n<p><b>QM list:</b> $qmlist";
}
if ($u_drawn_survey) {
print FILE "\n\n<p><b>Survey:</b> $u_drawn_survey";
}
if ($notes) {
print FILE "\n\n<p><b>Notes:</b> $notes";
}
if ($explorers) {
print FILE "\n\n<p><b>Explorers:</b> $explorers";
}
if ($katstatus) {
print FILE "\n\n<p><b>Kataster Status:</b> $katstatus";
}
if ($u_centre_line) {
print FILE "\n\n<p><b>Centre Line:</b> $u_centre_line";
}
if ($survex_file) {
print FILE "\n\n<p><b>Survex file:</b> $survex_file";
}
print FILE "\n\n<!-- LINKS -->\n<hr>\n<p>";
if ($footer) {
print FILE "$footer\n<p>";
}
# Find the area the cave is in, and add appropriate links
if ($area =~ /(1a|1b|1c|1d)/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/plateau\/index.htm#$number\">Plateau area index and description</a><br>";
}
if ($area =~ /(2a|2b)/) {
# we repeat this each time due to cave 39
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/smkridge\/index.htm#$number\">Schwarzmooskogel ridge area index and description</a><br>";
}
if ($area =~ /3/) {
print FILE "<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "\n<a href=\"$toroot\/br-alm\/index.htm#$number\">Br&auml;uning Alm area index and description</a><br>";
}
if ($area =~ /4/) {
print FILE "<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "\n<a href=\"$toroot\/kratzer\/index.htm#$number\">Kratzer valley index and description</a><br>";
}
if ($area =~ /5/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/wilden\/index.htm#$number\">Schwarzmoos-Wildensee area index and description</a><br>";
}
if ($area =~ /6/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/plateau\/index.htm#$number\">Far plateau area index and description</a><br>";
}
if ($area =~ /7/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/egglgrub\/index.htm#$number\">Egglgrube area index and description</a><br>";
}
if ($area =~ /(8a|8b|8c|8d)/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/loser\/index.htm#$number\">Loser/Augst See area index and description</a><br>";
}
if ($area =~ /9/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/gschwand\/index.htm#$number\">Gschwandt area index and description</a><br>";
}
if ($area =~ /10/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/aaussee\/index.htm#$number\">N & NE shore of Altauseer See</a><br>";
}
if ($area =~ /11/) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"$toroot\/augstb\/index.htm#$number\">Augstbach area index and description</a><br>";
}
unless ($area) {
print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
print FILE "<a href=\"javascript:history.back(1)\">Go Back (Javascript)</a><br>"; # ACCK! ACCK! Evil JavaScript!
}
# Finish writing to file
print FILE << "END";
<img alt="&gt;" src="$toroot/../icons/lists/0.png"><a href="$toroot/indxal.htm#$number">Full Index</a><br>
<img alt="&gt;" src="$toroot/../icons/lists/0.png"><a href="$toroot/areas.htm">Other Areas</a><br>
<img alt="&gt;" src="$toroot/../icons/lists/0.png"><a href="$toroot/index.htm">Back to Expedition Intro page</a>
<!-- /LINKS -->
</body>
</html>
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 "<b>Entrance Name:</b> $ent_name\n\n<p>";
}
if ($altitude) {
print FILE "<b>Recorded Alt:</b> $altitude ";
}
if ($northing) {
print FILE "<b>Recorded as N</b>$northing ";
}
if ($easting) {
print FILE "<b>Recorded as E</b>$easting ";
}
if ($fix_type) {
print FILE "<b>Fix type:</b> $fix_type ";
}
if ($tag_punkt) {
print FILE "<b>Tag point:</b> $tag_punkt ";
}
if ($other_punkt) {
print FILE "<b>Point:</b> $other_punkt ";
if ($desc_other_punkt) {
print FILE "<b>Point description:</b> $desc_other_punkt ";
} else {
print FILE "<b>Point description:</b> none ";
}
}
if ($exact_punkt) {
print FILE "<b>Exact entrance:</b> $exact_punkt ";
}
if ($gpspresa) {
print FILE "<b>GPS pre sa:</b> $gpspresa ";
}
if ($gpspostsa) {
print FILE "<b>GPS post sa:</b> $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 "<br>Lookup values for $desc data: ";
print FILE "<b>Alt:</b> $calc_altitude ";
print FILE "<b>N</b>$calc_northing ";
print FILE "<b>E</b>$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<p><b>Entrances:</b>";
print FILE "\n<menu>";
my $e_mult_ents;
# Process each entrance
do {
my $e = <CSV>;
chomp;
my ($ekat_num, undef, $eents, $eother_number, $emult_ents, $efile, $elinkfile, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $eent_name, $etag_punkt, $eother_punkt, $edesc_other_punkt, $eexact_punkt, $efix_type, $egpspresa, $egpspostsa, $enorthing, $eeasting, $ealtitude) = &parse_csv($e);
if ($eother_number) {
$eother_number = "($eother_number)"; # wrap it in brackets, so it doesn't appear to be official
}
print FILE "\n<li>";
if ($elinkfile) { # this is a link to another cave - add link to entrance into cave file but don't generate another file for the entrance
print FILE "<a href=\"$toroot\/$elinkfile\">$eents $eother_number</a> ";
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
} elsif ($efile) { # call ourselves recursively to create a file for the entrance
print FILE "<a href=\"$toroot\/$efile\">$eents $eother_number</a> ";
close FILE; # perl filehandles are not recursively safe (when hacking at 4 in the morning). thus do this.
do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
open FILE, ">> $file" or die $!;
} else { # no entrance file needed, and no link to another cave
print FILE "$eents $eother_number";
}
# Process the location data for the entrance
do_ent($etag_punkt,$eother_punkt,$eexact_punkt,$egpspostsa,$egpspresa,$eeasting,$enorthing,$ealtitude,$eent_name,$efix_type,$edesc_other_punkt);
$e_mult_ents = $emult_ents;
} while ($e_mult_ents ne "last entrance");
print FILE "\n</menu>";
}
2004-04-20 01:11:21 +01:00
# Usage
sub usage {
print << "EOF";
USAGE: $progname [-options] <CSV file>
-q, --quiet Be quiet about progress
-h, --help Show this message
EOF
exit(0);
}