27 using namespace netCDF;
28 using namespace netCDF::exceptions;
32 0, 5, 87, 170, 358, 567, 720, 850, 997, 1120, 1275, 1600
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 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
45 {+8, +8, +8, 0, 0, 0, 0, 0, 0, 0, 0},
46 {+8, -1, -1, +7, 0, 0, 0, 0, 0, 0, 0},
47 {-2, +7, +7, -1, +6, 0, 0, 0, 0, 0, 0},
48 {+7, -2, -2, +6, -1, +5, 0, 0, 0, 0, 0},
49 {-3, +6, +6, -2, +5, -1, +4, 0, 0, 0, 0},
50 {+6, -3, -3, +5, -2, +4, -1, +3, 0, 0, 0},
51 {-4, +5, +5, -3, +4, -2, +3, -1, +2, 0, 0},
52 {+5, -4, -4, +4, -3, +3, -2, +2, -1, +1, 0},
57 {-5, +4, +4, -4, +3, -3, +2, -2, +1, -1, 0},
58 {+4, -5, -5, +3, -4, +2, -3, +1, -2, 0, 0},
59 {-6, +3, +3, -5, +2, -4, +1, -3, 0, 0, 0},
60 {+3, -6, -6, +2, -5, +1, -4, 0, 0, 0, 0},
61 {-7, +2, +2, -6, +1, -5, 0, 0, 0, 0, 0},
62 {+11, -7, -7, +1, -6, 0, 0, 0, 0, 0, 0},
63 {+1, +1, +1, -7, 0, 0, 0, 0, 0, 0, 0},
64 {-9, +9, -8, 0, 0, 0, 0, 0, 0, 0, 0},
65 {+9, -9, +8, 0, 0, 0, 0, 0, 0, 0, 0},
66 {-1, -1, -1, +7, 0, 0, 0, 0, 0, 0, 0},
67 {-11, +7, +7, -1, +6, 0, 0, 0, 0, 0, 0},
68 {+7, -2, -2, +6, -1, +5, 0, 0, 0, 0, 0},
69 {-3, +6, +6, -2, +5, -1, +4, 0, 0, 0, 0},
70 {+6, -3, -3, +5, -2, +4, -1, +3, 0, 0, 0},
71 {-4, +5, +5, -3, +4, -2, +3, -1, +2, 0, 0},
72 {+5, -4, -4, +4, -3, +3, -2, +2, -1, +1, 0},
77 {-5, +4, +4, -4, +3, -3, +2, -2, +1, -1, 0},
78 {+4, -5, -5, +3, -4, +2, -3, +1, -2, 0, 0},
79 {-6, +3, +3, -5, +2, -4, +1, -3, 0, 0, 0},
80 {+3, -6, -6, +2, -5, +1, -4, 0, 0, 0, 0},
81 {-7, +2, +2, -6, +1, -5, 0, 0, 0, 0, 0},
82 {+2, -7, -7, +1, -6, 0, 0, 0, 0, 0, 0},
83 {-8, +1, +1, -7, 0, 0, 0, 0, 0, 0, 0},
84 {-8, -8, -8, 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},
92 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
134 if (filepath_l1b.empty() || filepath_geo.empty()) {
140 nc_io =
new NcFile(filepath_l1b, NcFile::read);
141 }
catch (NcException& e) {
143 cerr <<
"RsInput:: Failure opening VIIRS L1B input file: "
144 + filepath_l1b << endl;
147 NcDim line_dim = nc_io->getDim(
"number_of_lines");
148 NcDim pixel_dim = nc_io->getDim(
"number_of_pixels");
150 lines_ = line_dim.getSize();
151 pixels_ = pixel_dim.getSize();
154 status = generate_sort_index();
157 memset( sa, 0,
sizeof(
sio));
159 memset( usa, 0,
sizeof(
usio));
161 memset( fa, 0,
sizeof(
fio));
164 nc_io =
new NcFile(filepath_geo, NcFile::write);
165 }
catch (NcException& e) {
167 cerr <<
"RsViirs:: Failure opening VIIRS Geolocation input file: "
168 + filepath_geo << endl;
172 NcGroup nc_group = nc_io->getGroup(
"geolocation_data");
173 NcVar
nc_var = nc_group.getVar(
"quality_flag");
177 nc_var = nc_group.getVar(
"height");
181 nc_var = nc_group.getVar(
"range");
185 nc_var = nc_group.getVar(
"sensor_azimuth");
189 nc_var = nc_group.getVar(
"sensor_zenith");
193 nc_var = nc_group.getVar(
"solar_azimuth");
197 nc_var = nc_group.getVar(
"solar_zenith");
201 nc_var = nc_group.getVar(
"latitude");
205 nc_var = nc_group.getVar(
"longitude");
212 nc_io =
new NcFile(filepath_l1b, NcFile::write);
213 }
catch (NcException& e) {
215 cerr <<
"RsViirs:: Failure opening VIIRS L1B input file: "
216 + filepath_l1b << endl;
219 nc_group = nc_io->getGroup(
"observation_data");
220 for (
int ib = 0; ib <
NMBANDS; ib++) {
222 sprintf(
str,
"M%02d", ib + 1);
228 sprintf(
str,
"M%02d_quality_flags", ib + 1);
254 for (
int ix =
SBP[
i]; ix <
SBP[
i+1]; ix++) {
255 for (
int iy = 0; iy <
ND; iy++) {
259 for (
int iy =
ND; iy < lines_ -
ND; iy++) {
263 for (
int iy = lines_ -
ND; iy < lines_; iy++) {
281 for (
int iy = 0; iy < lines_; iy++) {
282 for (
int ix = 0; ix < pixels_; ix++) {
283 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
290 for (
int iy = 0; iy < lines_; iy++) {
291 for (
int ix = 0; ix < pixels_; ix++) {
292 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
299 for (
int iy = 0; iy < lines_; iy++) {
300 for (
int ix = 0; ix < pixels_; ix++) {
301 io->
out[iy][ix] = io->
in[si_[iy][ix]][ix];
317 for (
int iy = 1; iy < lines_ - 1; iy++) {
318 for (
int ix = 0; ix < pixels_; ix++) {
319 if (io->
out[iy][ix] >= filltest) {
320 if (io->
out[iy - 1][ix] < filltest &&
321 io->
out[iy + 1][ix] < filltest) {
322 io->
out[iy][ix] = io->
out[iy - 1][ix] / 2 +
323 io->
out[iy + 1][ix] / 2;
324 }
else if (io->
out[iy - 1][ix] < filltest) {
325 io->
out[iy][ix] = io->
out[iy - 1][ix];
326 }
else if (io->
out[iy + 1][ix] < filltest) {
327 io->
out[iy][ix] = io->
out[iy + 1][ix];
332 for (
int ix = 0; ix < pixels_; ix++) {
333 if (io->
out[0][ix] >= filltest) {
334 if (io->
out[1][ix] < filltest) {
335 io->
out[0][ix] = io->
out[1][ix];
339 for (
int ix = 0; ix < pixels_; ix++) {
340 if (io->
out[lines_-1][ix] >= filltest) {
341 if (io->
out[lines_-2][ix] < filltest) {
342 io->
out[lines_-1][ix] = io->
out[lines_-2][ix];
353 for (
int iy = 1; iy < lines_ - 1; iy++) {
354 for (
int ix = 0; ix < pixels_; ix++) {
355 if (io->
out[iy][ix] < filltest) {
356 if (io->
out[iy - 1][ix] > filltest &&
357 io->
out[iy + 1][ix] > filltest) {
358 io->
out[iy][ix] = io->
out[iy - 1][ix] / 2 +
359 io->
out[iy + 1][ix] / 2;
360 }
else if (io->
out[iy - 1][ix] > filltest) {
361 io->
out[iy][ix] = io->
out[iy - 1][ix];
362 }
else if (io->
out[iy + 1][ix] > filltest) {
363 io->
out[iy][ix] = io->
out[iy + 1][ix];
368 for (
int ix = 0; ix < pixels_; ix++) {
369 if (io->
out[0][ix] < filltest) {
370 if (io->
out[1][ix] > filltest) {
371 io->
out[0][ix] = io->
out[1][ix];
375 for (
int ix = 0; ix < pixels_; ix++) {
376 if (io->
out[lines_-1][ix] < filltest) {
377 if (io->
out[lines_-2][ix] > filltest) {
378 io->
out[lines_-1][ix] = io->
out[lines_-2][ix];