fg-chunks.pl to HTML.

index -|- end

Generated: Sat Oct 24 16:35:15 2020 from fg-chunks.pl 2018/03/31 3.7 KB. text copy

#!/usr/bin/perl -w
# NAME: fg-chunks.pl
# AIM: Output set of chunks, 10x10 degree blocks
# 2018-03-31 - make loop '<=' rather than just '<'. and add span
# 2016-08-07 - First cut
use strict;
use warnings;

# Format            Example
# 10x10 deg folder   w070n10
# — 1x1 deg subfolder   — w065n17
# —— bucket index file   —— 1891048.arr.gz

# Objects
#  with e000n40 e070n30 e080n20 e080n30 e110n20 e140s40 e150s40 ...

# Terrain
#  with CHUNKS 10x10 labelled by lower left like 
# e000n40 e070n30 e080n20 e080n30 e110n20 e140s40 e150s40 e160s50 w010n50 ...

sub prt($) { print shift; }

#// Build the path name for this bucket
#string SGBucket::gen_base_path() const {
sub gen_base_bpath($$) {
   my ($lat,$lon) = @_;
   my ($top_lon, $top_lat, $main_lon, $main_lat);
   my ($hem, $pole);
   #my ($lon, $lat, $x, $y);
   #$lon = $self->lon();
   #$lat = $self->lat();
   #$x = $self->get_x();
   #$y = $self->get_y();
   # char raw_path[256];

   $top_lon = int($lon / 10);
   # print "top_lon / 10 = $top_lon\n";

   $main_lon = $lon;
   if ( ($lon < 0) && ($top_lon * 10 != $lon) ) {
        $top_lon -= 1;
   }
   $top_lon *= 10;
   # print "top_lon / 10 * 10 = $top_lon\n";
   if ( $top_lon >= 0 ) {
        $hem = 'e';
   } else {
          $hem = 'w';
        $top_lon *= -1;
   }
   if ( $main_lon < 0 ) {
        $main_lon *= -1;
   }
    
   $top_lat = int($lat / 10);
   $main_lat = $lat;
   if ( ($lat < 0) && ($top_lat * 10 != $lat) ) {
        $top_lat -= 1;
   }
   $top_lat *= 10;
   if ( $top_lat >= 0 ) {
        $pole = 'n';
   } else {
        $pole = 's';
        $top_lat *= -1;
   }
   if ( $main_lat < 0 ) {
       $main_lat *= -1;
   }

   return sprintf("$hem%03d$pole%02d/$hem%03d$pole%02d",
       $top_lon, $top_lat, 
       $main_lon, $main_lat);
   # SGPath path( raw_path );
   # return path.str();
}

sub get_bucket_stg($$) {
    my ($lat,$lon) = @_;
    my $bp = gen_base_bpath($lat,$lon);
    my @arr = split('/',$bp);
    return $arr[0];
}

sub get_span($) {
    my $l = shift; # latitude
    if ( $l >= 89.0 ) {
   return 360.0;
    } elsif ( $l >= 88.0 ) {
   return 8.0;
    } elsif ( $l >= 86.0 ) {
   return 4.0;
    } elsif ( $l >= 83.0 ) {
   return 2.0;
    } elsif ( $l >= 76.0 ) {
   return 1.0;
    } elsif ( $l >= 62.0 ) {
   return 0.5;
    } elsif ( $l >= 22.0 ) {
   return 0.25;
    } elsif ( $l >= -22.0 ) {
   return 0.125;
    } elsif ( $l >= -62.0 ) {
   return 0.25;
    } elsif ( $l >= -76.0 ) {
   return 0.5;
    } elsif ( $l >= -83.0 ) {
   return 1.0;
    } elsif ( $l >= -86.0 ) {
   return 2.0;
    } elsif ( $l >= -88.0 ) {
   return 4.0;
    } elsif ( $l >= -89.0 ) {
   return 8.0;
    } # else {
   return 360.0;
    #}
}



sub get_bucket_ll($) {
    my $txt = shift;
    my ($ew,$lon,$ns,$lat);
    $lon = 0;
    $lat = 0;
    if ($txt =~ /^(e|w)(\d{3})(n|s)(\d{2})$/) {
        $ew = $1;
        $lon = $2;
        $ns = $3;
        $lat = $4;
        if ($ew eq 'w') {
            $lon *= -1;
        }
        if ($ns eq 's') {
            $lat *= -1;
        }
    }
    return ($lat,$lon);
}


sub get_all_buckets() {
    my ($lat,$lon,$path);
    my ($dlat,$dlon,$span);

    for ($lat = -90; $lat <= 90; $lat += 10) {
        for ($lon = -180; $lon <= 180; $lon += 10) {
            ###$path = gen_base_bpath($lat,$lon);
            $span = get_span($lat);
            $path = get_bucket_stg($lat,$lon);
            ($dlat,$dlon) = get_bucket_ll($path);
            if (($dlat == $lat) && ($dlon == $lon)) {
                prt("$path $lat,$lon $span\n");
            } else {
                prt("CHECK ME $path $lat,$lon CHECK ME $lon $dlat,$dlon\n");
            }
        }
        prt("\n");
    }
}

get_all_buckets();

# eof

index -|- top

checked by tidy  Valid HTML 4.01 Transitional