PROCEDURE caldat(julian: real; VAR mm,id,iyyy: integer);
CONST
   igreg: real=2299161.;
VAR
   je,jd,jc,jb,jalpha,ja: real;
BEGIN
   IF (julian >= igreg) THEN BEGIN
      jalpha := rtrunc(((julian-1867216.0)-0.25)/36524.25);
      ja := julian+1.+jalpha-trunc(0.25*jalpha)
   END ELSE BEGIN
      ja := julian
   END;
   jb := ja+1524.;
   jc := trunc(6680.0+((jb-2439870.0)-122.1)/365.25);
   jd := 365.*jc+trunc(0.25*jc);
   je := trunc((jb-jd)/30.6001);
   id := trunc(jb-jd-trunc(30.6001*je));
   mm := trunc(je)-1;
   IF (mm > 12) THEN mm := mm-12;
   iyyy := trunc(jc)-4715;
   IF (mm > 2) THEN iyyy := iyyy-1;
   IF (iyyy <= 0) THEN iyyy := iyyy-1
END;
