 {~ Julian date, sidereal time, position of the Sun ~}

  { Has to be converted to the appropriate code page;
   the original one is 'Kamenicky'
  -- this is just because of a character denoting a degree}

PROGRAM SUN;
    {adapted by Jan Hollan from Tomas Rezek's program SUN_BY_NAKED_EYES;}
(*  Copyright (C) 1999 Jan Hollan

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)

uses dos,
     str_num,angles_o,Solar_ut,planets,params;
VAR
 T,LambS,aux_r: REAL; aux_s:string;
 j:byte;

procedure Help;
begin
 WRITE(cl,
 'Program from Tomas Rezek and Jan Hollan, Obs. and Planetarium in Brno, 1999,',cl,
 ' (subject to the GNU General Public License, http://www.gnu.org/copyleft , ',cl,
 '  source code available at http://astro.sci.muni.cz/pub/hollan/programmes)'+cl2,

 'computes the position of the Sun:',cl2,

 'Sun dDD[.MM[.YYYY]] tHH[:MM[:SS] UT# l<longitude> f<latitude>',cl2,

 'D and T: initial values are taken from the system date and time,',cl,
 'UT is the t-UTC difference / 1 h (default 1 from Nov. to March, else 2)'+cl+
 'longitude and latitude (/ 1 degree) are initially those of '
  +MyLocation_Name+'.',cl);
 halt
end;

BEGIN
if paramcount>0 then for j:= 1 to paramcount do
 begin
  Par:=paramstr(j);
  if Par[1] in ['/','-'] then Par:=copy(Par,2,length(par)-1);
  case UpCase(Par[1]) of
   '?'     : Help;
   'D' : if not Par_date then help;
   'T' : if not Par_time_or_TT then help;
   'U' : if not Par_UT then help;
   'L' : if not Par_Lambda then help;
   'F' : if not Par_Fi then help;
  end; {of case}
 end; {of for}

Get_JD;
if not tt_UT_set then tt_ut:=tt_UTC_in_days(JD);
Planet_hel(3,jd+tt_UT,LambS,T,aux_r,aux_s);
LambS:=bas_int(LambS+180,360);
  {LambS:=Sun_long(JD);} {this had rather low precision}
Ecl_to_Equ(LambS,RA,Decl);
T:=Bas_int(SM-(RA/15),24);
A_h_PA(SM,RA,Decl, A,h,PA,Air_mass);

if tt_UT>0.001 then
 writeln('Terrestric Time - UT assumed : ',tt_UT*24:6:2,' h',cl);
write(cl,
'On Julian date ',JD:13:4, ', or',cl,
yyyy,'-',mm:2,'-',nd:2,'  at ',h_min_s(UT),', expressed in the UTC, or',cl);

Par:=DoW(JD,t_UT,_English);
write(
yyyy,'-',mm:2,'-',nd:2,'  at ',h_min_s(Bas_Int(UT+t_UT,24)),
                                                 '  (',Par,'),',cl,
' expressed in the used time, which is ',t_UT:4:1,' h ahead of th UTC:',cl2,

'At Longitude ',rad_to_deg(Lambda):6:3,'°  and Latitude ',
                rad_to_deg(Fi):6:3,'°',cl2,

'is the Local sidereal time ',h_min_s(sm),cl2,

'and the position of the Sun would be (not considering refraction):',cl2,

'longitude         : ',LambS:5:1,'° = ',LambS/15:5:2,' h',  cl,
'Right Asc.        : ',RA:5:1,'° = ',RA/15:5:2,' h = ',h_min_s(RA/15), cl,
'Declination       : ',Decl:5:1,'° =',deg_to_dm(Decl),      cl,
'Hour angle        : ',T*15:5:1,'° = ',T:5:2,' h = ',h_min_s(T), cl,
'Angular height    : ',h:5:1,'°', cl,
'Azimuth from South: ',A:5:1,'° ( = ',Bas_Int(A+180,360):5:1,'° from North)', cl,
'Zenith-Sun-N.Pole : ',PA:3:0,'. °',cl);

if Air_mass>0 then writeln(
'Air mass (1/sin h): ',Air_mass:7:2);

END.
