< previous page page_188 next page >

Page 188
(continued)
Listing 7.4
#include <math.h>
#include "scdtl_6.h"


struct DATE_INFO JD0_to_gregorian_proleptic (double jd)
{
   struct DATE_INFO date;
   double x, n, it;
   double d, m, y;
   x = floor (jd + 0.5) + 68569L;
   n = floor (4 * x / 146097L);
   x = x - floor ( (146097L * n + 3) / 4);
   it = floor (4000 * (x + 1) / 1461001L);
   x = x - floor (1461 * it / 4) + 31;
   m = floor (80 * x / 2447);
   d = x - floor (2447 * m / 80);
   x = floor (m / 11);
   m = m + 2 - 12 * x;
   y = 100 * (n - 49) + it + x;


   date.year = (int) y;
   date.month = (int) m;
   date.day = (int) d;


   return (date);
}

Listing 7.5 julian_to_gregorian ()
/* jul2greg.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |         All rights reserved.              |
   +-------------------------------------------+


   Routine converts a proleptic Julian calendar date into the
   corresponding proleptic Gregorian calendar date.


   INPUTS:
   1. jdate, pointer to a DATE_INFO structure, containing the Julian
      proleptic date to be converted.


   OUTPUTS:


   1. Returned by routine, a DATE_INFO structure, containing the
      Gregorian proleptic date corresponding to the input Julian date.


   NOTES:


   1. This routine can be used to convert proleptic Julian dates into
      their correct Gregorian dates. It may also be used to convert
      correct Julian dates into proleptic Gregorian dates.


 
< previous page page_188 next page >