1
0
Fork 0

maintenance: clean up the perl scripts

This commit is contained in:
scttgs0 2023-05-07 19:28:40 -05:00
parent d021c32840
commit 796e7daa96
10 changed files with 232 additions and 236 deletions

View file

@ -50,7 +50,7 @@ for ( $i = 0; $i < $height; $i++ ) {
$d = <INPUT>; chomp($d);
if ( $d > 0 ) {
$level = 55 + int(200 * ( $d - $min ) / ( $max - $min ));
} else {
} else {
$level = 0;
}
@ -65,7 +65,7 @@ $im->line( 0, 2, $width, 2, $red );
# write out gif
$data = $im->png;
open( OUTPUT, ">$output" ) ||
die "cannot open $output\n";
die "cannot open $output\n";
binmode OUTPUT;
print OUTPUT $data;
close OUTPUT;

View file

@ -10,7 +10,6 @@ use strict;
use POSIX;
########################################################################
# Constants.
########################################################################
@ -19,7 +18,6 @@ my $EPSILON = 0.0000001;
my $DIRSEP = '/';
########################################################################
# Functions.
########################################################################
@ -28,70 +26,70 @@ my $DIRSEP = '/';
# Calculate the number of columns of tiles in a degree of longitude.
#
sub bucket_span {
my ($lat) = (@_);
if ($lat>= 89.0 ) {
return 12.0;
} elsif ($lat>= 86.0 ) {
return 4.0;
} elsif ($lat>= 83.0 ) {
return 2.0;
} elsif ($lat>= 76.0 ) {
return 1.0;
} elsif ($lat>= 62.0 ) {
return 0.5;
} elsif ($lat>= 22.0 ) {
return 0.25;
} elsif ($lat>= -22.0 ) {
return 0.125;
} elsif ($lat>= -62.0 ) {
return 0.25;
} elsif ($lat>= -76.0 ) {
return 0.5;
} elsif ($lat>= -83.0 ) {
return 1.0;
} elsif ($lat>= -86.0 ) {
return 2.0;
} elsif ($lat>= -89.0 ) {
return 4.0;
} else {
return 12.0;
}
my ($lat) = (@_);
if ($lat>= 89.0 ) {
return 12.0;
} elsif ($lat>= 86.0 ) {
return 4.0;
} elsif ($lat>= 83.0 ) {
return 2.0;
} elsif ($lat>= 76.0 ) {
return 1.0;
} elsif ($lat>= 62.0 ) {
return 0.5;
} elsif ($lat>= 22.0 ) {
return 0.25;
} elsif ($lat>= -22.0 ) {
return 0.125;
} elsif ($lat>= -62.0 ) {
return 0.25;
} elsif ($lat>= -76.0 ) {
return 0.5;
} elsif ($lat>= -83.0 ) {
return 1.0;
} elsif ($lat>= -86.0 ) {
return 2.0;
} elsif ($lat>= -89.0 ) {
return 4.0;
} else {
return 12.0;
}
}
#
# Format longitude as e/w.
#
sub format_lon {
my ($lon) = (@_);
if ($lon < 0) {
return sprintf("w%03d", int(0-$lon));
} else {
return sprintf("e%03d", int($lon));
}
my ($lon) = (@_);
if ($lon < 0) {
return sprintf("w%03d", int(0-$lon));
} else {
return sprintf("e%03d", int($lon));
}
}
#
# Format latitude as n/s.
#
sub format_lat {
my ($lat) = (@_);
if ($lat < 0) {
return sprintf("s%02d", int(0-$lat));
} else {
return sprintf("n%02d", int($lat));
}
my ($lat) = (@_);
if ($lat < 0) {
return sprintf("s%02d", int(0-$lat));
} else {
return sprintf("n%02d", int($lat));
}
}
#
# Generate the directory name for a location.
#
sub directory_name {
my ($lon, $lat) = (@_);
my $lon_floor = POSIX::floor($lon);
my $lat_floor = POSIX::floor($lat);
my $lon_chunk = POSIX::floor($lon/10.0) * 10;
my $lat_chunk = POSIX::floor($lat/10.0) * 10;
return format_lon($lon_chunk) . format_lat($lat_chunk) . $DIRSEP
my ($lon, $lat) = (@_);
my $lon_floor = POSIX::floor($lon);
my $lat_floor = POSIX::floor($lat);
my $lon_chunk = POSIX::floor($lon/10.0) * 10;
my $lat_chunk = POSIX::floor($lat/10.0) * 10;
return format_lon($lon_chunk) . format_lat($lat_chunk) . $DIRSEP
. format_lon($lon_floor) . format_lat($lat_floor);
}
@ -99,55 +97,54 @@ sub directory_name {
# Generate the tile index for a location.
#
sub tile_index {
my ($lon, $lat) = (@_);
my $lon_floor = POSIX::floor($lon);
my $lat_floor = POSIX::floor($lat);
my $span = bucket_span($lat);
my $x;
if ($span < $EPSILON) {
$lon = 0;
$x = 0;
} elsif ($span <= 1.0) {
$x = int(($lon - $lon_floor) / $span);
} else {
if ($lon >= 0) {
$lon = int(int($lon/$span) * $span);
} else {
$lon = int(int(($lon+1)/$span) * $span - $span);
if ($lon < -180) {
$lon = -180;
}
my ($lon, $lat) = (@_);
my $lon_floor = POSIX::floor($lon);
my $lat_floor = POSIX::floor($lat);
my $span = bucket_span($lat);
my $x;
if ($span < $EPSILON) {
$lon = 0;
$x = 0;
} elsif ($span <= 1.0) {
$x = int(($lon - $lon_floor) / $span);
} else {
if ($lon >= 0) {
$lon = int(int($lon/$span) * $span);
} else {
$lon = int(int(($lon+1)/$span) * $span - $span);
if ($lon < -180) {
$lon = -180;
}
}
$x = 0;
}
$x = 0;
}
my $y;
$y = int(($lat - $lat_floor) * 8);
my $index = 0;
$index += ($lon_floor + 180) << 14;
$index += ($lat_floor + 90) << 6;
$index += $y << 3;
$index += $x;
return $index;
my $y;
$y = int(($lat - $lat_floor) * 8);
my $index = 0;
$index += ($lon_floor + 180) << 14;
$index += ($lat_floor + 90) << 6;
$index += $y << 3;
$index += $x;
return $index;
}
########################################################################
# Main program.
########################################################################
if ( 0 ) {
my ($lon, $lat) = (@ARGV);
my $dir = directory_name($lon, $lat);
my $index = tile_index($lon, $lat);
my $path = "$dir$DIRSEP$index.stg";
print "Longitude: $lon\n";
print "Latitude: $lat\n";
print "Tile: $index\n";

View file

@ -10,20 +10,19 @@
use IO::Socket;
use strict;
sub my_not() {
my( $val ) = shift;
if ( $val eq "true" ) {
return 0;
} elsif ( $val eq "false" ) {
} elsif ( $val eq "false" ) {
return 1;
} elsif ( $val eq "" ) {
} elsif ( $val eq "" ) {
return 1;
} else {
} else {
return 0;
}
}
@ -31,31 +30,31 @@ sub my_not() {
sub get_prop() {
my( $handle ) = shift;
&send( $handle, "get " . shift );
eof $handle and die "\nconnection closed by host";
$_ = <$handle>;
s/\015?\012$//;
/^-ERR (.*)/ and die "\nfgfs error: $1\n";
return $_;
}
sub set_prop() {
sub set_prop() {
my( $handle ) = shift;
my( $prop ) = shift;
my( $value ) = shift;
&send( $handle, "set $prop $value");
# eof $handle and die "\nconnection closed by host";
}
sub send() {
my( $handle ) = shift;
print $handle shift, "\015\012";
}
@ -68,12 +67,12 @@ sub connect() {
STDOUT->autoflush(1);
while ($timeout--) {
if ($socket = IO::Socket::INET->new( Proto => 'tcp',
PeerAddr => $host,
PeerPort => $port) )
{
PeerAddr => $host,
PeerPort => $port) )
{
$socket->autoflush(1);
return $socket;
}
}
print "Attempting to connect to $host ... " . $timeout . "\n";
sleep(1);
}

View file

@ -20,13 +20,13 @@ while( $arg = shift(@ARGV) ) {
$arg =~ s/^--input=//;
$infile = $arg;
print "infile = $infile\n";
} elsif ( $arg =~ m/^--outdir=/ ) {
} elsif ( $arg =~ m/^--outdir=/ ) {
$arg =~ s/^--outdir=//;
$outdir = $arg;
print "outdir = $outdir\n";
} elsif ( $arg =~ m/^--count-only/ ) {
} elsif ( $arg =~ m/^--count-only/ ) {
$countonly = 1;
} else {
} else {
usage();
}
}
@ -59,13 +59,13 @@ while( <IN> ) {
if ( $F[6] eq "" || $F[6] eq " " || $F[6] eq "N" ) {
# do nothing
} else {
} else {
print $_;
$lat = -$lat;
}
if ( $F[11] eq "" || $F[11] eq " " || $F[11] eq "W" ) {
$lon = -$lon
} else {
} else {
# do nothing
print $_;
}
@ -97,12 +97,12 @@ while( <IN> ) {
# but let's skip because too many of these just get too crazy
next;
} elsif ( $height < 200.0 ) {
} elsif ( $height < 200.0 ) {
# medium tower
$model = "Models/Structures/radio-medium.xml";
$base_elev = $top_msl - 200.0;
$mediumcount++;
} else {
} else {
# tall tower
$model = "Models/Structures/radio-tall.xml";
$base_elev = $top_msl - 610.0;
@ -115,11 +115,11 @@ while( <IN> ) {
if ( ! $countonly ) {
system( "mkdir -p $outdir/$dir" );
my( $indfile ) = "$outdir/$dir/$index.ind";
open( INDEX, ">>$indfile" );
printf( INDEX "OBJECT_SHARED %s %.6f %.6f %.1f 0.00\n",
$model, $lon, $lat, $base_elev );
$model, $lon, $lat, $base_elev );
}
}

View file

@ -11,21 +11,21 @@ if ( $#ARGV != 1 ) {
print " - and <disk_size_mb> is the size in MB of each individual disk.\n";
print " DVD=4500 (Mb), CDROM=700 (Mb)\n";
exit;
} else {
} else {
$reserve = shift(@ARGV);
$disksize = shift(@ARGV);
}
@lons = ( "w180", "w170", "w160", "w150", "w140", "w130", "w120",
"w110", "w100", "w090", "w080", "w070", "w060", "w050",
"w040", "w030", "w020", "w010", "e000", "e010", "e020",
"e030", "e040", "e050", "e060", "e070", "e080", "e090",
"e100", "e110", "e120", "e130", "e140", "e150", "e160",
"e170" );
"w110", "w100", "w090", "w080", "w070", "w060", "w050",
"w040", "w030", "w020", "w010", "e000", "e010", "e020",
"e030", "e040", "e050", "e060", "e070", "e080", "e090",
"e100", "e110", "e120", "e130", "e140", "e150", "e160",
"e170" );
@lats = ( "n80", "n70", "n60", "n50", "n40", "n30", "n20", "n10",
"n00", "s10", "s20", "s30", "s40", "s50", "s60", "s70",
"s80", "s90" );
"n00", "s10", "s20", "s30", "s40", "s50", "s60", "s70",
"s80", "s90" );
# @files = `ls $tgzdir/*.tar.gz`;
@files = ();
@ -43,27 +43,27 @@ $total_collection = 0;
foreach $file ( @files ) {
chomp $file;
while ( $file =~ m/\// ) {
$file =~ s/.*\///;
}
if ( -f "$tgzdir/$file" ) {
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat( "$tgzdir/$file" );
$mtime, $ctime, $blksize, $blocks) = stat( "$tgzdir/$file" );
$kb = $size / 1024;
$mb = $kb / 1024;
# printf( "%s %9.2f kb\n", $file, $kb );
if ( $total_disk + $mb < $disksize ) {
$total_disk += $mb;
} else {
} else {
$disk++;
$total_disk = $mb;
}
$total_collection += $mb;
printf( "Disk%02d/%s", $disk, $file );
printf( " %.2f %.2f", $mb, $total_disk ) if $verbose;
printf( "\n" );

View file

@ -27,7 +27,7 @@ $response = <STDIN>;
chomp($response);
if ( $response eq "y" || $response eq "Y" ) {
system( "/bin/rm -rf $dest" );
} else {
} else {
die "Stopped with no action.\n";
}
@ -38,11 +38,11 @@ foreach $file ( @layout ) {
}
$dir = $file;
$dir =~ s/\/[^\/]+$//;
if ( ! -d "$dest/$dir" ) {
system( "mkdir -p $dest/$dir" );
}
printf( "ln -sf $source/$base $dest/$file\n" );
system( "ln -sf $source/$base $dest/$file" );
}

View file

@ -4,7 +4,7 @@ $tgzdir = "/stage/fgfs03/curt/Scenery/Scenery-0.9.5";
if ( $#ARGV < 0 ) {
die "usage: $0 <layout_dir>\n";
} else {
} else {
$cdromdir = shift(@ARGV);
}
@ -13,17 +13,17 @@ $total = 0;
foreach $file ( @files ) {
chomp $file;
while ( $file =~ m/\// ) {
$file =~ s/.*\///;
}
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat( "$tgzdir/$file" );
$mtime, $ctime, $blksize, $blocks) = stat( "$tgzdir/$file" );
$kb = $size / 1024;
# printf( "%s %9.2f kb\n", $file, $kb );
$total += $size;
}
# print "\n";

View file

@ -8,13 +8,13 @@ $DEG_TO_RAD = $PI / 180.0;
while ( <> ) {
chop;
($name, $junk, $ra, $decl, $mag, $junk) = split(/,/);
@RA = split(/:/, $ra);
@DECL = split(/:/, $decl);
$new_ra = $RA[0] + ( $RA[1] / 60.0 ) + ( $RA[2] / 3600.0 );
$new_decl = $DECL[0] + ( $DECL[1] / 60.0 ) + ( $DECL[2] / 3600.0 );
printf("%s,%.6f,%.6f,%.6f\n", $name, $new_ra * 15 * $DEG_TO_RAD,
$new_decl * $DEG_TO_RAD, $mag);
printf("%s,%.6f,%.6f,%.6f\n", $name, $new_ra * 15 * $DEG_TO_RAD,
$new_decl * $DEG_TO_RAD, $mag);
}

View file

@ -53,8 +53,8 @@ $im->line( $width / 2, 0, $width / 2, $height, $red3 );
$im->line( 0, $height / 2, $width, $height / 2, $red3 );
# create html file
open ( HTML, ">$outputdir/$htmlout" ) ||
die "cannot open $outputdir/$htmlout\n";
open ( HTML, ">$outputdir/$htmlout" ) ||
die "cannot open $outputdir/$htmlout\n";
print HTML "<HTML>\n";
print HTML "<TITLE>FGFS Scenery Downloads Version $version</TITLE>\n";
print HTML "<BODY>\n";
@ -72,90 +72,90 @@ print HTML "<MAP NAME=\"map\">\n";
$toggle = 0;
foreach $dir ( @ARGV ) {
@files = `ls $dir/*.tgz`;
foreach $file ( @files ) {
chop($file);
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat($file);
$mtime, $ctime, $blksize, $blocks) = stat($file);
$mb = $size / (1024*1024);
# print "$file size = $mb\n";
# recover the modification date from the stat
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime($mtime);
localtime($mtime);
$date = sprintf("%2d/%02d/%02d", $mon + 1, $mday, 1900 + $year);
$age = (time() - $mtime) / $daysecs;
if ( !$toggle ) {
if ( $age < 7 ) {
$color1 = $green1;
$color2 = $green2;
} elsif ( $age < 14 ) {
} elsif ( $age < 14 ) {
$color1 = $yellow1;
$color2 = $yellow2;
} else {
} else {
$color1 = $orange1;
$color2 = $orange2;
}
} else {
} else {
if ( $age < 7 ) {
$color1 = $orange1;
$color2 = $orange2;
} elsif ( $age < 14 ) {
} elsif ( $age < 14 ) {
$color1 = $yellow1;
$color2 = $yellow2;
} else {
} else {
$color1 = $orange1;
$color2 = $orange2;
}
}
$file =~ s/.*\///g;
$file =~ s/.tgz//;
# print "$file\n";
($ew, $lon, $ns, $lat) = $file =~ m/(\w)(\d\d\d)(\w)(\d\d)/;
# print "$ew $lon, $ns, $lat\n";
if ( $ew eq "w" ) {
$lon = $lon * -1;
} else {
} else {
$lon = $lon * 1;
}
if ( $ns eq "s" ) {
$lat = $lat * -1;
} else {
} else {
$lat = $lat * 1;
}
# print "$lon $lat\n";
$x1 = ($lon + 180) * $xstep / 10.0;
$y1 = $height - ($lat + 90) * $ystep / 10.0;
$x2 = ($lon + 10 + 180) * $xstep / 10.0;
$y2 = $height - ($lat + 10 + 90) * $ystep / 10.0;
$im->line($x1, $y1, $x2, $y2, $color1);
$im->line($x1, $y2, $x2, $y1, $color1);
$im->rectangle($x1, $y1, $x2, $y2, $color2);
# $y1 = $height - $y1;
# $y2 = $height - $y2;
print HTML "<AREA SHAPE=rect COORDS=$x1,$y2,$x2,$y1 ";
print HTML "HREF=$ftpurl/$file.tgz ";
printf(HTML "ALT=\"%s %.2f Mb $date\">\n", $file, $mb);
}
$toggle = !$toggle;
}
# write out gif
$png_data = $im->png;
open( OUTPUT, ">$outputdir/$mapout" ) ||
die "cannot open output $outputdir/$mapout\n";
open( OUTPUT, ">$outputdir/$mapout" ) ||
die "cannot open output $outputdir/$mapout\n";
binmode OUTPUT;
print OUTPUT $png_data;
close OUTPUT;

View file

@ -10,17 +10,17 @@ open( MAGVAR, "<$file" ) || die "cannot open $file\n";
while ( <MAGVAR> ) {
chomp;
($id, $city, $state, $type, $lat, $lon, $magvar, $rawfreq ) =
split( /\t/ );
split( /\t/ );
$freq = sprintf("%.2f", $rawfreq);
$keylat = sprintf("%.2f", $lat);
$key = $id . $freq . $keylat;
if ( $VAR{$key} ne "" ) {
print "warning, dup key = $key\n";
print "warning, dup key = $key\n";
}
$VAR{$key} = $_;
# print "$key $id $magvar\n";
if ( $lat < 0 ) {
# print "$lat $key\n";
# print "$lat $key\n";
}
}
@ -36,42 +36,42 @@ print $line;
while ( <NAV> ) {
if ( $_ eq "[End]\n" ) {
print $_;
print "\n";
break;
} else {
chomp();
($type, $lat, $lon, $elev, $freq, $range, $dme, $id, $magvar, $name) =
split( /\s+/, $_, 10);
$keylat = sprintf("%.2f", $lat);
$key = $id . $freq . $keylat;
if ( $VAR{$key} eq "" ) {
# print "warning $id $freq not in magvar database\n";
} else {
# print "found $id $freq\n";
($junk, $junk, $junk, $junk, $lat, $lon, $magvar, $junk ) =
split( /\t/, $VAR{$key} );
if ( $lon > -100 && $lon < 100 ) {
$lon =~ s/\-/\-0/;
}
delete $VAR{$key};
}
if ( $lat >= 0 ) {
$prettylat = " " . $lat;
} else {
$prettylat = $lat;
}
if ( $lon >= 0 ) {
$prettylon = " " . $lon;
} else {
$prettylon = $lon;
}
printf("%s %s %s %5d %06.2f %4d %s %-4s %3s %s\n",
$type, $prettylat, $prettylon, $elev, $freq, $range, $dme,
$id, $magvar, $name );
print $_;
print "\n";
break;
} else {
chomp();
($type, $lat, $lon, $elev, $freq, $range, $dme, $id, $magvar, $name) =
split( /\s+/, $_, 10);
$keylat = sprintf("%.2f", $lat);
$key = $id . $freq . $keylat;
if ( $VAR{$key} eq "" ) {
# print "warning $id $freq not in magvar database\n";
} else {
# print "found $id $freq\n";
($junk, $junk, $junk, $junk, $lat, $lon, $magvar, $junk ) =
split( /\t/, $VAR{$key} );
if ( $lon > -100 && $lon < 100 ) {
$lon =~ s/\-/\-0/;
}
delete $VAR{$key};
}
if ( $lat >= 0 ) {
$prettylat = " " . $lat;
} else {
$prettylat = $lat;
}
if ( $lon >= 0 ) {
$prettylon = " " . $lon;
} else {
$prettylon = $lon;
}
printf("%s %s %s %5d %06.2f %4d %s %-4s %3s %s\n",
$type, $prettylat, $prettylon, $elev, $freq, $range, $dme,
$id, $magvar, $name );
}
}
@ -81,52 +81,52 @@ print "Unmatched:\n\n";
foreach $key (sort keys %VAR) {
($id, $city, $state, $basetype, $lat, $lon, $magvar, $rawfreq ) =
split( /\t/, $VAR{$key} );
split( /\t/, $VAR{$key} );
if ( $basetype =~ m/NDB/ ) {
$type = "N";
} elsif ( $basetype =~ m/VOR/ ) {
$type = "V";
} else {
$type = "X";
$type = "N";
} elsif ( $basetype =~ m/VOR/ ) {
$type = "V";
} else {
$type = "X";
}
if ( $basetype =~ m/DME/ || $basetype =~ m/VORTAC/ ) {
$dme = "Y";
} else {
$dme = "N";
$dme = "Y";
} else {
$dme = "N";
}
$name = "$city";
if ( $basetype =~ m/NDB/ ) {
$name .= " NDB";
} elsif ( $basetype =~ m/VORTAC/ ) {
$name .= " VORTAC";
} elsif ( $basetype =~ m/VOR/ ) {
$name .= " VOR";
$name .= " NDB";
} elsif ( $basetype =~ m/VORTAC/ ) {
$name .= " VORTAC";
} elsif ( $basetype =~ m/VOR/ ) {
$name .= " VOR";
}
if ( $magvar eq "" ) {
$magvar = "XXX";
$magvar = "XXX";
}
if ( $lat >= 0 ) {
$prettylat = " " . $lat;
} else {
$prettylat = $lat;
$prettylat = " " . $lat;
} else {
$prettylat = $lat;
}
if ( $lon >= 0 ) {
$prettylon = " " . $lon;
} else {
$prettylon = $lon;
$prettylon = " " . $lon;
} else {
$prettylon = $lon;
}
if ( $prettylon > -100 && $prettylon < 100 ) {
$prettylon =~ s/\-/\-0/;
$prettylon =~ s/\-/\-0/;
}
$freq = sprintf("%.2f", $rawfreq);
printf("%s %s %s %5d %06.2f %4d %s %-4s %3s %s\n",
$type, $prettylat, $prettylon, $elev, $freq, $range, $dme,
$id, $magvar, $name );
$type, $prettylat, $prettylon, $elev, $freq, $range, $dme,
$id, $magvar, $name );
}