| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | package Astro::Montenbruck::Ephemeris; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.22.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | no warnings qw/experimental/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Module::Load; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Memoize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | memoize qw/_create_constructor/; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Exporter qw/import/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 16 | all => [ qw/iterator find_positions/ ], | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }, ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | our $VERSION = 0.03; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Math::Trig qw/deg2rad/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use List::Util qw/any/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use Astro::Montenbruck::Ephemeris::Planet qw/:ids/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use Astro::Montenbruck::NutEqu qw/mean2true/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use Astro::Montenbruck::MathUtils qw/diff_angle/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | Readonly our $DAY_IN_CENT => 1 / 36525; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Factory function. Loads given class and returns function that wraps | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # its constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # Example: | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # my $f = _create_constructor('Astro::Montenbruck::Ephemeris::Planets::Sun'); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # my $sun = $f->(); # instantiate the object | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # my @pos = $sun->position($t); # calculate coordinates for the moment $t | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 23 | ▶ | sub _create_constructor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_constructor: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 23 | my $pkg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 23 | load $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 935 | ▶ | sub { $pkg->new(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 23 | } | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # shortcut for _create_constructor | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 935 | ▶ | sub _construct { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_construct: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 935 | _create_constructor(join('::', qw/Astro Montenbruck Ephemeris/, @_)) | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 680 | ▶ | sub _iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iterator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 680 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 680 | my $ids_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 680 | my @items = @{$ids_ref}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 680 | my %arg = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 680 | my $sun = _construct('Planet', $SU)->(); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 680 | my @sun_pos = $sun->sunpos($t); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 680 | my $sun_lbr = { | |||||||||||||||||||||||||||||||||||||||||
| 58 | l => deg2rad($sun_pos[0]), | ||||||||||||||||||||||||||||||||||||||||||
| 59 | b => deg2rad($sun_pos[1]), | ||||||||||||||||||||||||||||||||||||||||||
| 60 | r => $sun_pos[2] | ||||||||||||||||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 680 | my $nut_func = mean2true($t); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Calculate required position. Sun's coordinates are calculated only once. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 696 | ▶ | my $get_position = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 696 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 696 | given ($id) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 696 | when ($SU) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 441 | $sun->apparent($t, \@sun_pos, $nut_func) | |||||||||||||||||||||||||||||||||||||||||
| 72 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 255 | when ($MO) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 219 | my $moo = _construct('Planet', $id)->(); | |||||||||||||||||||||||||||||||||||||||||
| 76 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 219 | $moo->apparent([$moo->moonpos($t)], $nut_func) | |||||||||||||||||||||||||||||||||||||||||
| 78 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 36 | default { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 36 | my $pla = _construct('Planet', $id)->(); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 36 | my @lbr = $pla->heliocentric($t); | |||||||||||||||||||||||||||||||||||||||||
| 83 | # planets | ||||||||||||||||||||||||||||||||||||||||||
| 84 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 36 | $pla->apparent($t, \@lbr, $sun_lbr, $nut_func) | |||||||||||||||||||||||||||||||||||||||||
| 86 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 680 | }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 702 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 702 | ▶ | NEXT: | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | return unless @items; # no more items, stop iteration | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 698 | my $id = shift @items; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 698 | ▶ | goto NEXT if $id eq $PL && ($t < -1.1 || $t > 1.0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$id eq $Astro::Montenbruck::Ephemeris::PL and $t < "-1.1" || $t > 1
$t < "-1.1" or $t > 1
MC/DC100%3/3
$id eq $Astro::Montenbruck::Ephemeris::PL and $t < "-1.1" || $t > 1
$id eq $Astro::Montenbruck::Ephemeris::PL
$t < "-1.1"
$t > 1
Truth table100%4/4
A and B or C
A= $id eq $Astro::Montenbruck::Ephemeris::PLB= $t < "-1.1"C= $t > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 696 | [ $id, $get_position->($id) ] | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 680 | } | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 680 | ▶ | sub iterator { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator: called CC=2 SCAR=10.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 680 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 680 | my $ids_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 680 | my %arg = (with_motion => 0, @_); | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 680 | my $iter_1 = _iterator($t, $ids_ref, %arg); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 680 | ▶ | return $iter_1 unless $arg{with_motion}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # to calculate mean daily motion, we need another iterator, for the next day | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $iter_2 = _iterator($t + $DAY_IN_CENT, $ids_ref, %arg); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $res = $iter_1->() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $res->[2] = diff_angle($res->[1]->[0], $iter_2->()->[1]->[0]); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $res | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub find_positions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_positions: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | my $t = shift; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my $ids_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $callback = shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | my $iter = iterator($t, $ids_ref, @_); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | while ( my $res = $iter->() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | my ($id, $pos, $motion) = @$res; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | $callback->( $id, @$pos, $motion ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||