< previous page page_182 next page >

Page 182
7.2
julian_proleptic_to_JD0 ()
The routine julp2JD0.c (Listing 7.1) converts a Julian proleptic calendar date into the corresponding Julian Day number, expressed as a type double.
(continued)
Listing 7.1
/*
   'tab2' contains the number of elapsed days prior to each month in a
   common Julian year. If the year is a leap year, the table is
   incremented for indices > 1 (i.e., February and after).
*/


   int tab2 [12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
   long jdl;


   y = jdate->year;
   m = jdate->month;
   d = jdate->day;


/* Intercept obviously invalid date values */


   if ( (y < -4712) || (m < 1) || (m > 12) || (d < 1) || (d > 31) )
      return (0.0);


/* Start with year -4712 for Julian Day number. */


   y0 = y + 4712;


/*
   'g4' is the number of complete groups of 4 years, each consisting of
   1461 days. 'r4' is the remainder, and contains the number of complete
   years (0, 1, 2 or 3) elapsed, in addition to the 4-year groups.
*/


   g4 = y0 / 4;
   r4 = y0 - (g4 * 4);
   jdl = 1461L * (long) g4;
   jdl += (long) (tab1 [r4]);


/* Increments the table for leap year. */


   if ( (y % 4) == 0)
      {
      for (i = 2; i < 12; i++)
          tab2 [i]++;
      }


   jdl += (long) (tab2 [m - 1]);
   jdl += (long) (d - 1);
   jd = (double) jdl;


   return (jd);
}


 
< previous page page_182 next page >