One of the most useful data that Hams need are the global position of other station also the distance and position of the Sun.

In HF (High Frecuency) is usual the transmission through Ionospheric layers, so sometimes is important to know when will be the Sunrise or the Sunset for optimized his use as well as distance between the two stations. And if our antena is directional, we need to know which is the course to that station.

For these reasons I developed this module, Ham::Resources::Utils.

This module has two main methods:


           my $date = "14-03-2012";
           my %coordinates = ( lat_1  => "41N23",
                               long_1 => "2E11",
                               lat_2  => "30S0",
                               long_2 => "10W45");

           my %data = $foo->data_by_coordinates{$date, %coordinates};
           print Dumper(%data);


          my $date = "14-03-2012"; # date in 'dd-mm-yyyy' format
          my $locator_dep = "JN11cj";
          my $locator_arr = "IJ90ca";

          my %data = $foo->data_by_locator($date,$locator_dep,$locator_arr);
          print Dumper(%data);

Both methods offer the same response, but the difference between them are the data entry.

The data_by_coordinates method requires a hash with coordinates (longitude and latitude) between two points, while data_by_locator, requires strings with the grid locator (Maidenhead Locator System) of the same points.

Grid locator

The response of these methods are a hash like this:

compass: SW                  # compass direction to point B
course_dec: 225.95           # direction to point B in decimal
course_sexag: 225.57         # direction to point B in sexagesimal
date: 28-6-2012              # date of event
distance_km: 10466.03        # distance to point B in kilometers
distance_mi: 6503.29         # distance to point B in miles
lat_1: 41N23                 # Latitude of point A in sexagesinal
lat_1_dec: 41.3833333333333  # Latitude of point A in decimal
lat_2:  34S36                # Latitude of point B in sexagesinal
lat_2_dec: -34.6             # Latitude of point B in decimal
locator_1: JN11cj            # Locator of point A
locator_2: GF05tj            # Locator of point B
long_1: 2E12                 # Longitude of point A in sexagesimal
long_1_dec: 2.2              # Longitude of point A in decimal
long_2:  58W22               # Longitude of point B in sexagesimal
long_2_dec: -58.366666666666 # Longitude of point B in decimal
midday_arrive: 11h 54m       # Midday time on point B in UTC
midday_departure: 11h 54m    # Midday time on point A in UTC
sunrise_arrive: 4h 20m       # Sunrise time on point B in UTC
sunrise_departure: 4h 20m    # Sunrise time on point A in UTC
sunset_arrive: 19h 28m       # Sunset time on point B in UTC
sunset_departure: 19h 28m    # Sunset time on point A in UTC

To access it use the simple constructor:

    use Ham::Resources::Utils;
    my $foo = Ham::Resources::Utils->new();

Anything else?
Yes, of course. This module also offer access to methods used inside by the main methods:

  • loc2degree
    Converts a grid locator into sexagesimal degrees.
  • degree2loc
    This is the loc2degree inverse. Gets a latitude and a longitude, and returns the grid locator notation conversion. This method requires Ham::Locator module installed.

               my $lat = "41N23";
               my $long = "2E11";
               my $locator = $foo->degree2loc($lat, $long);
  • compass
    Util for convert decimal degrees into its equivalent value in a cardinal direction (North, East, …). It uses a separation of 11.25 degrees for each position, 32 cardinal positions of total.

               my $compass = $foo->compass("-90.0"); # returns "W" (west)
               my $compass = $foo->compass("270.0"); # returns "W" (west)


  • dec2sexag
    Converts a decimal degree value into its equivalence to sexagesimal degree form.
  • sexag2dec
    Inverse of dec2sexag, converts sexagesimal values into its decimal values.

    Values must be a pair, longitude and latitude. Two values for one point
    or four values (two pairs) for two points.

    There is not mandatory send a complete hash (4 values), but you will
    receive a hash with the four.

    You can use it like this:

               my %coord = (
                 Long_1 => "41N23.30",
                 Lat_1  => "2E11.10",
    	         Long_2 => "",
    	         Lat_2  => ""
               my %sexag = $foo->sexag2dec(%coord);
               foreach my $key (sort keys %sexag) {
                 say $key." = ".$sexag{$key} if ($sexag{$key});

    The index send it, you will receive with ‘_dec’ suffix, ie, you send
    ‘latitude’ and receive ‘latitude_dec’

  • cicle_sun
    Gets three strings: latitude, longitude, in decimal degrees, and date, in ‘dd-mm-yyyy’ format and returns a hash with:

    • Sunrise time
    • Sunset time
    • Midday (or Zenit) time

    in hours and minutes format in Universal Time (UTC).

               my %sun = $foo->cicle_sun($lat,$long,$date);
  • date_split
    This method checks if a date is valid, in format ‘dd-mm-yyyy’.
    Returns an array with the day, month and year … or error message.

Checking errors
In functions that return only a string or an array, errors will detect
to match /Error/ word. In complex functions, like data_by_coordinates,
that responses with a hash, you check the ‘_error‘ index, i.e:

           %data = $foo->data_by_locator($date,$locator_1,$locator_2);
           if (!$data{_error}) {
                   foreach my $key (sort keys %data) {
                           say $key.": ".$data{$key};
           } else {
                   say $data{_error};

What’s next?

  • Add long path course and distances from point A to B. Now, the module calculated thye short path only.
  • Add a function to calculate X and Y coordinates based on real coordinates for use it on a geographical projection (or Plate Carree). This can be useful to obtain points (X and Y) for to be represented graphically in a map.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: