< previous page page_186 next page >

Page 186
7.4
gregorian_proleptic_to_JD0 ()
The routine grep2JD0.c (Listing 7.3) converts a Gregorian proleptic calendar date to the corresponding Julian Day number.
Listing 7.3 gregorian_proleptic_to_JD0 ()
/* grep2JD0.c


   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+


   Routine converts a Gregorian proleptic calendar date to the
   corresponding Julian Day number.


   INPUTS:
   1. date, pointer to a DATE_INFO structure, containing the Gregorian
      date to be converted to a Julian Day number.


   OUTPUTS:
   1. Returned by routine, type double, the Julian Day number
      corresponding to the input Gregorian date.


      NOTES:
   1. This routine is similar to the 'forward' algorithm presented
      in CACM, v11, n 10. p657, "A Machine Algorithm for Processing
      Calendar Dates", by Henry F. Fliegel and Thomas C. Van Flandern.


   2. This routine does not validate the inputs. To validate Gregorian
      dates, use the routine in this series, 'valid_date_gregorian ()'.
*/


#include "scdtl_6.h"


double gregorian_proleptic_to_JD0 (struct DATE_INFO *gdate)
{
   double jd;
   long y, m, d, yp, mi, jdl;


   y = (long) gdate->year;
   m = (long) gdate->month;
   d = (long) gdate->day;


   yp = (y + 4800L);
   mi = ((m - 14L) / 12L);


   jdl = (d - 32075L);
   jdl += 1461L * (yp + mi) / 4L;
   jdl += 367L * (m - 2L - (mi * 12L)) / 12L;
   jdl -= 3L * ((yp + 100L + mi) / 100L) / 4L;


   jd = (double) jdl;


   return (jd);
}

 
< previous page page_186 next page >