31 static short *tmpShort;
32 static int normalizedLt = 0;
33 static int use_rhot = 1;
44 static size_t expected_num_blue_bands = 121;
45 static size_t expected_num_red_bands = 165;
46 static size_t expected_num_SWIR_bands = 9;
47 static size_t tot_num_bands = 295;
52 static size_t num_scans, num_pixels;
53 static size_t num_blue_bands, num_red_bands, num_SWIR_bands, nband_view, npol_band_view;
58 static double *scan_time;
59 static int32_t scan_time_year, scan_time_month, scan_time_day;
66 static int geolocationGrp, lambdaGrp, blueGrp;
67 static int lonId, latId, senzId, senaId, solzId, solaId, bwId, rwId, swId, iwId, pwId, IntId, IpolId, vpId;
68 static float latFillValue =
BAD_FLT;
69 static float lonFillValue =
BAD_FLT;
70 static short senzFillValue =
BAD_FLT;
71 static float senzScale = 0.01;
72 static float senzOffset = 0.0;
73 static short senaFillValue =
BAD_FLT;
74 static float senaScale = 0.01;
75 static float senaOffset = 0.0;
76 static short solzFillValue =
BAD_FLT;
77 static float solzScale = 0.01;
78 static float solzOffset = 0.0;
79 static short solaFillValue =
BAD_FLT;
80 static float solaScale = 0.01;
81 static float solaOffset = 0.0;
83 static float I_FillValue =
BAD_FLT;
84 static float Ipol_FillValue =
BAD_FLT;
87 static int observationGrp;
88 static int Lt_blueId, Lt_redId, Lt_SWIRId;
95 static float Lt_blueFillValue =
BAD_FLT;
96 static float Lt_redFillValue =
BAD_FLT;
97 static float Lt_SWIRFillValue =
BAD_FLT;
114 :
att_ang{-999.0, -999.0, -999.0}, orb_pos{-999.0, -999.0, -999.0}, orb_vel{-999.0, -999.0, -999.0} {
121 ev_mid_time =
nullptr;
122 scan_quality_flag =
nullptr;
135 blue_lambdas =
nullptr;
136 red_lambdas =
nullptr;
137 SWIR_lambdas =
nullptr;
140 I_polsample =
nullptr;
142 pol_lambdas =
nullptr;
163 senazpix_3d =
nullptr;
166 latpix2_3d =
nullptr;
167 lonpix2_3d =
nullptr;
171 lonershift =
nullptr;
172 terr_height =
nullptr;
173 cloud_height =
nullptr;
189 printf(
"Opening MISR L1B file\n");
190 cout << ptstr << endl;
193 printf(
"-E- %s: Error opening for reading.\n",
l1file->name);
206 printf(
"Opening SPEXone L1B file\n");
209 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
211 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
217 status = nc_inq_dimid(ncid_L1B,
"number_of_views", &dimid);
219 fprintf(
stderr,
"-E- Error reading number_of_views.\n");
222 nc_inq_dimlen(ncid_L1B, dimid, &
nviews);
226 status = nc_inq_dimid(ncid_L1B,
"bins_along_track", &dimid);
228 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
231 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
232 l1cstr->
nscan = num_scans;
235 status = nc_inq_dimid(ncid_L1B,
"spatial_samples_per_image", &dimid);
237 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
240 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
241 l1cstr->
npix = num_pixels;
244 status = nc_inq_dimid(ncid_L1B,
"intensity_bands_per_view", &dimid);
246 fprintf(
stderr,
"-E- Error reading intensity_bands_per_view.\n");
249 nc_inq_dimlen(ncid_L1B, dimid, &nband_view);
251 status = nc_inq_dimid(ncid_L1B,
"polarization_bands_per_view", &dimid);
253 fprintf(
stderr,
"-E- Error reading polarization_bands_per_view.\n");
256 nc_inq_dimlen(ncid_L1B, dimid, &npol_band_view);
259 printf(
"L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
262 l1cstr->
senazpix = (
float *)calloc(num_pixels,
sizeof(
float));
263 l1cstr->
latpix = (
float *)calloc(num_pixels,
sizeof(
float));
264 l1cstr->
lonpix = (
float *)calloc(num_pixels,
sizeof(
float));
265 l1cstr->
latpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
266 l1cstr->
lonpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
272 l1cstr->
viewport = (uint8_t *)calloc(num_pixels,
sizeof(uint8_t));
276 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
279 char *
time_str = (
char *)malloc(att_len + 1);
281 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
289 scan_time_year =
syear;
290 scan_time_month = smon;
291 scan_time_day =
sday;
295 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
299 status = nc_inq_grp_ncid(ncid_L1B,
"SENSOR_VIEW_BANDS", &lambdaGrp);
301 status = nc_inq_varid(lambdaGrp,
"intensity_wavelengths", &iwId);
303 status = nc_inq_varid(lambdaGrp,
"polarization_wavelengths", &pwId);
305 status = nc_inq_varid(lambdaGrp,
"viewport_index", &vpId);
316 status = nc_inq_grp_ncid(ncid_L1B,
"GEOLOCATION_DATA", &geolocationGrp);
318 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
321 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
323 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
325 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
328 status = nc_inq_varid(geolocationGrp,
"sensor_zenith", &senzId);
330 status = nc_inq_var_fill(geolocationGrp, senzId,
NULL, &senzFillValue);
337 status = nc_inq_varid(geolocationGrp,
"sensor_azimuth", &senaId);
339 status = nc_inq_var_fill(geolocationGrp, senaId,
NULL, &senaFillValue);
346 status = nc_inq_varid(geolocationGrp,
"solar_zenith", &solzId);
348 status = nc_inq_var_fill(geolocationGrp, solzId,
NULL, &solzFillValue);
350 status = nc_get_att_float(geolocationGrp, solzId,
"scale_factor", &solzScale);
355 status = nc_inq_varid(geolocationGrp,
"solar_azimuth", &solaId);
357 status = nc_inq_var_fill(geolocationGrp, solaId,
NULL, &solaFillValue);
359 status = nc_get_att_float(geolocationGrp, solaId,
"scale_factor", &solaScale);
365 status = nc_inq_grp_ncid(ncid_L1B,
"OBSERVATION_DATA", &observationGrp);
369 status = nc_inq_varid(observationGrp,
"I", &IntId);
371 status = nc_inq_var_fill(observationGrp, IntId,
NULL, &I_FillValue);
374 status = nc_inq_varid(observationGrp,
"I_polsample", &IpolId);
376 status = nc_inq_var_fill(observationGrp, IpolId,
NULL, &Ipol_FillValue);
385 cout <<
"nband_view =" << nband_view << endl;
386 cout <<
"npol_band_view = " << npol_band_view << endl;
394 cout <<
"n_views..." <<
l1cfile->
n_views <<
"intensity bands.per view..." << nband_view
395 <<
"polarization bands.per view." << npol_band_view << endl;
407 printf(
"Opening OCI L1B file\n");
410 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
412 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
418 status = nc_inq_dimid(ncid_L1B,
"number_of_scans", &dimid);
420 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
423 cout <<
"reading OCI" << endl;
424 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
425 l1cstr->
nscan = num_scans;
428 status = nc_inq_dimid(ncid_L1B,
"ccd_pixels", &dimid);
430 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
433 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
434 l1cstr->
npix = num_pixels;
437 status = nc_inq_dimid(ncid_L1B,
"blue_bands", &dimid);
439 fprintf(
stderr,
"-E- Error reading num_blue_bands.\n");
442 nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
443 if (num_blue_bands < expected_num_blue_bands) {
444 fprintf(
stderr,
"-E- blue bands in file are less than expected!, expecting %d, found %d.\n",
445 (
int)expected_num_blue_bands, (
int)num_blue_bands);
450 status = nc_inq_dimid(ncid_L1B,
"red_bands", &dimid);
452 fprintf(
stderr,
"-E- Error reading num_red_bands.\n");
455 nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
456 if (num_red_bands < expected_num_red_bands) {
457 fprintf(
stderr,
"-E- red bands in file are less than expected!, expecting %d, found %d.\n",
458 (
int)expected_num_red_bands, (
int)num_red_bands);
463 status = nc_inq_dimid(ncid_L1B,
"SWIR_bands", &dimid);
465 fprintf(
stderr,
"-E- Error reading num_SWIR_bands.\n");
468 nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
469 if (num_SWIR_bands < expected_num_SWIR_bands) {
470 fprintf(
stderr,
"-E- SWIR bands in file are less than expected!, expecting %d, found %d.\n",
471 (
int)expected_num_SWIR_bands, (
int)num_SWIR_bands);
476 printf(
"L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
480 tmpShort = (
short *)calloc(num_pixels,
sizeof(
short));
481 l1cstr->
timepix = (
double *)calloc(num_scans,
sizeof(
double));
482 l1cstr->
tilt = (
float *)calloc(num_scans,
sizeof(
float));
483 l1cstr->
latpix = (
float *)calloc(num_pixels,
sizeof(
float));
484 l1cstr->
lonpix = (
float *)calloc(num_pixels,
sizeof(
float));
485 l1cstr->
latpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
486 l1cstr->
lonpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
487 l1cstr->
latpix3 = (
float *)calloc(num_pixels,
sizeof(
float));
488 l1cstr->
lonpix3 = (
float *)calloc(num_pixels,
sizeof(
float));
493 l1cstr->
Lt_tot = (
float *)calloc(num_pixels * tot_num_bands,
sizeof(
float));
495 l1cstr->
Fobar = (
float *)calloc(tot_num_bands,
sizeof(
float));
496 l1cstr->
solz = (
float *)calloc(num_pixels,
sizeof(
float));
497 l1cstr->
senz = (
float *)calloc(num_pixels,
sizeof(
float));
499 l1cstr->
blue_lambdas = (
float *)calloc(num_blue_bands,
sizeof(
float));
500 l1cstr->
red_lambdas = (
float *)calloc(num_red_bands,
sizeof(
float));
501 l1cstr->
SWIR_lambdas = (
float *)calloc(num_SWIR_bands,
sizeof(
float));
503 scan_time = (
double *)malloc(num_scans *
sizeof(
double));
509 if ((nc_inq_grp_ncid(ncid_L1B,
"navigation_data", &groupid)) == NC_NOERR) {
511 fprintf(
stderr,
"-E- Error finding navigation_data.\n");
514 status = nc_inq_varid(groupid,
"tilt", &varid);
517 status = nc_inq_var_fill(groupid, varid,
NULL, &tiltFillValue);
519 status = nc_get_var_float(groupid, varid, l1cstr->
tilt);
523 if ((nc_inq_grp_ncid(ncid_L1B,
"scan_line_attributes", &groupid)) == NC_NOERR) {
525 fprintf(
stderr,
"-E- Error finding scan_line_attributes.\n");
529 double scan_timeFillValue =
BAD_FLT;
530 status = nc_inq_varid(groupid,
"time", &varid);
532 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
544 status = nc_inq_varid(groupid,
"ev_mid_time", &varid);
546 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
548 status = nc_get_var_double(groupid, varid, scan_time);
553 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
557 char *
time_str = (
char *)malloc(att_len + 1);
560 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
568 scan_time_year =
syear;
569 scan_time_month = smon;
570 scan_time_day =
sday;
573 for (
size_t i = 0;
i < num_scans;
i++) {
574 if (scan_time[
i] == scan_timeFillValue)
584 status = nc_inq_grp_ncid(ncid_L1B,
"sensor_band_parameters", &lambdaGrp);
586 status = nc_inq_varid(lambdaGrp,
"blue_wavelength", &bwId);
588 status = nc_inq_varid(lambdaGrp,
"red_wavelength", &rwId);
590 status = nc_inq_varid(lambdaGrp,
"SWIR_wavelength", &swId);
600 status = nc_inq_grp_ncid(ncid_L1B,
"geolocation_data", &geolocationGrp);
602 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
605 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
607 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
609 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
612 status = nc_inq_varid(geolocationGrp,
"sensor_zenith", &senzId);
614 status = nc_inq_var_fill(geolocationGrp, senzId,
NULL, &senzFillValue);
621 status = nc_inq_varid(geolocationGrp,
"sensor_azimuth", &senaId);
623 status = nc_inq_var_fill(geolocationGrp, senaId,
NULL, &senaFillValue);
630 status = nc_inq_varid(geolocationGrp,
"solar_zenith", &solzId);
632 status = nc_inq_var_fill(geolocationGrp, solzId,
NULL, &solzFillValue);
639 status = nc_inq_varid(geolocationGrp,
"solar_azimuth", &solaId);
641 status = nc_inq_var_fill(geolocationGrp, solaId,
NULL, &solaFillValue);
650 status = nc_inq_grp_ncid(ncid_L1B,
"observation_data", &observationGrp);
653 status = nc_inq_varid(observationGrp,
"Lt_blue", &Lt_blueId);
658 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
661 status = nc_inq_varid(observationGrp,
"Lt_red", &Lt_redId);
663 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
666 status = nc_inq_varid(observationGrp,
"Lt_SWIR", &Lt_SWIRId);
668 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
671 status = nc_inq_varid(observationGrp,
"rhot_blue", &Lt_blueId);
673 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
675 status = nc_inq_varid(observationGrp,
"rhot_red", &Lt_redId);
677 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
680 status = nc_inq_varid(observationGrp,
"rhot_SWIR", &Lt_SWIRId);
682 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
687 l1cstr->
nbands = tot_num_bands;
693 l1cfile->
nbands = num_blue_bands + num_red_bands + num_SWIR_bands;
729 printf(
"Opening OCIS L1B file\n");
732 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
734 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
740 status = nc_inq_dimid(ncid_L1B,
"number_of_scans", &dimid);
742 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
745 cout <<
"reading OCIS" << endl;
746 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
747 l1cstr->
nscan = num_scans;
750 status = nc_inq_dimid(ncid_L1B,
"ccd_pixels", &dimid);
752 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
755 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
756 l1cstr->
npix = num_pixels;
759 status = nc_inq_dimid(ncid_L1B,
"blue_bands", &dimid);
761 fprintf(
stderr,
"-E- Error reading num_blue_bands.\n");
764 nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
765 if (num_blue_bands < expected_num_blue_bands) {
766 fprintf(
stderr,
"-E- blue bands in file is less than expected!, expecting %d, found %d.\n",
767 (
int)expected_num_blue_bands, (
int)num_blue_bands);
772 status = nc_inq_dimid(ncid_L1B,
"red_bands", &dimid);
774 fprintf(
stderr,
"-E- Error reading num_red_bands.\n");
777 nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
778 if (num_red_bands < expected_num_red_bands) {
779 fprintf(
stderr,
"-E- red bands in file is less than expected!, expecting %d, found %d.\n",
780 (
int)expected_num_red_bands, (
int)num_red_bands);
785 status = nc_inq_dimid(ncid_L1B,
"SWIR_bands", &dimid);
787 fprintf(
stderr,
"-E- Error reading num_SWIR_bands.\n");
790 nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
791 if (num_SWIR_bands < expected_num_SWIR_bands) {
792 fprintf(
stderr,
"-E- SWIR bands in file is less than expected!, expecting %d, found %d.\n",
793 (
int)expected_num_SWIR_bands, (
int)num_SWIR_bands);
798 printf(
"L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
802 tmpShort = (
short *)calloc(num_pixels,
sizeof(
short));
803 l1cstr->
timepix = (
double *)calloc(num_scans,
sizeof(
double));
804 l1cstr->
tilt = (
float *)calloc(num_scans,
sizeof(
float));
805 l1cstr->
latpix = (
float *)calloc(num_pixels,
sizeof(
float));
806 l1cstr->
lonpix = (
float *)calloc(num_pixels,
sizeof(
float));
807 l1cstr->
latpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
808 l1cstr->
lonpix2 = (
float *)calloc(num_pixels,
sizeof(
float));
809 l1cstr->
latpix3 = (
float *)calloc(num_pixels,
sizeof(
float));
810 l1cstr->
lonpix3 = (
float *)calloc(num_pixels,
sizeof(
float));
815 l1cstr->
Lt_tot = (
float *)calloc(num_pixels * tot_num_bands,
sizeof(
float));
817 l1cstr->
Fobar = (
float *)calloc(tot_num_bands,
sizeof(
float));
818 l1cstr->
solz = (
float *)calloc(num_pixels,
sizeof(
float));
819 l1cstr->
senz = (
float *)calloc(num_pixels,
sizeof(
float));
821 l1cstr->
blue_lambdas = (
float *)calloc(num_blue_bands,
sizeof(
float));
822 l1cstr->
red_lambdas = (
float *)calloc(num_red_bands,
sizeof(
float));
823 l1cstr->
SWIR_lambdas = (
float *)calloc(num_SWIR_bands,
sizeof(
float));
825 scan_time = (
double *)malloc(num_scans *
sizeof(
double));
831 if ((nc_inq_grp_ncid(ncid_L1B,
"navigation_data", &groupid)) == NC_NOERR) {
833 fprintf(
stderr,
"-E- Error finding navigation_data.\n");
836 status = nc_inq_varid(groupid,
"tilt_angle", &varid);
839 status = nc_inq_var_fill(groupid, varid,
NULL, &tiltFillValue);
841 status = nc_get_var_float(groupid, varid, l1cstr->
tilt);
845 if ((nc_inq_grp_ncid(ncid_L1B,
"scan_line_attributes", &groupid)) == NC_NOERR) {
847 fprintf(
stderr,
"-E- Error finding scan_line_attributes.\n");
851 double scan_timeFillValue =
BAD_FLT;
852 status = nc_inq_varid(groupid,
"time", &varid);
854 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
858 status = nc_get_att_int(groupid, varid,
"year", &scan_time_year);
860 status = nc_get_att_int(groupid, varid,
"month", &scan_time_month);
862 status = nc_get_att_int(groupid, varid,
"day", &scan_time_day);
866 status = nc_inq_varid(groupid,
"ev_mid_time", &varid);
868 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
870 status = nc_get_var_double(groupid, varid, scan_time);
875 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
879 char *
time_str = (
char *)malloc(att_len + 1);
882 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
890 scan_time_year =
syear;
891 scan_time_month = smon;
892 scan_time_day =
sday;
895 for (
size_t i = 0;
i < num_scans;
i++) {
896 if (scan_time[
i] == scan_timeFillValue)
902 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
906 status = nc_inq_grp_ncid(ncid_L1B,
"sensor_band_parameters", &lambdaGrp);
908 status = nc_inq_varid(lambdaGrp,
"blue_wavelength", &bwId);
910 status = nc_inq_varid(lambdaGrp,
"red_wavelength", &rwId);
912 status = nc_inq_varid(lambdaGrp,
"SWIR_wavelength", &swId);
922 status = nc_inq_grp_ncid(ncid_L1B,
"geolocation_data", &geolocationGrp);
924 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
927 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
929 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
931 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
934 status = nc_inq_varid(geolocationGrp,
"sensor_zenith", &senzId);
936 status = nc_inq_var_fill(geolocationGrp, senzId,
NULL, &senzFillValue);
938 status = nc_get_att_float(geolocationGrp, senzId,
"scale_factor", &senzScale);
940 status = nc_get_att_float(geolocationGrp, senzId,
"add_offset", &senzOffset);
943 status = nc_inq_varid(geolocationGrp,
"sensor_azimuth", &senaId);
945 status = nc_inq_var_fill(geolocationGrp, senaId,
NULL, &senaFillValue);
947 status = nc_get_att_float(geolocationGrp, senaId,
"scale_factor", &senaScale);
949 status = nc_get_att_float(geolocationGrp, senaId,
"add_offset", &senaOffset);
952 status = nc_inq_varid(geolocationGrp,
"solar_zenith", &solzId);
954 status = nc_inq_var_fill(geolocationGrp, solzId,
NULL, &solzFillValue);
956 status = nc_get_att_float(geolocationGrp, solzId,
"scale_factor", &solzScale);
958 status = nc_get_att_float(geolocationGrp, solzId,
"add_offset", &solzOffset);
961 status = nc_inq_varid(geolocationGrp,
"solar_azimuth", &solaId);
963 status = nc_inq_var_fill(geolocationGrp, solaId,
NULL, &solaFillValue);
965 status = nc_get_att_float(geolocationGrp, solaId,
"scale_factor", &solaScale);
967 status = nc_get_att_float(geolocationGrp, solaId,
"add_offset", &solaOffset);
971 status = nc_inq_grp_ncid(ncid_L1B,
"observation_data", &observationGrp);
974 status = nc_inq_varid(observationGrp,
"Lt_blue", &Lt_blueId);
979 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
982 status = nc_inq_varid(observationGrp,
"Lt_red", &Lt_redId);
984 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
987 status = nc_inq_varid(observationGrp,
"Lt_SWIR", &Lt_SWIRId);
989 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
992 status = nc_inq_varid(observationGrp,
"rhot_blue", &Lt_blueId);
994 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
996 status = nc_inq_varid(observationGrp,
"rhot_red", &Lt_redId);
998 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
1001 status = nc_inq_varid(observationGrp,
"rhot_SWIR", &Lt_SWIRId);
1003 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
1008 l1cstr->
nbands = tot_num_bands;
1014 l1cfile->
nbands = num_blue_bands + num_red_bands + num_SWIR_bands;
1048 ptstr =
str.c_str();
1049 printf(
"Opening HARP2 L1B file\n");
1050 cout <<
str << endl;
1052 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
1053 if (
status != NC_NOERR) {
1054 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n", __FILE__, __LINE__, ptstr);
1060 status = nc_inq_grp_ncid(ncid_L1B,
"blue", &blueGrp);
1061 if (
status != NC_NOERR) {
1062 fprintf(
stderr,
"-E- Error reading group blue.\n");
1067 status = nc_inq_dimid(blueGrp,
"Views", &dimid);
1068 if (
status != NC_NOERR) {
1069 fprintf(
stderr,
"-E- Error reading number_of_views.\n");
1072 nc_inq_dimlen(ncid_L1B, dimid, &
nviews);
1076 status = nc_inq_dimid(ncid_L1B,
"Swath_Lines", &dimid);
1077 if (
status != NC_NOERR) {
1078 fprintf(
stderr,
"-E- Error reading number_of_lines.\n");
1081 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
1082 l1cstr->
nscan = num_scans;
1085 status = nc_inq_dimid(ncid_L1B,
"Swath_Pixels", &dimid);
1086 if (
status != NC_NOERR) {
1087 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
1090 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
1091 l1cstr->
npix = num_pixels;
1115 printf(
"L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
1147 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
1151 char *
time_str = (
char *)malloc(att_len + 1);
1154 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
1162 scan_time_year =
syear;
1163 scan_time_month = smon;
1164 scan_time_day =
sday;
1175 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
1197 status = nc_inq_varid(blueGrp,
"Longitude", &lonId);
1200 status = nc_inq_var_fill(blueGrp, lonId,
NULL, &lonFillValue);
1202 status = nc_inq_varid(blueGrp,
"Latitude", &latId);
1204 status = nc_inq_var_fill(blueGrp, latId,
NULL, &latFillValue);
1207 status = nc_inq_varid(blueGrp,
"View_Zenith", &senzId);
1209 status = nc_inq_var_fill(blueGrp, senzId,
NULL, &senzFillValue);
1216 status = nc_inq_varid(blueGrp,
"View_Azimuth", &senaId);
1218 status = nc_inq_var_fill(blueGrp, senaId,
NULL, &senaFillValue);
1225 status = nc_inq_varid(blueGrp,
"Solar_Zenith", &solzId);
1227 status = nc_inq_var_fill(blueGrp, solzId,
NULL, &solzFillValue);
1229 status = nc_get_att_float(blueGrp, solzId,
"scale_factor", &solzScale);
1234 status = nc_inq_varid(blueGrp,
"Solar_Azimuth", &solaId);
1236 status = nc_inq_var_fill(blueGrp, solaId,
NULL, &solaFillValue);
1238 status = nc_get_att_float(blueGrp, solaId,
"scale_factor", &solaScale);
1245 status = nc_inq_varid(blueGrp,
"I", &IntId);
1247 status = nc_inq_var_fill(blueGrp, IntId,
NULL, &I_FillValue);
1262 cout <<
"nband_view =" << nband_view << endl;
1263 cout <<
"npol_band_view = " << npol_band_view << endl;
1271 cout <<
"n_views..." <<
l1cfile->
n_views <<
"intensity bands.per view..." << nband_view
1272 <<
"polarization bands.per view." << npol_band_view << endl;
1280 size_t start[] = {0, 0}, start2[] = {0, 0}, start3[] = {0, 0, 0};
1281 size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1286 printf(
"Reading SPEXone L1B file\n");
1287 cout <<
str << endl;
1292 l1cstr->
iscan = sline;
1297 count[1] = num_pixels;
1299 status = nc_get_vara_float(
1309 if (oneline < num_scans - 1)
1310 start2[0] = sline + 1;
1326 count2[1] = num_pixels;
1327 count2[2] = nband_view;
1329 status = nc_get_vara_float(observationGrp, IntId, start3, count2,
1333 count2[2] = npol_band_view;
1334 status = nc_get_vara_float(observationGrp, IpolId, start3, count2, l1cstr->
I_polsample[0]);
1341 float **areafrac,
short **obs_view,
int band_ix,
int view_ix) {
1343 short minval, maxval;
1344 float minval2, maxval2;
1346 netCDF::NcDim yd = nc_output->getDim(
"bins_along_track");
1347 int ybins = yd.getSize();
1348 netCDF::NcDim xd = nc_output->getDim(
"bins_across_track");
1349 int xbins = xd.getSize();
1351 cout <<
"saving full L1C granule -- aw binning.."
1352 <<
"ybins.." << ybins <<
"xbins.." << xbins <<
"band #: " << band_ix + 1
1353 <<
"view #: " << view_ix + 1 << endl;
1355 std::vector<size_t> start3;
1356 start3.push_back(0);
1357 start3.push_back(0);
1358 start3.push_back(view_ix);
1360 std::vector<size_t> count3;
1361 count3.push_back(ybins);
1362 count3.push_back(xbins);
1363 count3.push_back(1);
1367 netCDF::NcGroup od_grp = nc_output->getGroup(
"observation_data");
1368 netCDF::NcVar v1 = od_grp.getVar(
"obs_per_view");
1369 netCDF::NcVarAtt a1 = v1.getAtt(
"valid_min");
1370 a1.getValues(&minval);
1371 a1 = v1.getAtt(
"valid_max");
1372 a1.getValues(&maxval);
1374 for (
int i = 0;
i < ybins;
i++) {
1375 for (
int j = 0;
j < xbins;
j++) {
1376 if (obs_view[
i][
j] > maxval || obs_view[
i][
j] < minval) {
1379 obs_clean[
i][
j] = obs_view[
i][
j];
1382 v1.putVar(start3, count3, &obs_clean[0][0]);
1385 v1 = od_grp.getVar(
"I");
1386 a1 = v1.getAtt(
"valid_min");
1387 a1.getValues(&minval2);
1388 a1 = v1.getAtt(
"valid_max");
1389 a1.getValues(&maxval2);
1391 std::vector<size_t> start4;
1392 start4.push_back(0);
1393 start4.push_back(0);
1394 start4.push_back(view_ix);
1395 start4.push_back(band_ix);
1397 std::vector<size_t> count4;
1398 count4.push_back(ybins);
1399 count4.push_back(xbins);
1400 count4.push_back(1);
1401 count4.push_back(1);
1405 for (
int i = 0;
i < ybins;
i++) {
1406 for (
int j = 0;
j < xbins;
j++) {
1407 if (areafrac[
i][
j] > 0) {
1408 Lt[
i][
j] = Ltfrac[
i][
j] / sqrt(areafrac[
i][
j]);
1411 if (
Lt[
i][
j] < minval2 ||
Lt[
i][
j] > maxval2)
1419 v1.putVar(start4, count4, &
Lt[0][0]);
1428 size_t start[] = {0, 0}, start2[] = {0, 0}, start4[] = {0, 0, 0};
1429 size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1434 printf(
"Reading OCIS L1B file\n");
1435 cout <<
str << endl;
1440 l1cstr->
iscan = sline;
1445 count[1] = num_pixels;
1456 if (oneline < num_scans - 1)
1457 start2[0] = sline + 1;
1472 count2[0] = num_blue_bands;
1474 count2[2] = num_pixels;
1476 status = nc_get_vara_float(observationGrp, Lt_blueId, start4, count2,
1480 count2[0] = num_red_bands;
1481 status = nc_get_vara_float(observationGrp, Lt_redId, start4, count2, l1cstr->
Lt_red[0]);
1484 count2[0] = num_SWIR_bands;
1485 status = nc_get_vara_float(observationGrp, Lt_SWIRId, start4, count2, l1cstr->
Lt_SWIR[0]);
1488 double scantime =
ymds2unix((int16_t)scan_time_year, (int16_t)scan_time_month, (int16_t)scan_time_day,
1496 int32_t
msec = (int32_t)(secs * 1000.0);
1499 float fsol = pow(1.0 /
esdist, 2);
1501 for (
size_t ip = 0; ip < num_pixels; ip++) {
1504 int ipb = ip * tot_num_bands;
1507 if(num_blue_bands<expected_num_blue_bands){
1508 expected_num_blue_bands=num_blue_bands;
1511 expected_num_blue_bands=expected_num_blue_bands-2;
1514 for (
band = 0;
band < expected_num_blue_bands;
band++) {
1516 l1cstr->
Lt_tot[ipb] = 0.001;
1520 l1cstr->
Lt_tot[ipb] *= 100;
1521 }
else if (use_rhot) {
1526 l1cstr->
Lt_tot[ipb] /= 10.;
1534 if(num_red_bands<expected_num_red_bands){
1535 expected_num_red_bands=num_red_bands;
1538 expected_num_red_bands=expected_num_red_bands-4;
1541 for (
band = 2;
band < expected_num_red_bands;
band++) {
1543 l1cstr->
Lt_tot[ipb] = 0.001;
1547 l1cstr->
Lt_tot[ipb] *= 100;
1548 }
else if (use_rhot) {
1551 l1cstr->
Lt_tot[ipb] /= 10.;
1559 if(num_SWIR_bands<expected_num_SWIR_bands){
1560 expected_num_SWIR_bands=num_SWIR_bands;
1563 for (
band = 0;
band < expected_num_SWIR_bands;
band++) {
1567 l1cstr->
Lt_tot[ipb] = 0.001;
1571 l1cstr->
Lt_tot[ipb] *= 100;
1572 }
else if (use_rhot) {
1575 l1cstr->
Lt_tot[ipb] /= 10.;
1588 size_t start[] = {0, 0}, start2[] = {0, 0}, start3[] = {0, 0}, start4[] = {0, 0, 0};
1589 size_t count[] = {1, 1}, count2[] = {1, 1, 1};
1594 printf(
"Reading OCIS L1B file\n");
1600 l1cstr->
iscan = sline;
1605 count[1] = num_pixels;
1616 if (oneline < num_scans - 1)
1617 start2[0] = sline + 1;
1628 if (oneline < num_scans - 2)
1629 start3[0] = sline + 2;
1644 count2[0] = num_blue_bands;
1646 count2[2] = num_pixels;
1648 status = nc_get_vara_float(observationGrp, Lt_blueId, start4, count2,
1652 count2[0] = num_red_bands;
1653 status = nc_get_vara_float(observationGrp, Lt_redId, start4, count2, l1cstr->
Lt_red[0]);
1656 count2[0] = num_SWIR_bands;
1657 status = nc_get_vara_float(observationGrp, Lt_SWIRId, start4, count2, l1cstr->
Lt_SWIR[0]);
1660 double scantime =
ymds2unix((int16_t)scan_time_year, (int16_t)scan_time_month, (int16_t)scan_time_day,
1668 int32_t
msec = (int32_t)(secs * 1000.0);
1671 float fsol = pow(1.0 /
esdist, 2);
1673 for (
size_t ip = 0; ip < num_pixels; ip++) {
1676 int ipb = ip * tot_num_bands;
1679 if(num_blue_bands<expected_num_blue_bands){
1680 expected_num_blue_bands=num_blue_bands;
1683 expected_num_blue_bands=expected_num_blue_bands-2;
1686 for (
band = 0;
band < expected_num_blue_bands;
band++) {
1688 l1cstr->
Lt_tot[ipb] = 0.001;
1692 l1cstr->
Lt_tot[ipb] *= 100;
1693 }
else if (use_rhot) {
1697 l1cstr->
Lt_tot[ipb] /= 10.;
1705 if(num_red_bands<expected_num_red_bands){
1706 expected_num_red_bands=num_red_bands;
1709 expected_num_red_bands=expected_num_red_bands-4;
1712 for (
band = 2;
band < expected_num_red_bands;
band++) {
1714 l1cstr->
Lt_tot[ipb] = 0.001;
1718 l1cstr->
Lt_tot[ipb] *= 100;
1719 }
else if (use_rhot) {
1722 l1cstr->
Lt_tot[ipb] /= 10.;
1731 if(num_SWIR_bands<expected_num_SWIR_bands){
1732 expected_num_SWIR_bands=num_SWIR_bands;
1734 for (
band = 0;
band < expected_num_SWIR_bands;
band++) {
1738 l1cstr->
Lt_tot[ipb] = 0.001;
1742 l1cstr->
Lt_tot[ipb] *= 100;
1743 }
else if (use_rhot) {
1746 l1cstr->
Lt_tot[ipb] /= 10.;
1759 size_t start3[] = {0, 0, 0};
1760 size_t count2[] = {1, 1, 1};
1765 printf(
"Reading HARP2 L1B file\n");
1766 cout <<
str << endl;
1771 l1cstr->
iscan = sline;
1779 count2[2] = num_pixels;
1781 status = nc_get_vara_float(blueGrp, senaId, start3, count2,
1784 status = nc_get_vara_float(blueGrp, latId, start3, count2,
1787 status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1793 if (oneline < num_scans - 1)
1794 start3[1] = sline + 1;
1798 status = nc_get_vara_float(blueGrp, latId, start3, count2,
1801 status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1805 status = nc_get_vara_float(blueGrp, IntId, start3, count2,
1815 size_t start3[] = {0, 0, 0};
1816 size_t count2[] = {1, 1, 1};
1821 printf(
"Reading HARP2 L1B file\n");
1822 cout <<
str << endl;
1827 l1cstr->
iscan = sline;
1835 count2[2] = num_pixels;
1837 status = nc_get_vara_float(blueGrp, senaId, start3, count2,
1840 status = nc_get_vara_float(blueGrp, latId, start3, count2,
1843 status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1849 if (oneline < num_scans - 1)
1850 start3[1] = sline + 1;
1854 status = nc_get_vara_float(blueGrp, latId, start3, count2,
1857 status = nc_get_vara_float(blueGrp, lonId, start3, count2,
1861 status = nc_get_vara_float(blueGrp, IntId, start3, count2,
1875 printf(
"Closing spexone l1b file\n");
1876 cout <<
str << endl;
1884 if (l1cstr->
latpix !=
nullptr)
1886 if (l1cstr->
lonpix !=
nullptr)
1888 if (l1cstr->
latpix2 !=
nullptr)
1890 if (l1cstr->
lonpix2 !=
nullptr)
1892 if (l1cstr->
latpix3 !=
nullptr)
1894 if (l1cstr->
lonpix3 !=
nullptr)
1907 l1cstr->
latpix =
nullptr;
1910 l1cstr->
lonpix =
nullptr;
1914 l1cstr->
I =
nullptr;
1924 printf(
"Closing ocis l1b file\n");
1925 cout <<
str << endl;
1931 if (l1cstr->
latpix !=
nullptr)
1933 if (l1cstr->
lonpix !=
nullptr)
1935 if (l1cstr->
latpix2 !=
nullptr)
1937 if (l1cstr->
lonpix2 !=
nullptr)
1939 if (l1cstr->
latpix3 !=
nullptr)
1941 if (l1cstr->
lonpix3 !=
nullptr)
1943 if (l1cstr->
timepix !=
nullptr)
1945 if (l1cstr->
tilt !=
nullptr)
1946 free (l1cstr->
tilt);
1966 if (l1cstr->
Lt_tot !=
nullptr)
1968 if (l1cstr->
Fobar !=
nullptr)
1969 free (l1cstr->
Fobar);
1970 if (l1cstr->
solz !=
nullptr)
1971 free (l1cstr->
solz);
1972 if (l1cstr->
senz !=
nullptr)
1973 free (l1cstr->
senz);
1975 l1cstr->
latpix =
nullptr;
1978 l1cstr->
lonpix =
nullptr;
1982 l1cstr->
tilt =
nullptr;
1985 l1cstr->
Lt_red =
nullptr;
1987 l1cstr->
Lt_tot =
nullptr;
1988 l1cstr->
Fobar =
nullptr;
1997 printf(
"Closing ocis l1b file\n");
1998 cout <<
str << endl;
2004 if (l1cstr->
latpix !=
nullptr)
2006 if (l1cstr->
lonpix !=
nullptr)
2008 if (l1cstr->
latpix2 !=
nullptr)
2010 if (l1cstr->
lonpix2 !=
nullptr)
2012 if (l1cstr->
latpix3 !=
nullptr)
2014 if (l1cstr->
lonpix3 !=
nullptr)
2016 if (l1cstr->
timepix !=
nullptr)
2037 if (l1cstr->
Lt_tot !=
nullptr)
2039 if (l1cstr->
Fobar !=
nullptr)
2040 free (l1cstr->
Fobar);
2041 if (l1cstr->
solz !=
nullptr)
2042 free (l1cstr->
solz);
2043 if (l1cstr->
senz !=
nullptr)
2044 free (l1cstr->
senz);
2046 l1cstr->
latpix =
nullptr;
2048 l1cstr->
lonpix =
nullptr;
2052 l1cstr->
Lt_red =
nullptr;
2054 l1cstr->
Lt_tot =
nullptr;
2055 l1cstr->
Fobar =
nullptr;
2064 printf(
"Closing harp2 l1b file\n");
2065 cout <<
str << endl;
2090 l1cstr->
latpix =
nullptr;
2092 l1cstr->
lonpix =
nullptr;
2095 l1cstr->
I =
nullptr;
2105 printf(
"Closing harp2 l1b file\n");
2106 cout <<
str << endl;
2131 l1cstr->
latpix =
nullptr;
2133 l1cstr->
lonpix =
nullptr;
2136 l1cstr->
I =
nullptr;