5 static int lutLoaded = 0;
8 static float scale_551;
9 static float offset_551;
10 static float scale_488;
11 static float offset_488;
12 static float scale_sst;
13 static float offset_sst;
16 static int32_t lut_num_rows = 0;
17 static float *lut_nlw_551;
18 static float *lut_nlw_488;
19 static float *lut_sst;
20 static int16_t *lut_class_ward;
21 static int16_t *lut_class_k;
22 static int16_t *lut_class_34k_w;
25 static int32_t current_iscan = -1;
26 static float *class_ward;
27 static float *class_k;
28 static float *class_34k_w;
30 static int ib551 = -1;
31 static int ib488 = -1;
34 char titleStr[256] =
"";
38 int32 dims[H4_MAX_VAR_DIMS];
56 l1str *
l1rec = l2rec->l1rec;
60 printf(
"Loading OWMC lut file %s.\n",
input->owmcfile);
63 sd_id = SDstart(
input->owmcfile, DFACC_RDONLY);
65 fprintf(
stderr,
"-E- %s line %d: Could not open OWMC lut file %s.\n",
66 __FILE__, __LINE__,
input->owmcfile);
74 if (strcmp(titleStr,
"OWMC LUT") != 0) {
75 fprintf(
stderr,
"-E- %s line %d: Global attribute \"Title\" from %s should be \"OWMC LUT\".\n",
76 __FILE__, __LINE__,
input->owmcfile);
90 fprintf(
stderr,
"-E- %s line %d: Could get dimensions for \"nlw_551\" from, %s.\n",
91 __FILE__, __LINE__,
input->owmcfile);
94 lut_num_rows = dims[0];
97 lut_nlw_551 = (
float*) malloc(lut_num_rows *
sizeof (
float));
99 lut_nlw_488 = (
float*) malloc(lut_num_rows *
sizeof (
float));
101 lut_sst = (
float*) malloc(lut_num_rows *
sizeof (
float));
104 lut_class_ward = (int16_t *) malloc(lut_num_rows *
sizeof (int16_t));
105 assert(lut_class_ward);
106 lut_class_k = (int16_t *) malloc(lut_num_rows *
sizeof (int16_t));
108 lut_class_34k_w = (int16_t *) malloc(lut_num_rows *
sizeof (int16_t));
109 assert(lut_class_34k_w);
112 class_ward = (
float *) malloc(
l1rec->npix * sizeof (
float));
114 class_k = (
float *) malloc(
l1rec->npix * sizeof (
float));
116 class_34k_w = (
float *) malloc(
l1rec->npix * sizeof (
float));
120 READ_SDS_E(
"nlw_551", lut_nlw_551, 0, 0, 0, lut_num_rows, 1, 1);
121 READ_SDS_E(
"nlw_488", lut_nlw_488, 0, 0, 0, lut_num_rows, 1, 1);
122 READ_SDS_E(
"sst", lut_sst, 0, 0, 0, lut_num_rows, 1, 1);
123 READ_SDS_E(
"class_ward", lut_class_ward, 0, 0, 0, lut_num_rows, 1, 1);
124 READ_SDS_E(
"class_k", lut_class_k, 0, 0, 0, lut_num_rows, 1, 1);
125 READ_SDS_E(
"class_34k_w", lut_class_34k_w, 0, 0, 0, lut_num_rows, 1, 1);
130 fprintf(
stderr,
"-E- %s line %d: Could not close OWMC lut file %s.\n",
131 __FILE__, __LINE__,
input->owmcfile);
140 printf(
"-E- %s line %d: can't find 551 band\n", __FILE__, __LINE__);
145 printf(
"-E- %s line %d: can't find 488 band\n", __FILE__, __LINE__);
154 if (
l1rec->iscan != current_iscan) {
155 current_iscan =
l1rec->iscan;
158 for (ip = 0; ip <
l1rec->npix; ip++) {
159 ipb = ip *
l1rec->l1file->nbands;
161 raw_551 = l2rec->nLw[ipb + ib551];
162 raw_488 = l2rec->nLw[ipb + ib488];
166 if (l2rec->sst && (l2rec->sst[ip] > -2.0))
167 raw_sst = l2rec->sst[ip];
169 raw_sst =
l1rec->sstref[ip];
171 cooked_551 = (raw_551 - offset_551) / scale_551;
172 cooked_488 = (raw_488 - offset_488) / scale_488;
173 cooked_sst = (raw_sst - offset_sst) / scale_sst;
175 best_delta = fabsf(cooked_551 - lut_nlw_551[0]) +
176 fabsf(cooked_488 - lut_nlw_488[0]) +
177 fabsf(cooked_sst - lut_sst[0]);
181 for (row = 1; row < lut_num_rows; row++) {
182 delta = fabsf(cooked_551 - lut_nlw_551[row]) +
183 fabsf(cooked_488 - lut_nlw_488[row]) +
184 fabsf(cooked_sst - lut_sst[row]);
185 if (
delta < best_delta) {
191 class_ward[ip] = lut_class_ward[best_lut_row];
192 class_k[ip] = lut_class_k[best_lut_row];
193 class_34k_w[ip] = lut_class_34k_w[best_lut_row];