26 #include <boost/foreach.hpp>
27 #include <boost/algorithm/string.hpp>
29 static short *tmpShort;
32 static size_t expected_number_of_bands = 239;
34 static size_t num_scans, num_pixels,number_of_bands;
38 static double *scan_time;
39 static int32_t scan_time_year, scan_time_month, scan_time_day;
45 static int geolocationGrp;
46 static int tiltId,lonId, latId,prodims[345];
47 static float latFillValue = -999.0;
48 static float lonFillValue = -999.0;
50 static float tiltmin = 0.0,tiltmax=0.0;
51 static float tiltFillValue = -999.0;
54 static int observationGrp;
65 l2_str::l2_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} {
74 scan_quality_flag=
nullptr;
120 string delim1 =
":, ";
121 string l2prod_str = l1cinput->
l2prod;
122 boost::trim_if(l2prod_str, boost::is_any_of(delim1));
123 vector<string> prodparam;
124 boost::algorithm::split(prodparam, l2prod_str,
125 boost::is_any_of(delim1));
126 cout<<
"number of L2 products to be processed...................#:..."<<prodparam.size()<<endl;
127 for(
size_t iprod=0;iprod<prodparam.size();iprod++){
128 cout<<
"selected L2 ----------- prodparam...."<<prodparam[iprod]<<endl;
136 printf(
"Opening OCIS L2 file\n");
139 status = nc_open(ptstr, NC_NOWRITE, &ncid_L1B);
141 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
142 __FILE__, __LINE__, ptstr);
147 status = nc_inq_dimid(ncid_L1B,
"number_of_lines", &dimid);
149 fprintf(
stderr,
"-E- Error reading number_of_scans.\n");
152 nc_inq_dimlen(ncid_L1B, dimid, &num_scans);
153 l2str->
nscan=num_scans;
156 status = nc_inq_dimid(ncid_L1B,
"pixels_per_line", &dimid);
158 fprintf(
stderr,
"-E- Error reading num_pixels.\n");
161 nc_inq_dimlen(ncid_L1B, dimid, &num_pixels);
162 l2str->
npix=num_pixels;
165 status = nc_inq_dimid(ncid_L1B,
"number_of_bands", &dimid);
167 fprintf(
stderr,
"-E- Error reading number of_bands.\n");
170 nc_inq_dimlen(ncid_L1B, dimid, &number_of_bands);
171 if(number_of_bands < expected_number_of_bands) {
172 fprintf(
stderr,
"-E- Not enough bands, expecting %d, found %d.\n",
173 (
int)expected_number_of_bands, (
int)number_of_bands);
178 printf(
"OCI L2 Npix :%d Nlines:%d\n", (
int)num_pixels, (
int)num_scans);
183 tmpShort = (
short*) calloc(num_pixels,
sizeof(
short));
184 scan_time = (
double*) calloc(num_scans,
sizeof(
double));
185 l2str->
tilt=(
float*)calloc(num_scans,
sizeof(
float));
186 l2str->
latpix=(
float*)calloc(num_pixels,
sizeof(
float));
187 l2str->
lonpix=(
float*)calloc(num_pixels,
sizeof(
float));
194 if ((nc_inq_grp_ncid(ncid_L1B,
"scan_line_attributes", &groupid)) == NC_NOERR) {
196 fprintf(
stderr,
"-E- Error finding scan_line_attributes.\n");
200 double scan_timeFillValue = -999.9;
201 status = nc_inq_varid(groupid,
"time", &varid);
203 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
205 status = nc_get_var_double(groupid, varid, scan_time);
207 status = nc_get_att_int(groupid, varid,
"year", &scan_time_year);
209 status = nc_get_att_int(groupid, varid,
"month", &scan_time_month);
211 status = nc_get_att_int(groupid, varid,
"day", &scan_time_day);
214 status = nc_inq_varid(groupid,
"msec", &varid);
216 status = nc_inq_var_fill(groupid, varid,
NULL, &scan_timeFillValue);
218 status = nc_get_var_double(groupid, varid, scan_time);
223 status = nc_inq_attlen(ncid_L1B, NC_GLOBAL,
"time_coverage_start", &att_len);
227 char*
time_str = (
char *) malloc(att_len + 1);
230 status = nc_get_att_text(ncid_L1B, NC_GLOBAL,
"time_coverage_start",
time_str);
238 scan_time_year =
syear;
239 scan_time_month = smon;
240 scan_time_day =
sday;
244 for(
size_t i=0;
i<num_scans;
i++) {
245 if(scan_time[
i] == scan_timeFillValue)
251 status = nc_get_att_int(ncid_L1B, NC_GLOBAL,
"orbit_number", &orbit_number);
255 status = nc_inq_grp_ncid(ncid_L1B,
"navigation_data", &geolocationGrp);
257 status = nc_inq_varid(geolocationGrp,
"longitude", &lonId);
260 status = nc_inq_var_fill(geolocationGrp, lonId,
NULL, &lonFillValue);
262 status = nc_inq_varid(geolocationGrp,
"latitude", &latId);
264 status = nc_inq_var_fill(geolocationGrp, latId,
NULL, &latFillValue);
267 status = nc_inq_varid(geolocationGrp,
"tilt", &tiltId);
269 status = nc_inq_var_fill(geolocationGrp, tiltId,
NULL, &tiltFillValue);
271 status = nc_get_att_float(geolocationGrp, tiltId,
"valid_min", &tiltmin);
273 status = nc_get_att_float(geolocationGrp, tiltId,
"valid_max", &tiltmax);
279 status = nc_inq_grp_ncid(ncid_L1B,
"geophysical_data", &observationGrp);
282 for (
size_t iprod = 0;iprod <
nl2prod;iprod++) {
283 cout<<
"getting sds id for product.."<<prodparam[iprod].c_str()<<endl;
284 status = nc_inq_varid(observationGrp, prodparam[iprod].c_str(), &prodims[iprod]);
293 string ATT_NAME1=
"scale_factor",ATT_NAME2=
"add_offset";
294 for (
size_t iprod = 0;iprod <
nl2prod;iprod++) {
295 if (nc_get_att_float(observationGrp, prodims[iprod], ATT_NAME1.c_str(), &l2str->
slopeprod[iprod]))
297 if (nc_get_att_float(observationGrp, prodims[iprod], ATT_NAME2.c_str() , &l2str->
offsetprod[iprod]))
304 status = nc_get_var_float(geolocationGrp,tiltId,l2str->
tilt);
335 size_t start[] = {0,0};
336 size_t count[] = {1,1};
340 printf(
"Reading OCIS L2 file\n");
351 count[1] = num_pixels;
360 for (
size_t iprod = 0;iprod <
nl2prod;iprod++) {
375 printf(
"Closing ocis L2 file\n");
381 if (l2str->
latpix !=
nullptr)
382 delete [] (l2str->
latpix);
383 if (l2str->
lonpix !=
nullptr)
384 delete [] (l2str->
lonpix);
389 if (l2str->
tilt !=
nullptr)
390 delete [] (l2str->
tilt);
391 if (l2str->
l2prod !=
nullptr)
392 delete [] (l2str->
l2prod);
394 if (tmpShort) free(tmpShort);
395 if (scan_time) free(scan_time);