PROGRAM Julian (Input,Output);

(* David Wills
   CMIS 102
   Term 4  SHAPE
   Class example
   Turbo Pascal 5.5 *)

(* This program prompts the user for the month, day and year
   and computes the Julian day of the year.  Leap years are
   accounted for.  *)

VAR
   Month,               (* Month input by user, 1..12 *)
   Day,                 (* Day input by user, 1..31 *)
   Year : Integer;      (* Year input by user *)
   JDay : Integer;      (* Computed Julian day *)

BEGIN
   Writeln('This program will convert a month and day to the day of the ');
   Writeln('year (the Julian day).');
   Writeln('Enter the month as an integer from 1 to 12');
   Readln(Month);
   Writeln('Enter the day of the month');
   Readln(Day);
   Writeln('Enter the year');
   Readln(Year);

   (* Add all days in previous months to day of month *)
   IF (Month >= 1) AND (Month <= 12) THEN
     BEGIN
      IF Month = 1 THEN
         Jday := Day
      ELSE IF Month = 2 THEN
         Jday := 31 + Day
      ELSE IF Month = 3 THEN
         Jday := 59 + Day
      ELSE IF Month = 4 THEN
         Jday := 90 + Day
      ELSE IF Month = 5 THEN
         Jday := 120 + Day
      ELSE IF Month = 6 THEN
         Jday := 151 + Day
      ELSE IF Month = 7 THEN
         Jday := 181 + Day
      ELSE IF Month = 8 THEN
         Jday := 212 + Day
      ELSE IF Month = 9 THEN
         Jday := 243 + Day
      ELSE IF Month = 10 THEN
         Jday := 273 + Day
      ELSE IF Month = 11 THEN
         Jday := 304 + Day
      ELSE IF Month = 12 THEN
         Jday := 334 + Day;
      IF (Year MOD 4) = 0 THEN   (* If leap year *)
         IF Month >= 3 THEN      (* If after February *)
            JDay := JDay + 1;    (* add one day for 29 Feb *)
      Writeln('Julian day is ',JDay);
     END
   ELSE
      Writeln('Illegal month.  Must be from 1 to 12');

END.

