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"
125 static int32_t n_files_open = 0;
147 static idDS *ds_id_l2_flags;
148 static idDS *ds_id_eng_qual;
149 static idDS *ds_id_s_flags;
150 static idDS *ds_id_nflag;
151 static idDS *ds_id_pixnum;
152 static idDS *ds_id_file;
153 static idDS *ds_id_wave;
155 static int32_t *nsta;
156 static int32_t *ninc;
158 static int databufSize = 0;
159 static unsigned char *databuf =
NULL;
160 static char **prodlist;
162 static int32_t n_cntl_pnts;
163 static int32_t prev_n_cntl_pnts = -1;
165 static float geonav[6][9];
167 static int32_t one = 1;
168 static int32_t zero32 = 0;
169 static int32_t l2_flags_type;
171 static int32_t bandsPerPixel = 1;
173 static cache_str cache_l2_flags;
174 static cache_str cache_eng_qual;
175 static cache_str cache_s_flags;
176 static cache_str cache_nflag;
177 static cache_str cache_pixnum;
178 static cache_str cache_longitude;
179 static cache_str cache_latitude;
180 static int32_t cache_nprod;
181 static cache_str **cache_l2_data;
197 pixelAreaInfo.
nsamp = 0;
214 if (
dtype == DFNT_INT8)
216 else if (
dtype == DFNT_UINT8)
220 else if (
dtype == DFNT_UINT16)
224 else if (
dtype == DFNT_UINT32)
228 else if (
dtype == DFNT_FLOAT64)
239 cache_l2_flags.bscan = -1;
240 cache_eng_qual.bscan = -1;
241 cache_s_flags.bscan = -1;
242 cache_nflag.bscan = -1;
243 cache_pixnum.bscan = -1;
244 cache_longitude.bscan = -1;
245 cache_latitude.bscan = -1;
247 cache_l2_flags.escan = -1;
248 cache_eng_qual.escan = -1;
249 cache_s_flags.escan = -1;
250 cache_nflag.escan = -1;
251 cache_pixnum.escan = -1;
252 cache_longitude.escan = -1;
253 cache_latitude.escan = -1;
255 for (
i = 0;
i < cache_nprod;
i++) {
256 cache_l2_data[
i]->bscan = -1;
257 cache_l2_data[
i]->escan = -1;
268 tmp_cache.bscan = -1;
269 tmp_cache.escan = -1;
270 tmp_cache.dataSize = 0;
271 tmp_cache.data =
NULL;
273 cache_l2_flags = tmp_cache;
274 cache_eng_qual = tmp_cache;
275 cache_s_flags = tmp_cache;
276 cache_nflag = tmp_cache;
277 cache_pixnum = tmp_cache;
278 cache_longitude = tmp_cache;
279 cache_latitude = tmp_cache;
284 int newSize = l2_str->nsamp * maxThirdDim * 8;
285 if(databufSize < newSize) {
288 databufSize = newSize;
289 databuf = (
unsigned char *) malloc(databufSize);
296 int32_t
openL2(
const char *fname,
char *plist, l2_prod *l2_str) {
302 int32_t tilt_start[2] = {0, 0};
303 int32_t tilt_edges[2] = {20, 2};
304 int16_t t_ranges[2 * 20];
312 char buffer[2048 * 8];
314 char *numstr[] = {
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
315 "11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
316 "21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
319 static int32_t first = 1;
323 if (Hishdf(fname) == 1) {
331 if (l2_str->nrec == 0) {
332 strcpy(l2_str->filename, fname);
334 fileindex = n_files_open - 1;
335 l2_str->fileindex = fileindex;
337 fileindex = l2_str->fileindex;
369 prodlist[fileindex] = (
char *) calloc(strlen(plist) + 1,
sizeof (char));
370 strcpy(prodlist[fileindex], plist);
372 getProdlist(fname, &prodlist[fileindex], &l2_flags_type);
379 l2_str->prodname[0] = &prodlist[fileindex][0];
380 len = strlen(prodlist[fileindex]);
381 for (
i = 0;
i < len;
i++) {
382 if (prodlist[fileindex][
i] ==
':') {
383 l2_str->prodname[l2_str->nprod] = prodlist[fileindex] +
i + 1;
385 prodlist[fileindex][
i] = 0;
389 if (strlen(prodlist[fileindex]) == 0) l2_str->nprod = 0;
394 ds_id_file[fileindex] = ds_id;
397 nc_inq_ncid(ds_id.
fid,
"sensor_band_parameters", &grp_id[fileindex][0]);
398 nc_inq_ncid(ds_id.
fid,
"sensor_tilt", &grp_id[fileindex][1]);
399 nc_inq_ncid(ds_id.
fid,
"scan_line_attributes", &grp_id[fileindex][2]);
400 nc_inq_ncid(ds_id.
fid,
"geophysical_data", &grp_id[fileindex][3]);
401 nc_inq_ncid(ds_id.
fid,
"navigation_data", &grp_id[fileindex][4]);
402 nc_inq_ncid(ds_id.
fid,
"processing_control", &grp_id[fileindex][5]);
408 status = nc_inq_dimid(ds_id.
fid,
"number_of_lines", &dim_id);
410 status = nc_inq_dimid(ds_id.
fid,
"Number_of_Scan_Lines", &dim_id);
412 printf(
"-E- %s:%d - openL2 - could not find number_of_lines.\n",
417 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
418 l2_str->nrec = tmpSizet;
419 status = nc_inq_dimid(ds_id.
fid,
"pixels_per_line", &dim_id);
421 status = nc_inq_dimid(ds_id.
fid,
"Pixels_per_Scan_Line", &dim_id);
423 printf(
"-E- %s:%d - openL2 - could not find pixels_per_line.\n",
428 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
429 l2_str->nsamp = tmpSizet;
431 status = nc_inq_dimid(ds_id.
fid,
"bands_per_pixel", &dim_id);
433 nc_inq_dimlen(ds_id.
fid, dim_id, &tmpSizet);
434 bandsPerPixel = tmpSizet;
436 l2_str->bandsPerPixel = bandsPerPixel;
439 readAttr(ds_id,
"Number of Scan Lines", (
void*) & l2_str->nrec);
440 readAttr(ds_id,
"Pixels per Scan Line", (
void*) & l2_str->nsamp);
447 status =
readAttr(ds_id,
"orbit_number", (
void*) & l2_str->orbit);
451 tmpStr =
readAttrStr(ds_id,
"time_coverage_start");
453 printf(
"-E- %s:%d - openL2 - could not find time_coverage_start.\n",
460 l2_str->syear = (int16_t) yr;
461 l2_str->sday = (int16_t) dy;
467 printf(
"-E- %s:%d - openL2 - could not find time_coverage_end.\n",
474 l2_str->eyear = (int16_t) yr;
475 l2_str->eday = (int16_t) dy;
479 readAttr(ds_id,
"Start Year", (
void*) & l2_str->syear);
480 readAttr(ds_id,
"Start Day", (
void*) & l2_str->sday);
481 readAttr(ds_id,
"Start Millisec", (
void*) & l2_str->smsec);
482 readAttr(ds_id,
"End Year", (
void*) & l2_str->eyear);
483 readAttr(ds_id,
"End Day", (
void*) & l2_str->eday);
484 readAttr(ds_id,
"End Millisec", (
void*) & l2_str->emsec);
485 readAttr(ds_id,
"Orbit Number", (
void*) & l2_str->orbit);
486 readAttr(ds_id,
"Data Type", (
void*) & l2_str->dtype);
491 l2_str->latitude = (
float *) calloc(l2_str->nsamp, sizeof (
float));
492 l2_str->longitude = (
float *) calloc(l2_str->nsamp, sizeof (
float));
494 l2_str->lat1 = (
float *) malloc((l2_str->nsamp+1) *
sizeof (
float));
495 l2_str->lon1 = (
float *) malloc((l2_str->nsamp+1) *
sizeof (
float));
497 l2_str->lat2 = (
float *) malloc((l2_str->nsamp+1) *
sizeof (
float));
498 l2_str->lon2 = (
float *) malloc((l2_str->nsamp+1) *
sizeof (
float));
504 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][4];
505 ds_id_ll[fileindex][0] = (
idDS){ds_id.
fid,
508 ds_id_ll[fileindex][1] = (
idDS){ds_id.
fid,
511 ds_id_ll[fileindex][2] = (
idDS){ds_id.
fid, -1, ds_id.
fftype};
515 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][2];
516 ds_id_date[fileindex][0] = (
idDS){ds_id.
fid,
519 ds_id_date[fileindex][1] = (
idDS){ds_id.
fid,
522 ds_id_date[fileindex][2] = (
idDS){ds_id.
fid,
526 l2_str->geointerp = 0;
529 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][0];
530 ds_id_wave[fileindex] = (
idDS){ds_id.
fid,
533 if (ds_id_wave[fileindex].sid != -1) {
534 readDS(ds_id_wave[fileindex],
"wavelength", &zero32,
NULL,
535 &bandsPerPixel, l2_str->wavelength);
541 if (dims[0] != l2_str->nrec || dims[1] != l2_str->nsamp ||
542 ds_id_ll[fileindex][0].sid == -1) {
544 l2_str->geointerp = 1;
548 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][4];
549 ds_id_geonav[fileindex][0] = (
idDS){ds_id.
fid,
552 ds_id_geonav[fileindex][1] = (
idDS){ds_id.
fid,
555 ds_id_geonav[fileindex][2] = (
idDS){ds_id.
fid,
558 ds_id_geonav[fileindex][3] = (
idDS){ds_id.
fid,
562 ds_id_geonav[fileindex][4].sid = -1;
563 ds_id_geonav[fileindex][5] = (
idDS){ds_id.
fid,
567 ds_id = ds_id_file[fileindex];
568 nsta[fileindex] = -1;
569 ninc[fileindex] = -1;
570 readAttr(ds_id_file[fileindex],
"LAC Pixel Start Number",
571 (
void*) & nsta[fileindex]);
572 readAttr(ds_id_file[fileindex],
"LAC Pixel Subsampling",
573 (
void*) & ninc[fileindex]);
575 if (ds_id_geonav[fileindex][0].sid != -1 &&
576 ds_id_geonav[fileindex][1].sid != -1 &&
577 ds_id_geonav[fileindex][2].sid != -1 &&
578 ds_id_geonav[fileindex][3].sid != -1 &&
579 nsta[fileindex] != -1 && ninc[fileindex] != -1) {
581 l2_str->geointerp = 2;
583 for (
i = 0;
i < 6;
i++) l2_str->geonav[
i] = geonav[
i];
589 status = nc_inq_dimid(ds_id_file[fileindex].fid,
"pixel_control_points", &dim_id);
591 printf(
"-E- %s:%d - openL2 - Could not find the dimension pixel_control_points.\n",
595 status = nc_inq_dimlen(ds_id_file[fileindex].fid, dim_id, &tmpSizet);
597 printf(
"-E- %s:%d - openL2 - Could not read the dimension pixel_control_points\n",
601 n_cntl_pnts = tmpSizet;
603 readAttr(ds_id_file[fileindex],
"Number of Pixel Control Points",
604 (
void*) & n_cntl_pnts);
608 if (prev_n_cntl_pnts != -1 && prev_n_cntl_pnts != n_cntl_pnts) {
609 printf(
"L2 file #:%4d has %d control points.\n", fileindex,
611 printf(
"L2 file #:%4d has %d control points.\n", fileindex + 1,
613 printf(
"These must be identical.\n");
616 prev_n_cntl_pnts = n_cntl_pnts;
621 l2_str->lon_cntl = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
622 l2_str->lat_cntl = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
623 l2_str->cntl_pnts = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
624 l2_str->cntl_pnts_cache = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
625 l2_str->spline_arr = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
629 ds_id_ll[fileindex][2].sid =
selectDS(ds_id,
"cntl_pt_cols");
633 int32_t *tmpPtr = (int32_t*) l2_str->cntl_pnts;
634 readDS(ds_id_ll[fileindex][2],
"cntl_pt_cols",
635 &zero32,
NULL, &n_cntl_pnts, tmpPtr);
637 ds_id_ll[fileindex][2].sid = -1;
641 for (
i = 0;
i < n_cntl_pnts;
i++) {
642 l2_str->cntl_pnts_cache[
i] = tmpPtr[
i];
651 ds_id.
fid = grp_id[fileindex][3];
652 for (
i = 0;
i < l2_str->nprod;
i++) {
653 sds_id =
selectDS(ds_id, l2_str->prodname[
i]);
656 getTypeDS(ds_id, l2_str->prodname[
i], &(prodtype[fileindex][
i]));
663 if (prodtype[fileindex][
i] != NC_FLOAT && prodtype[fileindex][
i] != NC_DOUBLE) {
666 slope[fileindex][
i] = 1.0;
673 slope[fileindex][
i] = 1.0;
676 readAttr(ds_id0,
"_FillValue", (
void*) (&l2_str->bv_scaled[
i]));
680 if (
slope[fileindex][
i] == 0.0)
681 slope[fileindex][
i] = 1.0;
683 if (
findAttr(ds_id0,
"bad_value_unscaled") != -1)
684 readAttr(ds_id0,
"bad_value_unscaled", (
void*) (&l2_str->bv_unscaled[
i]));
686 l2_str->bv_unscaled[
i] = -1e30;
688 if (
findAttr(ds_id0,
"bad_value_scaled") != -1)
689 readAttr(ds_id0,
"bad_value_scaled", (
void*) (&l2_str->bv_scaled[
i]));
691 l2_str->bv_scaled[
i] = -32768;
694 ds_id_prod[fileindex][
i] = (
idDS){ds_id.
fid, sds_id, ds_id.
fftype};
696 int32_t fldDims[8]={0,0,0,0,0,0,0,0};
697 getDimsDS(ds_id, l2_str->prodname[
i], fldDims);
698 if (fldDims[2] == bandsPerPixel)
699 l2_str->thirdDim[
i] = bandsPerPixel;
701 l2_str->thirdDim[
i] = 1;
704 printf(
"Data Product: \"%s\" not found.\n", l2_str->prodname[
i]);
712 if (cache_l2_data ==
NULL) {
713 cache_nprod = l2_str->nprod;
714 cache_l2_data = (cache_str**) malloc(
sizeof (cache_str*) * cache_nprod);
715 for (
i = 0;
i < cache_nprod;
i++) {
716 cache_l2_data[
i] = (cache_str*) malloc(
sizeof (cache_str));
717 cache_l2_data[
i]->bscan = -1;
718 cache_l2_data[
i]->escan = -1;
719 cache_l2_data[
i]->dataSize = 0;
720 cache_l2_data[
i]->data =
NULL;
722 }
else if (cache_nprod < l2_str->nprod) {
725 for (
i = 0;
i < cache_nprod;
i++) free(cache_l2_data[
i]);
728 cache_nprod = l2_str->nprod;
729 cache_l2_data = (cache_str**) malloc(
sizeof (cache_str*) * cache_nprod);
730 for (
i = 0;
i < cache_nprod;
i++) {
731 cache_l2_data[
i] = (cache_str*) malloc(
sizeof (cache_str));
732 cache_l2_data[
i]->bscan = -1;
733 cache_l2_data[
i]->escan = -1;
734 cache_l2_data[
i]->dataSize = 0;
735 cache_l2_data[
i]->data =
NULL;
742 l2_str->l2_data = (
float**) malloc(l2_str->nprod * sizeof (
float*));
743 for (
i = 0;
i < l2_str->nprod;
i++) {
744 l2_str->l2_data[
i] = (
float*) malloc(l2_str->nsamp*l2_str->thirdDim[
i]*
sizeof(
float));
745 if(l2_str->thirdDim[
i] > maxThirdDim)
746 maxThirdDim = l2_str->thirdDim[
i];
755 if ((ds_id_pixnum[fileindex].sid =
selectDS(ds_id,
"pixnum")) != -1) {
756 l2_str->pixnum = (int32_t *) calloc(l2_str->nsamp, sizeof (int32_t));
758 l2_str->pixnum =
NULL;
760 ds_id_pixnum[fileindex].
fid = ds_id.
fid;
765 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][2];
766 if ((ds_id.
sid =
selectDS(ds_id,
"mside")) != -1) {
767 l2_str->mside = (
byte *) calloc(l2_str->nrec, sizeof (
byte));
769 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec,
770 (
void*) l2_str->mside);
777 SDgetinfo(ds_id.
sid,
NULL, &
rank, dimsizes, &ntype, &num_attrs);
778 if (ntype == DFNT_INT8) {
779 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec,
780 (
void*) l2_str->mside);
783 int32_t junk[l2_str->nrec];
785 readDS(ds_id,
"mside", &zero32,
NULL, &l2_str->nrec, (
void*) junk);
786 for (
i = 0;
i < l2_str->nrec;
i++)
787 l2_str->mside[
i] = (
byte) junk[
i];
792 l2_str->mside =
NULL;
795 if ((ds_id.
sid =
selectDS(ds_id,
"detnum")) != -1) {
796 l2_str->detnum = (
byte *) calloc(l2_str->nrec, sizeof (
byte));
798 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec,
799 (
void*) l2_str->detnum);
806 SDgetinfo(ds_id.
sid,
NULL, &
rank, dimsizes, &ntype, &num_attrs);
807 if (ntype == DFNT_INT8) {
808 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec,
809 (
void*) l2_str->detnum);
812 int32_t junk[l2_str->nrec];
814 readDS(ds_id,
"detnum", &zero32,
NULL, &l2_str->nrec, (
void*) junk);
815 for (
i = 0;
i < l2_str->nrec;
i++)
816 l2_str->detnum[
i] = (
byte) junk[
i];
821 l2_str->detnum =
NULL;
827 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][1];
828 if (
selectDS(ds_id,
"ntilts") != -1) {
830 readDS(ds_id,
"ntilts", tilt_start,
NULL, &one,
831 (
void*) & l2_str->ntilts);
833 readDS(ds_id,
"tilt_flags", tilt_start,
NULL, tilt_edges,
834 (
void*) l2_str->tilt_flags);
836 readDS(ds_id,
"tilt_ranges", tilt_start,
NULL, tilt_edges,
839 for (
i = 0;
i < l2_str->ntilts;
i++) {
840 l2_str->tilt_ranges[0][
i] = t_ranges[
i * 2];
841 l2_str->tilt_ranges[1][
i] = t_ranges[
i * 2 + 1];
850 ds_id.
fid = grp_id[fileindex][3];
851 ds_id_l2_flags[fileindex] = (
idDS){
856 idDS temp_ds_id = ds_id_l2_flags[fileindex];
857 temp_ds_id.
fid *= -1;
859 if (ds_id_l2_flags[fileindex].sid != -1) {
860 l2_str->l2_flags = (int32_t *) calloc(l2_str->nsamp, sizeof (int32_t));
861 l2_str->flagnames =
readAttrStr(temp_ds_id,
"flag_meanings");
862 if(!l2_str->flagnames) {
863 printf(
"-E- %s:%d - openL2 - could not find flag_meanings.\n",
867 for (
i = 0;
i < strlen(l2_str->flagnames);
i++) {
868 if (l2_str->flagnames[
i] ==
' ')
869 l2_str->flagnames[
i] =
',';
872 l2_str->l2_flags = 0x0;
877 ds_id_l2_flags[fileindex] = (
idDS){
883 if (ds_id_l2_flags[fileindex].sid != -1) {
884 l2_str->l2_flags = (int32_t *) calloc(l2_str->nsamp, sizeof (int32_t));
890 idDS temp_ds_id = ds_id_l2_flags[fileindex];
891 temp_ds_id.
fid *= -1;
893 sprintf(buffer,
"f%s_name", numstr[n_l2flags]);
894 if (
findAttr(temp_ds_id, buffer) != -1) {
896 listlen += strlen(tmpStr) + 1;
902 l2_str->flagnames = (
char *) calloc(listlen,
sizeof (
char));
903 for (
i = 0;
i < n_l2flags;
i++) {
904 sprintf(buffer,
"f%s_name", numstr[
i]);
906 strcat(l2_str->flagnames, tmpStr);
908 if (
i < n_l2flags - 1)
909 strcat(l2_str->flagnames,
",");
912 l2_str->l2_flags = 0x0;
918 if (
checkDS(ds_id_file[fileindex],
"eng_qual") != -1) {
919 ds_id_eng_qual[fileindex].
sid =
selectDS(ds_id,
"eng_qual");
920 ds_id_eng_qual[fileindex].
fid = ds_id.
fid;
923 ds_id_eng_qual[fileindex].
sid = -1;
928 if (
checkDS(ds_id_file[fileindex],
"s_flags") != -1) {
929 ds_id_s_flags[fileindex].
sid =
selectDS(ds_id,
"s_flags");
930 ds_id_s_flags[fileindex].
fid = ds_id.
fid;
933 ds_id_s_flags[fileindex].
sid = -1;
938 if (
checkDS(ds_id_file[fileindex],
"nflag") != -1) {
939 ds_id_nflag[fileindex].
sid =
selectDS(ds_id,
"nflag");
940 ds_id_nflag[fileindex].
fid = ds_id.
fid;
943 ds_id_nflag[fileindex].
sid = -1;
948 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][2];
949 if (ds_id_date[fileindex][0].sid != -1) {
950 l2_str->year_cache = (int32_t*) malloc(
sizeof (int32_t) * l2_str->nrec);
951 readDS(ds_id_date[fileindex][0],
"year", &zero32,
NULL,
952 &(l2_str->nrec), l2_str->year_cache);
956 if (ds_id_date[fileindex][1].sid != -1) {
957 l2_str->day_cache = (int32_t*) malloc(
sizeof (int32_t) * l2_str->nrec);
958 readDS(ds_id_date[fileindex][1],
"day", &zero32,
NULL,
959 &(l2_str->nrec), l2_str->day_cache);
963 if (ds_id_date[fileindex][2].sid != -1) {
964 l2_str->msec_cache = (int32_t*) malloc(
sizeof (int32_t) * l2_str->nrec);
965 readDS(ds_id_date[fileindex][2],
"msec", &zero32,
NULL,
966 &(l2_str->nrec), l2_str->msec_cache);
975 int32_t
reopenL2(int32_t fileindex, l2_prod *l2_str) {
981 if (Hishdf(l2_str->filename) == 1) {
988 ds_id_file[fileindex] = ds_id;
991 nc_inq_ncid(ds_id.
fid,
"sensor_band_parameters", &grp_id[fileindex][0]);
992 nc_inq_ncid(ds_id.
fid,
"sensor_tilt", &grp_id[fileindex][1]);
993 nc_inq_ncid(ds_id.
fid,
"scan_line_attributes", &grp_id[fileindex][2]);
994 nc_inq_ncid(ds_id.
fid,
"geophysical_data", &grp_id[fileindex][3]);
995 nc_inq_ncid(ds_id.
fid,
"navigation_data", &grp_id[fileindex][4]);
996 nc_inq_ncid(ds_id.
fid,
"processing_control", &grp_id[fileindex][5]);
999 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][4];
1000 ds_id_ll[fileindex][0] = (
idDS){ds_id.
fid,
1003 ds_id_ll[fileindex][1] = (
idDS){ds_id.
fid,
1007 if (l2_str->geointerp == 2) {
1008 ds_id_geonav[fileindex][0] = (
idDS){ds_id.
fid,
1011 ds_id_geonav[fileindex][1] = (
idDS){ds_id.
fid,
1014 ds_id_geonav[fileindex][2] = (
idDS){ds_id.
fid,
1017 ds_id_geonav[fileindex][3] = (
idDS){ds_id.
fid,
1020 ds_id_geonav[fileindex][5] = (
idDS){ds_id.
fid,
1025 if (fileformat ==
DS_NCDF) ds_id.
fid = grp_id[fileindex][3];
1026 for (
i = 0;
i < l2_str->nprod;
i++) {
1027 ds_id_prod[fileindex][
i] = (
idDS){ds_id.
fid,
1032 ds_id_l2_flags[fileindex] = (
idDS){ds_id.
fid,
1036 ds_id_eng_qual[fileindex] = (
idDS){ds_id.
fid,
1040 ds_id_s_flags[fileindex] = (
idDS){ds_id.
fid,
1044 ds_id_nflag[fileindex] = (
idDS){ds_id.
fid,
1048 ds_id_pixnum[fileindex] = (
idDS){ds_id.
fid,
1060 int32_t *
start, int32_t *stride, int32_t *
edges,
1061 void*
data,
unsigned char *scan_in_rowgroup,
1080 recSize *=
edges[1];
1081 if (
edges[2] != 1) {
1082 recSize *=
edges[2];
1083 edges2[2] =
edges[2];
1094 bscan = escan =
start[0];
1095 while (scan_in_rowgroup[escan] != 0)
1098 nscans = escan - bscan + 1;
1099 size = nscans * recSize;
1106 cache->bscan = bscan;
1107 cache->escan = escan;
1109 start2[1] =
start[1];
1110 start2[2] =
start[2];
1112 edges2[1] =
edges[1];
1113 edges2[2] =
edges[2];
1118 memcpy(
data, ptr, recSize);
1125 if(*deltaLon > 90) {
1130 }
else if(*deltaLon < -90) {
1131 if(*deltaLon < -270)
1151 float* lat1,
float* lon1,
1152 float* latOut,
float* lonOut,
1153 int32_t numPoints) {
1156 float dLat = (lat1[0] - lat0[0] + lat0[1] - lat0[0]) / 2.0;
1157 float dLon = (lon1[0] - lon0[0] + lon0[1] - lon0[0]) / 2.0;
1161 latOut[0] = lat1[0] - dLat;
1162 lonOut[0] = lon1[0] - dLon;
1165 for(
int i=0;
i<numPoints-1;
i++) {
1166 dLat = (lat1[
i] - lat0[
i] + lat0[
i+1] - lat0[
i]) / 2.0;
1167 dLon = (lon1[
i] - lon0[
i] + lon0[
i+1] - lon0[
i]) / 2.0;
1170 latOut[
i+1] = lat0[
i] + dLat;
1171 lonOut[
i+1] = lon0[
i] + dLon;
1175 latOut[numPoints] = lat0[numPoints-1] + dLat;
1176 lonOut[numPoints] = lon0[numPoints-1] + dLon;
1192 float* lat1,
float* lon1,
1193 float* latOut,
float* lonOut,
1194 int32_t numPoints) {
1197 float dLat = (lat1[1] - lat1[0] + lat0[0] - lat1[0]) / 2.0;
1198 float dLon = (lon1[1] - lon1[0] + lon0[0] - lon1[0]) / 2.0;
1202 latOut[0] = lat1[0] - dLat;
1203 lonOut[0] = lon1[0] - dLon;
1206 for(
int i=0;
i<numPoints-1;
i++) {
1207 dLat = (lat1[
i] - lat0[
i] + lat0[
i+1] - lat0[
i]) / 2.0;
1208 dLon = (lon1[
i] - lon0[
i] + lon0[
i+1] - lon0[
i]) / 2.0;
1211 latOut[
i+1] = lat1[
i] + dLat;
1212 lonOut[
i+1] = lon1[
i] + dLon;
1216 latOut[numPoints] = lat1[numPoints-1] + dLat;
1217 lonOut[numPoints] = lon1[numPoints-1] + dLon;
1232 float* lat1,
float* lon1,
1233 float* latOut,
float* lonOut,
1234 int32_t numPoints) {
1237 for(
int i=0;
i<numPoints-1;
i++) {
1238 latOut[
i] = fabsf(lat0[
i] - lat1[
i]) / 2.0;
1239 lonOut[
i] = fabsf(lon0[
i] - lon0[
i+1]) / 2.0;
1240 if(lonOut[
i] > 90) {
1241 lonOut[
i] = 180.0 - lonOut[
i];
1246 latOut[numPoints-1] = latOut[numPoints-2];
1247 lonOut[numPoints-1] = lonOut[numPoints-2];
1251 unsigned char *scan_in_rowgroup) {
1253 int32_t
start[3] = {0, 0, 0};
1254 int32_t
edges[3] = {1, 1, 1};
1262 int32_t flag_edges[2] = {1, 4};
1263 int32_t nflag_edges[2] = {1, 8};
1265 float nan = __builtin_nanf(
"");
1271 edges[1] = l2_str->nsamp;
1275 if (ds_id_l2_flags[
ifile].sid != -1) {
1276 if (scan_in_rowgroup ==
NULL) {
1278 (
void*) l2_str->l2_flags);
1282 (
void*) l2_str->l2_flags, scan_in_rowgroup,
1283 &cache_l2_flags, l2_flags_type);
1289 int16_t *ptr16 = (int16_t*) l2_str->l2_flags;
1290 for (
i = l2_str->nsamp - 1;
i >= 0;
i--)
1291 l2_str->l2_flags[
i] = ptr16[
i];
1298 if (ds_id_eng_qual[
ifile].sid != -1) {
1299 if (scan_in_rowgroup ==
NULL) {
1302 (
void*) l2_str->eng_qual);
1306 (
void*) l2_str->eng_qual, scan_in_rowgroup,
1307 &cache_eng_qual,
get_dtype(DFNT_INT8, ds_id_eng_qual[
ifile].fftype));
1313 if (ds_id_s_flags[
ifile].sid != -1) {
1314 if (scan_in_rowgroup ==
NULL) {
1317 (
void*) l2_str->s_flags);
1321 (
void*) l2_str->s_flags, scan_in_rowgroup,
1322 &cache_s_flags,
get_dtype(DFNT_INT8, ds_id_s_flags[
ifile].fftype));
1328 if (ds_id_nflag[
ifile].sid != -1) {
1329 if (scan_in_rowgroup ==
NULL) {
1332 (
void*) l2_str->nflag);
1336 (
void*) l2_str->nflag, scan_in_rowgroup,
1343 if (ds_id_pixnum[
ifile].sid != -1) {
1344 if (scan_in_rowgroup ==
NULL) {
1347 (
void*) l2_str->pixnum);
1351 (
void*) l2_str->pixnum, scan_in_rowgroup,
1358 l2_str->year = l2_str->year_cache[
recnum];
1359 l2_str->day = l2_str->day_cache[
recnum];
1360 l2_str->msec = l2_str->msec_cache[
recnum];
1365 for (
i = 0;
i < l2_str->nprod;
i++) {
1367 if ((iprod != -1) && (
i != iprod))
continue;
1372 edges[2] = l2_str->thirdDim[
i];
1376 if (scan_in_rowgroup ==
NULL) {
1383 (
void*) databuf, scan_in_rowgroup,
1384 cache_l2_data[
i], prodtype[
ifile][
i]);
1388 printf(
"Read Error: %d (%s) %d\n",
1389 ifile, l2_str->filename,
i);
1395 ptype = prodtype[
ifile][
i];
1397 switch (prodtype[
ifile][
i]) {
1420 uint8*
tmp = (uint8*) databuf;
1421 float*
result = l2_str->l2_data[
i];
1422 for (ipix = 0; ipix < l2_str->nsamp; ipix++) {
1423 if (*
tmp == l2_str->bv_scaled[
i]) {
1429 result += l2_str->thirdDim[
i];
1435 int8*
tmp = (int8*) databuf;
1436 float*
result = l2_str->l2_data[
i];
1437 for (ipix = 0; ipix < l2_str->nsamp; ipix++) {
1438 if (*
tmp == l2_str->bv_scaled[
i]) {
1444 result += l2_str->thirdDim[
i];
1450 int16_t*
tmp = (int16_t*) databuf;
1451 float*
result = l2_str->l2_data[
i];
1452 for (ipix = 0; ipix < l2_str->nsamp; ipix++) {
1453 if (*
tmp == l2_str->bv_scaled[
i]) {
1462 result += l2_str->thirdDim[
i];
1468 float*
tmp = (
float*) databuf;
1469 float*
result = l2_str->l2_data[
i];
1470 for (ipix = 0; ipix < l2_str->nsamp; ipix++) {
1473 result += l2_str->thirdDim[
i];
1486 if(pixelAreaInfo.
nsamp != l2_str->nsamp) {
1487 pixelAreaInfo.
nsamp = l2_str->nsamp;
1492 pixelAreaInfo.
lastLat = (
float *) malloc(l2_str->nsamp * sizeof (
float));
1493 pixelAreaInfo.
lastLon = (
float *) malloc(l2_str->nsamp * sizeof (
float));
1500 scan_in_rowgroup[pixelAreaInfo.
lastLine] = 1;
1511 tmpFloat = pixelAreaInfo.
lastLat;
1512 pixelAreaInfo.
lastLat = l2_str->latitude;
1513 l2_str->latitude = tmpFloat;
1514 tmpFloat = pixelAreaInfo.
lastLon;
1515 pixelAreaInfo.
lastLon = l2_str->longitude;
1516 l2_str->longitude = tmpFloat;
1528 for (
i = 0;
i < l2_str->nsamp;
i++) {
1529 if ((l2_str->longitude[
i] > 180 || l2_str->longitude[
i] < -180) &&
1530 ((l2_str->l2_flags[
i] & 33554432) == 0)) {
1531 printf(
"Scheme: %d\n", l2_str->geointerp);
1532 printf(
"Pixel Longitude %d out of range (%f) for scan %d in %s.\n",
1533 i, l2_str->longitude[
i],
recnum, l2_str->filename);
1539 if ((l2_str->latitude[
i] > 180 || l2_str->latitude[
i] < -180) &&
1540 ((l2_str->l2_flags[
i] & 33554432) == 0)) {
1541 printf(
"Scheme: %d\n", l2_str->geointerp);
1542 printf(
"Pixel Latitude %d out of range (%f) for scan %d in %s.\n",
1543 i, l2_str->latitude[
i],
recnum, l2_str->filename);
1560 if(l2_str->detnum &&
1561 (l2_str->detnum[pixelAreaInfo.
lastLine] != l2_str->detnum[
recnum]) &&
1567 l2_str->lat2Valid = 0;
1574 if(l2_str->detnum &&
1575 (l2_str->detnum[pixelAreaInfo.
lastLine] != l2_str->detnum[
recnum]) &&
1583 tmpFloat = pixelAreaInfo.
lastLat;
1584 pixelAreaInfo.
lastLat = l2_str->latitude;
1585 l2_str->latitude = tmpFloat;
1586 tmpFloat = pixelAreaInfo.
lastLon;
1587 pixelAreaInfo.
lastLon = l2_str->longitude;
1588 l2_str->longitude = tmpFloat;
1594 edges[1] = l2_str->nsamp;
1598 tmpFloat = pixelAreaInfo.
lastLat;
1599 pixelAreaInfo.
lastLat = l2_str->latitude;
1600 l2_str->latitude = tmpFloat;
1601 tmpFloat = pixelAreaInfo.
lastLon;
1602 pixelAreaInfo.
lastLon = l2_str->longitude;
1603 l2_str->longitude = tmpFloat;
1616 if(l2_str->detnum &&
1617 (l2_str->detnum[
recnum+1] != l2_str->detnum[
recnum]) &&
1619 printf(
"ERROR - %s:%d - the detector number of the next line is not from the next detector.\n", __FILE__, __LINE__);
1620 printf(
" Can not do area weighting on file=%s, line=%d\n", l2_str->filename,
recnum);
1625 if(
recnum+1 >= l2_str->nrec) {
1626 printf(
"ERROR - %s:%d - the previous line was invalid and there are no more lines to read.\n", __FILE__, __LINE__);
1627 printf(
" Can not do area weighting on file=%s, line=%d\n", l2_str->filename,
recnum);
1632 tmpFloat = pixelAreaInfo.
lastLat;
1633 pixelAreaInfo.
lastLat = l2_str->latitude;
1634 l2_str->latitude = tmpFloat;
1635 tmpFloat = pixelAreaInfo.
lastLon;
1636 pixelAreaInfo.
lastLon = l2_str->longitude;
1637 l2_str->longitude = tmpFloat;
1643 edges[1] = l2_str->nsamp;
1647 tmpFloat = pixelAreaInfo.
lastLat;
1648 pixelAreaInfo.
lastLat = l2_str->latitude;
1649 l2_str->latitude = tmpFloat;
1650 tmpFloat = pixelAreaInfo.
lastLon;
1651 pixelAreaInfo.
lastLon = l2_str->longitude;
1652 l2_str->longitude = tmpFloat;
1656 l2_str->latitude, l2_str->longitude,
1657 l2_str->lat1, l2_str->lon1,
1661 l2_str->lat2, l2_str->lon2,
1666 l2_str->lat1, l2_str->lon1,
1673 if(l2_str->lat2Valid) {
1675 tmpFloat = l2_str->lat1;
1676 l2_str->lat1 = l2_str->lat2;
1677 l2_str->lat2 = tmpFloat;
1678 tmpFloat = l2_str->lon1;
1679 l2_str->lon1 = l2_str->lon2;
1680 l2_str->lon2 = tmpFloat;
1683 l2_str->latitude, l2_str->longitude,
1684 l2_str->lat1, l2_str->lon1,
1688 l2_str->latitude, l2_str->longitude,
1689 l2_str->lat2, l2_str->lon2,
1694 l2_str->lat1, l2_str->lon1,
1738 l2_str->lat2Valid = 1;
1746 unsigned char *scan_in_rowgroup) {
1748 int32_t geo_edge[6] = {3, 3, 6, 3, 3, 3};
1751 int32_t n_cntl_pnts_removed;
1754 float *cntl_pnt_buf1;
1755 float *cntl_pnt_buf2;
1756 float lon_lat_lim = 0.1;
1758 char *geonav_name[6] = {
"orb_vec",
"sen_mat",
"scan_ell",
1759 "sun_ref",
"l_vert",
"att_ang"};
1762 switch (l2_str->geointerp) {
1768 if (scan_in_rowgroup ==
NULL) {
1770 (
void*) l2_str->longitude);
1772 (
void*) l2_str->latitude);
1776 (
void*) l2_str->longitude, scan_in_rowgroup,
1780 (
void*) l2_str->latitude, scan_in_rowgroup,
1790 edges2[0] =
edges[0];
1791 edges2[1] = n_cntl_pnts;
1792 if (scan_in_rowgroup ==
NULL) {
1794 (
void*) l2_str->lon_cntl);
1796 (
void*) l2_str->lat_cntl);
1800 (
void*) l2_str->lon_cntl, scan_in_rowgroup,
1804 (
void*) l2_str->lat_cntl, scan_in_rowgroup,
1810 cntl_pnt_buf1 = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
1811 cntl_pnt_buf2 = (
float *) calloc(n_cntl_pnts,
sizeof (
float));
1818 n_cntl_pnts_removed = 0;
1819 for (
i = 0;
i < n_cntl_pnts;
i++) {
1820 if (l2_str->lat_cntl[
i] < -91 || l2_str->lat_cntl[
i] > +91) {
1821 n_cntl_pnts_removed++;
1823 cntl_pnt_buf1[
i - n_cntl_pnts_removed] = l2_str->lat_cntl[
i];
1824 cntl_pnt_buf2[
i - n_cntl_pnts_removed] = l2_str->cntl_pnts_cache[
i];
1828 if (((
float) n_cntl_pnts_removed) / n_cntl_pnts > lon_lat_lim) {
1829 fprintf(
stderr,
"%s (Latitude failure)\n", l2_str->filename);
1830 fprintf(
stderr,
"More that 10%% failure.\n");
1835 n_cntl_pnts -= n_cntl_pnts_removed;
1837 for (
i = 0;
i < n_cntl_pnts;
i++) {
1838 l2_str->lat_cntl[
i] = cntl_pnt_buf1[
i];
1839 l2_str->cntl_pnts[
i] = cntl_pnt_buf2[
i];
1842 spline(l2_str->cntl_pnts, l2_str->lat_cntl, n_cntl_pnts,
1843 1e30, 1e30, l2_str->spline_arr);
1844 for (
i = 0;
i < l2_str->nsamp;
i++) {
1845 splint(l2_str->cntl_pnts, l2_str->lat_cntl,
1846 l2_str->spline_arr, n_cntl_pnts,
1847 i + 1.0, &l2_str->latitude[
i]);
1851 n_cntl_pnts += n_cntl_pnts_removed;
1857 n_cntl_pnts_removed = 0;
1858 for (
i = 0;
i < n_cntl_pnts;
i++) {
1859 if (l2_str->lon_cntl[
i] < -181 || l2_str->lon_cntl[
i] > +181) {
1860 n_cntl_pnts_removed++;
1862 cntl_pnt_buf1[
i - n_cntl_pnts_removed] = l2_str->lon_cntl[
i];
1863 cntl_pnt_buf2[
i - n_cntl_pnts_removed] = l2_str->cntl_pnts_cache[
i];
1867 if (((
float) n_cntl_pnts_removed) / n_cntl_pnts > lon_lat_lim) {
1868 fprintf(
stderr,
"%s (Longitude failure)\n", l2_str->filename);
1869 fprintf(
stderr,
"More that 10%% failure.\n");
1873 n_cntl_pnts -= n_cntl_pnts_removed;
1875 for (
i = 0;
i < n_cntl_pnts;
i++) {
1876 l2_str->lon_cntl[
i] = cntl_pnt_buf1[
i];
1877 l2_str->cntl_pnts[
i] = cntl_pnt_buf2[
i];
1883 for (
i = 1;
i < n_cntl_pnts;
i++) {
1884 delta = l2_str->lon_cntl[
i] - l2_str->lon_cntl[
i - 1];
1885 if (
delta < -180) l2_str->lon_cntl[
i] += 360;
1886 else if (
delta > 180) l2_str->lon_cntl[
i] -= 360;
1889 spline(l2_str->cntl_pnts, l2_str->lon_cntl, n_cntl_pnts,
1890 1e30, 1e30, l2_str->spline_arr);
1892 for (
i = 0;
i < l2_str->nsamp;
i++) {
1893 splint(l2_str->cntl_pnts, l2_str->lon_cntl, l2_str->spline_arr,
1895 i + 1.0, &l2_str->longitude[
i]);
1899 while (l2_str->longitude[
i] > 180)
1900 l2_str->longitude[
i] -= 360;
1901 while (l2_str->longitude[
i] < -180)
1902 l2_str->longitude[
i] += 360;
1905 n_cntl_pnts += n_cntl_pnts_removed;
1907 free(cntl_pnt_buf1);
1908 free(cntl_pnt_buf2);
1913 edges2[0] =
edges[0];
1915 for (
i = 0;
i < 4;
i++) {
1916 edges2[1] = geo_edge[
i];
1917 if (ds_id_geonav[
ifile][
i].sid != -1) {
1924 geonav_(geonav[0], geonav[1], geonav[2], geonav[3], (int32_t*) & nsta[
ifile],
1925 (int32_t*) & ninc[
ifile], (int32_t*) & l2_str->nsamp, l2_str->latitude,
1926 l2_str->longitude, (
float *) databuf,
1927 (
float *) databuf, (
float *) databuf,
1940 for (
i = 0;
i < l2_str->nprod;
i++) {
1941 if (ds_id_prod[
ifile][
i].sid != -1) {
1944 printf(
"Error ending access to product sds: %d for file: %d\n",
1951 for (
i = 0;
i < 3;
i++) {
1952 if (ds_id_ll[
ifile][
i].sid != -1) {
1956 printf(
"Error ending access to ll sds: %d for file: %d\n",
i,
ifile);
1962 if (l2_str->geointerp == 2) {
1963 for (
i = 0;
i < 6;
i++) {
1965 if (ds_id_geonav[
ifile][
i].sid != -1)
1968 printf(
"Error ending access to geonav sds: %d for file: %d\n",
1975 if (ds_id_l2_flags[
ifile].sid != -1) {
1978 printf(
"Error ending access to l2_flags sds for file: %d\n",
ifile);
1984 if (ds_id_eng_qual[
ifile].sid != -1) {
1987 printf(
"Error ending access to eng_qual sds for file: %d\n",
ifile);
1993 if (ds_id_s_flags[
ifile].sid != -1) {
1996 printf(
"Error ending access to s_flags sds for file: %d\n",
ifile);
2001 if (ds_id_nflag[
ifile].sid != -1) {
2004 printf(
"Error ending access to n_flag sds for file: %d\n",
ifile);
2009 if (ds_id_pixnum[
ifile].sid != -1) {
2012 printf(
"Error ending access to pixnum sds for file: %d\n",
ifile);
2019 printf(
"Error ending access to file: %d\n",
ifile);
2029 if (l2_str ==
NULL) {
2032 if (prodlist[
i] !=
NULL) free(prodlist[
i]);
2037 if (l2_str->geointerp == 1) {
2038 free(l2_str->lon_cntl);
2039 free(l2_str->lat_cntl);
2040 free(l2_str->spline_arr);
2041 free(l2_str->cntl_pnts);
2044 for(
i = 0;
i < l2_str->nprod;
i++) {
2045 free(l2_str->l2_data[
i]);
2047 free(l2_str->l2_data);
2048 free(l2_str->latitude);
2049 free(l2_str->longitude);
2051 if (l2_str->l2_flags) free(l2_str->l2_flags);
2052 if (l2_str->flagnames) free(l2_str->flagnames);
2053 if (l2_str->pixnum) free(l2_str->pixnum);
2054 if (l2_str->mside) free(l2_str->mside);
2055 if (l2_str->detnum) free(l2_str->detnum);
2056 if (l2_str->year_cache) free(l2_str->year_cache);
2057 if (l2_str->day_cache) free(l2_str->day_cache);
2058 if (l2_str->msec_cache) free(l2_str->msec_cache);
2061 if(l2_str->lat1) free(l2_str->lat1);
2062 if(l2_str->lon1) free(l2_str->lon1);
2063 if(l2_str->lat2) free(l2_str->lat2);
2064 if(l2_str->lon2) free(l2_str->lon2);
2074 for (
i = 0;
i < l2_str->nprod;
i++) {
2075 if (strcmp(l2_str->prodname[
i], prodname) == 0)
return i;
2105 ds_id = ds_id_file[
ifile];
2107 meta_l2->title =
NULL;
2108 meta_l2->infiles =
NULL;
2109 meta_l2->sensor_name =
NULL;
2110 meta_l2->data_center =
NULL;
2111 meta_l2->ctime =
NULL;
2112 meta_l2->ntime =
NULL;
2113 meta_l2->snode =
NULL;
2114 meta_l2->enode =
NULL;
2115 meta_l2->mission =
NULL;
2116 meta_l2->mission_char =
NULL;
2117 meta_l2->sensor =
NULL;
2118 meta_l2->sensor_char =
NULL;
2163 printf(
"Error - Could not find global attribute \"%s\" in file: %d\n", titleStr,
ifile);
2170 if (
findAttr(ds_id, infilesStr) != -1) {
2171 meta_l2->infiles =
readAttrStr(ds_id, infilesStr);
2173 if (
findAttr(ds_id,
"source") != -1) {
2178 ds_id = ds_id_file[
ifile];
2180 if (
findAttr(ds_id, dcenterStr) != -1) {
2181 meta_l2->data_center =
readAttrStr(ds_id, dcenterStr);
2190 if (
findAttr(ds_id, ntimeStr) != -1) {
2194 if (
findAttr(ds_id, snodeStr) != -1) {
2198 if (
findAttr(ds_id, enodeStr) != -1) {
2203 if (
findAttr(ds_id, sennmeStr) != -1) {
2204 meta_l2->sensor_name =
readAttrStr(ds_id, sennmeStr);
2207 if (
findAttr(ds_id, missionStr) != -1) {
2208 meta_l2->mission =
readAttrStr(ds_id, missionStr);
2213 meta_l2->sensor =
NULL;
2217 if (
findAttr(ds_id, sennmeStr) != -1) {
2221 if (
findAttr(ds_id, missionStr) != -1) {
2222 meta_l2->mission =
readAttrStr(ds_id, missionStr);
2236 readAttr(ds_id, orbnumStr, (
void*) & meta_l2->orbnum);
2237 readAttr(ds_id, nlatStr, (
void*) & meta_l2->northlat);
2238 readAttr(ds_id, slatStr, (
void*) & meta_l2->southlat);
2239 readAttr(ds_id, wlonStr, (
void*) & meta_l2->westlon);
2240 readAttr(ds_id, elonStr, (
void*) & meta_l2->eastlon);
2241 readAttr(ds_id, stclatStr, (
void*) & meta_l2->startclat);
2242 readAttr(ds_id, stclonStr, (
void*) & meta_l2->startclon);
2243 readAttr(ds_id, endclatStr, (
void*) & meta_l2->endclat);
2244 readAttr(ds_id, endclonStr, (
void*) & meta_l2->endclon);
2245 readAttr(ds_id, nodelStr, (
void*) & meta_l2->nodel);
2256 #define FREE(ptr) if((ptr) != 0x0) free(ptr);
2258 FREE(meta_l2->title);
2259 FREE(meta_l2->infiles);
2260 FREE(meta_l2->sensor_name);
2261 FREE(meta_l2->data_center);
2262 FREE(meta_l2->ctime);
2263 FREE(meta_l2->ntime);
2264 FREE(meta_l2->snode);
2265 FREE(meta_l2->enode);
2266 FREE(meta_l2->mission);
2267 FREE(meta_l2->mission_char);
2268 FREE(meta_l2->sensor);
2269 FREE(meta_l2->sensor_char);
2282 char_ptr = strchr(l3b_prodname,
'/');
2283 if (char_ptr !=
NULL) *char_ptr = 0;
2285 memset(bufnum, 0, 128);
2286 memset(bufden, 0, 128);
2287 for (
i = 0;
i < l2_str[
ifile].nprod;
i++) {
2288 if (strcmp(l3b_prodname, l2_str[
ifile].prodname[
i]) == 0) {
2290 ds_id_prod[
ifile][
i].sid,
2291 ds_id_prod[
ifile][
i].fftype};
2297 strcpy(bufnum,
"undefined");
2302 if (char_ptr !=
NULL) {
2303 for (
i = 0;
i < l2_str[
ifile].nprod;
i++) {
2304 if (strcmp(char_ptr + 1, l2_str[
ifile].prodname[
i]) == 0) {
2306 ds_id_prod[
ifile][
i].sid,
2307 ds_id_prod[
ifile][
i].fftype};
2313 strcpy(bufden,
"undefined");
2318 if (strcmp(bufnum, bufden) == 0) {
2319 if(strcmp(bufnum,
"undefined") == 0)
2323 }
else if (strcmp(bufnum,
"dimensionless") == 0) {
2325 strcat(
units, bufden);
2326 }
else if (strcmp(bufden,
"dimensionless") == 0) {
2330 strcat(
units,
" / ");
2331 strcat(
units, bufden);