Debian Codegraph @

libharp/harp-ingest-tes_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 <stdlib.h>
36 #include <string.h>
37 #include <stdio.h>
38
39 #define SECONDS_FROM_1993_TO_2000 (220838400 + 5)
40
41 typedef struct ingest_info_struct
42 {
43 const char *swath_name;
44 const char *value_variable_name;
45 const char *error_variable_name;
46
47 coda_product *product;
48 coda_cursor swath_cursor;
49 coda_cursor geo_cursor;
50
51 long num_times;
52 long num_levels;
53 } ingest_info;
54
55 static int init_cursors(ingest_info *info)
56 {
57 if (coda_cursor_set_product(&info->swath_cursor, info->product) != 0)
58 {
59 harp_set_error(HARP_ERROR_CODA, NULL);
60 return -1;
61 }
62 if (coda_cursor_goto(&info->swath_cursor, "/HDFEOS/SWATHS") != 0)
63 {
64 harp_set_error(HARP_ERROR_CODA, NULL);
65 return -1;
66 }
67 if (coda_cursor_goto_record_field_by_name(&info->swath_cursor, info->swath_name) != 0)
68 {
69 harp_set_error(HARP_ERROR_CODA, NULL);
70 return -1;
71 }
72 info->geo_cursor = info->swath_cursor;
73 if (coda_cursor_goto_record_field_by_name(&info->swath_cursor, "Data_Fields") != 0)
74 {
75 harp_set_error(HARP_ERROR_CODA, NULL);
76 return -1;
77 }
78 if (coda_cursor_goto_record_field_by_name(&info->geo_cursor, "Geolocation_Fields") != 0)
79 {
80 harp_set_error(HARP_ERROR_CODA, NULL);
81 return -1;
82 }
83
84 return 0;
85 }
86
87 static int get_dimensions(ingest_info *info)
88 {
89 coda_cursor cursor;
90 long coda_dimension[CODA_MAX_NUM_DIMS];
91 int num_coda_dimensions;
92
93 cursor = info->swath_cursor;
94 if (coda_cursor_goto_record_field_by_name(&cursor, "Altitude") != 0)
95 {
96 harp_set_error(HARP_ERROR_CODA, NULL);
97 return -1;
98 }
99 if (coda_cursor_get_array_dim(&cursor, &num_coda_dimensions, coda_dimension) != 0)
100 {
101 harp_set_error(HARP_ERROR_CODA, NULL);
102 return -1;
103 }
104
105 info->num_times = coda_dimension[0];
106 info->num_levels = coda_dimension[1];
107
108 return 0;
109 }
110
111 static int get_variable_attributes(coda_cursor *cursor, double *missing_value, double *scale_factor, double *offset)
112 {
113 if (coda_cursor_goto_attributes(cursor) != 0)
114 {
115 harp_set_error(HARP_ERROR_CODA, NULL);
116 return -1;
117 }
118 if (coda_cursor_goto_record_field_by_name(cursor, "MissingValue") != 0)
119 {
120 harp_set_error(HARP_ERROR_CODA, NULL);
121 return -1;
122 }
123 if (coda_cursor_goto_first_array_element(cursor) != 0)
124 {
125 harp_set_error(HARP_ERROR_CODA, NULL);
126 return -1;
127 }
128 if (coda_cursor_read_double(cursor, missing_value) != 0)
129 {
130 harp_set_error(HARP_ERROR_CODA, NULL);
131 return -1;
132 }
133 coda_cursor_goto_parent(cursor);
134 coda_cursor_goto_parent(cursor);
135
136 if (coda_cursor_goto_record_field_by_name(cursor, "ScaleFactor") != 0)
137 {
138 /* use a scale factor of 1 */
139 *scale_factor = 1;
140 }
141 else
142 {
143 if (coda_cursor_goto_first_array_element(cursor) != 0)
144 {
145 harp_set_error(HARP_ERROR_CODA, NULL);
146 return -1;
147 }
148 if (coda_cursor_read_double(cursor, scale_factor) != 0)
149 {
150 harp_set_error(HARP_ERROR_CODA, NULL);
151 return -1;
152 }
153 coda_cursor_goto_parent(cursor);
154 coda_cursor_goto_parent(cursor);
155 }
156
157 if (coda_cursor_goto_record_field_by_name(cursor, "Offset") != 0)
158 {
159 /* use an offset of 0 */
160 *offset = 0;
161 }
162 else
163 {
164 if (coda_cursor_goto_first_array_element(cursor) != 0)
165 {
166 harp_set_error(HARP_ERROR_CODA, NULL);
167 return -1;
168 }
169 if (coda_cursor_read_double(cursor, offset) != 0)
170 {
171 harp_set_error(HARP_ERROR_CODA, NULL);
172 return -1;
173 }
174 coda_cursor_goto_parent(cursor);
175 coda_cursor_goto_parent(cursor);
176 }
177 coda_cursor_goto_parent(cursor);
178
179 return 0;
180 }
181
182 static int read_variable(coda_cursor *cursor, const char *name, int num_dimensions, long dimension_0, long dimension_1,
183 harp_array data)
184 {
185 double missing_value;
186 double scale_factor;
187 double offset;
188 long num_elements;
189 long coda_dimension[CODA_MAX_NUM_DIMS];
190 int num_coda_dimensions;
191 long i;
192
193 if (coda_cursor_goto_record_field_by_name(cursor, name) != 0)
194 {
195 harp_set_error(HARP_ERROR_CODA, NULL);
196 return -1;
197 }
198 if (coda_cursor_get_array_dim(cursor, &num_coda_dimensions, coda_dimension) != 0)
199 {
200 harp_set_error(HARP_ERROR_CODA, NULL);
201 return -1;
202 }
203 if (num_coda_dimensions != num_dimensions)
204 {
205 harp_set_error(HARP_ERROR_INGESTION, "product error detected in TES L2 product (variable %s has %d dimensions, "
206 "expected %d)", name, num_coda_dimensions, num_dimensions);
207 return -1;
208 }
209 if (dimension_0 != coda_dimension[0])
210 {
211 harp_set_error(HARP_ERROR_INGESTION,
212 "product error detected in TES L2 product (first dimension for variable %s "
213 "has %ld elements, expected %ld", name, coda_dimension[0], dimension_0);
214 return -1;
215 }
216 num_elements = coda_dimension[0];
217 if (num_dimensions > 1)
218 {
219 if (dimension_1 != coda_dimension[1])
220 {
221 harp_set_error(HARP_ERROR_INGESTION, "product error detected in TES L2 product (second dimension for "
222 "variable %s has %ld elements, expected %ld", name, coda_dimension[1], dimension_1);
223 return -1;
224 }
225 num_elements *= coda_dimension[1];
226 }
227 if (get_variable_attributes(cursor, &missing_value, &scale_factor, &offset) != 0)
228 {
229 return -1;
230 }
231 if (coda_cursor_read_double_array(cursor, data.double_data, coda_array_ordering_c) != 0)
232 {
233 harp_set_error(HARP_ERROR_CODA, NULL);
234 return -1;
235 }
236
237 /* apply scaling and filter for NaN */
238 for (i = 0; i < num_elements; i++)
239 {
240 if (data.double_data[i] == missing_value)
241 {
242 data.double_data[i] = coda_NaN();
243 }
244 else
245 {
246 data.double_data[i] = offset + scale_factor * data.double_data[i];
247 }
248 }
249
250 coda_cursor_goto_parent(cursor);
251
252 return 0;
253 }
254
255 static int read_dimensions(void *user_data, long dimension[HARP_NUM_DIM_TYPES])
256 {
257 ingest_info *info = (ingest_info *)user_data;
258
259 dimension[harp_dimension_time] = info->num_times;
260 dimension[harp_dimension_vertical] = info->num_levels;
261
262 return 0;
263 }
264
265 static int read_time(void *user_data, harp_array data)
266 {
267 ingest_info *info = (ingest_info *)user_data;
268 long i;
269
270 if (read_variable(&info->geo_cursor, "Time", 1, info->num_times, 0, data) != 0)
271 {
272 return -1;
273 }
274
275 /* convert time values from TAI93 to seconds since 2000-01-01 */
276 for (i = 0; i < info->num_times; i++)
277 {
278 data.double_data[i] -= SECONDS_FROM_1993_TO_2000;
279 }
280
281 return 0;
282 }
283
284 static int read_longitude(void *user_data, harp_array data)
285 {
286 ingest_info *info = (ingest_info *)user_data;
287
288 return read_variable(&info->geo_cursor, "Longitude", 1, info->num_times, 0, data);
289 }
290
291 static int read_latitude(void *user_data, harp_array data)
292 {
293 ingest_info *info = (ingest_info *)user_data;
294
295 return read_variable(&info->geo_cursor, "Latitude", 1, info->num_times, 0, data);
296 }
297
298 static int read_pressure(void *user_data, harp_array data)
299 {
300 ingest_info *info = (ingest_info *)user_data;
301
302 return read_variable(&info->swath_cursor, "Pressure", 2, info->num_times, info->num_levels, data);
303 }
304
305 static int read_altitude(void *user_data, harp_array data)
306 {
307 ingest_info *info = (ingest_info *)user_data;
308
309 if (read_variable(&info->swath_cursor, "Altitude", 2, info->num_times, info->num_levels, data) != 0)
310 {
311 return -1;
312 }
313
314 return 0;
315 }
316
317 static int read_value(void *user_data, harp_array data)
318 {
319 ingest_info *info = (ingest_info *)user_data;
320
321 return read_variable(&info->swath_cursor, info->value_variable_name, 2, info->num_times, info->num_levels, data);
322 }
323
324 static int read_error(void *user_data, harp_array data)
325 {
326 ingest_info *info = (ingest_info *)user_data;
327
328 return read_variable(&info->swath_cursor, info->error_variable_name, 2, info->num_times, info->num_levels, data);
329 }
330
331 static void ingestion_done(void *user_data)
332 {
333 ingest_info *info = (ingest_info *)user_data;
334
335 if (info != NULL)
336 {
337 free(info);
338 }
339 }
340
341 static int ingestion_init(const harp_ingestion_module *module, coda_product *product,
342 const harp_ingestion_options *options, harp_product_definition **definition, void **user_data,
343 const char *swath_name, const char *value_variable_name, const char *error_variable_name)
344 {
345 ingest_info *info;
346
347 (void)options;
348
349 info = malloc(sizeof(ingest_info));
350 if (info == NULL)
351 {
352 harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)",
353 sizeof(ingest_info), __FILE__, __LINE__);
354 return -1;
355 }
356 info->product = product;
357 info->swath_name = swath_name;
358 info->value_variable_name = value_variable_name;
359 info->error_variable_name = error_variable_name;
360
361 if (init_cursors(info) != 0)
362 {
363 ingestion_done(info);
364 return -1;
365 }
366 if (get_dimensions(info) != 0)
367 {
368 ingestion_done(info);
369 return -1;
370 }
371
372 *definition = *module->product_definition;
373 *user_data = info;
374
375 return 0;
376 }
377
378 static int ingestion_init_ch3oh_nadir(const harp_ingestion_module *module, coda_product *product,
379 const harp_ingestion_options *options, harp_product_definition **definition,
380 void **user_data)
381 {
382 return ingestion_init(module, product, options, definition, user_data, "CH3OHNadirSwath", "CH3OH",
383 "CH3OHPrecision");
384 }
385
386 static int ingestion_init_ch4_nadir(const harp_ingestion_module *module, coda_product *product,
387 const harp_ingestion_options *options, harp_product_definition **definition,
388 void **user_data)
389 {
390 return ingestion_init(module, product, options, definition, user_data, "CH4NadirSwath", "CH4", "CH4Precision");
391 }
392
393 static int ingestion_init_co_nadir(const harp_ingestion_module *module, coda_product *product,
394 const harp_ingestion_options *options, harp_product_definition **definition,
395 void **user_data)
396 {
397 return ingestion_init(module, product, options, definition, user_data, "CONadirSwath", "CO", "COPrecision");
398 }
399
400 static int ingestion_init_co2_nadir(const harp_ingestion_module *module, coda_product *product,
401 const harp_ingestion_options *options, harp_product_definition **definition,
402 void **user_data)
403 {
404 return ingestion_init(module, product, options, definition, user_data, "CO2NadirSwath", "CO2", "CO2Precision");
405 }
406
407 static int ingestion_init_h2o_nadir(const harp_ingestion_module *module, coda_product *product,
408 const harp_ingestion_options *options, harp_product_definition **definition,
409 void **user_data)
410 {
411 return ingestion_init(module, product, options, definition, user_data, "H2ONadirSwath", "H2O", "H2OPrecision");
412 }
413
414 static int ingestion_init_hcooh_nadir(const harp_ingestion_module *module, coda_product *product,
415 const harp_ingestion_options *options, harp_product_definition **definition,
416 void **user_data)
417 {
418 return ingestion_init(module, product, options, definition, user_data, "HCOOHNadirSwath", "HCOOH",
419 "HCOOHPrecision");
420 }
421
422 static int ingestion_init_hdo_nadir(const harp_ingestion_module *module, coda_product *product,
423 const harp_ingestion_options *options, harp_product_definition **definition,
424 void **user_data)
425 {
426 return ingestion_init(module, product, options, definition, user_data, "HDONadirSwath", "HDO", "HDOPrecision");
427 }
428
429 static int ingestion_init_n2o_nadir(const harp_ingestion_module *module, coda_product *product,
430 const harp_ingestion_options *options, harp_product_definition **definition,
431 void **user_data)
432 {
433 return ingestion_init(module, product, options, definition, user_data, "N2ONadirSwath", "N2O", "N2OPrecision");
434 }
435
436 static int ingestion_init_nh3_nadir(const harp_ingestion_module *module, coda_product *product,
437 const harp_ingestion_options *options, harp_product_definition **definition,
438 void **user_data)
439 {
440 return ingestion_init(module, product, options, definition, user_data, "NH3NadirSwath", "NH3", "NH3Precision");
441 }
442
443 static int ingestion_init_o3_nadir(const harp_ingestion_module *module, coda_product *product,
444 const harp_ingestion_options *options, harp_product_definition **definition,
445 void **user_data)
446 {
447 return ingestion_init(module, product, options, definition, user_data, "O3NadirSwath", "O3", "O3Precision");
448 }
449
450 static int ingestion_init_tatm_nadir(const harp_ingestion_module *module, coda_product *product,
451 const harp_ingestion_options *options, harp_product_definition **definition,
452 void **user_data)
453 {
454 return ingestion_init(module, product, options, definition, user_data, "TATMNadirSwath", "TATM", "TATMPrecision");
455 }
456
457 static int ingestion_init_ch4_limb(const harp_ingestion_module *module, coda_product *product,
458 const harp_ingestion_options *options, harp_product_definition **definition,
459 void **user_data)
460 {
461 return ingestion_init(module, product, options, definition, user_data, "CH4LimbSwath", "CH4", "CH4Precision");
462 }
463
464 static int ingestion_init_h2o_limb(const harp_ingestion_module *module, coda_product *product,
465 const harp_ingestion_options *options, harp_product_definition **definition,
466 void **user_data)
467 {
468 return ingestion_init(module, product, options, definition, user_data, "H2OLimbSwath", "H2O", "H2OPrecision");
469 }
470
471 static int ingestion_init_hdo_limb(const harp_ingestion_module *module, coda_product *product,
472 const harp_ingestion_options *options, harp_product_definition **definition,
473 void **user_data)
474 {
475 return ingestion_init(module, product, options, definition, user_data, "HDOLimbSwath", "HDO", "HDOPrecision");
476 }
477
478 static int ingestion_init_hno3_limb(const harp_ingestion_module *module, coda_product *product,
479 const harp_ingestion_options *options, harp_product_definition **definition,
480 void **user_data)
481 {
482 return ingestion_init(module, product, options, definition, user_data, "HNO3LimbSwath", "HNO3", "HNO3Precision");
483 }
484
485 static int ingestion_init_no2_limb(const harp_ingestion_module *module, coda_product *product,
486 const harp_ingestion_options *options, harp_product_definition **definition,
487 void **user_data)
488 {
489 return ingestion_init(module, product, options, definition, user_data, "O3LimbSwath", "O3", "O3Precision");
490 }
491
492 static int ingestion_init_o3_limb(const harp_ingestion_module *module, coda_product *product,
493 const harp_ingestion_options *options, harp_product_definition **definition,
494 void **user_data)
495 {
496 return ingestion_init(module, product, options, definition, user_data, "O3LimbSwath", "O3", "O3Precision");
497 }
498
499 static int ingestion_init_tatm_limb(const harp_ingestion_module *module, coda_product *product,
500 const harp_ingestion_options *options, harp_product_definition **definition,
501 void **user_data)
502 {
503 return ingestion_init(module, product, options, definition, user_data, "TATMLimbSwath", "TATM", "TATMPrecision");
504 }
505
506 static void register_datetime_variable(harp_product_definition *product_definition, const char *path)
507 {
508 harp_variable_definition *variable_definition;
509 harp_dimension_type dimension_type[1] = { harp_dimension_time };
510 const char *description;
511
512 description = "time of the measurement";
513 variable_definition = harp_ingestion_register_variable_full_read(product_definition, "datetime", harp_type_double,
514 1, dimension_type, NULL, description,
515 "seconds since 2000-01-01", NULL, read_time);
516
517 description = "the time converted from TAI93 to seconds since 2000-01-01T00:00:00";
518 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);
519 }
520
521 static void register_longitude_variable(harp_product_definition *product_definition, const char *path)
522 {
523 harp_variable_definition *variable_definition;
524 harp_dimension_type dimension_type[1] = { harp_dimension_time };
525 const char *description;
526
527 description = "tangent longitude";
528 variable_definition = harp_ingestion_register_variable_full_read(product_definition, "longitude", harp_type_double,
529 1, dimension_type, NULL, description,
530 "degree_east", NULL, read_longitude);
531 harp_variable_definition_set_valid_range_double(variable_definition, -180.0, 180.0);
532 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
533 }
534
535 static void register_latitude_variable(harp_product_definition *product_definition, const char *path)
536 {
537 harp_variable_definition *variable_definition;
538 harp_dimension_type dimension_type[1] = { harp_dimension_time };
539 const char *description;
540
541 description = "tangent latitude";
542 variable_definition = harp_ingestion_register_variable_full_read(product_definition, "latitude", harp_type_double,
543 1, dimension_type, NULL, description,
544 "degree_north", NULL, read_latitude);
545 harp_variable_definition_set_valid_range_double(variable_definition, -90.0, 90.0);
546 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
547 }
548
549 static void register_altitude_variable(harp_product_definition *product_definition, const char *path)
550 {
551 harp_variable_definition *variable_definition;
552 harp_dimension_type dimension_type[2] = { harp_dimension_time, harp_dimension_vertical };
553 const char *description;
554
555 description = "altitude per profile level";
556 variable_definition = harp_ingestion_register_variable_full_read(product_definition, "altitude", harp_type_double,
557 2, dimension_type, NULL, description, "m", NULL,
558 read_altitude);
559 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
560 }
561
562 static void register_pressure_variable(harp_product_definition *product_definition, const char *path)
563 {
564 harp_variable_definition *variable_definition;
565 harp_dimension_type dimension_type[2] = { harp_dimension_time, harp_dimension_vertical };
566 const char *description;
567
568 description = "pressure per profile level";
569 variable_definition = harp_ingestion_register_variable_full_read(product_definition, "pressure", harp_type_double,
570 2, dimension_type, NULL, description, "hPa", NULL,
571 read_pressure);
572 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
573 }
574
575 static void register_nadir_product(const char *gas_code, const char *gas_name, const char *product_type,
576 int (*ingestion_init)(const harp_ingestion_module *module,
577 coda_product *product,
578 const harp_ingestion_options *options,
579 harp_product_definition **definition, void **user_data))
580 {
581 harp_ingestion_module *module;
582 harp_product_definition *product_definition;
583 harp_variable_definition *variable_definition;
584 harp_dimension_type dimension_type[2] = { harp_dimension_time, harp_dimension_vertical };
585 char name[81], description[81], path[255];
586
587 sprintf(name, "TES_L2_%s_Nadir", gas_code);
588 sprintf(description, "TES %s nadir profile", gas_name);
589 module = harp_ingestion_register_module(name, "TES", "AURA_TES", product_type, description,
590 ingestion_init, ingestion_done);
591
592 /* Nadir product */
593 product_definition = harp_ingestion_register_product(module, name, NULL, read_dimensions);
594
595 /* datetime */
596 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Geolocation_Fields/Time[]", gas_code);
597 register_datetime_variable(product_definition, path);
598
599 /* longitude and latitude */
600 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Geolocation_Fields/Longitude[]", gas_code);
601 register_longitude_variable(product_definition, path);
602 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Geolocation_Fields/Latitude[]", gas_code);
603 register_latitude_variable(product_definition, path);
604
605 /* altitude */
606 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/Altitude[]", gas_code);
607 register_altitude_variable(product_definition, path);
608
609 /* pressure */
610 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/Pressure[]", gas_code);
611 register_pressure_variable(product_definition, path);
612
613 if (strcmp(gas_code, "Temperature") == 0)
614 {
615 /* temperature */
616 sprintf(name, "temperature");
617 sprintf(description, "atmospheric temperature");
618 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/%s[]", gas_code, gas_code);
619 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
620 dimension_type, NULL, description, "K", NULL,
621 read_value);
622 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
623
624 /* temperature_uncertainty */
625 sprintf(name, "temperature_uncertainty");
626 sprintf(description, "atmospheric temperature precision");
627 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/%sPrecision[]", gas_code, gas_code);
628 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
629 dimension_type, NULL, description, "K", NULL,
630 read_error);
631 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
632 }
633 else
634 {
635 /* volume_mixing_ratio */
636 sprintf(name, "%s_volume_mixing_ratio", gas_code);
637 sprintf(description, "%s volume mixing ratio", gas_name);
638 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/%s[]", gas_code, gas_code);
639 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
640 dimension_type, NULL, description, "ppv", NULL,
641 read_value);
642 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
643
644 /* volume_mixing_ratio_uncertainty */
645 sprintf(name, "%s_volume_mixing_ratio_uncertainty", gas_code);
646 sprintf(description, "%s volume mixing ratio precision", gas_name);
647 sprintf(path, "/HDFEOS/SWATHS/%sNadirSwath/Data_Fields/%sPrecision[]", gas_code, gas_code);
648 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
649 dimension_type, NULL, description, "ppv", NULL,
650 read_error);
651 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
652 }
653 }
654
655 static void register_limb_product(const char *gas_code, const char *gas_name, const char *product_type,
656 int (*ingestion_init)(const harp_ingestion_module *module,
657 coda_product *product,
658 const harp_ingestion_options *options,
659 harp_product_definition **definition, void **user_data))
660 {
661 harp_ingestion_module *module;
662 harp_product_definition *product_definition;
663 harp_variable_definition *variable_definition;
664 harp_dimension_type dimension_type[2] = { harp_dimension_time, harp_dimension_vertical };
665 char name[81], description[81], path[255];
666
667 sprintf(name, "TES_L2_%s_Limb", gas_code);
668 sprintf(description, "TES %s limb profile", gas_name);
669 module = harp_ingestion_register_module(name, "TES", "AURA_TES", product_type, description,
670 ingestion_init, ingestion_done);
671
672 /* Limb product */
673 product_definition = harp_ingestion_register_product(module, name, NULL, read_dimensions);
674
675 /* datetime */
676 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Geolocation_Fields/Time[]", gas_code);
677 register_datetime_variable(product_definition, path);
678
679 /* longitude and latitude */
680 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Geolocation_Fields/Longitude[]", gas_code);
681 register_longitude_variable(product_definition, path);
682 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Geolocation_Fields/Latitude[]", gas_code);
683 register_latitude_variable(product_definition, path);
684
685 /* altitude */
686 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/Altitude[]", gas_code);
687 register_altitude_variable(product_definition, path);
688
689 /* pressure */
690 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/Pressure[]", gas_code);
691 register_pressure_variable(product_definition, path);
692
693 if (strcmp(gas_code, "Temperature") == 0)
694 {
695 /* temperature */
696 sprintf(name, "temperature");
697 sprintf(description, "atmospheric temperature");
698 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/%s[]", gas_code, gas_code);
699 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
700 dimension_type, NULL, description, "K", NULL,
701 read_value);
702 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
703
704 /* volume_mixing_ratio_uncertainty */
705 sprintf(name, "temperature_uncertainty");
706 sprintf(description, "atmospheric temperature precision");
707 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/%sPrecision[]", gas_code, gas_code);
708 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
709 dimension_type, NULL, description, "K", NULL,
710 read_error);
711 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
712 }
713 else
714 {
715 /* volume_mixing_ratio */
716 sprintf(name, "%s_volume_mixing_ratio", gas_code);
717 sprintf(description, "%s volume mixing ratio", gas_name);
718 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/%s[]", gas_code, gas_code);
719 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
720 dimension_type, NULL, description, "ppv", NULL,
721 read_value);
722 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
723
724 /* volume_mixing_ratio_uncertainty */
725 sprintf(name, "%s_volume_mixing_ratio_uncertainty", gas_code);
726 sprintf(description, "%s volume mixing ratio precision", gas_name);
727 sprintf(path, "/HDFEOS/SWATHS/%sLimbSwath/Data_Fields/%sPrecision[]", gas_code, gas_code);
728 variable_definition = harp_ingestion_register_variable_full_read(product_definition, name, harp_type_double, 2,
729 dimension_type, NULL, description, "ppv", NULL,
730 read_error);
731 harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);
732 }
733 }
734
735 int harp_ingestion_module_tes_l2_init(void)
736 {
737 register_nadir_product("CH3OH", "methanol", "TL2MTLN", ingestion_init_ch3oh_nadir);
738 register_nadir_product("CH4", "methane", "TL2CH4N", ingestion_init_ch4_nadir);
739 register_nadir_product("CO", "carbon monoxide", "TL2CON", ingestion_init_co_nadir);
740 register_nadir_product("CO2", "carbon dioxide", "TL2CO2N", ingestion_init_co2_nadir);
741 register_nadir_product("H2O", "water vapor", "TL2H2ON", ingestion_init_h2o_nadir);
742 register_nadir_product("HCOOH", "formic acid", "TL2FORN", ingestion_init_hcooh_nadir);
743 register_nadir_product("HDO", "deuterium oxide", "TL2HDON", ingestion_init_hdo_nadir);
744 register_nadir_product("N2O", "nitrous oxide", "TL2N2ON", ingestion_init_n2o_nadir);
745 register_nadir_product("NH3", "ammonia", "TL2NH3N", ingestion_init_nh3_nadir);
746 register_nadir_product("O3", "ozone", "TL2O3N", ingestion_init_o3_nadir);
747 register_nadir_product("Temperature", NULL, "TL2ATMTN", ingestion_init_tatm_nadir);
748
749 register_limb_product("CH4", "methane", "TL2CH4L", ingestion_init_ch4_limb);
750 register_limb_product("H2O", "water vapor", "TL2H2OL", ingestion_init_h2o_limb);
751 register_limb_product("HDO", "deuterium oxide", "TL2HDOL", ingestion_init_hdo_limb);
752 register_limb_product("HNO3", "nitric acid", "TL2HNO3L", ingestion_init_hno3_limb);
753 register_limb_product("NO2", "nitrogen dioxide", "TL2NO2L", ingestion_init_no2_limb);
754 register_limb_product("O3", "ozone", "TL2O3L", ingestion_init_o3_limb);
755 register_limb_product("Temperature", NULL, "TL2ATMTL", ingestion_init_tatm_limb);
756
757 return 0;
758 }