Skip to content

Commit 793995e

Browse files
committed
Merge branch 'esa_baseline_4' into develop
2 parents 0d5674c + 0bf823b commit 793995e

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

src/cross-level/string-cl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,39 @@ void copy_string(char *dst, size_t size, const char *src){
5050
return;
5151
}
5252

53+
54+
int char_to_int(const char *src, int *val){
55+
long int temp_val;
56+
char *temp;
57+
errno = 0;
58+
59+
60+
temp_val = strtol(src, &temp, 0);
61+
62+
if (temp == src || *temp != '\0' || errno == ERANGE){
63+
return FAILURE;}
64+
65+
if (temp_val < INT_MIN ||
66+
temp_val > INT_MAX){
67+
return FAILURE;}
68+
69+
*val = (int)temp_val;
70+
return SUCCESS;
71+
}
72+
73+
74+
int char_to_float(const char *src, float *val){
75+
float temp_val;
76+
char *temp;
77+
errno = 0;
78+
79+
80+
temp_val = strtof(src, &temp);
81+
82+
if (temp == src || *temp != '\0' || errno == ERANGE){
83+
return FAILURE;}
84+
85+
*val = (float)temp_val;
86+
return SUCCESS;
87+
}
88+

src/cross-level/string-cl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ String handling header
3131
#include <stdio.h> // core input and output functions
3232
#include <stdlib.h> // standard general utilities library
3333
#include <string.h> // string handling functions
34+
#include <limits.h> // macro constants of the integer types
35+
#include <errno.h> // error numbers
3436

37+
#include "../cross-level/const-cl.h"
3538

3639
#ifdef __cplusplus
3740
extern "C" {
3841
#endif
3942

4043
void copy_string(char *dst, size_t size, const char *src);
44+
int char_to_int(const char *src, int *val);
45+
int char_to_float(const char *src, float *val);
4146

4247
#ifdef __cplusplus
4348
}

src/lower-level/meta-ll.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ GDALDatasetH fp_;
334334

335335

336336
meta->cal = allocate_calibration(nb);
337-
//alloc((void**)&meta->cal, nb, sizeof(cal_t));
338-
//for (b=0; b<nb; b++) init_calib(&meta->cal[b]);
339337

340338

341339
// set start of Relative Spectral Response Array
@@ -736,8 +734,6 @@ int svgrid = 5000;
736734
for (b=0; b<nb; b++) set_brick_sensor(DN, b, sensor);
737735

738736
meta->cal = allocate_calibration(nb);
739-
//alloc((void**)&meta->cal, nb, sizeof(cal_t));
740-
//for (b=0; b<nb; b++) init_calib(&meta->cal[b]);
741737

742738
// set start of Relative Spectral Response Array
743739
if (strcmp(sensor, "SEN2A") == 0){
@@ -883,6 +879,25 @@ int svgrid = 5000;
883879
tokenptr = strtok(NULL, separator);
884880
}
885881

882+
// additive scaling factor (since baseline 4.0)
883+
} else if (strcmp(tag, "RADIO_ADD_OFFSET") == 0){
884+
// re-init to 0 to be compatible with older baselines
885+
for (b=0; b<nb; b++){
886+
if (meta->cal[b].radd == meta->cal[b].fill) meta->cal[b].radd = 0;
887+
}
888+
b = -1;
889+
while (strcmp(tokenptr, "/RADIO_ADD_OFFSET") != 0){
890+
if (b < 0){
891+
char_to_int(tokenptr, &b);
892+
} else if (b >= 0 || b < nb){
893+
char_to_float(tokenptr, &meta->cal[b].radd);
894+
}
895+
tag = tokenptr;
896+
tokenptr = strtok(NULL, separator);
897+
}
898+
#ifdef FORCE_DEBUG
899+
if (b >= 0) printf("additive scaling factor for band %d: %f\n", b, meta->cal[b].radd);
900+
#endif
886901
}
887902

888903
// in case tag (key words) is not the first word in a line

src/lower-level/read-ll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ float dn_scale, toa_scale;
395395
dn_scale = get_brick_scale(DN, b);
396396
toa_scale = get_brick_scale(TOA, b);
397397

398-
#pragma omp parallel shared(b, nc, dn_scale, toa_scale, dn_, toa_) default(none)
398+
#pragma omp parallel shared(b, nc, dn_scale, toa_scale, dn_, toa_, meta) default(none)
399399
{
400400

401401
#pragma omp for schedule(static)
402-
for (p=0; p<nc; p++) toa_[b][p] = dn_[b][p]/dn_scale*toa_scale;
402+
for (p=0; p<nc; p++) toa_[b][p] = (dn_[b][p] + meta->cal[b].radd) / dn_scale*toa_scale;
403403

404404
}
405405

0 commit comments

Comments
 (0)