Skip to content

Instantly share code, notes, and snippets.

@andripwn
Last active January 6, 2020 17:50
Show Gist options
  • Save andripwn/73857db9411a2141a3602523c98ec75d to your computer and use it in GitHub Desktop.
Save andripwn/73857db9411a2141a3602523c98ec75d to your computer and use it in GitHub Desktop.
(APS) Ocean Color Satellite Data Processing System - Data Structures
1
11 /*
12 * Portions based on TCL source code which is:
13 *
14 * Copyright (c) 1987-1994 The Regents of the University of California.
15 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
16 * Copyright (c) 1993-1996 Lucent Technologies.
17 *
18 */
19
20 /*
21 * This header is large and is divided into the following sections
22 *
23 * 1. Standard headers. These are headers that are used alot,
24 * so we'll cut down on the code by placing them here.
25 *
26 * 2. Data Type typdefs. Rather than use int, use int32, so
27 * that the APS code will at least in theory be platform
28 * independent. Other platform specific typedefs go here.
29 *
30 * 3. Useful macros. Like min/max/swap, etc.
31 *
32 * 4. Redefine's of low-level routines. These are redefinitions
33 * of low-level functions that might be different on the
34 * various platforms.
35 */
36
37 #ifndef _APS_H
38 #define _APS_H
39
40 /*
41 *--------------------------------------------------------------------
42 * 1. Include standard headers
43 *--------------------------------------------------------------------
44 */
45
46 #include <stdio.h>
47 #include <sys/types.h>
48 #include <stddef.h>
49 #include <stdbool.h>
50 #include <inttypes.h>
51 #include <float.h>
52 #include <time.h>
53 #include "gs_hash.h"
54
55 #ifdef __cplusplus
56 # define APS_EXTERN extern "C"
57 #else
58 # define APS_EXTERN extern
59 #endif
60
67 typedef enum
68 {
69
70 APS_OK = 0,
71 APS_ERROR = 1,
72 APS_EMAXDIMS = 2,
73 APS_EPERM = 3,
74 APS_ENAMEXISTS = 4,
75 APS_EINVTYPE = 5,
76 APS_EINVACCESS = 6,
77 APS_EMULTIOPEN = 7,
78 APS_ENOROOT = 8,
79 APS_EMEMORY = 9,
80 APS_EFILEFORMAT = 10,
81 APS_EPARAM = 11,
82 APS_EFILLVALUE = 12,
83 APS_EDIMNAME = 13,
84 APS_EFLAG = 14,
85 APS_EPROD = 15,
86 APS_EDIMCHECK = 16,
87 APS_ECHUNK = 17,
88 APS_EHISTORY = 18,
89 APS_ENOATTR = 19,
90 APS_EATTRINFO = 20,
91 APS_EATTRREAD = 21,
92 APS_EATTRMAKE = 22,
93 APS_EIMAG = 23,
94 APS_EGROUP = 24,
95 APS_EINIT = 25,
96 APS_EOPEN = 26,
97 APS_EREAD = 27,
98 APS_EWRITE = 28,
99 APS_ECLOSE = 29,
100 APS_EFOPEN = 30,
101 APS_EFCLOSE = 31,
102 APS_EFCREATE = 32,
103 APS_EDOPEN = 33,
104 APS_EDCLOSE = 34,
105 APS_EDCREATE = 35,
106 APS_EPRODCAL = 36,
107 APS_EPRODCLASS = 37,
108 APS_EPRODBAD = 38,
109 APS_EPRODLONG = 39,
110 APS_EPRODINTER = 40,
111 APS_EPRODVRANGE = 41,
112 APS_EPRODBROWSE = 42,
113 APS_EPRODVERSION= 43,
114 APS_ECLOSEROOT = 44
116 } aps_status_enum;
117
125 typedef enum
126 {
127
128 APS_BOX_MIXED_CASE = -1,
129 APS_BOX_MISS_ARG = -2,
130 APS_BOX_ERROR = -3,
132 APS_BOX_NOTSET = 0,
133 APS_BOX_FILE_TYPE = 1,
134 APS_BOX_GEO_TYPE = 2
136 } aps_arg_box_enum;
137
144 typedef enum
145 {
146
147 APS_BIG_ENDIAN = 0,
148 APS_LITTLE_ENDIAN = 1,
149 APS_MIXED_ENDIAN = 2,
150 APS_UNKNOWN_ENDIAN = 255
152 } aps_endian_enum;
153
154 /*
155 *--------------------------------------------------------------------
156 * 3. Useful macros
157 *--------------------------------------------------------------------
158 */
159
160 #ifdef __GNUC__
161 #define UNUSED __attribute__((unused))
162 #elif _MIPS_FPSET
163 #define UNUSED _Pragma( "set woff 3201" )
164 #else
165 #define UNUSED
166 #endif
167
168 #define str(s) #s
169 #define xstr(s) str(s)
170 #define SOFT_VERSION "v" PACKAGE_VERSION " (" __DATE__ " " __TIME__ " for " PLATFORM ")"
171
172 #ifndef min
173 #define min(a,b) (((a)<(b)) ? (a) : (b))
174 #endif
175 #ifndef max
176 #define max(a,b) (((a)>(b)) ? (a) : (b))
177 #endif
178 #ifndef swap
179 #define swap(a,b) a^=b;b^=a;a^=b
180 #endif
181
182 #define nint(a) ((int) ((a) + ((a) < 0 ? -0.5 : 0.5)))
183
184 /*
185 * Useful constants (some defined for _XOPEN_SOURCE)
186 */
187
188 #define K_2_PI 6.283185307
189 #define K_PI 3.141592654
190 #define K_PI_2 1.570796327
191 #define K_PI_4 0.785398163
192 #define K_RAD_DEG 57.29577951
193 #define K_DEG_RAD 0.017453292
194 #define K_SECONDS_IN_DAY 86400.0
195
196 /*
197 * Override Standard I/O routines
198 *
199 * This allows us to replace the standard I/O function with the
200 * zlib version. Due to a conflict between the hdf and zlib
201 * headers we can't include both so use USE_ZLIB to include zlib.
202 */
203
204 #if defined HAVE_ZLIB && defined USE_ZLIB
205 #include <zlib.h>
206 typedef gzFile apsFile;
207
208 #define Aps_Open(name,access) gzopen(name,access)
209 #define Aps_DOpen(fp,access) gzdopen(fp,access)
210 #define Aps_Read(buf,size,nitems,fp) gzread(fp,buf,size*nitems)
211 #define Aps_Write(buf,size,nitems,fp) gzwrite(fp,buf,size*nitems)
212 #define Aps_Close(fp) gzclose(fp)
213 #else
214 typedef FILE apsFile;
215
216 #define Aps_Open(name,access) fopen(name,access)
217 #define Aps_DOpen(fp,access) fdopen(fp,access)
218 #define Aps_Read(buf,size,nitems,fp) fread(buf,size,nitems,fp)
219 #define Aps_Write(buf,size,nitems,fp) fwrite(buf,size,nitems,fp)
220 #define Aps_Close(fp) fclose(fp)
221 #endif
222
223 typedef long apsFilePos;
224
225 #define Aps_GetPos(fp,pos) (pos = ftell(fp))
226 #define Aps_SetPos(fp,pos) fseek(fp,pos,SEEK_SET)
227
228 /*
229 * apsDegrees.c
230 * --------
231 */
232
233 #define LL_DEGREES 1
234 #define LL_DMS 2
235 #define LL_RADIANS 3
236
237 #define LL_DEG180 1
238 #define LL_DEG360 2
239 #define LL_DMS180 3
240 #define LL_DMS360 4
241 #define LL_RAD1PI 5
242 #define LL_RAD2PI 6
243
244 #define LL_NM 1
245 #define LL_KM 2
246 #define LL_METERS 3
247
257 typedef enum aps_file_type_enum
258 {
259
260 APS_FT_UNKNOWN = 0,
261
262 APS_FT_PS = 1,
263 APS_FT_GIF = 2,
264 APS_FT_JPEG = 3,
265 APS_FT_SRF = 4,
266 APS_FT_SGI = 5,
267 APS_FT_BMP = 6,
268 APS_FT_TIFF = 7,
269 APS_FT_PBM = 8,
270 APS_FT_PGM = 9,
271 APS_FT_PPM = 10,
272 APS_FT_PBM_RAW = 11,
273 APS_FT_PGM_RAW = 12,
274 APS_FT_PPM_RAW = 13,
275 APS_FT_XBM = 14,
276 APS_FT_PNG = 15,
277 APS_FT_HDF = 16,
278 APS_FT_HDF5 = 17,
279 APS_FT_NETCDF = 18,
280 APS_FT_DIRECTORY = 19,
281
282 APS_FT_ESA_OLCI_L1 = 20,
283 APS_FT_ESA_OLCI_GEO = 21,
284 APS_FT_ESA_OLCI_TIME = 22,
285
286 APS_FT_CZCS = 32,
287 APS_FT_NESDIS_AVHRR_LAC = 33,
288 APS_FT_NESDIS_AVHRR_GAC = 34,
289
290 APS_FT_NSIPS = 36,
291 APS_FT_TERAHRPT = 37,
292 APS_FT_TERASWHRPT = 38,
293 APS_FT_NASA_SWF_L0 = 39,
294 APS_FT_NASA_SWF_L1A = 40,
295 APS_FT_NASA_SWF_L2 = 41,
296 APS_FT_NASA_SWF_L2QC = 42,
297 APS_FT_NASA_SWF_L3 = 43,
298 APS_FT_NESDIS_AVHRR_HRPT = 44,
299 APS_FT_NESDIS_AVHRR_FRAC = 45,
300
301 APS_FT_NASA_SWF_L1A_BROWSE = 46,
302 APS_FT_NASA_SWF_L2_BROWSE = 47,
303 APS_FT_NASA_SWF_L3_BROWSE = 48,
304 APS_FT_NASA_SWF_L3_SMI = 49,
305 APS_FT_NASA_SWF_CAL_TBL = 50,
306
307 APS_FT_KORDI_GOCI_L1B = 55,
308
309 APS_FT_NASA_L1B_SEAWIFS = 60,
310 APS_FT_NASA_L1B_MODIST = 61,
311 APS_FT_NASA_L1B_MODISA = 62,
312 APS_FT_NASA_L1B_HMODIST = 63,
313 APS_FT_NASA_L1B_HMODISA = 64,
314 APS_FT_NASA_L1B_MERIS = 65,
315 APS_FT_NASA_L1B_VIIRS = 66,
316 APS_FT_NASA_L1B_HICO = 67,
317 APS_FT_NASA_NO2 = 68,
318 APS_FT_NASA_SEAICE = 69,
319
320 APS_FT_NASA_MOS_1B = 70,
321 APS_FT_NASA_POLDER_1B = 71,
322 APS_FT_NASA_NCEP = 72,
323 APS_FT_NASA_EPTOMS = 73,
324 APS_FT_NASA_TOVS = 74,
325 APS_FT_NASA_OCTS_1B = 75,
326 APS_FT_NASDAQ_OCTS_1B = 76,
327 APS_FT_NRL_OCM_1B = 77,
328 APS_FT_NRL_L2 = 78,
329 APS_FT_NRL_L3 = 79,
330
331 APS_FT_NRL_L3M = 80,
332 APS_FT_NRL_L4 = 81,
333 APS_FT_NRL_L5 = 82,
334
335 APS_FT_NRL_OCM_1A = 87,
336 APS_FT_ISRO_OCM2_L1B = 88,
337
338 APS_FT_IPO_VIIRS_L1B_M = 90,
339 APS_FT_IPO_VIIRS_L1B_I = 91,
340 APS_FT_IPO_VIIRS_L1B_DNB = 92,
341 APS_FT_IPO_VIIRS_L1_M_GEO = 93,
342 APS_FT_IPO_VIIRS_L1_I_GEO = 94,
343 APS_FT_IPO_VIIRS_L1_DNB_GEO = 95,
344 APS_FT_NRL_VIIRS_L1B_M = 96,
345 APS_FT_IPO_VIIRS_L2_OCC = 97,
346 APS_FT_IPO_VIIRS_L1_CLDMASK = 98,
347 APS_FT_IPO_VIIRS_L2_SST = 99,
348
349 APS_FT_NASA_MODIS_L1B_1KM = 100,
350 APS_FT_NASA_MODIS_L1B_500M = 101,
351 APS_FT_NASA_MODIS_L1B_250M = 102,
352 APS_FT_NASA_MODIS_L1_GEO = 103,
353 APS_FT_NASA_MODIS_L2_35 = 104,
354 APS_FT_NASA_MODIS_L1B_SS = 105,
355 APS_FT_NASA_MODIS_L1A = 106,
356 APS_FT_NASA_MODIS_L0 = 107,
357
358 APS_FT_NRL_HICO_L1A = 110,
359 APS_FT_NRL_HICO_L1B = 111,
360
361 APS_FT_ESA_MERIS_FRS_L1_N1 = 119,
362 APS_FT_WISC_MODIS_L1B_1KM = 120,
363 APS_FT_THDF_AVHRR_L1B_1KM = 121,
364 APS_FT_ESA_MERIS_L2_N1 = 122,
365 APS_FT_ESA_MERIS_L1_N1 = 123,
366 APS_FT_ESA_MERIS_FRS_L2_N1 = 124,
367 APS_FT_ESA_MERIS_FR_L1_N1 = 125,
368 APS_FT_ESA_MERIS_FR_L2_N1 = 126
369
370 } aps_file_type_enum;
371
372 /* standard APS messages */
373
374 #define APS_E_FILE_W_ACCESS "unable to access file %s for write permissions"
375 #define APS_E_FILE_R_ACCESS "unable to access file %s for read permissions"
376 #define APS_E_FILE_OPEN "unable to open file %s"
377 #define APS_E_FILE_CLOSE "unable to close file %s"
378 #define APS_E_FILE_READ "unable to read from file %s"
379 #define APS_E_FILE_WRITE "unable to write to file %s"
380 #define APS_E_FILE_ATTR_COPY "unable to copy file attributes"
381 #define APS_E_DATA_OPEN "unable to open data set %s"
382 #define APS_E_DATA_OPEN_FILE "unable to open data set %s in file %s"
383 #define APS_E_DATA_READ "unable to read from data set %s"
384 #define APS_E_DATA_READ_FILE "unable to read from data set %s in file %s"
385 #define APS_E_DATA_WRITE "unable to write to data set %s"
386 #define APS_E_DATA_WRITE_FILE "unable to write to data set %s in file %s"
387 #define APS_E_DATA_CLOSE "unable to close data set %s"
388 #define APS_E_DATA_CLOSE_FILE "unable to close data set %s in file %s"
389 #define APS_E_DATA_CREATE "unable to create data set %s"
390 #define APS_E_DATA_COPY "unable to copy data set %s"
391 #define APS_E_DATA_NOT_2_3D "data set %s not 2 or 3-D array"
392 #define APS_E_DATA_NOT_2D "data set %s not 2-D array"
393 #define APS_E_DATA_EXISTS "data set %s already exists"
394 #define APS_E_DATA_ATTR_COPY "unable to copy data set attributes"
395 #define APS_E_DATA_ATTR_SET "unable to set attr %s for data set %s"
396 #define APS_E_DATA_ATTR_READ "unable to read attr %s for data set %s"
397 #define APS_E_DATA_DIM_SET "unable to set dimension %s for data set %s"
398 #define APS_E_DATA_DIM_GET "unable to get dimension %s for data set %s"
399 #define APS_E_DATA_DIM_GET_ID "unable to get dimension id for data set %s"
400 #define APS_E_ATTR_SET "unable to set attr %s"
401 #define APS_E_ATTR_READ "unable to read attr %s"
402 #define APS_E_SET_BAD_DATA APS_E_DATA_ATTR_SET, "badData"
403
404 #define APS_E_SET_DEFAULT_MAP "unable to set default map name"
405 #define APS_E_LANDMASK_OPEN "unable to open landmask %s"
406
407 #define APS_E_PROJ_FAILED "unable to project point"
408
409 #define APS_E_FLAG_OPEN "unable to open flags %s"
410 #define APS_E_FLAG_OPEN_FILE "unable to open flags %s in file %s"
411 #define APS_E_FLAG_READ "unable to read from flags %s"
412 #define APS_E_FLAG_READ_FILE "unable to read from flags %s in file %s"
413 #define APS_E_FLAG_WRITE "unable to write to flags %s"
414 #define APS_E_FLAG_WRITE_FILE "unable to write to flags %s in file %s"
415 #define APS_E_FLAG_CLOSE "unable to close flags %s"
416 #define APS_E_FLAG_CLOSE_FILE "unable to close flags %s in file %s"
417 #define APS_E_FLAG_CREATE "unable to create flags %s"
418 #define APS_E_FLAG_COPY "unable to copy flags %s"
419 #define APS_E_FLAG_FIND "unable to find flag %s (missing or unknown)"
420 #define APS_E_FLAG_INVALID "invalid flag dataset %s"
421
422 #define APS_E_GRID_READ "unable to read control point grid from %s"
423 #define APS_E_GRID_WRITE "unable to write control point grid to %s"
424
425 #define APS_E_MEMORY_ALLOC "memory allocation failure"
426
427 #define APS_E_NO_PRODUCTS "no products specified or found in file"
428
429 #define APS_E_DATABASE_CONNECT "unable to connect to %s on %s as %s"
430 #define APS_E_SQL_COMMAND "SQL execution failure (%s)"
431
432 #define APS_E_NOT_MODIS "%s not/unknown MODIS file format"
433 #define APS_E_NOT_SEAWIFS "%s not/unknown SeaWiFS file format"
434 #define APS_E_NOT_AVHRR "%s not/unknown AVHRR file format"
435 #define APS_E_FT_UNKNOWN "%s unknown file format"
436
437 #define APS_E_NO_MAP_FOUND "map %s not found in file %s"
438 #define APS_E_NO_NAVIGATION "no navigation found"
439 #define APS_E_NO_NAVIGATION_FILE "no navigation found in file %s"
440 #define APS_E_UNKNOWN_NAVIGATION "unknown navigation found"
441
442 #define APS_E_BOX_MIXED_CASE "using image subsection and geolocation subsection together for -B option"
443 #define APS_E_BOX_ERROR "program error in call to Aps_ArgBox()"
444 #define APS_E_BOX_MISS_ARG "missing a required argument for a -B option parameter"
445 #define APS_E_BOX_NOTSET "box type not set for -B parameter"
446 #define APS_E_BOX_REPL_NOT_1 "replication factor option not implemented for -B option"
447 #define APS_E_BOX_MUST_BE_BOX "geographic box options (nlat,slat,wlon,elon) not implemented for -B option"
448 #define APS_E_BOX_FILE_RANGE "file box options (isp,iep,isl,iel) overlap or invalid"
449 #define APS_E_BOX_GEO_RANGE "geographic box options (nlat,slat,wlon,elon) overlap or invalid"
450
451 #define APS_E_INVALID_REPL "invalid replication factor"
452
453 #define APS_W_NO_OPTION "unknown option %c"
454 #define APS_W_BOX_OUTSIDE_IMAGE "given parameters for -B option are outside of image, resizing to edges"
455 #define APS_W_BOX_UNKNOWN_ARG "unknown parameter (%s) in -B option"
456
457 #define APS_M_USE_DEFAULT_MAP "using default map file $(APS_ETC/default.maps)"
458 #define APS_M_USE_MAP_FROM "using map %s from %s"
459 #define APS_M_OPEN_FILE "opening file %s"
460 #define APS_M_AGENCY "Naval Research Laboratory, Stennis Space Center"
461
462 #define ARG_B_img_HELP \
463 " -B isp=isp,iep=iep,isl=isl,iel=iel,irp=irp,irl=irl", \
464 "", \
465 " defines a region to extract from the input file", \
466 "", \
467 " isp is the starting sample number", \
468 " iep is the ending sample number", \
469 " isl is the starting line number", \
470 " iel is the ending line number", \
471 "", \
472 " irp is the sample replication number", \
473 " irl is the line replication number"
474
475 #define ARG_B_nav_HELP \
476 " -B nlat=nlat,slat=lat,elon=elon,wlon=wlon,irp=irp,irl=irl", \
477 "", \
478 " -B north=north,sout=south,east=east,west=west,irp=irp,irl=irl", \
479 "", \
480 " defines a geographical region to extract from the input file", \
481 "", \
482 " nlat/north is the Northernmost latitude (-90 to 90)", \
483 " slat/south is the Southernmost latitude (-90 to 90)", \
484 " elon/east is the Easternmost longitude (-180 to 180)", \
485 " wlon/west is the Westernmost longitude (-180 to 180)", \
486 "", \
487 " irp is the sample replication number", \
488 " irl is the line replication number"
489
490 #define ARG_M_HELP \
491 " -M draw=[0|1],name=name,masks='MASK1:color;MASK2;...',filter=", \
492 "", \
493 " use draw to turn on (1 - default) or off (0) masks", \
494 " use name to define data set containing flags to overlay", \
495 " default is 'l2_flags'", \
496 " use masks to select mask to overlay", \
497 " default is inputMasks from file", \
498 " use filter to filter the mask"
499
500 #define ARG_o_HELP \
501 " -o name=name,format=['hdf'|'h5|'nc'],conv=['aps3','coards']", \
502 "", \
503 " use name as output filename", \
504 " use format for output file format", \
505 " use conv for attribute conventions"
506
507 /* image scaling options */
508
509 #define IMG_LINEAR 0
510 #define IMG_LOG 1
511 #define IMG_LOG10 2
512
513
514 /*
515 * apsModis.c
516 * ---------
517 */
518
519 #define MODIS_UNKNOWN 0
520 #define MODIS_TERRA 1
521 #define MODIS_AQUA 2
522
523
524 /*
525 * apsPlot.c
526 * ---------
527 */
528
529 #define APS_PROJ_INSYS_ILLEGAL 1
530 #define APS_PROJ_OUSYS_ILLEGAL 2
531 #define APS_PROJ_GCTP_3 3
532 #define APS_PROJ_GCTP_5 5
533 #define APS_PROJ_GCTP_6 6
534 #define APS_PROJ_GCTP_11 11
535 #define APS_PROJ_GCTP_21 21
536 #define APS_PROJ_GCTP_22 22
537 #define APS_PROJ_GCTP_23 23
538 #define APS_PROJ_GCTP_31 31
539 #define APS_PROJ_GCTP_41 41
540 #define APS_PROJ_GCTP_44 44
541 #define APS_PROJ_GCTP_53 53
542 #define APS_PROJ_GCTP_93 93
543 #define APS_PROJ_GCTP_95 95
544 #define APS_PROJ_GCTP_103 103
545 #define APS_PROJ_GCTP_113 113
546 #define APS_PROJ_GCTP_115 115
547 #define APS_PROJ_GCTP_123 123
548 #define APS_PROJ_GCTP_125 125
549 #define APS_PROJ_GCTP_133 133
550 #define APS_PROJ_GCTP_143 143
551 #define APS_PROJ_GCTP_145 145
552 #define APS_PROJ_GCTP_153 153
553 #define APS_PROJ_GCTP_155 155
554 #define APS_PROJ_GCTP_201 201
555 #define APS_PROJ_GCTP_202 202
556 #define APS_PROJ_GCTP_234 234
557 #define APS_PROJ_GCTP_235 235
558 #define APS_PROJ_GCTP_236 236
559 #define APS_PROJ_GCTP_241 241
560 #define APS_PROJ_GCTP_251 251
561 #define APS_PROJ_GCTP_1101 1101
562 #define APS_PROJ_NO_X_DELTA 1601
563 #define APS_PROJ_NO_Y_DELTA 1602
564
565 typedef unsigned int flag_t;
566
573 typedef struct aps_flag_stats_t
574 {
575 double percents[32];
576 int counts[32];
577 int tested;
578 } aps_flag_stats_t;
579
584 typedef enum aps_histogram_plot_enum
585 {
586
587 HISTOGRAM_NOTSET = -1,
588 HISTOGRAM_LINEAR = 0,
589 HISTOGRAM_LOG = 1,
590 HISTOGRAM_LOGLOG = 2
592 } aps_histogram_plot_enum;
593
600 typedef union
601 {
602 double *d;
603 float *f;
604 int32_t *i;
605 uint32_t *ui;
606 int16_t *s;
607 uint16_t *us;
608 int8_t *c;
609 uint8_t *uc;
610 } aps_type_p;
611
618 typedef union
619 {
620 double d;
621 float f;
622 int32_t i;
623 uint32_t ui;
624 int16_t s;
625 uint16_t us;
626 int8_t c;
627 uint8_t uc;
628 } aps_type_u;
629
637 typedef struct aps_hist_stats_t {
638 char *name;
639 char *title;
640 char *subtitle;
641 char *xtitle;
642 char *ytitle;
643 int num_type;
644 aps_type_u min;
645 aps_type_u max;
646 aps_type_u delta;
647 double mean;
648 double median;
649 double *percent;
650 double *means;
651 double *pdf;
652 double *totals;
653 unsigned int total;
654 unsigned int *bin;
655 int nbins;
656 aps_histogram_plot_enum scaling;
657 } aps_hist_stats_t;
658
668 typedef struct aps_stat_t {
669 aps_flag_stats_t *flagStats;
670 GSHashTable *histograms;
671 } aps_stat_t;
672
680 typedef struct aps_time_t {
681 int tm_msec;
682 int tm_yday;
683 int tm_year;
684 } aps_time_t;
685
686 #define TM_YYDDDMSEC 0
687 #define TM_YYMMDD 1
688 #define TM_PACKED_YD_DECIMAL_HOURS 2
689
696 typedef struct aps_geo_point_t
697 {
698
699 double lon;
700 double lat;
701 double meridian;
703 } aps_geo_point_t;
704
705 /*
706 * Exported APS routines
707 */
708
709 APS_EXTERN void Aps_ApplyCoef(double ipin, double ilin,
710 double *ipout, double *ilout, double *c,
711 double *d);
712 APS_EXTERN aps_arg_box_enum Aps_ArgBox(char *subopt, double *isp, double *iep,
713 double *isl, double *iel, double *irp,
714 double *irl);
715 APS_EXTERN void Aps_ArgMask(const char *s, bool *do_masks, char **masks,
716 char **flagName, int *filter);
717 APS_EXTERN void Aps_ArgOutput(const char *s, char **name, char **format,
718 char **conv, int *compress);
719 APS_EXTERN void Aps_BitStream(char *InputBitStream,
720 int InputWordLength, int InputPadding,
721 int InputLorR, char *OutputBitStream,
722 int OutputWordLength, int OutputPadding,
723 int OutputLorR, int numWords);
724 APS_EXTERN void Aps_ConvertAngle(double, int, double *, int);
725 APS_EXTERN void Aps_ConvertAnglef(float, int, float *, int);
726 APS_EXTERN double Aps_Convolve( int resp_n, double *resp_wave, double *resp,
727 int in_n, double *in_wave, double *in_data );
728 APS_EXTERN bool Aps_CrossGPM(double lonc[4], int unit);
729 APS_EXTERN bool Aps_CrossIDL(double lonc[4], int unit);
730 APS_EXTERN void Aps_CTimeToApsTime(aps_time_t * apsTime, struct tm cTime);
731 APS_EXTERN double Aps_DoubleSwap(double *a);
732 APS_EXTERN void Aps_DouglasPeuker(int n, double *xin, double *yin,
733 double res, int *nout, double **xout,
734 double **yout);
735 APS_EXTERN aps_endian_enum Aps_Endianess(void);
736 APS_EXTERN off_t Aps_FileSize(const char *path);
737 APS_EXTERN aps_file_type_enum Aps_FileFormat(const char *path, FILE * fp,
738 char type[64]);
739 APS_EXTERN float Aps_FloatSwap(float *a);
740 APS_EXTERN aps_status_enum Aps_GetCoef(double ixin[4], double iyin[4],
741 double ixout[4], double iyout[4], double c[4],
742 double d[4]);
743 APS_EXTERN aps_time_t Aps_GetTime(double aps_epoch);
744 APS_EXTERN int Aps_GetValueInt(char *ptr, size_t offset, int num,
745 aps_endian_enum endian);
746 APS_EXTERN double Aps_GetValueDouble(char *ptr, size_t offset,
747 int num, aps_endian_enum endian);
748 APS_EXTERN void Aps_Gregor(int year, int doy, int *month, int *day);
749 APS_EXTERN aps_geo_point_t *Aps_GPnew(double lon, double lat);
750 APS_EXTERN void Aps_GPfree(aps_geo_point_t *gp);
751 APS_EXTERN void Aps_GPget(aps_geo_point_t * gp, double *lon, double *lat);
752 APS_EXTERN void Aps_GPget360(aps_geo_point_t * gp, double *lon,
753 double *lat);
754 APS_EXTERN void Aps_GPset_meridian(aps_geo_point_t * gp, double meridian);
755 APS_EXTERN void Aps_HHMMSS(int flag, int *sec, int *hour,
756 int *min, double *rsec);
757 APS_EXTERN int Aps_IntSwap(int *a);
758 APS_EXTERN int16_t Aps_Int16Swap(int16_t * a);
759 APS_EXTERN int32_t Aps_Int32Swap(int32_t * a);
760 APS_EXTERN aps_status_enum Aps_InvertMatrix(double A[4][4], double b[4],
761 int nRowCols, int l, double x[4]);
762 APS_EXTERN int Aps_IsLeapYear(aps_time_t time);
763 APS_EXTERN void Aps_JulianDay(int year, int month, int day, int *jday);
764 APS_EXTERN void Aps_JulianCalendar(int jday, int *year, int *yday);
765 APS_EXTERN int Aps_LeapYear(int year);
766 APS_EXTERN void Aps_LinearInterp(int nin, double *xin,
767 double *yin, int nout, double *xout,
768 double *yout);
769 APS_EXTERN void Aps_LinearInterpF(int nin, float *xin, float *yin,
770 int nout, float *xout, float *yout);
771 APS_EXTERN void Aps_LinearRegress(int n, double *xdata, double *ydata,
772 double *G0, double *G1,
773 double *r_squared);
774 const char *Aps_LibVersion(void);
775 const char *Aps_LibPlatform(void);
776 APS_EXTERN double Aps_LonDiff(double lon1, double lon2, int inunit);
777 APS_EXTERN double Aps_LonMid(double lon1, double lon2, int inunit,
778 int ouunit);
779 APS_EXTERN double Aps_MapDistance(double lat1, double lon1, double lat2,
780 double lon2, int inunit, int ouunit);
781 APS_EXTERN float Aps_MapDistancef(float lat1, float lon1, float lat2,
782 float lon2, int inunit, int ouunit);
783 APS_EXTERN double Aps_Mktime(aps_time_t t);
784 APS_EXTERN int Aps_Metrics(double value, double *validRange,
785 double *dataRange, int *dataRangeSet,
786 double *actualRange, int *actualSet);
787 APS_EXTERN int Aps_MetricsF(float value, float *validRange,
788 float *dataRange, int *dataRangeSet,
789 float *actualRange, int *actualSet);
790 APS_EXTERN void Aps_MinMax(double *a, int n, double *mn, double *mx);
791 APS_EXTERN void Aps_MinMaxF(float *a, int n, float *mn, float *mx);
792 APS_EXTERN void Aps_MinMaxI(int *a, int n, int *mn, int *mx);
793 APS_EXTERN void Aps_MinMaxUI(unsigned int *a, int n,
794 unsigned int *mn, unsigned int *mx);
795 APS_EXTERN int Aps_MonthFromAbbr( char *string );
796 APS_EXTERN int Aps_NiceScaleRange(double *min, double *max,
797 double *incr);
798 APS_EXTERN int Aps_PointInPolygon(int npol, double *xp,
799 double *yp, double x, double y);
800 APS_EXTERN int Aps_PointInPolygonI(int npol, int *xp, int *yp,
801 int x, int y);
802 APS_EXTERN bool Aps_PointInQuad(double x, double y, double xp[4],
803 double yp[4]);
804 APS_EXTERN bool Aps_PointInQuadI(int x, int y, int xp[4], int yp[4]);
805 APS_EXTERN bool Aps_PointInQuadUI(unsigned int x, unsigned int y,
806 unsigned int xp[4], unsigned int yp[4]);
807 APS_EXTERN int Aps_Prompt(const char *prompt, char *result,
808 size_t len, const char *deflt);
809 APS_EXTERN void Aps_LogDestroy(void);
810 APS_EXTERN aps_status_enum Aps_LogInit(char *progname);
811 APS_EXTERN void Aps_LogVerbose(int verbose, int silent);
812 APS_EXTERN void Aps_Critical(const char *format, ...);
813 APS_EXTERN void Aps_Warning(const char *format, ...);
814 APS_EXTERN void Aps_Error(const char *format, ...);
815 APS_EXTERN void Aps_Message(const char *format, ...);
816 APS_EXTERN void Aps_VerbMessage(int level, const char *format, ...);
817 APS_EXTERN void Aps_Progress(int i, int max, char *format);
818 APS_EXTERN int Aps_PutValueInt(char *ptr, int val, size_t offset,
819 int num, aps_endian_enum endian);
820 APS_EXTERN double Aps_PutValueDouble(char *ptr, double val,
821 size_t offset, int num,
822 aps_endian_enum endian);
823 APS_EXTERN int Aps_ShortSwap(short *a);
824 APS_EXTERN void Aps_StatFlags(aps_stat_t * stats, unsigned int *flags,
825 int nflags);
826 APS_EXTERN int Aps_StatHistogram(aps_stat_t * stats, char *name, int n,
827 void *data);
828 APS_EXTERN int Aps_StatHistogramGeo(aps_stat_t * stats, char *name,
829 int n, double *data);
830 APS_EXTERN int Aps_StatHistogramFlag(aps_stat_t * stats, char *name,
831 int n, flag_t * flags);
832 APS_EXTERN int Aps_StatHistogramFindPercent(aps_stat_t * stats,
833 char *hist_name,
834 int percent);
835 APS_EXTERN void Aps_StatHistogramNew(aps_stat_t * stats, char *name,
836 int type, int nbins, ...);
837 APS_EXTERN aps_status_enum Aps_StatHistogramPlot(aps_stat_t * stats, char *hist_name,
838 char *pfile);
839 APS_EXTERN int Aps_StatHistogramTitles(aps_stat_t* stats, char *hist_name,
840 char *title, char *subtitle,
841 char *xtitle, char *ytitle );
842 APS_EXTERN int Aps_StatClose(aps_stat_t * stats);
843 APS_EXTERN aps_stat_t *Aps_StatOpen(void);
844 APS_EXTERN int Aps_StrMatch(char *str, char *pattern);
845 APS_EXTERN void Aps_StrReplaceConsecMults(char *in_string, char ch);
846 APS_EXTERN void Aps_SunAngle(int year, int doy, double secofDay,
847 double lat, double lon, double *azimuth,
848 double *elevation, double *zenith,
849 int inunit, int ouunit);
850 APS_EXTERN void Aps_TimeMsecHMSs(int msec, int *hr, int *min,
851 int *sec, double *fsec);
852 APS_EXTERN aps_time_t *Aps_TimeCreate(int option, ...);
853 APS_EXTERN void Aps_TimeToCTime(aps_time_t apstime, struct tm *tm);
854 APS_EXTERN char *Aps_TimeString(aps_time_t apsTime);
855
856
857
858 /* signed functions */
859 extern void rsort8(signed char *base, unsigned int num);
860 extern void rsort16(short *base, unsigned int num);
861 extern void rsort32(long *base, unsigned int num);
862 extern void rsort64(long long *base, unsigned int num);
863 extern void rsortf32(float *base, unsigned int num);
864 extern void rsortd64(double *base, unsigned int num);
865
866 #define Aps_RSort8(a,b) rsort8(a,b)
867 #define Aps_RSort16(a,b) rsort16(a,b)
868 #define Aps_RSort32(a,b) rsort32(a,b)
869 #define Aps_RSort64(a,b) rsort64(a,b)
870 #define Aps_RSortf32(a,b) rsortf32(a,b)
871 #define Aps_RSortd64(a,b) rsortd64(a,b)
872
873 /* unsigned functions */
874 extern void rsortu8(unsigned char *base, unsigned int num);
875 extern void rsortu16(unsigned short *base, unsigned int num);
876 extern void rsortu32(unsigned long *base, unsigned int num);
877 extern void rsortu64(unsigned long long *base, unsigned int num);
878
879 #define Aps_RSortu8(a,b) rsortu8(a,b)
880 #define Aps_RSortu16(a,b) rsortu16(a,b)
881 #define Aps_RSortu32(a,b) rsortu32(a,b)
882 #define Aps_RSortu64(a,b) rsortu64(a,b)
883
884 #endif
1
10 #ifndef _APS_BATHY_H
11 #define _APS_BATHY_H
12
13 APS_EXTERN double Aps_Bathy(double lat, double lon);
14 APS_EXTERN aps_status_enum Aps_BathyFree(void);
15 APS_EXTERN char* Aps_BathyGetDefaultFileName(void);
16 APS_EXTERN aps_status_enum Aps_BathyGetImage(double **bathy,
17 int *width, int *height,
18 double **lons, double **lats);
19 APS_EXTERN aps_status_enum Aps_BathyGetImageSubSection(double **data,
20 int *width, int *height,
21 double **lons, double **lats,
22 double tl_lon, double tl_lat,
23 double br_lon, double br_lat);
24 APS_EXTERN aps_status_enum Aps_BathyInit(const char *path);
25 APS_EXTERN int Aps_BathyResolution(void);
26
27 #endif
1
8 #ifndef _APS_NSIPS_H
9 #define _APS_NSIPS_H
10
17 typedef struct aps_nsips_header_t
18 {
19 aps_endian_enum endian;
20 size_t data_size;
21 int version;
22 int type;
23 int samples;
24 int lines;
25 int bands;
26 int times;
27 int proj;
28 int gridx;
29 int gridy;
30 int ellip;
31 int zone;
32 int minScale;
33 int maxScale;
34 double NWLat;
35 double NWLon;
36 double DPLat;
37 double DPLon;
38 double trueLat;
39 double trueLon;
40 double xScale;
41 double yScale;
42 double baseLat;
43 double baseLon;
44 double falseEast;
45 double falseNorth;
46 double misc[10];
47 double XMin;
48 double XMax;
49 double YMin;
50 double YMax;
51 double minLat;
52 double minLon;
53 double maxLat;
54 double maxLon;
55 char comment_1[26]; // comment (on disk) is 25, we +1 for NULL character
56 char comment_2[26];
57 } aps_nsips_header_t;
58
59 #define NS_VERSION( hd ) hd->version;
60 #define NS_INT8 (1)
61 #define NS_INT16 (2)
62 #define NS_INT32 (3)
63 #define NS_FLOAT32 (4)
64 #define NS_FLOAT64 (5)
65 #define NS_HDRSIZE 512
66
67 typedef apsFile apsNSIPSFile;
68
69 APS_EXTERN void* Aps_AllocNSIPSData(size_t nitems, aps_nsips_header_t hd);
70 APS_EXTERN int Aps_CloseNSIPS(apsNSIPSFile * fp);
71 APS_EXTERN int Aps_DecodeNSIPSHeader(char *buf, aps_nsips_header_t * hd);
72 APS_EXTERN int Aps_EncodeNSIPSHeader(char *buf, aps_nsips_header_t hd,
73 aps_endian_enum endian);
74 APS_EXTERN void Aps_NSIPSGetComment(aps_nsips_header_t hd, int field,
75 char comment[26]);
76 APS_EXTERN void Aps_NSIPSGetInfo(aps_nsips_header_t hd, int *npixs,
77 int *nlins, int *nbands, int *type);
78 APS_EXTERN void Aps_NSIPSGetProj(aps_nsips_header_t hd, int *proj,
79 int *gridx, int *gridy, int *ellip,
80 int *zone, double *NWLat, double *NWLon,
81 double *DPLat, double *DPLon,
82 double *trueLat, double *trueLon);
83 APS_EXTERN void Aps_NSIPSGetProjData(aps_nsips_header_t hd, double *baseLat,
84 double *baseLon, double *falseEast,
85 double *falseNorth, double *misc,
86 double *XMin, double *XMax,
87 double *YMin, double *YMax,
88 double *minLat, double *maxLat,
89 double *minLon, double *maxLon);
90 APS_EXTERN void Aps_NSIPSSetComment(aps_nsips_header_t * hd, int field,
91 char comment[26]);
92 APS_EXTERN void Aps_NSIPSSetInfo(aps_nsips_header_t * hd, int npixs, int nlins,
93 int nbands, int type);
94 APS_EXTERN void Aps_NSIPSSetProj(aps_nsips_header_t * hd, int proj, int gridx,
95 int gridy, int ellip, int zone,
96 double NWLat, double NWLon, double DPLat,
97 double DPLon, double trueLat,
98 double trueLon);
99 APS_EXTERN apsNSIPSFile *Aps_OpenNSIPS(const char *file, const char *access);
100 APS_EXTERN size_t Aps_ReadNSIPSData(void *data, size_t nitems, aps_nsips_header_t hd,
101 apsNSIPSFile * fp);
102 APS_EXTERN int Aps_ReadNSIPSHeader(aps_nsips_header_t * hd, const char *path,
103 apsNSIPSFile * fp);
104 APS_EXTERN size_t Aps_WriteNSIPSData(void *buf, size_t nitems,
105 aps_nsips_header_t hd, apsNSIPSFile * fp);
106 APS_EXTERN int Aps_WriteNSIPSHeader(const char *path,
107 apsNSIPSFile * fp, aps_nsips_header_t hd,
108 aps_endian_enum data);
109
110 #endif
#include <string.h>
#include "aps.h"
#include "apsNSIPS.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "gs_strfuncs.h"
#include "pslib.h"
#include "aps.h"
#include "apsPlot.h"
1
9 #ifndef _APS_PLOT_H
10 #define _APS_PLOT_H
11
12 #define Aps_PlotSetColor(rgb) ps_setpaint(rgb)
13
21 typedef enum {
22 APS_PLOT_POINT_DIAMOND = 0x0001,
23 APS_PLOT_POINT_SQUARE = 0x0002,
24 APS_PLOT_POINT_STAR = 0x0004,
25 APS_PLOT_POINT_TRIANGLE = 0x0008,
26 APS_PLOT_POINT_ITRIANGLE = 0x0010,
27 APS_PLOT_POINT_CIRCLE = 0x0020,
28 APS_PLOT_POINT_INDEX = 0x0100,
29 APS_PLOT_POINT_LABEL = 0x0200
30 } aps_plot_point_enum;
31
38 typedef enum {
39 APS_PLOT_AXIS_LIN = 1,
40 APS_PLOT_AXIS_LOG = 2
41 } aps_plot_axis_enum;
42
51 typedef struct aps_plot_t {
52 double xmin;
53 double xmax;
54 double xtick;
55 double ymin[2];
56 double ymax[2];
57 double ytick[2];
58 double left_margin;
59 double right_margin;
60 double width;
61 double top_margin;
62 double btm_margin;
63 double height;
64 double xscale;
65 double x0;
66 double yscale[2];
67 double y0[2];
68 int ny;
69 aps_plot_axis_enum xtype;
70 aps_plot_axis_enum ytype[2];
71 char *path;
72 char *xtitle;
73 char *ytitle[2];
74 char *title;
75 } aps_plot_t;
76
84 typedef int aps_rgb_t[3];
85
86 APS_EXTERN void Aps_PlotClose(aps_plot_t *plot);
87 APS_EXTERN aps_status_enum Aps_PlotDualAxis(char *file, double xmin, double xmax,
88 double xtick, double ymin[2],
89 double ymax[2], double ytick[2],
90 char *title, char *xtitle,
91 char *ytitle[2], int *dash, int nx,
92 int ny, int *yaxis, double *xdata,
93 double **ydata);
94 APS_EXTERN void Aps_PlotGrid(aps_plot_t *plot, double xmin, double xmax,
95 double xtick, double ymin, double ymax,
96 double ytick, int xspace, int yspace,
97 aps_rgb_t *rgb, int dash);
98 APS_EXTERN aps_status_enum Aps_PlotLegend(aps_plot_t *plot, char **values,
99 aps_rgb_t *rgb, int nvalues, int position,
100 int border);
101 APS_EXTERN void Aps_PlotSetDash(int dash);
102 APS_EXTERN aps_status_enum Aps_PlotLine(aps_plot_t *plot, int n, double *xdata,
103 double *ydata, int yaxis, aps_rgb_t *color);
104 APS_EXTERN aps_status_enum Aps_PlotPoints(aps_plot_t *plot, int n,
105 double *xdata, double *ydata, int yaxis,
106 aps_plot_point_enum type, aps_rgb_t *color,
107 char **label);
108 APS_EXTERN aps_plot_t* Aps_PlotOpen(char *file, aps_plot_axis_enum xtype,
109 double xmin, double xmax, double xtick,
110 int ny, aps_plot_axis_enum *ytype,
111 double *ymin, double *ymax, double *ytick,
112 char *title, char *xtitle, char **ytitle,
113 int *paper);
114 APS_EXTERN aps_status_enum Aps_PlotScatter(char *file,
115 double xmin, double xmax, double xtick,
116 double ymin, double ymax, double ytick,
117 char *title, char *xtitle, char *ytitle,
118 int nx, double *xdata, double *ydata);
119 APS_EXTERN aps_status_enum Aps_PlotSimple(char *file, double xmin, double xmax,
120 double xtick, double ymin, double ymax,
121 double ytick, char *title, char *xtitle,
122 char *ytitle, int *colors[3], int *dash, int thick,
123 int nx, int ny, double *xdata,
124 double **ydata);
125 #endif
1
8 #ifndef _APS_SIMBIOS_H
9 #define _APS_SIMBIOS_H
10
17 typedef struct aps_simbios_header_t
18 {
19 int ncomment_lines;
20 char *instrument;
21 char *investigators;
22 char *affiliations;
23 char *contact;
24 char *experiment;
25 char *cruise;
26 char *station;
27 char *data_file_name;
28 char *documents;
29 char *calibration_files;
30 char *data_type;
31 char *data_status;
32 char *start_date;
33 char *end_date;
34 char *start_time;
35 char *end_time;
36 double proc_version;
37 double north_latitude;
38 double south_latitude;
39 double east_longitude;
40 double west_longitude;
41 char *cloud_percent;
42 char *measurement_depth;
43 char *secchi_depth;
44 char *water_depth;
45 char *wave_height;
46 char *wind_speed;
47 char *missing;
48 char *delimiter;
49 char *fields;
50 char *units;
51 char **comments;
52 } aps_simbios_header_t;
53
54 typedef apsFile apsSimbiosFile;
55
56 APS_EXTERN bool Aps_IsSimbios(const char *file);
57 APS_EXTERN bool Aps_IsSimbiosHeaderValid(aps_simbios_header_t hd,
58 FILE * fp, char **error);
59 APS_EXTERN int Aps_SimbiosClose(apsSimbiosFile * fp);
60 APS_EXTERN void Aps_SimbiosFreeHeader(aps_simbios_header_t * hd);
61 APS_EXTERN int Aps_SimbiosGetFieldIdx(aps_simbios_header_t hd,
62 char **field_names,
63 int **field_idxs);
64
65 APS_EXTERN apsSimbiosFile *Aps_SimbiosOpen(const char *file);
66 APS_EXTERN aps_status_enum Aps_SimbiosReadData(apsSimbiosFile * fp,
67 int nfields, int *num,
68 double ***data);
69 APS_EXTERN int Aps_SimbiosReadFields(apsSimbiosFile * fp, int nfields,
70 int *field_idxs, int *num,
71 double ***data);
72 APS_EXTERN aps_status_enum Aps_SimbiosReadHeader(aps_simbios_header_t * hd,
73 apsSimbiosFile * fp);
74 APS_EXTERN int Aps_SimbiosWriteHeader(aps_simbios_header_t * hd,
75 apsSimbiosFile * fp);
76 APS_EXTERN aps_status_enum Aps_ReadL2GenResponseData( const char *path,
77 aps_simbios_header_t *hd, int *nrows, int *ncols,
78 double ***resp );
79 APS_EXTERN aps_status_enum Aps_ReadL2GenResponse( const char *path,
80 aps_simbios_header_t *hd, int *nbands, int *nvals,
81 double **wave, double ***resp );
82
83 #endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment