X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FSun.pm;h=0616d47321c5b57804b0e94c96745950e45b4ea1;hb=1172aa77de530206b0dbb648d8489922a518d502;hp=2fe033cd8e42911c37209f430120f402312dea98;hpb=d0adf21cbcea77d72ffc021441961039c41852bf;p=spider.git diff --git a/perl/Sun.pm b/perl/Sun.pm index 2fe033cd..0616d473 100644 --- a/perl/Sun.pm +++ b/perl/Sun.pm @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#/usr/bin/perl -w # # This module was written by Steve Franke K9AN. # November, 1999. @@ -18,6 +18,7 @@ # # $Id$ # +# 2001/12/16 Fixed Julian_Date_of_Epoch and now I actually use it... # 2001/09/15 some changes to take care of cases where the object # doesn't rise or set on a given day... @@ -33,7 +34,7 @@ use strict; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0; +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); $main::build += $VERSION; $main::branch += $BRANCH; @@ -76,13 +77,18 @@ sub Julian_Day sub Julian_Date_of_Epoch { my $epoch=shift; - my $year=int($epoch*1e-3); - $year=$year+2000 if ($year < 57); - $year=$year+1900 if ($year >= 57); - my $day=$epoch-$year*1e3; + my $year=int($epoch/1000); + my $day=$epoch-$year*1000; + if ($year < 57 ) { + $year=$year+2000; + } + else { + $year=$year+1900; + } my $Julian_Date_of_Epoch=Julian_Date_of_Year($year)+$day; return $Julian_Date_of_Epoch; } + sub Julian_Date_of_Year { my $year=shift; @@ -169,6 +175,7 @@ sub rise_set 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); my $tt1 = ($julianday-1-2451545)/36525.; @@ -198,10 +205,10 @@ sub rise_set } if ( $sun0_moon1 == 1 ) { - ($alpha1, $delta1, $distance)=get_moon_alpha_delta($tt1); - ($alpha2, $delta2, $distance)=get_moon_alpha_delta($tt2); - ($alpha3, $delta3, $distance)=get_moon_alpha_delta($tt3); - ($alphanow, $deltanow, $distancenow)=get_moon_alpha_delta($ttnow); + ($alpha1, $delta1, $distance, $ifrac)=get_moon_alpha_delta($tt1); + ($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.; $H=$thetanow-$lon-$alphanow; $H=reduce_angle_to_360($H); @@ -315,7 +322,7 @@ sub rise_set } if ( $sun0_moon1 == 1 ) { return (sprintf("%s", $risetime), sprintf("%s",$settime), - $aznow+180,$hnow, -40*log10($distance/385000) ); + $aznow+180,$hnow, -40*log10($distance/385000), $ifracnow ); } } sub get_moon_alpha_delta @@ -323,6 +330,9 @@ sub get_moon_alpha_delta # # Calculate the moon's right ascension and declination # + # As of October 2001, also calculate the illuminated fraction of the + # moon's disk... (why not?) + # my $tt=shift; my $Lp=218.3164477+481267.88123421*$tt- @@ -542,7 +552,20 @@ sub get_moon_alpha_delta my $delta=asin(cosdeg($beta)*sindeg($epsilon)*sindeg($lambda)+sindeg($beta)*cosdeg($epsilon))*$r2d; $delta = reduce_angle_to_360($delta); - return ($alpha,$delta,$distance); +# $phase will be the "moon phase angle" from p. 346 of Meeus' book... + my $phase=180.0 - $D - 6.289 *sindeg($Mp) + + 2.100 *sindeg($M) + - 1.274 *sindeg(2.*$D - $Mp) + - 0.658 *sindeg(2.*$D) + - 0.214 *sindeg(2.*$Mp) + - 0.110 *sindeg($D); + +# $illum_frac is the fraction of the disk that is illuminated, and will be +# zero at new moon and 1.0 at full moon. + + my $illum_frac = (1.0 + cosdeg( $phase ))/2.; + + return ($alpha,$delta,$distance,$illum_frac); } sub get_sun_alpha_delta @@ -628,14 +651,7 @@ sub get_satellite_pos my $epoch = $sat_ref ->{epoch}; #printf("epoch = %10.2f\n",$epoch); - my $epoch_year=int($epoch/1000); - my $epoch_day=$epoch-int(1000*$epoch_year); -#printf("epoch_year = %10.2f\n",$epoch_year); -#printf("epoch_day = %17.12f\n",$epoch_day); - my $ep_year=$epoch_year+2000 if ($epoch_year < 57); - $ep_year=$epoch_year+1900 if ($epoch_year >= 57); - my $jt_epoch=Julian_Date_of_Year($ep_year); - $jt_epoch=$jt_epoch+$epoch_day; + my $jt_epoch=Julian_Date_of_Epoch($epoch); #printf("JT for epoch = %17.12f\n",$jt_epoch); my $tsince=($jtime-$jt_epoch)*24*60; #printf("tsince (min) = %17.12f\n",$tsince);