29 static short *tmpShort;
32 static size_t expected_num_blue_bands = 60;
33 static size_t expected_num_red_bands = 60;
34 static size_t expected_num_SWIR_bands = 9;
38 static size_t num_scans, num_pixels;
39 static size_t num_blue_bands, num_red_bands, num_SWIR_bands;
44 static double *scan_time;
45 static int32_t scan_time_year, scan_time_month, scan_time_day;
52 static int geolocationGrp;
53 static int lonId, latId, senzId, senaId, solzId, solaId;
54 static float latFillValue = -999.0;
55 static float lonFillValue = -999.0;
56 static short senzFillValue = -32768;
57 static float senzScale = 0.01;
58 static float senzOffset = 0.0;
59 static short senaFillValue = -32768;
60 static float senaScale = 0.01;
61 static float senaOffset = 0.0;
62 static short solzFillValue = -32768;
63 static float solzScale = 0.01;
64 static float solzOffset = 0.0;
65 static short solaFillValue = -32768;
66 static float solaScale = 0.01;
67 static float solaOffset = 0.0;
70 static int observationGrp;
71 static int Lt_blueId, Lt_redId, Lt_SWIRId;
78 static float Lt_blueFillValue = -999.0;
79 static float Lt_redFillValue = -999.0;
80 static float Lt_SWIRFillValue = -999.0;
106 l1c_str::l1c_str() :
att_ang{-999.0,-999.0,-999.0}, orb_pos{-999.0,-999.0,-999.0}, orb_vel{-999.0,-999.0,-999.0} {
115 scan_quality_flag=
nullptr;
144 cloud_height=
nullptr;
164 printf(
"Opening OCIS L1B file\n");
167 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
169 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
170 __FILE__, __LINE__, ptstr);
175 status = nc_inq_dimid(ncid_L1B,
"number_of_scans", &dimid);
177 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
180 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
181 l1cstr->
nscan=num_scans;
184 status = nc_inq_dimid(ncid_L1B,
"ccd_pixels", &dimid);
186 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
189 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
190 l1cstr->
npix=num_pixels;
193 status = nc_inq_dimid(ncid_L1B,
"blue_bands", &dimid);
195 fprintf(
stderr,
"-E- Error reading num_blue_bands.\n");
198 nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
199 if(num_blue_bands < expected_num_blue_bands) {
200 fprintf(
stderr,
"-E- Not enough blue bands, expecting %d, found %d.\n",
201 (
int)expected_num_blue_bands, (
int)num_blue_bands);
206 status = nc_inq_dimid(ncid_L1B,
"red_bands", &dimid);
208 fprintf(
stderr,
"-E- Error reading num_red_bands.\n");
211 nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
212 if(num_red_bands < expected_num_red_bands) {
213 fprintf(
stderr,
"-E- Not enough red bands, expecting %d, found %d.\n",
214 (
int)expected_num_red_bands, (
int)num_red_bands);
219 status = nc_inq_dimid(ncid_L1B,
"SWIR_bands", &dimid);
221 fprintf(
stderr,
"-E- Error reading num_SWIR_bands.\n");
224 nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
225 if(num_SWIR_bands < expected_num_SWIR_bands) {
226 fprintf(
stderr,
"-E- Not enough SWIR bands, expecting %d, found %d.\n",
227 (
int)expected_num_SWIR_bands, (
int)num_SWIR_bands);
232 printf(
"OCI L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
237 tmpShort = (
short*) calloc(num_pixels,
sizeof(
short));
238 scan_time = (
double*) calloc(num_scans,
sizeof(
double));
240 l1cstr->
senazpix=(
float*)calloc(num_pixels,
sizeof(
float));
241 l1cstr->
latpix=(
float*)calloc(num_pixels,
sizeof(
float));
242 l1cstr->
lonpix=(
float*)calloc(num_pixels,
sizeof(
float));
243 l1cstr->
latpix2=(
float*)calloc(num_pixels,
sizeof(
float));
244 l1cstr->
lonpix2=(
float*)calloc(num_pixels,
sizeof(
float));
253 if ((nc_inq_grp_ncid(ncid_L1B,
"scan_line_attributes", &groupid)) == NC_NOERR) {
255 fprintf(
stderr,
"-E- Error finding scan_line_attributes.\n");
259 double scan_timeFillValue = -999.9;
260 status = nc_inq_varid(groupid,
"time", &varid);
262 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
264 status = nc_get_var_double(groupid, varid, scan_time);
266 status = nc_get_att_int(groupid, varid,
"year", &scan_time_year);
268 status = nc_get_att_int(groupid, varid,
"month", &scan_time_month);
270 status = nc_get_att_int(groupid, varid,
"day", &scan_time_day);
273 status = nc_inq_varid(groupid,
"ev_mid_time", &varid);
275 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
277 status = nc_get_var_double(groupid, varid, scan_time);
282 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
286 char*
time_str = (
char *) malloc(att_len + 1);
289 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
297 scan_time_year =
syear;
298 scan_time_month = smon;
299 scan_time_day =
sday;
303 for(
size_t i=0;
i<num_scans;
i++) {
304 if(scan_time[
i] == scan_timeFillValue)
310 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
314 status = nc_inq_grp_ncid(ncid_L1B,
"geolocation_data", &geolocationGrp);
316 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
319 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
321 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
323 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
326 status = nc_inq_varid(geolocationGrp,
"sensor_zenith", &senzId);
328 status = nc_inq_var_fill(geolocationGrp, senzId,
NULL, &senzFillValue);
330 status = nc_get_att_float(geolocationGrp, senzId,
"scale_factor", &senzScale);
332 status = nc_get_att_float(geolocationGrp, senzId,
"add_offset", &senzOffset);
335 status = nc_inq_varid(geolocationGrp,
"sensor_azimuth", &senaId);
337 status = nc_inq_var_fill(geolocationGrp, senaId,
NULL, &senaFillValue);
339 status = nc_get_att_float(geolocationGrp, senaId,
"scale_factor", &senaScale);
341 status = nc_get_att_float(geolocationGrp, senaId,
"add_offset", &senaOffset);
344 status = nc_inq_varid(geolocationGrp,
"solar_zenith", &solzId);
346 status = nc_inq_var_fill(geolocationGrp, solzId,
NULL, &solzFillValue);
348 status = nc_get_att_float(geolocationGrp, solzId,
"scale_factor", &solzScale);
350 status = nc_get_att_float(geolocationGrp, solzId,
"add_offset", &solzOffset);
353 status = nc_inq_varid(geolocationGrp,
"solar_azimuth", &solaId);
355 status = nc_inq_var_fill(geolocationGrp, solaId,
NULL, &solaFillValue);
357 status = nc_get_att_float(geolocationGrp, solaId,
"scale_factor", &solaScale);
359 status = nc_get_att_float(geolocationGrp, solaId,
"add_offset", &solaOffset);
364 status = nc_inq_grp_ncid(ncid_L1B,
"observation_data", &observationGrp);
368 status = nc_inq_varid(observationGrp,
"Lt_blue", &Lt_blueId);
370 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
373 status = nc_inq_varid(observationGrp,
"Lt_red", &Lt_redId);
375 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
378 status = nc_inq_varid(observationGrp,
"Lt_SWIR", &Lt_SWIRId);
380 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
415 size_t start[] = {0,0},start2[]={0,0},start3[] = {0,0,0};
416 size_t count[] = {1,1},count2[] = {1,1,1};
422 printf(
"Reading OCIS L1B file\n");
433 count[1] = num_pixels;
444 if(oneline<num_scans-1)
462 count2[0] = num_blue_bands;
464 count2[2] = num_pixels;
466 status = nc_get_vara_float(observationGrp, Lt_blueId, start3, count2, l1cstr->
Lt_blue[0]);
469 count2[0] = num_red_bands;
470 status = nc_get_vara_float(observationGrp, Lt_redId, start3, count2, l1cstr->
Lt_red[0]);
473 count2[0] = num_SWIR_bands;
474 status = nc_get_vara_float(observationGrp, Lt_SWIRId, start3, count2, l1cstr->
Lt_SWIR[0]);
485 printf(
"Closing ocis l1b file\n");
495 if (l1cstr->
latpix !=
nullptr)
496 delete [] (l1cstr->
latpix);
497 if (l1cstr->
lonpix !=
nullptr)
498 delete [] (l1cstr->
lonpix);
499 if (l1cstr->
latpix2 !=
nullptr)
501 if (l1cstr->
lonpix2 !=
nullptr)
504 if (tmpShort) free(tmpShort);
505 if (scan_time) free(scan_time);