File: harp-ingest-iasi_l1.c

package info (click to toggle)
harp 1.5%2Bdata-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 54,032 kB
  • sloc: xml: 286,510; ansic: 143,710; yacc: 1,910; python: 913; makefile: 600; lex: 574; sh: 69
file content (651 lines) | stat: -rw-r--r-- 22,861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*
 * Copyright (C) 2015-2018 S[&]T, The Netherlands.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "coda.h"
#include "harp-ingestion.h"
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef enum main_data_variable_enum
{
    DATETIME,
    LONGITUDE,
    LATITUDE
} main_data_variable;

#define CHECKED_MALLOC(v, s) v = malloc(s); if (v == NULL) { harp_set_error(HARP_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", s, __FILE__, __LINE__); return -1;}

#define SCANS_PER_SCANLINE     30
#define SPECTRA_PER_SCAN        4
#define SPECTRA_PER_SCANLINE   (SPECTRA_PER_SCAN * SCANS_PER_SCANLINE)

typedef struct ingest_info_struct
{
    coda_product *product;
    int format_version;
    long mdr_records;   /* Total number of MDR records (valid scanlines and dummy records) */
    long valid_scanlines;       /* Each file is a series of scanlines, each scanline is a series of scans, each scan is a 2x2 matrix of spectral measurements. */
    coda_cursor *mdr_cursors;
    long num_main;      /* Number spectral measurements in the file (number scanlines * 30 * 4) */
    long num_pixels;    /* Number of pixels in 1 scan (will usually be 8700) */
    int16_t nr_scale_factors;
    int16_t *scale_factors;
    int16_t *channel_first;
    int16_t *channel_last;
} ingest_info;

static int get_main_data(ingest_info *info, const char *fieldname, main_data_variable var_type,
                         double *double_data_array)
{
    coda_cursor cursor;
    double *double_data;
    double locations[SPECTRA_PER_SCANLINE * 2];
    long mdr_nr, i, offset;

    double_data = double_data_array;
    for (mdr_nr = 0; mdr_nr < info->valid_scanlines; mdr_nr++)
    {
        cursor = info->mdr_cursors[mdr_nr];
        if (coda_cursor_goto(&cursor, fieldname) != 0)
        {
            harp_set_error(HARP_ERROR_CODA, NULL);
            return -1;
        }
        switch (var_type)
        {
            case DATETIME:
                if (coda_cursor_read_double(&cursor, double_data) != 0)
                {
                    harp_set_error(HARP_ERROR_CODA, NULL);
                    return -1;
                }
                double_data++;
                break;
            case LONGITUDE:
            case LATITUDE:
                if (coda_cursor_read_double_array(&cursor, locations, coda_array_ordering_c) != 0)
                {
                    harp_set_error(HARP_ERROR_CODA, NULL);
                    return -1;
                }
                if (var_type == LONGITUDE)
                {
                    offset = 0;
                }
                else
                {
                    offset = 1;
                }
                for (i = 0; i < SPECTRA_PER_SCANLINE; i++)
                {
                    *double_data = locations[2 * i + offset];
                    double_data++;
                }
                break;
        }
    }
    if (coda_cursor_goto_root(&cursor) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    return 0;
}

static int get_spectra_sample_data(ingest_info *info, long row, float *float_data_array)
{
    int32_t first_channel;
    int16_t measured_spectrum_data[8700];
    int16_t *spectrum_data;
    coda_cursor cursor;
    float *float_data;
    int16_t scale_nr, channel_nr;
    int16_t *start_of_this_spectrum;

    float_data = float_data_array;
    cursor = info->mdr_cursors[row / SPECTRA_PER_SCANLINE];
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefNsfirst1b") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_int32(&cursor, &first_channel) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    coda_cursor_goto_parent(&cursor);

    /* GS1cSpect contains int16 and has the following dimensions: */
    /* dim[0] = SCANS_PER_SCANLINE (fixed at 30)                  */
    /* dim[1] = SPECTRA_PER_SCAN (fixed at 4)                     */
    /* dim[2] = pixels in one spectrum (fixed at 8700)            */
    if (coda_cursor_goto_record_field_by_name(&cursor, "GS1cSpect") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    if (coda_cursor_read_int16_partial_array(&cursor, (row % SPECTRA_PER_SCANLINE) * info->num_pixels,
                                             info->num_pixels, measured_spectrum_data) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    spectrum_data = measured_spectrum_data;

    start_of_this_spectrum = spectrum_data;
    for (scale_nr = 0; scale_nr < info->nr_scale_factors; scale_nr++)
    {
        spectrum_data = start_of_this_spectrum + info->channel_first[scale_nr] - first_channel;
        for (channel_nr = info->channel_first[scale_nr]; channel_nr <= info->channel_last[scale_nr]; channel_nr++)
        {
            /* Because this data has limited precision (it was stored in */
            /* an int16), we store the radiance in a float.              */
            *float_data = (float)((*spectrum_data) * pow(10.0, -(info->scale_factors[scale_nr])));
            float_data++;
            spectrum_data++;
        }
    }
    spectrum_data = start_of_this_spectrum + info->num_pixels;

    return 0;
}

static int get_wavenumber_sample_data(ingest_info *info, long row, float *float_data_array)
{
    double sample_width;
    int32_t first_sample, last_sample, sample;
    coda_cursor cursor;
    float *float_data;
    long i;

    float_data = float_data_array;
    cursor = info->mdr_cursors[row / SPECTRA_PER_SCANLINE];
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefSpectDWn1b") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_double(&cursor, &sample_width) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    coda_cursor_goto_parent(&cursor);
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefNsfirst1b") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_int32(&cursor, &first_sample) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    coda_cursor_goto_parent(&cursor);
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefNslast1b") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_int32(&cursor, &last_sample) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (last_sample < first_sample)
    {
        harp_set_error(HARP_SUCCESS, "product error detected (IDefNslast1b < IDefNsfirst1b)");
        return -1;
    }
    if ((last_sample - first_sample + 1) > info->num_pixels)
    {
        harp_set_error(HARP_SUCCESS, "product error detected (IDefNslast1b - IDefNsfirst1b + 1 > 8700)");
        return -1;
    }
    for (sample = first_sample, i = 0; sample <= last_sample; sample++, i++)
    {
        *float_data = (float)(sample_width * sample);
        float_data++;
    }
    for (; i < info->num_pixels; i++)
    {
        float_data++;
    }
    return 0;
}

static void ingestion_done(void *user_data)
{
    ingest_info *info = (ingest_info *)user_data;

    if (info->scale_factors != NULL)
    {
        free(info->scale_factors);
    }
    if (info->channel_first != NULL)
    {
        free(info->channel_first);
    }
    if (info->channel_last != NULL)
    {
        free(info->channel_last);
    }

    free(info);
}

static int read_dimensions(void *user_data, long dimension[HARP_NUM_DIM_TYPES])
{
    dimension[harp_dimension_time] = ((ingest_info *)user_data)->num_main;
    dimension[harp_dimension_spectral] = ((ingest_info *)user_data)->num_pixels;
    return 0;
}

static int read_datetime(void *user_data, harp_array data)
{
    double *mdr_times, *double_data;
    double scantime;
    ingest_info *info = (ingest_info *)user_data;
    long i, j, k;
    int retval;

    CHECKED_MALLOC(mdr_times, sizeof(double) * info->valid_scanlines);
    retval = get_main_data(info, "RECORD_HEADER/RECORD_START_TIME", DATETIME, mdr_times);
    double_data = data.double_data;
    for (i = 0; i < info->valid_scanlines; i++)
    {
        for (j = 0; j < SCANS_PER_SCANLINE; j++)
        {
            /* A full scanline takes 8 seconds and consist of 37 scans */
            /* (30 scans with data and 7 for calibration etc.          */
            scantime = mdr_times[i] + (j * 8.0 / 37);
            for (k = 0; k < SPECTRA_PER_SCAN; k++)
            {
                *double_data = scantime;
                double_data++;
            }
        }
    }
    free(mdr_times);
    return retval;
}

static int read_orbit_index(void *user_data, harp_array data)
{
    ingest_info *info = (ingest_info *)user_data;
    coda_cursor cursor;

    if (coda_cursor_set_product(&cursor, info->product) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_goto(&cursor, "/MPHR/ORBIT_START") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_int32(&cursor, data.int32_data) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    return 0;
}

static int read_latitude(void *user_data, harp_array data)
{
    return get_main_data((ingest_info *)user_data, "GGeoSondLoc", LATITUDE, data.double_data);
}

static int read_longitude(void *user_data, harp_array data)
{
    return get_main_data((ingest_info *)user_data, "GGeoSondLoc", LONGITUDE, data.double_data);
}

static int read_spectral_radiance_sample(void *user_data, long index, harp_array data)
{
    return get_spectra_sample_data((ingest_info *)user_data, index, data.float_data);
}

static int read_wavenumber_sample(void *user_data, long index, harp_array data)
{
    return get_wavenumber_sample_data((ingest_info *)user_data, index, data.float_data);
}

static int read_scan_subindex(void *user_data, harp_array data)
{
    int8_t *int8_data;
    long i;
    int8_t j;

    int8_data = data.int8_data;
    for (i = 0; i < ((ingest_info *)user_data)->valid_scanlines; i++)
    {
        for (j = 0; j < SPECTRA_PER_SCANLINE; j++)
        {
            *int8_data = j;
            int8_data++;
        }
    }
    return 0;
}

static int init_dimensions(ingest_info *info)
{
    coda_cursor cursor, saved_cursor;
    int num_dims;
    long dim[HARP_MAX_NUM_DIMS], i;

    if (coda_cursor_set_product(&cursor, info->product) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    /* Count the number of valid scanlines per product */
    if (coda_cursor_goto_record_field_by_name(&cursor, "MDR") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_get_num_elements(&cursor, &info->mdr_records) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_goto_first_array_element(&cursor) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    info->valid_scanlines = 0;
    CHECKED_MALLOC(info->mdr_cursors, sizeof(coda_cursor) * info->mdr_records);
    for (i = 0; i < info->mdr_records; i++)
    {
        int is_mdr;

        saved_cursor = cursor;
        if (coda_cursor_goto_record_field_by_name(&cursor, "MDR") != 0)
        {
            harp_set_error(HARP_ERROR_CODA, NULL);
            return -1;
        }
        if ((coda_cursor_get_record_field_available_status(&cursor, 0, &is_mdr) == 0) && is_mdr)
        {
            info->mdr_cursors[info->valid_scanlines] = cursor;
            info->valid_scanlines++;
        }
        coda_cursor_goto_parent(&cursor);
        if (i < (info->mdr_records - 1))
        {
            cursor = saved_cursor;
            if (coda_cursor_goto_next_array_element(&cursor) != 0)
            {
                harp_set_error(HARP_ERROR_CODA, NULL);
                return -1;
            }
        }
    }
    if (info->valid_scanlines == 0)
    {
        harp_set_error(HARP_SUCCESS, "No MDR records with valid scanlines found");
        return -1;
    }
    info->num_main = info->valid_scanlines * SPECTRA_PER_SCANLINE;

    cursor = info->mdr_cursors[0];

    /* Count the number of pixels with spectra data per spectrum (this will usually be 8700) */
    if (coda_cursor_goto_record_field_by_name(&cursor, "GS1cSpect") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_get_array_dim(&cursor, &num_dims, dim) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    /* dim[0] = SCANS_PER_SCANLINE (fixed at 30) */
    /* dim[1] = SPECTRA_PER_SCAN (fixed at 4)    */
    /* dim[2] = pixels in one spectrum           */
    info->num_pixels = dim[2];

    coda_cursor_goto_root(&cursor);

    return 0;
}

static int read_GIADR_scalefactors(ingest_info *info)
{
    coda_cursor cursor;
    long max_scale_factors;

    if (coda_cursor_set_product(&cursor, info->product) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_goto_record_field_by_name(&cursor, "GIADR_ScaleFactors") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefScaleSondNbScale") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_read_int16(&cursor, &info->nr_scale_factors) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    coda_cursor_goto_parent(&cursor);
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefScaleSondScaleFactor") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_cursor_get_num_elements(&cursor, &max_scale_factors) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    CHECKED_MALLOC(info->scale_factors, max_scale_factors * sizeof(int16_t));
    if (coda_cursor_read_int16_array(&cursor, info->scale_factors, coda_array_ordering_c) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    coda_cursor_goto_parent(&cursor);
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefScaleSondNsfirst") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    CHECKED_MALLOC(info->channel_first, max_scale_factors * sizeof(int16_t));
    if (coda_cursor_read_int16_array(&cursor, info->channel_first, coda_array_ordering_c) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    coda_cursor_goto_parent(&cursor);
    if (coda_cursor_goto_record_field_by_name(&cursor, "IDefScaleSondNslast") != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    CHECKED_MALLOC(info->channel_last, max_scale_factors * sizeof(int16_t));
    if (coda_cursor_read_int16_array(&cursor, info->channel_last, coda_array_ordering_c) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    return 0;
}

static int ingestion_init(const harp_ingestion_module *module, coda_product *product,
                          const harp_ingestion_options *options, harp_product_definition **definition, void **user_data)
{
    int format_version;
    ingest_info *info;

    (void)options;

    if (coda_get_product_version(product, &format_version) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    CHECKED_MALLOC(info, sizeof(ingest_info));
    memset(info, '\0', sizeof(ingest_info));
    info->product = product;
    info->format_version = format_version;
    info->valid_scanlines = 0;

    if (init_dimensions(info) != 0)
    {
        ingestion_done(info);
        return -1;
    }
    if (read_GIADR_scalefactors(info) != 0)
    {
        ingestion_done(info);
        return -1;
    }

    *definition = *module->product_definition;
    *user_data = info;

    return 0;
}

int harp_ingestion_module_iasi_l1_init(void)
{
    harp_ingestion_module *module;
    harp_product_definition *product_definition;
    harp_variable_definition *variable_definition;
    harp_dimension_type dimension_type[2];
    const char *description;
    const char *path;

    description = "IASI Level 1";
    module =
        harp_ingestion_register_module_coda("IASI_L1", "IASI", "EPS", "IASI_xxx_1C", description, ingestion_init,
                                            ingestion_done);

    description = "IASI Level 1 product";
    product_definition = harp_ingestion_register_product(module, "IASI_L1", description, read_dimensions);
    description = "IASI Level 1 products contain a number of scanlines, each scanline contains 30 scans, each scan "
        "contains 4 spectra and each spectrum contains 8700 measurements";
    harp_product_definition_add_mapping(product_definition, description, NULL);

    dimension_type[0] = harp_dimension_time;
    dimension_type[1] = harp_dimension_spectral;

    /* datetime */
    description = "time of the measurement";
    variable_definition =
        harp_ingestion_register_variable_full_read(product_definition, "datetime", harp_type_double, 1, dimension_type,
                                                   NULL, description, "seconds since 2000-01-01", NULL, read_datetime);
    path = "/MDR[]/MDR/RECORD_HEADER/RECORD_START_TIME";
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, "");

    /* orbit_index */
    description = "absolute orbit number";
    variable_definition =
        harp_ingestion_register_variable_full_read(product_definition, "orbit_index", harp_type_int32, 0, NULL, NULL,
                                                   description, NULL, NULL, read_orbit_index);
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, "/MPHR/ORBIT_START", NULL);

    /* latitude */
    description = "center latitude of the measurement";
    variable_definition =
        harp_ingestion_register_variable_full_read(product_definition, "latitude", harp_type_double, 1, dimension_type,
                                                   NULL, description, "degree_north", NULL, read_latitude);
    harp_variable_definition_set_valid_range_double(variable_definition, -90.0, 90.0);
    path = "/MDR[]/MDR/GGeoSondLoc[,,1]";
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);

    /* longitude */
    description = "center longitude of the measurement";
    variable_definition =
        harp_ingestion_register_variable_full_read(product_definition, "longitude", harp_type_double, 1, dimension_type,
                                                   NULL, description, "degree_east", NULL, read_longitude);
    harp_variable_definition_set_valid_range_double(variable_definition, -180.0, 180.0);
    path = "/MDR[]/MDR/GGeoSondLoc[,,0]";
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, NULL);

    /* wavenumber_radiance */
    description = "measured radiances";
    variable_definition =
        harp_ingestion_register_variable_block_read(product_definition, "wavenumber_radiance", harp_type_float, 2,
                                                    dimension_type, NULL, description, "W/m^2.sr.m^-1", NULL,
                                                    read_spectral_radiance_sample);
    path = "/MDR[]/MDR/GS1cSpect[], /MDR[]/MDR/IDefNsfirst1b, /GIADR_ScaleFactors/IDefScaleSondNbScale, "
        "/GIADR_ScaleFactors/IDefScaleSondScaleFactor[], /GIADR_ScaleFactors/IdefScaleSondNsfirst[], "
        "/GIADR_ScaleFactors/IDefScaleSondNslast[]";
    description = "spectral data is scaled using the information in GIADR_ScaleFactors:"
        "``for numScale = 0 to (IDefScaleSondNbScale - 1) do`` ``{`` ``SF = IDefScaleSondScaleFactor[numScale];``"
        " ``for chanNb = IdefScaleSondNsfirst[numScale] to IDefScaleSondNslast[numScale] do`` ``{``"
        " ``w = chanNb - IDefNsfirst1b + 1;`` ``pixel_readout[w] = GS1cSpect[..,..,w] * 10^(-SF)`` ``}`` ``}``";
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);

    /* wavenumber */
    description = "nominal wavelength assignment for each of the detector pixels";
    variable_definition =
        harp_ingestion_register_variable_block_read(product_definition, "wavenumber", harp_type_float, 2,
                                                    dimension_type, NULL, description, "m^-1", NULL,
                                                    read_wavenumber_sample);
    path = "/MDR[]/MDR/IDefSpectDWn1b, /MDR[]/MDR/IDefNsfirst1b, /MDR[]/MDR/IDefNslast1b";
    description = "wavenumber[i] = IDefSpectDWn1b * (i + IDefNsfirst1b - 1). ";
    harp_variable_definition_add_mapping(variable_definition, NULL, NULL, path, description);

    /* scan_subindex */
    description = "relative index (0-119) of this measurement within an MDR";
    variable_definition =
        harp_ingestion_register_variable_full_read(product_definition, "scan_subindex", harp_type_int8, 1,
                                                   dimension_type, NULL, description, NULL, NULL, read_scan_subindex);

    return 0;
}