NavList:
A Community Devoted to the Preservation and Practice of Celestial Navigation and Other Methods of Traditional Wayfinding
Long-term Sun Almanac - Awk Version
From: Dan Allen
Date: 2000 Dec 09, 11:53 AM
From: Dan Allen
Date: 2000 Dec 09, 11:53 AM
Here is an Awk version of a long-term Sun almanac.
Awk is available at Brian Kernighan's website:
http://inferno.bell-labs.com/cm/cs/awkbook/index.html
---
# s2k.awk - Sun 2000 from Meeus Astronomical Algorithms
# s2k is Copyright Daniel K. Allen, 2000.
# All rights reserved.
#
# 6 Dec 2000 - Created by Dan Allen.
#
# Usage: awk -f s2k.awk mm.ddyyyy hh:mm:ss
#
BEGIN { # all arguments and results are in decimal degrees
CONVFMT = OFMT = "%10.6f"
PI = 4*atan2(1,1)
D2R = PI/180
R2D = 180/PI
if (lat == "") lat = 47.4807666667
if (lon == "") lon = 121.797433333
if (tz == "") tz = 8
t = J2000(ARGV[1],ARGV[2] ? ARGV[2] : 12)
l = Mod(280.46645 + 36000.76983*t + 0.0003032*t*t,360)
m = Mod(357.5291 + 35999.0503*t + -0.0001559*t*t + -0.00000048*t*t*t,360)
e = (0.016708617 + -0.000042037*t + -0.0000001236*t*t)
c = (1.9146 + -0.004817*t + -0.000014*t*t) * Sin(m)
c += (0.019993 + -0.000101*t) * Sin(m*2)
c += (0.00029) * Sin(m*3)
sunLong = l + c
ecc = (84381.448 + -46.815*t - 0.00059*t*t + 0.001813*t*t*t) / 3600
ra = Mod(ATan2(Cos(ecc)*Sin(sunLong),Cos(sunLong)),360)
dec = ASin(Sin(ecc)*Sin(sunLong))
gst = (280.46061837 + 0.000387933*t*t + -2.58331180573E-8*t*t*t)
gst += t*36525*360.985647366
gst = Mod(gst,360)
lha = gst - lon - ra
alt = ASin(Sin(lat) * Sin(dec) + Cos(lat) * Cos(dec) * Cos(lha))
az = 180 + ATan(Sin(lha) / (Cos(lha) * Sin(lat) - Cos(lat)*Tan(dec)))
print " RA:",ra," Dec:",dec
print " AZ:",az," Alt:",alt
}
function Floor(x) { return x < 0 ? int(x) - 1 : int(x) }
function Mod(x,y) { return x - y * Floor(x/y) }
function Sin(x) { return sin(x*D2R) }
function Cos(x) { return cos(x*D2R) }
function Tan(x) { return Sin(x)/Cos(x) }
function ASin(x) { return atan2(x,sqrt(1 - x * x))*R2D }
function ATan(x) { return atan2(x,1)*R2D }
function ATan2(y,x){ return atan2(y,x)*R2D }
function J2000(date,time, m,d,y,a) {
if (index(date,"/") > 0) { # mm/dd/yy or mm/dd/yyyy - Y2K compatible
split(date,a,"/")
m = a[1]
d = a[2]
y = a[3] < 50 ? 2000 + a[3] : a[3] < 100 ? 1900 + a[3] : a[3]
delete a
}
else { # mm.ddyyyy - HP calculator compatible
m = int(date)
d = int((date - m)*100)
y = int(1000000*(date - int(date) - d/100)+0.5)
}
split(time,a,":")
print "Time:",y,m,d,a[1],a[2],a[3]," TZ:",tz
print " Lon:",lon," Lat:",lat
return (Julian(y,m,d,a[1]+tz,a[2],a[3]) - Julian(2000,1,1,12,0,0))/36525
}
function Julian(year,month,day,hr,min,sec, m,y,t,jd)
{
if (month <= 2) { y = year - 1; m = month + 12 }
else { y = year; m = month }
if (year < 1582) t = -2
else if (year == 1582 && (month < 10 || month == 10 && day <= 4)) t = -2
else t = int(y/400) - int(y/100)
jd = int(365.25*y) + int(30.6001*(m+1)) + t + 1720996.5 + day
jd += hr/24.0 + min/(24.0*60) + sec/(24.0*3600)
return jd
}






