home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG039.ARC
/
SUNCALC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
4KB
|
109 lines
(**from Colin Mc Carthy date 17/11/84
The following program written in Turbo Pascal
calculates sunrise and sunset for any longitude
and latitude. Although not elegent, it seems to
work ok. Please note negative argument for east
longitude, south latitude, east timezone.**)
(* Program to find sunrise & sunset for any lat. long.
Modified from D. Rapson's Sbasic program Day.bas
This version written in Turbo Pascal by C.McCarthy 18 Oct 1984
Accuracy +/- 10 min. from 1752 UK. 1610 Europe. *)
var factor,fa,day,daysaving,date,month,lat,long,timezone:real;
s,x,c,cons,t,ds,et,br,bs,gmt1,gmt2,rise,riset,sets,sett:real;
d,m,y,weekday:integer;
start,error:boolean;
more,dsaving:char;
function tan(angle:real):real;
begin
tan:=sin(angle)/cos(angle);
end;
begin
start:=true;
while start do begin
error:=true;
while error do
begin
clrscr;
writeln('---------- Sunrise and Sunset ----------':61);
writeln('(Not valid prior to 1610)':54);writeln;
write('Day: ');read(d);write(' Month: ');read(m);
write(' Year: ');readln(y);
error:=false;
if (d>31) or (m>12) or (y<1610) then error:=true;
end;
write('Daylight saving? (Y/N) ');
repeat read(kbd,dsaving) until upcase(dsaving) in ['Y','N'];
writeln(dsaving);
if upcase(dsaving)='Y' then daysaving:=1 else daysaving:=0;
writeln;
writeln('Enter -DD.MM for east longitude, south latitude, east timezone');
write('Longitude: ');readln(long);
write('Latitude: ');readln(lat);
write('Timezone: ');readln(timezone);
if lat=90 then lat:=89.99;
if lat=-90 then lat:=-89.99;
if (m=1) or (m=2) then
factor:=365.0*y+d+31*(m-1)+int((y-1)/4)-int(0.75*int((y/100)+1))
else
factor:=365.0*y+d+31*(m-1)-int(0.4*m+2.3)+int(y/4)-int(0.75*int((y/100)+1));
fa:=int(-factor/7);
day:=factor+(fa*7);
weekday:=trunc(day);è writeln;
case weekday of
0:write('Saturday');
1:write('Sunday');
2:write('Monday');
3:write('Tuesday');
4:write('Wednesday');
5:write('Thursday');
6:write('Friday');
end;
write(' ',d,' ');
case m of
1:write('January');
2:write('February');
3:write('March');
4:write('April');
5:write('May');
6:write('June');
7:write('July');
8:write('August');
9:write('September');
10:write('October');
11:write('November');
12:write('December');
end;
writeln(' ',y);
date:=int(d);
month:=int(m);
c:=0.0174532925;
t:=0.988*(date+30.3*(month-1));
ds:=23.5*(cos((t+10)*c));
et:=0.123*(cos((t+87)*c))-(sin(2*(t+10)*c))/6;
x:=tan(ds*c)*tan(lat*c);
s:=sqr(x);
cons:=(1.5708-(x*(1+s/2*(1/3+3/4*s*(1/5+5/6*s*(1/7+7/8*s*(1/9+0.9*s/11)))))))/c;
gmt1:=12-et+(long-cons)/15;
gmt2:=12-et+(long+cons)/15;
rise:=gmt1-timezone-0.05;
sets:=gmt2-timezone+0.05;
br:=(rise-int(rise))*60/100-0.005;
bs:=(sets-int(sets))*60/100-0.005;
riset:=int(rise)+br+daysaving;
sett:=int(sets)+bs+daysaving;
writeln;
if sett>23.59 then writeln('Sun does not set.')
else if riset>sett then writeln('Sun does not rise.')
else
begin
writeln('Sunrise ',riset:11:2);
writeln('Sunset ',sett:11:2);
end;
writeln;writeln;
write('More? (Y/N) ');
repeat read(kbd,more) until upcase(more) in ['Y','N'];
writeln(more);
if upcase(more)='N' then start:=false;
end;(* start *)
end.