26 using namespace netCDF;
27 using namespace netCDF::exceptions;
31 0, 5, 87, 170, 358, 567, 720, 850, 997, 1120, 1275, 1600
36 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
37 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
38 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
39 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
40 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
41 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
42 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
43 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
44 {+8, +8, +8, 0, 0, 0, 0, 0, 0, 0, 0},
45 {+8, -1, -1, +7, 0, 0, 0, 0, 0, 0, 0},
46 {-2, +7, +7, -1, +6, 0, 0, 0, 0, 0, 0},
47 {+7, -2, -2, +6, -1, +5, 0, 0, 0, 0, 0},
48 {-3, +6, +6, -2, +5, -1, +4, 0, 0, 0, 0},
49 {+6, -3, -3, +5, -2, +4, -1, +3, 0, 0, 0},
50 {-4, +5, +5, -3, +4, -2, +3, -1, +2, 0, 0},
51 {+5, -4, -4, +4, -3, +3, -2, +2, -1, +1, 0},
56 {-5, +4, +4, -4, +3, -3, +2, -2, +1, -1, 0},
57 {+4, -5, -5, +3, -4, +2, -3, +1, -2, 0, 0},
58 {-6, +3, +3, -5, +2, -4, +1, -3, 0, 0, 0},
59 {+3, -6, -6, +2, -5, +1, -4, 0, 0, 0, 0},
60 {-7, +2, +2, -6, +1, -5, 0, 0, 0, 0, 0},
61 {+11, -7, -7, +1, -6, 0, 0, 0, 0, 0, 0},
62 {+1, +1, +1, -7, 0, 0, 0, 0, 0, 0, 0},
63 {-9, +9, -8, 0, 0, 0, 0, 0, 0, 0, 0},
64 {+9, -9, +8, 0, 0, 0, 0, 0, 0, 0, 0},
65 {-1, -1, -1, +7, 0, 0, 0, 0, 0, 0, 0},
66 {-11, +7, +7, -1, +6, 0, 0, 0, 0, 0, 0},
67 {+7, -2, -2, +6, -1, +5, 0, 0, 0, 0, 0},
68 {-3, +6, +6, -2, +5, -1, +4, 0, 0, 0, 0},
69 {+6, -3, -3, +5, -2, +4, -1, +3, 0, 0, 0},
70 {-4, +5, +5, -3, +4, -2, +3, -1, +2, 0, 0},
71 {+5, -4, -4, +4, -3, +3, -2, +2, -1, +1, 0},
76 {-5, +4, +4, -4, +3, -3, +2, -2, +1, -1, 0},
77 {+4, -5, -5, +3, -4, +2, -3, +1, -2, 0, 0},
78 {-6, +3, +3, -5, +2, -4, +1, -3, 0, 0, 0},
79 {+3, -6, -6, +2, -5, +1, -4, 0, 0, 0, 0},
80 {-7, +2, +2, -6, +1, -5, 0, 0, 0, 0, 0},
81 {+2, -7, -7, +1, -6, 0, 0, 0, 0, 0, 0},
82 {-8, +1, +1, -7, 0, 0, 0, 0, 0, 0, 0},
83 {-8, -8, -8, 0, 0, 0, 0, 0, 0, 0, 0},
84 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
85 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
89 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
90 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
91 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
133 if (filepath_l1b.empty() || filepath_geo.empty()) {
139 nc_io =
new NcFile(filepath_l1b, NcFile::read);
140 }
catch (NcException& e) {
142 cerr <<
"RsInput:: Failure opening VIIRS L1B input file: "
143 + filepath_l1b << endl;
146 NcDim line_dim = nc_io->getDim(
"number_of_lines");
147 NcDim pixel_dim = nc_io->getDim(
"number_of_pixels");
149 lines_ = line_dim.getSize();
150 pixels_ = pixel_dim.getSize();
153 status = generate_sort_index();
156 memset( sa, 0,
sizeof(
sio));
158 memset( ua, 0,
sizeof(
uio));
160 memset( usa, 0,
sizeof(
usio));
162 memset( fa, 0,
sizeof(
fio));
165 nc_io =
new NcFile(filepath_geo, NcFile::write);
166 }
catch (NcException& e) {
168 cerr <<
"RsViirs:: Failure opening VIIRS Geolocation input file: "
169 + filepath_geo << endl;
173 NcGroup nc_group = nc_io->getGroup(
"geolocation_data");
174 NcVar
nc_var = nc_group.getVar(
"quality_flag");
178 nc_var = nc_group.getVar(
"height");
182 nc_var = nc_group.getVar(
"range");
186 nc_var = nc_group.getVar(
"sensor_azimuth");
190 nc_var = nc_group.getVar(
"sensor_zenith");
194 nc_var = nc_group.getVar(
"solar_azimuth");
198 nc_var = nc_group.getVar(
"solar_zenith");
202 nc_var = nc_group.getVar(
"latitude");
206 nc_var = nc_group.getVar(
"longitude");
213 nc_io =
new NcFile(filepath_l1b, NcFile::write);
214 }
catch (NcException& e) {
216 cerr <<
"RsViirs:: Failure opening VIIRS L1B input file: "
217 + filepath_l1b << endl;
220 nc_group = nc_io->getGroup(
"observation_data");
221 for (
int ib = 0; ib <
NMBANDS; ib++) {
222 if (ib==12)
continue;
224 sprintf(
str,
"M%02d", ib + 1);
237 sprintf(
str,
"M%02d_quality_flags", ib + 1);
264 for (
int ix =
SBP[
i]; ix <
SBP[
i+1]; ix++) {
265 for (
int iy = 0; iy <
ND; iy++) {
269 for (
int iy =
ND; iy < lines_ -
ND; iy++) {
273 for (
int iy = lines_ -
ND; iy < lines_; iy++) {
291 for (
int iy = 0; iy < lines_; iy++) {
292 for (
int ix = 0; ix < pixels_; ix++) {
293 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
300 for (
int iy = 0; iy < lines_; iy++) {
301 for (
int ix = 0; ix < pixels_; ix++) {
302 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
309 for (
int iy = 0; iy < lines_; iy++) {
310 for (
int ix = 0; ix < pixels_; ix++) {
311 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
318 for (
int iy = 0; iy < lines_; iy++) {
319 for (
int ix = 0; ix < pixels_; ix++) {
320 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
336 for (
int iy = 1; iy < lines_ - 1; iy++) {
337 for (
int ix = 0; ix < pixels_; ix++) {
338 if (io->
out[iy][ix] >= filltest) {
339 if (io->
out[iy - 1][ix] < filltest &&
340 io->
out[iy + 1][ix] < filltest) {
341 io->
out[iy][ix] = io->
out[iy - 1][ix] / 2 +
342 io->
out[iy + 1][ix] / 2;
343 }
else if (io->
out[iy - 1][ix] < filltest) {
344 io->
out[iy][ix] = io->
out[iy - 1][ix];
345 }
else if (io->
out[iy + 1][ix] < filltest) {
346 io->
out[iy][ix] = io->
out[iy + 1][ix];
351 for (
int ix = 0; ix < pixels_; ix++) {
352 if (io->
out[0][ix] >= filltest) {
353 if (io->
out[1][ix] < filltest) {
354 io->
out[0][ix] = io->
out[1][ix];
358 for (
int ix = 0; ix < pixels_; ix++) {
359 if (io->
out[lines_-1][ix] >= filltest) {
360 if (io->
out[lines_-2][ix] < filltest) {
361 io->
out[lines_-1][ix] = io->
out[lines_-2][ix];
370 const unsigned int filltest = 327680;
372 for (
int iy = 1; iy < lines_ - 1; iy++) {
373 for (
int ix = 0; ix < pixels_; ix++) {
374 if (io->
out[iy][ix] >= filltest) {
375 if (io->
out[iy - 1][ix] < filltest &&
376 io->
out[iy + 1][ix] < filltest) {
377 io->
out[iy][ix] = io->
out[iy - 1][ix] / 2 +
378 io->
out[iy + 1][ix] / 2;
379 }
else if (io->
out[iy - 1][ix] < filltest) {
380 io->
out[iy][ix] = io->
out[iy - 1][ix];
381 }
else if (io->
out[iy + 1][ix] < filltest) {
382 io->
out[iy][ix] = io->
out[iy + 1][ix];
387 for (
int ix = 0; ix < pixels_; ix++) {
388 if (io->
out[0][ix] >= filltest) {
389 if (io->
out[1][ix] < filltest) {
390 io->
out[0][ix] = io->
out[1][ix];
394 for (
int ix = 0; ix < pixels_; ix++) {
395 if (io->
out[lines_-1][ix] >= filltest) {
396 if (io->
out[lines_-2][ix] < filltest) {
397 io->
out[lines_-1][ix] = io->
out[lines_-2][ix];
408 for (
int iy = 1; iy < lines_ - 1; iy++) {
409 for (
int ix = 0; ix < pixels_; ix++) {
410 if (io->
out[iy][ix] < filltest) {
411 if (io->
out[iy - 1][ix] > filltest &&
412 io->
out[iy + 1][ix] > filltest) {
413 io->
out[iy][ix] = io->
out[iy - 1][ix] / 2 +
414 io->
out[iy + 1][ix] / 2;
415 }
else if (io->
out[iy - 1][ix] > filltest) {
416 io->
out[iy][ix] = io->
out[iy - 1][ix];
417 }
else if (io->
out[iy + 1][ix] > filltest) {
418 io->
out[iy][ix] = io->
out[iy + 1][ix];
423 for (
int ix = 0; ix < pixels_; ix++) {
424 if (io->
out[0][ix] < filltest) {
425 if (io->
out[1][ix] > filltest) {
426 io->
out[0][ix] = io->
out[1][ix];
430 for (
int ix = 0; ix < pixels_; ix++) {
431 if (io->
out[lines_-1][ix] < filltest) {
432 if (io->
out[lines_-2][ix] > filltest) {
433 io->
out[lines_-1][ix] = io->
out[lines_-2][ix];