From 773556adfc941ef624203b98ebb9ed4d6430d23f Mon Sep 17 00:00:00 2001
From: sb476 <devnull@localhost>
Date: Tue, 6 Apr 2004 04:08:25 +0200
Subject: [PATCH] [svn r5684] first release of make-indxal4. let's see what is
 made of it.

---
 noinfo/make-indxal4.pl | 543 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 543 insertions(+)
 create mode 100755 noinfo/make-indxal4.pl

diff --git a/noinfo/make-indxal4.pl b/noinfo/make-indxal4.pl
new file mode 100755
index 000000000..8f6c8add1
--- /dev/null
+++ b/noinfo/make-indxal4.pl
@@ -0,0 +1,543 @@
+#!/usr/bin/perl -w
+use strict;
+
+# no file made for 1996-01 (e.g.) Fix it.
+# 136 ents are in 161. why?
+# no_info col is redundant
+
+((my $progname = $0) =~ s/^.*(\/|\\)//ig); # basename $0
+
+unless ($ARGV[0]) {
+	print "Specify a CSV file name as the first argument (e.g. CAVETAB2.CSV)\n";
+	die $!;
+}
+
+open (CSV, "< $ARGV[0]");
+
+my $verbose_progress = 1;
+if ($ARGV[1]) {
+	if ($ARGV[1] eq "-q") {
+		$verbose_progress = undef;
+	}
+}
+
+# Start writing index file
+open IDXALL, ">..\/indxal.htm" or die $!;
+print IDXALL << "END";
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
+<html lang="en">
+
+<head>
+<title>Loser Plateau area : Cave description index</title>
+</head>
+
+<body>
+
+<h1>Kataster Gruppe 1623:<br>Loser Augst-Eck - INDEX</h1>
+
+<!-- <dl compact> -->
+<table border=0 frame=0>
+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");
+}
+
+print IDXALL << "END";
+</table>
+<!--</dl>-->
+<hr>
+
+<!-- LINKS -->
+<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>
+
+<img alt="&gt;" src="../icons/lists/0.png">
+<b>Main Indices:</b><br>
+
+<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>
+
+<img alt="&gt;" src="../icons/lists/0.png">
+<b>Pictures:</b><br>
+
+<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>
+
+<img alt="&gt;" src="../icons/lists/0.png">
+Other info:<br>
+
+<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>
+
+</body>
+</html>
+END
+
+close IDXALL;
+print "Information: Done\n";
+
+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 ($_[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 ($_[1] eq "cave") {	
+		my $e = $ents;
+		$e =~ s/ +/&nbsp;/g;
+		print IDXALL "<tr><td><a name=\"$number\">$kat_num $other_number";
+		if ($e) {
+			print IDXALL "<small> - $e</small>";
+		}
+		print IDXALL "</a></td><td>";
+		if ($file) {
+			print IDXALL "<a href=\"$file\">";
+		} elsif ($linkfile) {
+			print IDXALL "<a href=\"$linkfile\">";
+		}
+		if ($name) {
+			print IDXALL $name;
+		} else {
+			print IDXALL "?";
+		}
+		if ($unofficial_name) {
+			print IDXALL " ($unofficial_name)";
+		}
+		if ($file or $linkfile) {
+			print IDXALL "</a>";
+		}
+		if ($comment) {
+			print IDXALL " - $comment";
+		}
+		print IDXALL "</tr>\n";
+	}
+
+	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 ($verbose_progress) {
+		print "Progress: $file\n";
+	}
+
+	$number =~ s/\//-/g;
+	$number =~ s/\?/q/;
+	open FILE, "> $file" or die $!;
+
+	print FILE << "END";
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<!-- *** This file is auto-generated by $progname - edit cavetab2.csv instead -->
+<html lang=en>
+
+<head>
+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";
+			}
+		}
+		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") { # 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<hr>\n\n<!-- LINKS -->";
+
+	if ($footer) {
+		print FILE "\n<p>$footer";
+	}
+
+	if ($area =~ /(1a|1b|1c|1d)/) {
+		print FILE "\n<img alt=\"&gt;\" src=\"$toroot\/..\/icons\/lists\/0.png\">";
+		print FILE "\n<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 "\n<a href=\"$toroot\/smkridge\/index.htm#$number\">Schwarzmooskogel ridge area index and description</a><br>";
+	}
+	if ($area =~ /3/) {
+		print FILE "\n<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 "\n<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 "\n<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 "\n<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 "\n<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 "\n<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 "\n<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 "\n<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 "\n<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 "\n<a href=\"javascript:history.back(1)\">Go Back (Javascript)</a><br>";
+	}
+
+	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>
+
+</body>
+</html>
+END
+
+	close FILE;
+}
+
+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);
+}
+
+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"; }
+	}
+}
+
+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<menu>";
+	print FILE "\n<p><b>Entrances:</b>\n<br>";
+	my $e_mult_ents;
+
+	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\n<li>";
+
+		if ($elinkfile) {
+			print FILE "<a href=\"$toroot\/$elinkfile\">$eents $eother_number</a> ";
+			do_this_line($e, "entrance", $kat_num, $other_number_no_brackets);
+		} elsif ($efile) {
+			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 {
+			print FILE "$eents $eother_number";
+		}
+
+		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\n</menu>";
+}