MISR Toolkit  1.5.1
MisrUtil.h
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MisrUtil =
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 #ifndef MISRUTIL_H
18 #define MISRUTIL_H
19 
20 #include <netcdf.h>
21 #include <MisrError.h>
22 #include <mfhdf.h>
23 #ifndef _WIN32
24 #include <sys/types.h>
25 #endif
26 
27 #define MAXDIMS 10
28 #define MAXSTR 80
29 
30 #define MTKd_NDATATYPE 13
31 #define MTKd_DataType { "void", "char8", "uchar8", "int8", "uint8", \
32  "int16", "uint16", "int32", "uint32", \
33  "int64", "uint64", "float", "double" }
34 #define MTKd_DataSize { 0, 1, 1, 1, 1, 2, 2, 4, 4, 8, 8, 4, 8 }
35 
36 typedef enum {
51 
52 #ifdef _WIN32
53 typedef char MTKt_char8;
54 typedef unsigned char MTKt_uchar8;
55 typedef char MTKt_int8;
56 typedef unsigned char MTKt_uint8;
57 typedef short MTKt_int16;
58 typedef unsigned short MTKt_uint16;
59 typedef int MTKt_int32;
60 typedef unsigned int MTKt_uint32;
61 typedef long int MTKt_int64;
62 typedef unsigned long int MTKt_uint64;
63 typedef float MTKt_float;
64 typedef double MTKt_double;
65 #else
66 typedef char MTKt_char8;
67 typedef unsigned char MTKt_uchar8;
68 typedef int8_t MTKt_int8;
69 typedef u_int8_t MTKt_uint8;
70 typedef int16_t MTKt_int16;
71 typedef u_int16_t MTKt_uint16;
72 typedef int32_t MTKt_int32;
73 typedef u_int32_t MTKt_uint32;
74 typedef int64_t MTKt_int64;
75 typedef u_int64_t MTKt_uint64;
76 typedef float MTKt_float;
77 typedef double MTKt_double;
78 #endif
79 
81 typedef union {
82  void **v;
96 
98 typedef struct {
99  int nline;
100  int nsample;
101  int datasize;
105  void **vdata;
106  void *dataptr;
108 
109 #define MTKT_DATABUFFER_INIT { 0, 0, 0, MTKe_void, MTK_FALSE, {0}, NULL, NULL }
110 
112 typedef union {
113  void ***v;
127 
129 typedef struct {
130  int nblock;
131  int nline;
132  int nsample;
133  int datasize;
136  void ***vdata;
137  void *dataptr;
139 
140 #define MTKT_DATABUFFER3D_INIT { 0, 0, 0, 0, 0, {0}, NULL, NULL }
141 
142 /* Time conversion constants */
143 #define EPOCH_DAY 2448988.5
144 #define EPOCH_DAY_FRACTION 0.0003125
145 #define SECONDSperDAY 86400.0
146 #define SECONDSperHOUR 3600.0
147 #define SECONDSperMINUTE 60.0
148 
149 #define MTKd_DATETIME_LEN 28
150 
151  /* JD TAI - UTC */
152 #define LEAP_SECONDS {{ 2441317.5, 10.0 }, /* 1972 JAN 1 =JD 2441317.5 TAI-UTC= 10.0000000 S */ \
153  { 2441499.5, 11.0 }, /* 1972 JUL 1 =JD 2441499.5 TAI-UTC= 11.0000000 S */ \
154  { 2441683.5, 12.0 }, /* 1973 JAN 1 =JD 2441683.5 TAI-UTC= 12.0000000 S */ \
155  { 2442048.5, 13.0 }, /* 1974 JAN 1 =JD 2442048.5 TAI-UTC= 13.0000000 S */ \
156  { 2442413.5, 14.0 }, /* 1975 JAN 1 =JD 2442413.5 TAI-UTC= 14.0000000 S */ \
157  { 2442778.5, 15.0 }, /* 1976 JAN 1 =JD 2442778.5 TAI-UTC= 15.0000000 S */ \
158  { 2443144.5, 16.0 }, /* 1977 JAN 1 =JD 2443144.5 TAI-UTC= 16.0000000 S */ \
159  { 2443509.5, 17.0 }, /* 1978 JAN 1 =JD 2443509.5 TAI-UTC= 17.0000000 S */ \
160  { 2443874.5, 18.0 }, /* 1979 JAN 1 =JD 2443874.5 TAI-UTC= 18.0000000 S */ \
161  { 2444239.5, 19.0 }, /* 1980 JAN 1 =JD 2444239.5 TAI-UTC= 19.0000000 S */ \
162  { 2444786.5, 20.0 }, /* 1981 JUL 1 =JD 2444786.5 TAI-UTC= 20.0000000 S */ \
163  { 2445151.5, 21.0 }, /* 1982 JUL 1 =JD 2445151.5 TAI-UTC= 21.0000000 S */ \
164  { 2445516.5, 22.0 }, /* 1983 JUL 1 =JD 2445516.5 TAI-UTC= 22.0000000 S */ \
165  { 2446247.5, 23.0 }, /* 1985 JUL 1 =JD 2446247.5 TAI-UTC= 23.0000000 S */ \
166  { 2447161.5, 24.0 }, /* 1988 JAN 1 =JD 2447161.5 TAI-UTC= 24.0000000 S */ \
167  { 2447892.5, 25.0 }, /* 1990 JAN 1 =JD 2447892.5 TAI-UTC= 25.0000000 S */ \
168  { 2448257.5, 26.0 }, /* 1991 JAN 1 =JD 2448257.5 TAI-UTC= 26.0000000 S */ \
169  { 2448804.5, 27.0 }, /* 1992 JUL 1 =JD 2448804.5 TAI-UTC= 27.0000000 S */ \
170  { 2449169.5, 28.0 }, /* 1993 JUL 1 =JD 2449169.5 TAI-UTC= 28.0000000 S */ \
171  { 2449534.5, 29.0 }, /* 1994 JUL 1 =JD 2449534.5 TAI-UTC= 29.0000000 S */ \
172  { 2450083.5, 30.0 }, /* 1996 JAN 1 =JD 2450083.5 TAI-UTC= 30.0000000 S */ \
173  { 2450630.5, 31.0 }, /* 1997 JUL 1 =JD 2450630.5 TAI-UTC= 31.0000000 S */ \
174  { 2451179.5, 32.0 }, /* 1999 JAN 1 =JD 2451179.5 TAI-UTC= 32.0000000 S */ \
175  { 2453736.5, 33.0 }, /* 2006 JAN 1 =JD 2453736.5 TAI-UTC= 33.0000000 S */ \
176  { 2454832.5, 34.0 }, /* 2009 JAN 1 =JD 2454832.5 TAI-UTC= 34.0000000 S */ \
177  { 2456109.5, 35.0 }, /* 2012 JUL 1 =JD 2456109.5 TAI-UTC= 35.0000000 S */ \
178  { 2457204.5, 36.0 }, /* 2015 JUL 1 =JD 2457204.5 TAI-UTC= 36.0000000 S */ \
179  { 2457754.5, 37.0 }} /* 2017 JAN 1 =JD 2457754.5 TAI-UTC= 37.0000000 S */
180 
182  int nsample,
184  MTKt_DataBuffer *databuf );
185 
187  int nline,
188  int nsample,
190  MTKt_DataBuffer3D *databuf );
191 
193 
195 
197  int nsample,
199  void *dataptr,
200  MTKt_DataBuffer *databuf );
201 
202 MTKt_status MtkHdfToMtkDataTypeConvert( int32 hdf_datatype,
204 
207 
208 MTKt_status MtkParseFieldname( const char *fieldname,
209  char **basefieldname,
210  int *ndim,
211  int **dimlist );
212 
213 MTKt_status MtkStringListFree( int strcnt,
214  char **strlist[] );
215 
217  int m,
218  int d,
219  int h,
220  int mn,
221  int s,
222  double *julian );
223 
224 MTKt_status MtkJulianToCal( double jd,
225  int *year,
226  int *month,
227  int *day,
228  int *hour,
229  int *min,
230  int *sec );
231 
232 MTKt_status MtkDateTimeToJulian( const char *datetime,
233  double *jd );
234 
236  char datetime[MTKd_DATETIME_LEN] );
237 
238 MTKt_status MtkTaiJdToTai( double jdTAI[2],
239  double *secTAI93 );
240 
241 MTKt_status MtkTaiJdToUtcJd( double jdTAI[2],
242  double jdUTC[2] );
243 
244 MTKt_status MtkTaiToTaiJd( double secTAI93,
245  double jdTAI[2] );
246 
247 MTKt_status MtkTaiToUtc( double secTAI93,
248  char utc_datetime[MTKd_DATETIME_LEN] );
249 
250 MTKt_status MtkUtcJdToTaiJd( double jdUTC[2],
251  double jdTAI[2] );
252 
253 MTKt_status MtkUtcJdToUtc( double jdUTCin[2],
254  char utc_datetime[MTKd_DATETIME_LEN] );
255 
256 MTKt_status MtkUtcToTai( char utc_datetime[MTKd_DATETIME_LEN],
257  double *secTAI93 );
258 
259 MTKt_status MtkUtcToUtcJd( char utc_datetime[MTKd_DATETIME_LEN],
260  double jdUTC[2] );
261 
262 
263 typedef struct {
264  int gid; // netcdf group id
265  int varid; // netcdf variable id
266 } MTKt_ncvarid;
267 
268 MTKt_status MtkNCVarId(int Ncid, const char *Name, MTKt_ncvarid *Var);
269 
270 char *MtkVersion(void);
271 
272 
273 #ifdef _MSC_VER
274 char* win_strcasestr(const char *s, const char *find);
275 #define strncasecmp _strnicmp
276 #define strdup _strdup
277 #define strlwr _strlwr
278 #define strcasestr win_strcasestr
279 #endif
280 
281 #endif /* MISRUTIL_H */
u_int64_t MTKt_uint64
Definition: MisrUtil.h:75
MTKt_int64 *** i64
Definition: MisrUtil.h:122
MTKt_status MtkStringListFree(int strcnt, char **strlist[])
Free string list.
unsigned char MTKt_uchar8
Definition: MisrUtil.h:67
MTKt_status MtkNcToMtkDataTypeConvert(nc_type nc_datatype, MTKt_DataType *datatype)
MTKt_double ** d
Definition: MisrUtil.h:94
MTKt_uchar8 *** uc8
Definition: MisrUtil.h:115
nc_type
Definition: netcdf.h:253
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
MTKt_int64 ** i64
Definition: MisrUtil.h:91
MTKt_status MtkDataBufferAllocate3D(int nblock, int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer3D *databuf)
Allocate 3-dimensional Data Buffer (a buffer stack)
HDFFCLIBAPI _fcd _fcd intf intf * datatype
MTKt_DataBufferType data
Definition: MisrUtil.h:104
MTKt_DataType
Definition: MisrUtil.h:36
MTKt_char8 *** c8
Definition: MisrUtil.h:114
MTKt_status MtkCalToJulian(int y, int m, int d, int h, int mn, int s, double *julian)
Convert calendar date to Julian date.
MTKt_double *** d
Definition: MisrUtil.h:125
MTKt_status MtkTaiToUtc(double secTAI93, char utc_datetime[MTKd_DATETIME_LEN])
Convert TAI93 to UTC.
Definition: MtkTaiToUtc.c:32
int32_t MTKt_int32
Definition: MisrUtil.h:72
MTKt_status MtkParseFieldname(const char *fieldname, char **basefieldname, int *ndim, int **dimlist)
Parses extra dimensions from fieldnames.
void *** vdata
Definition: MisrUtil.h:136
MTKt_int8 *** i8
Definition: MisrUtil.h:116
MTKt_uint32 *** u32
Definition: MisrUtil.h:121
MTKt_uint8 *** u8
Definition: MisrUtil.h:117
MTKt_uint64 *** u64
Definition: MisrUtil.h:123
MTKt_status MtkUtcToTai(char utc_datetime[MTKd_DATETIME_LEN], double *secTAI93)
Convert UTC to TAI93.
Definition: MtkUtcToTai.c:32
MTKt_boolean
Definition: MisrError.h:6
2-dimensional Data Buffer
Definition: MisrUtil.h:98
MTKt_float ** f
Definition: MisrUtil.h:93
void ** vdata
Definition: MisrUtil.h:105
char * MtkVersion(void)
MisrToolkit Version.
Definition: MtkVersion.c:31
MTKt_status MtkHdfToMtkDataTypeConvert(int32 hdf_datatype, MTKt_DataType *datatype)
Convert HDF data type to MISR Toolkit data type.
MTKt_int16 *** i16
Definition: MisrUtil.h:118
3-dimensional Data Buffer
Definition: MisrUtil.h:129
MTKt_status MtkDateTimeToJulian(const char *datetime, double *jd)
Convert date and time (ISO 8601) to Julian date.
void * dataptr
Definition: MisrUtil.h:106
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_char8 ** c8
Definition: MisrUtil.h:83
u_int16_t MTKt_uint16
Definition: MisrUtil.h:71
MTKt_DataType datatype
Definition: MisrUtil.h:102
MTKt_uint8 ** u8
Definition: MisrUtil.h:86
MTKt_DataType datatype
Definition: MisrUtil.h:134
int64_t MTKt_int64
Definition: MisrUtil.h:74
MTKt_status MtkUtcJdToTaiJd(double jdUTC[2], double jdTAI[2])
Convert UTC Julian date to TAI Julian date.
MTKt_status MtkDataBufferImport(int nline, int nsample, MTKt_DataType datatype, void *dataptr, MTKt_DataBuffer *databuf)
Import Data Buffer.
MTKt_int8 ** i8
Definition: MisrUtil.h:85
u_int8_t MTKt_uint8
Definition: MisrUtil.h:69
MTKt_uchar8 ** uc8
Definition: MisrUtil.h:84
int8_t MTKt_int8
Definition: MisrUtil.h:68
MTKt_int32 *** i32
Definition: MisrUtil.h:120
MTKt_status MtkTaiJdToUtcJd(double jdTAI[2], double jdUTC[2])
Convert TAI Julian date to UTC Julian date.
MTKt_status MtkTaiToTaiJd(double secTAI93, double jdTAI[2])
Convert TAI93 to TAI Julian date.
Definition: MtkTaiToTaiJd.c:33
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 MtkTaiJdToTai(double jdTAI[2], double *secTAI93)
Convert TAI Julian date to TAI93 time.
Definition: MtkTaiJdToTai.c:32
MTKt_float *** f
Definition: MisrUtil.h:124
MTKt_uint16 ** u16
Definition: MisrUtil.h:88
int16_t MTKt_int16
Definition: MisrUtil.h:70
MTKt_uint64 ** u64
Definition: MisrUtil.h:92
MTKt_status MtkJulianToCal(double jd, int *year, int *month, int *day, int *hour, int *min, int *sec)
Convert Julian date to calendar date.
MTKt_uint32 ** u32
Definition: MisrUtil.h:90
MTKt_DataBufferType3D data
Definition: MisrUtil.h:135
char * win_strcasestr(const char *s, const char *find)
Definition: strcasestr.c:18
MTKt_int32 ** i32
Definition: MisrUtil.h:89
MTKt_uint16 *** u16
Definition: MisrUtil.h:119
char MTKt_char8
Definition: MisrUtil.h:66
float MTKt_float
Definition: MisrUtil.h:76
u_int32_t MTKt_uint32
Definition: MisrUtil.h:73
MTKt_status MtkDataBufferFree3D(MTKt_DataBuffer3D *databuf)
Free 3-dimensional data buffer (a buffer stack)
MTKt_status
Definition: MisrError.h:11
double MTKt_double
Definition: MisrUtil.h:77
3-dimensional Data Buffer Type Union
Definition: MisrUtil.h:112
MTKt_status MtkUtcJdToUtc(double jdUTCin[2], char utc_datetime[MTKd_DATETIME_LEN])
Convert calendar date to Julian date.
MTKt_status MtkNCVarId(int Ncid, const char *Name, MTKt_ncvarid *Var)
Definition: MtkNCVarId.c:21
MTKt_boolean imported
Definition: MisrUtil.h:103
MTKt_int16 ** i16
Definition: MisrUtil.h:87
int const JOCTET * dataptr
Definition: jpeglib.h:950
HDFFCLIBAPI void * min
#define MTKd_DATETIME_LEN
Definition: MisrUtil.h:149
MTKt_status MtkJulianToDateTime(double jd, char datetime[MTKd_DATETIME_LEN])
Convert Julian date to date and time (ISO 8601)
2-dimensional Data Buffer Type Union
Definition: MisrUtil.h:81

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