MISR Toolkit  1.5.1
MtkCalToJulian.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkCalToJulian =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrUtil.h"
18 #include "MisrError.h"
19 #include <math.h>
20 #include <string.h>
21 #include <stdio.h>
22 
23 /* LEAP_GREGORIAN -- Is a given year in the Gregorian calendar a leap year ? */
24 
25 static int leap_gregorian(int year)
26 {
27  return ((year % 4) == 0) &&
28  (!(((year % 100) == 0) && ((year % 400) != 0)));
29 }
30 
31 /* GREGORIAN_TO_JD -- Determine Julian day number from Gregorian calendar date */
32 
33 #define GREGORIAN_EPOCH 1721425.5
34 
35 static double gregorian_to_jd(int year, int month, int day)
36 {
37  return (GREGORIAN_EPOCH - 1.0) +
38  (365.0 * (year - 1.0)) +
39  floor((year - 1.0) / 4.0) +
40  (-floor((year - 1.0) / 100.0)) +
41  floor((year - 1.0) / 400.0) +
42  floor((((367.0 * month) - 362.0) / 12.0) +
43  ((month <= 2) ? 0 :
44  (leap_gregorian(year) ? -1 : -2)
45  ) +
46  day);
47 }
48 
62  int year,
63  int month,
64  int day,
65  int hour,
66  int min,
67  int sec,
68  double *jd )
69 {
70  MTKt_status status_code; /* Return code of this function */
71 
72  if (jd == NULL)
74 
75  if (year == 0 || month <= 0 || day <= 0 || hour < 0 || min < 0 || sec < 0)
77 
78  *jd = gregorian_to_jd(year, month, day) +
79  (floor(sec + 60 * (min + 60 * hour) + 0.5) / 86400.0);
80 
81  return MTK_SUCCESS;
82 
83 ERROR_HANDLE:
84  return status_code;
85 }
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_status MtkCalToJulian(int year, int month, int day, int hour, int min, int sec, double *jd)
Convert calendar date to Julian date.
#define GREGORIAN_EPOCH
MTKt_status
Definition: MisrError.h:11
static int leap_gregorian(int year)
static double gregorian_to_jd(int year, int month, int day)
HDFFCLIBAPI void * min

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51