  FUNCTION drdate(d : dateln) : integer;
  (* 1 Jan 1978 <--> drd = 1. Assumes valid d *)

    VAR
      dayspermonth : ARRAY[1..12] OF 1..31;
      year, month, day, i  : integer;

    BEGIN (* drdate *)
    FOR month := 1 TO 12 DO dayspermonth[month] := 31;
    dayspermonth[2] := 28; dayspermonth[4] := 30;
    dayspermonth[6] := 30; dayspermonth[9] := 30;
    dayspermonth[11] := 30;
    year  := 10 * (ord(d[1])-ord('0')) + ord(d[2])-ord('0');
    month := 10 * (ord(d[4])-ord('0')) + ord(d[5])-ord('0');
    day   := 10 * (ord(d[7])-ord('0')) + ord(d[8])-ord('0');
    IF year < 66 THEN year := year + 100;
    IF (year < 78) OR (month = 0) OR (day = 0) THEN drdate := 0
    ELSE BEGIN
      year := (year - 76); i := year DIV 4; year := year MOD 4;
      day := day - 731 (* from 1 Jan 1976, -1 *) + 1461 * i;
      IF (year > 0) OR (month > 2) THEN day := day+1;
      day := day + 365 * year;
      FOR i := 1 TO month-1 DO day := day + dayspermonth[i];
      drdate := day; END
    END; (* drdate *)

  (* 1-----------------1 *)

)C