MISR Toolkit  1.5.1
MtkOrbitToTimeRange.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkOrbitToTimeRange =
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 "MisrOrbitPath.h"
18 #include "MisrUtil.h"
19 #include "MisrError.h"
20 #include <stdio.h>
21 #include <math.h>
22 #include <string.h>
23 
39  int orbit,
40  char start_time[MTKd_DATETIME_LEN],
41  char end_time[MTKd_DATETIME_LEN] )
42 {
43  MTKt_status status; /* Return status */
44  MTKt_status status_code; /* Return code of this function */
45  const double JNref[] = MISR_ORBIT_REF;
46  const double JNref_995 = MISR_ORBIT_REF_995;
47  double jn;
48  int year;
49  int month;
50  int day;
51  int hour;
52  int min;
53  int sec;
54  int ref_num;
55 
56  if (orbit < 995)
58 
59  if (start_time == NULL || end_time == NULL)
61 
62  /* Determine Start Time */
63  if (orbit < MISR_ORBIT_REF_DT) {
64  jn = JNref_995 + 16.0 / 233.0 * ( orbit - 995 );
65  } else {
66  ref_num = orbit / MISR_ORBIT_REF_DT;
67  if (ref_num > sizeof JNref / sizeof *JNref)
68  ref_num = sizeof JNref / sizeof *JNref;
69 
70  jn = JNref[ref_num - 1] + 16.0 / 233.0 * ( orbit - ref_num * MISR_ORBIT_REF_DT );
71  }
72  status = MtkJulianToCal(jn,&year,&month,&day,&hour,&min,&sec);
73  MTK_ERR_COND_JUMP(status);
74 
75  sprintf(start_time,"%04d-%02d-%02dT%02d:%02d:%02dZ",year,month,day,hour,min,sec);
76 
77  /* Determine End Time */
78  if (orbit < MISR_ORBIT_REF_DT) {
79  jn = JNref_995 + 16.0 / 233.0 * ( (orbit + 1) - 995 );
80  } else {
81  ref_num = (orbit + 1) / MISR_ORBIT_REF_DT;
82  if (ref_num > sizeof JNref / sizeof *JNref)
83  ref_num = sizeof JNref / sizeof *JNref;
84 
85  jn = JNref[ref_num - 1] + 16.0 / 233.0 * ( (orbit + 1) - ref_num * MISR_ORBIT_REF_DT );
86  }
87  status = MtkJulianToCal(jn,&year,&month,&day,&hour,&min,&sec);
88  MTK_ERR_COND_JUMP(status);
89 
90  sprintf(end_time,"%04d-%02d-%02dT%02d:%02d:%02dZ",year,month,day,hour,min,sec);
91 
92  return MTK_SUCCESS;
93 
94 ERROR_HANDLE:
95  return status_code;
96 }
97 
#define MISR_ORBIT_REF_995
Definition: MisrOrbitPath.h:38
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
#define MISR_ORBIT_REF_DT
Definition: MisrOrbitPath.h:39
#define MISR_ORBIT_REF
Definition: MisrOrbitPath.h:40
MTKt_status MtkOrbitToTimeRange(int orbit, char start_time[MTKd_DATETIME_LEN], char end_time[MTKd_DATETIME_LEN])
Given a orbit number return time.
MTKt_status MtkJulianToCal(double jd, int *year, int *month, int *day, int *hour, int *min, int *sec)
Convert Julian date to calendar date.
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
HDFFCLIBAPI void * min
#define MTKd_DATETIME_LEN
Definition: MisrUtil.h:149

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