| 1 | package Astro::Montenbruck::RiseSet::Sunset; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | no warnings qw/experimental/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use feature qw/switch/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Exporter qw/import/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Math::Trig qw/:pi deg2rad/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Astro::Montenbruck::MathUtils qw/quad/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Astro::Montenbruck::Time qw/cal2jd jd_cent/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Astro::Montenbruck::Time::Sidereal qw/ramc/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Astro::Montenbruck::RiseSet::Constants qw/:events :states/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | our @EXPORT_OK = qw/riseset_func/; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | our $VERSION = 0.02; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 22 | ▶ | sub _cs_phi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cs_phi: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 22 | my $phi = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 22 | my $rphi = deg2rad($phi); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 22 | cos($rphi), sin($rphi); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Calculates sine of the altitude at hourly intervals. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 654 | ▶ | sub _sin_alt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sin_alt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 654 | my ( $jd, $lambda, $cphi, $sphi, $get_position ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 654 | my ( $ra, $de ) = $get_position->($jd); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # hour angle | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 654 | my $tau = deg2rad( ramc( $jd, $lambda ) ) - $ra; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 654 | $sphi * sin($de) + $cphi * cos($de) * cos($tau); | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 22 | ▶ | sub riseset_func { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
riseset_func: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | my %arg = ( date => undef, phi => undef, lambda => undef, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | my $jd0 = cal2jd( @{ $arg{date} } ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | my ( $cphi, $sphi ) = _cs_phi( $arg{phi} ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 654 | ▶ | my $sin_alt = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 654 | my ( $hour, $get_position ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 654 | _sin_alt( $jd0 + $hour / 24, $arg{lambda}, $cphi, $sphi, | |||||||||||||||||||||||||||||||||||||||||
| 45 | $get_position ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 22 | }; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 32 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | # h0 = altitude corection | ||||||||||||||||||||||||||||||||||||||||||
| 50 | my %arg = ( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | sin_h0 => undef, # sine of altitude correction | ||||||||||||||||||||||||||||||||||||||||||
| 52 | get_position => | ||||||||||||||||||||||||||||||||||||||||||
| 53 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 54 | , # function for calculation equatorial coordinates of the body | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | on_event => sub { }, # callback for rise/set event | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | on_noevent => sub { }, # callback when an event is missing | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 32 | ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 32 | my $get_coords = $arg{get_position}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 32 | my $sin_h0 = $arg{sin_h0}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 32 | my $on_event = $arg{on_event}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 32 | my $hour = 1; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 32 | my $y_minus = $sin_alt->( $hour - 1, $get_coords ) - $sin_h0; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 32 | my $above = $y_minus > 0; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 32 | my ( $rise_found, $set_found ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 32 | ▶ | my $jd_with_hour = sub { $jd0 + $_[0] / 24 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # loop over search intervals from [0h-2h] to [22h-24h] | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 32 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$hour >= 36 or $rise_found and $set_found
$rise_found and $set_found
MC/DC100%3/3
$hour >= 36 or $rise_found and $set_found
$hour >= 36
$rise_found
$set_found
Truth table100%4/4
A or B and C
A= $hour >= 36B= $rise_foundC= $set_found
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 311 | my $y_0 = $sin_alt->( $hour, $get_coords ) - $sin_h0; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 311 | my $y_plus = $sin_alt->( $hour + 1, $get_coords ) - $sin_h0; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # find parabola through three values $y_minus, $y_0, $y_plus | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 311 | my ( $nz, $xe, $ye, @zeroes ) = quad( $y_minus, $y_0, $y_plus ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 311 | given ($nz) { | |||||||||||||||||||||||||||||||||||||||||
| 79 | 311 | when (1) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 62 | ▶ | if ( $y_minus < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 31 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 82 | $EVT_RISE, $jd_with_hour->( $hour + $zeroes[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 31 | $rise_found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 31 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 88 | $EVT_SET, $jd_with_hour->( $hour + $zeroes[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 31 | $set_found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 249 | when (2) { | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( $ye < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 96 | $EVT_RISE, $jd_with_hour->( $hour + $zeroes[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 99 | $EVT_SET, $jd_with_hour->( $hour + $zeroes[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 104 | $EVT_RISE, $jd_with_hour->( $hour + $zeroes[0] ) | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $on_event->( | |||||||||||||||||||||||||||||||||||||||||
| 107 | $EVT_SET, $jd_with_hour->( $hour + $zeroes[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ( $rise_found, $set_found ) = ( 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # prepare for next interval | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 311 | $y_minus = $y_plus; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 311 | $hour += 2; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } until ( ( $hour >= 36 ) || ( $rise_found && $set_found ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 32 | ▶ | $arg{on_noevent}->( $above ? $STATE_CIRCUMPOLAR : $STATE_NEVER_RISES ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$rise_found or $set_found
MC/DC50%1/2
$rise_found or $set_found
$rise_found
$set_found
Truth table66%2/3
A or B
A= $rise_foundB= $set_found
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | unless ( $rise_found || $set_found ); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 22 | } | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||||||||||||||||