Debian Codegraph @

libharp/harp-ingest-s5_l2.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2015-2026 S[&]T, The Netherlands.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "coda.h"
33 #include "harp-ingestion.h"
34
35 #include <assert.h>
36 #include <math.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <ctype.h>
41
42
43 static const char *snow_ice_type_values[] = { "snow_free_land", "sea_ice", "permanent_ice", "snow", "ocean" };
44
45
46 typedef enum s5_product_type_enum
47 {
48 s5_type_aui,
49 s5_type_ch4,
50 s5_type_no2,
51 s5_type_o3,
52 s5_type_so2,
53 s5_type_cld,
54 s5_type_co,
55 } s5_product_type;
56
57
58 #define S5_NUM_PRODUCT_TYPES (((int)s5_type_co) + 1)
59
60
61 typedef enum s5_dimension_type_enum
62 {
63 s5_dim_time = 0, /* flattened scanline x pixel grid */
64 s5_dim_scanline, /* original along-track dimension */
65 s5_dim_pixel, /* original across-track dimension */
66 s5_dim_corner, /* 4 polygon corners per ground pixel */
67 s5_dim_layer, /* pressure / altitude layers */
68 s5_dim_level, /* layer +1 (bounds) */
69 s5_dim_spectral, /* extra wavelengths (e.g. reflectance pair) */
70 s5_dim_profile /* short profile axis (SO2 options, etc.) */
71 } s5_dimension_type;
72
73 /* handy constant: last enum value + 1 */
74 #define S5_NUM_DIM_TYPES ((int)s5_dim_profile + 1)
75
76 static const char *s5_dimension_name[S5_NUM_PRODUCT_TYPES][S5_NUM_DIM_TYPES] = {
77 {"time", "scanline", "ground_pixel", "corner", NULL, NULL, NULL, NULL}, /* AUI */
78 {"time", "scanline", "ground_pixel", "corner", "layer", NULL, "sif_wavelengths", NULL}, /* CH4 */
79 {"time", "scanline", "ground_pixel", "corner", "layer", NULL, NULL, NULL}, /* NO2 */
80 {"time", "scanline", "ground_pixel", "corner", "layer", NULL, NULL, NULL}, /* O3_ */
81 {"time", "scanline", "ground_pixel", "corner", "layer", NULL, NULL, "profile"}, /* SO2 */
82 {"time", "scanline", "ground_pixel", "corner", NULL, NULL, NULL, NULL}, /* CLD */
83 {"time", "scanline", "ground_pixel", "corner", "layer", NULL, NULL, NULL}, /* CO_ */
84 };
85
86 typedef struct ingest_info_struct
87 {
88 coda_product *product;
89
90 int use_co_corrected;
91 int use_co_nd_avk;
92 int use_ch4_band_options; /* CH4: SWIR-1 (default), SWIR-3, or NIR-2 */
93 int use_cld_band_options; /* CLD: BAND3A (default), or BAND3C */
94 int so2_column_type; /* 0: PBL (anthropogenic), 1: 1km box profile, 2: 7km bp, 3: 15km bp, 4: layer height */
95
96 s5_product_type product_type;
97 long num_times;
98 long num_scanlines;
99 long num_pixels;
100 long num_corners;
101 long num_layers;
102 long num_levels;
103 long num_latitudes;
104 long num_longitudes;
105 long num_spectral;
106 long num_profile;
107
108 coda_cursor product_cursor;
109 coda_cursor geolocation_cursor;
110 coda_cursor detailed_results_cursor;
111 coda_cursor input_data_cursor;
112
113 /* CLD */
114 coda_cursor b3a_product_cursor;
115 coda_cursor b3a_geolocation_cursor;
116 coda_cursor b3a_detailed_results_cursor;
117 coda_cursor b3a_input_data_cursor;
118 coda_cursor b3c_product_cursor;
119 coda_cursor b3c_geolocation_cursor;
120 coda_cursor b3c_detailed_results_cursor;
121 coda_cursor b3c_input_data_cursor;
122
123 int wavelength_ratio;
124 int ch4_option; /* CH4: physics (default) or precision */
125 int no2_column_option; /* NO2: total (default) or summed */
126 int is_nrti;
127
128 uint8_t *surface_layer_status; /* used for O3; 0: use as-is, 1: remove */
129 } ingest_info;
130
131
132 static const char *get_product_type_name(s5_product_type product_type)
133 {
134 switch (product_type)
135 {
136 case s5_type_aui:
137 return "SN5_02_AUI";
138 case s5_type_ch4:
139 return "SN5_02_CH4";
140 case s5_type_no2:
141 return "SN5_02_NO2";
142 case s5_type_o3:
143 return "SN5_02_O3_";
144 case s5_type_so2:
145 return "SN5_02_SO2";
146 case s5_type_cld:
147 return "SN5_02_CLD";
148 case s5_type_co:
149 return "SN5_02_CO_";
150 }
151
152 assert(0);
153 exit(1);
154 }
155
156
157 static void broadcast_array_float(long num_scanlines, long num_pixels, float *data)
158 {
159 long i;
160
161 /* Repeat the value for each scanline for all pixels in that scanline. Iterate in reverse to avoid overwriting
162 * scanline values.
163 */
164 for (i = num_scanlines - 1; i >= 0; i--)
165 {
166 long j;
167
168 for (j = 0; j < num_pixels; j++)
169 {
170 data[i * num_pixels + j] = data[i];
171 }
172 }
173 }
174
175 static int get_product_type(coda_product *product, s5_product_type *product_type)
176 {
177 const char *coda_product_type;
178 int i;
179
180 if (coda_get_product_type(product, &coda_product_type) != 0)
181 {
182 harp_set_error(HARP_ERROR_CODA, NULL);
183 return -1;
184 }
185 for (i = 0; i < S5_NUM_PRODUCT_TYPES; i++)
186 {
187 if (strcmp(get_product_type_name((s5_product_type)i), coda_product_type) == 0)
188 {
189 *product_type = ((s5_product_type)i);
190 return 0;
191 }
192 }
193
194 harp_set_error(HARP_ERROR_INGESTION, "unsupported product type '%s'", coda_product_type);
195 return -1;
196 }
197
198
199 /* Recursively search for the named 1D dimension field within a CODA structure. */
200 static int find_dimension_length_recursive(coda_cursor *cursor, const char *name, long *length)
201 {
202 coda_type_class type_class;
203
204 if (coda_cursor_get_type_class(cursor, &type_class) != 0)
205 {
206 harp_set_error(HARP_ERROR_CODA, "failed to get type class");
207 return -1;
208 }
209
210 if (type_class == coda_record_class)
211 {
212 coda_cursor sub_cursor = *cursor;
213
214 /* Navigate to the first field */
215 if (coda_cursor_goto_first_record_field(&sub_cursor) == 0)
216 {
217 do
218 {
219 /* Attempt to navigate to the field by name */
220 coda_cursor test_cursor = *cursor;
221
222 if (coda_cursor_goto_record_field_by_name(&test_cursor, name) == 0)
223 {
224 long coda_dim[CODA_MAX_NUM_DIMS];
225 int num_dims;
226
227 if (coda_cursor_get_array_dim(&test_cursor, &num_dims, coda_dim) != 0)
228 {
229 harp_set_error(HARP_ERROR_CODA, "failed to get array dimensions");
230 return -1;
231 }
232
233 if (num_dims != 1)
234 {
235 harp_set_error(HARP_ERROR_INGESTION, "field '%s' is not a 1D array", name);
236 return -1;
237 }
238
239 *length = coda_dim[0];
240 return 0;
241 }
242
243 /* Recursively search in the substructure */
244 if (find_dimension_length_recursive(&sub_cursor, name, length) == 0)
245 {
246 return 0;
247 }
248
249 } while (coda_cursor_goto_next_record_field(&sub_cursor) == 0);
250 }
251 }
252 else if (type_class == coda_array_class)
253 {
254 long num_elements;
255
256 if (coda_cursor_get_num_elements(cursor, &num_elements) != 0)
257 {
258 harp_set_error(HARP_ERROR_CODA, "failed to get number of array elements");
259 return -1;
260 }
261
262 if (num_elements > 0)
263 {
264 coda_cursor sub_cursor = *cursor;
265
266 if (coda_cursor_goto_array_element_by_index(&sub_cursor, 0) != 0)
267 {
268 harp_set_error(HARP_ERROR_CODA, "failed to go to array element");
269 return -1;
270 }
271
272 if (find_dimension_length_recursive(&sub_cursor, name, length) == 0)
273 {
274 return 0;
275 }
276 }
277 }
278
279 /* Not found in this branch */
280 return -1;
281 }
282
283 /* Find dimension length by recursively searching under data/PRODUCT. */
284 static int get_dimension_length(ingest_info *info, const char *name, long *length)
285 {
286 coda_cursor cursor = info->product_cursor;
287
288 if (find_dimension_length_recursive(&cursor, name, length) != 0)
289 {
290 harp_set_error(HARP_ERROR_INGESTION, "dimension '%s' not found in product structure", name);
291 return -1;
292 }
293
294 return 0;
295 }
296
297
298 /* Init Routines */
299
300 /* Initialize CODA cursors for main record groups with inline comments. */
301 static int init_cursors(ingest_info *info)
302 {
303 coda_cursor cursor;
304
305 /* Bind a cursor to the root of the CODA product */
306 if (coda_cursor_set_product(&cursor, info->product) != 0)
307 {
308 harp_set_error(HARP_ERROR_CODA, NULL);
309 return -1;
310 }
311 /* CLD product has to set of bands each containing its own product type */
312 if (info->product_type == s5_type_cld)
313 {
314 if (coda_cursor_goto_record_field_by_name(&cursor, "PRODUCT_BAND3A") != 0)
315 {
316 /* Fallback to data/PRODUCT for simulated files */
317 if (coda_cursor_goto_record_field_by_name(&cursor, "data") != 0 ||
318 coda_cursor_goto_record_field_by_name(&cursor, "PRODUCT_BAND3A") != 0)
319 {
320 harp_set_error(HARP_ERROR_CODA, NULL);
321 return -1;
322 }
323 }
324 /* Save PRODUCT_BAND3A cursor; subsequent navigation is relative to this. */
325 info->b3a_product_cursor = cursor;
326
327 /* Enter SUPPORT_DATA under PRODUCT (same location for both layouts):
328 * '/PRODUCT/SUPPORT_DATA' or '/data/PRODUCT/SUPPORT_DATA'
329 */
330 if (coda_cursor_goto_record_field_by_name(&cursor, "SUPPORT_DATA") != 0)
331 {
332 harp_set_error(HARP_ERROR_CODA, NULL);
333 return -1;
334 }
335
336 /* Geolocation group (skip for O3-TCL): under SUPPORT_DATA
337 * '/.../SUPPORT_DATA/GEOLOCATIONS' for both layouts.
338 */
339 if (coda_cursor_goto_record_field_by_name(&cursor, "GEOLOCATIONS") != 0)
340 {
341 harp_set_error(HARP_ERROR_CODA, NULL);
342 return -1;
343 }
344 info->b3a_geolocation_cursor = cursor;
345
346 /* Back to SUPPORT_DATA */
347 coda_cursor_goto_parent(&cursor);
348
349 /* Detailed results: '/.../SUPPORT_DATA/DETAILED_RESULTS' */
350 if (coda_cursor_goto_record_field_by_name(&cursor, "DETAILED_RESULTS") != 0)
351 {
352 harp_set_error(HARP_ERROR_CODA, NULL);
353 return -1;
354 }
355 info->b3a_detailed_results_cursor = cursor;
356
357 /* Back to SUPPORT_DATA */
358 coda_cursor_goto_parent(&cursor);
359
360 /* Input data group (skip for O3-TCL): '/.../SUPPORT_DATA/INPUT_DATA' */
361 if (coda_cursor_goto_record_field_by_name(&cursor, "INPUT_DATA") != 0)
362 {
363 harp_set_error(HARP_ERROR_CODA, NULL);
364 return -1;
365 }
366 info->b3a_input_data_cursor = cursor;
367
368 /* (Again) Bind a cursor to the root of the CODA product
369 * (to repeat the procedure above for BAND3B). */
370 if (coda_cursor_set_product(&cursor, info->product) != 0)
371 {
372 harp_set_error(HARP_ERROR_CODA, NULL);
373 return -1;
374 }
375
376 if (coda_cursor_goto_record_field_by_name(&cursor, "PRODUCT_BAND3C") != 0)
377 {
378 /* fallback to data/PRODUCT for simulated files */
379 if (coda_cursor_goto_record_field_by_name(&cursor, "data") != 0 ||
380 coda_cursor_goto_record_field_by_name(&cursor, "PRODUCT_BAND3C") != 0)
381 {
382 harp_set_error(HARP_ERROR_CODA, NULL);
383 return -1;
384 }
385 }
386 /* Save PRODUCT_BAND3A cursor; subsequent navigation is relative to this. */
387 info->b3c_product_cursor = cursor;
388
389 /* Enter SUPPORT_DATA under PRODUCT (same location for both layouts):
390 * '/PRODUCT/SUPPORT_DATA' or '/data/PRODUCT/SUPPORT_DATA'
391 */
392 if (coda_cursor_goto_record_field_by_name(&cursor, "SUPPORT_DATA") != 0)
393 {
394 harp_set_error(HARP_ERROR_CODA, NULL);
395 return -1;
396 }
397
398 /* Geolocation group (skip for O3-TCL): under SUPPORT_DATA
399 * '/.../SUPPORT_DATA/GEOLOCATIONS' for both layouts.
400 */
401 if (coda_cursor_goto_record_field_by_name(&cursor, "GEOLOCATIONS") != 0)
402 {
403 harp_set_error(HARP_ERROR_CODA, NULL);
404 return -1;
405 }
406 info->b3c_geolocation_cursor = cursor;
407
408 /* Back to SUPPORT_DATA */
409 coda_cursor_goto_parent(&cursor);
410
411 /* Detailed results: '/.../SUPPORT_DATA/DETAILED_RESULTS' */
412 if (coda_cursor_goto_record_field_by_name(&cursor, "DETAILED_RESULTS") != 0)
413 {
414 harp_set_error(HARP_ERROR_CODA, NULL);
415 return -1;
416 }
417 info->b3c_detailed_results_cursor = cursor;
418 /* Back to SUPPORT_DATA */
419 coda_cursor_goto_parent(&cursor);
420
421 /* Input data group (skip for O3-TCL): '/.../SUPPORT_DATA/INPUT_DATA' */
422 if (coda_cursor_goto_record_field_by_name(&cursor, "INPUT_DATA") != 0)
423 {
424 harp_set_error(HARP_ERROR_CODA, NULL);
425 return -1;
426 }
427 info->b3c_input_data_cursor = cursor;
428
429 /* Make the cursors point to BAND3A by default */
430 if (info->use_cld_band_options == 0)
431 {
432 info->product_cursor = info->b3a_product_cursor;
433 info->geolocation_cursor = info->b3a_geolocation_cursor;
434 info->detailed_results_cursor = info->b3a_detailed_results_cursor;
435 info->input_data_cursor = info->b3a_input_data_cursor;
436 }
437 else
438 {
439 info->product_cursor = info->b3c_product_cursor;
440 info->geolocation_cursor = info->b3c_geolocation_cursor;
441 info->detailed_results_cursor = info->b3c_detailed_results_cursor;
442 info->input_data_cursor = info->b3c_input_data_cursor;
443 }
444 }
445 else
446 {
447 if (coda_cursor_goto_record_field_by_name(&cursor, "data") != 0 ||
448 coda_cursor_goto_record_field_by_name(&cursor, "PRODUCT") != 0)
449 {
450 harp_set_error(HARP_ERROR_CODA, NULL);
451 return -1;
452 }
453
454 /* Save PRODUCT cursor; subsequent navigation is relative to this. */
455 info->product_cursor = cursor;
456
457 /* Enter SUPPORT_DATA under PRODUCT (same location for both layouts):
458 * '/PRODUCT/SUPPORT_DATA' or '/data/PRODUCT/SUPPORT_DATA'
459 */
460 if (coda_cursor_goto_record_field_by_name(&cursor, "SUPPORT_DATA") != 0)
461 {
462 harp_set_error(HARP_ERROR_CODA, NULL);
463 return -1;
464 }
465
466 /* Geolocation group (skip for O3-TCL): under SUPPORT_DATA
467 * '/.../SUPPORT_DATA/GEOLOCATIONS' for both layouts.
468 */
469 if (coda_cursor_goto_record_field_by_name(&cursor, "GEOLOCATIONS") != 0)
470 {
471 harp_set_error(HARP_ERROR_CODA, NULL);
472 return -1;
473 }
474 info->geolocation_cursor = cursor;
475
476 /* Back to SUPPORT_DATA */
477 coda_cursor_goto_parent(&cursor);
478
479 /* Detailed results: '/.../SUPPORT_DATA/DETAILED_RESULTS' */
480 if (coda_cursor_goto_record_field_by_name(&cursor, "DETAILED_RESULTS") != 0)
481 {
482 harp_set_error(HARP_ERROR_CODA, NULL);
483 return -1;
484 }
485 info->detailed_results_cursor = cursor;
486
487 /* Back to SUPPORT_DATA */
488 coda_cursor_goto_parent(&cursor);
489
490 /* Input data group (skip for O3-TCL): '/.../SUPPORT_DATA/INPUT_DATA' */
491 if (coda_cursor_goto_record_field_by_name(&cursor, "INPUT_DATA") != 0)
492 {
493 harp_set_error(HARP_ERROR_CODA, NULL);
494 return -1;
495 }
496 info->input_data_cursor = cursor;
497 }
498
499 return 0;
500 }
501
502 static int init_dimensions(ingest_info *info)
503 {
504 if (s5_dimension_name[info->product_type][s5_dim_scanline] != NULL)
505 {
506 if (get_dimension_length(info, s5_dimension_name[info->product_type][s5_dim_scanline],
507 &info->num_scanlines) != 0)
508 {
509 return -1;
510 }
511 }
512
513 if (s5_dimension_name[info->product_type][s5_dim_pixel] != NULL)
514 {
515 if (get_dimension_length(info, s5_dimension_name[info->product_type][s5_dim_pixel], &info->num_pixels) != 0)
516 {
517 return -1;
518 }
519 }
520
521 if (s5_dimension_name[info->product_type][s5_dim_corner] != NULL)
522 {
523 if (get_dimension_length(info, s5_dimension_name[info->product_type][s5_dim_corner], &info->num_corners) != 0)
524 {
525 return -1;
526 }
527 if (info->num_corners != 4)
528 {
529 harp_set_error(HARP_ERROR_INGESTION, "dimension '%s' has length %ld; expected 4",
530 s5_dimension_name[info->product_type][s5_dim_corner], info->num_corners);
531 return -1;
532 }
533 }
534
535 if (s5_dimension_name[info->product_type][s5_dim_layer] != NULL)
536 {
537 if (get_dimension_length(info, s5_dimension_name[info->product_type][s5_dim_layer], &info->num_layers) != 0)
538 {
539 return -1;
540 }
541 }
542
543 if (s5_dimension_name[info->product_type][s5_dim_level] != NULL)
544 {
545 if (get_dimension_length(info, s5_dimension_name[info->product_type][s5_dim_level], &info->num_levels) != 0)
546 {
547 return -1;
548 }
549 }
550
551 /* Infer levels = layers + 1 */
552 if (info->num_layers > 0 && info->num_levels > 0)
553 {
554 if (info->num_levels != info->num_layers + 1)
555 {
556 harp_set_error(HARP_ERROR_INGESTION, "dimension '%s' has length %ld; expected %ld",
557 s5_dimension_name[info->product_type][s5_dim_level], info->num_levels, info->num_layers + 1);
558 return -1;
559 }
560 }
561 else if (info->num_layers > 0)
562 {
563 info->num_levels = info->num_layers + 1;
564 }
565 else if (info->num_levels > 0)
566 {
567 if (info->num_levels < 2)
568 {
569 harp_set_error(HARP_ERROR_INGESTION, "dimension '%s' has length %ld; expected >= 2",
570 s5_dimension_name[info->product_type][s5_dim_level], info->num_levels);
571 return -1;
572 }
573
574 info->num_layers = info->num_levels - 1;
575 }
576
577 return 0;
578 }
579
580
581 static void ingestion_done(void *user_data)
582 {
583 ingest_info *info = (ingest_info *)user_data;
584
585 if (info->surface_layer_status != NULL)
586 {
587 free(info->surface_layer_status);
588 }
589
590 free(info);
591 }
592
593
594 static int ingestion_init(const harp_ingestion_module *module, coda_product *product,
595 const harp_ingestion_options *options, harp_product_definition **definition, void **user_data)
596 {
597 const char *option_value;
598 ingest_info *info;
599
600 info = (ingest_info *)malloc(sizeof(ingest_info));
601 if (info == NULL)
602 {
603 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
604 sizeof(ingest_info), __FILE__, __LINE__);
605 return -1;
606 }
607
608 info->product = product;
609 info->num_times = 0;
610 info->num_scanlines = 0;
611 info->num_pixels = 0;
612 info->num_corners = 0;
613 info->num_layers = 0;
614 info->num_levels = 0;
615
616 info->num_spectral = 0;
617 info->num_profile = 0;
618
619 info->wavelength_ratio = 354;
620
621 info->surface_layer_status = NULL;
622
623 /* default */
624 info->ch4_option = 0;
625 info->use_ch4_band_options = 0;
626 info->no2_column_option = 0;
627 info->use_cld_band_options = 0; /* CLD: BAND3A (default), or BAND3C */
628 info->so2_column_type = 0; /* 0=PBL (default) 1=1 km 2=7 km 3=15 km */
629
630 if (get_product_type(info->product, &info->product_type) != 0)
631 {
632 ingestion_done(info);
633 return -1;
634 }
635
636 *definition = *module->product_definition;
637
638 if (harp_ingestion_options_has_option(options, "wavelength_ratio"))
639 {
640 if (harp_ingestion_options_get_option(options, "wavelength_ratio", &option_value) != 0)
641 {
642 ingestion_done(info);
643 return -1;
644 }
645 if (strcmp(option_value, "335_367nm") == 0)
646 {
647 info->wavelength_ratio = 335;
648 }
649 else if (strcmp(option_value, "354_388nm") == 0)
650 {
651 info->wavelength_ratio = 354;
652 }
653 else
654 {
655 /* Option values are guaranteed to be legal if present. */
656 assert(strcmp(option_value, "340_380nm") == 0);
657 info->wavelength_ratio = 340;
658 }
659 }
660
661
662 if (info->product_type == s5_type_ch4)
663 {
664 /* CH4: methane_dry_air_column_mixing_ratio_[physics|proxy] */
665 if (harp_ingestion_options_has_option(options, "ch4"))
666 {
667 if (harp_ingestion_options_get_option(options, "ch4", &option_value) != 0)
668 {
669 ingestion_done(info);
670 return -1;
671 }
672 if (strcmp(option_value, "proxy") == 0)
673 {
674 info->ch4_option = 1;
675 }
676 else
677 {
678 /* Physics is the default and first in the list */
679 assert(strcmp(option_value, "physics") == 0);
680 info->ch4_option = 0;
681 }
682 }
683 /* CH4: surface_albedo_[swir_1|swir_3|nir_2] */
684 if (harp_ingestion_options_has_option(options, "band"))
685 {
686 if (harp_ingestion_options_get_option(options, "band", &option_value) != 0)
687 {
688 ingestion_done(info);
689 return -1;
690 }
691 if (strcmp(option_value, "SWIR-3") == 0)
692 {
693 info->use_ch4_band_options = 1;
694 }
695 else if (strcmp(option_value, "NIR-2") == 0)
696 {
697 info->use_ch4_band_options = 2;
698 }
699 else
700 {
701 /* Must be SWIR-1 */
702 assert(strcmp(option_value, "SWIR-1") == 0);
703 info->use_ch4_band_options = 0;
704 }
705 }
706 }
707
708 /* CLD: BAND3A (default), or BAND3C */
709 if (info->product_type == s5_type_cld)
710 {
711 /* Only if option was provided, otherwise use the dafult value, provided above */
712 if (harp_ingestion_options_has_option(options, "band"))
713 {
714 if (harp_ingestion_options_get_option(options, "band", &option_value) != 0)
715 {
716 ingestion_done(info);
717 return -1;
718 }
719 if (strcmp(option_value, "band3c") == 0)
720 {
721 info->use_cld_band_options = 1;
722 }
723 else
724 {
725 /* Must be BAND3A */
726 assert(strcmp(option_value, "band3a") == 0);
727 info->use_cld_band_options = 0;
728 }
729 }
730 }
731
732 /* NO2: nitrogen_dioxide_[|summed]_total_column */
733 if (harp_ingestion_options_has_option(options, "total_column"))
734 {
735 if (harp_ingestion_options_get_option(options, "total_column", &option_value) != 0)
736 {
737 ingestion_done(info);
738 return -1;
739 }
740 if (strcmp(option_value, "summed") == 0)
741 {
742 info->no2_column_option = 1;
743 }
744 else
745 {
746 /* physics is the default and first in the list */
747 assert(strcmp(option_value, "total") == 0);
748 info->no2_column_option = 0;
749 }
750 }
751
752
753 /* SO2 */
754 if (harp_ingestion_options_has_option(options, "so2_column"))
755 {
756 if (harp_ingestion_options_get_option(options, "so2_column", &option_value) != 0)
757 {
758 ingestion_done(info);
759 return -1;
760 }
761 if (strcmp(option_value, "1km") == 0)
762 {
763 info->so2_column_type = 1;
764 }
765 else if (strcmp(option_value, "7km") == 0)
766 {
767 info->so2_column_type = 2;
768 }
769 else if (strcmp(option_value, "15km") == 0)
770 {
771 info->so2_column_type = 3;
772 }
773 }
774
775 if (init_cursors(info) != 0)
776 {
777 ingestion_done(info);
778 return -1;
779 }
780
781
782 if (init_dimensions(info) != 0)
783 {
784 ingestion_done(info);
785 return -1;
786 }
787
788 /* Adding spectral dimension to AUI product for reflectance */
789 if (info->product_type == s5_type_aui)
790 {
791 info->num_spectral = 2; /* (lower, upper) reflectances */
792 }
793 else if (info->product_type == s5_type_ch4)
794 {
795 info->num_spectral = 4; /* sif_wavelengths */
796 }
797
798 if (info->product_type == s5_type_so2)
799 {
800 info->num_profile = 4;
801 }
802
803 *user_data = info;
804
805 return 0;
806 }
807
808
809 /* Reading Routines */
810
811 static int read_dimensions(void *user_data, long dimension[HARP_NUM_DIM_TYPES])
812 {
813 ingest_info *info = (ingest_info *)user_data;
814
815 /* From the online documentation:
816 *
817 * time : Temporal dimension; this is also the only appendable dimension.
818 * vertical : Vertical dimension, indicating height or depth.
819 * spectral : Spectral dimension, associated with wavelength, wavenumber, or frequency.
820 * latitude : Latitude dimension, only to be used for the latitude axis
821 * of a regular latitude x longitude grid.
822 * longitude : Longitude dimension, only to be used for the longitude axis
823 * of a regular latitude x longitude grid.
824 * independent: Independent dimension, used to index other quantities, such
825 * as the corner coordinates of ground pixel polygons.
826 *
827 * [Note]: Within a HARP product, all dimensions of the same type should
828 * have the same length, except independent dimensions. For example, it is
829 * an error to have two variables within the same product that both have a
830 * time dimension, yet of a different length.
831 */
832
833
834 dimension[harp_dimension_time] = info->num_scanlines * info->num_pixels;
835
836 /* 2. vertical grid - only if available */
837 if (info->num_layers > 0)
838 {
839 dimension[harp_dimension_vertical] = info->num_layers;
840 }
841
842 switch (info->product_type)
843 {
844 case s5_type_aui:
845 dimension[harp_dimension_spectral] = info->num_spectral;
846 break;
847 case s5_type_ch4:
848 dimension[harp_dimension_spectral] = info->num_spectral;
849 break;
850 case s5_type_so2:
851 dimension[harp_dimension_time] = info->num_scanlines * info->num_pixels;
852 break;
853 /* CLD, NO2, CO, ... need no extra axes */
854 default:
855 break;
856 }
857
858 return 0;
859 }
860
861 /* Copied from the s5p l2 module */
862 static int read_dataset(coda_cursor cursor, const char *dataset_name, harp_data_type data_type, long num_elements,
863 harp_array data)
864 {
865 long coda_num_elements;
866 harp_scalar fill_value;
867
868 if (coda_cursor_goto_record_field_by_name(&cursor, dataset_name) != 0)
869 {
870 harp_set_error(HARP_ERROR_CODA, NULL);
871 return -1;
872 }
873 if (coda_cursor_get_num_elements(&cursor, &coda_num_elements) != 0)
874 {
875 harp_set_error(HARP_ERROR_CODA, NULL);
876 return -1;
877 }
878 if (coda_num_elements != num_elements)
879 {
880 harp_set_error(HARP_ERROR_INGESTION, "dataset has %ld elements; expected %ld", coda_num_elements, num_elements);
881 harp_add_coda_cursor_path_to_error_message(&cursor);
882 return -1;
883 }
884
885 switch (data_type)
886 {
887 case harp_type_int8:
888 {
889 coda_native_type read_type;
890
891 if (coda_cursor_goto_first_array_element(&cursor) != 0)
892 {
893 harp_set_error(HARP_ERROR_CODA, NULL);
894 return -1;
895 }
896 if (coda_cursor_get_read_type(&cursor, &read_type) != 0)
897 {
898 harp_set_error(HARP_ERROR_CODA, NULL);
899 return -1;
900 }
901 coda_cursor_goto_parent(&cursor);
902 if (read_type == coda_native_type_uint8)
903 {
904 if (coda_cursor_read_uint8_array(&cursor, (uint8_t *)data.int8_data, coda_array_ordering_c) != 0)
905 {
906 harp_set_error(HARP_ERROR_CODA, NULL);
907 return -1;
908 }
909 }
910 else
911 {
912 if (coda_cursor_read_int8_array(&cursor, data.int8_data, coda_array_ordering_c) != 0)
913 {
914 harp_set_error(HARP_ERROR_CODA, NULL);
915 return -1;
916 }
917 }
918 }
919 break;
920 case harp_type_int32:
921 {
922 coda_native_type read_type;
923
924 if (coda_cursor_goto_first_array_element(&cursor) != 0)
925 {
926 harp_set_error(HARP_ERROR_CODA, NULL);
927 return -1;
928 }
929 if (coda_cursor_get_read_type(&cursor, &read_type) != 0)
930 {
931 harp_set_error(HARP_ERROR_CODA, NULL);
932 return -1;
933 }
934 coda_cursor_goto_parent(&cursor);
935 if (read_type == coda_native_type_uint32)
936 {
937 if (coda_cursor_read_uint32_array(&cursor, (uint32_t *)data.int32_data, coda_array_ordering_c) != 0)
938 {
939 harp_set_error(HARP_ERROR_CODA, NULL);
940 return -1;
941 }
942 }
943 else
944 {
945 if (coda_cursor_read_int32_array(&cursor, data.int32_data, coda_array_ordering_c) != 0)
946 {
947 harp_set_error(HARP_ERROR_CODA, NULL);
948 return -1;
949 }
950 }
951 }
952 break;
953 case harp_type_float:
954 if (coda_cursor_read_float_array(&cursor, data.float_data, coda_array_ordering_c) != 0)
955 {
956 harp_set_error(HARP_ERROR_CODA, NULL);
957 return -1;
958 }
959 if (coda_cursor_goto(&cursor, "@FillValue[0]") != 0)
960 {
961 harp_set_error(HARP_ERROR_CODA, NULL);
962 return -1;
963 }
964 if (coda_cursor_read_float(&cursor, &fill_value.float_data) != 0)
965 {
966 harp_set_error(HARP_ERROR_CODA, NULL);
967 return -1;
968 }
969 /* Replace values equal to the _FillValue variable attribute by NaN. */
970 harp_array_replace_fill_value(data_type, num_elements, data, fill_value);
971 break;
972 case harp_type_double:
973 if (coda_cursor_read_double_array(&cursor, data.double_data, coda_array_ordering_c) != 0)
974 {
975 harp_set_error(HARP_ERROR_CODA, NULL);
976 return -1;
977 }
978 if (coda_cursor_goto(&cursor, "@FillValue[0]") != 0)
979 {
980 harp_set_error(HARP_ERROR_CODA, NULL);
981 return -1;
982 }
983 if (coda_cursor_read_double(&cursor, &fill_value.double_data) != 0)
984 {
985 harp_set_error(HARP_ERROR_CODA, NULL);
986 return -1;
987 }
988 /* Replace values equal to the _FillValue variable attribute by NaN. */
989 harp_array_replace_fill_value(data_type, num_elements, data, fill_value);
990 break;
991 default:
992 assert(0);
993 exit(1);
994 }
995
996 return 0;
997 }
998
999
1000 static int read_datetime(void *user_data, harp_array data)
1001 {
1002 ingest_info *info = (ingest_info *)user_data;
1003 harp_array time_reference_array;
1004 double time_reference;
1005 long i, j;
1006
1007 time_reference_array.ptr = &time_reference;
1008 if (read_dataset(info->product_cursor, "time", harp_type_double, 1, time_reference_array) != 0)
1009 {
1010 return -1;
1011 }
1012
1013 if (read_dataset(info->product_cursor, "delta_time", harp_type_double, info->num_scanlines, data) != 0)
1014 {
1015 return -1;
1016 }
1017
1018 for (i = info->num_scanlines - 1; i >= 0; i--)
1019 {
1020 data.double_data[i] += time_reference * 24 * 60 * 60;
1021 /* replicate for each pixel in the scanline */
1022 for (j = 0; j <= info->num_pixels; j++)
1023 {
1024 data.double_data[i * info->num_pixels + j] = data.double_data[i];
1025 }
1026 }
1027
1028 return 0;
1029 }
1030
1031 static int read_datetime_length(void *user_data, harp_array data)
1032 {
1033 ingest_info *info = (ingest_info *)user_data;
1034 coda_cursor cursor = info->product_cursor;
1035 double first, second;
1036
1037 if (coda_cursor_goto_record_field_by_name(&cursor, "delta_time") != 0)
1038 {
1039 harp_set_error(HARP_ERROR_CODA, NULL);
1040 return -1;
1041 }
1042 if (coda_cursor_goto_first_array_element(&cursor) != 0)
1043 {
1044 harp_set_error(HARP_ERROR_CODA, NULL);
1045 return -1;
1046 }
1047 if (coda_cursor_read_double(&cursor, &first) != 0)
1048 {
1049 harp_set_error(HARP_ERROR_CODA, NULL);
1050 return -1;
1051 }
1052 if (coda_cursor_goto_next_array_element(&cursor) != 0)
1053 {
1054 harp_set_error(HARP_ERROR_CODA, NULL);
1055 return -1;
1056 }
1057 if (coda_cursor_read_double(&cursor, &second) != 0)
1058 {
1059 harp_set_error(HARP_ERROR_CODA, NULL);
1060 return -1;
1061 }
1062 *data.double_data = second - first;
1063
1064 return 0;
1065 }
1066
1067 /* Read the absolute orbit number from the global attribute */
1068 static int read_orbit_index(void *user_data, harp_array data)
1069 {
1070 ingest_info *info = (ingest_info *)user_data;
1071 coda_cursor cursor;
1072 coda_native_type read_type;
1073 uint32_t uval;
1074 int32_t ival;
1075
1076 /* 1) Bind a cursor to the root product */
1077 if (coda_cursor_set_product(&cursor, info->product) != 0)
1078 {
1079 harp_set_error(HARP_ERROR_CODA, NULL);
1080 return -1;
1081 }
1082
1083 /* 2) Try /@orbit_start first, then /@orbit */
1084 if (coda_cursor_goto(&cursor, "/@orbit_start") != 0 && coda_cursor_goto(&cursor, "/@orbit") != 0)
1085 {
1086 harp_set_error(HARP_ERROR_CODA, NULL);
1087 return -1;
1088 }
1089
1090 /* 3) If it's an array, move to its first element */
1091 {
1092 coda_type_class tc;
1093
1094 if (coda_cursor_get_type_class(&cursor, &tc) != 0)
1095 {
1096 return -1;
1097 }
1098 if (tc == coda_array_class)
1099 {
1100 if (coda_cursor_goto_first_array_element(&cursor) != 0)
1101 {
1102 harp_set_error(HARP_ERROR_CODA, NULL);
1103 return -1;
1104 }
1105 }
1106 }
1107
1108 /* 4) Determine the native storage type and read appropriately */
1109 if (coda_cursor_get_read_type(&cursor, &read_type) != 0)
1110 {
1111 harp_set_error(HARP_ERROR_CODA, NULL);
1112 return -1;
1113 }
1114 if (read_type == coda_native_type_uint32)
1115 {
1116 /* Stored as an unsigned 32-bit */
1117 if (coda_cursor_read_uint32(&cursor, &uval) != 0)
1118 {
1119 harp_set_error(HARP_ERROR_CODA, NULL);
1120 return -1;
1121 }
1122 ival = (int32_t)uval;
1123 }
1124 else
1125 {
1126 /* Stored as a signed 32-bit (or other compatible) */
1127 if (coda_cursor_read_int32(&cursor, &ival) != 0)
1128 {
1129 harp_set_error(HARP_ERROR_CODA, NULL);
1130 return -1;
1131 }
1132 }
1133
1134 /* 5) Write back into the HARP buffer */
1135 data.int32_data[0] = ival;
1136 return 0;
1137 }
1138
1139
1140 /* Field: data/PRODUCT */
1141
1142 static int read_product_latitude(void *user_data, harp_array data)
1143 {
1144 ingest_info *info = (ingest_info *)user_data;
1145
1146 return read_dataset(info->geolocation_cursor, "latitude", harp_type_float, info->num_scanlines * info->num_pixels,
1147 data);
1148 }
1149
1150 static int read_product_longitude(void *user_data, harp_array data)
1151 {
1152 ingest_info *info = (ingest_info *)user_data;
1153
1154 return read_dataset(info->geolocation_cursor, "longitude", harp_type_float, info->num_scanlines * info->num_pixels,
1155 data);
1156 }
1157
1158 static int read_product_qa_value(void *user_data, harp_array data)
1159 {
1160 ingest_info *info = (ingest_info *)user_data;
1161 int result;
1162
1163 /* we don't want the add_offset/scale_factor applied for the qa_value; we just want the raw 8bit value */
1164 coda_set_option_perform_conversions(0);
1165 result = read_dataset(info->product_cursor, "qa_value", harp_type_int8,
1166 info->num_scanlines * info->num_pixels, data);
1167 coda_set_option_perform_conversions(1);
1168
1169 return result;
1170 }
1171
1172 static int read_product_carbon_monoxide_total_column(void *user_data, harp_array data)
1173 {
1174 ingest_info *info = (ingest_info *)user_data;
1175
1176 if (info->product_type == s5_type_co)
1177 {
1178 return read_dataset(info->product_cursor, "carbon_monoxide_total_column", harp_type_float,
1179 info->num_scanlines * info->num_pixels, data);
1180 }
1181 else
1182 {
1183 return read_dataset(info->detailed_results_cursor, "carbon_monoxide_total_column", harp_type_float,
1184 info->num_scanlines * info->num_pixels, data);
1185 }
1186 }
1187
1188 static int read_product_carbon_monoxide_total_column_precision(void *user_data, harp_array data)
1189 {
1190 ingest_info *info = (ingest_info *)user_data;
1191
1192 return read_dataset(info->product_cursor, "carbon_monoxide_total_column_precision", harp_type_float,
1193 info->num_scanlines * info->num_pixels, data);
1194 }
1195
1196
1197 static int read_product_aerosol_index(void *user_data, harp_array data)
1198 {
1199 ingest_info *info = (ingest_info *)user_data;
1200 const char *variable_name = NULL;
1201
1202 switch (info->wavelength_ratio)
1203 {
1204 case 354:
1205 variable_name = "aerosol_index_354_388";
1206 break;
1207 case 340:
1208 variable_name = "aerosol_index_340_380";
1209 break;
1210 case 335:
1211 variable_name = "aerosol_index_335_367";
1212 break;
1213 default:
1214 assert(0);
1215 exit(1);
1216 }
1217
1218 return read_dataset(info->product_cursor, variable_name, harp_type_float, info->num_scanlines * info->num_pixels,
1219 data);
1220 }
1221
1222 static int read_product_aerosol_index_precision(void *user_data, harp_array data)
1223 {
1224 ingest_info *info = (ingest_info *)user_data;
1225 const char *variable_name = NULL;
1226
1227 switch (info->wavelength_ratio)
1228 {
1229 case 354:
1230 variable_name = "aerosol_index_354_388_precision";
1231 break;
1232 case 340:
1233 variable_name = "aerosol_index_340_380_precision";
1234 break;
1235 case 335:
1236 variable_name = "aerosol_index_335_367_precision";
1237 break;
1238 default:
1239 assert(0);
1240 exit(1);
1241 }
1242
1243 return read_dataset(info->product_cursor, variable_name, harp_type_float, info->num_scanlines * info->num_pixels,
1244 data);
1245 }
1246
1247 static int read_product_methane_dry_air_column_mixing_ratio(void *user_data, harp_array data)
1248 {
1249 ingest_info *info = (ingest_info *)user_data;
1250 const char *dataset_name = NULL;
1251 long count;
1252
1253 /* Total number of elements = scanlines x ground pixels */
1254 count = info->num_scanlines * info->num_pixels;
1255
1256 /* Pick the right HDF5 field based on the ch4 option */
1257 switch (info->ch4_option)
1258 {
1259 case 0:
1260 dataset_name = "methane_dry_air_column_mixing_ratio_physics"; /* physics-based */
1261 break;
1262 case 1:
1263 dataset_name = "methane_dry_air_column_mixing_ratio_proxy"; /* proxy-based */
1264 break;
1265 default:
1266 assert(0);
1267 exit(1);
1268 }
1269
1270 /* Read the chosen dataset in one shot */
1271 if (read_dataset(info->product_cursor, dataset_name, harp_type_float, count, data) != 0)
1272 {
1273 return -1;
1274 }
1275
1276 /* 1-D along time already ascending -> nothing more to do */
1277 return 0;
1278 }
1279
1280
1281 static int read_product_methane_dry_air_column_mixing_ratio_precision(void *user_data, harp_array data)
1282 {
1283 ingest_info *info = (ingest_info *)user_data;
1284 const char *dataset_name = NULL;
1285 long count;
1286
1287 /* Total number of elements = scanlines x ground pixels */
1288 count = info->num_scanlines * info->num_pixels;
1289
1290 /* Pick the right HDF5 field based on the ch4 option */
1291 switch (info->ch4_option)
1292 {
1293 case 0:
1294 dataset_name = "methane_dry_air_column_mixing_ratio_precision_physics"; /* physics-based */
1295 break;
1296 case 1:
1297 dataset_name = "methane_dry_air_column_mixing_ratio_precision_proxy"; /* proxy-based */
1298 break;
1299 default:
1300 /* Should never happen if option parsing is correct */
1301 harp_set_error(HARP_ERROR_INGESTION, "invalid CH4 option %d", info->ch4_option);
1302 return -1;
1303 }
1304
1305 /* Read the chosen dataset in one shot */
1306 if (read_dataset(info->product_cursor, dataset_name, harp_type_float, count, data) != 0)
1307 {
1308 return -1;
1309 }
1310
1311 /* 1-D along time already ascending -> nothing more to do */
1312 return 0;
1313 }
1314
1315
1316 static int read_product_nitrogen_dioxide_tropospheric_column(void *user_data, harp_array data)
1317 {
1318 ingest_info *info = (ingest_info *)user_data;
1319
1320 return read_dataset(info->product_cursor, "nitrogen_dioxide_tropospheric_column", harp_type_float,
1321 info->num_scanlines * info->num_pixels, data);
1322 }
1323
1324 static int read_product_nitrogen_dioxide_tropospheric_column_uncertainty(void *user_data, harp_array data)
1325 {
1326 ingest_info *info = (ingest_info *)user_data;
1327
1328 return read_dataset(info->product_cursor, "nitrogen_dioxide_tropospheric_column_uncertainty", harp_type_float,
1329 info->num_scanlines * info->num_pixels, data);
1330 }
1331
1332 static int read_product_nitrogen_dioxide_tropospheric_column_air_mass_factor(void *user_data, harp_array data)
1333 {
1334 ingest_info *info = (ingest_info *)user_data;
1335
1336 return read_dataset(info->product_cursor, "nitrogen_dioxide_tropospheric_column_air_mass_factor", harp_type_float,
1337 info->num_scanlines * info->num_pixels, data);
1338 }
1339
1340
1341 static int read_product_nitrogen_dioxide_total_column_air_mass_factor(void *user_data, harp_array data)
1342 {
1343 ingest_info *info = (ingest_info *)user_data;
1344
1345 return read_dataset(info->product_cursor, "nitrogen_dioxide_total_column_air_mass_factor", harp_type_float,
1346 info->num_scanlines * info->num_pixels, data);
1347 }
1348
1349 static int read_product_nitrogen_dioxide_total_column_avk(void *user_data, harp_array data)
1350 {
1351 ingest_info *info = (ingest_info *)user_data;
1352 long dimension[2];
1353
1354 if (read_dataset(info->product_cursor, "nitrogen_dioxide_total_column_averaging_kernel", harp_type_float,
1355 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1356 {
1357 return -1;
1358 }
1359 dimension[0] = info->num_scanlines * info->num_pixels;
1360 dimension[1] = info->num_layers;
1361 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1362 }
1363
1364
1365 static int read_product_ozone_total_column(void *user_data, harp_array data)
1366 {
1367 ingest_info *info = (ingest_info *)user_data;
1368
1369 return read_dataset(info->product_cursor, "ozone_total_column", harp_type_float,
1370 info->num_scanlines * info->num_pixels, data);
1371 }
1372
1373 static int read_product_ozone_total_column_precision(void *user_data, harp_array data)
1374 {
1375 ingest_info *info = (ingest_info *)user_data;
1376
1377 return read_dataset(info->product_cursor, "ozone_total_column_precision", harp_type_float,
1378 info->num_scanlines * info->num_pixels, data);
1379 }
1380
1381 static int read_product_ozone_total_column_trueness(void *user_data, harp_array data)
1382 {
1383 ingest_info *info = (ingest_info *)user_data;
1384
1385 return read_dataset(info->product_cursor, "ozone_total_column_trueness", harp_type_float,
1386 info->num_scanlines * info->num_pixels, data);
1387 }
1388
1389 static int read_product_effective_cloud_fraction(void *user_data, harp_array data)
1390 {
1391 ingest_info *info = (ingest_info *)user_data;
1392
1393 return read_dataset(info->product_cursor, "effective_cloud_fraction", harp_type_float,
1394 info->num_scanlines * info->num_pixels, data);
1395 }
1396
1397 static int read_product_effective_cloud_fraction_uncertainty(void *user_data, harp_array data)
1398 {
1399 ingest_info *info = (ingest_info *)user_data;
1400
1401 return read_dataset(info->product_cursor, "effective_cloud_fraction_precision", harp_type_float,
1402 info->num_scanlines * info->num_pixels, data);
1403 }
1404
1405 static int read_product_cloud_pressure(void *user_data, harp_array data)
1406 {
1407 ingest_info *info = (ingest_info *)user_data;
1408
1409 return read_dataset(info->product_cursor, "cloud_pressure", harp_type_float,
1410 info->num_scanlines * info->num_pixels, data);
1411 }
1412
1413 static int read_product_cloud_pressure_uncertainty(void *user_data, harp_array data)
1414 {
1415 ingest_info *info = (ingest_info *)user_data;
1416
1417 return read_dataset(info->product_cursor, "cloud_pressure_precision", harp_type_float,
1418 info->num_scanlines * info->num_pixels, data);
1419 }
1420
1421 static int read_product_cloud_height(void *user_data, harp_array data)
1422 {
1423 ingest_info *info = (ingest_info *)user_data;
1424
1425 return read_dataset(info->product_cursor, "cloud_height_precision", harp_type_float,
1426 info->num_scanlines * info->num_pixels, data);
1427 }
1428
1429 static int read_product_cloud_height_uncertainty(void *user_data, harp_array data)
1430 {
1431 ingest_info *info = (ingest_info *)user_data;
1432
1433 return read_dataset(info->product_cursor, "cloud_height_precision", harp_type_float,
1434 info->num_scanlines * info->num_pixels, data);
1435 }
1436
1437 static int read_product_sulfur_dioxide_layer_height(void *user_data, harp_array data)
1438 {
1439 ingest_info *info = (ingest_info *)user_data;
1440
1441 return read_dataset(info->product_cursor, "sulfur_dioxide_layer_height", harp_type_float,
1442 info->num_scanlines * info->num_pixels, data);
1443 }
1444
1445 static int read_product_sulfur_dioxide_layer_height_uncertainty(void *user_data, harp_array data)
1446 {
1447 ingest_info *info = (ingest_info *)user_data;
1448
1449 return read_dataset(info->product_cursor, "sulfur_dioxide_layer_height_uncertainty", harp_type_float,
1450 info->num_scanlines * info->num_pixels, data);
1451 }
1452
1453 static int read_product_sulfur_dioxide_layer_height_flag(void *user_data, harp_array data)
1454 {
1455 ingest_info *info = (ingest_info *)user_data;
1456
1457 return read_dataset(info->product_cursor, "sulfur_dioxide_layer_height_flag", harp_type_int8,
1458 info->num_scanlines * info->num_pixels, data);
1459 }
1460
1461
1462 /* Field: data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS */
1463
1464 /* Convert **processing-quality flags** from the file to the type/shape
1465 * expected by HARP.
1466 */
1467 static int read_results_processing_quality_flags(void *user_data, harp_array data)
1468 {
1469 ingest_info *info = (ingest_info *)user_data;
1470 coda_cursor cursor = info->product_cursor;
1471 long expected = info->num_scanlines * info->num_pixels;
1472 uint64_t *tmp = NULL;
1473 long i;
1474
1475 /* inside PRODUCT, go to the variable */
1476 if (coda_cursor_goto_record_field_by_name(&cursor, "processing_quality_flags") != 0)
1477 {
1478 harp_set_error(HARP_ERROR_CODA, NULL);
1479 return -1;
1480 }
1481
1482 /* sanity-check element count */
1483 long actual;
1484
1485 if (coda_cursor_get_num_elements(&cursor, &actual) != 0 || actual != expected)
1486 {
1487 harp_set_error(HARP_ERROR_INGESTION, "processing_quality_flags: expected %ld elements, got %ld", expected,
1488 actual);
1489 return -1;
1490 }
1491
1492 /* read uint64 -> tmp */
1493 tmp = malloc(expected * sizeof(*tmp));
1494 if (tmp == NULL)
1495 {
1496 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
1497 expected * sizeof(*tmp), __FILE__, __LINE__);
1498 return -1;
1499 }
1500
1501 if (coda_cursor_read_uint64_array(&cursor, tmp, coda_array_ordering_c) != 0)
1502 {
1503 harp_set_error(HARP_ERROR_CODA, NULL);
1504 free(tmp);
1505 return -1;
1506 }
1507
1508 /* Cast to int32 in place */
1509 for (i = 0; i < expected; i++)
1510 {
1511 data.int32_data[i] = (int32_t)tmp[i];
1512 }
1513
1514 free(tmp);
1515 return 0;
1516 }
1517
1518
1519 static int read_results_water_total_column(void *user_data, harp_array data)
1520 {
1521 ingest_info *info = (ingest_info *)user_data;
1522
1523 return read_dataset(info->detailed_results_cursor, "water_total_column", harp_type_float,
1524 info->num_scanlines * info->num_pixels, data);
1525 }
1526
1527 static int read_results_semiheavy_water_total_column(void *user_data, harp_array data)
1528 {
1529 ingest_info *info = (ingest_info *)user_data;
1530
1531 return read_dataset(info->detailed_results_cursor, "semiheavy_water_total_column", harp_type_float,
1532 info->num_scanlines * info->num_pixels, data);
1533 }
1534
1535 static int read_results_carbon_dioxide_total_column(void *user_data, harp_array data)
1536 {
1537 ingest_info *info = (ingest_info *)user_data;
1538
1539 return read_dataset(info->detailed_results_cursor, "carbon_dioxide_total_column", harp_type_float,
1540 info->num_scanlines * info->num_pixels, data);
1541 }
1542
1543
1544
1545 /* Read the **measured TOA reflectances** that form the Aerosol-Index
1546 * wavelength pair and pack them into a 2-column HARP array.
1547 */
1548 static int read_results_reflectance_measured(void *user_data, harp_array data)
1549 {
1550 ingest_info *info = (ingest_info *)user_data;
1551
1552 const char *variable_name_lower = NULL;
1553 const char *variable_name_upper = NULL;
1554
1555 long num_elements = info->num_scanlines * info->num_pixels;
1556
1557 long i;
1558
1559 /* Allocate temporary buffers */
1560 harp_array refl_lower;
1561 harp_array refl_upper;
1562
1563 /* Determine reflectance variable names based on wavelength_ratio */
1564 switch (info->wavelength_ratio)
1565 {
1566 case 354:
1567 variable_name_lower = "reflectance_354_measured";
1568 variable_name_upper = "reflectance_388_measured";
1569 break;
1570 case 340:
1571 variable_name_lower = "reflectance_340_measured";
1572 variable_name_upper = "reflectance_380_measured";
1573 break;
1574 case 335:
1575 variable_name_lower = "reflectance_335_measured";
1576 variable_name_upper = "reflectance_367_measured";
1577 break;
1578 default:
1579 assert(0);
1580 exit(1);
1581 }
1582
1583
1584 refl_lower.float_data = malloc(num_elements * sizeof(float));
1585 if (refl_lower.float_data == NULL)
1586 {
1587 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
1588 num_elements * sizeof(float), __FILE__, __LINE__);
1589 return -1;
1590 }
1591
1592 refl_upper.float_data = malloc(num_elements * sizeof(float));
1593 if (refl_upper.float_data == NULL)
1594 {
1595 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
1596 num_elements * sizeof(float), __FILE__, __LINE__);
1597 free(refl_lower.float_data);
1598 return -1;
1599 }
1600
1601 /* Check actual dataset sizes */
1602 {
1603 coda_cursor cursor = info->detailed_results_cursor;
1604
1605 if (coda_cursor_goto_record_field_by_name(&cursor, variable_name_lower) == 0)
1606 {
1607 long actual_elements;
1608
1609 coda_cursor_get_num_elements(&cursor, &actual_elements);
1610 if (actual_elements != num_elements)
1611 {
1612 harp_set_error(HARP_ERROR_INGESTION, "dataset has %ld elements; expected %ld",
1613 actual_elements, num_elements);
1614 return -1;
1615 }
1616 }
1617
1618 cursor = info->detailed_results_cursor;
1619 if (coda_cursor_goto_record_field_by_name(&cursor, variable_name_upper) == 0)
1620 {
1621 long actual_elements;
1622
1623 coda_cursor_get_num_elements(&cursor, &actual_elements);
1624 if (actual_elements != num_elements)
1625 {
1626 harp_set_error(HARP_ERROR_INGESTION, "dataset has %ld elements; expected %ld",
1627 actual_elements, num_elements);
1628 return -1;
1629 }
1630 }
1631 }
1632
1633 /* Read the lower reflectance dataset */
1634 if (read_dataset(info->detailed_results_cursor, variable_name_lower, harp_type_float, num_elements, refl_lower) !=
1635 0)
1636 {
1637 harp_set_error(HARP_ERROR_CODA, NULL);
1638 free(refl_lower.float_data);
1639 free(refl_upper.float_data);
1640 return -1;
1641 }
1642
1643 /* Read the upper reflectance dataset */
1644 if (read_dataset(info->detailed_results_cursor, variable_name_upper, harp_type_float, num_elements, refl_upper) !=
1645 0)
1646 {
1647 harp_set_error(HARP_ERROR_CODA, NULL);
1648 free(refl_lower.float_data);
1649 free(refl_upper.float_data);
1650 return -1;
1651 }
1652
1653 /* Fill the final harp_array (2D: {time, spectral=2}) */
1654 for (i = 0; i < num_elements; i++)
1655 {
1656 data.float_data[i] = refl_lower.float_data[i]; /* spectral index 0 */
1657 data.float_data[num_elements + i] = refl_upper.float_data[i]; /* spectral index 1 */
1658 }
1659
1660 /* Clean up */
1661 free(refl_lower.float_data);
1662 free(refl_upper.float_data);
1663
1664 return 0;
1665 }
1666
1667
1668 /* Read the **measured-reflectance precisions** for the two
1669 * wavelengths that form the Aerosol-Index pair.
1670 */
1671 static int read_results_reflectance_precision(void *user_data, harp_array data)
1672 {
1673 ingest_info *info = (ingest_info *)user_data;
1674
1675 const char *var_lo = NULL;
1676 const char *var_hi = NULL;
1677
1678 long n = info->num_scanlines * info->num_pixels;
1679 long i;
1680
1681 harp_array prec_lo, prec_hi;
1682
1683 /* 1) Map wavelength-ratio -> variable names */
1684 switch (info->wavelength_ratio)
1685 {
1686 case 354:
1687 var_lo = "reflectance_precision_354_measured";
1688 var_hi = "reflectance_precision_388_measured";
1689 break;
1690 case 340:
1691 var_lo = "reflectance_precision_340_measured";
1692 var_hi = "reflectance_precision_380_measured";
1693 break;
1694 case 335:
1695 var_lo = "reflectance_precision_335_measured";
1696 var_hi = "reflectance_precision_367_measured";
1697 break;
1698 default:
1699 assert(0);
1700 exit(1);
1701 }
1702
1703 /* 2) Allocate temp buffers */
1704 prec_lo.float_data = malloc(n * sizeof(float));
1705 if (prec_lo.float_data == NULL)
1706 {
1707 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
1708 n * sizeof(float), __FILE__, __LINE__);
1709 return -1;
1710 }
1711 prec_hi.float_data = malloc(n * sizeof(float));
1712 if (prec_hi.float_data == NULL)
1713 {
1714 free(prec_lo.float_data);
1715 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
1716 n * sizeof(float), __FILE__, __LINE__);
1717 return -1;
1718 }
1719
1720 /* 3) Read datasets */
1721 if (read_dataset(info->detailed_results_cursor, var_lo, harp_type_float, n, prec_lo) != 0 ||
1722 read_dataset(info->detailed_results_cursor, var_hi, harp_type_float, n, prec_hi) != 0)
1723 {
1724 harp_set_error(HARP_ERROR_CODA, NULL);
1725 free(prec_lo.float_data);
1726 free(prec_hi.float_data);
1727 return -1; /* read_dataset() already set an error */
1728 }
1729
1730 /* 4) Interleave into output {time, spectral=2} */
1731 for (i = 0; i < n; i++)
1732 {
1733 data.float_data[i] = prec_lo.float_data[i]; /* lambda_low */
1734 data.float_data[n + i] = prec_hi.float_data[i]; /* lambda_high */
1735 }
1736
1737 free(prec_lo.float_data);
1738 free(prec_hi.float_data);
1739 return 0;
1740 }
1741
1742
1743 static int read_co_column_number_density_avk(void *user_data, harp_array data)
1744 {
1745 ingest_info *info = (ingest_info *)user_data;
1746 long dimension[2];
1747
1748 if (read_dataset(info->detailed_results_cursor, "carbon_monoxide_total_column_averaging_kernel", harp_type_float,
1749 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1750 {
1751 return -1;
1752 }
1753 dimension[0] = info->num_scanlines * info->num_pixels;
1754 dimension[1] = info->num_layers;
1755
1756 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1757 }
1758
1759 static int read_results_ch4_total_column_avk(void *user_data, harp_array data)
1760 {
1761 ingest_info *info = (ingest_info *)user_data;
1762 long dimension[2];
1763
1764 if (read_dataset(info->detailed_results_cursor, "methane_total_column_averaging_kernel", harp_type_float,
1765 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1766 {
1767 return -1;
1768 }
1769 dimension[0] = info->num_scanlines * info->num_pixels;
1770 dimension[1] = info->num_layers;
1771
1772 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1773 }
1774
1775 static int read_results_cloud_centre_height(void *user_data, harp_array data)
1776 {
1777 ingest_info *info = (ingest_info *)user_data;
1778
1779 return read_dataset(info->detailed_results_cursor, "cloud_centre_height", harp_type_float,
1780 info->num_scanlines * info->num_pixels, data);
1781 }
1782
1783 static int read_results_cloud_optical_depth(void *user_data, harp_array data)
1784 {
1785 ingest_info *info = (ingest_info *)user_data;
1786
1787 return read_dataset(info->detailed_results_cursor, "cloud_optical_depth", harp_type_float,
1788 info->num_scanlines * info->num_pixels, data);
1789 }
1790
1791 static int read_results_surface_albedo(void *user_data, harp_array data)
1792 {
1793 ingest_info *info = (ingest_info *)user_data;
1794 const char *variable_name = NULL;
1795
1796 if (info->product_type == s5_type_aui)
1797 {
1798 switch (info->wavelength_ratio)
1799 {
1800 case 354:
1801 variable_name = "scene_albedo_388"; /* for 354_388nm (default) */
1802 break;
1803 case 340:
1804 variable_name = "scene_albedo_380"; /* for 340_380nm */
1805 break;
1806 case 335:
1807 variable_name = "scene_albedo_367"; /* for 335_367nm */
1808 break;
1809 default:
1810 assert(0);
1811 exit(1);
1812 }
1813
1814 return read_dataset(info->detailed_results_cursor, variable_name, harp_type_float,
1815 info->num_scanlines * info->num_pixels, data);
1816 }
1817 else if (info->product_type == s5_type_ch4)
1818 {
1819
1820 switch (info->use_ch4_band_options)
1821 {
1822 case 0:
1823 variable_name = "surface_albedo_swir_1"; /* default */
1824 break;
1825 case 1:
1826 variable_name = "surface_albedo_swir_3";
1827 break;
1828 case 2:
1829 variable_name = "surface_albedo_nir_2";
1830 break;
1831 default:
1832 assert(0);
1833 exit(1);
1834 }
1835
1836 return read_dataset(info->detailed_results_cursor, variable_name, harp_type_float,
1837 info->num_scanlines * info->num_pixels, data);
1838
1839 }
1840 else if (info->product_type == s5_type_no2)
1841 {
1842 variable_name = "surface_albedo";
1843 return read_dataset(info->input_data_cursor, variable_name, harp_type_float,
1844 info->num_scanlines * info->num_pixels, data);
1845 }
1846 else if (info->product_type == s5_type_o3)
1847 {
1848 variable_name = "surface_albedo_335";
1849 return read_dataset(info->input_data_cursor, variable_name, harp_type_float,
1850 info->num_scanlines * info->num_pixels, data);
1851 }
1852 else if (info->product_type == s5_type_so2)
1853 {
1854 variable_name = "surface_albedo";
1855 return read_dataset(info->input_data_cursor, variable_name, harp_type_float,
1856 info->num_scanlines * info->num_pixels, data);
1857 }
1858 else if (info->product_type == s5_type_co)
1859 {
1860 variable_name = "surface_albedo";
1861 return read_dataset(info->detailed_results_cursor, variable_name, harp_type_float,
1862 info->num_scanlines * info->num_pixels, data);
1863 }
1864
1865 harp_set_error(HARP_ERROR_CODA, NULL);
1866 return -1;
1867
1868 }
1869
1870
1871 static int read_results_methane_total_column_prefit(void *user_data, harp_array data)
1872 {
1873 ingest_info *info = (ingest_info *)user_data;
1874
1875 return read_dataset(info->detailed_results_cursor, "methane_total_column_prefit", harp_type_float,
1876 info->num_scanlines * info->num_pixels, data);
1877 }
1878
1879
1880 static int read_results_methane_profile_apriori(void *user_data, harp_array data)
1881 {
1882 ingest_info *info = (ingest_info *)user_data;
1883 long dimension[2];
1884
1885 if (read_dataset(info->detailed_results_cursor, "methane_profile_apriori", harp_type_float,
1886 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1887 {
1888 return -1;
1889 }
1890 dimension[0] = info->num_scanlines * info->num_pixels;
1891 dimension[1] = info->num_layers;
1892 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1893 }
1894
1895
1896 static int read_results_carbon_monoxide_profile_apriori(void *user_data, harp_array data)
1897 {
1898 ingest_info *info = (ingest_info *)user_data;
1899 long dimension[2];
1900
1901 if (read_dataset(info->detailed_results_cursor, "carbon_monoxide_profile_apriori", harp_type_float,
1902 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1903 {
1904 return -1;
1905 }
1906
1907 dimension[0] = info->num_scanlines * info->num_pixels;
1908 dimension[1] = info->num_layers;
1909 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1910 }
1911
1912
1913 static int read_results_carbon_dioxide_profile_apriori(void *user_data, harp_array data)
1914 {
1915 ingest_info *info = (ingest_info *)user_data;
1916 long dimension[2];
1917
1918 if (read_dataset(info->detailed_results_cursor, "carbon_dioxide_profile_apriori", harp_type_float,
1919 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1920 {
1921 return -1;
1922 }
1923
1924 dimension[0] = info->num_scanlines * info->num_pixels;
1925 dimension[1] = info->num_layers;
1926 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1927 }
1928
1929
1930 static int read_results_oxygen_total_column_apriori(void *user_data, harp_array data)
1931 {
1932 ingest_info *info = (ingest_info *)user_data;
1933
1934 return read_dataset(info->detailed_results_cursor, "oxygen_total_column_apriori", harp_type_float,
1935 info->num_scanlines * info->num_pixels, data);
1936 }
1937
1938 static int read_results_water_total_column_apriori(void *user_data, harp_array data)
1939 {
1940 ingest_info *info = (ingest_info *)user_data;
1941
1942 return read_dataset(info->detailed_results_cursor, "water_total_column_apriori", harp_type_float,
1943 info->num_scanlines * info->num_pixels, data);
1944 }
1945
1946 static int read_results_dry_air_column(void *user_data, harp_array data)
1947 {
1948 ingest_info *info = (ingest_info *)user_data;
1949
1950 return read_dataset(info->detailed_results_cursor, "dry_air_column", harp_type_float,
1951 info->num_scanlines * info->num_pixels, data);
1952 }
1953
1954 static int read_results_solar_induced_fluorescence(void *user_data, harp_array data)
1955 {
1956 ingest_info *info = (ingest_info *)user_data;
1957
1958 if (read_dataset(info->detailed_results_cursor, "solar_induced_fluorescence", harp_type_float,
1959 info->num_scanlines * info->num_pixels * info->num_spectral, data) != 0)
1960 {
1961 return -1;
1962 }
1963
1964 return 0;
1965 }
1966
1967 static int read_results_pressure(void *user_data, harp_array data)
1968 {
1969 ingest_info *info = (ingest_info *)user_data;
1970 long dimension[2];
1971
1972 if (read_dataset(info->detailed_results_cursor, "pressure", harp_type_float,
1973 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1974 {
1975 return -1;
1976 }
1977 dimension[0] = info->num_scanlines * info->num_pixels;
1978 dimension[1] = info->num_layers;
1979 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1980 }
1981
1982 static int read_results_altitude(void *user_data, harp_array data)
1983 {
1984 ingest_info *info = (ingest_info *)user_data;
1985 long dimension[2];
1986
1987 if (read_dataset(info->detailed_results_cursor, "altitude", harp_type_float,
1988 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
1989 {
1990 return -1;
1991 }
1992 dimension[0] = info->num_scanlines * info->num_pixels;
1993 dimension[1] = info->num_layers;
1994 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
1995 }
1996
1997
1998 static int read_results_aerosol_size(void *user_data, harp_array data)
1999 {
2000 ingest_info *info = (ingest_info *)user_data;
2001
2002 return read_dataset(info->detailed_results_cursor, "aerosol_size", harp_type_float,
2003 info->num_scanlines * info->num_pixels, data);
2004 }
2005
2006
2007 static int read_results_aerosol_particle_column(void *user_data, harp_array data)
2008 {
2009 ingest_info *info = (ingest_info *)user_data;
2010
2011 return read_dataset(info->detailed_results_cursor, "aerosol_particle_column", harp_type_float,
2012 info->num_scanlines * info->num_pixels, data);
2013 }
2014
2015 static int read_results_aerosol_layer_height(void *user_data, harp_array data)
2016 {
2017 ingest_info *info = (ingest_info *)user_data;
2018
2019 return read_dataset(info->detailed_results_cursor, "aerosol_layer_height", harp_type_float,
2020 info->num_scanlines * info->num_pixels, data);
2021 }
2022
2023 static int read_results_nitrogen_dioxide_stratospheric_column_amf(void *user_data, harp_array data)
2024 {
2025 ingest_info *info = (ingest_info *)user_data;
2026
2027 return read_dataset(info->detailed_results_cursor,
2028 "nitrogen_dioxide_stratospheric_column_air_mass_factor",
2029 harp_type_float, info->num_scanlines * info->num_pixels, data);
2030 }
2031
2032 static int read_results_cloud_radiance_fraction(void *user_data, harp_array data)
2033 {
2034 ingest_info *info = (ingest_info *)user_data;
2035
2036 return read_dataset(info->detailed_results_cursor, "cloud_radiance_fraction", harp_type_float,
2037 info->num_scanlines * info->num_pixels, data);
2038 }
2039
2040
2041 static int read_results_nitrogen_dioxide_slant_column(void *user_data, harp_array data)
2042 {
2043 ingest_info *info = (ingest_info *)user_data;
2044
2045 return read_dataset(info->detailed_results_cursor, "nitrogen_dioxide_slant_column", harp_type_float,
2046 info->num_scanlines * info->num_pixels, data);
2047 }
2048
2049
2050 static int read_results_nitrogen_dioxide_slant_column_uncertainty(void *user_data, harp_array data)
2051 {
2052 ingest_info *info = (ingest_info *)user_data;
2053
2054 return read_dataset(info->detailed_results_cursor, "nitrogen_dioxide_slant_column_uncertainty", harp_type_float,
2055 info->num_scanlines * info->num_pixels, data);
2056 }
2057
2058
2059 static int read_results_ozone_slant_column(void *user_data, harp_array data)
2060 {
2061 ingest_info *info = (ingest_info *)user_data;
2062
2063 return read_dataset(info->detailed_results_cursor, "ozone_slant_column", harp_type_float,
2064 info->num_scanlines * info->num_pixels, data);
2065 }
2066
2067
2068 static int read_results_ozone_slant_column_uncertainty(void *user_data, harp_array data)
2069 {
2070 ingest_info *info = (ingest_info *)user_data;
2071
2072 if (info->product_type == s5_type_o3)
2073 {
2074 return read_dataset(info->detailed_results_cursor, "ozone_slant_column_precision", harp_type_float,
2075 info->num_scanlines * info->num_pixels, data);
2076 }
2077 else
2078 {
2079 return read_dataset(info->detailed_results_cursor, "ozone_slant_column_uncertainty", harp_type_float,
2080 info->num_scanlines * info->num_pixels, data);
2081 }
2082
2083 harp_set_error(HARP_ERROR_CODA, NULL);
2084 return -1;
2085 }
2086
2087 static int read_results_water_vapor_slant_column(void *user_data, harp_array data)
2088 {
2089 ingest_info *info = (ingest_info *)user_data;
2090
2091 return read_dataset(info->detailed_results_cursor, "water_vapor_slant_column", harp_type_float,
2092 info->num_scanlines * info->num_pixels, data);
2093 }
2094
2095 static int read_results_water_vapor_slant_column_uncertainty(void *user_data, harp_array data)
2096 {
2097 ingest_info *info = (ingest_info *)user_data;
2098
2099 return read_dataset(info->detailed_results_cursor, "water_vapor_slant_column_uncertainty", harp_type_float,
2100 info->num_scanlines * info->num_pixels, data);
2101 }
2102
2103 static int read_results_water_liquid_slant_column(void *user_data, harp_array data)
2104 {
2105 ingest_info *info = (ingest_info *)user_data;
2106
2107 return read_dataset(info->detailed_results_cursor, "water_liquid_slant_column", harp_type_float,
2108 info->num_scanlines * info->num_pixels, data);
2109 }
2110
2111 static int read_results_nitrogen_dioxide_stratospheric_column(void *user_data, harp_array data)
2112 {
2113 ingest_info *info = (ingest_info *)user_data;
2114
2115 return read_dataset(info->detailed_results_cursor, "nitrogen_dioxide_stratospheric_column", harp_type_float,
2116 info->num_scanlines * info->num_pixels, data);
2117 }
2118
2119
2120 static int read_results_nitrogen_dioxide_stratospheric_column_uncertainty(void *user_data, harp_array data)
2121 {
2122 ingest_info *info = (ingest_info *)user_data;
2123
2124 return read_dataset(info->detailed_results_cursor, "nitrogen_dioxide_stratospheric_column_uncertainty",
2125 harp_type_float, info->num_scanlines * info->num_pixels, data);
2126 }
2127
2128 static int read_results_nitrogen_dioxide_total_column(void *user_data, harp_array data)
2129 {
2130 ingest_info *info = (ingest_info *)user_data;
2131 const char *variable_name = NULL;
2132
2133 if (info->product_type == s5_type_no2)
2134 {
2135 switch (info->no2_column_option)
2136 {
2137 case 0:
2138 variable_name = "nitrogen_dioxide_total_column";
2139 break;
2140 case 1:
2141 variable_name = "nitrogen_dioxide_summed_total_column";
2142 break;
2143 default:
2144 assert(0);
2145 exit(1);
2146 }
2147
2148 return read_dataset(info->detailed_results_cursor,
2149 variable_name, harp_type_float, info->num_scanlines * info->num_pixels, data);
2150 }
2151
2152 harp_set_error(HARP_ERROR_CODA, NULL);
2153 return -1;
2154 }
2155
2156 static int read_results_nitrogen_dioxide_total_column_uncertainty(void *user_data, harp_array data)
2157 {
2158 ingest_info *info = (ingest_info *)user_data;
2159 const char *variable_name = NULL;
2160
2161 if (info->product_type == s5_type_no2)
2162 {
2163 switch (info->no2_column_option)
2164 {
2165 case 0:
2166 variable_name = "nitrogen_dioxide_total_column_uncertainty";
2167 break;
2168 case 1:
2169 variable_name = "nitrogen_dioxide_summed_total_column_uncertainty";
2170 break;
2171 default:
2172 assert(0);
2173 exit(1);
2174 }
2175
2176 return read_dataset(info->detailed_results_cursor,
2177 variable_name, harp_type_float, info->num_scanlines * info->num_pixels, data);
2178 }
2179
2180 harp_set_error(HARP_ERROR_CODA, NULL);
2181 return -1;
2182 }
2183
2184 static int read_results_effective_temperature(void *user_data, harp_array data)
2185 {
2186 ingest_info *info = (ingest_info *)user_data;
2187
2188 return read_dataset(info->detailed_results_cursor, "effective_temperature", harp_type_float,
2189 info->num_scanlines * info->num_pixels, data);
2190 }
2191
2192 static int read_results_effective_scene_amf(void *user_data, harp_array data)
2193 {
2194 ingest_info *info = (ingest_info *)user_data;
2195
2196 return read_dataset(info->detailed_results_cursor, "effective_scene_air_mass_factor", harp_type_float,
2197 info->num_scanlines * info->num_pixels, data);
2198 }
2199
2200 static int read_results_effective_scene_albedo(void *user_data, harp_array data)
2201 {
2202 ingest_info *info = (ingest_info *)user_data;
2203
2204 return read_dataset(info->detailed_results_cursor, "effective_scene_albedo", harp_type_float,
2205 info->num_scanlines * info->num_pixels, data);
2206 }
2207
2208 static int read_results_ozone_total_column_avk(void *user_data, harp_array data)
2209 {
2210 ingest_info *info = (ingest_info *)user_data;
2211 long dimension[2];
2212
2213 if (read_dataset(info->detailed_results_cursor, "ozone_total_column_averaging_kernel", harp_type_float,
2214 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
2215 {
2216 return -1;
2217 }
2218
2219 dimension[0] = info->num_scanlines * info->num_pixels;
2220 dimension[1] = info->num_layers;
2221
2222 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
2223 }
2224
2225 static int read_results_ozone_profile_apriori(void *user_data, harp_array data)
2226 {
2227 ingest_info *info = (ingest_info *)user_data;
2228 long dimension[2];
2229
2230 if (read_dataset(info->detailed_results_cursor, "ozone_profile_apriori", harp_type_float,
2231 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
2232 {
2233 return -1;
2234 }
2235
2236 dimension[0] = info->num_scanlines * info->num_pixels;
2237 dimension[1] = info->num_layers;
2238
2239 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
2240 }
2241
2242 static int read_results_pressure_grid(void *user_data, harp_array data)
2243 {
2244 ingest_info *info = (ingest_info *)user_data;
2245 long dimension[2];
2246
2247 if (read_dataset(info->detailed_results_cursor, "pressure_grid", harp_type_float,
2248 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
2249 {
2250 return -1;
2251 }
2252
2253 dimension[0] = info->num_scanlines * info->num_pixels;
2254 dimension[1] = info->num_layers;
2255
2256 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
2257 }
2258
2259 static int read_results_scene_albedo(void *user_data, harp_array data)
2260 {
2261 ingest_info *info = (ingest_info *)user_data;
2262
2263 return read_dataset(info->detailed_results_cursor, "scene_albedo", harp_type_float,
2264 info->num_scanlines * info->num_pixels, data);
2265 }
2266
2267
2268 static int read_results_scene_albedo_uncertainty(void *user_data, harp_array data)
2269 {
2270 ingest_info *info = (ingest_info *)user_data;
2271
2272 return read_dataset(info->detailed_results_cursor, "scene_albedo_precision", harp_type_float,
2273 info->num_scanlines * info->num_pixels, data);
2274 }
2275
2276 static int read_results_scene_pressure(void *user_data, harp_array data)
2277 {
2278 ingest_info *info = (ingest_info *)user_data;
2279
2280 return read_dataset(info->detailed_results_cursor, "scene_pressure", harp_type_float,
2281 info->num_scanlines * info->num_pixels, data);
2282 }
2283
2284
2285 static int read_results_scene_pressure_uncertainty(void *user_data, harp_array data)
2286 {
2287 ingest_info *info = (ingest_info *)user_data;
2288
2289 return read_dataset(info->detailed_results_cursor, "scene_pressure_precision", harp_type_float,
2290 info->num_scanlines * info->num_pixels, data);
2291 }
2292
2293 static int read_results_scene_height(void *user_data, harp_array data)
2294 {
2295 ingest_info *info = (ingest_info *)user_data;
2296
2297 return read_dataset(info->detailed_results_cursor, "scene_height", harp_type_float,
2298 info->num_scanlines * info->num_pixels, data);
2299 }
2300
2301
2302 static int read_results_scene_height_uncertainty(void *user_data, harp_array data)
2303 {
2304 ingest_info *info = (ingest_info *)user_data;
2305
2306 return read_dataset(info->detailed_results_cursor, "scene_height_precision", harp_type_float,
2307 info->num_scanlines * info->num_pixels, data);
2308 }
2309
2310 static int read_results_cloud_albedo(void *user_data, harp_array data)
2311 {
2312 ingest_info *info = (ingest_info *)user_data;
2313
2314 return read_dataset(info->detailed_results_cursor, "cloud_albedo", harp_type_float,
2315 info->num_scanlines * info->num_pixels, data);
2316 }
2317
2318
2319 static int read_results_cloud_albedo_uncertainty(void *user_data, harp_array data)
2320 {
2321 ingest_info *info = (ingest_info *)user_data;
2322
2323 return read_dataset(info->detailed_results_cursor, "cloud_albedo_precision", harp_type_float,
2324 info->num_scanlines * info->num_pixels, data);
2325 }
2326
2327 static int read_results_sulfur_dioxide_slant_column(void *user_data, harp_array data)
2328 {
2329 ingest_info *info = (ingest_info *)user_data;
2330
2331 return read_dataset(info->detailed_results_cursor, "sulfur_dioxide_slant_column", harp_type_float,
2332 info->num_scanlines * info->num_pixels, data);
2333 }
2334
2335 static int read_results_sulfur_dioxide_slant_column_precision(void *user_data, harp_array data)
2336 {
2337 ingest_info *info = (ingest_info *)user_data;
2338
2339 return read_dataset(info->detailed_results_cursor, "sulfur_dioxide_slant_column_precision", harp_type_float,
2340 info->num_scanlines * info->num_pixels, data);
2341 }
2342
2343 static int read_results_sulfur_dioxide_slant_column_trueness(void *user_data, harp_array data)
2344 {
2345 ingest_info *info = (ingest_info *)user_data;
2346
2347 return read_dataset(info->detailed_results_cursor, "sulfur_dioxide_slant_column_trueness", harp_type_float,
2348 info->num_scanlines * info->num_pixels, data);
2349 }
2350
2351 static int read_results_sulfur_dioxide_total_column_avk(void *user_data, harp_array data)
2352 {
2353 ingest_info *info = (ingest_info *)user_data;
2354 long dimension[2];
2355
2356 if (read_dataset(info->detailed_results_cursor, "sulfur_dioxide_total_column_averaging_kernel", harp_type_float,
2357 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
2358 {
2359 return -1;
2360 }
2361 dimension[0] = info->num_scanlines * info->num_pixels;
2362 dimension[1] = info->num_layers;
2363 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
2364 }
2365
2366 static int read_results_sulfur_dioxide_layer_pressure(void *user_data, harp_array data)
2367 {
2368 ingest_info *info = (ingest_info *)user_data;
2369
2370 return read_dataset(info->detailed_results_cursor, "sulfur_dioxide_layer_pressure", harp_type_float,
2371 info->num_scanlines * info->num_pixels, data);
2372 }
2373
2374 static int read_results_sulfur_dioxide_layer_pressure_uncertainty(void *user_data, harp_array data)
2375 {
2376 ingest_info *info = (ingest_info *)user_data;
2377
2378 return read_dataset(info->detailed_results_cursor, "sulfur_dioxide_layer_pressure_uncertainty", harp_type_float,
2379 info->num_scanlines * info->num_pixels, data);
2380 }
2381
2382 /* Field: data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS */
2383
2384 static int read_geolocation_latitude_bounds(void *user_data, harp_array data)
2385 {
2386 ingest_info *info = (ingest_info *)user_data;
2387
2388 return read_dataset(info->geolocation_cursor, "latitude_bounds", harp_type_float,
2389 info->num_scanlines * info->num_pixels * info->num_corners, data);
2390 }
2391
2392 static int read_geolocation_longitude_bounds(void *user_data, harp_array data)
2393 {
2394 ingest_info *info = (ingest_info *)user_data;
2395
2396 return read_dataset(info->geolocation_cursor, "longitude_bounds", harp_type_float,
2397 info->num_scanlines * info->num_pixels * info->num_corners, data);
2398 }
2399
2400 static int read_geolocation_satellite_altitude(void *user_data, harp_array data)
2401 {
2402 ingest_info *info = (ingest_info *)user_data;
2403
2404 if (read_dataset(info->geolocation_cursor, "satellite_altitude", harp_type_float, info->num_scanlines, data) != 0)
2405 {
2406 return -1;
2407 }
2408
2409 broadcast_array_float(info->num_scanlines, info->num_pixels, data.float_data);
2410
2411 return 0;
2412 }
2413
2414 static int read_geolocation_satellite_latitude(void *user_data, harp_array data)
2415 {
2416 ingest_info *info = (ingest_info *)user_data;
2417
2418 if (read_dataset(info->geolocation_cursor, "satellite_latitude", harp_type_float, info->num_scanlines, data) != 0)
2419 {
2420 return -1;
2421 }
2422
2423 broadcast_array_float(info->num_scanlines, info->num_pixels, data.float_data);
2424
2425 return 0;
2426 }
2427
2428
2429 static int read_geolocation_satellite_longitude(void *user_data, harp_array data)
2430 {
2431 ingest_info *info = (ingest_info *)user_data;
2432
2433 if (read_dataset(info->geolocation_cursor, "satellite_longitude", harp_type_float, info->num_scanlines, data) != 0)
2434 {
2435 return -1;
2436 }
2437
2438 broadcast_array_float(info->num_scanlines, info->num_pixels, data.float_data);
2439
2440 return 0;
2441 }
2442
2443 static int read_geolocation_satellite_orbit_phase(void *user_data, harp_array data)
2444 {
2445 ingest_info *info = (ingest_info *)user_data;
2446
2447 return read_dataset(info->geolocation_cursor, "satellite_orbit_phase", harp_type_double, info->num_scanlines, data);
2448 }
2449
2450
2451 static int read_geolocation_solar_zenith_angle(void *user_data, harp_array data)
2452 {
2453 ingest_info *info = (ingest_info *)user_data;
2454
2455 return read_dataset(info->geolocation_cursor, "solar_zenith_angle", harp_type_float,
2456 info->num_scanlines * info->num_pixels, data);
2457 }
2458
2459 static int read_geolocation_solar_azimuth_angle(void *user_data, harp_array data)
2460 {
2461 ingest_info *info = (ingest_info *)user_data;
2462
2463 return read_dataset(info->geolocation_cursor, "solar_azimuth_angle", harp_type_float,
2464 info->num_scanlines * info->num_pixels, data);
2465 }
2466
2467
2468 static int read_geolocation_viewing_azimuth_angle(void *user_data, harp_array data)
2469 {
2470 ingest_info *info = (ingest_info *)user_data;
2471
2472 return read_dataset(info->geolocation_cursor, "viewing_azimuth_angle", harp_type_float,
2473 info->num_scanlines * info->num_pixels, data);
2474 }
2475
2476
2477 static int read_geolocation_viewing_zenith_angle(void *user_data, harp_array data)
2478 {
2479 ingest_info *info = (ingest_info *)user_data;
2480
2481 return read_dataset(info->geolocation_cursor, "viewing_zenith_angle", harp_type_float,
2482 info->num_scanlines * info->num_pixels, data);
2483 }
2484
2485
2486 /* Field: data/PRODUCT/SUPPORT_DATA/INPUT_DATA */
2487
2488 static int read_input_surface_altitude(void *user_data, harp_array data)
2489 {
2490 ingest_info *info = (ingest_info *)user_data;
2491
2492 return read_dataset(info->input_data_cursor, "surface_altitude", harp_type_float,
2493 info->num_scanlines * info->num_pixels, data);
2494 }
2495
2496 static int read_input_surface_altitude_precision(void *user_data, harp_array data)
2497 {
2498 ingest_info *info = (ingest_info *)user_data;
2499 const char *variable_name = NULL;
2500
2501 if (info->product_type == s5_type_no2)
2502 {
2503 variable_name = "surface_altitude_uncertainty";
2504 }
2505 else
2506 {
2507 variable_name = "surface_altitude_precision";
2508 }
2509 return read_dataset(info->input_data_cursor, variable_name, harp_type_float,
2510 info->num_scanlines * info->num_pixels, data);
2511 }
2512
2513 static int read_input_surface_pressure(void *user_data, harp_array data)
2514 {
2515 ingest_info *info = (ingest_info *)user_data;
2516
2517 return read_dataset(info->input_data_cursor, "surface_pressure", harp_type_float,
2518 info->num_scanlines * info->num_pixels, data);
2519 }
2520
2521 static int read_input_aerosol_index(void *user_data, harp_array data)
2522 {
2523 ingest_info *info = (ingest_info *)user_data;
2524
2525 if (info->product_type == s5_type_o3 || info->product_type == s5_type_so2)
2526 {
2527 return read_dataset(info->input_data_cursor, "aerosol_index_340_380", harp_type_float,
2528 info->num_scanlines * info->num_pixels, data);
2529 }
2530 else
2531 {
2532 return read_dataset(info->input_data_cursor, "aerosol_index_354_388", harp_type_float,
2533 info->num_scanlines * info->num_pixels, data);
2534 }
2535 }
2536
2537 static int read_input_cloud_albedo(void *user_data, harp_array data)
2538 {
2539 ingest_info *info = (ingest_info *)user_data;
2540
2541 return read_dataset(info->input_data_cursor, "cloud_albedo", harp_type_float,
2542 info->num_scanlines * info->num_pixels, data);
2543 }
2544
2545 static int read_input_cloud_albedo_uncertainty(void *user_data, harp_array data)
2546 {
2547 ingest_info *info = (ingest_info *)user_data;
2548
2549 return read_dataset(info->input_data_cursor, "cloud_albedo_uncertainty", harp_type_float,
2550 info->num_scanlines * info->num_pixels, data);
2551 }
2552
2553 static int read_input_cloud_pressure(void *user_data, harp_array data)
2554 {
2555 ingest_info *info = (ingest_info *)user_data;
2556
2557 return read_dataset(info->input_data_cursor, "cloud_pressure", harp_type_float,
2558 info->num_scanlines * info->num_pixels, data);
2559 }
2560
2561 static int read_input_effective_cloud_fraction(void *user_data, harp_array data)
2562 {
2563 ingest_info *info = (ingest_info *)user_data;
2564
2565 return read_dataset(info->input_data_cursor, "effective_cloud_fraction", harp_type_float,
2566 info->num_scanlines * info->num_pixels, data);
2567 }
2568
2569 static int read_input_scene_albedo(void *user_data, harp_array data)
2570 {
2571 ingest_info *info = (ingest_info *)user_data;
2572
2573 return read_dataset(info->input_data_cursor, "scene_albedo", harp_type_float,
2574 info->num_scanlines * info->num_pixels, data);
2575 }
2576
2577 static int read_input_scene_albedo_uncertainty(void *user_data, harp_array data)
2578 {
2579 ingest_info *info = (ingest_info *)user_data;
2580
2581 return read_dataset(info->input_data_cursor, "scene_albedo_uncertainty", harp_type_float,
2582 info->num_scanlines * info->num_pixels, data);
2583 }
2584
2585 static int read_input_scene_pressure(void *user_data, harp_array data)
2586 {
2587 ingest_info *info = (ingest_info *)user_data;
2588
2589 return read_dataset(info->input_data_cursor, "scene_pressure", harp_type_float,
2590 info->num_scanlines * info->num_pixels, data);
2591 }
2592
2593 static int read_input_scene_pressure_uncertainty(void *user_data, harp_array data)
2594 {
2595 ingest_info *info = (ingest_info *)user_data;
2596
2597 return read_dataset(info->input_data_cursor, "scene_pressure_uncertainty", harp_type_float,
2598 info->num_scanlines * info->num_pixels, data);
2599 }
2600
2601 static int read_input_tropopause_pressure(void *user_data, harp_array data)
2602 {
2603 ingest_info *info = (ingest_info *)user_data;
2604
2605 return read_dataset(info->input_data_cursor, "tropopause_pressure", harp_type_float,
2606 info->num_scanlines * info->num_pixels, data);
2607 }
2608
2609 static int read_input_sulfur_dioxide_profile_apriori(void *user_data, harp_array data)
2610 {
2611 ingest_info *info = (ingest_info *)user_data;
2612 long dimension[2];
2613
2614 if (read_dataset(info->input_data_cursor, "sulfur_dioxide_profile_apriori", harp_type_float,
2615 info->num_scanlines * info->num_pixels * info->num_layers, data) != 0)
2616 {
2617 return -1;
2618 }
2619
2620 dimension[0] = info->num_scanlines * info->num_pixels;
2621 dimension[1] = info->num_layers;
2622 return harp_array_invert(harp_type_float, 1, 2, dimension, data);
2623 }
2624
2625 static int read_input_cloud_height(void *user_data, harp_array data)
2626 {
2627 ingest_info *info = (ingest_info *)user_data;
2628
2629 return read_dataset(info->input_data_cursor, "cloud_height", harp_type_float,
2630 info->num_scanlines * info->num_pixels, data);
2631 }
2632
2633 static int read_input_ozone_total_column(void *user_data, harp_array data)
2634 {
2635 ingest_info *info = (ingest_info *)user_data;
2636
2637 return read_dataset(info->input_data_cursor, "ozone_total_column", harp_type_float,
2638 info->num_scanlines * info->num_pixels, data);
2639 }
2640
2641 /* Helper function */
2642 static int read_sea_ice_fraction_from_flag(void *user_data, const char *variable_name, harp_array data)
2643 {
2644 ingest_info *info = (ingest_info *)user_data;
2645 long i;
2646
2647 if (read_dataset(info->input_data_cursor, variable_name, harp_type_float, info->num_scanlines * info->num_pixels,
2648 data) != 0)
2649 {
2650 return -1;
2651 }
2652 for (i = 0; i < info->num_scanlines * info->num_pixels; i++)
2653 {
2654 if (data.float_data[i] > 0 && data.float_data[i] <= 100)
2655 {
2656 data.float_data[i] /= (float)100.0;
2657 }
2658 else
2659 {
2660 data.float_data[i] = 0.0;
2661 }
2662 }
2663
2664 return 0;
2665 }
2666
2667 /* Helper function */
2668 static int read_snow_ice_type_from_flag(void *user_data, const char *variable_name, harp_array data)
2669 {
2670 ingest_info *info = (ingest_info *)user_data;
2671 long i;
2672
2673 if (read_dataset(info->input_data_cursor, variable_name, harp_type_int8, info->num_scanlines * info->num_pixels,
2674 data) != 0)
2675 {
2676 return -1;
2677 }
2678 for (i = 0; i < info->num_scanlines * info->num_pixels; i++)
2679 {
2680 if (data.int8_data[i] < 0)
2681 {
2682 if (data.int8_data[i] == -1) /* == int8 representation of 255 */
2683 {
2684 data.int8_data[i] = 4;
2685 }
2686 else
2687 {
2688 data.int8_data[i] = -1;
2689 }
2690 }
2691 else if (data.int8_data[i] > 0)
2692 {
2693 if (data.int8_data[i] <= 100) /* 1..100 is mapped to sea_ice */
2694 {
2695 data.int8_data[i] = 1;
2696 }
2697 else if (data.int8_data[i] == 101)
2698 {
2699 data.int8_data[i] = 2;
2700 }
2701 else if (data.int8_data[i] == 103)
2702 {
2703 data.int8_data[i] = 3;
2704 }
2705 else
2706 {
2707 data.int8_data[i] = -1;
2708 }
2709 }
2710 }
2711
2712 return 0;
2713 }
2714
2715
2716 static int read_snow_ice_type(void *user_data, harp_array data)
2717 {
2718 return read_snow_ice_type_from_flag(user_data, "snow_ice_flag", data);
2719 }
2720
2721 static int read_sea_ice_fraction(void *user_data, harp_array data)
2722 {
2723 return read_sea_ice_fraction_from_flag(user_data, "snow_ice_flag", data);
2724 }
2725
2726 /* Helper function */
2727 static int read_no2_pressure_bounds(void *user_data, harp_array data)
2728 {
2729 ingest_info *info = (ingest_info *)user_data;
2730
2731 /* Dimensions */
2732 const long num_profiles = info->num_scanlines * info->num_pixels; /* time dimension */
2733 const long num_layers = info->num_layers; /* 137 for S-5 simulated */
2734 const long num_levels = num_layers + 1; /* 138 level boundaries */
2735 harp_array psurf; /* surface pressure for every pixel */
2736
2737 /* Temporary buffers for a, b and surface-pressure */
2738 harp_array coef_a;
2739 harp_array coef_b;
2740
2741 long p;
2742
2743 coef_a.ptr = malloc(num_levels * sizeof(double));
2744 if (coef_a.ptr == NULL)
2745 {
2746 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
2747 num_levels * sizeof(double), __FILE__, __LINE__);
2748 return -1;
2749 }
2750
2751
2752 coef_b.ptr = malloc(num_levels * sizeof(double));
2753 if (coef_b.ptr == NULL)
2754 {
2755 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
2756 num_levels * sizeof(double), __FILE__, __LINE__);
2757 free(coef_a.ptr);
2758 return -1;
2759 }
2760
2761 psurf.ptr = malloc(num_profiles * sizeof(double));
2762 if (psurf.ptr == NULL)
2763 {
2764 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
2765 num_levels * sizeof(double), __FILE__, __LINE__);
2766 free(coef_a.ptr);
2767 free(coef_b.ptr);
2768 return -1;
2769 }
2770
2771 /* Read the three datasets */
2772 if (read_dataset(info->input_data_cursor, "pressure_coefficient_a",
2773 harp_type_double, num_levels, coef_a) != 0 ||
2774 read_dataset(info->input_data_cursor, "pressure_coefficient_b",
2775 harp_type_double, num_levels, coef_b) != 0 ||
2776 read_dataset(info->input_data_cursor, "surface_pressure", harp_type_double, num_profiles, psurf) != 0)
2777 {
2778 free(coef_a.ptr);
2779 free(coef_b.ptr);
2780 free(psurf.ptr);
2781 return -1;
2782 }
2783
2784 /* Build the (layer,2) pressure-bounds array.
2785 * Every access uses data.double_data[idx]; no helper pointer.
2786 * Outer loop: p = 0 .. num_profiles-1
2787 * Inner loop: j = 0 .. num_layers-1
2788 */
2789 for (p = 0; p < num_profiles; p++)
2790 {
2791 double sp = psurf.double_data[p]; /* surface pressure for profile p */
2792
2793 long j;
2794
2795 for (j = 0; j < num_layers; j++)
2796 {
2797 /* Flat index in the {profile, layer, upper/lower} layout */
2798 long upper_idx = (p * num_layers * 2) + (j * 2); /* upper boundary */
2799 long lower_idx = upper_idx + 1; /* lower boundary */
2800
2801 /* upper bound of layer j */
2802 data.double_data[upper_idx] = coef_a.double_data[j] + coef_b.double_data[j] * sp;
2803
2804 /* lower bound of layer j (equal to upper of j+1) */
2805 data.double_data[lower_idx] = coef_a.double_data[j + 1] + coef_b.double_data[j + 1] * sp;
2806 }
2807
2808 /* Clamp top-of-atmosphere pressure to at least 1 mPa */
2809 long toa_idx = (p * num_layers * 2) + ((num_layers - 1) * 2);
2810
2811 if (data.double_data[toa_idx] < 1e-3)
2812 {
2813 data.double_data[toa_idx] = 1e-3;
2814 }
2815 }
2816
2817 free(coef_a.ptr);
2818 free(coef_b.ptr);
2819 free(psurf.ptr);
2820 return 0;
2821 }
2822
2823 static int read_input_surface_classification(void *user_data, harp_array data)
2824 {
2825 ingest_info *info = (ingest_info *)user_data;
2826
2827 return read_dataset(info->input_data_cursor, "surface_classification", harp_type_int8,
2828 info->num_scanlines * info->num_pixels, data);
2829 }
2830
2831 /*
2832 * Variables' Registration Routines
2833 */
2834
2835 static void register_core_variables(harp_product_definition *product_definition, int include_validity)
2836 {
2837 const char *path;
2838 const char *description;
2839 harp_variable_definition *variable_definition;
2840 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
2841
2842 /* datetime (center of scanline) */
2843 description = "time of the measurement";
2844 variable_definition =
2845 harp_ingestion_register_variable_full_read(product_definition, "datetime", harp_type_double, 1,
2846 dimension_type_1d, NULL, description, "seconds since 2020-01-01",
2847 NULL, read_datetime);
2848 path = "/data/PRODUCT/time, /data/PRODUCT/delta_time[]";
2849 description = "time converted from days since 2020-01-01 to seconds since 2020-01-01 (using 86400 seconds per "
2850 "day) and delta_time added; the time associated with a scanline is repeated for each pixel in the scanline";
2851 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
2852
2853 /* datetime_length */
2854 description = "measurement duration";
2855 variable_definition =
2856 harp_ingestion_register_variable_full_read(product_definition, "datetime_length", harp_type_double, 0, NULL,
2857 NULL, description, "s", NULL, read_datetime_length);
2858
2859 /* two alternative paths, selected by the user option */
2860 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, "/data/PRODUCT/delta_time[]",
2861 "delta_time[1] - delta_time[0]");
2862
2863 /* orbit_index */
2864 description = "absolute orbit number";
2865 variable_definition =
2866 harp_ingestion_register_variable_full_read(product_definition, "orbit_index", harp_type_int32, 0, NULL, NULL,
2867 description, NULL, NULL, read_orbit_index);
2868 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, "/@orbit_start", NULL);
2869
2870
2871 if (include_validity)
2872 {
2873 /* validity */
2874 description = "processing quality flag";
2875 variable_definition =
2876 harp_ingestion_register_variable_full_read(product_definition, "validity", harp_type_int32, 1,
2877 dimension_type_1d, NULL, description, NULL, NULL,
2878 read_results_processing_quality_flags);
2879 path = "/data/PRODUCT/processing_quality_flags[]";
2880 description = "the uint64 data is cast to int32";
2881 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
2882 }
2883 }
2884
2885 /* CLD product: core variables for BAND-3A / BAND-3C */
2886 static void register_core_variables_cld(harp_product_definition *product_definition, int include_validity)
2887 {
2888 const char *description;
2889 harp_variable_definition *var;
2890 harp_dimension_type dim_time[1] = { harp_dimension_time };
2891
2892 /* datetime (center of scanline) */
2893 description = "time of the measurement";
2894 var = harp_ingestion_register_variable_full_read(product_definition, "datetime", harp_type_double, 1,
2895 dim_time, NULL, description, "seconds since 2020-01-01", NULL,
2896 read_datetime);
2897
2898 /* two alternative paths, selected by the user option */
2899 description = "time converted from days since 2020-01-01 to seconds since 2020-01-01 (using 86400 seconds per "
2900 "day) and delta_time added; the time associated with a scanline is repeated for each pixel in the scanline";
2901 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
2902 "/data/PRODUCT_BAND3A/time, /data/PRODUCT_BAND3A/delta_time[]", description);
2903
2904 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
2905 "/data/PRODUCT_BAND3C/time, /data/PRODUCT_BAND3C/delta_time[]", description);
2906
2907 /* datetime_length */
2908 description = "measurement duration";
2909 var = harp_ingestion_register_variable_full_read(product_definition, "datetime_length", harp_type_double, 0,
2910 NULL, NULL, description, "s", NULL, read_datetime_length);
2911
2912 /* two alternative paths, selected by the user option */
2913 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
2914 "/data/PRODUCT_BAND3A/delta_time[]", "delta_time[1] - delta_time[0]");
2915
2916 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
2917 "/data/PRODUCT_BAND3C/delta_time[]", "delta_time[1] - delta_time[0]");
2918
2919 /* orbit_index */
2920 description = "absolute orbit number";
2921 var = harp_ingestion_register_variable_full_read(product_definition, "orbit_index", harp_type_int32, 0, NULL, NULL,
2922 description, NULL, NULL, read_orbit_index);
2923 harp_variable_definition_add_mapping(var, NULL, NULL, "/@orbit_start", NULL);
2924
2925 /* validity */
2926 if (include_validity)
2927 {
2928 description = "processing quality flag";
2929 var = harp_ingestion_register_variable_full_read(product_definition, "validity", harp_type_int32, 1, dim_time,
2930 NULL, description, NULL, NULL,
2931 read_results_processing_quality_flags);
2932
2933 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
2934 "/data/PRODUCT_BAND3A/processing_quality_flags[]",
2935 "the uint64 data is cast to int32");
2936
2937 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
2938 "/data/PRODUCT_BAND3C/processing_quality_flags[]",
2939 "the uint64 data is cast to int32");
2940 }
2941 }
2942
2943
2944
2945 static void register_geolocation_variables(harp_product_definition *product_definition)
2946 {
2947 const char *path;
2948 const char *description;
2949 harp_variable_definition *variable_definition;
2950 harp_dimension_type dimension_type[1] = { harp_dimension_time };
2951
2952 /* latitude */
2953 description = "latitude of the ground pixel center (WGS84)";
2954 variable_definition =
2955 harp_ingestion_register_variable_full_read(product_definition, "latitude", harp_type_float, 1, dimension_type,
2956 NULL, description, "degree_north", NULL, read_product_latitude);
2957 harp_variable_definition_set_valid_range_float(variable_definition, -90.0f, 90.0f);
2958 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/latitude[]";
2959 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
2960
2961 /* longitude */
2962 description = "longitude of the ground pixel center (WGS84)";
2963 variable_definition =
2964 harp_ingestion_register_variable_full_read(product_definition, "longitude", harp_type_float, 1, dimension_type,
2965 NULL, description, "degree_east", NULL, read_product_longitude);
2966 harp_variable_definition_set_valid_range_float(variable_definition, -180.0f, 180.0f);
2967 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/longitude[]";
2968 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
2969 }
2970
2971 /* CLD product: geolocation (BAND-3A / BAND-3C) */
2972 static void register_geolocation_variables_cld(harp_product_definition *product_definition)
2973 {
2974 const char *description;
2975 harp_variable_definition *var;
2976 harp_dimension_type dim_time[1] = { harp_dimension_time };
2977
2978 /* latitude */
2979 description = "latitude of the ground-pixel centre (WGS-84)";
2980 var = harp_ingestion_register_variable_full_read(product_definition, "latitude", harp_type_float, 1, dim_time, NULL,
2981 description, "degree_north", NULL, read_product_latitude);
2982
2983 harp_variable_definition_set_valid_range_float(var, -90.0f, 90.0f);
2984
2985 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
2986 "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/latitude[]", NULL);
2987
2988 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
2989 "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/latitude[]", NULL);
2990
2991 /* longitude */
2992 description = "longitude of the ground-pixel centre (WGS-84)";
2993 var = harp_ingestion_register_variable_full_read(product_definition, "longitude", harp_type_float, 1, dim_time,
2994 NULL, description, "degree_east", NULL, read_product_longitude);
2995
2996 harp_variable_definition_set_valid_range_float(var, -180.0f, 180.0f);
2997
2998 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
2999 "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/longitude[]", NULL);
3000
3001 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
3002 "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/longitude[]", NULL);
3003 }
3004
3005
3006
3007 static void register_additional_geolocation_variables(harp_product_definition *product_definition)
3008 {
3009 const char *path;
3010 const char *description;
3011 harp_variable_definition *variable_definition;
3012 harp_dimension_type dimension_type[1] = { harp_dimension_time };
3013 harp_dimension_type bounds_dimension_type[2] = { harp_dimension_time, harp_dimension_independent };
3014 long bounds_dimension[2] = { -1, 4 };
3015
3016 /* latitude_bounds */
3017 description = "the four latitude boundaries of each ground pixel";
3018 variable_definition =
3019 harp_ingestion_register_variable_full_read(product_definition, "latitude_bounds", harp_type_float, 2,
3020 bounds_dimension_type, bounds_dimension, description, "degree_north",
3021 NULL, read_geolocation_latitude_bounds);
3022 harp_variable_definition_set_valid_range_float(variable_definition, -90.0f, 90.0f);
3023 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/latitude_bounds[]";
3024 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3025
3026 /* longitude_bounds */
3027 description = "the four longitude boundaries of each ground pixel";
3028 variable_definition =
3029 harp_ingestion_register_variable_full_read(product_definition, "longitude_bounds", harp_type_float, 2,
3030 bounds_dimension_type, bounds_dimension, description, "degree_east",
3031 NULL, read_geolocation_longitude_bounds);
3032 harp_variable_definition_set_valid_range_float(variable_definition, -180.0f, 180.0f);
3033 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/longitude_bounds[]";
3034 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3035
3036 /* sensor_latitude */
3037 description = "latitude of the spacecraft sub-satellite point on the WGS84 reference ellipsoid";
3038 variable_definition =
3039 harp_ingestion_register_variable_full_read(product_definition, "sensor_latitude", harp_type_float, 1,
3040 dimension_type, NULL, description, "degree_north", NULL,
3041 read_geolocation_satellite_latitude);
3042 harp_variable_definition_set_valid_range_float(variable_definition, -90.0f, 90.0f);
3043 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/satellite_latitude[]";
3044 description = "the satellite latitude associated with a scanline is repeated for each pixel in the scanline";
3045 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3046
3047 /* sensor_longitude */
3048 description = "longitude of the spacecraft sub-satellite point on the WGS84 reference ellipsoid";
3049 variable_definition =
3050 harp_ingestion_register_variable_full_read(product_definition, "sensor_longitude", harp_type_float, 1,
3051 dimension_type, NULL, description, "degree_east", NULL,
3052 read_geolocation_satellite_longitude);
3053 harp_variable_definition_set_valid_range_float(variable_definition, -180.0f, 180.0f);
3054 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/satellite_longitude[]";
3055 description = "the satellite longitude associated with a scanline is repeated for each pixel in the scanline";
3056 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3057
3058 /* sensor_altitude */
3059 description = "altitude of the spacecraft relative to the WGS84 reference ellipsoid.";
3060 variable_definition =
3061 harp_ingestion_register_variable_full_read(product_definition, "sensor_altitude", harp_type_float, 1,
3062 dimension_type, NULL, description, "m", NULL,
3063 read_geolocation_satellite_altitude);
3064 harp_variable_definition_set_valid_range_float(variable_definition, 700000.0f, 900000.0f);
3065 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/satellite_altitude[]";
3066 description = "the satellite altitude associated with a scanline is repeated for each pixel in the scanline";
3067 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3068
3069 /* sensor_orbit_phase */
3070 description = "relative offset (0.0 ... 1.0) of the measurement in the orbit.";
3071 variable_definition =
3072 harp_ingestion_register_variable_full_read(product_definition, "sensor_orbit_phase", harp_type_double, 1,
3073 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3074 read_geolocation_satellite_orbit_phase);
3075 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/satellite_orbit_phase[]";
3076 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3077
3078 /* solar_zenith_angle */
3079 description = "zenith angle of the sun measured from the ground pixel location on the WGS84 reference ellipsoid";
3080 variable_definition =
3081 harp_ingestion_register_variable_full_read(product_definition, "solar_zenith_angle", harp_type_float, 1,
3082 dimension_type, NULL, description, "degree", NULL,
3083 read_geolocation_solar_zenith_angle);
3084 harp_variable_definition_set_valid_range_float(variable_definition, 0.0f, 180.0f);
3085 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/solar_zenith_angle[]";
3086 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3087
3088 /* solar_azimuth_angle */
3089 description = "azimuth angle of the sun measured from the ground pixel location on the WGS84 ellipsoid";
3090 variable_definition =
3091 harp_ingestion_register_variable_full_read(product_definition, "solar_azimuth_angle", harp_type_float, 1,
3092 dimension_type, NULL, description, "degree", NULL,
3093 read_geolocation_solar_azimuth_angle);
3094 harp_variable_definition_set_valid_range_float(variable_definition, -180.0f, 180.0f);
3095 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/solar_azimuth_angle[]";
3096 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3097
3098 /* sensor_zenith_angle */
3099 description =
3100 "zenith angle of the spacecraft measured from the ground pixel location on the WGS84 reference ellipsoid";
3101 variable_definition =
3102 harp_ingestion_register_variable_full_read(product_definition, "sensor_zenith_angle", harp_type_float, 1,
3103 dimension_type, NULL, description, "degree", NULL,
3104 read_geolocation_viewing_zenith_angle);
3105 harp_variable_definition_set_valid_range_float(variable_definition, 0.0f, 180.0f);
3106 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/viewing_zenith_angle[]";
3107 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3108
3109 /* sensor_azimuth_angle */
3110 description = "azimuth angle of the spacecraft measured from the ground pixel WGS84 reference ellipsoid";
3111 variable_definition =
3112 harp_ingestion_register_variable_full_read(product_definition, "sensor_azimuth_angle", harp_type_float, 1,
3113 dimension_type, NULL, description, "degree", NULL,
3114 read_geolocation_viewing_azimuth_angle);
3115 harp_variable_definition_set_valid_range_float(variable_definition, -180.0f, 180.0f);
3116 path = "/data/PRODUCT/SUPPORT_DATA/GEOLOCATIONS/viewing_azimuth_angle[]";
3117 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3118 }
3119
3120 /* CLD product: full geolocation set (BAND-3A / BAND-3C) */
3121 static void register_additional_geolocation_variables_cld(harp_product_definition *pd)
3122 {
3123 /* common helpers */
3124 harp_dimension_type t1[1] = { harp_dimension_time };
3125 harp_dimension_type t2[2] = { harp_dimension_time, harp_dimension_independent };
3126 long sz2[2] = { -1, 4 }; /* {time, corner=4} */
3127
3128 const char *description;
3129 harp_variable_definition *var;
3130 const char *path_a; /* PRODUCT_BAND3A ... */
3131 const char *path_c; /* PRODUCT_BAND3C ... */
3132
3133 /* latitude_bounds (time, corner) */
3134 description = "four latitude boundaries of each ground pixel";
3135 var = harp_ingestion_register_variable_full_read(pd, "latitude_bounds", harp_type_float, 2, t2, sz2, description,
3136 "degree_north", NULL, read_geolocation_latitude_bounds);
3137
3138 harp_variable_definition_set_valid_range_float(var, -90.f, 90.f);
3139
3140 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/latitude_bounds[]";
3141 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/latitude_bounds[]";
3142
3143 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3144 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3145
3146 /* longitude_bounds (time, corner) */
3147 description = "four longitude boundaries of each ground pixel";
3148 var = harp_ingestion_register_variable_full_read(pd, "longitude_bounds", harp_type_float, 2, t2, sz2, description,
3149 "degree_east", NULL, read_geolocation_longitude_bounds);
3150
3151 harp_variable_definition_set_valid_range_float(var, -180.f, 180.f);
3152
3153 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/longitude_bounds[]";
3154 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/longitude_bounds[]";
3155
3156 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3157 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3158
3159 /* sensor_latitude (scalar) */
3160 description = "sub-satellite latitude";
3161 var = harp_ingestion_register_variable_full_read(pd, "sensor_latitude", harp_type_float, 1, t1, NULL, description,
3162 "degree_north", NULL, read_geolocation_satellite_latitude);
3163
3164 harp_variable_definition_set_valid_range_float(var, -90.f, 90.f);
3165
3166 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/satellite_latitude[]";
3167 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/satellite_latitude[]";
3168
3169 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a,
3170 "value for each scanline is repeated for every pixel");
3171 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c,
3172 "value for each scanline is repeated for every pixel");
3173
3174 /* sensor_longitude (scalar) */
3175 description = "sub-satellite longitude";
3176 var = harp_ingestion_register_variable_full_read(pd, "sensor_longitude", harp_type_float, 1, t1, NULL, description,
3177 "degree_east", NULL, read_geolocation_satellite_longitude);
3178
3179 harp_variable_definition_set_valid_range_float(var, -180.f, 180.f);
3180
3181 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/satellite_longitude[]";
3182 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/satellite_longitude[]";
3183
3184 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a,
3185 "value for each scanline is repeated for every pixel");
3186 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c,
3187 "value for each scanline is repeated for every pixel");
3188
3189 /* sensor_altitude (scalar) */
3190 description = "space-craft altitude (WGS-84)";
3191 var = harp_ingestion_register_variable_full_read(pd, "sensor_altitude", harp_type_float, 1, t1, NULL, description,
3192 "m", NULL, read_geolocation_satellite_altitude);
3193
3194 harp_variable_definition_set_valid_range_float(var, 700000.f, 900000.f);
3195
3196 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/satellite_altitude[]";
3197 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/satellite_altitude[]";
3198
3199 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a,
3200 "value for each scanline is repeated for every pixel");
3201 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c,
3202 "value for each scanline is repeated for every pixel");
3203
3204 /* sensor_orbit_phase (scalar, double) */
3205 description = "relative orbital phase (0 ... 1)";
3206 var = harp_ingestion_register_variable_full_read(pd, "sensor_orbit_phase", harp_type_double, 1, t1, NULL,
3207 description, HARP_UNIT_DIMENSIONLESS, NULL,
3208 read_geolocation_satellite_orbit_phase);
3209
3210 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/satellite_orbit_phase[]";
3211 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/satellite_orbit_phase[]";
3212
3213 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3214 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3215
3216 /* solar_zenith_angle (scalar) */
3217 description = "solar zenith angle";
3218 var = harp_ingestion_register_variable_full_read(pd, "solar_zenith_angle", harp_type_float, 1, t1, NULL,
3219 description, "degree", NULL, read_geolocation_solar_zenith_angle);
3220
3221 harp_variable_definition_set_valid_range_float(var, 0.f, 180.f);
3222
3223 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/solar_zenith_angle[]";
3224 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/solar_zenith_angle[]";
3225
3226 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3227 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3228
3229 /* solar_azimuth_angle (scalar) */
3230 description = "Solar azimuth angle.";
3231 var = harp_ingestion_register_variable_full_read(pd, "solar_azimuth_angle", harp_type_float, 1, t1, NULL,
3232 description, "degree", NULL, read_geolocation_solar_azimuth_angle);
3233
3234 harp_variable_definition_set_valid_range_float(var, -180.f, 180.f);
3235
3236 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/solar_azimuth_angle[]";
3237 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/solar_azimuth_angle[]";
3238
3239 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3240 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3241
3242 /* sensor_zenith_angle (scalar) */
3243 description = "space-craft zenith angle";
3244 var = harp_ingestion_register_variable_full_read(pd, "sensor_zenith_angle", harp_type_float, 1, t1, NULL,
3245 description, "degree", NULL,
3246 read_geolocation_viewing_zenith_angle);
3247
3248 harp_variable_definition_set_valid_range_float(var, 0.f, 180.f);
3249
3250 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/viewing_zenith_angle[]";
3251 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/viewing_zenith_angle[]";
3252
3253 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3254 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3255
3256 /* sensor_azimuth_angle (scalar) */
3257 description = "space-craft azimuth angle";
3258 var = harp_ingestion_register_variable_full_read(pd, "sensor_azimuth_angle", harp_type_float, 1, t1, NULL,
3259 description, "degree", NULL,
3260 read_geolocation_viewing_azimuth_angle);
3261
3262 harp_variable_definition_set_valid_range_float(var, -180.f, 180.f);
3263
3264 path_a = "/data/PRODUCT_BAND3A/SUPPORT_DATA/GEOLOCATIONS/viewing_azimuth_angle[]";
3265 path_c = "/data/PRODUCT_BAND3C/SUPPORT_DATA/GEOLOCATIONS/viewing_azimuth_angle[]";
3266
3267 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL, path_a, NULL);
3268 harp_variable_definition_add_mapping(var, "band=band3c", NULL, path_c, NULL);
3269 }
3270
3271 static void register_surface_variables(harp_product_definition *product_definition, const char *product_type)
3272 {
3273 const char *path;
3274 const char *description;
3275
3276 harp_variable_definition *variable_definition;
3277 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
3278
3279 /* surface_altitude */
3280 description = "height of the surface above WGS84 ellipsoid averaged over the S5 pixel";
3281 variable_definition =
3282 harp_ingestion_register_variable_full_read(product_definition, "surface_altitude", harp_type_float, 1,
3283 dimension_type_1d, NULL, description, "m", NULL,
3284 read_input_surface_altitude);
3285 path = "/data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_altitude[]";
3286 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3287
3288
3289 /* surface_altitude_uncertainty */
3290 /* [Note]: O3 does not contain this record */
3291 if (strcmp(product_type, "SN5_02_O3") != 0)
3292 {
3293 description =
3294 "standard deviation of the height of the surface above WGS84 ellipsoid averaged over the S5 pixel";
3295 variable_definition =
3296 harp_ingestion_register_variable_full_read(product_definition, "surface_altitude_uncertainty",
3297 harp_type_float, 1, dimension_type_1d, NULL, description, "m",
3298 NULL, read_input_surface_altitude_precision);
3299 if (strcmp(product_type, "SN5_02_NO2") == 0)
3300 {
3301 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_altitude_uncertainty[]";
3302 }
3303 else
3304 {
3305 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_altitude_precision[]";
3306 }
3307 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3308 }
3309
3310 /* surface_pressure */
3311 description = "surface pressure; from ECMWF and adjusted for surface elevation";
3312 variable_definition =
3313 harp_ingestion_register_variable_full_read(product_definition, "surface_pressure", harp_type_float, 1,
3314 dimension_type_1d, NULL, description, "Pa", NULL,
3315 read_input_surface_pressure);
3316 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure[]";
3317 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3318
3319 /* surface_classification */
3320 description = "surface classification";
3321 variable_definition =
3322 harp_ingestion_register_variable_full_read(product_definition, "surface_type", harp_type_int32, 1,
3323 dimension_type_1d, NULL, description, NULL, NULL,
3324 read_input_surface_classification);
3325
3326 path = "/data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_classification[]";
3327 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3328 }
3329
3330 /* CLD product - surface variables (BAND-3A / BAND-3C) */
3331 static void register_surface_variables_cld(harp_product_definition *pd)
3332 {
3333 harp_dimension_type t1[1] = { harp_dimension_time };
3334 const char *description;
3335 harp_variable_definition *var;
3336
3337 /* surface_altitude */
3338 description = "height of the surface above the WGS-84 ellipsoid averaged over the Sentinel-5 ground pixel.";
3339 var = harp_ingestion_register_variable_full_read(pd, "surface_altitude", harp_type_float, 1, t1, NULL, description,
3340 "m", NULL, read_input_surface_altitude);
3341
3342 /* BAND-3A (default / option unset) */
3343 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
3344 "/data/PRODUCT_BAND3A/SUPPORT_DATA/INPUT_DATA/surface_altitude[]", NULL);
3345
3346 /* BAND-3C */
3347 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
3348 "/data/PRODUCT_BAND3C/SUPPORT_DATA/INPUT_DATA/surface_altitude[]", NULL);
3349
3350 /* surface_altitude_uncertainty (file name: surface_altitude_precision) */
3351 description = "1-sigma uncertainty of the surface altitude";
3352 var = harp_ingestion_register_variable_full_read(pd, "surface_altitude_uncertainty", harp_type_float, 1, t1, NULL,
3353 description, "m", NULL, read_input_surface_altitude_precision);
3354
3355 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
3356 "/data/PRODUCT_BAND3A/SUPPORT_DATA/INPUT_DATA/surface_altitude_precision[]",
3357 NULL);
3358
3359 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
3360 "/data/PRODUCT_BAND3C/SUPPORT_DATA/INPUT_DATA/surface_altitude_precision[]",
3361 NULL);
3362
3363 /* surface_pressure */
3364 description = "surface pressure from ECMWF, adjusted for surface elevation";
3365 var = harp_ingestion_register_variable_full_read(pd, "surface_pressure", harp_type_float, 1, t1, NULL, description,
3366 "Pa", NULL, read_input_surface_pressure);
3367
3368 harp_variable_definition_add_mapping(var, "band=band3a or band unset", NULL,
3369 "/data/PRODUCT_BAND3A/SUPPORT_DATA/INPUT_DATA/surface_pressure[]", NULL);
3370
3371 harp_variable_definition_add_mapping(var, "band=band3c", NULL,
3372 "/data/PRODUCT_BAND3C/SUPPORT_DATA/INPUT_DATA/surface_pressure[]", NULL);
3373 }
3374
3375 static void register_snow_ice_flag_variables(harp_product_definition *product_definition, const char *product_type)
3376 {
3377 const char *path;
3378 const char *description;
3379 const char *mapping_condition = NULL;
3380 harp_variable_definition *variable_definition;
3381 harp_dimension_type dimension_type[1] = { harp_dimension_time };
3382 int (*read_snow_ice_type_function)(void *, harp_array);
3383 int (*read_sea_ice_fraction_function)(void *, harp_array);
3384 int (*condition_function)(void *) = NULL;
3385
3386 read_snow_ice_type_function = read_snow_ice_type;
3387 read_sea_ice_fraction_function = read_sea_ice_fraction;
3388
3389 if (strcmp(product_type, "SN5_02_CLD") != 0)
3390 {
3391 /* snow_ice_type */
3392 description = "surface condition (snow/ice)";
3393 variable_definition =
3394 harp_ingestion_register_variable_full_read(product_definition, "snow_ice_type", harp_type_int32, 1,
3395 dimension_type, NULL, description, NULL, condition_function,
3396 read_snow_ice_type_function);
3397 harp_variable_definition_set_enumeration_values(variable_definition, 5, snow_ice_type_values);
3398 description = "0: snow_free_land (0), 1-100: sea_ice (1), 101: permanent_ice (2), "
3399 "103: snow (3), 255: ocean (4), other values map to -1";
3400
3401 /* BAND-3A (default / option unset) */
3402 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", mapping_condition,
3403 "/data/PRODUCT_BAND3A/SUPPORT_DATA/INPUT_DATA/snow_ice_flag[]",
3404 description);
3405
3406 /* BAND-3C */
3407 harp_variable_definition_add_mapping(variable_definition, "band=band3c", mapping_condition,
3408 "/data/PRODUCT_BAND3C/SUPPORT_DATA/INPUT_DATA/snow_ice_flag[]",
3409 description);
3410
3411 /* sea_ice_fraction */
3412 description = "sea-ice concentration (as a fraction)";
3413 variable_definition =
3414 harp_ingestion_register_variable_full_read(product_definition, "sea_ice_fraction", harp_type_float, 1,
3415 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS,
3416 condition_function, read_sea_ice_fraction_function);
3417 description = "if 1 <= snow_ice_flag <= 100 then snow_ice_flag/100.0 else 0.0";
3418
3419 /* BAND-3A (default / option unset) */
3420 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", mapping_condition,
3421 "/data/PRODUCT_BAND3A/SUPPORT_DATA/INPUT_DATA/snow_ice_flag[]",
3422 description);
3423
3424 /* BAND-3C */
3425 harp_variable_definition_add_mapping(variable_definition, "band=band3c", mapping_condition,
3426 "/data/PRODUCT_BAND3C/SUPPORT_DATA/INPUT_DATA/snow_ice_flag[]",
3427 description);
3428 }
3429 else
3430 {
3431 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/snow_ice_flag[]";
3432 read_snow_ice_type_function = read_snow_ice_type;
3433 read_sea_ice_fraction_function = read_sea_ice_fraction;
3434
3435 /* snow_ice_type */
3436 description = "surface condition (snow/ice)";
3437 variable_definition =
3438 harp_ingestion_register_variable_full_read(product_definition, "snow_ice_type", harp_type_int32, 1,
3439 dimension_type, NULL, description, NULL, condition_function,
3440 read_snow_ice_type_function);
3441 harp_variable_definition_set_enumeration_values(variable_definition, 5, snow_ice_type_values);
3442 description =
3443 "0: snow_free_land (0), 1-100: sea_ice (1), 101: permanent_ice (2), 103: snow (3), 255: ocean (4), "
3444 "other values map to -1";
3445 harp_variable_definition_add_mapping(variable_definition, NULL, mapping_condition, path, description);
3446
3447 /* sea_ice_fraction */
3448 description = "sea-ice concentration (as a fraction)";
3449 variable_definition =
3450 harp_ingestion_register_variable_full_read(product_definition, "sea_ice_fraction", harp_type_float, 1,
3451 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS,
3452 condition_function, read_sea_ice_fraction_function);
3453 description = "if 1 <= snow_ice_flag <= 100 then snow_ice_flag/100.0 else 0.0";
3454 harp_variable_definition_add_mapping(variable_definition, NULL, mapping_condition, path, description);
3455 }
3456 }
3457
3458
3459 /*
3460 * Product Registration Routines
3461 */
3462
3463
3464 /* Aerosol */
3465 static void register_aui_product(void)
3466 {
3467 const char *path;
3468 const char *description;
3469
3470 harp_ingestion_module *module;
3471 harp_product_definition *product_definition;
3472 harp_variable_definition *variable_definition;
3473
3474 harp_dimension_type dimension_type[1] = { harp_dimension_time };
3475 /* 2-D: {time, spectral=2} */
3476 harp_dimension_type dimension_type_2d[2] = { harp_dimension_time, harp_dimension_spectral };
3477 const char *wavelength_ratio_option_values[3] = { "354_388nm", "340_380nm", "335_367nm" };
3478
3479 /* Product Registration Phase */
3480 module = harp_ingestion_register_module("S5_L2_AUI", "Sentinel-5", "EPS_SG", "SN5_02_AUI",
3481 "Sentinel-5 L2 AUI total column", ingestion_init, ingestion_done);
3482
3483 /* wavelength_ratio */
3484 description = "ingest aerosol index retrieved at wavelengths 354/388 nm (default), 340/380 nm, or 335/367 nm";
3485 harp_ingestion_register_option(module, "wavelength_ratio", description, 3, wavelength_ratio_option_values);
3486
3487 product_definition = harp_ingestion_register_product(module, "S5_L2_AUI", NULL, read_dimensions);
3488
3489 /* Variables' Registration Phase */
3490
3491 register_core_variables(product_definition, 1);
3492 register_geolocation_variables(product_definition);
3493 register_additional_geolocation_variables(product_definition);
3494 register_surface_variables(product_definition, "SN5_02_AUI");
3495 register_snow_ice_flag_variables(product_definition, "SN5_02_AUI");
3496
3497 /* absorbing_aerosol_index */
3498 description = "aerosol index";
3499 variable_definition =
3500 harp_ingestion_register_variable_full_read(product_definition, "absorbing_aerosol_index", harp_type_float, 1,
3501 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3502 read_product_aerosol_index);
3503 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=354_388nm or wavelength_ratio unset",
3504 NULL, "/data/PRODUCT/aerosol_index_354_388", NULL);
3505 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=340_380nm", NULL,
3506 "/data/PRODUCT/aerosol_index_340_380", NULL);
3507 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=335_367nm", NULL,
3508 "/data/PRODUCT/aerosol_index_335_367", NULL);
3509
3510 /* absorbing_aerosol_index_uncertainty */
3511 description = "uncertainty of the aerosol index";
3512 variable_definition =
3513 harp_ingestion_register_variable_full_read(product_definition, "absorbing_aerosol_index_uncertainty",
3514 harp_type_float, 1, dimension_type, NULL, description,
3515 HARP_UNIT_DIMENSIONLESS, NULL, read_product_aerosol_index_precision);
3516 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=354_388nm (default)", NULL,
3517 "data/PRODUCT/aerosol_index_354_388_precision", NULL);
3518 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=340_380nm", NULL,
3519 "data/PRODUCT/aerosol_index_340_380_precision", NULL);
3520 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=335_367nm", NULL,
3521 "data/PRODUCT/aerosol_index_335_367_precision", NULL);
3522
3523 /* absorbing_aerosol_index_validity */
3524 description = "continuous quality descriptor, varying between 0 (no data) and 100 (full quality data)";
3525 variable_definition =
3526 harp_ingestion_register_variable_full_read(product_definition, "absorbing_aerosol_index_validity",
3527 harp_type_int32, 1, dimension_type, NULL, description, NULL, NULL,
3528 read_product_qa_value);
3529 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, "data/PRODUCT/qa_value", NULL);
3530
3531
3532 /* reflectance */
3533 description = "measured reflectance pair (lower, upper) for selected wavelength ratio";
3534 variable_definition =
3535 harp_ingestion_register_variable_full_read(product_definition, "reflectance", harp_type_float, 2,
3536 dimension_type_2d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3537 read_results_reflectance_measured);
3538
3539 /* Add mappings for the variable
3540 * (not strictly needed if read routine does
3541 * all the work, but it's good practice)
3542 */
3543 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=354_388nm or wavelength_ratio unset",
3544 NULL,
3545 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_354_measured[], "
3546 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_388_measured[]",
3547 NULL);
3548 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=340_380nm", NULL,
3549 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_340_measured[], "
3550 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_380_measured[]",
3551 NULL);
3552 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=335_367nm", NULL,
3553 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_335_measured[], "
3554 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_367_measured[]",
3555 NULL);
3556
3557
3558 /* reflectance_uncertainty */
3559 description = "measured reflectance uncertainty";
3560 variable_definition =
3561 harp_ingestion_register_variable_full_read(product_definition, "reflectance_uncertainty", harp_type_float, 2,
3562 dimension_type_2d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3563 read_results_reflectance_precision);
3564
3565 /* mappings (optional but nice for clarity) */
3566 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=354_388nm or wavelength_ratio unset",
3567 NULL,
3568 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_354_measured[], "
3569 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_388_measured[]",
3570 NULL);
3571
3572 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=340_380nm", NULL,
3573 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_340_measured[], "
3574 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_380_measured[]",
3575 NULL);
3576
3577 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=335_367nm", NULL,
3578 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_335_measured[], "
3579 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/reflectance_precision_367_measured[]",
3580 NULL);
3581
3582 /* surface_albedo */
3583 description = "scene albedo";
3584 variable_definition =
3585 harp_ingestion_register_variable_full_read(product_definition, "surface_albedo", harp_type_float, 1,
3586 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS,
3587 NULL, read_results_surface_albedo);
3588 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo_388[]";
3589 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=354_388nm or wavelength_ratio unset",
3590 NULL, path, NULL);
3591 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo_380[]";
3592 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=340_380nm", NULL, path, NULL);
3593 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo_367[]";
3594 harp_variable_definition_add_mapping(variable_definition, "wavelength_ratio=335_367nm", NULL, path, NULL);
3595 }
3596
3597
3598 /* CH4 */
3599 static void register_ch4_product(void)
3600 {
3601 const char *path;
3602 const char *description;
3603
3604 harp_ingestion_module *module;
3605 harp_product_definition *product_definition;
3606 harp_variable_definition *variable_definition;
3607
3608 int include_validity = 1;
3609
3610 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
3611 /* 2-D: {time, spectral=2} */
3612 harp_dimension_type dimension_type_2d_spec[2] = { harp_dimension_time, harp_dimension_spectral };
3613 harp_dimension_type dimension_type_2d_vert[2] = { harp_dimension_time, harp_dimension_vertical };
3614
3615 const char *ch4_option_values[2] = { "physics", "proxy" };
3616 const char *ch4_band_option_values[3] = { "SWIR-1", "SWIR-3", "NIR-2" };
3617
3618
3619 /* Product Registration Phase */
3620 module = harp_ingestion_register_module("S5_L2_CH4", "Sentinel-5", "EPS_SG", "SN5_02_CH4",
3621 "Sentinel-5 L2 CH4 total column", ingestion_init, ingestion_done);
3622
3623 description = "which CH4 column to ingest: 'physics' (default physics-based column) or 'proxy' "
3624 "(alternate proxy column)";
3625 harp_ingestion_register_option(module, "ch4", description, 2, ch4_option_values);
3626
3627
3628 description = "Choose which surface albedo to ingest: " "SWIR-1 (default), SWIR-3, or NIR-2";
3629 harp_ingestion_register_option(module, "band", description, 3, ch4_band_option_values);
3630
3631 product_definition = harp_ingestion_register_product(module, "S5_L2_CH4", NULL, read_dimensions);
3632
3633 /* Variables' Registration Phase */
3634 register_core_variables(product_definition, include_validity);
3635 register_geolocation_variables(product_definition);
3636 register_additional_geolocation_variables(product_definition);
3637 register_surface_variables(product_definition, "SN5_02_CH4");
3638 register_snow_ice_flag_variables(product_definition, "SN5_02_CH4");
3639
3640 /* methane_dry_air_column_mixing_ratio */
3641 description = "physics CH4 dry air column mixing ratio";
3642 variable_definition =
3643 harp_ingestion_register_variable_full_read(product_definition, "CH4_column_volume_mixing_ratio_dry_air",
3644 harp_type_float, 1, dimension_type_1d, NULL, description, "ppbv",
3645 NULL, read_product_methane_dry_air_column_mixing_ratio);
3646
3647 path = "data/PRODUCT/methane_dry_air_column_mixing_ratio_physics[]";
3648 harp_variable_definition_add_mapping(variable_definition, "ch4=physics", NULL, path, NULL);
3649 path = "data/PRODUCT/methane_dry_air_column_mixing_ratio_proxy[]";
3650 harp_variable_definition_add_mapping(variable_definition, "ch4=proxy", NULL, path, NULL);
3651
3652
3653 /* methane_dry_air_column_mixing_ratio_precision */
3654 description = "physics CH4 dry air column mixing ratio noise estimate";
3655 variable_definition =
3656 harp_ingestion_register_variable_full_read(product_definition,
3657 "CH4_column_volume_mixing_ratio_dry_air_uncertainty",
3658 harp_type_float, 1, dimension_type_1d, NULL, description, "ppbv",
3659 NULL, read_product_methane_dry_air_column_mixing_ratio_precision);
3660
3661 path = "data/PRODUCT/methane_dry_air_column_mixing_ratio_precision_physics[]";
3662 harp_variable_definition_add_mapping(variable_definition, "ch4=physics", NULL, path, NULL);
3663 path = "data/PRODUCT/methane_dry_air_column_mixing_ratio_precision_proxy[]";
3664 harp_variable_definition_add_mapping(variable_definition, "ch4=proxy", NULL, path, NULL);
3665
3666
3667 /* qa_value */
3668 description = "quality assurance value describing the quality of the product";
3669 variable_definition =
3670 harp_ingestion_register_variable_full_read(product_definition,
3671 "CH4_column_volume_mixing_ratio_dry_air_validity", harp_type_int32,
3672 1, dimension_type_1d, NULL, description, NULL, NULL,
3673 read_product_qa_value);
3674 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, "data/PRODUCT/qa_value", NULL);
3675
3676
3677 /* pressure */
3678 description = "pressure grid";
3679 variable_definition =
3680 harp_ingestion_register_variable_full_read(product_definition, "pressure", harp_type_float, 2,
3681 dimension_type_2d_vert, NULL, description, "Pa", NULL,
3682 read_results_pressure);
3683 description = "the vertical grid is inverted to make it ascending";
3684 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/pressure[]";
3685 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3686
3687
3688 /* altitude */
3689 description = "altitude grid";
3690 variable_definition =
3691 harp_ingestion_register_variable_full_read(product_definition, "altitude", harp_type_float, 2,
3692 dimension_type_2d_vert, NULL, description, "m", NULL,
3693 read_results_altitude);
3694 description = "the vertical grid is inverted to make it ascending";
3695 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/altitude[]";
3696 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3697
3698
3699 /* dry_air_column */
3700 description = "column number density profile of dry air";
3701 variable_definition =
3702 harp_ingestion_register_variable_full_read(product_definition, "dry_air_column_number_density", harp_type_float,
3703 1, dimension_type_1d, NULL, description, "mol/m2", NULL,
3704 read_results_dry_air_column);
3705 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/dry_air_column[]";
3706 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3707
3708
3709 /* methane_profile_apriori */
3710 description = "a-priori CH4 profile";
3711 variable_definition =
3712 harp_ingestion_register_variable_full_read(product_definition, "CH4_column_number_density_apriori",
3713 harp_type_float, 2, dimension_type_2d_vert, NULL, description,
3714 "mol/m2", NULL, read_results_methane_profile_apriori);
3715 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/methane_profile_apriori[]";
3716 description = "the vertical grid is inverted to make it ascending";
3717 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3718
3719
3720 /* carbon_dioxide_profile_apriori */
3721 description = "a-priori CO2 profile";
3722 variable_definition =
3723 harp_ingestion_register_variable_full_read(product_definition, "CO2_column_number_density_apriori",
3724 harp_type_float, 2, dimension_type_2d_vert, NULL, description,
3725 "mol/m2", NULL, read_results_carbon_dioxide_profile_apriori);
3726 description = "the vertical grid is inverted to make it ascending";
3727 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/carbon_dioxide_profile_apriori[]";
3728 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3729
3730
3731 /* oxygen_total_column_apriori */
3732 description = "a-priori O2 column";
3733 variable_definition =
3734 harp_ingestion_register_variable_full_read(product_definition, "O2_column_number_density_apriori",
3735 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m2",
3736 NULL, read_results_oxygen_total_column_apriori);
3737 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/oxygen_total_column_apriori[]";
3738 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3739
3740
3741 /* water_total_column_apriori */
3742 description = "a-priori H2O column";
3743 variable_definition =
3744 harp_ingestion_register_variable_full_read(product_definition, "H2O_column_number_density_apriori",
3745 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m2",
3746 NULL, read_results_water_total_column_apriori);
3747 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_total_column_apriori[]";
3748 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3749
3750
3751 /* solar_induced_fluorescence */
3752 description = "solar induced fluorescence";
3753 variable_definition =
3754 harp_ingestion_register_variable_full_read(product_definition, "solar_induced_fluorescence", harp_type_float, 2,
3755 dimension_type_2d_spec, NULL, description, HARP_UNIT_DIMENSIONLESS,
3756 NULL, read_results_solar_induced_fluorescence);
3757 description = "the spectral grid is inverted to make it ascending";
3758 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/solar_induced_fluorescence[]";
3759 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3760
3761
3762 /* methane_total_column_averaging_kernel */
3763 description = "physics CH4 column averaging kernel";
3764 variable_definition =
3765 harp_ingestion_register_variable_full_read(product_definition, "CH4_column_number_density_avk", harp_type_float,
3766 2, dimension_type_2d_vert, NULL, description,
3767 HARP_UNIT_DIMENSIONLESS, NULL, read_results_ch4_total_column_avk);
3768 description = "the vertical grid is inverted to make it ascending";
3769 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/methane_total_column_averaging_kernel[]";
3770 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3771
3772
3773 /* water_total_column */
3774 description = "H2O column";
3775 variable_definition =
3776 harp_ingestion_register_variable_full_read(product_definition, "H2O_column_number_density", harp_type_float, 1,
3777 dimension_type_1d, NULL, description, "mol/m^2", NULL,
3778 read_results_water_total_column);
3779 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_total_column[]";
3780 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3781
3782
3783 /* carbon_dioxide_total_column */
3784 description = "CO2 column";
3785 variable_definition =
3786 harp_ingestion_register_variable_full_read(product_definition, "CO2_column_number_density", harp_type_float, 1,
3787 dimension_type_1d, NULL, description, "mol/m^2", NULL,
3788 read_results_carbon_dioxide_total_column);
3789 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/carbon_dioxide_total_column[]";
3790 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3791
3792
3793 /* carbon_monoxide_total_column */
3794 description = "CO column";
3795 variable_definition =
3796 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density", harp_type_float, 1,
3797 dimension_type_1d, NULL, description, "mol/m^2", NULL,
3798 read_product_carbon_monoxide_total_column);
3799 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/carbon_monoxide_total_column[]";
3800 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3801
3802
3803 /* aerosol_size */
3804 description = "aerosol particle size";
3805 variable_definition =
3806 harp_ingestion_register_variable_full_read(product_definition, "aerosol_effective_radius", harp_type_float, 1,
3807 dimension_type_1d, NULL, description, "m", NULL,
3808 read_results_aerosol_size);
3809 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/aerosol_size[]";
3810 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3811
3812
3813 /* aerosol_particle_column */
3814 description = "Aerosol particle column";
3815 variable_definition =
3816 harp_ingestion_register_variable_full_read(product_definition, "aerosol_column_number_density", harp_type_float,
3817 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
3818 read_results_aerosol_particle_column);
3819 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/aerosol_particle_column[]";
3820 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3821
3822
3823 /* aerosol_layer_height */
3824 description = "aerosol layer height above the surface";
3825 variable_definition =
3826 harp_ingestion_register_variable_full_read(product_definition, "aerosol_height", harp_type_float, 1,
3827 dimension_type_1d, NULL, description, "m", NULL,
3828 read_results_aerosol_layer_height);
3829 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/aerosol_layer_height[]";
3830 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3831
3832 /* surface_albedo */
3833 description = "surface albedo in the selected band";
3834 variable_definition =
3835 harp_ingestion_register_variable_full_read(product_definition, "surface_albedo", harp_type_float, 1,
3836 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3837 read_results_surface_albedo);
3838
3839 /* three mappings, each gated on band=... */
3840 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/surface_albedo_swir_1[]";
3841 harp_variable_definition_add_mapping(variable_definition, "band=SWIR-1", NULL, path, NULL);
3842
3843 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/surface_albedo_swir_3[]";
3844 harp_variable_definition_add_mapping(variable_definition, "band=SWIR-3", NULL, path, NULL);
3845
3846 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/surface_albedo_nir_2[]";
3847 harp_variable_definition_add_mapping(variable_definition, "band=NIR-2", NULL, path, NULL);
3848 }
3849
3850
3851 /* NO2 */
3852 static void register_no2_product(void)
3853 {
3854 const char *path;
3855 const char *description;
3856
3857 harp_ingestion_module *module;
3858 harp_product_definition *product_definition;
3859 harp_variable_definition *variable_definition;
3860
3861 int include_validity = 1;
3862
3863 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
3864 harp_dimension_type dimension_type_2d_vert[2] = { harp_dimension_time, harp_dimension_vertical };
3865
3866 harp_dimension_type pressure_bounds_dimension_type[3] =
3867 { harp_dimension_time, harp_dimension_vertical, harp_dimension_independent };
3868 long pressure_bounds_dimension[3] = { -1, -1, 2 };
3869
3870 const char *no2_column_option_values[2] = { "total", "summed" };
3871
3872 /* Product Registration Phase */
3873 module = harp_ingestion_register_module("S5_L2_NO2", "Sentinel-5", "EPS_SG", "SN5_02_NO2",
3874 "Sentinel-5 L2 NO2 total column", ingestion_init, ingestion_done);
3875
3876 description = "which NO2 column to ingest: 'total' (default) or 'summed'";
3877 harp_ingestion_register_option(module, "total_column", description, 2, no2_column_option_values);
3878
3879 product_definition = harp_ingestion_register_product(module, "S5_L2_NO2", NULL, read_dimensions);
3880
3881 /* Variables' Registration Phase */
3882
3883 register_core_variables(product_definition, include_validity);
3884 register_geolocation_variables(product_definition);
3885 register_additional_geolocation_variables(product_definition);
3886 register_surface_variables(product_definition, "SN5_02_NO2");
3887 register_snow_ice_flag_variables(product_definition, "SN5_02_NO2");
3888
3889
3890 /* nitrogen_dioxide_tropospheric_column */
3891 description = "tropospheric NO2 vertical column density";
3892 variable_definition =
3893 harp_ingestion_register_variable_full_read(product_definition, "tropospheric_NO2_column_number_density",
3894 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3895 NULL, read_product_nitrogen_dioxide_tropospheric_column);
3896 path = "data/PRODUCT/nitrogen_dioxide_tropospheric_column[]";
3897 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3898
3899 /* nitrogen_dioxide_tropospheric_column_uncertainty */
3900 description = "tropospheric NO2 vertical column density";
3901 variable_definition =
3902 harp_ingestion_register_variable_full_read(product_definition,
3903 "tropospheric_NO2_column_number_density_uncertainty",
3904 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3905 NULL, read_product_nitrogen_dioxide_tropospheric_column_uncertainty);
3906 path = "data/PRODUCT/nitrogen_dioxide_tropospheric_column_uncertainty[]";
3907 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3908
3909
3910 /* nitrogen_dioxide_tropospheric_column_air_mass_factor */
3911 description = "tropospheric air mass factor";
3912 variable_definition =
3913 harp_ingestion_register_variable_full_read(product_definition, "tropospheric_NO2_column_number_density_amf",
3914 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3915 NULL,
3916 read_product_nitrogen_dioxide_tropospheric_column_air_mass_factor);
3917 path = "data/PRODUCT/nitrogen_dioxide_tropospheric_column_air_mass_factor[]";
3918 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3919
3920
3921 /* nitrogen_dioxide_total_column_air_mass_factor */
3922 description = "total air mass factor";
3923 variable_definition =
3924 harp_ingestion_register_variable_full_read(product_definition, "NO2_column_number_density_amf", harp_type_float,
3925 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
3926 read_product_nitrogen_dioxide_total_column_air_mass_factor);
3927 path = "data/PRODUCT/nitrogen_dioxide_total_column_air_mass_factor[]";
3928 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3929
3930 /* nitrogen_dioxide_total_column_averaging_kernel */
3931 description = "averaging kernel";
3932 variable_definition =
3933 harp_ingestion_register_variable_full_read(product_definition, "NO2_column_number_density_avk", harp_type_float,
3934 2, dimension_type_2d_vert, NULL, description,
3935 HARP_UNIT_DIMENSIONLESS, NULL,
3936 read_product_nitrogen_dioxide_total_column_avk);
3937 path = "data/PRODUCT/nitrogen_dioxide_total_column_averaging_kernel[]";
3938 description = "the vertical grid is inverted to make it ascending";
3939 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
3940
3941
3942 /* qa_value */
3943 description = "quality assurance value describing the quality of the product";
3944 variable_definition =
3945 harp_ingestion_register_variable_full_read(product_definition,
3946 "tropospheric_NO2_column_number_density_validity",
3947 harp_type_int32, 1, dimension_type_1d, NULL, description,
3948 HARP_UNIT_DIMENSIONLESS, NULL, read_product_qa_value);
3949 path = "data/PRODUCT/qa_value[]";
3950 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3951
3952 /* nitrogen_dioxide_stratospheric_column_air_mass_factor */
3953 description = "stratospheric air mass factor";
3954 variable_definition =
3955 harp_ingestion_register_variable_full_read(product_definition, "stratospheric_NO2_column_number_density_amf",
3956 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3957 NULL, read_results_nitrogen_dioxide_stratospheric_column_amf);
3958 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_stratospheric_column_air_mass_factor[]";
3959 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3960
3961 /* cloud_radiance_fraction */
3962 description = "cloud radiance fraction";
3963 variable_definition =
3964 harp_ingestion_register_variable_full_read(product_definition, "cloud_fraction", harp_type_float, 1,
3965 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
3966 read_results_cloud_radiance_fraction);
3967 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/cloud_radiance_fraction[]";
3968 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3969
3970
3971 /* nitrogen_dioxide_slant_column */
3972 description = "total NO2 slant column density";
3973 variable_definition =
3974 harp_ingestion_register_variable_full_read(product_definition, "NO2_slant_column_number_density",
3975 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3976 NULL, read_results_nitrogen_dioxide_slant_column);
3977 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_slant_column[]";
3978 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3979
3980 /* nitrogen_dioxide_slant_column_uncertainty */
3981 description = "total NO2 slant column density uncertainty";
3982 variable_definition =
3983 harp_ingestion_register_variable_full_read(product_definition, "NO2_slant_column_number_density_uncertainty",
3984 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3985 NULL, read_results_nitrogen_dioxide_slant_column_uncertainty);
3986 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_slant_column_uncertainty[]";
3987 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3988
3989 /* ozone_slant_column */
3990 description = "O3 slant column density";
3991 variable_definition =
3992 harp_ingestion_register_variable_full_read(product_definition, "O3_slant_column_number_density",
3993 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
3994 NULL, read_results_ozone_slant_column);
3995 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_slant_column[]";
3996 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
3997
3998 /* ozone_slant_column_uncertainty */
3999 description = "O3 slant column density uncertainty";
4000 variable_definition =
4001 harp_ingestion_register_variable_full_read(product_definition, "O3_slant_column_number_density_uncertainty",
4002 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4003 NULL, read_results_ozone_slant_column_uncertainty);
4004 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_slant_column_uncertainty[]";
4005 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4006
4007 /* water_vapor_slant_column */
4008 description = "H2O vapor slant column density";
4009 variable_definition =
4010 harp_ingestion_register_variable_full_read(product_definition, "H2O_vapor_slant_column_number_density",
4011 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4012 NULL, read_results_water_vapor_slant_column);
4013 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_vapor_slant_column[]";
4014 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4015
4016 /* water_vapor_slant_column_uncertainty */
4017 description = "H2O vapor slant column density uncertainty";
4018 variable_definition =
4019 harp_ingestion_register_variable_full_read(product_definition,
4020 "H2O_vapor_slant_column_number_density_uncertainty",
4021 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4022 NULL, read_results_water_vapor_slant_column_uncertainty);
4023 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_vapor_slant_column_uncertainty[]";
4024 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4025
4026 /* water_liquid_slant_column */
4027 description = "H2O liquid coefficient";
4028 variable_definition =
4029 harp_ingestion_register_variable_full_read(product_definition, "liquid_H2O_slant_column_number_density",
4030 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4031 NULL, read_results_water_liquid_slant_column);
4032 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_liquid_slant_column[]";
4033 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4034
4035 /* water_liquid_slant_column_uncertainty */
4036 description = "H2O liquid coefficient uncertainty";
4037 variable_definition =
4038 harp_ingestion_register_variable_full_read(product_definition,
4039 "liquid_H2O_slant_column_number_density_uncertainty",
4040 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4041 NULL, read_results_water_liquid_slant_column);
4042 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_liquid_slant_column_uncertainty[]";
4043 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4044
4045
4046 /* nitrogen_dioxide_stratospheric_column */
4047 description = "stratospheric NO2 vertical column density";
4048 variable_definition =
4049 harp_ingestion_register_variable_full_read(product_definition, "stratospheric_NO2_column_number_density",
4050 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4051 NULL, read_results_nitrogen_dioxide_stratospheric_column);
4052 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_stratospheric_column[]";
4053 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4054
4055 /* nitrogen_dioxide_stratospheric_column_uncertainty */
4056 description = "stratospheric NO2 vertical column density uncertainty";
4057 variable_definition =
4058 harp_ingestion_register_variable_full_read(product_definition,
4059 "stratospheric_NO2_column_number_density_uncertainty",
4060 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4061 NULL,
4062 read_results_nitrogen_dioxide_stratospheric_column_uncertainty);
4063 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_stratospheric_column_uncertainty[]";
4064 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4065
4066 /* nitrogen_dioxide_[|summed]_total_column */
4067 description = "NO2 column number density values in the selected column option";
4068 variable_definition =
4069 harp_ingestion_register_variable_full_read(product_definition, "NO2_column_number_density", harp_type_float, 1,
4070 dimension_type_1d, NULL, description, "mol/m^2", NULL,
4071 read_results_nitrogen_dioxide_total_column);
4072
4073 /* two mappings */
4074 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_total_column[]";
4075 description = "total NO2 vertical column density";
4076 harp_variable_definition_add_mapping(variable_definition, "total_column=total", NULL, path, description);
4077
4078 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_summed_total_column[]";
4079 description = "sum of partial NO2 columns";
4080 harp_variable_definition_add_mapping(variable_definition, "total_column=summed", NULL, path, description);
4081
4082 /* nitrogen_dioxide_total_column_uncertainty */
4083 description = "NO2 column number density uncertainty values in the selected column option";
4084 variable_definition =
4085 harp_ingestion_register_variable_full_read(product_definition, "NO2_column_number_density_uncertainty",
4086 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4087 NULL, read_results_nitrogen_dioxide_total_column_uncertainty);
4088
4089 /* two mappings */
4090 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_total_column_uncertainty[]";
4091 description = "total NO2 vertical column density uncertainty";
4092 harp_variable_definition_add_mapping(variable_definition, "total_column=total", NULL, path, description);
4093
4094 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogen_dioxide_summed_total_column_uncertainty[]";
4095 description = "sum of partial NO2 vertical column density uncertainty";
4096 harp_variable_definition_add_mapping(variable_definition, "total_column=summed", NULL, path, description);
4097
4098 /* surface_albedo */
4099 description = "surface albedo";
4100 variable_definition =
4101 harp_ingestion_register_variable_full_read(product_definition, "surface_albedo", harp_type_float, 1,
4102 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4103 read_results_surface_albedo);
4104 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_albedo[]";
4105 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4106
4107
4108 /* pressure_bounds */
4109 description = "pressure boundaries";
4110 variable_definition =
4111 harp_ingestion_register_variable_full_read(product_definition, "pressure_bounds", harp_type_double, 3,
4112 pressure_bounds_dimension_type, pressure_bounds_dimension,
4113 description, "Pa", NULL, read_no2_pressure_bounds);
4114 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/pressure_coefficient_a[], "
4115 "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/pressure_coefficient_b[], "
4116 "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure[]";
4117 description =
4118 "pressure in Pa at level k is derived from surface pressure in Pa as: pressure_coefficient_a[k] + "
4119 "pressure_coefficient_b[k] * surface_pressure[]; the top of atmosphere pressure is clamped to 1e-3 Pa";
4120 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4121
4122 /* aerosol_index_354_388 */
4123 description = "aerosol absorbing index 354/388 pair";
4124 variable_definition =
4125 harp_ingestion_register_variable_full_read(product_definition, "aerosol_index", harp_type_float, 1,
4126 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4127 read_input_aerosol_index);
4128 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/aerosol_index_354_388[]";
4129 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4130
4131 /* cloud_albedo */
4132 description = "cloud albedo";
4133 variable_definition =
4134 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo", harp_type_float, 1,
4135 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4136 read_input_cloud_albedo);
4137 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_albedo[]";
4138 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4139
4140 /* cloud_albedo_uncertainty */
4141 description = "cloud albedo uncertainty";
4142 variable_definition =
4143 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo_uncertainty", harp_type_float, 1,
4144 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4145 read_input_cloud_albedo_uncertainty);
4146 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_albedo_uncertainty[]";
4147 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4148
4149 /* cloud_pressure */
4150 description = "cloud pressure";
4151 variable_definition =
4152 harp_ingestion_register_variable_full_read(product_definition, "cloud_pressure", harp_type_float, 1,
4153 dimension_type_1d, NULL, description, "Pa", NULL,
4154 read_input_cloud_pressure);
4155 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_pressure[]";
4156 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4157
4158 /* cloud_pressure_uncertainty */
4159 description = "cloud pressure uncertainty";
4160 variable_definition =
4161 harp_ingestion_register_variable_full_read(product_definition, "cloud_pressure_uncertainty", harp_type_float, 1,
4162 dimension_type_1d, NULL, description, "Pa", NULL,
4163 read_input_cloud_pressure);
4164 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_pressure_uncertainty[]";
4165 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4166
4167 /* scene_albedo */
4168 description = "scene albedo";
4169 variable_definition =
4170 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo", harp_type_float, 1,
4171 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4172 read_input_scene_albedo);
4173 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_albedo[]";
4174 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4175
4176 /* scene_albedo_uncertainty */
4177 description = "scene albedo uncertainty";
4178 variable_definition =
4179 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo_uncertainty", harp_type_float, 1,
4180 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4181 read_input_scene_albedo_uncertainty);
4182 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_albedo_uncertainty[]";
4183 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4184
4185 /* scene_pressure */
4186 description = "scene pressure";
4187 variable_definition =
4188 harp_ingestion_register_variable_full_read(product_definition, "scene_pressure", harp_type_float, 1,
4189 dimension_type_1d, NULL, description, "Pa", NULL,
4190 read_input_scene_pressure);
4191 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_pressure[]";
4192 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4193
4194 /* scene_pressure_uncertainty */
4195 description = "scene pressure uncertainty";
4196 variable_definition =
4197 harp_ingestion_register_variable_full_read(product_definition, "scene_pressure_uncertainty", harp_type_float, 1,
4198 dimension_type_1d, NULL, description, "Pa", NULL,
4199 read_input_scene_pressure_uncertainty);
4200 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_pressure_uncertainty[]";
4201 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4202
4203 /* tropopause_pressure */
4204 description = "tropopause pressure (CAMS)";
4205 variable_definition =
4206 harp_ingestion_register_variable_full_read(product_definition, "tropopause_pressure", harp_type_float, 1,
4207 dimension_type_1d, NULL, description, "Pa", NULL,
4208 read_input_tropopause_pressure);
4209 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/tropopause_pressure[]";
4210 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4211 }
4212
4213 /* O3 */
4214 static void register_o3_product(void)
4215 {
4216 const char *path;
4217 const char *description;
4218
4219 harp_ingestion_module *module;
4220 harp_product_definition *product_definition;
4221 harp_variable_definition *variable_definition;
4222
4223 int include_validity = 1;
4224
4225 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
4226 harp_dimension_type dimension_type_2d[2] = { harp_dimension_time, harp_dimension_vertical };
4227
4228
4229 /* Product Registration Phase */
4230 module = harp_ingestion_register_module("S5_L2_O3", "Sentinel-5", "EPS_SG", "SN5_02_O3_",
4231 "Sentinel-5 L2 O3 total column", ingestion_init, ingestion_done);
4232
4233 /* harp_ingestion_register_product( module ptr, "ProductShortName", options table (NULL), dimension-callback ) */
4234 product_definition = harp_ingestion_register_product(module, "S5_L2_O3", NULL, read_dimensions);
4235
4236
4237 /* Variables' Registration Phase */
4238
4239 register_core_variables(product_definition, include_validity);
4240 register_geolocation_variables(product_definition);
4241 register_additional_geolocation_variables(product_definition);
4242 register_surface_variables(product_definition, "SN5_02_O3");
4243 register_snow_ice_flag_variables(product_definition, "SN5_02_O3");
4244
4245 /* ozone_total_column */
4246 description = "O3 VCD";
4247 variable_definition =
4248 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density", harp_type_float, 1,
4249 dimension_type_1d, NULL, description, "mol/m^2", NULL,
4250 read_product_ozone_total_column);
4251 path = "data/PRODUCT/ozone_total_column";
4252 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4253
4254 /* ozone_total_column_precision */
4255 description = "O3 VCD random error";
4256 variable_definition =
4257 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density_uncertainty_random",
4258 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4259 NULL, read_product_ozone_total_column_precision);
4260 path = "data/PRODUCT/ozone_total_column_precision";
4261 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4262
4263 /* ozone_total_column_precision */
4264 description = "O3 VCD systematic error";
4265 variable_definition =
4266 harp_ingestion_register_variable_full_read(product_definition,
4267 "O3_column_number_density_uncertainty_systematic", harp_type_float,
4268 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
4269 read_product_ozone_total_column_trueness);
4270 path = "data/PRODUCT/ozone_total_column_trueness";
4271 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4272
4273 /* qa_value */
4274 description = "quality assurance value describing the quality of the product";
4275 variable_definition =
4276 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density_validity",
4277 harp_type_int32, 1, dimension_type_1d, NULL, description, NULL, NULL,
4278 read_product_qa_value);
4279 path = "data/PRODUCT/qa_value[]";
4280 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4281
4282 /* ozone_slant_column */
4283 description = "O3 SCD";
4284 variable_definition =
4285 harp_ingestion_register_variable_full_read(product_definition, "O3_slant_column_number_density",
4286 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4287 NULL, read_results_ozone_slant_column);
4288 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_slant_column[]";
4289 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4290
4291 /* ozone_slant_column_uncertainty */
4292 description = "O3 SCD random error";
4293 variable_definition =
4294 harp_ingestion_register_variable_full_read(product_definition, "O3_slant_column_number_density_uncertainty",
4295 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4296 NULL, read_results_ozone_slant_column_uncertainty);
4297 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_slant_column_precision[]";
4298 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4299
4300 /* effective_temperature */
4301 description = "effective temperature";
4302 variable_definition =
4303 harp_ingestion_register_variable_full_read(product_definition, "O3_effective_temperature", harp_type_float, 1,
4304 dimension_type_1d, NULL, description, "K", NULL,
4305 read_results_effective_temperature);
4306 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/effective_temperature[]";
4307 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4308
4309 /* effective_scene_air_mass_factor */
4310 description = "effective scene AMF";
4311 variable_definition =
4312 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density_amf", harp_type_float,
4313 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
4314 read_results_effective_scene_amf);
4315 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/effective_scene_air_mass_factor[]";
4316 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4317
4318
4319 /* effective_scene_albedo */
4320 description = "effective scene albedo";
4321 variable_definition =
4322 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo", harp_type_float, 1,
4323 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4324 read_results_effective_scene_albedo);
4325 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/effective_scene_albedo[]";
4326 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4327
4328 /* ozone_total_column_avk */
4329 description = "averaging kernels of ozone total column";
4330 variable_definition =
4331 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density_avk", harp_type_float,
4332 2, dimension_type_2d, NULL, description, HARP_UNIT_DIMENSIONLESS,
4333 NULL, read_results_ozone_total_column_avk);
4334 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_total_column_averaging_kernel[]";
4335 description = "the vertical grid is inverted to make it ascending";
4336 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4337
4338 /* ozone_profile_apriori */
4339 description = "O3 profile";
4340 variable_definition =
4341 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density_apriori",
4342 harp_type_float, 2, dimension_type_2d, NULL, description,
4343 HARP_UNIT_DIMENSIONLESS, NULL, read_results_ozone_profile_apriori);
4344 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/ozone_profile_apriori[]";
4345 description = "the vertical grid is inverted to make it ascending";
4346 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4347
4348 /* pressure_grid */
4349 description = "pressure grid";
4350 variable_definition =
4351 harp_ingestion_register_variable_full_read(product_definition, "pressure", harp_type_float, 2,
4352 dimension_type_2d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4353 read_results_pressure_grid);
4354 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/pressure_grid[]";
4355 description = "the vertical grid is inverted to make it ascending";
4356 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4357
4358 /* surface_albedo */
4359 description = "surface albedo";
4360 variable_definition =
4361 harp_ingestion_register_variable_full_read(product_definition, "surface_albedo", harp_type_float, 1,
4362 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4363 read_results_surface_albedo);
4364 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_albedo_335[]";
4365 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4366
4367 /* effective_cloud_fraction */
4368 description = "cloud fraction";
4369 variable_definition =
4370 harp_ingestion_register_variable_full_read(product_definition, "cloud_fraction", harp_type_float, 1,
4371 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4372 read_input_effective_cloud_fraction);
4373 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/effective_cloud_fraction[]";
4374 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4375
4376 /* cloud_pressure */
4377 description = "cloud pressure";
4378 variable_definition =
4379 harp_ingestion_register_variable_full_read(product_definition, "cloud_pressure", harp_type_float, 1,
4380 dimension_type_1d, NULL, description, "Pa", NULL,
4381 read_input_cloud_pressure);
4382 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_pressure[]";
4383 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4384
4385 /* cloud_albedo */
4386 description = "cloud top albedo";
4387 variable_definition =
4388 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo", harp_type_float, 1,
4389 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4390 read_input_cloud_albedo);
4391 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_albedo[]";
4392 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4393
4394 /* scene_pressure */
4395 description = "scene pressure";
4396 variable_definition =
4397 harp_ingestion_register_variable_full_read(product_definition, "scene_pressure", harp_type_float, 1,
4398 dimension_type_1d, NULL, description, "Pa", NULL,
4399 read_input_scene_pressure);
4400 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_pressure[]";
4401 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4402
4403 /* aerosol_index_340_380 */
4404 description = "aerosol absorbing index 340/380 pair";
4405 variable_definition =
4406 harp_ingestion_register_variable_full_read(product_definition, "aerosol_index", harp_type_float, 1,
4407 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4408 read_input_aerosol_index);
4409 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/aerosol_index_340_380[]";
4410 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4411
4412 /* tropopause_pressure */
4413 description = "tropopause pressure (CAMS)";
4414 variable_definition =
4415 harp_ingestion_register_variable_full_read(product_definition, "tropopause_pressure", harp_type_float, 1,
4416 dimension_type_1d, NULL, description, "Pa", NULL,
4417 read_input_tropopause_pressure);
4418 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/tropopause_pressure[]";
4419 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4420 }
4421
4422
4423 /* Read a SO2 scalar field with an extra 'profile' dimension */
4424 /* and collapse that dimension according to info->so2_column_type. */
4425 static int read_so2_scalar(void *user_data, const char *dataset_name, harp_array data)
4426 {
4427 ingest_info *info = (ingest_info *)user_data;
4428
4429 /* total elements in the 3-D variable on file */
4430 long num_elements = info->num_scanlines * info->num_pixels * info->num_profile; /* 4 profiles */
4431
4432 /* copy the requested profile (0...3) into the 1-D HARP array */
4433 long stride = info->num_profile; /* profile dimension length */
4434 long sel_idx = info->so2_column_type; /* 0=PBL,1=1 km,2=7 km,3=15 km */
4435 long out_idx = 0;
4436
4437 int status;
4438 long i;
4439
4440 /* temporary buffer for the full 3-D variable */
4441 harp_array buffer;
4442
4443 buffer.ptr = malloc(num_elements * sizeof(float));
4444 if (buffer.ptr == NULL)
4445 {
4446 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
4447 num_elements * sizeof(float), __FILE__, __LINE__);
4448 return -1;
4449 }
4450
4451 /* We first try under /data/PRODUCT/... */
4452 status = read_dataset(info->product_cursor, dataset_name, harp_type_float, num_elements, buffer);
4453
4454 /* If that failed, fall back to /data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/... */
4455 if (status != 0)
4456 {
4457 status = read_dataset(info->detailed_results_cursor, dataset_name, harp_type_float, num_elements, buffer);
4458 }
4459
4460 if (status != 0)
4461 {
4462 free(buffer.ptr);
4463 return -1; /* read_dataset set a HARP error for us */
4464 }
4465
4466
4467 for (i = sel_idx; i < num_elements; i += stride)
4468 {
4469 data.float_data[out_idx++] = buffer.float_data[i];
4470 }
4471
4472 free(buffer.ptr);
4473 return 0;
4474 }
4475
4476
4477 static int read_so2_total_column(void *u, harp_array d)
4478 {
4479 return read_so2_scalar(u, "sulfur_dioxide_total_column", d);
4480 }
4481
4482 static int read_so2_total_column_precision(void *u, harp_array d)
4483 {
4484 return read_so2_scalar(u, "sulfur_dioxide_total_column_precision", d);
4485 }
4486
4487 static int read_so2_total_column_trueness(void *u, harp_array d)
4488 {
4489 return read_so2_scalar(u, "sulfur_dioxide_total_column_trueness", d);
4490 }
4491
4492 static int read_so2_total_amf(void *u, harp_array d)
4493 {
4494 return read_so2_scalar(u, "sulfur_dioxide_total_column_air_mass_factor", d);
4495 }
4496
4497 static int read_so2_total_amf_precision(void *u, harp_array d)
4498 {
4499 return read_so2_scalar(u, "sulfur_dioxide_total_column_air_mass_factor_precision", d);
4500 }
4501
4502 static int read_so2_total_amf_trueness(void *u, harp_array d)
4503 {
4504 return read_so2_scalar(u, "sulfur_dioxide_total_column_air_mass_factor_trueness", d);
4505 }
4506
4507
4508 /* SO2 */
4509 static void register_so2_product(void)
4510 {
4511 const char *path;
4512 const char *description;
4513
4514 harp_ingestion_module *module;
4515 harp_product_definition *product_definition;
4516 harp_variable_definition *variable_definition;
4517
4518 int include_validity = 1;
4519
4520 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
4521 harp_dimension_type dimension_type_2d[2] = { harp_dimension_time, harp_dimension_vertical };
4522
4523 harp_dimension_type pressure_bounds_dimension_type[3] =
4524 { harp_dimension_time, harp_dimension_vertical, harp_dimension_independent };
4525 long pressure_bounds_dimension[3] = { -1, -1, 2 };
4526
4527 const char *so2_column_options[] = { "1km", "7km", "15km" };
4528
4529 /* Product Registration Phase */
4530 module = harp_ingestion_register_module("S5_L2_SO2", "Sentinel-5", "EPS_SG", "SN5_02_SO2",
4531 "Sentinel-5 L2 SO2 total column", ingestion_init, ingestion_done);
4532
4533 harp_ingestion_register_option(module,
4534 "so2_column",
4535 "select the SO2 column from the 1 km, 7 km, or 15 km box profile; "
4536 "if the option is omitted the polluted-boundary-layer column (PBL) "
4537 "is ingested", 3, so2_column_options);
4538
4539 product_definition = harp_ingestion_register_product(module, "S5_L2_SO2", NULL, read_dimensions);
4540
4541 /* Variables' Registration Phase */
4542
4543 register_core_variables(product_definition, include_validity);
4544 register_geolocation_variables(product_definition);
4545 register_additional_geolocation_variables(product_definition);
4546 register_surface_variables(product_definition, "SN5_02_SO2");
4547 register_snow_ice_flag_variables(product_definition, "SN5_02_SO2");
4548
4549 /* SO2_column_number_density */
4550 description = "SO2 vertical column density";
4551 variable_definition =
4552 harp_ingestion_register_variable_full_read(product_definition, "SO2_column_number_density", harp_type_float,
4553 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
4554 read_so2_total_column);
4555 harp_variable_definition_add_mapping(variable_definition, NULL, NULL,
4556 "/data/PRODUCT/sulfur_dioxide_total_column[]",
4557 "profile dimension sliced according to so2_column option");
4558
4559 /* SO2_column_number_density_uncertainty_random */
4560 description = "random uncertainty of SO2 column density";
4561 variable_definition =
4562 harp_ingestion_register_variable_full_read(product_definition, "SO2_column_number_density_uncertainty_random",
4563 harp_type_float, 1, dimension_type_1d, NULL, description, "mol/m^2",
4564 NULL, read_so2_total_column_precision);
4565 harp_variable_definition_add_mapping(variable_definition, NULL, NULL,
4566 "/data/PRODUCT/sulfur_dioxide_total_column_precision[]",
4567 "profile dimension sliced according to so2_column option");
4568
4569 /* SO2_column_number_density_uncertainty_systematic */
4570 description = "systematic uncertainty of SO2 column density";
4571 variable_definition =
4572 harp_ingestion_register_variable_full_read(product_definition,
4573 "SO2_column_number_density_uncertainty_systematic", harp_type_float,
4574 1, dimension_type_1d, NULL, description, "mol/m^2", NULL,
4575 read_so2_total_column_trueness);
4576 harp_variable_definition_add_mapping(variable_definition, NULL, NULL,
4577 "/data/PRODUCT/sulfur_dioxide_total_column_trueness[]",
4578 "profile dimension sliced according to so2_column option");
4579
4580
4581 /* sulfur_dioxide_layer_height */
4582 description = "retrieved layer height of SO2 above sea level";
4583 variable_definition =
4584 harp_ingestion_register_variable_full_read(product_definition, "SO2_layer_height", harp_type_float, 1,
4585 dimension_type_1d, NULL, description, "m", NULL,
4586 read_product_sulfur_dioxide_layer_height);
4587
4588 path = "data/PRODUCT/sulfur_dioxide_layer_height[]";
4589 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4590
4591 /* sulfur_dioxide_layer_height_uncertainty */
4592 description = "uncertainty of the retrieved SO2 layer height";
4593 variable_definition =
4594 harp_ingestion_register_variable_full_read(product_definition,
4595 "SO2_layer_height_uncertainty",
4596 harp_type_float, 1, dimension_type_1d, NULL,
4597 description, "m", NULL,
4598 read_product_sulfur_dioxide_layer_height_uncertainty);
4599
4600 path = "data/PRODUCT/sulfur_dioxide_layer_height_uncertainty[]";
4601 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4602
4603 /* sulfur_dioxide_layer_height_flag */
4604 description = "flag associated with SO2 layer-height retrieval quality";
4605 variable_definition =
4606 harp_ingestion_register_variable_full_read(product_definition,
4607 "SO2_layer_height_validity",
4608 harp_type_int8, 1, dimension_type_1d, NULL,
4609 description, NULL, NULL,
4610 read_product_sulfur_dioxide_layer_height_flag);
4611
4612 path = "data/PRODUCT/sulfur_dioxide_layer_height_flag[]";
4613 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4614
4615 /* qa_value */
4616 description = "quality-assurance value describing the quality of the product";
4617 variable_definition =
4618 harp_ingestion_register_variable_full_read(product_definition,
4619 "SO2_column_number_density_validity",
4620 harp_type_int8, 1, dimension_type_1d, NULL,
4621 description, NULL, NULL, read_product_qa_value);
4622
4623 path = "data/PRODUCT/qa_value[]";
4624 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4625
4626
4627 /* SO2_column_number_density_amf */
4628 description = "total air-mass factor of the SO2 column";
4629 variable_definition =
4630 harp_ingestion_register_variable_full_read(product_definition, "SO2_column_number_density_amf", harp_type_float,
4631 1, dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS,
4632 NULL, read_so2_total_amf);
4633 harp_variable_definition_add_mapping(variable_definition, NULL, NULL,
4634 "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_total_column_air_mass_factor[]",
4635 "profile dimension sliced according to so2_column option");
4636
4637 /* SO2_column_number_density_amf_uncertainty_random */
4638 description = "random uncertainty of SO2 air-mass factor";
4639 variable_definition =
4640 harp_ingestion_register_variable_full_read(product_definition,
4641 "SO2_column_number_density_amf_uncertainty_random", harp_type_float,
4642 1, dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS,
4643 NULL, read_so2_total_amf_precision);
4644 path = "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_total_column_air_mass_factor_precision[]";
4645 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path,
4646 "profile dimension sliced according to so2_column option");
4647
4648 /* SO2_column_number_density_amf_uncertainty_systematic */
4649 description = "systematic uncertainty of SO2 air-mass factor";
4650 variable_definition =
4651 harp_ingestion_register_variable_full_read(product_definition,
4652 "SO2_column_number_density_amf_uncertainty_systematic",
4653 harp_type_float, 1, dimension_type_1d, NULL, description,
4654 HARP_UNIT_DIMENSIONLESS, NULL, read_so2_total_amf_trueness);
4655 path = "/data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_total_column_air_mass_factor_trueness[]";
4656 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path,
4657 "profile dimension sliced according to so2_column option");
4658
4659 /* sulfur_dioxide_slant_column */
4660 description = "SO2 slant column density";
4661 variable_definition =
4662 harp_ingestion_register_variable_full_read(product_definition,
4663 "SO2_slant_column_number_density",
4664 harp_type_float, 1, dimension_type_1d, NULL,
4665 description, "mol/m^2", NULL,
4666 read_results_sulfur_dioxide_slant_column);
4667
4668 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_slant_column_corrected[]";
4669 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4670
4671 /* sulfur_dioxide_slant_column_precision */
4672 description = "random component of the uncertainty of the SO2 slant column density";
4673 variable_definition =
4674 harp_ingestion_register_variable_full_read(product_definition,
4675 "SO2_slant_column_number_density_uncertainty_random",
4676 harp_type_float, 1, dimension_type_1d, NULL,
4677 description, "mol/m^2", NULL,
4678 read_results_sulfur_dioxide_slant_column_precision);
4679
4680 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_slant_column_precision[]";
4681 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4682
4683 /* sulfur_dioxide_slant_column_trueness */
4684 description = "systematic component of the uncertainty of the SO2 slant column density";
4685 variable_definition =
4686 harp_ingestion_register_variable_full_read(product_definition,
4687 "SO2_slant_column_number_density_uncertainty_systematic",
4688 harp_type_float, 1, dimension_type_1d, NULL,
4689 description, "mol/m^2", NULL,
4690 read_results_sulfur_dioxide_slant_column_trueness);
4691
4692 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_slant_column_trueness[]";
4693 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4694
4695 /* cloud_radiance_fraction */
4696 description = "cloud radiance fraction";
4697 variable_definition =
4698 harp_ingestion_register_variable_full_read(product_definition,
4699 "cloud_fraction",
4700 harp_type_float, 1, dimension_type_1d, NULL,
4701 description, HARP_UNIT_DIMENSIONLESS, NULL,
4702 read_results_cloud_radiance_fraction);
4703
4704 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/cloud_radiance_fraction[]";
4705 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4706
4707 /* sulfur_dioxide_total_column_averaging_kernel */
4708 description = "averaging kernel for the SO2 total column";
4709 variable_definition =
4710 harp_ingestion_register_variable_full_read(product_definition,
4711 "SO2_column_number_density_avk",
4712 harp_type_float, 2, dimension_type_2d, NULL,
4713 description, HARP_UNIT_DIMENSIONLESS, NULL,
4714 read_results_sulfur_dioxide_total_column_avk);
4715
4716 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_total_column_averaging_kernel[]";
4717 description = "the vertical grid is inverted to make it ascending";
4718 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4719
4720 /* sulfur_dioxide_layer_pressure */
4721 description = "retrieved layer pressure of SO2";
4722 variable_definition =
4723 harp_ingestion_register_variable_full_read(product_definition, "SO2_layer_pressure", harp_type_float, 1,
4724 dimension_type_1d, NULL, description, "Pa", NULL,
4725 read_results_sulfur_dioxide_layer_pressure);
4726
4727 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_layer_pressure[]";
4728 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4729
4730 /* sulfur_dioxide_layer_pressure_uncertainty */
4731 description = "total error on retrieved layer pressure of SO2";
4732 variable_definition =
4733 harp_ingestion_register_variable_full_read(product_definition,
4734 "SO2_layer_pressure_uncertainty",
4735 harp_type_float, 1, dimension_type_1d, NULL,
4736 description, "Pa", NULL,
4737 read_results_sulfur_dioxide_layer_pressure_uncertainty);
4738
4739 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/sulfur_dioxide_layer_pressure_uncertainty[]";
4740 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4741
4742 /* surface_albedo */
4743 description = "surface albedo at 340 nm";
4744 variable_definition =
4745 harp_ingestion_register_variable_full_read(product_definition,
4746 "surface_albedo", harp_type_float, 1, dimension_type_1d,
4747 NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4748 read_results_surface_albedo);
4749 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_albedo[]";
4750 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4751
4752
4753 /* sulfur_dioxide_profile_apriori */
4754 description = "a priori SO2 profile (CAMS)";
4755 variable_definition =
4756 harp_ingestion_register_variable_full_read(product_definition,
4757 "SO2_column_number_density_apriori", harp_type_float, 2,
4758 dimension_type_2d, NULL, description, "mol/m^2", NULL,
4759 read_input_sulfur_dioxide_profile_apriori);
4760 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/sulfur_dioxide_profile_apriori[]";
4761 description = "the vertical grid is inverted to make it ascending";
4762 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4763
4764 /* pressure_bounds */
4765 description = "pressure boundaries";
4766 /* Note: reusing logic from NO2 */
4767 variable_definition =
4768 harp_ingestion_register_variable_full_read(product_definition, "pressure_bounds", harp_type_double, 3,
4769 pressure_bounds_dimension_type, pressure_bounds_dimension,
4770 description, "Pa", NULL, read_no2_pressure_bounds);
4771 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/pressure_coefficient_a[], "
4772 "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/pressure_coefficient_b[], "
4773 "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/surface_pressure[]";
4774 description =
4775 "pressure in Pa at level k is derived from surface pressure in Pa as: pressure_coefficient_a[k] + "
4776 "pressure_coefficient_b[k] * surface_pressure[]; the top of atmosphere pressure is clamped to 1e-3 Pa";
4777 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
4778
4779 /* cloud_pressure */
4780 description = "Cloud top pressure";
4781 variable_definition =
4782 harp_ingestion_register_variable_full_read(product_definition,
4783 "cloud_pressure", harp_type_float, 1, dimension_type_1d,
4784 NULL, description, "Pa", NULL, read_input_cloud_pressure);
4785 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_pressure[]";
4786 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4787
4788 /* cloud_height */
4789 description = "cloud centre height above the surface";
4790 variable_definition =
4791 harp_ingestion_register_variable_full_read(product_definition, "cloud_height", harp_type_float, 1,
4792 dimension_type_1d, NULL, description, "m", NULL,
4793 read_input_cloud_height);
4794 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_height[]";
4795 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4796
4797 /* cloud_albedo */
4798 description = "cloud albedo";
4799 variable_definition =
4800 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo", harp_type_float, 1,
4801 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4802 read_input_cloud_albedo);
4803 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/cloud_albedo[]";
4804 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4805
4806 /* aerosol_index_340_380 */
4807 description = "aerosol absorbing index 340/380 pair";
4808 variable_definition =
4809 harp_ingestion_register_variable_full_read(product_definition, "absorbing_aerosol_index", harp_type_float, 1,
4810 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4811 read_input_aerosol_index);
4812 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/aerosol_index_340_380[]";
4813 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4814
4815 /* ozone_total_column */
4816 description = "O3 total column";
4817 variable_definition =
4818 harp_ingestion_register_variable_full_read(product_definition, "O3_column_number_density", harp_type_float, 1,
4819 dimension_type_1d, NULL, description, "mol/m^2", NULL,
4820 read_input_ozone_total_column);
4821 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/ozone_total_column";
4822 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4823
4824 /* scene_albedo */
4825 description = "effective scene albedo at 340 nm";
4826 variable_definition =
4827 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo", harp_type_float, 1,
4828 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4829 read_input_scene_albedo);
4830 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_albedo[]";
4831 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4832
4833 /* scene_pressure */
4834 description = "effective scene pressure at 340 nm";
4835 variable_definition =
4836 harp_ingestion_register_variable_full_read(product_definition, "scene_pressure", harp_type_float, 1,
4837 dimension_type_1d, NULL, description, "Pa", NULL,
4838 read_input_scene_pressure);
4839 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/scene_pressure[]";
4840 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
4841 }
4842
4843 /* CLD */
4844 static void register_cld_product(void)
4845 {
4846 const char *path;
4847 const char *description;
4848
4849 harp_ingestion_module *module;
4850 harp_product_definition *product_definition;
4851 harp_variable_definition *variable_definition;
4852
4853 int include_validity = 1;
4854
4855 harp_dimension_type dimension_type_1d[1] = { harp_dimension_time };
4856
4857 const char *cld_band_option_values[3] = { "band3a", "band3c" };
4858
4859
4860 /* Product Registration Phase */
4861 module = harp_ingestion_register_module("S5_L2_CLD", "Sentinel-5", "EPS_SG", "SN5_02_CLD",
4862 "Sentinel-5 L2 CLD total column", ingestion_init, ingestion_done);
4863
4864 description = "which CLD band values to ingest: `band3a` (default) or `band3c`";
4865 harp_ingestion_register_option(module, "band", description, 2, cld_band_option_values);
4866
4867 product_definition = harp_ingestion_register_product(module, "S5_L2_CLD", NULL, read_dimensions);
4868
4869 register_core_variables_cld(product_definition, include_validity);
4870 register_geolocation_variables_cld(product_definition);
4871 register_additional_geolocation_variables_cld(product_definition);
4872 register_surface_variables_cld(product_definition);
4873 register_snow_ice_flag_variables(product_definition, "SN5_02_CLD");
4874
4875
4876 /* effective_cloud_fraction */
4877 description = "effective cloud fraction";
4878 variable_definition =
4879 harp_ingestion_register_variable_full_read(product_definition, "cloud_fraction", harp_type_float, 1,
4880 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4881 read_product_effective_cloud_fraction);
4882
4883 /* default (BAND-3A) */
4884 path = "/data/PRODUCT_BAND3A/effective_cloud_fraction[]";
4885 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4886
4887 /* alternative (BAND-3C) */
4888 path = "/data/PRODUCT_BAND3C/effective_cloud_fraction[]";
4889 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4890
4891 description = "effective cloud fraction precision";
4892 variable_definition =
4893 harp_ingestion_register_variable_full_read(product_definition, "cloud_fraction_uncertainty",
4894 harp_type_float, 1, dimension_type_1d, NULL, description,
4895 HARP_UNIT_DIMENSIONLESS, NULL,
4896 read_product_effective_cloud_fraction_uncertainty);
4897
4898 path = "/data/PRODUCT_BAND3A/effective_cloud_fraction_precision[]";
4899 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4900
4901 path = "/data/PRODUCT_BAND3C/effective_cloud_fraction_precision[]";
4902 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4903
4904 description = "cloud pressure";
4905 variable_definition =
4906 harp_ingestion_register_variable_full_read(product_definition, "cloud_pressure", harp_type_float, 1,
4907 dimension_type_1d, NULL, description, "Pa", NULL,
4908 read_product_cloud_pressure);
4909
4910 path = "/data/PRODUCT_BAND3A/cloud_pressure[]";
4911 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4912
4913 path = "/data/PRODUCT_BAND3C/cloud_pressure[]";
4914 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4915
4916 /* cloud_pressure_precision */
4917 description = "cloud pressure precision";
4918 variable_definition =
4919 harp_ingestion_register_variable_full_read(product_definition, "cloud_pressure_precision", harp_type_float,
4920 1, dimension_type_1d, NULL, description, "Pa", NULL,
4921 read_product_cloud_pressure_uncertainty);
4922
4923 path = "/data/PRODUCT_BAND3A/cloud_pressure_precision[]";
4924 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4925
4926 path = "/data/PRODUCT_BAND3C/cloud_pressure_precision[]";
4927 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4928
4929 description = "cloud height above sea-level";
4930 variable_definition =
4931 harp_ingestion_register_variable_full_read(product_definition, "cloud_height", harp_type_float, 1,
4932 dimension_type_1d, NULL, description, "m", NULL,
4933 read_product_cloud_height);
4934
4935 path = "/data/PRODUCT_BAND3A/cloud_height[]";
4936 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4937
4938 path = "/data/PRODUCT_BAND3C/cloud_height[]";
4939 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4940
4941 /* cloud_height_precision */
4942 description = "cloud height above sea-level precision";
4943 variable_definition =
4944 harp_ingestion_register_variable_full_read(product_definition, "cloud_height_precision", harp_type_float, 1,
4945 dimension_type_1d, NULL, description, "m", NULL,
4946 read_product_cloud_height_uncertainty);
4947
4948 path = "/data/PRODUCT_BAND3A/cloud_height_precision[]";
4949 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4950
4951 path = "/data/PRODUCT_BAND3C/cloud_height_precision[]";
4952 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4953
4954 /* processing_quality_flags */
4955 description = "quality assurance value describing the quality of the product";
4956 variable_definition =
4957 harp_ingestion_register_variable_full_read(product_definition, "cloud_fraction_validity", harp_type_int32, 1,
4958 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4959 read_product_qa_value);
4960
4961 path = "/data/PRODUCT_BAND3A/qa_value[]";
4962 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4963
4964 path = "/data/PRODUCT_BAND3C/qa_value[]";
4965 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4966
4967
4968 description = "scene albedo";
4969 variable_definition =
4970 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo", harp_type_float, 1,
4971 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4972 read_results_scene_albedo);
4973
4974 path = "data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo[]";
4975 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4976
4977 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo[]";
4978 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4979
4980 /* scene_albedo_precision */
4981 description = "scene albedo precision";
4982 variable_definition =
4983 harp_ingestion_register_variable_full_read(product_definition, "scene_albedo_uncertainty", harp_type_float, 1,
4984 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
4985 read_results_scene_albedo_uncertainty);
4986
4987 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo_precision[]";
4988 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
4989
4990 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/scene_albedo_precision[]";
4991 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
4992
4993 description = "scene pressure";
4994 variable_definition =
4995 harp_ingestion_register_variable_full_read(product_definition, "scene_pressure", harp_type_float, 1,
4996 dimension_type_1d, NULL, description, "Pa", NULL,
4997 read_results_scene_pressure);
4998
4999 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_pressure[]";
5000 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5001
5002 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/scene_pressure[]";
5003 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5004
5005 /* scene_pressure_precision */
5006 description = "scene pressure precision";
5007 variable_definition =
5008 harp_ingestion_register_variable_full_read(product_definition,
5009 "scene_pressure_uncertainty", harp_type_float,
5010 1, dimension_type_1d, NULL, description,
5011 "Pa", NULL, read_results_scene_pressure_uncertainty);
5012
5013 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_pressure_precision[]";
5014 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5015
5016 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/scene_pressure_precision[]";
5017 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5018
5019 description = "scene height above sea-level";
5020 variable_definition =
5021 harp_ingestion_register_variable_full_read(product_definition, "scene_height", harp_type_float, 1,
5022 dimension_type_1d, NULL, description, "m", NULL,
5023 read_results_scene_height);
5024
5025 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_height[]";
5026 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5027
5028 path = "/data/PRODUCT_BAND3C/sSUPPORT_DATA/DETAILED_RESULTS/cene_height[]";
5029 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5030
5031 /* scene_height_precision */
5032 description = "scene height above sea-level precision";
5033 variable_definition =
5034 harp_ingestion_register_variable_full_read(product_definition, "scene_height_uncertainty", harp_type_float, 1,
5035 dimension_type_1d, NULL, description, "m", NULL,
5036 read_results_scene_height_uncertainty);
5037
5038 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/scene_height_precision[]";
5039 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5040
5041 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/scene_height_precision[]";
5042 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5043
5044 description = "cloud albedo";
5045 variable_definition =
5046 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo", harp_type_float, 1,
5047 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
5048 read_results_cloud_albedo);
5049
5050 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/cloud_albedo[]";
5051 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5052
5053 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/cloud_albedo[]";
5054 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5055
5056 /* cloud_albedo_precision */
5057 description = "cloud albedo precision";
5058 variable_definition =
5059 harp_ingestion_register_variable_full_read(product_definition, "cloud_albedo_uncertainty", harp_type_float, 1,
5060 dimension_type_1d, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
5061 read_results_cloud_albedo_uncertainty);
5062
5063 path = "/data/PRODUCT_BAND3A/SUPPORT_DATA/DETAILED_RESULTS/cloud_albedo_precision[]";
5064 harp_variable_definition_add_mapping(variable_definition, "band=band3a or band unset", NULL, path, NULL);
5065
5066 path = "/data/PRODUCT_BAND3C/SUPPORT_DATA/DETAILED_RESULTS/cloud_albedo_precision[]";
5067 harp_variable_definition_add_mapping(variable_definition, "band=band3c", NULL, path, NULL);
5068 }
5069
5070
5071
5072
5073 /* CO */
5074 static void register_co_product(void)
5075 {
5076 const char *path;
5077 const char *description;
5078
5079 harp_ingestion_module *module;
5080 harp_product_definition *product_definition;
5081 harp_variable_definition *variable_definition;
5082
5083 int include_validity = 1;
5084
5085 harp_dimension_type dimension_type[2] = { harp_dimension_time, harp_dimension_vertical };
5086
5087 /* Product Registration Phase */
5088 module = harp_ingestion_register_module("S5_L2_CO", "Sentinel-5", "EPS_SG", "SN5_02_CO_",
5089 "Sentinel-5 L2 CO total column", ingestion_init, ingestion_done);
5090
5091 /* harp_ingestion_register_product( module ptr, "ProductShortName", options table (NULL), dimension-callback ) */
5092 product_definition = harp_ingestion_register_product(module, "S5_L2_CO", NULL, read_dimensions);
5093
5094 /* Variables' Registration Phase */
5095
5096 register_core_variables(product_definition, include_validity);
5097 register_geolocation_variables(product_definition);
5098 register_additional_geolocation_variables(product_definition);
5099 register_surface_variables(product_definition, "SN5_02_CO_");
5100 register_snow_ice_flag_variables(product_definition, "SN5_02_CO_");
5101
5102 /* CO_column_number_density */
5103 description = "vertically integrated CO column density";
5104 variable_definition =
5105 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density", harp_type_float, 1,
5106 dimension_type, NULL, description, "mol/m^2", NULL,
5107 read_product_carbon_monoxide_total_column);
5108 path = "data/PRODUCT/carbon_monoxide_total_column";
5109 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5110
5111 /* CO_column_number_density_uncertainty */
5112 description = "uncertainty of the vertically integrated CO column density (standard error)";
5113 variable_definition =
5114 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density_uncertainty",
5115 harp_type_float, 1, dimension_type, NULL, description, "mol/m^2",
5116 NULL, read_product_carbon_monoxide_total_column_precision);
5117 path = "data/PRODUCT/carbon_monoxide_total_column_precision[]";
5118 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5119
5120 /* CO_column_number_density_validity */
5121 description = "continuous quality descriptor, varying between 0 (no data) and 100 (full quality data)";
5122 variable_definition =
5123 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density_validity",
5124 harp_type_int32, 1, dimension_type, NULL, description, NULL, NULL,
5125 read_product_qa_value);
5126 path = "data/PRODUCT/qa_value[]";
5127 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5128
5129 /* CO_column_number_density_avk */
5130 description = "CO total column averaging kernel";
5131 variable_definition =
5132 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density_avk", harp_type_float,
5133 2, dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
5134 read_co_column_number_density_avk);
5135 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/carbon_monoxide_total_column_averaging_kernel[]";
5136 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5137
5138 /* H2O_column_number_density */
5139 description = "H2O total column density";
5140 variable_definition =
5141 harp_ingestion_register_variable_full_read(product_definition, "H2O_column_number_density", harp_type_float, 1,
5142 dimension_type, NULL, description, "mol/m^2", NULL,
5143 read_results_water_total_column);
5144 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/water_total_column[]";
5145 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5146
5147 /* H2O_162_column_number_density */
5148 description = "HDO total column";
5149 variable_definition =
5150 harp_ingestion_register_variable_full_read(product_definition, "H2O_162_column_number_density",
5151 harp_type_float, 1, dimension_type, NULL, description, "mol/m^2",
5152 NULL, read_results_semiheavy_water_total_column);
5153 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/semiheavy_water_total_column[]";
5154 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5155
5156 /* CH4_column_number_density */
5157 description = "non scatering CH4 total column";
5158 variable_definition =
5159 harp_ingestion_register_variable_full_read(product_definition, "CH4_column_number_density", harp_type_float, 1,
5160 dimension_type, NULL, description, "mol/m2", NULL,
5161 read_results_methane_total_column_prefit);
5162 path = "data/PRODUCT/SUPPORT_DATA/INPUT_DATA/methane_total_column_prefit[]";
5163 description = "the vertical grid is inverted to make it ascending";
5164 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
5165
5166 /* cloud_height */
5167 description = "cloud centre height above the surface";
5168 variable_definition =
5169 harp_ingestion_register_variable_full_read(product_definition, "cloud_height", harp_type_float, 1,
5170 dimension_type, NULL, description, "m", NULL,
5171 read_results_cloud_centre_height);
5172 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/cloud_centre_height[]";
5173 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5174
5175 /* cloud_optical_depth */
5176 description = "cloud optical depth at 2330 nm";
5177 variable_definition =
5178 harp_ingestion_register_variable_full_read(product_definition, "cloud_optical_depth", harp_type_float, 1,
5179 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
5180 read_results_cloud_optical_depth);
5181 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/cloud_optical_depth[]";
5182 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5183
5184 /* surface_albedo */
5185 description = "surface albedo";
5186 variable_definition =
5187 harp_ingestion_register_variable_full_read(product_definition, "surface_albedo", harp_type_float, 1,
5188 dimension_type, NULL, description, HARP_UNIT_DIMENSIONLESS, NULL,
5189 read_results_surface_albedo);
5190 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/surface_albedo[]";
5191 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
5192
5193 /* CO_column_number_density_apriori */
5194 description = "a-priori CO profile";
5195 variable_definition =
5196 harp_ingestion_register_variable_full_read(product_definition, "CO_column_number_density_apriori",
5197 harp_type_float, 2, dimension_type, NULL, description, "mol/m2",
5198 NULL, read_results_carbon_monoxide_profile_apriori);
5199 description = "the vertical grid is inverted to make it ascending";
5200 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/carbon_monoxide_profile_apriori[]";
5201 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
5202
5203 /* CH4_column_number_density_apriori */
5204 description = "a-priori CH4 profile";
5205 variable_definition =
5206 harp_ingestion_register_variable_full_read(product_definition, "CH4_column_number_density_apriori",
5207 harp_type_float, 2, dimension_type, NULL, description, "mol/m2",
5208 NULL, read_results_methane_profile_apriori);
5209 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/methane_profile_apriori[]";
5210 description = "the vertical grid is inverted to make it ascending";
5211 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
5212
5213 /* dry_air_column_number_density */
5214 description = "column number density profile of dry air";
5215 variable_definition =
5216 harp_ingestion_register_variable_full_read(product_definition, "dry_air_column_number_density",
5217 harp_type_float, 1, dimension_type, NULL, description, "mol/m2",
5218 NULL, read_results_dry_air_column);
5219 path = "data/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/dry_air_column[]";
5220 description = "the vertical grid is inverted to make it ascending";
5221 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
5222 }
5223
5224
5225 int harp_ingestion_module_s5_l2_init(void)
5226 {
5227 register_aui_product();
5228 register_ch4_product();
5229 register_no2_product();
5230 register_o3_product();
5231 register_so2_product();
5232 register_cld_product();
5233 register_co_product();
5234
5235 return 0;
5236 }