Horizontal sundial calculations: Difference between revisions
Content deleted Content added
m →{{header|Phix}}: added syntax colouring, marked p2js compatible |
m →{{header|Wren}}: Minor tidy |
||
(13 intermediate revisions by 8 users not shown) | |||
Line 16:
{{trans|Python}}
<
V lng = Float(input(‘Enter longitude => ’))
V ref = Float(input(‘Enter legal meridian => ’))
Line 31:
hra -= lng - ref
V hla = degrees(atan(slat * tan(radians(hra))))
print(‘HR=#3; HRA=#3.3; HLA=#3.3’.format(h, hra, hla))</
{{out}}
Line 61:
{{trans|ALGOL 68}}
sundial.adb:
<
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
Line 105:
end;
end loop;
end Sundial;</
{{out}}
<pre>Enter latitude: -4.95
Line 142:
> Simon
-->
<
REAL lat, slat, lng, ref;
print ( "Enter latitude => " ); read (lat);
Line 165:
new line(stand out)
OD
END</
{{out}}
<pre>
Line 190:
HR= +6; HRA= +90.500; HLA= +84.225
</pre>
=={{header|Arturo}}==
{{trans|Nim}}
<syntaxhighlight lang="arturo">degToRad: function [deg]-> deg * pi // 180
radToDeg: function [rad]-> rad * 180 // pi
lat: to :floating input "Enter latitude => "
lng: to :floating input "Enter longitude => "
med: to :floating input "Enter legal meridian => "
print ""
slat: sin degToRad lat
print " sine of latitude: " ++ to :string .format:".3f" slat
print " diff longitude: " ++ to :string .format:".3f" lng-med
print ""
print "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
loop (neg 6)..6 'h [
hra: med + (to :floating 15*h) - lng
hla: radToDeg atan slat * tan degToRad hra
print "HR=" ++ (to :string .format:"3d" h) ++ "; " ++
"HRA=" ++ (to :string .format:"7.3f" hra) ++ "; " ++
"HLA=" ++ (to :string .format:"7.3f" hla)
]</syntaxhighlight>
{{out}}
<pre>Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -0.086
diff longitude: -0.500
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA=-89.500; HLA= 84.225
HR= -5; HRA=-74.500; HLA= 17.283
HR= -4; HRA=-59.500; HLA= 8.334
HR= -3; HRA=-44.500; HLA= 4.847
HR= -2; HRA=-29.500; HLA= 2.795
HR= -1; HRA=-14.500; HLA= 1.278
HR= 0; HRA= 0.500; HLA= -0.043
HR= 1; HRA= 15.500; HLA= -1.371
HR= 2; HRA= 30.500; HLA= -2.910
HR= 3; HRA= 45.500; HLA= -5.018
HR= 4; HRA= 60.500; HLA= -8.671
HR= 5; HRA= 75.500; HLA=-18.451
HR= 6; HRA= 90.500; HLA= 84.225</pre>
=={{header|AutoHotkey}}==
Line 195 ⟶ 246:
{{trans|F#}}
AutoHotkey is not a command-line programming language, let me make that clear. However, in translating the F# I found that the command line really is best for this type of app. The first 3 comments in the script describe the workarounds used to interface with the commandline.
<
Pi := 4*ATan(1)
,Degrees := Pi/180
Line 226 ⟶ 277:
FileAppend, %clockhour%`t`t%shr%`t`t%dhla%`n, CONOUT$
}
MsgBox close me when done.</
{{out}}
<pre>Enter Latitude:-4.95
Line 252 ⟶ 303:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f HORIZONTAL_SUNDIAL_CALCULATIONS.AWK
BEGIN {
Line 270 ⟶ 321:
function dr(x) { return x * 3.14159265 / 180 } # degrees to radians
function rd(x) { return x * 180 / 3.14159265 } # radians to degrees
</syntaxhighlight>
<p>output:</p>
<pre>
Line 293 ⟶ 344:
</pre>
=={{header|
==={{header|ANSI BASIC}}===
{{trans|ALGOL-68|ANSI BASIC has a possibility to use degrees in calculations.}}
{{works with|Decimal BASIC}}
<syntaxhighlight lang="basic">
100 REM Horizontal sundial calculations
110 INPUT PROMPT "Enter latitude => ": Lat
120 INPUT PROMPT "Enter longitude => ": Lng
130 INPUT PROMPT "Enter legal meridian => ": Ref
140 PRINT
150 OPTION ANGLE DEGREES
160 LET Slat = SIN(Lat)
170 PRINT " sine of latitude: "; Slat
180 PRINT " diff longitude: "; Lng - Ref
190 PRINT
200 PRINT "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
210 FOR Hour = -6 TO 6
220 LET HourAngle = 15 * Hour
230 LET HourAngle = HourAngle - (Lng - Ref) ! correct for longitude difference
240 LET HourLineAngle = ATN(Slat * TAN(HourAngle))
250 PRINT USING "HR=###; HRA=####.###; HLA=####.###": Hour, HourAngle, HourLineAngle
260 NEXT Hour
270 END
</syntaxhighlight>
{{out}}
<pre>
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -8.62863657979234E-2
diff longitude: -.5
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA= -89.500; HLA= 84.225
HR= -5; HRA= -74.500; HLA= 17.283
HR= -4; HRA= -59.500; HLA= 8.334
HR= -3; HRA= -44.500; HLA= 4.847
HR= -2; HRA= -29.500; HLA= 2.795
HR= -1; HRA= -14.500; HLA= 1.278
HR= 0; HRA= .500; HLA= -.043
HR= 1; HRA= 15.500; HLA= -1.371
HR= 2; HRA= 30.500; HLA= -2.910
HR= 3; HRA= 45.500; HLA= -5.018
HR= 4; HRA= 60.500; HLA= -8.671
HR= 5; HRA= 75.500; HLA= -18.451
HR= 6; HRA= 90.500; HLA= 84.225
</pre>
==={{header|BASIC256}}===
<syntaxhighlight 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</syntaxhighlight>
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<
INPUT "Enter latitude (degrees) : " latitude
Line 308 ⟶ 444:
IF ABS(hra) > 90 hla += 180 * SGN(hra * latitude)
PRINT FNusing("##.##", hour), FNusing(" ####.### ", hra), FNusing(" ####.###", hla)
NEXT hour</
{{out}}
(note the correct '''negative''' value for time 18:00)
Line 329 ⟶ 465:
17.00 75.500 -18.451
18.00 90.500 -95.775</pre>
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 CLS
20 DEF FNR(x) = x * PI/180
30 DEF FND(x) = x * 180/PI
40 INPUT " Enter latitude (degrees): ";latitude
50 INPUT " Enter longitude (degrees): ";longitude
60 INPUT "Enter legal meridian (degrees): ";meridian
70 PRINT
80 PRINT " Time Sun hour angle Dial hour line angle"
90 FOR h = 6 TO 18
100 hra = 15*h-longitude+meridian-180
110 hla = FN D(ARCTAN(SIN(FN R(latitude))*TAN(FN R(hra))))
120 IF ABS(hra) > 90 THEN hla = hla+180*SGN(hra*latitude)
130 PRINT USING "##.##";h;TAB (10)
140 PRINT USING "####.###";hra;TAB (27)
150 PRINT USING "####.###";hla
160 NEXT h
170 END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|FreeBASIC}}===
{{trans|BBC BASIC}}
<syntaxhighlight lang="freebasic">' version 04-11-2016
' compile with: fbc -s console
#Macro deg2rad (x)
(x) * Atn(1) / 45
#EndMacro
#Macro rad2deg (x)
(x) * 45 / Atn(1)
#EndMacro
' ------=< MAIN >=------
Dim As Double latitude, longitude, meridian, hra, hla
Dim As ULong h
Input " Enter latitude (degrees): ", latitude
Input " Enter longitude (degrees): ", longitude
Input "Enter legal meridian (degrees): ", meridian
Print
Print " Time Sun hour angle Dial hour line angle"
For h = 6 To 18
hra = h * 15 - longitude + meridian - 180
hla = rad2deg(Atn(Sin(deg2rad(latitude)) * Tan(deg2rad(hra))))
If Abs(hra) > 90 Then hla += 180 * Sgn(hra * latitude)
Print Using "##.## ####.### ####.###"; h; hra; hla
Next
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</syntaxhighlight>
{{out}}
<pre> Enter latitude (degrees): -4.95
Enter longitude (degrees): -150.5
Enter legal meridian (degrees): -150
Time Sun hour angle Dial hour line angle
6.00 -89.500 84.225
7.00 -74.500 17.283
8.00 -59.500 8.334
9.00 -44.500 4.847
10.00 -29.500 2.795
11.00 -14.500 1.278
12.00 0.500 -0.043
13.00 15.500 -1.371
14.00 30.500 -2.910
15.00 45.500 -5.018
16.00 60.500 -8.671
17.00 75.500 -18.451
18.00 90.500 -95.775</pre>
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1
def fn rad2deg( theta as double ) as double = theta * 180 / pi
def fn deg2rad( theta as double ) as double = theta * pi / 180
local fn SolarHourAngle( latitude as double, longitude as double, meridian as double )
long hour
double hra, hla, t
CFStringRef ap
print "Latitude = "; latitude; chr$(13); "Longitude = "; longitude; chr$(13); "Meridian = "; meridian
print : print "sine of latitude: "; sin(latitude * pi / 180 ); chr$(13); " diff longitude: "; longitude - meridian
print : print "Time", "Sun hour angle", "Dial hour line angle"
for hour = 6 to 18
hra = ( 15 * hour ) - longitude + meridian - 180
hla = fn rad2deg( atn( sin( fn deg2rad( latitude ) ) * tan( fn deg2rad( hra ) )))
if abs( hra ) > 90 then hla = hla + 180 * sgn( hra * latitude )
if hour > 12 then t = hour - 12 : ap = @" a.m." else t = hour : ap = @" p.m."
print using "##"; t; ap, using "####.##"; hra, using "####.###"; hla
next hour
end fn
fn SolarHourAngle( -4.95, -150.5, -150.0 )
HandleEvents</syntaxhighlight>
Output:
<pre>
Latitude = -4.95
Longitude = -150.5
Meridian = -150
sine of latitude: -0.0862863658
diff longitude: -0.5
Time Sun hour angle Dial hour line angle
6 p.m. -89.50 84.225
7 p.m. -74.50 17.283
8 p.m. -59.50 8.334
9 p.m. -44.50 4.847
10 p.m. -29.50 2.795
11 p.m. -14.50 1.278
12 p.m. 0.50 -0.043
1 a.m. 15.50 -1.371
2 a.m. 30.50 -2.910
3 a.m. 45.50 -5.018
4 a.m. 60.50 -8.671
5 a.m. 75.50 -18.451
6 a.m. 90.50 -95.775
</pre>
==={{header|GW-BASIC}}===
{{trans|ALGOL 68}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="qbasic">
10 ' Horizontal sundial calculations
20 PRINT "Enter latitude => ";
30 INPUT LAT
40 PRINT "Enter longitude => ";
50 INPUT LNG
60 PRINT "Enter legal meridian => ";
70 INPUT REF
80 PRINT
90 LET PI = 4 * ATN(1)
100 LET SLAT = SIN(LAT * PI / 180)
110 PRINT " sine of latitude: "; USING "#.##^^^^"; SLAT
120 PRINT " diff longitude: "; USING "####.###"; LNG - REF
130 PRINT
140 PRINT "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
150 FOR H% = -6 TO 6
160 LET HRA = 15 * H%
170 LET HRA = HRA - (LNG - REF): ' correct for longitude difference
180 LET HLA = ATN(SLAT * TAN(HRA * PI / 180)) * 180 / PI
190 PRINT "HR="; USING "+##"; H%;
200 PRINT "; HRA="; USING "+###.###"; HRA;
210 PRINT "; HLA="; USING "+###.###"; HLA
220 NEXT H%
230 END
</syntaxhighlight>
{{out}}
<pre>
Enter latitude => ? -4.95
Enter longitude => ? -150.5
Enter legal meridian => ? -150
sine of latitude: -.86E-01
diff longitude: -0.500
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA= -89.500; HLA= +84.225
HR= -5; HRA= -74.500; HLA= +17.283
HR= -4; HRA= -59.500; HLA= +8.334
HR= -3; HRA= -44.500; HLA= +4.847
HR= -2; HRA= -29.500; HLA= +2.795
HR= -1; HRA= -14.500; HLA= +1.278
HR= +0; HRA= +0.500; HLA= -0.043
HR= +1; HRA= +15.500; HLA= -1.371
HR= +2; HRA= +30.500; HLA= -2.910
HR= +3; HRA= +45.500; HLA= -5.018
HR= +4; HRA= +60.500; HLA= -8.671
HR= +5; HRA= +75.500; HLA= -18.451
HR= +6; HRA= +90.500; HLA= +84.225
</pre>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "SunDial.bas"
110 OPTION ANGLE RADIANS
120 TEXT 80
130 LET DR=PI/180:LET RD=180/PI
140 INPUT PROMPT "Enter latitude: ":LAT
150 INPUT PROMPT "Enter longitude: ":LNG
160 INPUT PROMPT "Enter legal meridian: ":REF
170 LET S=SIN(LAT*DR)
180 PRINT :PRINT "Sine of latitude :";S
190 PRINT "Diff longitude: ";LNG-REF
200 PRINT " Hour,",,"sun hour angle, dial hour line angle from 6am to 6 pm"
210 FOR H=6 TO 18
220 LET HRA=15*H-LNG+REF
230 LET HLA=ATN(S*TAN(HRA*DR))*RD
240 PRINT "HR = ";H,"HRA =";HRA,"HLA =";HLA
250 NEXT</syntaxhighlight>
==={{header|Liberty BASIC}}===
Based on Algol & BBC BASIC versions. Note Liberty BASIC works in radians.
<syntaxhighlight lang="lb">global pi
pi = 3.14159265
input "Enter latitude (degrees) : "; latitude ' -4.95
input "Enter longitude (degrees) : "; longitude ' -150.5
input "Enter legal meridian (degrees): "; meridian ' -150.0
print
print "Time Sun hour angle Dial hour line angle"
for hour = 6 TO 18
hra = 15 * hour - longitude + meridian - 180
hla = rad2deg(atn(sin(deg2rad(latitude)) * tan(deg2rad(hra))))
if abs(hra) > 90 then hla = hla + 180 * sgn(hra * latitude)
print using( "##.##", hour), using("####.### ", hra), using("####.###", hla)
next hour
end
function rad2deg(theta)
rad2deg = theta * 180 / pi
end function
function deg2rad(theta)
deg2rad = theta * pi / 180
end function
function sgn(x)
if x > 0 then sgn = 1 else sgn = -1
end function</syntaxhighlight>
{{out}}
<pre>
Enter latitude (degrees) : -4.95
Enter longitude (degrees) : -150.5
Enter legal meridian (degrees): -150.0
Time Sun hour angle Dial hour line angle
6.00 -89.500 84.225
7.00 -74.500 17.283
8.00 -59.500 8.334
9.00 -44.500 4.847
10.00 -29.500 2.795
11.00 -14.500 1.278
12.00 0.500 -0.043
13.00 15.500 -1.371
14.00 30.500 -2.910
15.00 45.500 -5.018
16.00 60.500 -8.671
17.00 75.500 -18.451
18.00 90.500 -95.775
</pre>
==={{header|Microsoft Small Basic}}===
{{trans|ALGOL-68}}
<syntaxhighlight lang="microsoftsmallbasic">
TextWindow.Write("Enter latitude => ")
lat = TextWindow.ReadNumber()
TextWindow.Write("Enter longitude => ")
lng = TextWindow.ReadNumber()
TextWindow.Write("Enter legal meridian => ")
ref = TextWindow.ReadNumber()
sLat = Math.Sin(Math.GetRadians(lat))
TextWindow.WriteLine("")
TextWindow.Write(" sine of latitude: ")
TextWindow.WriteLine(Math.Round(sLat * 10000) / 10000)
TextWindow.Write(" diff longitude: ")
TextWindow.WriteLine(lng - ref)
TextWindow.WriteLine("")
TextWindow.WriteLine("Hour, sun hour angle, dial hour line angle from 6am to 6pm")
For hour = -6 To 6
hourAngle = 15 * hour
hourAngle = hourAngle - (lng - ref) ' correct for longitude difference
hourLineAngle = math.GetDegrees(Math.ArcTan(sLat * Math.Tan(Math.GetRadians(hourAngle))))
TextWindow.Write("HR=")
TextWindow.CursorLeft = 3 + (3 - Text.GetLength(hour))
TextWindow.Write(hour)
TextWindow.Write("; HRA=")
TextWindow.CursorLeft = 12 + (6 - Text.GetLength(hourAngle))
TextWindow.Write(hourAngle)
TextWindow.Write("; HLA=")
TextWindow.CursorLeft = 24 + (4 - Text.GetLength(Math.Floor(hourLineAngle)))
TextWindow.Write(Math.Round(hourLineAngle * 1000) / 1000)
TextWindow.WriteLine("")
EndFor
</syntaxhighlight>
{{out}}
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -0.0863
diff longitude: -0.5
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA= -89.5; HLA= 84.225
HR= -5; HRA= -74.5; HLA= 17.283
HR= -4; HRA= -59.5; HLA= 8.334
HR= -3; HRA= -44.5; HLA= 4.847
HR= -2; HRA= -29.5; HLA= 2.795
HR= -1; HRA= -14.5; HLA= 1.278
HR= 0; HRA= 0.5; HLA= -0.043
HR= 1; HRA= 15.5; HLA= -1.371
HR= 2; HRA= 30.5; HLA= -2.91
HR= 3; HRA= 45.5; HLA= -5.018
HR= 4; HRA= 60.5; HLA= -8.671
HR= 5; HRA= 75.5; HLA= -18.451
HR= 6; HRA= 90.5; HLA= 84.225
==={{header|Minimal BASIC}}===
{{works with|QBasic}}
{{trans|ALGOL-68}}
<syntaxhighlight lang="gwbasic">
10 REM Horizontal sundial calculations
20 DEF FNM(X) = INT(X*1000+0.5)/1000
30 PRINT "Enter latitude";
40 INPUT L
50 PRINT "Enter longitude";
60 INPUT L1
70 PRINT "Enter legal meridian";
80 INPUT R
90 PRINT
100 LET P = 4*ATN(1)
110 LET S1 = SIN(L*P/180)
120 PRINT " sine of latitude:"; S1
130 PRINT " diff longitude: "; FNM(L1-R)
140 PRINT
150 PRINT "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
160 FOR H = -6 TO 6
170 LET A1 = 15*H
180 REM Correct for longitude difference:
190 LET A1 = A1-(L1-R)
200 LET A2 = ATN(S1*TAN(A1*P/180))*180/P
210 PRINT "HR ="; H;
220 PRINT TAB(9); "HRA ="; FNM(A1);
230 PRINT TAB(24); "HLA ="; FNM(A2)
240 NEXT H
250 END
</syntaxhighlight>
==={{header|PureBasic}}===
{{trans|ALGOL 68}}
<syntaxhighlight lang="purebasic">If OpenConsole()
Define.f lat, slat, lng, ref
Define.i h
Print("Enter latitude => "): lat=ValF(Input())
Print("Enter longitude => "): lng=ValF(Input())
Print("Enter legal meridian => "): ref=ValF(Input())
PrintN("")
slat=Sin(lat*2*#PI/360)
PrintN(" sine of latitude: "+StrF(slat,3))
PrintN(" diff longitude: "+StrF((lng-ref),3)+#CRLF$)
PrintN("Hour, sun hour angle, dial hour line angle from 6am to 6pm")
For h=-6 To 6
Define.f hra, hla
hra=15*h
hra=hra-(lng-ref)
hla=ATan(slat*Tan(hra*2*#PI/360))*360/(2*#PI)
PrintN("HR="+RSet(Str(h),3)+"; HRA="+RSet(StrF(hra,3),7)+"; HLA="+RSet(StrF(hla,3),7))
Next
EndIf</syntaxhighlight>
{{out}}
<pre>Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -0.086
diff longitude: -0.500
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA=-89.500; HLA= 84.225
HR= -5; HRA=-74.500; HLA= 17.283
HR= -4; HRA=-59.500; HLA= 8.334
HR= -3; HRA=-44.500; HLA= 4.847
HR= -2; HRA=-29.500; HLA= 2.795
HR= -1; HRA=-14.500; HLA= 1.278
HR= 0; HRA= 0.500; HLA= -0.043
HR= 1; HRA= 15.500; HLA= -1.371
HR= 2; HRA= 30.500; HLA= -2.910
HR= 3; HRA= 45.500; HLA= -5.018
HR= 4; HRA= 60.500; HLA= -8.671
HR= 5; HRA= 75.500; HLA=-18.451
HR= 6; HRA= 90.500; HLA= 84.225
</pre>
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">global pi
pi = 22 / 7
print "Enter latitude (degrees) : "; :input latitude ' -4.95
print "Enter longitude (degrees) : "; :input longitude ' -150.5
print "Enter legal meridian (degrees): "; :input meridian ' -150.0
print
print "Time Sun hour angle Dial hour line angle"
for hour = 6 TO 18
hra = (15 * hour) - longitude + meridian -180
hla =rad2deg( atn( sin( deg2rad( latitude)) *tan( deg2rad( hra))))
if abs( hra) >90 then hla =hla +180 *sgn( hra *latitude)
print using( "##", hour);" ";using("####.##", hra);" ";using("####.###", hla)
next hour
function rad2deg( theta)
rad2deg =theta *180 /pi
end function
function deg2rad( theta)
deg2rad =theta *pi /180
end function
function sgn( x)
if x >0 then sgn =1 else sgn =-1
end function
end</syntaxhighlight>
{{out}}
<pre>
Enter latitude: -4.95
Enter longitude: -150.5
Enter legal meridian: -150
Time Sun hour angle Dial hour line angle
6 -89.50 84.606
7 -74.50 17.316
8 -59.50 8.342
9 -44.50 4.850
10 -29.50 2.796
11 -14.50 1.279
12 0.50 -0.043
13 15.50 -1.371
14 30.50 -2.911
15 45.50 -5.021
16 60.50 -8.680
17 75.50 -18.488
18 90.50 -96.224</pre>
==={{header|True BASIC}}===
<syntaxhighlight 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</syntaxhighlight>
==={{header|XBasic}}===
{{trans|ALGOL-68}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">
PROGRAM "sundial"
VERSION "0.0001"
IMPORT "xma"
DECLARE FUNCTION Entry()
FUNCTION Entry()
lat! = SINGLE(INLINE$("Enter latitude => "))
lng! = SINGLE(INLINE$("Enter longitude => "))
ref! = SINGLE(INLINE$("Enter legal meridian => "))
PRINT
slat! = SIN(lat! * $$PI / 180.0)
PRINT " sine of latitude: "; FORMAT$("#.##^^^^", slat!)
PRINT " diff longitude: "; FORMAT$("#.###", lng! - ref!)
PRINT
PRINT "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
FOR hour@ = -6 TO 6
hourAngle! = 15 * hour@
hourAngle! = hourAngle! - (lng! - ref!) ' correct for longitude difference
hourLineAngle! = ATAN(slat! * TAN(hourAngle! * $$PI / 180.0)) * 180.0 / $$PI
PRINT "HR="; FORMAT$("###", hour@);
PRINT "; HRA="; FORMAT$("####.###", hourAngle!);
PRINT "; HLA="; FORMAT$("####.###", hourLineAngle!)
NEXT hour@
END FUNCTION
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -8.63E-02
diff longitude: -0.500
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA= -89.500; HLA= 84.225
HR= -5; HRA= -74.500; HLA= 17.283
HR= -4; HRA= -59.500; HLA= 8.334
HR= -3; HRA= -44.500; HLA= 4.847
HR= -2; HRA= -29.500; HLA= 2.795
HR= -1; HRA= -14.500; HLA= 1.278
HR= 0; HRA= 0.500; HLA= -0.043
HR= 1; HRA= 15.500; HLA= -1.371
HR= 2; HRA= 30.500; HLA= -2.910
HR= 3; HRA= 45.500; HLA= -5.018
HR= 4; HRA= 60.500; HLA= -8.671
HR= 5; HRA= 75.500; HLA= -18.451
HR= 6; HRA= 90.500; HLA= 84.225
</pre>
==={{header|Yabasic}}===
<syntaxhighlight 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</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
{{trans|ERRE}}
<syntaxhighlight lang="zxbasic">10 DEF FN r(x)=x*PI/180
20 DEF FN d(x)=x*180/PI
30 INPUT "Enter latitude (degrees): ";latitude
40 INPUT "Enter longitude (degrees): ";longitude
50 INPUT "Enter legal meridian (degrees): ";meridian
60 PRINT "Latitude: ";latitude
70 PRINT "Longitude:";longitude
80 PRINT "Legal meridian: ";meridian
90 PRINT '" Sun Dial"
100 PRINT "Time hour angle hour line ang."
110 PRINT "________________________________"
120 FOR h=6 TO 18
130 LET hra=15*h-longitude+meridian-180
140 LET hla=FN d(ATN (SIN (FN r(latitude))*TAN (FN r(hra))))
150 IF ABS (hra)>90 THEN LET hla=hla+180*SGN (hra*latitude)
160 PRINT h;" ";hra;" ";hla
170 NEXT h</syntaxhighlight>
=={{header|C}}==
{{trans|ALGOL 68}}
<
#include <math.h>
Line 374 ⟶ 1,079:
return 0;
}</
=={{header|C sharp|C#}}==
<
namespace RosettaCode
Line 408 ⟶ 1,113:
}
}
}</
=={{header|C++}}==
<
#include <iostream>
#include <numbers>
Line 473 ⟶ 1,178:
}
}
</syntaxhighlight>
{{out}}
<pre>
Line 496 ⟶ 1,201:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<
DATA DIVISION.
Line 549 ⟶ 1,254:
dial-hour-line-angle-disp
END-PERFORM
.</
{{out}}
Line 578 ⟶ 1,283:
=={{header|D}}==
{{trans|Python}}
<
double radians(in double x) pure nothrow { return x * (PI / 180); }
Line 605 ⟶ 1,310:
writefln("HR=%3d; HRA=%7.3f; HLA=%7.3f", h, hra, hla);
}
}</
{{out|Example run}}
<pre>Enter latitude => -4.95
Line 634 ⟶ 1,339:
=={{header|DWScript}}==
{{trans|Java}}
<
begin
PrintLn(Format('latitude: %7.2f', [lat]));
Line 656 ⟶ 1,361:
end;
PrintSundial(-4.95, -150.5, -150);</
{{out}}
<pre>latitude: -4.95
Line 680 ⟶ 1,385:
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
func
write s$
v = number input
print v
return v
.
slat = sin lat
diff = lng - merid
Line 696 ⟶ 1,403:
print "Hour\tSun hour angle\tDial hour line angle"
for h = -6 to 6
hra = 15 * h - diff
hla = atan2 (slat * sin hra) cos hra
print h + 12 & "\t" & hra & "\t\t" & hla
.
</syntaxhighlight>
=={{header|ERRE}}==
<
FUNCTION RAD(X)
Line 730 ⟶ 1,438:
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>
Line 756 ⟶ 1,464:
=={{header|Euphoria}}==
{{works with|OpenEuphoria}}
<syntaxhighlight lang="euphoria">
include std/console.e
include std/mathcons.e
Line 792 ⟶ 1,500:
if getc(0) then end if
</syntaxhighlight>
{{out}}
<pre>
Line 817 ⟶ 1,525:
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<
open System
Line 852 ⟶ 1,560:
//To keep the console window open, can be omitted with block comment (" (* comment *) ")
Console.WriteLine("Press any key to continue...")
Console.ReadKey() |> ignore</
{{out|Example output}}
<pre>
Line 882 ⟶ 1,590:
=={{header|Factor}}==
{{trans|Java}}
<
math.parser math.ranges math.trig sequences ;
IN: rosetta-code.sundial
Line 913 ⟶ 1,621:
: sundial-demo ( -- ) get-input nl 3dup .diff nl .angles ;
MAIN: sundial-demo</
{{out}}
<pre>
Line 940 ⟶ 1,648:
=={{header|Forth}}==
<
pad 32 accept pad swap >float 0= throw ;
: >radians ( deg -- rad ) 180e f/ pi f* ;
Line 958 ⟶ 1,666:
fdup f. ." , "
>radians fsincos fswap frot f* fswap fatan2 >degrees f.
loop fdrop fdrop ;</
=={{header|Fortran}}==
{{works with|gfortran}} with <tt>-fbackslash</tt> option
<
real :: lat, slat, lng, ref
Line 1,006 ⟶ 1,714:
end function rd
end program SunDial</
=={{header|Go}}==
<
import (
Line 1,153 ⟶ 1,749:
fmt.Printf("%2.0f %8.3f %8.3f\n", h, hra, hla)
}
}</
{{out}}
<pre>
Line 1,177 ⟶ 1,773:
5 75.500 -18.451
6 90.500 -95.775
</pre>
=={{header|Haskell}}==
<
roundDec d = (/ 10.0 ^ d) . fromIntegral . round . (* 10.0 ^ d)
Line 1,262 ⟶ 1,805:
take 16 (show (roundDec 3 sha) ++ repeat ' ') ++
" " ++ show (roundDec 3 dhla))
[-6,-5 .. 6]</
{{out}}
<pre>*Rosetta.HorSunDial> main
Line 1,286 ⟶ 1,829:
=={{header|Icon}} and {{header|Unicon}}==
<
PrintSundial(-4.95, -150.5, -150);
end
Line 1,309 ⟶ 1,852:
" HRA=",hra,", HLA=",hla)
}
end</
{{out}}
<pre>latitude: -4.95
Line 1,331 ⟶ 1,874:
HR= 5pm HRA=75.5, HLA=-18.45099922256532
HR= 6pm HRA=90.5, HLA=-95.77516739863968</pre>
=={{header|J}}==
<
atan2=: {:@*.@j. NB. arc tangent of y divided by x
Line 1,365 ⟶ 1,890:
r=.((,. (,. (atan2 *&slat)/@+.@r.&.rfd)) diff + 15&*) i:6
smoutput lbl ,: ('3.0';'7.3';'7.3') 8!:1 r
)</
{{out|Example}}
<
Latitude _4.95
Longitude _150.5
Line 1,389 ⟶ 1,914:
│ 5 │ 75.500 │-18.451 │
│ 6 │ 90.500 │-95.775 │
└──────┴────────────────┴────────────────────┘</
=={{header|Java}}==
{{trans|C}} (Substitutes in atan2 for the hour line angle calculation)
<
public class Sundial {
Line 1,424 ⟶ 1,949:
}
}
}</
{{out}}
<pre>Enter latitude: -4.95
Line 1,447 ⟶ 1,972:
HR= 5; HRA= 75.500; HLA= -18.451
HR= 6; HRA= 90.500; HLA= -95.775</pre>
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq.'''
'''Adapted from [[#Wren|Wren]]'''
'''Generic Utilities'''
<syntaxhighlight lang=jq>
# `prompts` should be an array defining the prompts, variable names, and their types,
# as exemplified below.
# After all values have been gathered, `get` emits an object defining the bindings.
def get($prompts):
label $out
| foreach range(0;infinite) as $_ ({i:null, imax: ($prompts|length)};
if .i == null then .i = 0
elif .i == .imax then break $out
else .help = null
| first(inputs) as $n
| $prompts[.i].type as $type
| if $type == null or $type == "string"
then .result[$prompts[.i].key] = $n
| .i += 1
elif $type == "number"
then (try ($n|tonumber) catch null) as $n
| if $n then .result[$prompts[.i].key] = $n
| .i += 1
else .help = .i
end
elif $type == "integer"
then if ($n|test("^[0-9]+$"))
then .result[$prompts[.i].key] = ($n|tonumber)
| .i += 1
else .help = .i
end
elif $type|type == "object"
then if $type.regex and ($n | test($type.regex))
then .result[$prompts[.i].key] = $n
| .i += 1
else .help = .i
end
else .
end
end;
(select(.help) | $prompts[.help].help // empty),
if .i < .imax then $prompts[.i].prompt
else .result
end )
;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
def rpad($len): tostring | ($len - length) as $l | . + ("0" * $l)[:$l];
# Input: a string of digits with up to one "."
# Output: the corresponding string representation with exactly $n decimal digits
def align_decimal($n):
tostring
| if index(".")
then capture("(?<i>[0-9]*[.])(?<j>[0-9]{0," + ($n|tostring) + "})")
| .i + (.j|rpad($n))
else . + "." + ("0" * $n)
end ;
def pi: 4*(1|atan);
</syntaxhighlight>
'''The Task'''
<syntaxhighlight lang=jq>
def prompts: [
{ prompt: "Enter latitude: ", key: "lat", type: "number", help: "in degrees"},
{ prompt: "Enter longitude: ", key: "lng", type: "number", help: "in degrees"},
{ prompt: "Enter legal meridian: ", key: "ref", type: "number", help: "in degrees"}
];
def task:
get(prompts)
| if type != "object" then . # the prompts
else
((.lat * pi / 180)|sin) as $slat
| (.lng - .ref) as $diff
| "\n sine of latitude : \($slat)",
" diff longitude : \($diff)",
"\nHour, sun hour angle, dial hour line angle from 6am to 6pm",
(range(-6;7) as $h
| (15*$h - $diff) as $hra
| (($hra * pi /180)|sin) as $s
| (($hra * pi /180)|cos) as $c
| (atan2($slat*$s; $c) * 180 / pi) as $hla
| [$h|lpad(3)] + ([$hra, $hla] | map(align_decimal(3)|lpad(7))) | join(" ") )
end;
task
</syntaxhighlight>
'''Invocation''':
The program handles user input errors provided the -R option is specified:
<pre>
jq -nRr -f horizontal-sundial-calculations.jq
</pre>
'''Transcript'''
<pre>
Enter latitude:
-4.95
Enter longitude:
-150.5
Enter legal meridian:
?
in degrees
Enter legal meridian:
-150
sine of latitude : -0.08628636579792338
diff longitude : -0.5
Hour, sun hour angle, dial hour line angle from 6am to 6pm
-6 89.500 84.224
-5 74.500 17.282
-4 59.500 8.333
-3 44.500 4.846
-2 29.500 2.794
-1 14.500 1.278
0 0.500 0.043
1 15.500 1.370
2 30.500 2.909
3 45.500 5.018
4 60.500 8.671
5 75.500 18.450
6 90.500 95.775
</pre>
=={{header|Julia}}==
{{trans|Python}}
<
print("Enter latitude => ")
lat = parse(Float64, readline(STDIN))
Line 1,471 ⟶ 2,124:
@printf "HR = %3d; HRA = %7.3f; HLA = %7.3f\n" h hra hla
end
</syntaxhighlight>
{{out}}
Line 1,500 ⟶ 2,153:
=={{header|Kotlin}}==
<
import java.lang.Math.cos
import java.lang.Math.sin
Line 1,532 ⟶ 2,185:
println("%2d %s %+7.3f %+7.3f".format(hr, am, sha, dhla))
}
}</
Sample input/output:
{{out}}
Line 1,560 ⟶ 2,213:
5 PM +75.500 -18.451
6 PM +90.500 -95.775
</pre>
=={{header|LiveCode}}==
Translation of BASIC versions.
<
ask "Enter lng,lat,meridian"
if it is empty then exit mouseup
Line 1,641 ⟶ 2,244:
function sgn x
if x >0 then return 1 else return -1
end sgn</
=={{header|Logo}}==
<
make "lat readword
type "|Enter longitude: |
Line 1,656 ⟶ 2,259:
make "hla arctan product sin :lat quotient sin :hra cos :hra
print (sentence "hour :hour ": :hra ", :hla)
]</
=={{header|Lua}}==
{{trans|Python}}
<
lat = tonumber(io.read())
Line 1,683 ⟶ 2,286:
hla = math.deg(math.atan(slat * math.tan(math.rad(hra))))
print(string.format("HR=%3d; HRA=%7.3f; HLA=%7.3f", h, hra, hla))
end</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
lng = Input["longitude", -150.5];
ref = Input["legal meridian", -150];
Line 1,699 ⟶ 2,302:
{h, -6, 6}
] // Prepend[{"Hour", "Sun hour angle",
"Dial hour line angle"}] // Grid</
{{out}}
<pre>Hour Sun hour angle Dial hour line angle
Line 1,715 ⟶ 2,318:
5 75.5 -18.451
6 90.5 84.2248</pre>
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">МГ П2 -> МГ П1 -> МГ sin П0
6 /-/ П3
ИП3 1 5 * ИП1 ИП2 - - П4
tg ИП0 * arctg ИП4 ИП3 С/П
ИП3 1 + П3 7 - x=0 12
Сx С/П</
''Input'': ''latitude'' ^ ''longitude'' ^ ''legal meridian'' С/П ... С/П ...; switch of the angle measure set to ''Г''.
Line 1,790 ⟶ 2,336:
{{trans|ALGOL-68}}
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<
MODULE SunDial;
Line 1,840 ⟶ 2,386:
END;
END SunDial.
</syntaxhighlight>
{{out}}
Enter latitude => -4.95
Line 1,866 ⟶ 2,412:
=={{header|newLISP}}==
{{trans|Lua}}
<
(define (radians degrees) (mul degrees (div pi 180)))
(define (degrees radians) (mul radians (div 180 pi)))
Line 1,894 ⟶ 2,440:
)
(exit)</
=={{header|Nim}}==
{{trans|Python}}
<
let lat = parseFloat readLineFromStdin "Enter latitude => "
Line 1,914 ⟶ 2,460:
let hra = float(15 * h) - lng + med
let hla = arctan(slat * tan(hra.degToRad)).radToDeg
echo &"HR={h:3d}; HRA={hra:7.3f}; HLA={hla:7.3f}"</
{{out}}
Line 1,941 ⟶ 2,487:
=={{header|Objeck}}==
{{trans|C#}}
<
class Sundial {
function : Main(args : String[]) ~ Nil {
Line 1,967 ⟶ 2,513:
}
}
</syntaxhighlight>
=={{header|OCaml}}==
{{trans|ALGOL 68}}
<
let pi = 4. *. atan 1. in
print_endline "Enter latitude => ";
Line 1,994 ⟶ 2,540:
Printf.printf "HR= %3d; \t HRA=%7.3f; \t HLA= %7.3f\n" h hra hla;
done
</syntaxhighlight>
{{out}}
<pre>
Line 2,024 ⟶ 2,570:
=={{header|Octave}}==
<
lng = input("Enter longitude: ");
ref = input("Enter legal meridian: ");
Line 2,035 ⟶ 2,581:
hlas = atand( tand(hras) .* slat );
printf("HR= %3d; \t HRA=%7.3f; \t HLA= %7.3f\n",
[ [-6:6]; hras; hlas] );</
=={{header|OoRexx}}==
{{trans|REXX}}
<
/* Use trigonometric functions provided by rxCalc */
parse arg lat lng mer . /*get the optional arguments from the CL*/
Line 2,076 ⟶ 2,622:
sep: say indent copies('-',w1) copies('-',w2) copies('-',w3)
Return
::Requires rxMath Library</
{{out}}
Not the same as for REXX anymore as the REXX computer programming example has been updated.
=={{header|Pascal}}==
<
Const
Line 2,116 ⟶ 2,662:
tab, ' HLA= ', hla:7:3)
end
end.</
=={{header|Perl}}==
{{trans|Raku}}
<
binmode STDOUT, ":utf8";
Line 2,144 ⟶ 2,690:
printf "%2d %s %8.3f %8.3f\n",
($hour + 12) % 12 || 12, ($hour < 0 ? 'AM' : 'PM'), $sun_deg, $line_deg;
}</
{{out}}
<pre>Enter latitude => -4.95
Line 2,170 ⟶ 2,716:
=={{header|Phix}}==
For better behaviour/proper input on pwa/p2js I suppose this should really be a pGUI app.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">prompt</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">text</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
Line 2,212 ⟶ 2,758:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3d:00%s %12.3f %17.3f\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">hour12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">am</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ha</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hla</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 2,241 ⟶ 2,787:
=={{header|PicoLisp}}==
{{trans|ALGOL 68}}
<
(de prompt (Str . Arg)
Line 2,266 ⟶ 2,812:
(align 8 (round Hra))
"; HLA="
(align 8 (round Hla)) ) ) ) ) ) )</
{{out}}
<pre>Enter latitude => -4.95
Line 2,291 ⟶ 2,837:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function Get-Sundial
{
Line 2,342 ⟶ 2,888:
$sundial | Select-Object -Property "Sine of Latitude", "Longitude Difference" | Format-List
$sundial.Hours | Format-Table -AutoSize
</syntaxhighlight>
{{Out}}
<pre>
Line 2,368 ⟶ 2,914:
6:00 PM 90.5 84.225
</pre>
=={{header|Python}}==
{{trans|ALGOL 68}}
<
import math
try: raw_input
Line 2,440 ⟶ 2,938:
hra -= lng - ref
hla = math.degrees(math.atan(slat * math.tan(math.radians(hra))))
print("HR=%3d; HRA=%7.3f; HLA=%7.3f" % (h, hra, hla))</
{{out}}
<pre>
Line 2,473 ⟶ 2,971:
Also, I apologize for the length; I added quite a bit of commenting, and I peeled things out into functions so I could test them. Hopefully, the result--though longer--is also more readable.
<
;; print the table for a given latitude and longitude-offset,
Line 2,550 ⟶ 3,048:
(check-= (to-hla -30 90) -90 1e-5)
(check < (to-hla -30 91) -90)
</syntaxhighlight>
{{Out}}
<pre>Welcome to DrRacket, version 5.3.3.5--2013-02-20(5eddac74/d) [3m].
Line 2,579 ⟶ 3,077:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
sub postfix:<®> ($a) { $a * 180 / pi } # radians to degrees
Line 2,597 ⟶ 3,095:
printf "%2d %s %7.3f %7.3f\n",
($hour + 12) % 12 || 12, ($hour < 0 ?? 'AM' !! 'PM'), $sun_deg, $line_deg;
}</
{{out|Example output}}
<pre>
Line 2,632 ⟶ 3,130:
No attempt was made to explain the inner workings of the trigonometric functions.
<
numeric digits length( pi() ) - length(.) /*in case sundial is in polar regions. */
parse arg lat lng . /*obtain optional arguments from the CL*/
Line 2,706 ⟶ 3,204:
m.=9; numeric form; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_ % 2
do j=0 while h>9; m.j= h; h= h % 2 + 1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g) *.5; end /*k*/; return g</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,776 ⟶ 3,274:
=={{header|Ring}}==
<
# Project : Horizontal sundial calculations
Line 2,801 ⟶ 3,299:
see "" + hour + " " + hra + " " + hla + nl
next
</syntaxhighlight>
Output:
<pre>
Line 2,826 ⟶ 3,324:
{{trans|ALGOL 68}}
{{trans|Python}}
<
DtoR = PI/180
Line 2,848 ⟶ 3,346:
hla = atan( slat * tan( hra * DtoR ))/ DtoR
puts "HR =%3d; HRA =%7.3f; HLA =%7.3f" % [h, hra, hla]
end</
{{out}}
<pre>
Line 2,873 ⟶ 3,371:
HR = 6; HRA = 90.500; HLA = 84.225
</pre>
=={{header|Rust}}==
<
use std::io;
struct SundialCalculation {
Line 2,977 ⟶ 3,424:
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,005 ⟶ 3,452:
=={{header|Sather}}==
<
getvalue(s:STR):FLT is
Line 3,036 ⟶ 3,483:
end;
end;
end;</
=={{header|Scala}}==
<
import scala.math.{atan2, cos, sin, toDegrees, toRadians}
Line 3,065 ⟶ 3,512:
}
}</
=={{header|Seed7}}==
<
include "float.s7i";
include "math.s7i";
Line 3,104 ⟶ 3,551:
"; HLA= " <& hla digits 3 lpad 7);
end for;
end func;</
{{out}}
<pre>Enter latitude: -4.95
Line 3,130 ⟶ 3,577:
=={{header|Sidef}}==
{{trans|Raku}}
<
var longitude = read('Enter longitude => ', Number)
var meridian = read('Enter legal meridian => ', Number)
Line 3,152 ⟶ 3,599:
printf("%2d %s %7.3f %7.3f\n",
(hour + 12) % 12 || 12, (hour < 0 ? 'AM' : 'PM'), sun_deg, line_deg)
}</
{{out}}
<pre>
Line 3,179 ⟶ 3,626:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<
pi := 1 arcTan * 4.
'Enter latitude: ' display. lat := stdin nextLine asNumber.
Line 3,195 ⟶ 3,642:
hla := (hra degreesToRadians tan * slat) arcTan radiansToDegrees.
('HR= %1; %4 HRA=%2; %4 HLA= %3' % { h. hra. hla. $<9> }) displayNl.
]</
=={{header|Tcl}}==
{{trans|ALGOL 68}}
<
fconfigure stdout -buffering none
puts -nonewline "Enter latitude => "; gets stdin lat
Line 3,217 ⟶ 3,664:
set hla [expr {atan($slat * tan($hra*$PI/180)) * 180/$PI}]
puts [format "HR=%+3d; HRA=%+8.3f; HLA=%+8.3f" $h $hra $hla]
}</
{{out|Sample output}}
<pre>
Line 3,246 ⟶ 3,693:
{{trans|Go}}
{{libheader|Wren-fmt}}
<
import "./fmt" for Fmt
var getNum = Fn.new { |prompt|
Line 3,274 ⟶ 3,721:
var hla = (slat*s).atan(c) * 180 / Num.pi
Fmt.print("$2.0f $8.3f $8.3f", h, hra, hla)
}</
{{out}}
Line 3,305 ⟶ 3,752:
{{libheader|libc}}
It must be linked with the C standard library and startup code.
<
extern printf, scanf
Line 3,441 ⟶ 3,888:
o_ft:
db "HR= %3d; ",9," HRA=%7.3f; ",9," HLA= %7.3f", 10, 0</
=={{header|XPL0}}==
<
def Pi = 3.14159265358979323846,
Deg2Rad = Pi/180.0,
Line 3,526 ⟶ 3,916:
RlOut(0, HA); ChOut(0, Tab); RlOut(0, HLA); CrLf(0);
];
]</
{{out}}
Line 3,552 ⟶ 3,942:
=={{header|zkl}}==
{{trans|F#}}
<
//(radian measure)/Degrees => Degree measure
const pi=(0.0).pi, toDeg=(0.0).pi/180;
Line 3,574 ⟶ 3,964:
dhla :=(sineLatitude*(shr*toDeg).tan()).atan()/toDeg;
Console.writeln("%s\t\t%5.1f\t\t%+7.3f".fmt(clockHour,shr,dhla));
}</
{{out}}
<pre>
Line 3,604 ⟶ 3,994:
<as above>
</pre>
|