MISR Toolkit  1.5.1
MtkTimeToOrbitPath.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkTimeToOrbitPath =
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 "MisrOrbitPath.h"
18 #include "MisrUtil.h"
19 #include "MisrError.h"
20 #include <stdio.h>
21 #include <math.h>
22 #include <string.h>
23 
39  const char *datetime,
40  int *orbit,
41  int *path )
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 j;
48  int year, month, day, hour, min, sec;
49  int num_values;
50  int ref_num;
51 
52  if (datetime == NULL || orbit == NULL || path == NULL)
54 
55  num_values = sscanf(datetime,"%4d-%2d-%2dT%2d:%2d:%2d",&year,&month,
56  &day,&hour,&min,&sec);
57 
58  if (num_values != 6)
60 
61  if (year < 2000)
63 
64  if (year == 2000 && month < 2)
66 
67  if (year == 2000 && month == 2 && day < 24)
69 
70  status = MtkCalToJulian(year,month,day,hour,min,sec,&j);
71  MTK_ERR_COND_JUMP(status);
72 
73  /* Implement special code for orbits 995-1000 */
74 
75  if (j < JNref[0]) {
76  *orbit = (int)( (233.0 / 16.0 * ( j - JNref_995))
77  +(995));
78  } else {
79  /* The JNref table is to account/adjust for drift in the orbit.
80  We need to find the closest entry in this table to our orbit. We do
81  this by determining the approximate orbit first and then using it
82  to find a more accurate entry in JNref table (ie ref_num = orbit/MISR_ORBIT_REF_DT).
83  Then we compute real orbit number. */
84 
85  ref_num = (int)((233.0 / 16.0 * ( j - JNref[0])) + MISR_ORBIT_REF_DT /*Nref*/)
87  if (ref_num > sizeof JNref / sizeof *JNref)
88  ref_num = sizeof JNref / sizeof *JNref;
89 
90  *orbit = (int)( (233.0 / 16.0 * ( j - JNref[ref_num - 1]))
91  +(ref_num * MISR_ORBIT_REF_DT) );
92  }
93 
94  status = MtkOrbitToPath(*orbit,path);
95  MTK_ERR_COND_JUMP(status);
96 
97  return MTK_SUCCESS;
98 
99  ERROR_HANDLE:
100  return status_code;
101 }
102 
#define MISR_ORBIT_REF_995
Definition: MisrOrbitPath.h:38
MTKt_status MtkCalToJulian(int y, int m, int d, int h, int mn, int s, double *julian)
Convert calendar date to Julian date.
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_status MtkOrbitToPath(int orbit, int *path)
Given orbit number return path number.
#define MISR_ORBIT_REF_DT
Definition: MisrOrbitPath.h:39
#define MISR_ORBIT_REF
Definition: MisrOrbitPath.h:40
MTKt_status MtkTimeToOrbitPath(const char *datetime, int *orbit, int *path)
Given time return orbit number and path number.
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
HDFFCLIBAPI void * min

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