MISR Toolkit  1.5.1
MtkUtcToUtcJd.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkUtcToUtcJd =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2006, 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 
20 /* Convert calendar day to Julian day */
21 static int julday(int year, int month, int day)
22 {
23  long j1; /* Scratch Variable */
24  long j2; /* Scratch Variable */
25  long j3; /* Scratch Variable */
26 
27  j1 = 1461L * (year + 4800L + (month - 14L) / 12L) / 4L;
28  j2 = 367L * (month - 2L - (month - 14L) / 12L * 12L) / 12L;
29  j3 = 3L * ((year + 4900L + (month - 14L) / 12L) / 100L) / 4L;
30  return (int)(day - 32075L + j1 + j2 - j3);
31 }
32 
33 
47  char utc_datetime[MTKd_DATETIME_LEN],
48  double jdUTC[2] )
49 {
50  MTKt_status status_code; /* Return code of this function */
51  int scanCheck; /* checks the return value of sscanf call */
52  int year; /* year portion of date */
53  int month; /* month portion of date */
54  int day; /* day portion of date */
55  int hours; /* hours of the given date */
56  int minutes; /* minutes of the given date */
57  double seconds;
58 
59  scanCheck = sscanf(utc_datetime,"%4d-%2d-%2dT%2d:%2d:%lfZ",
60  &year, &month, &day, &hours, &minutes, &seconds);
61  if (scanCheck != 6)
63 
64  if (month < 1 || month > 12)
66 
67  if (hours > 23)
69 
70  if (minutes > 59)
72 
73  if (seconds > 60.99999999)
74  {
76  }
77  else if (seconds >= 60.0 && (minutes != 59 || hours != 23))
79 
80 
81  if (seconds >= 60.0)
82  seconds -= 1.0;
83 
84  jdUTC[1] = (hours * SECONDSperHOUR + minutes * SECONDSperMINUTE + seconds) /
86 
87  jdUTC[0] = julday(year, month, day) - 0.5;
88 
89  return MTK_SUCCESS;
90 
91 ERROR_HANDLE:
92  return status_code;
93 }
#define SECONDSperDAY
Definition: MisrUtil.h:145
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
#define SECONDSperHOUR
Definition: MisrUtil.h:146
MTKt_status MtkUtcToUtcJd(char utc_datetime[MTKd_DATETIME_LEN], double jdUTC[2])
Convert UTC date to UTC Julian date.
Definition: MtkUtcToUtcJd.c:46
MTKt_status
Definition: MisrError.h:11
static int julday(int year, int month, int day)
Definition: MtkUtcToUtcJd.c:21
#define SECONDSperMINUTE
Definition: MisrUtil.h:147
#define MTKd_DATETIME_LEN
Definition: MisrUtil.h:149

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