Horizontal sundial calculations: Difference between revisions

Horizontal sundial calculations in various BASIC dialents (BASIC256, True BASIC and Yabasic)
(Horizontal sundial calculations in various BASIC dialents (BASIC256, True BASIC and Yabasic))
Line 324:
250 END
</lang>
 
==={{header|BASIC256}}===
<lang BASIC256>call SolarhoraAngle(-4.95, -150.5, -150.0)
end
 
function rad2deg(theta)
return theta * 180 / pi
end function
 
function deg2rad(theta)
return theta * pi / 180
end function
 
function sign(x)
if x < 0 then sign = -1
if x > 0 then sign = 1
if x = 0 then sign = 0
end function
 
subroutine SolarhoraAngle(latitude, longitude, meridian)
print "Latitude = "; latitude
print "Longitude = "; longitude
print "Meridian = "; meridian
print
print "sine of latitude: "; sin(latitude * pi / 180)
print " diff longitude: "; longitude - meridian
print
print " Time Sun hora angle Dial hora line angle"
for hora = 6 to 18
hra = (15 * hora) - longitude + meridian - 180
hla = rad2deg(atan(sin(deg2rad(latitude)) * tan(deg2rad(hra))))
if abs(hra) > 90 then hla += 180 * sign(hra * latitude)
if hora > 12 then time = hora - 12 : ap$ = " p.m." else time = hora : ap$ = " a.m."
print time; ap$; chr(9); hra; chr(9); chr(9); hla
next hora
end subroutine</lang>
 
==={{header|True BASIC}}===
<lang qbasic>FUNCTION rad2deg(theta)
LET rad2deg = theta*180/PI
END FUNCTION
FUNCTION deg2rad(theta)
LET deg2rad = theta*PI/180
END FUNCTION
FUNCTION signo(x)
IF x > 0 THEN LET signo = 1 ELSE LET signo = -1
END FUNCTION
INPUT prompt "Enter latitude (degrees) : ": latitude ! -4.95
INPUT prompt "Enter longitude (degrees) : ": longitude ! -150.5
INPUT prompt "Enter legal meridian (degrees): ": meridian ! -150.0
PRINT
PRINT "Time Sun hora angle Dial hora line angle"
FOR hora = 6 TO 18
LET hra = (15*hora)-longitude+meridian-180
LET hla = rad2deg(ATN(SIN(deg2rad(latitude))*TAN(deg2rad(hra))))
IF abs(hra) > 90 THEN LET hla = hla+180*signo(hra*latitude)
PRINT USING "## ####.## ####.###": hora, hra, hla
NEXT hora
END</lang>
 
==={{header|Yabasic}}===
<lang yabasic>SolarHourAngle(-4.95, -150.5, -150.0)
end
 
sub rad2deg(theta)
return theta * 180 / pi
end sub
 
sub deg2rad(theta)
return theta * pi / 180
end sub
 
sub SolarHourAngle(latitude, longitude, meridian)
local long, hour, hra, hla, time, ap$
print "Latitude = ", latitude
print "Longitude = ", longitude
print "Meridian = ", meridian
print "\nsine of latitude: ", sin(latitude * pi / 180)
print " diff longitude: ", longitude - meridian
print "\n Time Sun hour angle Dial hour line angle"
for hour = 6 to 18
hra = (15 * hour) - longitude + meridian - 180
hla = rad2deg(atan(sin(deg2rad(latitude)) * tan(deg2rad(hra))))
if abs(hra) > 90 hla = hla + 180 * sig(hra * latitude)
if hour > 12 then time = hour - 12 : ap$ = " a.m." else time = hour : ap$ = " p.m." : fi
print time using "##", ap$, chr$(9), hra using "####.##", chr$(9), chr$(9), hla using "####.###"
next hour
end sub</lang>
 
 
=={{header|BBC BASIC}}==
2,169

edits