program praezession;

const
   {$I b:math_con }

type
   ZEIT = record
             stunde:0..23;
             minute,sekunde:0..59;
          end;

   DATUM = record
              jahr:integer;
              monat:1..12;
              tag:1..31;
           end;

   JUL = record
            ganz:long_integer;
            fract:real;
         end;

var raa,ran:ZEIT;
    raa1,ran1,dea,den:real;
    jdalt,jdneu:JUL;
    c:char;

   {$I b:math_sub }

procedure juldat(var julian:JUL; gregorian:DATUM; uhrzeit:ZEIT;
                 flag:boolean);
external;

procedure praezession(var ran,den:real; raa,dea:real; equi,dat:JUL);
external;

procedure nutation(var ran,den:real; raa,dea:real; dat:JUL);
external;

procedure equinox(var jd:JUL);
var date:DATUM;
    lokal:ZEIT;
    c:char;
    flag:boolean;
begin
   write('> Year : '); readln(date.jahr);
   write('> Month: '); readln(date.monat);
   write('> Day  : '); readln(date.tag);
   write('> Greg. calendar (y/n): '); read(c); writeln;
   if c = 'n' then flag := false else flag := true;
   lokal.stunde := 0;
   lokal.minute := 0;
   lokal.sekunde := 0;
   juldat(jd,date,lokal,flag)
end;

procedure time(var t:ZEIT; t1:real);
var f:real;
begin
   f := deg(t1) / 15.0;
   t.stunde := trunc(f); f := (f - t.stunde) * 60.0;
   t.minute := trunc(f); f := (f - t.minute) * 60.0;
   t.sekunde := trunc(f);
end;

begin
   write(chr(27),'E');
   writeln('< CORRECT COORDINATES AGAINST PRECISION >');
   writeln;
   writeln('  Enter equinox of old coordinates:');
   equinox(jdalt);
   writeln('  Enter old mean coordinates:');
   write('> Right ascension: hour  : '); readln(raa.stunde);
   write('>                  minute: '); readln(raa.minute);
   write('>                  second: '); readln(raa.sekunde);
   write('> Declination            : '); readln(dea);
   raa1 := 15.0 * (raa.stunde + raa.minute / 60.0 + raa.sekunde / 3600.0);
   raa1 := rad(raa1); dea := rad(dea);
   write(chr(27),'E');
   writeln('< CORRECT COORDINATES AGAINST PRECISION >');
   writeln;
   writeln('  Enter equinox of new coordinates:');
   equinox(jdneu); writeln;
   praezession(ran1,den,raa1,dea,jdalt,jdneu);
   time(ran,ran1);
   writeln('  New mean coordinates:');
   writeln('  Right ascension: ',ran.stunde:2,ran.minute:3,ran.sekunde:3);
   writeln('  Declination    : ',deg(den):10:5);
   writeln;
   raa1 := ran1; dea := den;
   nutation(ran1,den,raa1,dea,jdneu);
   time(ran,ran1);
   writeln('  New true coordinates:');
   writeln('  Right ascension: ',ran.stunde:2,ran.minute:3,ran.sekunde:3);
   writeln('  Declination    : ',deg(den):10:5);
   writeln;
   read(c)
end.
