💾 Archived View for mirrors.apple2.org.za › archive › ground.icaen.uiowa.edu › Srcs › sunrise.txt captured on 2024-06-16 at 14:28:04.

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

{
DISCLAIMER

Copyright (C) 1997 by Adrian Philip Whichello. All rights reserved.

I, Adrian Philip Whichello, MAKE NO WARRANTY ON THIS SOFTWARE, EITHER EXPRESS
OR IMPLIED, WITH RESPECT TO QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR
A PARTICULAR PURPOSE.

IN NO EVENT WILL I BE HELD RESPONSIBLE FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OF THE SOFTWARE.

I RELEASE THIS PROGRAM AS FREEWARE. YOU MAY COPY, GIVE AWAY AND USE THIS
PROGRAM, PROVIDED THIS NOTICE REMAINS ATTACHED AT ALL TIMES.

}

program sunrise_sunset;
uses transcend, rtclock;
const
  deg_to_rad = 1.74532925E-02;
  local_time = 10.0; { replace these with the appropriate (real) numbers }
  summer_time = 0.0; { for your time zone }
  local_str = 'EST';
  def_lat = -33.7166666;  { 33 43'S }
  def_long = 150.45;     { 150 27'E  Hazelbrook, NSW }
var
  slot, today, month, hr, min, d, m : integer;
  defaults : boolean;
  lat, long, sunrise, sunset, alpha, Et, ds, t : real;
  zero : array [boolean] of string[1];
  numtim : numtim_array;
  
function cosd(deg : real) : real;
begin
  cosd := cos(deg * deg_to_rad)
end;

function sind(deg : real) : real;
begin
  sind := sin(deg * deg_to_rad)
end;
  
function tand(deg : real) : real;
begin
  tand := sind(deg) / cosd(deg)
end;

function acosd(x : real) : real;
begin
  acosd := 114.591559 * atan(sqrt((1.0 - x) / (1.0 + x)))
end;

procedure convert(time : real;
                  var hr, min : integer);
begin
  hr := trunc(time);  min := round(60.0 * (time - hr));
  if min >= 60 then begin
    hr := hr + min div 60;
    min := min mod 60
  end
end;

procedure skipblanks(var f : interactive);
begin
  repeat
    get(f)
  until eoln or (f^ <> ' ')
end;

begin
  zero[false] := '';
  zero[true] := '0';
  if CPS_found(slot) then begin
    get_time(slot, numtim);
    today := 10 * numtim[dayhi] + numtim[daylo];
    month := 10 * numtim[mnhi] + numtim[mnlo]
  end;
  while not eof do begin
    write('Enter latitude, longitude, day and month --> ');
    get(input);  defaults := eoln;
    if not defaults then readln(lat, long, d, m) else begin
      lat := def_lat;
      long := def_long;
      d := today;
      m := month
    end;
    if not eof then begin
      t := 0.988 * (30.3 * (m - 1) + d);
      Et := 0.123 * cosd(t + 87.0) - 0.16666666 * sind(2.0 * t + 20.0);
      ds := 23.5 * cosd(t + 10.0);
      alpha := acosd(tand(ds) * tand(lat));
      sunrise := local_time + summer_time
                   + 12.0 - Et - 6.6666666E-02 * (long + alpha);
      convert(sunrise, hr, min);
      if defaults then
        writeln('Lat ', lat:1:2, ', Long ', long:1:2, ', Date ', d:1, '/', m:1);
      writeln('sunrise ', local_str, ' at ', hr:1, ':', zero[min < 10], min:1);
      sunset := local_time + summer_time
                  + 12.0 - Et + 6.6666666E-02 * (alpha - long);
      convert(0.5 * (sunrise + sunset), hr, min);
      writeln('sunnoon ', local_str, ' at ', hr:1, ':', zero[min < 10], min:1);
      convert(sunset, hr, min);
      writeln('sunset ', local_str, ' at ', hr:1, ':', zero[min < 10], min:1);
      convert(sunset - sunrise, hr, min);
      writeln('daylight time ', hr:1, 'h', min:1, 'm')
    end
  end
end.