Radreise-Wiki:Km.pl: Unterschied zwischen den Versionen

Aus Radreise-Wiki
Zeile 12: Zeile 12:
  use strict;
  use strict;
   
   
  use Encode qw(encode decode);
  use Encode qw (encode decode);
   
   
  # Default Settings
  my $smoothAlt      =  6;
  require "ini.pl";
  my $changePlaceHm  =  0;
  my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
  my $changeDistHm  =  1;
my $makeRetour    =  0; # not yet implemented
my $verbose        = 0;
   
   
  my $smoothAlt  = 12;
  #==================================
my $makeRetour  = 0;
  # Default Settings and Subroutines
  my $getPlaceHm  =  1;
   
   
  my $routeFileName = "";
  require "ini.pl";
   
   
  if ($#ARGV != -1) {
  my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
$routeFileName = join " ", @ARGV;
if ($routeFileName =~ / \($/) {
$routeFileName .= "retour)";
}
} else {
my @content;
open FIN, "$baseDir/RouteList.txt" or die "\n$! : $baseDir/RouteList.txt";
while (<FIN>) { push @content, decode $encoding, $_; }
close (FIN);
my @content_s = reverse sort @content;
my ($dateTXT, $dateKML, $type, $name) = split " :: ", $content_s[0];
chomp $name;
$routeFileName = $name;
}
my $routeFileName_e = encode $encAnsi, $routeFileName;
#===================
# Reading Trackfile
   
   
  print encode $encOut, "\nReading $routeFileName:\n\n";
  my ($routeFileName, $routeFileName_e) = get_routeFileName (@ARGV);
   
   
  open FIN, "$baseDir/tracks/$routeFileName_e.txt" or die "\n$! : $baseDir/tracks/$routeFileName_e.txt";
  my ($track, $rawTrack) = get_trackfile ($routeFileName);
my $rawTrack = <FIN>;
close (FIN);
   
   
my @rawTrack = split " ", $rawTrack;
my @track    = @$track;
my @track = ();
my @rawTrack = @$rawTrack;
   
   
foreach (@rawTrack) {
  #====================
  # Glättung der Höhen
my ($lon, $lat, $alt) = split ",";
my @zeile    = ( $lat, $lon, $alt );
my $ref_zeile = \@zeile;
push @track, $ref_zeile;
}
  #============================
  # x-fache Glättung der Höhen
   
   
  for (my $j = 1; $j <= $smoothAlt; $j++) {
  for (my $j = 1; $j <= $smoothAlt; $j++) {
  for (my $i = 1; $i < $#track ; $i++) {
  for (my $i = 1; $i < $#track ; $i++) {
   
   
  my $avgAlt = ($track[$i-1][2] + $track[$i][2] + $track[$i+1][2]) / 3;
  my $avgAlt = ($track[$i-1][2] + $track[$i][2] + $track[$i+1][2]) / 3;
 
 
  $track[$i][2] = $avgAlt;
  $track[$i][2] = $avgAlt;
  }
  }
  }
  }
Zeile 89: Zeile 48:
  #======================
  #======================
  # Tracklänge berechnen
  # Tracklänge berechnen
my $length_0 = getDistance (
$track[0][0],          # Erster Punkt : lat
$track[0][1],          # Erster Punkt : lon
$track[$#rawTrack][0],  # Letzter Punkt: lat
$track[$#rawTrack][1]  # Letzter Punkt: lon
);
 
 
  my $length_1 = 0;
  my $length = 0;
   
   
  for (my $i = 0; $i < $#track ; $i++) {
  for (my $i = 0; $i < $#track ; $i++) {
Zeile 110: Zeile 61:
  );
  );
 
 
  $length_1 += $dist;
  $length += $dist;
  }
  }
   
   
Zeile 121: Zeile 72:
  # Ausgabe der Track-Statistik
  # Ausgabe der Track-Statistik
   
   
  print  "Trackpunkte : ", $#track + 1, "\n";
  printf "Trackpunkte : %6d pt\n",   $#track + 1;
printf "Luftlinie  : %4.0f km\n", $length_0;
  printf "Strecke    : %6.0f km\n", $length;
  printf "Strecke    : %4.0f km\n", $length_1;
  printf "Hm auf      : %6.0f<!-- Glattungsfaktor = %d -->\n",  $HmSumUp, $smoothAlt;
#unless ($length_0) { printf "Ratio      : %6.1f\n",    $length_1 / $length_0; }
  printf "Hm ab      : %6.0f\n", $HmSumDn, $smoothAlt;
  printf "Hm auf      : %4.0f m\n",  $HmSumUp;
  printf "Hm ab      : %4.0f m\n\n",$HmSumDn;
   
   
  # ============================
  # ==============
  # Get $routeFileName Textfile
  # Get Routefile
   
   
  my $ucontent = "";
  my ($fileContent, $pre_Roadbook, $Roadbook, $post_Roadbook) = get_routefile ($routeFileName);
open FILE, "$baseDir/text/$routeFileName_e.txt" or die "$baseDir/text/$routeFileName_e.txt: $!";
while (<FILE>) { $ucontent .= $_; }
close FILE;
my $fileContent = decode ($encoding, $ucontent);
   
   
  # ============
my @Roadbook = split "\n", $Roadbook;
  # Get Infobox
  # ===============
  # Get Placemarks
my ($PlacemarksRaw, $Placemarks) = get_placemarks (@Roadbook);
my @Placemarks = @$PlacemarksRaw;
my @placeName;
   
   
  if ( $fileContent =~ /(\{\{Infobox.*?\}\})/s ) {
  my @touriInfo;
   
   
my $infobox = $1;
my @geodaten;
my @geodaten_lat;
  my @geodaten_lon;
   
   
print encode $encOut, "$infobox\n\n";
my @geodaten_alt;
my @geodaten_alt_real;
my @geodaten_alt_res;
   
   
  }
  my @geodaten_info;
my @geodaten_nearest_tp;
my @geodaten_dist_to_tp;
my @roadInfo;
my @kilometrierung;
my @kilometrierung_km;
my @kilometrierung_km_real;
my @kilometrierung_km_res;
my @kilometrierung_km_sum;
my @kilometrierung_km_sum_real;
my @kilometrierung_km_sum_res;
my @kilometrierung_hmup;
my @kilometrierung_hmup_real;
my @kilometrierung_hmup_res;
my @kilometrierung_hmup_sum;
my @kilometrierung_hmup_sum_real;
my @kilometrierung_hmup_sum_res;
   
   
  # =============
  my @kilometrierung_hmdn;
  # Get Roadbook
  my @kilometrierung_hmdn_real;
my @kilometrierung_hmdn_res;
   
   
  my $pre_Roadbook;
  my @kilometrierung_hmdn_sum;
  my $Roadbook;
  my @kilometrierung_hmdn_sum_real;
  my $post_Roadbook;
  my @kilometrierung_hmdn_sum_res;
   
   
  if ( $fileContent =~ /(.*?== Roadbook ==.*?)(===.*?)(\n== .*)/s ) {
  my @rest;
   
   
$pre_Roadbook = $1;
  # =================================
$Roadbook      = $2;
# Check Placemarks except last one
$post_Roadbook = $3;
   
   
  } else { die "Wrong Roadbook Format\n"; }
  for (my $i = 0; $i < $#Placemarks; $i++) {
   
   
my @Roadbook = split "\n", $Roadbook;
my ($placeName, $touriInfo, $geodaten, $roadInfo, $kilometrierung, $rest) = get_placemarkData ($Placemarks[$i]);
   
   
# ===============
if ($placeName) {
# Get Placemarks
   
   
my @Placemarks    = ();
#print encode $encOut, "$placeName\n";
my $placemark    = "";
#print encode $encOut, "\n";
my @PlacemarksRaw = ();
#print encode $encOut, "   $geodaten\n";
my $placemarkRaw  = "";
#print encode $encOut, "  $kilometrierung\n";
#print encode $encOut, "\n";
   
   
foreach my $line (@Roadbook) {
push @placeName, $placeName;
push @touriInfo, $touriInfo;
push @geodaten, $geodaten;
push @roadInfo, $roadInfo;
push @kilometrierung, $kilometrierung;
push @rest, $rest;
   
   
  if ($line =~ /^=== .* ===$/) {
  } else { die "ERROR in get_placemarkData\n"; }
   
   
if ($placemark ne "") {
push @Placemarks  , $placemark;
push @PlacemarksRaw, $placemarkRaw;
}
   
   
$placemarkRaw  = "$line\n";
# ===============
$placemark    =  $line  ;
# Check Geodaten
   
   
  } else {
  my ($lat, $lon, $alt, $info) = get_geodaten ($geodaten[$i]);
   
   
$placemarkRaw .= "$line\n";
if ($lat) {
$placemark    .=  $line  ;
}
}
   
   
push @Placemarks  , $placemark;
my ($trackPoint, $distance) = getClosestPoint ( $lat, $lon );
push @PlacemarksRaw, $placemarkRaw;
   
   
# =================
#print encode $encOut, "  $lat\n";
# Check Placemarks
#print encode $encOut, "  $lon\n";
#print encode $encOut, "  $alt\n";
#print encode $encOut, "  $trackPoint\n";
#print encode $encOut, "  $distance\n";
#print encode $encOut, "\n";
   
   
my @PlaceName ;
push @geodaten_lat, $lat;
my @TouriInfo ;
push @geodaten_lon, $lon;
my @GeoData  ;
push @geodaten_alt, $alt;
my @TrackPoint;
push @geodaten_alt_real, sprintf "%.0f", $track[$trackPoint][2];
my @Distance  ;
push @geodaten_alt_res, $alt;
my @RoadInfo  ;
push @geodaten_info, $info;
my @Kilometer ;
push @geodaten_nearest_tp, $trackPoint;
my @RealKilo  ;
push @geodaten_dist_to_tp, $distance;
   
   
for (my $i=0; $i<=$#Placemarks; $i++) {
} else { die "ERROR in get_geodaten\n"; }
   
   
  my $placeName;
  # =====================
  my $touriInfo;
  # Check Kilometrierung
my $geoData  ;
my $roadInfo ;
my $kilometer;
my $rest;
   
   
  my $lat;
  my ($km, $km_sum, $hmup, $hmdn, $hmup_sum, $hmdn_sum) = get_kilometrierung ($kilometrierung[$i]);
my $lon;
my $alt;
my $info;
   
   
  my $deltaKilo;
  if ($verbose) { print encode $encOut, "$kilometrierung[$i]\n"; }
my $sumKilo;
   
   
  if ( $Placemarks[$i] =~ /
  if ($km) {
^===\ (.*)\ ===                    # placeName
(.*)                                # touriInfo
{{Geodaten\|(.*)}}                  # geoData
(.*)                                # roadInfo
{{Kilometrierung[Hm]*\|(.*)}}(.*)$  # kilometer
/x ) {
$placeName = $1;
$touriInfo = $2;
$geoData  = $3;
$roadInfo  = $4;
$kilometer = $5;
$rest      = $6;
   
   
  # ===============
  #print encode $encOut, "  $km\n";
  # Check: geoData
  #print encode $encOut, "  $sum\n";
#print encode $encOut, "  $hmup\n";
#print encode $encOut, "  $hmdn\n";
#print encode $encOut, "\n";
   
   
  if ($geoData =~ /^([-]?\d+\.\d+)\|([-]?\d+\.\d+)\|([-]?\d+)\|([^\|]+)$/) {
  push @kilometrierung_km,        $km;
push @kilometrierung_km_res,    $km;
   
   
$lat  = $1;
push @kilometrierung_km_sum,    $km_sum;
$lon  = $2;
push @kilometrierung_km_sum_res, $km_sum;
$alt  = $3;
$info = $4;
   
   
  } else {
  push @kilometrierung_hmup,      $hmup;
print "Error in geoData: $geoData\n";
push @kilometrierung_hmup_res,  $hmup;
exit;
}
   
   
  # =================
  push @kilometrierung_hmdn,      $hmdn;
  # Check: Kilometer
  push @kilometrierung_hmdn_res,  $hmdn;
   
   
  if ($kilometer =~ /([\d,]+)\|([\d]+)/) {
  push @kilometrierung_hmup_sum,    $hmup_sum;
push @kilometrierung_hmup_sum_res, $hmup_sum;
   
   
$deltaKilo = $1;
push @kilometrierung_hmdn_sum,    $hmdn_sum;
$sumKilo  = $2;
push @kilometrierung_hmdn_sum_res, $hmdn_sum;
   
   
} else {
} else { die "ERROR in get_kilometrierung\n"; }
print "Error in kilometer: $kilometer\n";
exit;
}
   
   
} elsif (( $i == $#Placemarks ) and ( $Placemarks[$i] =~ /
}
^===\ (.*)\ ===              # placeName
(.*)                        # touriInfo
{{Geodaten\|(.*)}}          # geoData
(.*)                        # roadInfo
/x )) {
   
   
$placeName = $1;
# =====================
$touriInfo = $2;
# Check last Placemark
$geoData  = $3;
$roadInfo  = $4;
# ===============
# Check: Geodata
   
   
if ($geoData =~ /(.*)\|(.*)\|(.*)\|(.*)/) {
my ($placeName, $touriInfo, $geodaten, $roadInfo) = get_lastPlacemarkData ($Placemarks[$#Placemarks]);
   
   
$lat = $1;
  if ($placeName) {
$lon  = $2;
$alt  = $3;
$info = $4;
   
   
} else {
#print encode $encOut, "$placeName\n";
print "Error in geoData: $geoData\n";
#print encode $encOut, "\n";
exit;
#print encode $encOut, "   $geodaten\n";
}
#print encode $encOut, "\n";
   
   
# ==================
push @placeName, $placeName;
# Kilometer Dummies
push @touriInfo, $touriInfo;
push @geodaten,  $geodaten;
push @roadInfo,  $roadInfo;
push @kilometrierung, "";
push @rest,          "";
   
   
$deltaKilo = "   ";
push @kilometrierung_km,        "";
$sumKilo  = " ";
push @kilometrierung_km_res,    "";
   
   
  } elsif ( $Placemarks[$i] =~ /
  push @kilometrierung_km_sum,    "";
push @kilometrierung_km_sum_res, "";
^===\ (.*)\ ===              # placeName
(.*)                        # touriInfo
{{Geodaten\|(.*)}}          # geoData
(.*)                        # roadInfo
/x ) {
   
   
$placeName = $1;
push @kilometrierung_hmup,      "";
$touriInfo = $2;
push @kilometrierung_hmup_res,   "";
$geoData   = $3;
$roadInfo  = $4;
# ===============
# Check: Geodata
   
   
if ($geoData =~ /(.*)\|(.*)\|(.*)\|(.*)/) {
push @kilometrierung_hmdn,      "";
push @kilometrierung_hmdn_res,  "";
   
   
$lat  = $1;
push @kilometrierung_hmup_sum,    "";
$lon  = $2;
push @kilometrierung_hmup_sum_res, "";
$alt  = $3;
$info = $4;
   
   
} else {
push @kilometrierung_hmdn_sum,    "";
print "Error in geoData: $geoData\n";
push @kilometrierung_hmdn_sum_res, "";
exit;
}
   
   
# ==================
} else { die "ERROR in get_lastPlacemarkData\n"; }
# Kilometer Dummies
   
   
$deltaKilo = "x,x";
# =================================
$sumKilo  = "x";
# Check Geodaten of last Placemark
   
   
} else {
my ($lat, $lon, $alt, $info) = get_geodaten ($geodaten[$#geodaten]);
   
   
print encode $encoding, "Untreated Error: $Placemarks[$i]\n";
if ($lat) {
exit;
}
   
   
  my ($trackPoint, $distance) = getClosestPoint ( $lat, $lon );
  my ($trackPoint, $distance) = getClosestPoint ( $lat, $lon );
   
   
  if ($distance < 200) {
  #print encode $encOut, "  $lat\n";
#print encode $encOut, "  $lon\n";
#$distance = "  ";
#print encode $encOut, $alt\n";
#print encode $encOut, "  $trackPoint\n";
  } else { $distance .= "!!!"; }
  #print encode $encOut, "  $distance\n";
#print encode $encOut, "\n";
push @geodaten_lat, $lat;
push @geodaten_lon, $lon;
push @geodaten_alt, $alt;
push @geodaten_alt_real, sprintf "%.0f", $track[$trackPoint][2];
push @geodaten_alt_res, $alt;
push @geodaten_info, $info;
push @geodaten_nearest_tp, $trackPoint;
push @geodaten_dist_to_tp, $distance;
   
   
push @PlaceName , $placeName;
  } else { die "ERROR in get_geodaten\n"; }
push @TouriInfo , $touriInfo;
push @GeoData  , sprintf "%10.7f %10.7f", $lat, $lon;
push @TrackPoint, sprintf "%5d", $trackPoint;
push @Distance , sprintf "%3.0f m", $distance;
push @RoadInfo  , $roadInfo;
push @Kilometer , sprintf "%4s %4s", $deltaKilo, $sumKilo;
}
   
   
  # =========================
  # =========================
  # Calculate real Distances
  # Calculate real Distances
   
   
  my $sum;
  my $sum_real;
my $HmTotSumUp;
my $HmTotSumDn;
   
   
  for (my $i=0; $i < $#Placemarks; $i++) {
  for (my $i=0; $i < $#Placemarks; $i++) {
   
   
  my $length;
  my $km_real;
   
   
  for (my $j = $TrackPoint[$i]; $j < $TrackPoint[$i+1] ; $j++) {
  for (my $j = $geodaten_nearest_tp[$i]; $j < $geodaten_nearest_tp[$i+1] ; $j++) {
   
   
  my $dist = getDistance ( $track[$j][0], $track[$j][1], $track[$j+1][0], $track[$j+1][1] );
  my $dist = getDistance ( $track[$j][0], $track[$j][1], $track[$j+1][0], $track[$j+1][1] );
   
   
  $length += $dist;
  $km_real += $dist;
  }
  }
   
   
  $sum += $length;
  $sum_real += $km_real;
   
   
  my $realKilo = sprintf "%4.1f %4.0f", $length, $sum;
  push @kilometrierung_km_real, sprintf "%.1f", $km_real;
push @kilometrierung_km_sum_real, sprintf "%.0f", $sum_real;
}
   
   
$realKilo =~ s/\./,/;
push @kilometrierung_km_real, "";
push @kilometrierung_km_sum_real, "";
   
   
if ($Kilometer[$i] eq $realKilo) {
$realKilo      = "        ";
$Kilometer[$i] = "        ";
}
   
   
push @RealKilo, $realKilo;
# ==========================
# Calculate real Höhenmeter
my $sum_hmup;
my $sum_hmdn;
for (my $i=0; $i < $#Placemarks; $i++) {
   
   
  my ($HmSumUp, $HmSumDn) = getHmSum ($TrackPoint[$i], $TrackPoint[$i+1]);
  my ($hmup, $hmdn) = getHmSum ($geodaten_nearest_tp[$i], $geodaten_nearest_tp[$i+1]);
   
   
  #printf "%s;%0.0f;%0.0f;%0.0f;%0.0f\n", encode ($encOut, $PlaceName[$i]),$length,$HmSumUp,$HmSumDn,$track[$TrackPoint[$i]][2];
  $sum_hmup += $hmup;
$sum_hmdn += $hmdn;
   
   
  $HmTotSumUp += $HmSumUp;
  push @kilometrierung_hmup_real, sprintf "%.0f", $hmup;
  $HmTotSumDn += $HmSumDn;
push @kilometrierung_hmdn_real, sprintf "%.0f", $hmdn;
  push @kilometrierung_hmup_sum_real, sprintf "%.0f", $sum_hmup;
push @kilometrierung_hmdn_sum_real, sprintf "%.0f", $sum_hmdn;
  }
  }
   
   
  push @RealKilo, "         ";
  push @kilometrierung_hmup_real, "";
push @kilometrierung_hmdn_real, "";
push @kilometrierung_hmup_sum_real, "";
push @kilometrierung_hmdn_sum_real, "";
   
   
printf "GesamtHm: %0.0f;%0.0f\n", $HmTotSumUp,$HmTotSumDn;
print "\n";
   
   
  # =====================================
  # =====================================
Zeile 410: Zeile 348:
  for (my $i=0; $i<$#Placemarks; $i++) {
  for (my $i=0; $i<$#Placemarks; $i++) {
   
   
  if ( $TrackPoint[$i] <= $TrackPoint[$i+1] ) {
  if ( $geodaten_nearest_tp[$i] <= $geodaten_nearest_tp[$i+1] ) {
   
   
  #ok
  #ok
Zeile 416: Zeile 354:
  } else {
  } else {
   
   
  print encode $encOut, "Error: Wrong TrackPoint Order in:\n";
  print encode $encOut, "ERROR: Wrong TrackPoint Order in:\n";
  print encode $encOut, "$PlaceName[$i] :: $GeoData[$i] :: $TrackPoint[$i]\n";
  print encode $encOut, "   $placeName[$i] :: $geodaten_nearest_tp[$i]\n";
  print encode $encOut, "$PlaceName[$i+1] :: $GeoData[$i+1] :: $TrackPoint[$i+1]\n";
  print encode $encOut, "   $placeName[$i+1] :: $geodaten_nearest_tp[$i+1]\n\n";
#exit(1);
  }
  }
  }
  }
   
   
  # =====================
  # ===================
  # Show Change Overview
# Summarize all Data
my $output = sprintf "%5s  %3s %4s %5s %5s %5s %5s %5s  %s",
   
"tp#",
"dist",
"k",
"k_s",
"k_r",
"k_s_r",
"a",
"a_r",
"place";
if ($verbose) { print encode $encOut, "$output\n"; }
   
   
  for (my $i=0; $i<=$#Placemarks; $i++) {
  for (my $i=0; $i <= $#Placemarks; $i++) {
   
   
  my $s = sprintf "%s %s %s %s %s\n",  
  my $output = sprintf "%5d %3.0f m %4s %5s %5s %5s %5s %5s  %s",
$TrackPoint[$i], $Distance[$i], $Kilometer[$i],
$RealKilo[$i], substr($PlaceName[$i], 0, 52);
   
   
  print encode $encOut, $s;
$geodaten_nearest_tp[$i],
$geodaten_dist_to_tp[$i],
$kilometrierung_km[$i],
$kilometrierung_km_sum[$i],
$kilometrierung_km_real[$i],
$kilometrierung_km_sum_real[$i],
$geodaten_alt[$i],
$geodaten_alt_real[$i],
$placeName[$i];
 
if ($verbose) { print encode $encOut, "$output\n"; }
  }
  }
print "\n";
   
   
  # ========================
if ($verbose) { print encode $encOut, "\n"; }
  # Perform Changes on File
  # ==================
  # Summarize Changes
my $change;
my $output = sprintf "%5s  %3s %4s %5s %5s %5s %5s %5s  %s",
   
   
my $change = 0;
"tp#",
"dist",
"k",
"k_s",
"k_r",
"k_s_r",
"a",
"a_r",
"place";
   
   
  for (my $i=0; $i<=$#Placemarks; $i++) {
  print encode $encOut, "$output\n";
   
   
  if ( $RealKilo[$i] !~ /^\s*$/ ) {
for (my $i=0; $i <= $#Placemarks; $i++) {
  $kilometrierung_km_real[$i] =~ s/\./\,/;
if ($kilometrierung_km[$i] eq $kilometrierung_km_real[$i]) {
$kilometrierung_km[$i] = "";
$kilometrierung_km_real[$i] = "";
} else {
 
 
  print encode $encOut, "Change: $PlaceName[$i]\n";
  $kilometrierung_km_res[$i] = $kilometrierung_km_real[$i];
$change = 1;
}
   
   
my $deltaKiloNew;
if ($kilometrierung_km_sum[$i] eq $kilometrierung_km_sum_real[$i]) {
my $sumKiloNew;
   
   
  if ( $RealKilo[$i] =~ /^\s*([0-9,]+)\s+([0-9]+)$/ ) {
  $kilometrierung_km_sum[$i] = "";
$kilometrierung_km_sum_real[$i] = "";
   
   
$deltaKiloNew = $1;
} else {
  $sumKiloNew  = $2;
$kilometrierung_km_sum_res[$i] = $kilometrierung_km_sum_real[$i];
$change = 1;
}
if ($changePlaceHm) {
if ($geodaten_alt[$i] eq $geodaten_alt_real[$i]) {
  $geodaten_alt[$i] = "";
$geodaten_alt_real[$i] = "";
   
   
  } else {
  } else {
  print "  No Match: >$RealKilo[$i]<\n";
  $geodaten_alt_res[$i] = $geodaten_alt_real[$i];
  exit;
  $change = 1;  
  }
  }
   
   
my $deltaKiloOld;
} else {
my $sumKiloOld;
   
   
  if ( $Kilometer[$i] =~ /^\s*([0-9,]+)\s+([0-9]+)$/ ) {
  $geodaten_alt[$i] = "";
$geodaten_alt_real[$i] = "";
}
   
   
$deltaKiloOld = $1;
if ($changeDistHm) {
$sumKiloOld  = $2;
   
   
if ($fileContent =~
if ($kilometrierung_hmdn[$i] eq $kilometrierung_hmdn_real[$i]) {
s/{{Kilometrierung\|$deltaKiloOld\|$sumKiloOld}}/{{Kilometrierung\|$deltaKiloNew\|$sumKiloNew}}/s) {
   
   
print "  $deltaKiloOld->$deltaKiloNew\n";
$kilometrierung_hmdn[$i] = "";
print "  $sumKiloOld->$sumKiloNew\n";
$kilometrierung_hmdn_real[$i] = "";
   
   
$change = 1;
} else {
$kilometrierung_hmdn_res[$i] = $kilometrierung_hmdn_real[$i];
$change = 1;  
}
   
   
} else {
if ($kilometrierung_hmup[$i] eq $kilometrierung_hmup_real[$i]) {
   
   
print "   No Match in km!\n";
$kilometrierung_hmup[$i] = "";
exit;
$kilometrierung_hmup_real[$i] = "";
}
   
   
  } elsif ( $Kilometer[$i] =~ /^\s*x,x\s+x$/ ) {
  } else {
$kilometrierung_hmup_res[$i] = $kilometrierung_hmup_real[$i];
$change = 1;
}
   
   
if ($fileContent =~
if ($kilometrierung_hmup_sum[$i] eq $kilometrierung_hmup_sum_real[$i]) {
s/=== $PlaceName[$i+1] ===/{{Kilometrierung\|$deltaKiloNew\|$sumKiloNew}}\n\n=== $PlaceName[$i+1] ===/s) {
   
   
print "   No Kilometrierung ->$deltaKiloNew\n";
$kilometrierung_hmup_sum[$i] = "";
print "   No Kilometrierung ->$sumKiloNew\n";
$kilometrierung_hmup_sum_real[$i] = "";
   
   
$change = 1;
} else {
$kilometrierung_hmup_sum_res[$i] = $kilometrierung_hmup_sum_real[$i];
$change = 1;  
}
   
   
} else {
if ($kilometrierung_hmdn_sum[$i] eq $kilometrierung_hmdn_sum_real[$i]) {
   
   
print "  No Match! $PlaceName[$i+1]\n{{Kilometrierung\|$deltaKiloNew\|$sumKiloNew}}\n";
$kilometrierung_hmdn_sum[$i] = "";
#exit;
$kilometrierung_hmdn_sum_real[$i] = "";
}
   
   
  } else {
  } else {
  print "  No Match: >$Kilometer[$i]<\n";
  $kilometrierung_hmdn_sum_res[$i] = $kilometrierung_hmdn_sum_real[$i];
  exit;
  $change = 1;  
  }
  }
   
   
} else {
  }
  }
my $output = sprintf "%5d %3.0f m %4s %5s %5s %5s %5s %5s  %s",
$geodaten_nearest_tp[$i],
$geodaten_dist_to_tp[$i],
$kilometrierung_km[$i],
$kilometrierung_km_sum[$i],
$kilometrierung_km_real[$i],
$kilometrierung_km_sum_real[$i],
$geodaten_alt[$i],
$geodaten_alt_real[$i],
$placeName[$i];
print encode $encOut, "$output\n";
  }
  }
# ======================
# Write Changes to File
   
   
  if ($change) {
  if ($change) {
   
   
  open  FOUT, "> $outDir/${routeFileName_e}_new.txt" or die $!;
  $fileContent = "";
print FOUT encode ($encoding, $fileContent);
close FOUT;
   
   
}
$fileContent .= $pre_Roadbook;
   
   
# ====================================
# Generate Retour-Roadbook with Track
   
   
if ($makeRetour) {
for (my $i=0; $i < $#Placemarks; $i++) {
   
   
my $content;
$fileContent .= "=== $placeName[$i] ===\n";
$fileContent .= "$touriInfo[$i]\n";
$fileContent .= "{{Geodaten|$geodaten_lat[$i]|$geodaten_lon[$i]|$geodaten_alt_res[$i]|$geodaten_info[$i]}}\n";
$fileContent .= "$roadInfo[$i]\n";
   
   
$content .= $pre_Roadbook;
if ($kilometrierung[$i] =~ /KilometrierungHm6/) {
   
   
for (my $i=$#Placemarks; $i>=0; $i--) {
$fileContent .= "{{KilometrierungHm6|$kilometrierung_km_res[$i]|$kilometrierung_hmup_res[$i]|$kilometrierung_hmdn_res[$i]|$kilometrierung_km_sum_res[$i]|$kilometrierung_hmup_sum_res[$i]|$kilometrierung_hmdn_sum_res[$i]}}";
   
   
  my $placemark = $PlacemarksRaw[$i];
  } elsif ($kilometrierung[$i] =~ /KilometrierungHm/) {
   
   
if ( $placemark =~ /(.+{{Geodaten.*?}})/s ) {
$fileContent .= "{{KilometrierungHm|$kilometrierung_km_res[$i]|$kilometrierung_km_sum_res[$i]|$kilometrierung_hmup_sum_res[$i]|$kilometrierung_hmdn_sum_res[$i]}}";
   
   
$placemark = $1;
} else {
   
   
} else {
  $fileContent .= "{{Kilometrierung|$kilometrierung_km_res[$i]|$kilometrierung_km_sum_res[$i]}}";
 
print "No match in Placemark: $placemark\n";
exit;  
  }
  }
   
   
  if ($i > 0) { $placemark .= "\n\n{{Kilometrierung|0,0|0}}\n"; }
  $fileContent .= "\n$rest[$i]";
$content .= "$placemark\n";
  }
  }
   
   
  $content .= $post_Roadbook;
  $fileContent .= "=== $placeName[$#Placemarks] ===\n";
$fileContent .= "$touriInfo[$#Placemarks]\n";
$fileContent .= "{{Geodaten|$geodaten_lat[$#Placemarks]|$geodaten_lon[$#Placemarks]|$geodaten_alt_res[$#Placemarks]|$geodaten_info[$#Placemarks]}}\n";
$fileContent .= "$roadInfo[$#Placemarks]";
   
   
  $content =~ s/\n\n\n/\n\n/g;
  $fileContent .= $post_Roadbook;
  $rawTrack = join " ", reverse @rawTrack;
  open  FOUT, "> $outDir/${routeFileName_e}_new.tx" or die $!;
  print FOUT encode ($encoding, $fileContent);
  $content .= "\n$routeFileName (retour) :: $routeFileName\_%28retour%29 :: $rawTrack\n";
close FOUT;
   
   
open  FOUT, "> $outDir/${routeFileName_e}_ret.txt" or die $!;
print FOUT encode ($encoding, $content);
close FOUT;
  }
  }
   
   
  exit;
  exit;
   
   
  #==========================================================
  #==========================================================
Zeile 589: Zeile 603:
  }
  }
   
   
  my $dist = acos($val) * 6378.137;      # radius of the equator in km
  my $dist = acos($val) * 6378.137;      # radius of equator in km
   
   
  #if (Double.isNaN(dist)) dist = 0;
  #if (Double.isNaN(dist)) dist = 0;
  return $dist;
  return $dist;
  }
  }

Version vom 29. Januar 2012, 21:23 Uhr

Das Perl-Skript km.pl wird mit dem Streckennamen als Parameter aufgerufen. Die zugehörige Streckendatei muss bereits im text- und die Trackdatei im track-Verzeichnis vorhanden sein. Beispiel für einen Aufruf:

perl km.pl Donau

Das Skript berechnet die Kilometrierung des Roadbook und speichert das Ergebnis als Datei im Output-Verzeichnis (siehe ini.pl). Die Datei "Donau_new.txt" enthält das neue Roadbook und kann mit einem UTF8-fähigen Texteditor geöffnet und direkt in das Edit-Fenster des Streckenartikels kopiert werden.

Wenn man die Variable $makeRetour = 1 setzt, dann wird zusätzlich eine Datei erzeugt, die das Retour-Roadbook und den Retour-Track enthält.

Quellcode des Skripts:

 use strict;
 
 use Encode qw (encode decode);
 
 my $smoothAlt      =  6;
 my $changePlaceHm  =  0;
 my $changeDistHm   =  1;
 my $makeRetour     =  0; # not yet implemented
 my $verbose        =  0;
 
 #==================================
 # Default Settings and Subroutines
 
 require "ini.pl";
 
 my ($baseDir, $outDir, $username, $password, $encoding, $encAnsi, $encOut) = getIni();
 
 my ($routeFileName, $routeFileName_e) = get_routeFileName (@ARGV);
 
 my ($track, $rawTrack) = get_trackfile ($routeFileName);
 
 	my @track    = @$track;
 	my @rawTrack = @$rawTrack;
 
 #====================
 # Glättung der Höhen
 
 for (my $j = 1; $j <= $smoothAlt; $j++) {
 	for (my $i = 1; $i < $#track ; $i++) {
 
 		my $avgAlt = ($track[$i-1][2] + $track[$i][2] + $track[$i+1][2]) / 3;
 		
 		$track[$i][2] = $avgAlt;
 	}
 }
 
 #======================
 # Tracklänge berechnen
 	
 my $length = 0;
 
 for (my $i = 0; $i < $#track ; $i++) {	
 
 	my $dist = getDistance ( 
 	
 		$track[$i][0], 
 		$track[$i][1], 
 		$track[$i+1][0], 
 		$track[$i+1][1] 
 	);
 		
 	$length += $dist;
 }
 
 #=============================
 # Gesamt-Höhenmeter berechnen
 
 my ($HmSumUp, $HmSumDn) = getHmSum (0, $#track);
 
 #=============================
 # Ausgabe der Track-Statistik
 
 printf "Trackpunkte : %6d pt\n",   $#track + 1;
 printf "Strecke     : %6.0f km\n", $length;
 printf "Hm auf      : %6.0f<!-- Glattungsfaktor = %d -->\n",  $HmSumUp, $smoothAlt;
 printf "Hm ab       : %6.0f\n",  $HmSumDn, $smoothAlt;
 
 # ==============
 # Get Routefile
 
 my ($fileContent, $pre_Roadbook, $Roadbook, $post_Roadbook) = get_routefile ($routeFileName);
 
 my @Roadbook = split "\n", $Roadbook;
 
 # ===============
 # Get Placemarks
 
 my ($PlacemarksRaw, $Placemarks) = get_placemarks (@Roadbook);
 
 my @Placemarks = @$PlacemarksRaw;
 
 my @placeName;
 
 my @touriInfo;
 
 my @geodaten;
 my @geodaten_lat;
 my @geodaten_lon;
 
 my @geodaten_alt;
 my @geodaten_alt_real;
 my @geodaten_alt_res;
 
 my @geodaten_info;
 my @geodaten_nearest_tp;
 my @geodaten_dist_to_tp;
 
 my @roadInfo;
 
 my @kilometrierung;
 
 my @kilometrierung_km;
 my @kilometrierung_km_real;
 my @kilometrierung_km_res;
 
 my @kilometrierung_km_sum;
 my @kilometrierung_km_sum_real;
 my @kilometrierung_km_sum_res;
 
 my @kilometrierung_hmup;
 my @kilometrierung_hmup_real;
 my @kilometrierung_hmup_res;
 
 my @kilometrierung_hmup_sum;
 my @kilometrierung_hmup_sum_real;
 my @kilometrierung_hmup_sum_res;
 
 my @kilometrierung_hmdn;
 my @kilometrierung_hmdn_real;
 my @kilometrierung_hmdn_res;
 
 my @kilometrierung_hmdn_sum;
 my @kilometrierung_hmdn_sum_real;
 my @kilometrierung_hmdn_sum_res;
 
 my @rest;
 
 # =================================
 # Check Placemarks except last one
 
 for (my $i = 0; $i < $#Placemarks; $i++) {
 
 	my ($placeName, $touriInfo, $geodaten, $roadInfo, $kilometrierung, $rest) = get_placemarkData ($Placemarks[$i]);
 
 	if ($placeName) {
 
 		#print encode $encOut, "$placeName\n";
 		#print encode $encOut, "\n";
 		#print encode $encOut, "   $geodaten\n";
 		#print encode $encOut, "   $kilometrierung\n";
 		#print encode $encOut, "\n";
 
 		push @placeName, $placeName;
 		push @touriInfo, $touriInfo;
 		push @geodaten, $geodaten;
 		push @roadInfo, $roadInfo;
 		push @kilometrierung, $kilometrierung;
 		push @rest, $rest;
 
 	} else { die "ERROR in get_placemarkData\n"; }
 
 
 	# ===============
 	# Check Geodaten
 
 	my ($lat, $lon, $alt, $info) = get_geodaten ($geodaten[$i]);
 
 	if ($lat) {
 
 		my ($trackPoint, $distance) = getClosestPoint ( $lat, $lon );
 
 		#print encode $encOut, "   $lat\n";
 		#print encode $encOut, "   $lon\n";
 		#print encode $encOut, "   $alt\n";
 		#print encode $encOut, "   $trackPoint\n";
 		#print encode $encOut, "   $distance\n";
 		#print encode $encOut, "\n";
 
 		push @geodaten_lat, $lat;
 		push @geodaten_lon, $lon;
 		push @geodaten_alt, $alt;
 		push @geodaten_alt_real, sprintf "%.0f", $track[$trackPoint][2];
 		push @geodaten_alt_res, $alt;
 		push @geodaten_info, $info;
 		push @geodaten_nearest_tp, $trackPoint;
 		push @geodaten_dist_to_tp, $distance;
 
 	} else { die "ERROR in get_geodaten\n"; }
 
 	# =====================
 	# Check Kilometrierung
 
 	my ($km, $km_sum, $hmup, $hmdn, $hmup_sum, $hmdn_sum) = get_kilometrierung ($kilometrierung[$i]);
 
 	if ($verbose) { print encode $encOut, "$kilometrierung[$i]\n"; }
 
 	if ($km) {
 
 		#print encode $encOut, "   $km\n";
 		#print encode $encOut, "   $sum\n";
 		#print encode $encOut, "   $hmup\n";
 		#print encode $encOut, "   $hmdn\n";
 		#print encode $encOut, "\n";
 
 		push @kilometrierung_km,         $km;
 		push @kilometrierung_km_res,     $km;
 
 		push @kilometrierung_km_sum,     $km_sum;
 		push @kilometrierung_km_sum_res, $km_sum;
 
 		push @kilometrierung_hmup,       $hmup;
 		push @kilometrierung_hmup_res,   $hmup;
 
 		push @kilometrierung_hmdn,       $hmdn;
 		push @kilometrierung_hmdn_res,   $hmdn;
 
 		push @kilometrierung_hmup_sum,     $hmup_sum;
 		push @kilometrierung_hmup_sum_res, $hmup_sum;
 
 		push @kilometrierung_hmdn_sum,     $hmdn_sum;
 		push @kilometrierung_hmdn_sum_res, $hmdn_sum;
 
 	} else { die "ERROR in get_kilometrierung\n"; }
 
 }
 
 # =====================
 # Check last Placemark
 
 my ($placeName, $touriInfo, $geodaten, $roadInfo) = get_lastPlacemarkData ($Placemarks[$#Placemarks]);
 
 if ($placeName) {
 
 	#print encode $encOut, "$placeName\n";
 	#print encode $encOut, "\n";
 	#print encode $encOut, "   $geodaten\n";
 	#print encode $encOut, "\n";
 
 	push @placeName, $placeName;
 	push @touriInfo, $touriInfo;
 	push @geodaten,  $geodaten;
 	push @roadInfo,  $roadInfo;
 	push @kilometrierung, "";
 	push @rest,           "";
 
 	push @kilometrierung_km,         "";
 	push @kilometrierung_km_res,     "";
 
 	push @kilometrierung_km_sum,     "";
 	push @kilometrierung_km_sum_res, "";
 
 	push @kilometrierung_hmup,       "";
 	push @kilometrierung_hmup_res,   "";
 
 	push @kilometrierung_hmdn,       "";
 	push @kilometrierung_hmdn_res,   "";
 
 	push @kilometrierung_hmup_sum,     "";
 	push @kilometrierung_hmup_sum_res, "";
 
 	push @kilometrierung_hmdn_sum,     "";
 	push @kilometrierung_hmdn_sum_res, "";
 
 } else { die "ERROR in get_lastPlacemarkData\n"; }
 
 # =================================
 # Check Geodaten of last Placemark
 
 my ($lat, $lon, $alt, $info) = get_geodaten ($geodaten[$#geodaten]);
 
 if ($lat) {
 
 	my ($trackPoint, $distance) = getClosestPoint ( $lat, $lon );
 
 	#print encode $encOut, "   $lat\n";
 	#print encode $encOut, "   $lon\n";
 	#print encode $encOut, "   $alt\n";
 	#print encode $encOut, "   $trackPoint\n";
 	#print encode $encOut, "   $distance\n";
 	#print encode $encOut, "\n";
 
 	push @geodaten_lat, $lat;
 	push @geodaten_lon, $lon;
 	push @geodaten_alt, $alt;
 	push @geodaten_alt_real, sprintf "%.0f", $track[$trackPoint][2];
 	push @geodaten_alt_res, $alt;
 	push @geodaten_info, $info;
 	push @geodaten_nearest_tp, $trackPoint;
 	push @geodaten_dist_to_tp, $distance;
 
 } else { die "ERROR in get_geodaten\n"; }
 
 # =========================
 # Calculate real Distances
 
 my $sum_real;
 
 for (my $i=0; $i < $#Placemarks; $i++) {
 
 	my $km_real;
 
 	for (my $j = $geodaten_nearest_tp[$i]; $j < $geodaten_nearest_tp[$i+1] ; $j++) {
 
 		my $dist = getDistance ( $track[$j][0], $track[$j][1], $track[$j+1][0], $track[$j+1][1] );
 
 		$km_real += $dist;
 	}
 
 	$sum_real += $km_real;
 
 	push @kilometrierung_km_real, sprintf "%.1f", $km_real;
 	push @kilometrierung_km_sum_real, sprintf "%.0f", $sum_real;
 }
 
 push @kilometrierung_km_real, "";
 push @kilometrierung_km_sum_real, "";
 
 
 # ==========================
 # Calculate real Höhenmeter
 
 my $sum_hmup;
 my $sum_hmdn;
 
 for (my $i=0; $i < $#Placemarks; $i++) {
 
 	my ($hmup, $hmdn) = getHmSum ($geodaten_nearest_tp[$i], $geodaten_nearest_tp[$i+1]);
 
 	$sum_hmup += $hmup;
 	$sum_hmdn += $hmdn;
 
 	push @kilometrierung_hmup_real, sprintf "%.0f", $hmup;
 	push @kilometrierung_hmdn_real, sprintf "%.0f", $hmdn;
 	push @kilometrierung_hmup_sum_real, sprintf "%.0f", $sum_hmup;
 	push @kilometrierung_hmdn_sum_real, sprintf "%.0f", $sum_hmdn;
 }
 
 push @kilometrierung_hmup_real, "";
 push @kilometrierung_hmdn_real, "";
 push @kilometrierung_hmup_sum_real, "";
 push @kilometrierung_hmdn_sum_real, "";
 
 
 # =====================================
 # Check ascending order of TrackPoints
 
 for (my $i=0; $i<$#Placemarks; $i++) {
 
 	if ( $geodaten_nearest_tp[$i] <= $geodaten_nearest_tp[$i+1] ) {
 
 		#ok
 
 	} else {
 
 		print encode $encOut, "ERROR: Wrong TrackPoint Order in:\n";
 		print encode $encOut, "   $placeName[$i] :: $geodaten_nearest_tp[$i]\n";
 		print encode $encOut, "   $placeName[$i+1] :: $geodaten_nearest_tp[$i+1]\n\n";
 	}
 }
 
 # ===================
 # Summarize all Data
 
 my $output = sprintf "%5s  %3s %4s %5s %5s %5s %5s %5s  %s",
 
 	"tp#",
 	"dist",
 	"k",
 	"k_s",
 	"k_r",
 	"k_s_r",
 	"a",
 	"a_r",
 	"place";
 
 if ($verbose) { print encode $encOut, "$output\n"; }
 
 for (my $i=0; $i <= $#Placemarks; $i++) {
 
 	my $output = sprintf "%5d %3.0f m %4s %5s %5s %5s %5s %5s  %s",
 
 		$geodaten_nearest_tp[$i],
 		$geodaten_dist_to_tp[$i],
 		$kilometrierung_km[$i],
 		$kilometrierung_km_sum[$i],
 		$kilometrierung_km_real[$i],
 		$kilometrierung_km_sum_real[$i],
 		$geodaten_alt[$i],
 		$geodaten_alt_real[$i],
 		$placeName[$i];
 	
 	if ($verbose) { print encode $encOut, "$output\n"; }
 }
 
 if ($verbose) { print encode $encOut, "\n"; }
 
 # ==================
 # Summarize Changes
 
 my $change;
 
 my $output = sprintf "%5s  %3s %4s %5s %5s %5s %5s %5s  %s",
 
 	"tp#",
 	"dist",
 	"k",
 	"k_s",
 	"k_r",
 	"k_s_r",
 	"a",
 	"a_r",
 	"place";
 
 print encode $encOut, "$output\n";
 
 for (my $i=0; $i <= $#Placemarks; $i++) {
 
 	$kilometrierung_km_real[$i] =~ s/\./\,/;
 
 	if ($kilometrierung_km[$i] eq $kilometrierung_km_real[$i]) {
 
 		$kilometrierung_km[$i] = "";
 		$kilometrierung_km_real[$i] = "";
 
 	} else {
 		
 		$kilometrierung_km_res[$i] = $kilometrierung_km_real[$i];
 		$change = 1; 
 	}
 
 	if ($kilometrierung_km_sum[$i] eq $kilometrierung_km_sum_real[$i]) {
 
 		$kilometrierung_km_sum[$i] = "";
 		$kilometrierung_km_sum_real[$i] = "";
 
 	} else {
 		
 		$kilometrierung_km_sum_res[$i] = $kilometrierung_km_sum_real[$i];
 		$change = 1;
 	}
 
 	if ($changePlaceHm) {
 
 		if ($geodaten_alt[$i] eq $geodaten_alt_real[$i]) {
 
 			$geodaten_alt[$i] = "";
 			$geodaten_alt_real[$i] = "";
 
 		} else {
 			
 			$geodaten_alt_res[$i] = $geodaten_alt_real[$i];
 			$change = 1; 
 		}
 
 	} else {
 
 		$geodaten_alt[$i] = "";
 		$geodaten_alt_real[$i] = "";
 	}
 
 	if ($changeDistHm) {
 
 		if ($kilometrierung_hmdn[$i] eq $kilometrierung_hmdn_real[$i]) {
 
 			$kilometrierung_hmdn[$i] = "";
 			$kilometrierung_hmdn_real[$i] = "";
 
 		} else {
 			
 			$kilometrierung_hmdn_res[$i] = $kilometrierung_hmdn_real[$i];
 			$change = 1; 
 		}
 
 		if ($kilometrierung_hmup[$i] eq $kilometrierung_hmup_real[$i]) {
 
 			$kilometrierung_hmup[$i] = "";
 			$kilometrierung_hmup_real[$i] = "";
 
 		} else {
 			
 			$kilometrierung_hmup_res[$i] = $kilometrierung_hmup_real[$i];
 			$change = 1; 
 		}
 
 		if ($kilometrierung_hmup_sum[$i] eq $kilometrierung_hmup_sum_real[$i]) {
 
 			$kilometrierung_hmup_sum[$i] = "";
 			$kilometrierung_hmup_sum_real[$i] = "";
 
 		} else {
 			
 			$kilometrierung_hmup_sum_res[$i] = $kilometrierung_hmup_sum_real[$i];
 			$change = 1; 
 		}
 
 		if ($kilometrierung_hmdn_sum[$i] eq $kilometrierung_hmdn_sum_real[$i]) {
 
 			$kilometrierung_hmdn_sum[$i] = "";
 			$kilometrierung_hmdn_sum_real[$i] = "";
 
 		} else {
 			
 			$kilometrierung_hmdn_sum_res[$i] = $kilometrierung_hmdn_sum_real[$i];
 			$change = 1; 
 		}
 
 	} else {
 	}
 
 	my $output = sprintf "%5d %3.0f m %4s %5s %5s %5s %5s %5s  %s",
 
 		$geodaten_nearest_tp[$i],
 		$geodaten_dist_to_tp[$i],
 		$kilometrierung_km[$i],
 		$kilometrierung_km_sum[$i],
 		$kilometrierung_km_real[$i],
 		$kilometrierung_km_sum_real[$i],
 		$geodaten_alt[$i],
 		$geodaten_alt_real[$i],
 		$placeName[$i];
 	
 	print encode $encOut, "$output\n";
 }
 
 # ======================
 # Write Changes to File
 
 
 if ($change) {
 
 	$fileContent = "";
 
 	$fileContent .= $pre_Roadbook;
 
 
 	for (my $i=0; $i < $#Placemarks; $i++) {
 
 		$fileContent .= "=== $placeName[$i] ===\n";
 		$fileContent .= "$touriInfo[$i]\n";
 		$fileContent .= "{{Geodaten|$geodaten_lat[$i]|$geodaten_lon[$i]|$geodaten_alt_res[$i]|$geodaten_info[$i]}}\n";
 		$fileContent .= "$roadInfo[$i]\n";
 
 		if ($kilometrierung[$i] =~ /KilometrierungHm6/) {
 
 			$fileContent .= "{{KilometrierungHm6|$kilometrierung_km_res[$i]|$kilometrierung_hmup_res[$i]|$kilometrierung_hmdn_res[$i]|$kilometrierung_km_sum_res[$i]|$kilometrierung_hmup_sum_res[$i]|$kilometrierung_hmdn_sum_res[$i]}}";
 
 		} elsif ($kilometrierung[$i] =~ /KilometrierungHm/) {
 
 			$fileContent .= "{{KilometrierungHm|$kilometrierung_km_res[$i]|$kilometrierung_km_sum_res[$i]|$kilometrierung_hmup_sum_res[$i]|$kilometrierung_hmdn_sum_res[$i]}}";
 
 		} else {
 
 			$fileContent .= "{{Kilometrierung|$kilometrierung_km_res[$i]|$kilometrierung_km_sum_res[$i]}}";
 		}
 
 		$fileContent .= "\n$rest[$i]";
 	}
 
 	$fileContent .= "=== $placeName[$#Placemarks] ===\n";
 	$fileContent .= "$touriInfo[$#Placemarks]\n";
 	$fileContent .= "{{Geodaten|$geodaten_lat[$#Placemarks]|$geodaten_lon[$#Placemarks]|$geodaten_alt_res[$#Placemarks]|$geodaten_info[$#Placemarks]}}\n";
 	$fileContent .= "$roadInfo[$#Placemarks]";
 
 	$fileContent .= $post_Roadbook;
 	
 	open  FOUT, "> $outDir/${routeFileName_e}_new.tx" or die $!;
 	print FOUT encode ($encoding, $fileContent);
 	close FOUT;
 
 }
 
 exit;
 
 
 #==========================================================
 #==========================================================
 
 sub getDistance {
 
 	use POSIX qw(acos);
 
 	my ($tp1_lat, $tp1_lon, $tp2_lat, $tp2_lon) = @_;
 
 	my $PI = 3.1415926;
 
 	my $lat1 = $tp1_lat / 180 * $PI;
 	my $lon1 = $tp1_lon / 180 * $PI;
 	my $lat2 = $tp2_lat / 180 * $PI;
 	my $lon2 = $tp2_lon / 180 * $PI;
 	
 	my $val = sin($lat1) * sin($lat2) + 
 			  cos($lat1) * cos($lat2) *
 			  cos($lon2-$lon1);
 
 	if ($val > +1) { 
 		$val = +1; 
 		#print "   ACOS-Error: $tp1_lon,$tp1_lat !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
 	}
 	if ($val < -1) { 
 		$val = -1; 
 		#print "   ACOS-Error: $tp1_lon,$tp1_lat !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
 	}
 
 	my $dist = acos($val) * 6378.137;      # radius of equator in km
 
 	#if (Double.isNaN(dist)) dist = 0;
 
 	return $dist;
 }
 
 #==========================================================
 
 sub getClosestPoint {
 
 	my ($tp_lat, $tp_lon) = @_;
 	
 	my $minDist = 111111111;
 	my $point   = -1;
 
 	for (my $i = 0; $i <= $#track ; $i++) {
 
 		my $dist = getDistance ( $track[$i][0], $track[$i][1], $tp_lat, $tp_lon );
 
 		if ($dist < $minDist) {
 
 			$minDist = $dist;
 			$point   = $i;
 		}
 	}
 
 	return ($point, $minDist*1000);
 }
 
 #==========================================================
 
 sub getHmSum {
 
 	my ($tp_begin, $tp_end) = @_;
 
 	if ($tp_end >= $#track) { $tp_end = $#track-1; }
 
 	my $HmSumUp = 0;
 	my $HmSumDn = 0;
 	
 	for (my $i = $tp_begin; $i <= $tp_end ; $i++) {
 
 		my $alt_0 = $track[$i][2];
 		my $alt_1 = $track[$i+1][2];
 		
 		my $diff  = $alt_1 - $alt_0;
 
 		if ($diff < 0) { $HmSumDn += $diff * (-1); }
 		if ($diff > 0) { $HmSumUp += $diff * (+1); }
 
 	}
 
 	return ($HmSumUp, $HmSumDn);
 }