How to resolve the algorithm Horizontal sundial calculations step by step in the Fortran programming language
How to resolve the algorithm Horizontal sundial calculations step by step in the Fortran programming language
Table of Contents
Problem Statement
Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.
For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), with a legal meridian of 150°W. (Note: the "meridian" is approximately the same concept as the "longitude" - the distinction is that the meridian is used to determine when it is "noon" for official purposes. This will typically be slightly different from when the sun appears at its highest location, because of the structure of time zones. For most, but not all, time zones (hour wide zones with hour zero centred on Greenwich), the legal meridian will be an even multiple of 15 degrees.) Wikipedia: A sundial is a device that measures time by the position of the Sun. In common designs such as the horizontal sundial, the sun casts a shadow from its style (also called its Gnomon, a thin rod or a sharp, straight edge) onto a flat surface marked with lines indicating the hours of the day (also called the dial face or dial plate). As the sun moves across the sky, the shadow-edge progressively aligns with different hour-lines on the plate. Such designs rely on the style being aligned with the axis of the Earth's rotation. Hence, if such a sundial is to tell the correct time, the style must point towards true north (not the north or south magnetic pole) and the style's angle with horizontal must equal the sundial's geographical latitude.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Horizontal sundial calculations step by step in the Fortran programming language
Source code in the fortran programming language
program SunDial
real :: lat, slat, lng, ref
real :: hra, hla
integer :: h
real, parameter :: pi = 3.14159265358979323846
print *, "Enter latitude"
read *, lat
print *, "Enter longitude"
read *, lng
print *, "Enter legal meridian"
read *, ref
print *
slat = sin(dr(lat))
write(*, '(A,1F6.3)') "sine of latitude: ", slat
write(*, '(A,1F6.3)') "diff longitude: ", lng - ref
print *, "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
do h = -6, 6
hra = 15.0*h
hra = hra - lng + ref
hla = rd( atan( slat * tan( dr(hra) ) ) )
write(*, '(" HR= ",I3,"; \t HRA=",F7.3,"; \t HLA= ", F7.3)'), h, hra, hla
end do
contains
function dr(angle)
real :: dr
real, intent(in) :: angle
dr = angle*pi/180.0
end function dr
function rd(angle)
real :: rd
real, intent(in) :: angle
rd = angle*180.0/pi
end function rd
end program SunDial
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the Prolog programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the jq programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the Delphi programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the Groovy programming language
You may also check:How to resolve the algorithm Doubly-linked list/Definition step by step in the Raku programming language