71 #define TITLE_OLD "Title"
72 #define INFILES "input_sources"
73 #define INFILES_OLD "Input Files"
74 #define SENNME "instrument"
75 #define SENNME_OLD "Sensor Name"
76 #define DCENTER "project"
77 #define DCENTER_OLD "Data Center"
78 #define NFREC "Filled Scan Lines"
79 #define PCTFLAG "flag_percentages"
80 #define PCTFLAG_OLD "Flag Percentages"
81 #define NTIME "equatorCrossingDateTime"
82 #define NTIME_OLD "Node Crossing Time"
83 #define SNODE "startDirection"
84 #define SNODE_OLD "Start Node"
85 #define ENODE "endDirection"
86 #define ENODE_OLD "End Node"
87 #define MISSION "platform"
88 #define MISSION_OLD "Mission"
89 #define MSNCHAR "Mission Characteristics"
90 #define SENSOR "Sensor"
91 #define SNSCHAR "Sensor Characteristics"
92 #define ORBNUM "orbit_number"
93 #define ORBNUM_OLD "Orbit Number"
94 #define NLAT "northernmost_latitude"
95 #define NLAT_OLD "Northernmost Latitude"
96 #define SLAT "southernmost_latitude"
97 #define SLAT_OLD "Southernmost Latitude"
98 #define WLON "westernmost_longitude"
99 #define WLON_OLD "Westernmost Longitude"
100 #define ELON "easternmost_longitude"
101 #define ELON_OLD "Easternmost Longitude"
102 #define STCLAT "start_center_latitude"
103 #define STCLAT_OLD "Start Center Latitude"
104 #define STCLON "start_center_longitude"
105 #define STCLON_OLD "Start Center Longitude"
106 #define ENDCLAT "end_center_latitude"
107 #define ENDCLAT_OLD "End Center Latitude"
108 #define ENDCLON "end_center_longitude"
109 #define ENDCLON_OLD "End Center Longitude"
110 #define NODEL "equatorCrossingLongitude"
111 #define NODEL_OLD "Orbit Node Longitude"
112 #define LAC_PX_ST "LAC Pixel Start Number"
113 #define LAC_PX_SUBSAMP "LAC Pixel Subsampling"
114 #define NUM_LATLON_NAME 4
115 #define INIT_DELTA 10000
116 #define SHOW_NC_ERROR(func, err, ...) \
118 if (err != NC_NOERR) { \
119 printf(__VA_ARGS__); \
120 exit(EXIT_FAILURE); \
130 static int32_t n_files_open = 0;
131 static char geo_location_data_grp_lat[256];
132 static char geo_location_data_grp_lon[256];
135 static int32_t grp_id_geo_lat[
MAXNFILES];
136 static int32_t grp_id_geo_lon[
MAXNFILES];
160 static idDS *ds_id_l2_flags;
161 static idDS *ds_id_eng_qual;
162 static idDS *ds_id_s_flags;
163 static idDS *ds_id_nflag;
164 static idDS *ds_id_pixnum;
165 static idDS *ds_id_file;
166 static idDS *ds_id_wave;
167 static idDS *ds_id_wave3d;
169 static int32_t *nsta;
170 static int32_t *ninc;
172 static int databufSize = 0;
173 static unsigned char *databuf =
NULL;
174 static char **prodlist;
176 static int32_t n_cntl_pnts;
177 static int32_t prev_n_cntl_pnts = -1;
179 static float geonav[6][9];
181 static int32_t one = 1;
182 static int32_t zero32 = 0;
183 static int32_t l2_flags_type;
185 static int32_t bandsPerPixel = 1;
186 static int32_t wavelength_3d = 1;
188 static cache_str cache_l2_flags;
189 static cache_str cache_eng_qual;
190 static cache_str cache_s_flags;
191 static cache_str cache_nflag;
192 static cache_str cache_pixnum;
193 static cache_str cache_longitude;
194 static cache_str cache_latitude;
195 static int32_t cache_nprod;
196 static cache_str **cache_l2_data;
217 pixelAreaInfo.
nsamp = 0;
233 if (
dtype == DFNT_INT8)
235 else if (
dtype == DFNT_UINT8)
239 else if (
dtype == DFNT_UINT16)
243 else if (
dtype == DFNT_UINT32)
247 else if (
dtype == DFNT_FLOAT64)
250 printf(
"-E- %s:%d - unknown data type.\n", __FILE__, __LINE__);
262 cache_l2_flags.bscan = -1;
263 cache_eng_qual.bscan = -1;
264 cache_s_flags.bscan = -1;
265 cache_nflag.bscan = -1;
266 cache_pixnum.bscan = -1;
267 cache_longitude.bscan = -1;
268 cache_latitude.bscan = -1;
270 cache_l2_flags.escan = -1;
271 cache_eng_qual.escan = -1;
272 cache_s_flags.escan = -1;
273 cache_nflag.escan = -1;
274 cache_pixnum.escan = -1;
275 cache_longitude.escan = -1;
276 cache_latitude.escan = -1;
278 for (
i = 0;
i < cache_nprod;
i++) {
279 cache_l2_data[
i]->bscan = -1;
280 cache_l2_data[
i]->escan = -1;
290 tmp_cache.bscan = -1;
291 tmp_cache.escan = -1;
292 tmp_cache.dataSize = 0;
293 tmp_cache.data =
NULL;
295 cache_l2_flags = tmp_cache;
296 cache_eng_qual = tmp_cache;
297 cache_s_flags = tmp_cache;
298 cache_nflag = tmp_cache;
299 cache_pixnum = tmp_cache;
300 cache_longitude = tmp_cache;
301 cache_latitude = tmp_cache;
305 int newSize = l2_str->nsamp * maxThirdDim * 8;
306 if (databufSize < newSize) {
309 databufSize = newSize;
310 databuf = (
unsigned char *)malloc(databufSize);
316 int32_t
openL2(
const char *fname,
const char *plist, l2_prod *l2_str) {
322 int32_t tilt_start[2] = {0, 0};
323 int32_t tilt_edges[2] = {20, 2};
324 int16_t t_ranges[2 * 20];
332 char buffer[2048 * 8];
334 char *numstr[] = {
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
335 "12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
336 "23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33"};
338 static int32_t first = 1;
342 if (Hishdf(fname) == 1) {
350 if (l2_str->nrec == 0) {
351 strcpy(l2_str->filename, fname);
353 fileindex = n_files_open - 1;
354 l2_str->fileindex = fileindex;
356 fileindex = l2_str->fileindex;
390 prodlist[fileindex] = (
char *)calloc(strlen(plist) + 1,
sizeof(char));
391 strcpy(prodlist[fileindex], plist);
396 getProdlist(fname, &prodlist[fileindex], &l2_flags_type);
401 l2_str->prodname[0] = &prodlist[fileindex][0];
402 len = strlen(prodlist[fileindex]);
403 for (
i = 0;
i < len;
i++) {
404 if (prodlist[fileindex][
i] ==
',') {
405 l2_str->prodname[l2_str->nprod] = prodlist[fileindex] +
i + 1;
407 prodlist[fileindex][
i] = 0;
411 if (strlen(prodlist[fileindex]) == 0)
417 ds_id_file[fileindex] = ds_id;
422 const char *
filename = l2_str->filename;
425 &grp_id_geo_lat[fileindex], &name_lat_nc[fileindex]),
426 status,
"\n--Error--: couldn't find latitude in file %s. See %s in line %d. Exiting ... \n",
430 &grp_id_geo_lon[fileindex], &name_lon_nc[fileindex]),
431 status,
"\n--Error--: couldn't find longitude in file %s. See %s in line %d. Exiting ... \n",
434 if (grp_id_geo_lon[fileindex] != grp_id_geo_lat[fileindex] &&
status != NC_NOERR) {
435 printf(
"\nWaring: latitude and longitude arrays are placed in different groups");
437 SHOW_NC_ERROR(nc_inq_grpname(grp_id_geo_lat[fileindex], geo_location_data_grp_lat),
status,
438 "\n--Error--: could not get the geolocation group name for latitude in file %s. See %s "
439 "in line %d. Exiting ...\n",
441 SHOW_NC_ERROR(nc_inq_grpname(grp_id_geo_lon[fileindex], geo_location_data_grp_lon),
status,
442 "\n--Error--: could not get the geolocation group name for longitude in file %s. See "
443 "%s in line %d. Exiting ...\n",
447 "scantime", ds_id.
fid, &scantime_var[fileindex], &scantime_grp[fileindex]);
449 scantime_grp[fileindex] = -1;
450 scantime_var[fileindex] = -1;
453 nc_inq_ncid(ds_id.
fid,
"sensor_band_parameters", &grp_id[fileindex][0]);
454 nc_inq_ncid(ds_id.
fid,
"sensor_tilt", &grp_id[fileindex][1]);
455 nc_inq_ncid(ds_id.
fid,
"scan_line_attributes", &grp_id[fileindex][2]);
456 nc_inq_ncid(ds_id.
fid,
"geophysical_data", &grp_id[fileindex][3]);
457 nc_inq_ncid(ds_id.
fid,
"navigation_data", &grp_id[fileindex][4]);
458 nc_inq_ncid(ds_id.
fid,
"processing_control", &grp_id[fileindex][5]);
464 status = nc_inq_dimid(ds_id.
fid,
"number_of_lines", &dim_id);
466 status = nc_inq_dimid(ds_id.
fid,
"Number_of_Scan_Lines", &dim_id);
468 printf(
"-E- %s:%d - openL2 - could not find number_of_lines.\n", __FILE__, __LINE__);
472 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
473 l2_str->nrec = tmpSizet;
474 status = nc_inq_dimid(ds_id.
fid,
"pixels_per_line", &dim_id);
476 status = nc_inq_dimid(ds_id.
fid,
"Pixels_per_Scan_Line", &dim_id);
478 printf(
"-E- %s:%d - openL2 - could not find pixels_per_line.\n", __FILE__, __LINE__);
482 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
483 l2_str->nsamp = tmpSizet;
485 status = nc_inq_dimid(ds_id.
fid,
"bands_per_pixel", &dim_id);
487 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
488 bandsPerPixel = tmpSizet;
490 l2_str->bandsPerPixel = bandsPerPixel;
491 wavelength_3d = bandsPerPixel;
493 status = nc_inq_dimid(ds_id.
fid,
"wavelength_3d", &dim_id);
495 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
496 wavelength_3d = tmpSizet;
498 l2_str->wavelength_3d = wavelength_3d;
501 readAttr(ds_id,
"Number of Scan Lines", (
void *)&l2_str->nrec);
502 readAttr(ds_id,
"Pixels per Scan Line", (
void *)&l2_str->nsamp);
513 tmpStr =
readAttrStr(ds_id,
"time_coverage_start");
515 printf(
"-E- %s:%d - openL2 - could not find time_coverage_start.\n", __FILE__, __LINE__);
521 l2_str->syear = (int16_t)yr;
522 l2_str->sday = (int16_t)dy;
524 l2_str->year = (int16_t)yr;
525 l2_str->day = (int16_t)dy;
531 printf(
"-E- %s:%d - openL2 - could not find time_coverage_end.\n", __FILE__, __LINE__);
537 l2_str->eyear = (int16_t)yr;
538 l2_str->eday = (int16_t)dy;
542 readAttr(ds_id,
"Start Year", (
void *)&l2_str->syear);
543 readAttr(ds_id,
"Start Day", (
void *)&l2_str->sday);
544 readAttr(ds_id,
"Start Millisec", (
void *)&l2_str->smsec);
545 readAttr(ds_id,
"End Year", (
void *)&l2_str->eyear);
546 readAttr(ds_id,
"End Day", (
void *)&l2_str->eday);
547 readAttr(ds_id,
"End Millisec", (
void *)&l2_str->emsec);
548 readAttr(ds_id,
"Orbit Number", (
void *)&l2_str->orbit);
549 readAttr(ds_id,
"Data Type", (
void *)&l2_str->dtype);
554 l2_str->latitude = (
float *)calloc(l2_str->nsamp,
sizeof(
float));
555 l2_str->longitude = (
float *)calloc(l2_str->nsamp,
sizeof(
float));
557 l2_str->lat1 = (
float *)malloc((l2_str->nsamp + 1) *
sizeof(
float));
558 l2_str->lon1 = (
float *)malloc((l2_str->nsamp + 1) *
sizeof(
float));
561 l2_str->lat2 = (
float *)malloc((l2_str->nsamp + 1) *
sizeof(
float));
562 l2_str->lon2 = (
float *)malloc((l2_str->nsamp + 1) *
sizeof(
float));
571 const char *
filename = l2_str->filename;
572 ds_id.
fid = grp_id_geo_lon[fileindex];
575 "--Error-- : could not get longitude dimensions in file %s. See %s in %d. Exiting.\n",
578 if (ds_id_ll[fileindex][0].sid == -1) {
579 printf(
"--Error-- : longitude can't be read in file %s. See %s in %d. Exiting.\n",
filename,
583 ds_id.
fid = grp_id_geo_lat[fileindex];
585 if (ds_id_ll[fileindex][1].sid == -1) {
586 printf(
"--Error-- : latitude can't be read in file %s. See %s in %d. Exiting.\n",
filename,
592 ds_id_ll[fileindex][2] = (
idDS){ds_id.
fid, -1, ds_id.
fftype};
595 ds_id.
fid = grp_id[fileindex][2];
600 l2_str->geointerp = 0;
604 ds_id.
fid = grp_id[fileindex][0];
606 if (ds_id_wave[fileindex].sid != -1) {
607 readDS(ds_id_wave[fileindex],
"wavelength", &zero32,
NULL, &bandsPerPixel, l2_str->wavelength);
612 ds_id.
fid = grp_id[fileindex][0];
614 if (ds_id_wave3d[fileindex].sid != -1) {
615 readDS(ds_id_wave3d[fileindex],
"wavelength_3d", &zero32,
NULL, &wavelength_3d,
616 l2_str->wavelengths_3d);
619 for (
int i = 0;
i < wavelength_3d;
i++)
620 l2_str->wavelengths_3d[
i] = l2_str->wavelength[
i];
626 if (dims[0] != l2_str->nrec || dims[1] != l2_str->nsamp || ds_id_ll[fileindex][0].sid == -1) {
627 l2_str->geointerp = 1;
632 ds_id.
fid = grp_id[fileindex][4];
638 ds_id_geonav[fileindex][4].sid = -1;
641 ds_id = ds_id_file[fileindex];
642 nsta[fileindex] = -1;
643 ninc[fileindex] = -1;
644 readAttr(ds_id_file[fileindex],
"LAC Pixel Start Number", (
void *)&nsta[fileindex]);
645 readAttr(ds_id_file[fileindex],
"LAC Pixel Subsampling", (
void *)&ninc[fileindex]);
647 if (ds_id_geonav[fileindex][0].sid != -1 && ds_id_geonav[fileindex][1].sid != -1 &&
648 ds_id_geonav[fileindex][2].sid != -1 && ds_id_geonav[fileindex][3].sid != -1 &&
649 nsta[fileindex] != -1 && ninc[fileindex] != -1) {
650 l2_str->geointerp = 2;
652 for (
i = 0;
i < 6;
i++)
653 l2_str->geonav[
i] = geonav[
i];
658 status = nc_inq_dimid(ds_id_file[fileindex].fid,
"pixel_control_points", &dim_id);
660 printf(
"-E- %s:%d - openL2 - Could not find the dimension pixel_control_points.\n",
664 status = nc_inq_dimlen(ds_id_file[fileindex].fid, dim_id, &tmpSizet);
666 printf(
"-E- %s:%d - openL2 - Could not read the dimension pixel_control_points\n",
670 n_cntl_pnts = tmpSizet;
672 readAttr(ds_id_file[fileindex],
"Number of Pixel Control Points", (
void *)&n_cntl_pnts);
676 if (prev_n_cntl_pnts != -1 && prev_n_cntl_pnts != n_cntl_pnts) {
677 printf(
"L2 file #:%4d has %d control points.\n", fileindex, prev_n_cntl_pnts);
678 printf(
"L2 file #:%4d has %d control points.\n", fileindex + 1, n_cntl_pnts);
679 printf(
"These must be identical.\n");
682 prev_n_cntl_pnts = n_cntl_pnts;
686 l2_str->lon_cntl = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
687 l2_str->lat_cntl = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
688 l2_str->cntl_pnts = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
689 l2_str->cntl_pnts_cache = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
690 l2_str->spline_arr = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
694 ds_id_ll[fileindex][2].sid =
selectDS(ds_id,
"cntl_pt_cols");
698 int32_t *tmpPtr = (int32_t *)l2_str->cntl_pnts;
699 readDS(ds_id_ll[fileindex][2],
"cntl_pt_cols", &zero32,
NULL, &n_cntl_pnts, tmpPtr);
701 ds_id_ll[fileindex][2].sid = -1;
705 for (
i = 0;
i < n_cntl_pnts;
i++) {
706 l2_str->cntl_pnts_cache[
i] = tmpPtr[
i];
713 for (
i = 0;
i < l2_str->nprod;
i++) {
720 status,
"--Error-- : could not find variable %s. See %s in %d. Exiting.\n", l2_prd,
726 &(prodtype[fileindex][
i]));
733 if (prodtype[fileindex][
i] != NC_FLOAT && prodtype[fileindex][
i] != NC_DOUBLE) {
736 slope[fileindex][
i] = 1.0;
743 slope[fileindex][
i] = 1.0;
746 readAttr(ds_id0,
"_FillValue", (
void *)(&l2_str->bv_scaled[
i]));
750 if (
slope[fileindex][
i] == 0.0)
751 slope[fileindex][
i] = 1.0;
753 if (
findAttr(ds_id0,
"bad_value_unscaled") != -1)
754 readAttr(ds_id0,
"bad_value_unscaled", (
void *)(&l2_str->bv_unscaled[
i]));
756 l2_str->bv_unscaled[
i] = -1e30;
758 if (
findAttr(ds_id0,
"bad_value_scaled") != -1)
759 readAttr(ds_id0,
"bad_value_scaled", (
void *)(&l2_str->bv_scaled[
i]));
761 l2_str->bv_scaled[
i] = -32768;
764 ds_id_prod[fileindex][
i] = (
idDS){ds_id.
fid, sds_id, ds_id.
fftype};
766 int32_t fldDims[8] = {0, 0, 0, 0, 0, 0, 0, 0};
768 if (fldDims[2] == bandsPerPixel)
770 else if (fldDims[2] == wavelength_3d)
771 l2_str->thirdDim[
i] =
774 l2_str->thirdDim[
i] = 1;
776 printf(
"Data Product: \"%s\" not found.\n", l2_prd);
784 if (cache_l2_data ==
NULL) {
785 cache_nprod = l2_str->nprod;
786 cache_l2_data = (cache_str **)malloc(
sizeof(cache_str *) * cache_nprod);
787 for (
i = 0;
i < cache_nprod;
i++) {
788 cache_l2_data[
i] = (cache_str *)malloc(
sizeof(cache_str));
789 cache_l2_data[
i]->bscan = -1;
790 cache_l2_data[
i]->escan = -1;
791 cache_l2_data[
i]->dataSize = 0;
792 cache_l2_data[
i]->data =
NULL;
794 }
else if (cache_nprod < l2_str->nprod) {
797 for (
i = 0;
i < cache_nprod;
i++)
798 free(cache_l2_data[
i]);
801 cache_nprod = l2_str->nprod;
802 cache_l2_data = (cache_str **)malloc(
sizeof(cache_str *) * cache_nprod);
803 for (
i = 0;
i < cache_nprod;
i++) {
804 cache_l2_data[
i] = (cache_str *)malloc(
sizeof(cache_str));
805 cache_l2_data[
i]->bscan = -1;
806 cache_l2_data[
i]->escan = -1;
807 cache_l2_data[
i]->dataSize = 0;
808 cache_l2_data[
i]->data =
NULL;
814 l2_str->l2_data = (
float **)malloc(l2_str->nprod *
sizeof(
float *));
815 for (
i = 0;
i < l2_str->nprod;
i++) {
816 l2_str->l2_data[
i] = (
float *)malloc(l2_str->nsamp * l2_str->thirdDim[
i] *
sizeof(
float));
817 if (l2_str->thirdDim[
i] > maxThirdDim)
818 maxThirdDim = l2_str->thirdDim[
i];
827 if ((ds_id_pixnum[fileindex].sid =
selectDS(ds_id,
"pixnum")) != -1) {
828 l2_str->pixnum = (int32_t *)calloc(l2_str->nsamp,
sizeof(int32_t));
830 l2_str->pixnum =
NULL;
832 ds_id_pixnum[fileindex].
fid = ds_id.
fid;
838 ds_id.
fid = grp_id[fileindex][2];
839 if ((ds_id.
sid =
selectDS(ds_id,
"mside")) != -1) {
840 l2_str->mside = (
byte *)calloc(l2_str->nrec,
sizeof(
byte));
842 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec, (
void *)l2_str->mside);
849 SDgetinfo(ds_id.
sid,
NULL, &
rank, dimsizes, &ntype, &num_attrs);
850 if (ntype == DFNT_INT8) {
851 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec, (
void *)l2_str->mside);
854 int32_t junk[l2_str->nrec];
856 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec, (
void *)junk);
857 for (
i = 0;
i < l2_str->nrec;
i++)
858 l2_str->mside[
i] = (
byte)junk[
i];
863 l2_str->mside =
NULL;
866 if ((ds_id.
sid =
selectDS(ds_id,
"detnum")) != -1) {
867 l2_str->detnum = (
byte *)calloc(l2_str->nrec,
sizeof(
byte));
869 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec, (
void *)l2_str->detnum);
876 SDgetinfo(ds_id.
sid,
NULL, &
rank, dimsizes, &ntype, &num_attrs);
877 if (ntype == DFNT_INT8) {
878 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec, (
void *)l2_str->detnum);
881 int32_t junk[l2_str->nrec];
883 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec, (
void *)junk);
884 for (
i = 0;
i < l2_str->nrec;
i++)
885 l2_str->detnum[
i] = (
byte)junk[
i];
890 l2_str->detnum =
NULL;
896 ds_id.
fid = grp_id[fileindex][1];
897 if (
selectDS(ds_id,
"ntilts") != -1) {
899 readDS(ds_id,
"ntilts", tilt_start,
NULL, &one, (
void *)&l2_str->ntilts);
901 readDS(ds_id,
"tilt_flags", tilt_start,
NULL, tilt_edges, (
void *)l2_str->tilt_flags);
903 readDS(ds_id,
"tilt_ranges", tilt_start,
NULL, tilt_edges, (
void *)t_ranges);
905 for (
i = 0;
i < l2_str->ntilts;
i++) {
906 l2_str->tilt_ranges[0][
i] = t_ranges[
i * 2];
907 l2_str->tilt_ranges[1][
i] = t_ranges[
i * 2 + 1];
917 "l2_flags", ds_id_file[fileindex].fid, &varid, &ds_id.
fid),
918 status,
"--Error-- : could not find variable %s. See %s in %d. Exiting.\n",
919 "l2_flags", __FILE__, __LINE__);
921 idDS temp_ds_id = ds_id_l2_flags[fileindex];
922 temp_ds_id.
fid *= -1;
924 if (ds_id_l2_flags[fileindex].sid != -1) {
925 l2_str->l2_flags = (int32_t *)calloc(l2_str->nsamp,
sizeof(int32_t));
926 l2_str->flagnames =
readAttrStr(temp_ds_id,
"flag_meanings");
929 nc_inq_att(ds_id_l2_flags[fileindex].fid, ds_id_l2_flags[fileindex].sid,
"flag_masks", &
dtype,
931 l2_str->l2_bits = calloc(l2_bits_size,
sizeof(int32_t));
932 status = nc_get_att(ds_id_l2_flags[fileindex].fid, ds_id_l2_flags[fileindex].sid,
933 "flag_masks", l2_str->l2_bits);
935 printf(
"-E- Could not read \"%s\" in L2 file.\n",
"flag_masks");
938 if (!l2_str->flagnames) {
939 printf(
"-E- %s:%d - openL2 - could not find flag_meanings.\n", __FILE__, __LINE__);
942 for (
i = 0;
i < strlen(l2_str->flagnames);
i++) {
943 if (l2_str->flagnames[
i] ==
' ')
944 l2_str->flagnames[
i] =
',';
947 l2_str->l2_flags = 0x0;
953 if (ds_id_l2_flags[fileindex].sid != -1) {
954 l2_str->l2_flags = (int32_t *)calloc(l2_str->nsamp,
sizeof(int32_t));
960 idDS temp_ds_id = ds_id_l2_flags[fileindex];
961 temp_ds_id.
fid *= -1;
963 sprintf(buffer,
"f%s_name", numstr[n_l2flags]);
964 if (
findAttr(temp_ds_id, buffer) != -1) {
966 listlen += strlen(tmpStr) + 1;
972 l2_str->flagnames = (
char *)calloc(listlen,
sizeof(
char));
973 for (
i = 0;
i < n_l2flags;
i++) {
974 sprintf(buffer,
"f%s_name", numstr[
i]);
976 strcat(l2_str->flagnames, tmpStr);
978 if (
i < n_l2flags - 1)
979 strcat(l2_str->flagnames,
",");
982 l2_str->l2_flags = 0x0;
988 if (
checkDS(ds_id_file[fileindex],
"eng_qual") != -1) {
989 ds_id_eng_qual[fileindex].
sid =
selectDS(ds_id,
"eng_qual");
990 ds_id_eng_qual[fileindex].
fid = ds_id.
fid;
993 ds_id_eng_qual[fileindex].
sid = -1;
998 if (
checkDS(ds_id_file[fileindex],
"s_flags") != -1) {
999 ds_id_s_flags[fileindex].
sid =
selectDS(ds_id,
"s_flags");
1000 ds_id_s_flags[fileindex].
fid = ds_id.
fid;
1003 ds_id_s_flags[fileindex].
sid = -1;
1008 if (
checkDS(ds_id_file[fileindex],
"nflag") != -1) {
1009 ds_id_nflag[fileindex].
sid =
selectDS(ds_id,
"nflag");
1010 ds_id_nflag[fileindex].
fid = ds_id.
fid;
1013 ds_id_nflag[fileindex].
sid = -1;
1019 ds_id.
fid = grp_id[fileindex][2];
1020 if (ds_id_date[fileindex][0].sid != -1) {
1021 l2_str->year_cache = (int32_t *)malloc(
sizeof(int32_t) * l2_str->nrec);
1022 readDS(ds_id_date[fileindex][0],
"year", &zero32,
NULL, &(l2_str->nrec), l2_str->year_cache);
1026 if (ds_id_date[fileindex][1].sid != -1) {
1027 l2_str->day_cache = (int32_t *)malloc(
sizeof(int32_t) * l2_str->nrec);
1028 readDS(ds_id_date[fileindex][1],
"day", &zero32,
NULL, &(l2_str->nrec), l2_str->day_cache);
1032 if (ds_id_date[fileindex][2].sid != -1) {
1033 l2_str->msec_cache = (int32_t *)malloc(
sizeof(int32_t) * l2_str->nrec);
1034 readDS(ds_id_date[fileindex][2],
"msec", &zero32,
NULL, &(l2_str->nrec), l2_str->msec_cache);
1038 ds_id.
fid = scantime_grp[fileindex];
1039 if (scantime_var[fileindex] != -1) {
1040 l2_str->scantime_cache = (
double *)malloc(
sizeof(
double) * l2_str->nrec);
1042 readDS(scan_ds,
"scantime", &zero32,
NULL, &(l2_str->nrec), l2_str->scantime_cache);
1056 if (Hishdf(l2_str->filename) == 1) {
1063 ds_id_file[fileindex] = ds_id;
1066 nc_inq_ncid(ds_id.
fid,
"sensor_band_parameters", &grp_id[fileindex][0]);
1067 nc_inq_ncid(ds_id.
fid,
"sensor_tilt", &grp_id[fileindex][1]);
1068 nc_inq_ncid(ds_id.
fid,
"scan_line_attributes", &grp_id[fileindex][2]);
1069 nc_inq_ncid(ds_id.
fid,
"geophysical_data", &grp_id[fileindex][3]);
1070 nc_inq_ncid(ds_id.
fid,
"navigation_data", &grp_id[fileindex][4]);
1071 nc_inq_ncid(ds_id.
fid,
"processing_control", &grp_id[fileindex][5]);
1078 const char *
filename = l2_str->filename;
1080 &grp_id_geo_lat[fileindex]),
1082 "--Error--: unable to find latitude after reopening %s. See %s in %d. Exiting...",
1085 &grp_id_geo_lon[fileindex]),
1087 "--Error--: unable to find longitude after reopening %s. See %s in %d. Exiting...",
1089 ds_id.
fid = grp_id_geo_lon[fileindex];
1091 if (ds_id_ll[fileindex][0].sid == -1) {
1092 printf(
"--Error-- : longitude can't be read after reopening %s. See %s in %d. Exiting...",
1096 ds_id.
fid = grp_id_geo_lat[fileindex];
1098 if (ds_id_ll[fileindex][1].sid == -1) {
1099 printf(
"--Error-- : latitude can't be read after reopening %s. See %s in %d. Exiting...",
1105 if (l2_str->geointerp == 2) {
1113 for (
i = 0;
i < l2_str->nprod;
i++) {
1118 &varid, &ds_id.
fid),
1120 "--Error-- : could not find variable after reopening %s. See %s in %d. Exiting.\n",
1121 l2_prd, __FILE__, __LINE__);
1127 &varid, &ds_id.
fid),
1129 "--Error-- : could not find variable after reopening %s. See %s in %d. Exiting.\n",
1130 "l2_flags", __FILE__, __LINE__);
1150 unsigned char *scan_in_rowgroup, cache_str *
cache, int32_t
dtype) {
1167 recSize *=
edges[1];
1168 if (
edges[2] != 1) {
1169 recSize *=
edges[2];
1170 edges2[2] =
edges[2];
1180 bscan = escan =
start[0];
1181 while (scan_in_rowgroup[escan] != 0)
1184 nscans = escan - bscan + 1;
1185 size = nscans * recSize;
1192 cache->bscan = bscan;
1193 cache->escan = escan;
1195 start2[1] =
start[1];
1196 start2[2] =
start[2];
1198 edges2[1] =
edges[1];
1199 edges2[2] =
edges[2];
1204 memcpy(
data, ptr, recSize);
1211 if (*deltaLon > 90) {
1212 if (*deltaLon > 270)
1216 }
else if (*deltaLon < -90) {
1217 if (*deltaLon < -270)
1237 int32_t numPoints) {
1239 float dLat = (lat1[0] - lat0[0] + lat0[1] - lat0[0]) / 2.0;
1240 float dLon = (lon1[0] - lon0[0] + lon0[1] - lon0[0]) / 2.0;
1244 latOut[0] = lat1[0] - dLat;
1245 lonOut[0] = lon1[0] - dLon;
1248 for (
int i = 0;
i < numPoints - 1;
i++) {
1249 dLat = (lat1[
i] - lat0[
i] + lat0[
i + 1] - lat0[
i]) / 2.0;
1250 dLon = (lon1[
i] - lon0[
i] + lon0[
i + 1] - lon0[
i]) / 2.0;
1253 latOut[
i + 1] = lat0[
i] + dLat;
1254 lonOut[
i + 1] = lon0[
i] + dLon;
1258 latOut[numPoints] = lat0[numPoints - 1] + dLat;
1259 lonOut[numPoints] = lon0[numPoints - 1] + dLon;
1275 int32_t numPoints) {
1277 float dLat = (lat1[1] - lat1[0] + lat0[0] - lat1[0]) / 2.0;
1278 float dLon = (lon1[1] - lon1[0] + lon0[0] - lon1[0]) / 2.0;
1282 latOut[0] = lat1[0] - dLat;
1283 lonOut[0] = lon1[0] - dLon;
1286 for (
int i = 0;
i < numPoints - 1;
i++) {
1287 dLat = (lat1[
i] - lat0[
i] + lat0[
i + 1] - lat0[
i]) / 2.0;
1288 dLon = (lon1[
i] - lon0[
i] + lon0[
i + 1] - lon0[
i]) / 2.0;
1291 latOut[
i + 1] = lat1[
i] + dLat;
1292 lonOut[
i + 1] = lon1[
i] + dLon;
1296 latOut[numPoints] = lat1[numPoints - 1] + dLat;
1297 lonOut[numPoints] = lon1[numPoints - 1] + dLon;
1312 int32_t numPoints) {
1315 int i_center = numPoints/2;
1316 float scale_factor = 4;
1317 if(
fabs(lat0[i_center]) > 73)
1319 if(fabsf(lat0[i_center] - lat1[i_center]) > latOut[i_center] * scale_factor && latOut[i_center]!=0)
1323 for (
int i = 0;
i < numPoints - 1;
i++) {
1324 latOut[
i] = fabsf(lat0[
i] - lat1[
i]) / 2.0;
1325 lonOut[
i] = fabsf(lon0[
i] - lon0[
i + 1]) / 2.0;
1326 if (lonOut[
i] > 90) {
1327 lonOut[
i] = 180.0 - lonOut[
i];
1332 latOut[numPoints - 1] = latOut[numPoints - 2];
1333 lonOut[numPoints - 1] = lonOut[numPoints - 2];
1337 unsigned char *scan_in_rowgroup) {
1339 int32_t
start[3] = {0, 0, 0};
1340 int32_t
edges[3] = {1, 1, 1};
1348 int32_t flag_edges[2] = {1, 4};
1349 int32_t nflag_edges[2] = {1, 8};
1356 edges[1] = l2_str->nsamp;
1364 if (ds_id_l2_flags[
ifile].sid != -1) {
1365 if (scan_in_rowgroup ==
NULL) {
1370 (
void *)l2_str->l2_flags, scan_in_rowgroup, &cache_l2_flags,
1377 int16_t *ptr16 = (int16_t *)l2_str->l2_flags;
1378 for (
i = l2_str->nsamp - 1;
i >= 0;
i--)
1379 l2_str->l2_flags[
i] = ptr16[
i];
1386 if (ds_id_eng_qual[
ifile].sid != -1) {
1387 if (scan_in_rowgroup ==
NULL) {
1392 (
void *)l2_str->eng_qual, scan_in_rowgroup, &cache_eng_qual,
1399 if (ds_id_s_flags[
ifile].sid != -1) {
1400 if (scan_in_rowgroup ==
NULL) {
1405 (
void *)l2_str->s_flags, scan_in_rowgroup, &cache_s_flags,
1412 if (ds_id_nflag[
ifile].sid != -1) {
1413 if (scan_in_rowgroup ==
NULL) {
1417 (
void *)l2_str->nflag, scan_in_rowgroup, &cache_nflag,
1424 if (ds_id_pixnum[
ifile].sid != -1) {
1425 if (scan_in_rowgroup ==
NULL) {
1429 (
void *)l2_str->pixnum, scan_in_rowgroup, &cache_pixnum,
1436 if (ds_id_date[
ifile][0].sid != -1) {
1437 l2_str->year = l2_str->year_cache[
recnum];
1439 if (ds_id_date[
ifile][1].sid != -1) {
1440 l2_str->day = l2_str->day_cache[
recnum];
1442 if (ds_id_date[
ifile][2].sid != -1) {
1443 l2_str->msec = l2_str->msec_cache[
recnum];
1445 if (scantime_var[
ifile] != -1) {
1446 double scantime = l2_str->scantime_cache[
recnum];
1450 l2_str->msec = (int32_t)(sec * 1000.0);
1452 l2_str->year = year;
1459 for (
i = 0;
i < l2_str->nprod;
i++) {
1460 if ((iprod != -1) && (
i != iprod))
1470 edges[2] = l2_str->thirdDim[
i];
1475 if (scan_in_rowgroup ==
NULL) {
1479 scan_in_rowgroup, cache_l2_data[
i], prodtype[
ifile][
i]);
1483 printf(
"Read Error: %d (%s) %d\n",
ifile, l2_str->filename,
i);
1488 ptype = prodtype[
ifile][
i];
1490 switch (prodtype[
ifile][
i]) {
1508 printf(
"-E- %s:%d - readL2 - unknown data type.\n", __FILE__, __LINE__);
1517 uint8 *
tmp = (uint8 *)databuf;
1518 float *
result = l2_str->l2_data[
i];
1519 for (ipix = 0; ipix < l2_str->nsamp * l2_str->thirdDim[
i];
1521 if (*
tmp == (uint8)l2_str->bv_scaled[
i]) {
1532 int8 *
tmp = (int8 *)databuf;
1533 float *
result = l2_str->l2_data[
i];
1534 for (ipix = 0; ipix < l2_str->nsamp * l2_str->thirdDim[
i]; ipix++) {
1535 if (*
tmp == (int8)l2_str->bv_scaled[
i]) {
1546 int16_t *
tmp = (int16_t *)databuf;
1547 float *
result = l2_str->l2_data[
i];
1548 for (ipix = 0; ipix < l2_str->nsamp * l2_str->thirdDim[
i]; ipix++) {
1549 if (*
tmp == l2_str->bv_scaled[
i]) {
1560 int32_t *
tmp = (int32_t *)databuf;
1561 float *
result = l2_str->l2_data[
i];
1562 for (ipix = 0; ipix < l2_str->nsamp * l2_str->thirdDim[
i]; ipix++) {
1563 if (*
tmp == l2_str->bv_scaled[
i]) {
1574 float *
tmp = (
float *)databuf;
1575 float *
result = l2_str->l2_data[
i];
1576 for (ipix = 0; ipix < l2_str->nsamp * l2_str->thirdDim[
i]; ipix++) {
1591 if (pixelAreaInfo.
nsamp != l2_str->nsamp) {
1592 pixelAreaInfo.
nsamp = l2_str->nsamp;
1597 pixelAreaInfo.
lastLat = (
float *)malloc(l2_str->nsamp *
sizeof(
float));
1598 pixelAreaInfo.
lastLon = (
float *)malloc(l2_str->nsamp *
sizeof(
float));
1602 if (pixelAreaInfo.
lastLine == -1) {
1605 scan_in_rowgroup[pixelAreaInfo.
lastLine] = 1;
1616 tmpFloat = pixelAreaInfo.
lastLat;
1617 pixelAreaInfo.
lastLat = l2_str->latitude;
1618 l2_str->latitude = tmpFloat;
1619 tmpFloat = pixelAreaInfo.
lastLon;
1620 pixelAreaInfo.
lastLon = l2_str->longitude;
1621 l2_str->longitude = tmpFloat;
1634 for (
i = 0;
i < l2_str->nsamp;
i++) {
1635 if ((l2_str->longitude[
i] > 180 || l2_str->longitude[
i] < -180) &&
1636 ((l2_str->l2_flags[
i] & 33554432) == 0)) {
1637 printf(
"Scheme: %d\n", l2_str->geointerp);
1638 printf(
"Pixel Longitude %d out of range (%f) for scan %d in %s.\n",
i, l2_str->longitude[
i],
1639 recnum, l2_str->filename);
1643 if ((l2_str->latitude[
i] > 180 || l2_str->latitude[
i] < -180) &&
1644 ((l2_str->l2_flags[
i] & 33554432) == 0)) {
1645 printf(
"Scheme: %d\n", l2_str->geointerp);
1646 printf(
"Pixel Latitude %d out of range (%f) for scan %d in %s.\n",
i, l2_str->latitude[
i],
1647 recnum, l2_str->filename);
1655 if (pixelAreaInfo.
lastLine != -1) {
1662 if (l2_str->detnum && (l2_str->detnum[pixelAreaInfo.
lastLine] != l2_str->detnum[
recnum]) &&
1667 l2_str->lat2Valid = 0;
1674 if (l2_str->detnum &&
1675 (l2_str->detnum[pixelAreaInfo.
lastLine] != l2_str->detnum[
recnum]) &&
1680 if (pixelAreaInfo.
lastLine != -1) {
1682 tmpFloat = pixelAreaInfo.
lastLat;
1683 pixelAreaInfo.
lastLat = l2_str->latitude;
1684 l2_str->latitude = tmpFloat;
1685 tmpFloat = pixelAreaInfo.
lastLon;
1686 pixelAreaInfo.
lastLon = l2_str->longitude;
1687 l2_str->longitude = tmpFloat;
1693 edges[1] = l2_str->nsamp;
1697 tmpFloat = pixelAreaInfo.
lastLat;
1698 pixelAreaInfo.
lastLat = l2_str->latitude;
1699 l2_str->latitude = tmpFloat;
1700 tmpFloat = pixelAreaInfo.
lastLon;
1701 pixelAreaInfo.
lastLon = l2_str->longitude;
1702 l2_str->longitude = tmpFloat;
1711 if (pixelAreaInfo.
lastLine == -1) {
1713 if (l2_str->detnum && (l2_str->detnum[
recnum + 1] != l2_str->detnum[
recnum]) &&
1716 "ERROR - %s:%d - the detector number of the next line is not from the next detector.\n",
1717 __FILE__, __LINE__);
1718 printf(
" Can not do area weighting on file=%s, line=%d\n", l2_str->filename,
recnum);
1723 if (
recnum + 1 >= l2_str->nrec) {
1724 printf(
"ERROR - %s:%d - the previous line was invalid and there are no more lines to read.\n",
1725 __FILE__, __LINE__);
1726 printf(
" Can not do area weighting on file=%s, line=%d\n", l2_str->filename,
recnum);
1731 tmpFloat = pixelAreaInfo.
lastLat;
1732 pixelAreaInfo.
lastLat = l2_str->latitude;
1733 l2_str->latitude = tmpFloat;
1734 tmpFloat = pixelAreaInfo.
lastLon;
1735 pixelAreaInfo.
lastLon = l2_str->longitude;
1736 l2_str->longitude = tmpFloat;
1742 edges[1] = l2_str->nsamp;
1746 tmpFloat = pixelAreaInfo.
lastLat;
1747 pixelAreaInfo.
lastLat = l2_str->latitude;
1748 l2_str->latitude = tmpFloat;
1749 tmpFloat = pixelAreaInfo.
lastLon;
1750 pixelAreaInfo.
lastLon = l2_str->longitude;
1751 l2_str->longitude = tmpFloat;
1755 l2_str->longitude, l2_str->lat1, l2_str->lon1, l2_str->nsamp);
1757 pixelAreaInfo.
lastLon, l2_str->lat2, l2_str->lon2, l2_str->nsamp);
1760 pixelAreaInfo.
lastLon, l2_str->lat1, l2_str->lon1, l2_str->nsamp);
1765 if (l2_str->lat2Valid) {
1767 tmpFloat = l2_str->lat1;
1768 l2_str->lat1 = l2_str->lat2;
1769 l2_str->lat2 = tmpFloat;
1770 tmpFloat = l2_str->lon1;
1771 l2_str->lon1 = l2_str->lon2;
1772 l2_str->lon2 = tmpFloat;
1775 l2_str->longitude, l2_str->lat1, l2_str->lon1, l2_str->nsamp);
1778 l2_str->longitude, l2_str->lat2, l2_str->lon2, l2_str->nsamp);
1781 pixelAreaInfo.
lastLon, l2_str->lat1, l2_str->lon1, l2_str->nsamp);
1821 l2_str->lat2Valid = 1;
1829 unsigned char *scan_in_rowgroup) {
1831 int32_t geo_edge[6] = {3, 3, 6, 3, 3, 3};
1834 int32_t n_cntl_pnts_removed;
1837 float *cntl_pnt_buf1;
1838 float *cntl_pnt_buf2;
1839 float lon_lat_lim = 0.1;
1841 char *geonav_name[6] = {
"orb_vec",
"sen_mat",
"scan_ell",
"sun_ref",
"l_vert",
"att_ang"};
1843 switch (l2_str->geointerp) {
1848 if (scan_in_rowgroup ==
NULL) {
1853 (
void *)l2_str->longitude, scan_in_rowgroup, &cache_longitude,
DFNT_FLOAT32);
1863 edges2[0] =
edges[0];
1864 edges2[1] = n_cntl_pnts;
1865 if (scan_in_rowgroup ==
NULL) {
1870 (
void *)l2_str->lon_cntl, scan_in_rowgroup, &cache_longitude,
DFNT_FLOAT32);
1877 cntl_pnt_buf1 = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
1878 cntl_pnt_buf2 = (
float *)calloc(n_cntl_pnts,
sizeof(
float));
1884 n_cntl_pnts_removed = 0;
1885 for (
i = 0;
i < n_cntl_pnts;
i++) {
1886 if (l2_str->lat_cntl[
i] < -91 || l2_str->lat_cntl[
i] > +91) {
1887 n_cntl_pnts_removed++;
1889 cntl_pnt_buf1[
i - n_cntl_pnts_removed] = l2_str->lat_cntl[
i];
1890 cntl_pnt_buf2[
i - n_cntl_pnts_removed] = l2_str->cntl_pnts_cache[
i];
1894 if (((
float)n_cntl_pnts_removed) / n_cntl_pnts > lon_lat_lim) {
1895 fprintf(
stderr,
"%s (Latitude failure)\n", l2_str->filename);
1896 fprintf(
stderr,
"More that 10%% failure.\n");
1901 n_cntl_pnts -= n_cntl_pnts_removed;
1903 for (
i = 0;
i < n_cntl_pnts;
i++) {
1904 l2_str->lat_cntl[
i] = cntl_pnt_buf1[
i];
1905 l2_str->cntl_pnts[
i] = cntl_pnt_buf2[
i];
1908 spline(l2_str->cntl_pnts, l2_str->lat_cntl, n_cntl_pnts, 1e30, 1e30, l2_str->spline_arr);
1909 for (
i = 0;
i < l2_str->nsamp;
i++) {
1910 splint(l2_str->cntl_pnts, l2_str->lat_cntl, l2_str->spline_arr, n_cntl_pnts,
i + 1.0,
1911 &l2_str->latitude[
i]);
1915 n_cntl_pnts += n_cntl_pnts_removed;
1921 n_cntl_pnts_removed = 0;
1922 for (
i = 0;
i < n_cntl_pnts;
i++) {
1923 if (l2_str->lon_cntl[
i] < -181 || l2_str->lon_cntl[
i] > +181) {
1924 n_cntl_pnts_removed++;
1926 cntl_pnt_buf1[
i - n_cntl_pnts_removed] = l2_str->lon_cntl[
i];
1927 cntl_pnt_buf2[
i - n_cntl_pnts_removed] = l2_str->cntl_pnts_cache[
i];
1931 if (((
float)n_cntl_pnts_removed) / n_cntl_pnts > lon_lat_lim) {
1932 fprintf(
stderr,
"%s (Longitude failure)\n", l2_str->filename);
1933 fprintf(
stderr,
"More that 10%% failure.\n");
1937 n_cntl_pnts -= n_cntl_pnts_removed;
1939 for (
i = 0;
i < n_cntl_pnts;
i++) {
1940 l2_str->lon_cntl[
i] = cntl_pnt_buf1[
i];
1941 l2_str->cntl_pnts[
i] = cntl_pnt_buf2[
i];
1946 for (
i = 1;
i < n_cntl_pnts;
i++) {
1947 delta = l2_str->lon_cntl[
i] - l2_str->lon_cntl[
i - 1];
1949 l2_str->lon_cntl[
i] += 360;
1950 else if (
delta > 180)
1951 l2_str->lon_cntl[
i] -= 360;
1954 spline(l2_str->cntl_pnts, l2_str->lon_cntl, n_cntl_pnts, 1e30, 1e30, l2_str->spline_arr);
1956 for (
i = 0;
i < l2_str->nsamp;
i++) {
1957 splint(l2_str->cntl_pnts, l2_str->lon_cntl, l2_str->spline_arr, n_cntl_pnts,
i + 1.0,
1958 &l2_str->longitude[
i]);
1962 while (l2_str->longitude[
i] > 180)
1963 l2_str->longitude[
i] -= 360;
1964 while (l2_str->longitude[
i] < -180)
1965 l2_str->longitude[
i] += 360;
1968 n_cntl_pnts += n_cntl_pnts_removed;
1970 free(cntl_pnt_buf1);
1971 free(cntl_pnt_buf2);
1976 edges2[0] =
edges[0];
1978 for (
i = 0;
i < 4;
i++) {
1979 edges2[1] = geo_edge[
i];
1980 if (ds_id_geonav[
ifile][
i].sid != -1) {
1985 geonav_(geonav[0], geonav[1], geonav[2], geonav[3], (int32_t *)&nsta[
ifile],
1986 (int32_t *)&ninc[
ifile], (int32_t *)&l2_str->nsamp, l2_str->latitude, l2_str->longitude,
1987 (
float *)databuf, (
float *)databuf, (
float *)databuf, (
float *)databuf);
1999 for (
i = 0;
i < l2_str->nprod;
i++) {
2000 if (ds_id_prod[
ifile][
i].sid != -1) {
2003 printf(
"Error ending access to product sds: %d for file: %d\n",
i,
ifile);
2009 for (
i = 0;
i < 3;
i++) {
2010 if (ds_id_ll[
ifile][
i].sid != -1) {
2014 printf(
"Error ending access to ll sds: %d for file: %d\n",
i,
ifile);
2020 if (l2_str->geointerp == 2) {
2021 for (
i = 0;
i < 6;
i++) {
2023 if (ds_id_geonav[
ifile][
i].sid != -1)
2026 printf(
"Error ending access to geonav sds: %d for file: %d\n",
i,
ifile);
2033 if (ds_id_l2_flags[
ifile].sid != -1) {
2036 printf(
"Error ending access to l2_flags sds for file: %d\n",
ifile);
2042 if (ds_id_eng_qual[
ifile].sid != -1) {
2045 printf(
"Error ending access to eng_qual sds for file: %d\n",
ifile);
2050 if (ds_id_s_flags[
ifile].sid != -1) {
2053 printf(
"Error ending access to s_flags sds for file: %d\n",
ifile);
2058 if (ds_id_nflag[
ifile].sid != -1) {
2061 printf(
"Error ending access to n_flag sds for file: %d\n",
ifile);
2066 if (ds_id_pixnum[
ifile].sid != -1) {
2069 printf(
"Error ending access to pixnum sds for file: %d\n",
ifile);
2076 printf(
"Error ending access to file: %d\n",
ifile);
2086 if (l2_str ==
NULL) {
2088 if (prodlist[
i] !=
NULL)
2092 if (l2_str->geointerp == 1) {
2093 free(l2_str->lon_cntl);
2094 free(l2_str->lat_cntl);
2095 free(l2_str->spline_arr);
2096 free(l2_str->cntl_pnts);
2099 for (
i = 0;
i < l2_str->nprod;
i++) {
2100 free(l2_str->l2_data[
i]);
2102 free(l2_str->l2_data);
2103 free(l2_str->latitude);
2104 free(l2_str->longitude);
2106 if (l2_str->l2_flags)
2107 free(l2_str->l2_flags);
2108 if (l2_str->flagnames)
2109 free(l2_str->flagnames);
2110 if (l2_str->l2_bits)
2111 free(l2_str->l2_bits);
2113 free(l2_str->pixnum);
2115 free(l2_str->mside);
2117 free(l2_str->detnum);
2118 if (l2_str->year_cache)
2119 free(l2_str->year_cache);
2120 if (l2_str->day_cache)
2121 free(l2_str->day_cache);
2122 if (l2_str->msec_cache)
2123 free(l2_str->msec_cache);
2124 if (l2_str->scantime_cache)
2125 free(l2_str->scantime_cache);
2143 for (
i = 0;
i < l2_str->nprod;
i++) {
2144 if (strcmp(l2_str->prodname[
i], prodname) == 0)
2175 ds_id = ds_id_file[
ifile];
2177 meta_l2->title =
NULL;
2178 meta_l2->infiles =
NULL;
2179 meta_l2->sensor_name =
NULL;
2180 meta_l2->data_center =
NULL;
2181 meta_l2->ctime =
NULL;
2182 meta_l2->ntime =
NULL;
2183 meta_l2->snode =
NULL;
2184 meta_l2->enode =
NULL;
2185 meta_l2->mission =
NULL;
2186 meta_l2->mission_char =
NULL;
2187 meta_l2->sensor =
NULL;
2188 meta_l2->sensor_char =
NULL;
2233 printf(
"Error - Could not find global attribute \"%s\" in file: %d\n", titleStr,
ifile);
2240 if (
findAttr(ds_id, infilesStr) != -1) {
2241 meta_l2->infiles =
readAttrStr(ds_id, infilesStr);
2243 if (
findAttr(ds_id,
"source") != -1) {
2248 ds_id = ds_id_file[
ifile];
2250 if (
findAttr(ds_id, dcenterStr) != -1) {
2251 meta_l2->data_center =
readAttrStr(ds_id, dcenterStr);
2260 if (
findAttr(ds_id, ntimeStr) != -1) {
2264 if (
findAttr(ds_id, snodeStr) != -1) {
2268 if (
findAttr(ds_id, enodeStr) != -1) {
2273 if (
findAttr(ds_id, sennmeStr) != -1) {
2274 meta_l2->sensor_name =
readAttrStr(ds_id, sennmeStr);
2277 if (
findAttr(ds_id, missionStr) != -1) {
2278 meta_l2->mission =
readAttrStr(ds_id, missionStr);
2283 meta_l2->sensor =
NULL;
2287 if (
findAttr(ds_id, sennmeStr) != -1) {
2291 if (
findAttr(ds_id, missionStr) != -1) {
2292 meta_l2->mission =
readAttrStr(ds_id, missionStr);
2306 readAttr(ds_id, orbnumStr, (
void *)&meta_l2->orbnum);
2307 readAttr(ds_id, nlatStr, (
void *)&meta_l2->northlat);
2308 readAttr(ds_id, slatStr, (
void *)&meta_l2->southlat);
2309 readAttr(ds_id, wlonStr, (
void *)&meta_l2->westlon);
2310 readAttr(ds_id, elonStr, (
void *)&meta_l2->eastlon);
2311 readAttr(ds_id, stclatStr, (
void *)&meta_l2->startclat);
2312 readAttr(ds_id, stclonStr, (
void *)&meta_l2->startclon);
2313 readAttr(ds_id, endclatStr, (
void *)&meta_l2->endclat);
2314 readAttr(ds_id, endclonStr, (
void *)&meta_l2->endclon);
2315 readAttr(ds_id, nodelStr, (
void *)&meta_l2->nodel);
2330 FREE(meta_l2->title);
2331 FREE(meta_l2->infiles);
2332 FREE(meta_l2->sensor_name);
2333 FREE(meta_l2->data_center);
2334 FREE(meta_l2->ctime);
2335 FREE(meta_l2->ntime);
2336 FREE(meta_l2->snode);
2337 FREE(meta_l2->enode);
2338 FREE(meta_l2->mission);
2339 FREE(meta_l2->mission_char);
2340 FREE(meta_l2->sensor);
2341 FREE(meta_l2->sensor_char);
2354 char_ptr = strchr(l3b_prodname,
'/');
2355 if (char_ptr !=
NULL)
2358 memset(bufnum, 0, 128);
2359 memset(bufden, 0, 128);
2360 for (
i = 0;
i < l2_str[
ifile].nprod;
i++) {
2361 if (strcmp(l3b_prodname, l2_str[
ifile].prodname[
i]) == 0) {
2368 strcpy(bufnum,
"undefined");
2373 if (char_ptr !=
NULL) {
2374 for (
i = 0;
i < l2_str[
ifile].nprod;
i++) {
2375 if (strcmp(char_ptr + 1, l2_str[
ifile].prodname[
i]) == 0) {
2377 ds_id_prod[
ifile][
i].fftype};
2383 strcpy(bufden,
"undefined");
2388 if (strcmp(bufnum, bufden) == 0) {
2389 if (strcmp(bufnum,
"undefined") == 0)
2393 }
else if (strcmp(bufnum,
"dimensionless") == 0) {
2395 strcat(
units, bufden);
2396 }
else if (strcmp(bufden,
"dimensionless") == 0) {
2400 strcat(
units,
" / ");
2401 strcat(
units, bufden);