23 static int extract_pixel_start = 0;
24 static int normalizedLt = 1;
25 static int use_rhot = 0;
27 static short *tmpShort;
30 static size_t expected_num_blue_bands = 120;
31 static size_t expected_num_red_bands = 120;
32 static size_t expected_num_SWIR_bands = 9;
34 static size_t num_scans, num_pixels;
35 static size_t num_blue_bands, num_red_bands, num_SWIR_bands;
36 static size_t tot_num_bands = 239;
40 static double *scan_time;
41 static int32_t scan_time_year, scan_time_month, scan_time_day;
46 static int geolocationGrp;
47 static int lonId, latId, senzId, senaId, solzId, solaId;
48 static float latFillValue = -999.0;
49 static float lonFillValue = -999.0;
50 static short senzFillValue = -32768;
51 static float senzScale = 0.01;
52 static float senzOffset = 0.0;
53 static short senaFillValue = -32768;
54 static float senaScale = 0.01;
55 static float senaOffset = 0.0;
56 static short solzFillValue = -32768;
57 static float solzScale = 0.01;
58 static float solzOffset = 0.0;
59 static short solaFillValue = -32768;
60 static float solaScale = 0.01;
61 static float solaOffset = 0.0;
64 static int observationGrp;
65 static int Lt_blueId, Lt_redId, Lt_SWIRId;
66 static float **Lt_blue;
67 static float **Lt_red;
68 static float **Lt_SWIR;
69 static float Lt_blueFillValue = -999.0;
70 static float Lt_redFillValue = -999.0;
71 static float Lt_SWIRFillValue = -999.0;
89 printf(
"Opening OCIS L1B file\n");
90 status = nc_open(
file->name, NC_NOWRITE, &ncid_L1B);
92 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
93 __FILE__, __LINE__,
file->name);
98 status = nc_inq_dimid(ncid_L1B,
"number_of_scans", &dimid);
100 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
103 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
106 status = nc_inq_dimid(ncid_L1B,
"ccd_pixels", &dimid);
108 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
111 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
114 status = nc_inq_dimid(ncid_L1B,
"blue_bands", &dimid);
116 fprintf(
stderr,
"-E- Error reading num_blue_bands.\n");
119 nc_inq_dimlen(ncid_L1B, dimid, &num_blue_bands);
120 if(num_blue_bands < expected_num_blue_bands) {
121 fprintf(
stderr,
"-E- Not enough blue bands, expecting %d, found %d.\n",
122 (
int)expected_num_blue_bands, (
int)num_blue_bands);
127 status = nc_inq_dimid(ncid_L1B,
"red_bands", &dimid);
129 fprintf(
stderr,
"-E- Error reading num_red_bands.\n");
132 nc_inq_dimlen(ncid_L1B, dimid, &num_red_bands);
133 if(num_red_bands < expected_num_red_bands) {
134 fprintf(
stderr,
"-E- Not enough red bands, expecting %d, found %d.\n",
135 (
int)expected_num_red_bands, (
int)num_red_bands);
140 status = nc_inq_dimid(ncid_L1B,
"SWIR_bands", &dimid);
142 fprintf(
stderr,
"-E- Error reading num_SWIR_bands.\n");
145 nc_inq_dimlen(ncid_L1B, dimid, &num_SWIR_bands);
146 if(num_SWIR_bands < expected_num_SWIR_bands) {
147 fprintf(
stderr,
"-E- Not enough SWIR bands, expecting %d, found %d.\n",
148 (
int)expected_num_SWIR_bands, (
int)num_SWIR_bands);
153 printf(
"OCI L1B Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
157 tmpShort = (
short*) malloc(num_pixels *
sizeof(
short));
158 scan_time = (
double*) malloc(num_scans *
sizeof(
double));
166 if ((nc_inq_grp_ncid(ncid_L1B,
"scan_line_attributes", &groupid)) == NC_NOERR) {
168 fprintf(
stderr,
"-E- Error finding scan_line_attributes.\n");
172 double scan_timeFillValue = -999.9;
173 status = nc_inq_varid(groupid,
"time", &varid);
175 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
177 status = nc_get_var_double(groupid, varid, scan_time);
179 status = nc_get_att_int(groupid, varid,
"year", &scan_time_year);
181 status = nc_get_att_int(groupid, varid,
"month", &scan_time_month);
183 status = nc_get_att_int(groupid, varid,
"day", &scan_time_day);
186 status = nc_inq_varid(groupid,
"ev_mid_time", &varid);
188 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
190 status = nc_get_var_double(groupid, varid, scan_time);
195 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
199 char*
time_str = (
char *) malloc(att_len + 1);
202 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
210 scan_time_year =
syear;
211 scan_time_month = smon;
212 scan_time_day =
sday;
216 for(
int i=0;
i<num_scans;
i++) {
217 if(scan_time[
i] == scan_timeFillValue)
224 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"normalizedLt", &normLt);
226 normalizedLt = normLt;
231 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
235 status = nc_inq_grp_ncid(ncid_L1B,
"geolocation_data", &geolocationGrp);
237 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
239 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
241 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
243 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
246 status = nc_inq_varid(geolocationGrp,
"sensor_zenith", &senzId);
248 status = nc_inq_var_fill(geolocationGrp, senzId,
NULL, &senzFillValue);
250 status = nc_get_att_float(geolocationGrp, senzId,
"scale_factor", &senzScale);
252 status = nc_get_att_float(geolocationGrp, senzId,
"add_offset", &senzOffset);
255 status = nc_inq_varid(geolocationGrp,
"sensor_azimuth", &senaId);
257 status = nc_inq_var_fill(geolocationGrp, senaId,
NULL, &senaFillValue);
259 status = nc_get_att_float(geolocationGrp, senaId,
"scale_factor", &senaScale);
261 status = nc_get_att_float(geolocationGrp, senaId,
"add_offset", &senaOffset);
264 status = nc_inq_varid(geolocationGrp,
"solar_zenith", &solzId);
266 status = nc_inq_var_fill(geolocationGrp, solzId,
NULL, &solzFillValue);
268 status = nc_get_att_float(geolocationGrp, solzId,
"scale_factor", &solzScale);
270 status = nc_get_att_float(geolocationGrp, solzId,
"add_offset", &solzOffset);
273 status = nc_inq_varid(geolocationGrp,
"solar_azimuth", &solaId);
275 status = nc_inq_var_fill(geolocationGrp, solaId,
NULL, &solaFillValue);
277 status = nc_get_att_float(geolocationGrp, solaId,
"scale_factor", &solaScale);
279 status = nc_get_att_float(geolocationGrp, solaId,
"add_offset", &solaOffset);
284 status = nc_inq_grp_ncid(ncid_L1B,
"observation_data", &observationGrp);
289 status = nc_inq_varid(observationGrp,
"Lt_blue", &Lt_blueId);
292 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
295 status = nc_inq_varid(observationGrp,
"Lt_red", &Lt_redId);
297 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
300 status = nc_inq_varid(observationGrp,
"Lt_SWIR", &Lt_SWIRId);
302 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
305 status = nc_inq_varid(observationGrp,
"rhot_blue", &Lt_blueId);
307 status = nc_inq_var_fill(observationGrp, Lt_blueId,
NULL, &Lt_blueFillValue);
310 status = nc_inq_varid(observationGrp,
"rhot_red", &Lt_redId);
312 status = nc_inq_var_fill(observationGrp, Lt_redId,
NULL, &Lt_redFillValue);
315 status = nc_inq_varid(observationGrp,
"rhot_SWIR", &Lt_SWIRId);
317 status = nc_inq_var_fill(observationGrp, Lt_SWIRId,
NULL, &Lt_SWIRFillValue);
323 file->sd_id = ncid_L1B;
324 file->nbands = tot_num_bands;
325 file->npix = num_pixels;
326 file->nscan = num_scans;
328 file->terrain_corrected = 1;
329 file->orbit_number = orbit_number;
333 "Fobar", (
void **) &Fobar);
336 printf(
"file->nbands = %d\n", (
int)
file->nbands);
357 size_t start[] = { 0, 0, 0 };
358 size_t count[] = { 1, 1, 1 };
361 for (
int ip = 0; ip < num_pixels; ip++) {
362 l1rec->pixnum[ip] = ip + extract_pixel_start;
367 l1rec->scantime =
ymds2unix((int16_t)scan_time_year, (int16_t)scan_time_month, (int16_t)scan_time_day, scan_time[
line]);
375 int32_t
msec = (int32_t) (secs * 1000.0);
384 count[1] = num_pixels;
391 for(
int i=0;
i<num_pixels;
i++) {
392 if(
l1rec->lat[
i] == latFillValue)
394 if(
l1rec->lon[
i] == lonFillValue)
400 for(
int i=0;
i<num_pixels;
i++) {
401 if(tmpShort[
i] == senaFillValue)
404 l1rec->sena[
i] = tmpShort[
i] * senaScale + senaOffset;
409 for(
int i=0;
i<num_pixels;
i++) {
410 if(tmpShort[
i] == senzFillValue)
413 l1rec->senz[
i] = tmpShort[
i] * senzScale + senzOffset;
418 for(
int i=0;
i<num_pixels;
i++) {
419 if(tmpShort[
i] == solaFillValue)
422 l1rec->sola[
i] = tmpShort[
i] * solaScale + solaOffset;
427 for(
int i=0;
i<num_pixels;
i++) {
428 if(tmpShort[
i] == solzFillValue)
431 l1rec->solz[
i] = tmpShort[
i] * solzScale + solzOffset;
438 count[0] = num_blue_bands;
440 count[2] = num_pixels;
441 status = nc_get_vara_float(observationGrp, Lt_blueId,
start,
count, Lt_blue[0]);
444 count[0] = num_red_bands;
445 status = nc_get_vara_float(observationGrp, Lt_redId,
start,
count, Lt_red[0]);
448 count[0] = num_SWIR_bands;
449 status = nc_get_vara_float(observationGrp, Lt_SWIRId,
start,
count, Lt_SWIR[0]);
460 for(
int ip=0; ip<num_pixels; ip++) {
463 int ipb = ip * tot_num_bands;
467 if(Lt_blue[
band][ip] == Lt_blueFillValue) {
468 l1rec->Lt[ipb] = 0.001;
473 }
else if (use_rhot) {
476 l1rec->Lt[ipb] /= 10.;
485 if(Lt_red[
band][ip] == Lt_redFillValue) {
486 l1rec->Lt[ipb] = 0.001;
491 }
else if (use_rhot) {
494 l1rec->Lt[ipb] /= 10.;
505 if(Lt_SWIR[
band][ip] == Lt_SWIRFillValue) {
506 l1rec->Lt[ipb] = 0.001;
511 }
else if (use_rhot) {
514 l1rec->Lt[ipb] /= 10.;
534 printf(
"Closing ocis l1b file\n");
540 if (tmpShort) free(tmpShort);
541 if (scan_time) free(scan_time);