--- /dev/null
+#!/usr/bin/perl
+#
+# show dawn, sunrise, sunset, and dusk times for each callsign or prefix entered
+#
+#
+my ($self, $line) = @_;
+my @f = split /\s+/, $line;
+
+my @out;
+my $f;
+my $l;
+my $n_offset;
+my @list;
+
+while ($f = shift @f){
+ if(!$n_offset){
+ ($n_offset) = $f =~ /^([-+]?\d+)$/;
+ next if $n_offset;
+ }
+ push @list, $f;
+}
+$n_offset = 0 unless defined $n_offset;
+$n_offset = 0 if $n_offset > 365; # can request moon rise/set up to 1 year ago or from now...
+$n_offset = 0 if $n_offset < -365;
+
+my ($lat, $lon); # lats and longs in radians
+my ($sec, $min, $hr, $day, $month, $yr) = (gmtime($main::systime+$n_offset*24*60*60))[0,1,2,3,4,5];
+
+$month++;
+$yr += 1900;
+
+my @in;
+
+if (@list) {
+ foreach $l (@list) {
+ my $user = DXUser->get_current(uc $l);
+ if ($user && $user->lat && $user->long) {
+ push @in, [$user->qth, $user->lat, -$user->long, uc $l ];
+ } else {
+ # prefixes --->
+ my @ans = Prefix::extract($l);
+ next if !@ans;
+ my $pre = shift @ans;
+ my $a;
+ foreach $a (@ans) {
+ $lat = $a->{lat};
+ $lon = -$a->{long};
+ push @in, [ $a->name, $lat, $lon, $pre ];
+ }
+ }
+ }
+} else {
+ if ($self->user->lat && $self->user->long) {
+ push @in, [$self->user->qth, $self->user->lat, -$self->user->long, $self->call ];
+ } else {
+ push @in, [$main::myqth, $main::mylatitude, -$main::mylongitude, $main::mycall ];
+ }
+}
+
+push @out, $self->msg('grayline1');
+push @out, $self->msg('grayline2');
+
+foreach $l (@in) {
+ my ($dawn, $rise, $set, $dusk, $az, $dec )=Sun::rise_set($yr,$month,$day,$hr,$min,$l->[1],$l->[2],0);
+ $l->[3] =~ s{(-\d+|/\w+)$}{};
+ push @out,sprintf("%-6.6s %-30.30s %02d/%02d/%4d %s %s %s %s", $l->[3], $l->[0], $day, $month, $yr, $dawn, $rise, $set, $dusk);
+}
+
+
+return (1, @out);
my $lat = shift;
my $lon = shift;
my $sun0_moon1=shift; # 0 for sun, 1 for moon, 2 for venus...
+ my ($alpha1,$delta1,$alpha2,$delta2,$alpha3,$delta3);
+ my ($aznow,$hnow,$alphanow,$deltanow,$distance,$distancenow);
+ my ($h0,$H);
+ my ($risetime,$settime);
+ my ($dawntime,$dusktime);
- my $norise = 0;
- my $noset = 0;
- my ($risehr,$risemin,$risetime,$sethr,$setmin,$settime);
-
- my ($alpha1,$alpha2,$alpha3,$delta1,$delta2,$delta3);
- my ($m0,$m1,$m2,$theta,$alpha,$delta,$H,$az,$h,$h0,$aznow,$hnow,$corr);
- my ($i,$arg,$argtest,$H0,$alphanow,$deltanow,$distance,$distancenow);
my ($ifrac,$ifracnow);
my $julianday=Julian_Day($year,$month,$day);
($alpha2, $delta2)=get_sun_alpha_delta($tt2);
($alpha3, $delta3)=get_sun_alpha_delta($tt3);
($alphanow, $deltanow)=get_sun_alpha_delta($ttnow);
- $h0=-0.8333;
$H=$thetanow-$lon-$alphanow;
$H=reduce_angle_to_360($H);
($aznow,$hnow)=get_az_el($H,$deltanow,$lat);
$hnow=$hnow +
1.02/(tandeg($hnow+10.3/($hnow+5.11)))/60;
+ $h0=-0.8333; # this is for sun rise and sun set
+ ($risetime,$settime)=
+ do_rise_set_calculations($h0,$theta0,$lat,$lon,$alpha1,$delta1,
+ $alpha2,$delta2,$alpha3,$delta3);
+ $h0=-6.0; # this is for civil dawn and dusk
+ ($dawntime,$dusktime)=
+ do_rise_set_calculations($h0,$theta0,$lat,$lon,$alpha1,$delta1,
+ $alpha2,$delta2,$alpha3,$delta3);
+ $dawntime = "------" if( $dawntime eq "NoRise" );
+ $dusktime = "------" if( $dusktime eq "NoSet " );
+
+ return (
+ sprintf("%s", $dawntime), sprintf("%s",$risetime),
+ sprintf("%s", $settime), sprintf("%s",$dusktime),
+ $aznow+180,$hnow
+ );
}
if ( $sun0_moon1 == 1 ) {
($alpha2, $delta2, $distance, $ifrac)=get_moon_alpha_delta($tt2);
($alpha3, $delta3, $distance, $ifrac)=get_moon_alpha_delta($tt3);
($alphanow, $deltanow, $distancenow, $ifracnow)=get_moon_alpha_delta($ttnow);
- $h0=0.7275*$r2d*asin(6378.14/$distancenow)-34./60.;
+ $h0=0.7275*$r2d*asin(6378.14/$distancenow)-34.0/60.;
$H=$thetanow-$lon-$alphanow;
$H=reduce_angle_to_360($H);
($aznow,$hnow)=get_az_el($H,$deltanow,$lat);
$hnow=$hnow-$r2d*asin(sin(6378.14/$distancenow)*cosdeg($hnow))+
1.02/(tandeg($hnow+10.3/($hnow+5.11)))/60;
+ ($risetime,$settime)=
+ do_rise_set_calculations($h0,$theta0,$lat,$lon,$alpha1,$delta1,
+ $alpha2,$delta2,$alpha3,$delta3);
+ return (sprintf("%s", $risetime), sprintf("%s",$settime),
+ $aznow+180,$hnow, -40*log10($distance/385000), $ifracnow );
+
}
+}
+
+sub do_rise_set_calculations
+{
+ my $norise = 0;
+ my $noset = 0;
+ my ($risehr,$risemin,$risetime,$sethr,$setmin,$settime);
+ my ($m0,$m1,$m2,$theta,$alpha,$delta,$H,$az,$h,$corr);
+ my ($i,$arg,$argtest,$H0);
+
+ my $h0=shift;
+ my $theta0=shift;
+ my $lat=shift;
+ my $lon=shift;
+ my $alpha1=shift;
+ my $delta1=shift;
+ my $alpha2=shift;
+ my $delta2=shift;
+ my $alpha3=shift;
+ my $delta3=shift;
+
$arg = (sindeg($h0)-sindeg($lat)*sindeg($delta2))/(cosdeg($lat)*cosdeg($delta2));
if ( abs($arg) > 1. ) { # either up all day or down all day
$norise = 1; # leave it to the user to examine
$corr=-$H/360;
$m0=$m0+$corr;
$m0=$m0+1 if( $m0 < 0 );
- $m0=$m0-1 if( $m0 > 1 );
+ $m0=$m0-1 if( $m0 >= 1 );
}
($az,$h)=get_az_el($H,$delta,$lat);
$corr=($h-$h0)/(360*(cosdeg($delta)*cosdeg($lat)*sindeg($H)));
$m1=$m1+$corr;
- $norise=1 if( $m1 < 0 || $m1 > 1);
+# $norise=1 if( $m1 < 0 || $m1 > 1);
+ $m1=$m1-1 if( $m1 >= 1);
+ $m1=$m1+1 if( $m1 < 0);
}
}
$risemin=$risemin-60;
$risehr=$risehr+1;
}
+ $risehr=0 if($risehr==24);
$risetime=sprintf("%02d:%02dZ",$risehr,$risemin);
} else {
$risetime="NoRise";
if( !$noset ){
$m2 = $m0 + $H0/360.;
$m2=$m2+1 if( $m2 < 0 );
- $m2=$m2-1 if( $m2 > 1 );
+ $m2=$m2-1 if( $m2 >= 1 );
for ($i=1; $i<=2; $i++) {
$theta = $theta0+360.985647*$m2;
$alpha=$alpha2+$m2*($aa+$ba+$m2*$ca)/2;
($az,$h)=get_az_el($H,$delta,$lat);
$corr=($h-$h0)/(360*(cosdeg($delta)*cosdeg($lat)*sindeg($H)));
$m2 = $m2 + $corr;
- $noset=1 if( $m2 < 0 || $m2 > 1);
+# $noset=1 if( $m2 < 0 || $m2 > 1);
+ $m2=$m2-1 if( $m2 >= 1);
+ $m2=$m2+1 if( $m2 < 0);
}
}
$setmin=$setmin-60;
$sethr=$sethr+1;
}
+ $sethr=0 if($sethr==24);
$settime=sprintf("%02d:%02dZ",$sethr,$setmin);
} else {
$settime="NoSet ";
}
+ return $risetime,$settime;
+}
+
- if ( $sun0_moon1 == 0 ) {
- return (sprintf("%s", $risetime), sprintf("%s",$settime),$aznow+180,$hnow);
- }
- if ( $sun0_moon1 == 1 ) {
- return (sprintf("%s", $risetime), sprintf("%s",$settime),
- $aznow+180,$hnow, -40*log10($distance/385000), $ifracnow );
- }
-}
sub get_moon_alpha_delta
{
#