Program Sunday; {Jarmo Lammi 13.1.94 Sunrise and Sunset timest} USES CRT,DOS; CONST tz = 2; wocht: array[0..6] of string = ('Sunday','Monday', 'Tuesday','Wednesday','Thursday','Friday','Saturday'); DayTime: Array[0..3] of String = ('Morning','Day','Evening','Night'); VAR dgr: CHAR; vv,kk,pp,vd: WORD; hr,mn,sc,tc: Word; inlat,inlon,tzone: Real; FUNCTION TAN(x:real):real; BEGIN TAN:=SIN(x)/COS(x) END; FUNCTION hhmm(h:real):string; {Converting decimal hours HH.HH to string HH:MM} VAR frac: REAL; hr,mn: INTEGER; hrs,mns: STRING[2]; BEGIN hr:=TRUNC(h) ; frac:=h-hr; mn:=TRUNC(60*frac+0.5); STR(hr,hrs) ; IF hr<10 THEN hrs:='0'+hrs; STR(mn,mns) ; IF mn<10 THEN mns:='0'+mns; hhmm:=hrs+':'+mns; END; {hhmm} PROCEDURE SunUpDown(lat:real;lon:real); {Sunrise and Sunset times} CONST DayOffs = 10.0; HoCor = 0.033; MDays: array[1..12] of Integer = (31,28,31,30,31,30,31,31,30,31,30,12); VAR dekl,fo,Nousu,Lasku:real; DayNr,j: Integer; BEGIN lon:=-lon; lat:=pi*lat/180; DayNr:=0; for j:= 1 to kk-1 do DayNr:=DayNr+MDays[j]; DayNr:= DayNr+pp; dekl:=-23.5*COS(pi/180*(DayOffs+0.988*DayNr)); fo:=TAN(pi/180*dekl)*TAN(lat-HoCor); IF fo>1 THEN Writeln('Sun will not set today !'); IF fo<-1 THEN Writeln('Sun will not rise today!'); fo:=pi/2-ARCTAN(fo/SQRT(1-fo*fo)); fo:=fo/(pi/180); Nousu:=(lon/15)+(fo/15)+tzone; IF Nousu>24 THEN Nousu:=Nousu-24; IF Nousu<0 THEN Nousu:=Nousu+24; Lasku:=(lon/15)-(fo/15)+tzone; IF Lasku>24 THEN Lasku:=Lasku-24; IF Lasku<0 THEN Lasku:=Lasku+24; GoToXY(15,7); Write('Sunrise: ',hhmm(Nousu)); GoToXY(15,8); Write('Sunset: ',hhmm(Lasku)); GoToXY(15,10); Write('Day number: ',DayNr); End; {SunUpDown} Procedure TellCoord(lat:Real; Lon:Real); Begin GoToXY(15,4); Write('Latitude: ',lat:6:2,dgr); GoToXY(15, 5); Write('Longitude: ',lon:6:2,dgr); SunUpDown(lat,lon); END; {TellCoord} Procedure Kehys; VAR j: Word; Begin ClrScr; Write(#201); For j:= 2 to 40 do Write(#205); Write(#187); GoToXY(1,15); Write(#200); For j:= 2 to 40 do Write(#205); Write(#188); End; Begin {MAIN} dgr:=CHR(248); {degree character} TextBackGround(Blue); TextColor(White); ClrScr; write('Input Latitude [S -90 ... 0 ... +90 N ] '); readln(inlat); write('Input longitude [W -180 ... 0 ... +180 E ] '); readln(inlon); write('Input timezone [ -12 h ... GMT 0 ... +12 h] '); readln(tzone); ClrScr; Window(10,5,51,19); TextBackGround(White); TextColor(Black); ClrScr; Kehys; GetDate(VV,KK,PP,VD); TellCoord(inlat,inlon); GoToXY(15,11); Write('Date: ',pp,'.',kk,'. ',vv); GoToXY(15,12); Write(wocht[vd]); GetTime(hr,mn,sc,tc); GoToXY(15,2); Write('Good ',DayTime[hr div 6],' !'); GoToXY(15,14); Write('Time ',hr,':',mn,':',sc); End.