Geo::Compass::Variation - Accurately calculate magnetic declination and inclination
use Geo::Compass::Variation qw(mag_dec mag_inc); my $lat = 53.1234567; my $lon = -114.1234567; my $alt = 1098; my $declination = mag_dec($lat, $lon, $alt); my $inclination = mag_inc($lat, $lon, $alt);
This module calculates and returns the Magnetic declination and inclination (dip) calculations based on WMM earth magnetism model for a specified latitude and longitude pair.
See NOAA for details.
The WMM data is currently valid from January 1, 2020 through December 31, 2024. This module will be updated with new WMM data as it becomes available. (Last update was the Dec 10, 2019 dataset).
All functions must be imported explicitly:
use Geo::Compass::Variation qw(mag_dec mag_inc); # or use Geo::Compass::Variation qw(:all);
Note: The mag_dec function has an alias of mag_var which can be imported explicitly, or with the :all tag.
mag_dec
mag_var
:all
Calculates and returns the magnetic declination of a pair of GPS coordinates.
Parameters:
$lat
Mandatory, Float: Latitude, in signed notation (eg: 53.1111111. Negative is South and positive is North of the Equator.
53.1111111
$lon
Mandatory, Float: Longitude, in signed notiation (eg: -114.11111. Negative is West and positive is East of the Prime Meridian.
-114.11111
$alt
Optional, Integer: Altitude above sea level, in metres. Defaults to 0.
0
$year
Optional, Integer|Float: The year to base the calculation from. Defaults to YYYY.M, where YYYY is the year from localtime() and M is the month number from localtime(), normalized to a digit between 1-10.
YYYY.M
YYYY
localtime()
M
We will warn() if the year is out of range of the current WMM specification.
warn()
Return: A floating point number representing the magnetic declination.
Simply an alias for "mag_dec".
Calculates and returns the magnetic inclination of a pair of GPS coordinates.
Parameters are exactly the same as for the "mag_dec" function. Please review that documentation section for full details.
Return: A floating point number representing the magnetic inclination.
Core function that calcluates the raw magnetic field north component ($X), the east component ($Y) and the vertical component ($Z).
$X
$Y
$Z
Takes the same parameters as "mag_dec". Please see that function's documentation for full details.
Steve Bertrand, <steveb at cpan.org>
<steveb at cpan.org>
All the thanks goes out to no_slogan of Perlmonks for all of the core functionality.
It was presented here, in response to this thread I had started regarding a code review of some prototype code I wrote to calculate the direction between two pairs of GPS coordinates.
Copyright 2017-2020 Steve Bertrand.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Geo::Compass::Variation, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::Compass::Variation
CPAN shell
perl -MCPAN -e shell install Geo::Compass::Variation
For more information on module installation, please visit the detailed CPAN module installation guide.