source: trunk/MagicSoft/slalib/cldj.c@ 7489

Last change on this file since 7489 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#include "slalib.h"
2#include "slamac.h"
3void slaCldj ( int iy, int im, int id, double *djm, int *j )
4/*
5** - - - - - - - -
6** s l a C l d j
7** - - - - - - - -
8**
9** Gregorian calendar to Modified Julian Date.
10**
11** Given:
12** iy,im,id int year, month, day in Gregorian calendar
13**
14** Returned:
15** *djm double Modified Julian Date (JD-2400000.5) for 0 hrs
16** *j int status:
17** 0 = OK
18** 1 = bad year (MJD not computed)
19** 2 = bad month (MJD not computed)
20** 3 = bad day (MJD computed)
21**
22** The year must be -4699 (i.e. 4700BC) or later.
23**
24** The algorithm is derived from that of Hatcher 1984 (QJRAS 25, 53-55).
25**
26** Last revision: 29 August 1994
27**
28** Copyright P.T.Wallace. All rights reserved.
29*/
30{
31 long iyL, imL;
32
33/* Month lengths in days */
34 static int mtab[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
35
36
37
38/* Validate year */
39 if ( iy < -4699 ) { *j = 1; return; }
40
41/* Validate month */
42 if ( ( im < 1 ) || ( im > 12 ) ) { *j = 2; return; }
43
44/* Allow for leap year */
45 mtab[1] = ( ( ( iy % 4 ) == 0 ) &&
46 ( ( ( iy % 100 ) != 0 ) || ( ( iy % 400 ) == 0 ) ) ) ?
47 29 : 28;
48
49/* Validate day */
50 *j = ( id < 1 || id > mtab[im-1] ) ? 3 : 0;
51
52/* Lengthen year and month numbers to avoid overflow */
53 iyL = (long) iy;
54 imL = (long) im;
55
56/* Perform the conversion */
57 *djm = (double)
58 ( ( 1461L * ( iyL - ( 12L - imL ) / 10L + 4712L ) ) / 4L
59 + ( 306L * ( ( imL + 9L ) % 12L ) + 5L ) / 10L
60 - ( 3L * ( ( iyL - ( 12L - imL ) / 10L + 4900L ) / 100L ) ) / 4L
61 + (long) id - 2399904L );
62}
Note: See TracBrowser for help on using the repository browser.