64 int main(
int argc,
char *argv[]) {
82 int32 lonlatinterp = 1;
97 int32 sscan, escan,
nscan;
102 int32 seawifs_l1a = 0;
104 int32 startyear = 0, cenyear = 0, endyear = 0;
105 int32 startday = 0, cenday = 0, endday = 0;
106 int32 startmsec = 0, cenmsec = 0, endmsec = 0;
109 float32 northern_lat = -90.0;
110 float32 southern_lat = +90.0;
111 float32 western_lon = +180.0;
112 float32 eastern_lon = -180.0;
114 static char buffer[2048];
115 static char buf2[2048];
117 static char geophyslist[2048];
119 static char fieldname[FIELDNAMELENMAX];
120 static char attrname[FIELDNAMELENMAX];
136 int32
start[8] = {0, 0, 0, 0, 0, 0, 0, 0};
137 int32 edge[8] = {0, 0, 0, 0, 0, 0, 0, 0};
138 int32 start_w[8] = {0, 0, 0, 0, 0, 0, 0, 0};
141 int32 pix_sub, sc_sub;
145 int16 old_tilt_flags[20];
146 int16 old_tilt_ranges[20][2];
147 int16 new_tilt_flags[20];
148 int16 new_tilt_ranges[20][2];
152 char *vgrpname[] = {
"Scan-Line Attributes",
156 float32 lllon, lllat, lrlon, lrlat, ullon, ullat, urlon, urlat;
157 float32 sclon, sclat, cclon, cclat, eclon, eclat;
160 char cntl_pt_cols_buf[4 * 4096];
165 float32 f32_buf[4096];
166 float32 spline_arr[4096];
168 uint8 datelinecross = 0;
170 printf(
"This is version %s of %s (compiled on %s %s)\n",
171 ver,
"l2extract", __DATE__, __TIME__);
176 printf(
"\n\n\nUsage: <%s> ", argv[0]);
177 printf(
"infile spix epix sscan escan pix_sub sc_sub outfile <prodlist>"
179 "\n\tinfile - input l2 data HDF file"
180 "\n\tspix - start pixel number (1-based)"
181 "\n\tepix - end pixel number (1-based)"
182 "\n\tsscan - start line (1-based)"
183 "\n\tescan - end line (1-based)"
184 "\n\tpix_sub - pixel subsampling rate"
185 "\n\tsc_sub - scan line subsampling rate"
186 "\n\toutfile - output file name"
187 "\n\tprodlist - product list, comma separated (optional)"
189 printf(
"\nNote: Enter line number NOT scan number!\n");
198 spix = atoi(argv[2]);
199 epix = atoi(argv[3]);
200 sscan = atoi(argv[4]);
201 escan = atoi(argv[5]);
202 pix_sub = atoi(argv[6]);
203 sc_sub = atoi(argv[7]);
205 if (pix_sub != 1 || sc_sub != 1) {
206 printf(
"Subsampling not yet implemented.\n");
211 if (argv[9] !=
NULL) {
215 printf(
"prodlist: %s\n", argv[9]);
223 HDFfid_r = Hopen(
infile, DFACC_READ, 0);
224 status = Vstart(HDFfid_r);
225 sd_id_r = SDstart(
infile, DFACC_RDONLY);
229 status = SDreadattr(sd_id_r, SDfindattr(sd_id_r,
"Number of Scan Lines"),
234 status = SDreadattr(sd_id_r, SDfindattr(sd_id_r,
"Title"), (VOIDP)
title);
235 if (strncmp(
title,
"OCTS", 4) == 0) octs = 1;
236 if (strstr(
title,
"Level-2") != 0) octs = 0;
237 if (strcmp(
title,
"SeaWiFS Level-1A Data") == 0) seawifs_l1a = 1;
242 if ((sscan % 2) == 0) sscan -= 1;
243 if ((escan % 2) == 1) escan -= 1;
244 printf(
"Actual OCTS sscan: %d\n", sscan);
245 printf(
"Actual OCTS escan: %d\n", escan);
249 SDfileinfo(sd_id_r, &ndatasets, &nglobal_attr);
251 if (sscan == -1 &&
spix == -1) lonlatinterp = 0;
258 if (escan > i32 * (octs + 1)) {
259 printf(
"escan: %d greater than # of scan lines: %d\n", escan, i32);
263 status = SDreadattr(sd_id_r, SDfindattr(sd_id_r,
"Pixels per Scan Line"),
272 printf(
"epix: %d greater than # of pixels per scan: %d\n",
epix, i32);
276 printf(
"sscan: %d escan: %d\n", sscan, escan);
277 nscan = escan - sscan + 1;
282 HDFfid_w = Hopen(outfile, DFACC_CREATE, 0);
283 status = Vstart(HDFfid_w);
284 sd_id_w = SDstart(outfile, DFACC_RDWR);
289 vg_ref = Vfind(HDFfid_r,
"Geophysical Data");
290 vgid_r = Vattach(HDFfid_r, vg_ref,
"r");
292 for (
i = 0;
i < Vntagrefs(vgid_r);
i++) {
294 sds_id = SDselect(sd_id_r, SDreftoindex(sd_id_r,
ref));
297 strcat(geophyslist, buffer);
298 strcat(geophyslist,
",");
303 for (jds = 0; jds < ndatasets; jds++) {
304 sds_id = SDselect(sd_id_r, jds);
307 printf(
"Name: %s rank: %d type: %d\n", fieldname,
rank,
dtype);
314 strcat(buffer, fieldname);
317 if (strstr(geophyslist, buffer) ==
NULL)
goto LBL1;
327 dim_id_r = SDgetdimid(sds_id,
i);
328 dim_id_w = SDgetdimid(sds_id_w,
i);
329 SDdiminfo(dim_id_r, buffer, &
count, &i32, &i32);
331 dims_w[jds][
i] = dims[
i];
336 if (strcmp(fieldname,
"samp_table") == 0)
continue;
338 if (strcmp(buffer,
"rec") == 0) {
339 dims_w[jds][
i] = (escan - sscan + 1) / 2;
342 if (strcmp(buffer,
"lines") == 0) {
343 dims_w[jds][
i] = escan - sscan + 1;
346 if (strcmp(buffer,
"blines") == 0) {
347 dims_w[jds][
i] = 5 * (escan - sscan + 1);
350 if (strcmp(buffer,
"nsamp") == 0) {
359 if (strcmp(buffer,
"Number of Scan Lines") == 0) {
360 dims_w[jds][
i] = escan - sscan + 1;
363 if (strcmp(buffer,
"Pixels per Scan Line") == 0) {
367 if (strcmp(buffer,
"Number of Pixel Control Points") == 0) {
377 for (
k = 0;
k <
rank;
k++) printf(
"%d\n", dims_w[jds][
k]);
378 printf(
"---------------\n");
382 sds_id_w = SDcreate(sd_id_w, fieldname,
dtype,
rank, dims_w[jds]);
383 if (sds_id_w == -1) {
384 printf(
"Field: %s cannot be created\n", fieldname);
391 dim_id_r = SDgetdimid(sds_id,
i);
392 dim_id_w = SDgetdimid(sds_id_w,
i);
393 SDdiminfo(dim_id_r, buffer, &
count, &i32, &i32);
394 SDsetdimname(dim_id_w, buffer);
399 for (
i = 0;
i < nattrs;
i++) {
400 status = SDreadattr(sds_id,
i, (VOIDP) buf2);
408 if (strcmp(fieldname,
"cntl_pt_cols") == 0 && lonlatinterp == 1) {
409 status = SDreaddata(sds_id,
start,
NULL, dims, (VOIDP) cntl_pt_cols_buf);
413 for (
i = 0;
i < n_cntl_pnts;
i++) {
414 memcpy(&i32, &cntl_pt_cols_buf[4 *
i],
sizeof (int32));
416 memcpy(&cntl_pt_cols_buf[4 *
i], &
f32,
sizeof (float32));
420 SDendaccess(sds_id_w);
428 for (
i = 0;
i < nglobal_attr;
i++) {
433 if (strcmp(buffer,
"Number of Scan Lines") == 0) {
434 memcpy(&nscans,
data, 4);
437 if (strcmp(buffer,
"Pixels per Scan Line") == 0) {
438 memcpy(&npixl,
data, 4);
448 for (jds = 0; jds < ndatasets; jds++) {
449 sds_id = SDselect(sd_id_r, jds);
458 strcat(buffer, fieldname);
461 if (strstr(geophyslist, buffer) ==
NULL)
goto LBL2;
467 printf(
"[Copy] %s\n", fieldname);
469 sds_id_w = SDselect(sd_id_w, n++);
477 dim_id_w = SDgetdimid(sds_id_w,
i);
478 SDdiminfo(dim_id_w, buffer, &
count, &i32, &nattrs);
479 SDsetdimname(dim_id_w, buffer);
483 if (strcmp(fieldname,
"samp_table_") != 0) {
485 if (strcmp(buffer,
"rec") == 0) {
486 start[
i] = (sscan - 1) / 2;
489 if (strcmp(buffer,
"lines") == 0) {
493 if (strcmp(buffer,
"blines") == 0) {
494 start[
i] = 5 * (sscan - 1);
497 if (strcmp(buffer,
"nsamp") == 0) {
506 if (strcmp(buffer,
"Number of Scan Lines") == 0) {
510 if (strcmp(buffer,
"Pixels per Scan Line") == 0) {
516 nelem = dims_w[jds][
i];
518 nelem *= dims_w[jds][
i];
522 if (seawifs_l1a == 0) {
523 if (strcmp(fieldname,
"slat") == 0 ||
524 strcmp(fieldname,
"slon") == 0 ||
525 strcmp(fieldname,
"elon") == 0 ||
526 strcmp(fieldname,
"elat") == 0 ||
527 strcmp(fieldname,
"clon") == 0 ||
528 strcmp(fieldname,
"clat") == 0) {
536 if (strcmp(fieldname,
"latitude") == 0 ||
537 strcmp(fieldname,
"longitude") == 0)
538 nelem = nscans * npixl;
540 data = (
char *) calloc(nelem, DFKNTsize(
dtype));
543 if (strcmp(fieldname,
"cntl_pt_cols") == 0 && lonlatinterp == 1) {
544 for (
i = 0;
i < dims_w[jds][0];
i++) {
546 memcpy(&
data[
i * 4], &i32, 4);
550 }
else if (strcmp(fieldname,
"latitude") == 0 && lonlatinterp == 1) {
551 dims_lonlat[0] = dims_w[jds][0];
552 dims_lonlat[1] = n_cntl_pnts;
554 for (
i = 0;
i < dims_w[jds][0];
i++) {
557 edge[1] = dims_lonlat[1];
559 (VOIDP) &
data[4 *
i * npixl]);
564 for (
j = 0;
j < dims_w[jds][0];
j++) {
565 spline((
float *) cntl_pt_cols_buf,
566 (
float *) &
data[
j * 4 * npixl],
571 splint((
float *) cntl_pt_cols_buf,
572 (
float *) &
data[
j * 4 * npixl],
576 &f32_buf[
i -
spix + 1]);
580 if (f32_buf[
i -
spix + 1] > northern_lat) northern_lat = f32_buf[
i -
spix + 1];
581 if (f32_buf[
i -
spix + 1] < southern_lat) southern_lat = f32_buf[
i -
spix + 1];
584 memcpy(&
data[
j * 4 * dims_w[jds][1]], f32_buf, 4 * dims_w[jds][1]);
589 }
else if (strcmp(fieldname,
"longitude") == 0 && lonlatinterp == 1) {
590 dims_lonlat[0] = dims_w[jds][0];
591 dims_lonlat[1] = n_cntl_pnts;
593 for (
i = 0;
i < dims_w[jds][0];
i++) {
596 edge[1] = dims_lonlat[1];
598 (VOIDP) &
data[4 *
i * npixl]);
603 for (
j = 0;
j < dims_w[jds][0];
j++) {
607 for (
i = 1;
i < dims_lonlat[1];
i++) {
608 memcpy(&f32_buf[1], &
data[4 * (
j * npixl +
i)], 4);
609 memcpy(&f32_buf[0], &
data[4 * (
j * npixl +
i - 1)], 4);
610 delta = f32_buf[1] - f32_buf[0];
614 }
else if (
delta > 180) {
618 memcpy(&
data[4 * (
j * npixl +
i)], &f32_buf[1], 4);
621 spline((
float *) cntl_pt_cols_buf,
622 (
float *) &
data[
j * 4 * npixl],
627 splint((
float *) cntl_pt_cols_buf,
628 (
float *) &
data[
j * 4 * npixl],
632 &f32_buf[
i -
spix + 1]);
633 if (f32_buf[
i -
spix + 1] > +180) f32_buf[
i -
spix + 1] -= 360;
634 if (f32_buf[
i -
spix + 1] < -180) f32_buf[
i -
spix + 1] += 360;
638 if (f32_buf[
i -
spix + 1] > eastern_lon) eastern_lon = f32_buf[
i -
spix + 1];
639 if (f32_buf[
i -
spix + 1] < western_lon) western_lon = f32_buf[
i -
spix + 1];
641 memcpy(&
data[
j * 4 * dims_w[jds][1]], f32_buf, 4 * dims_w[jds][1]);
647 printf(
"read status: %d for %s\n\n",
status, fieldname);
656 if (strcmp(fieldname,
"year") == 0) {
657 memcpy(&startyear, &
data[0], 4);
658 memcpy(&cenyear, &
data[4 * (dims_w[jds][0] / 2)], 4);
659 memcpy(&endyear, &
data[4 * (dims_w[jds][0] - 1)], 4);
662 if (strcmp(fieldname,
"day") == 0) {
663 memcpy(&startday, &
data[0], 4);
664 memcpy(&cenday, &
data[4 * (dims_w[jds][0] / 2)], 4);
665 memcpy(&endday, &
data[4 * (dims_w[jds][0] - 1)], 4);
668 if (strcmp(fieldname,
"msec") == 0) {
669 memcpy(&startmsec, &
data[0], 4);
670 memcpy(&cenmsec, &
data[4 * (dims_w[jds][0] / 2)], 4);
671 memcpy(&endmsec, &
data[4 * (dims_w[jds][0] - 1)], 4);
674 if (strcmp(fieldname,
"longitude") == 0) {
675 memcpy(&ullon, &
data[0], 4);
676 memcpy(&lllon, &
data[4 * (dims_w[jds][1]*(dims_w[jds][0] - 1))], 4);
678 memcpy(&urlon, &
data[4 * (dims_w[jds][1] - 1)], 4);
679 memcpy(&lrlon, &
data[4 * (dims_w[jds][0] * dims_w[jds][1] - 1)], 4);
681 memcpy(&cclon, &
data[4 * (dims_w[jds][1] * dims_w[jds][0] / 2 -
682 dims_w[jds][1] / 2)], 4);
683 memcpy(&sclon, &
data[4 * (dims_w[jds][1] / 2)], 4);
684 memcpy(&eclon, &
data[4 * (dims_w[jds][1] * dims_w[jds][0] -
685 dims_w[jds][1] / 2)], 4);
688 if (strcmp(fieldname,
"latitude") == 0) {
689 memcpy(&ullat, &
data[0], 4);
690 memcpy(&lllat, &
data[4 * (dims_w[jds][1]*(dims_w[jds][0] - 1))], 4);
692 memcpy(&urlat, &
data[4 * (dims_w[jds][1] - 1)], 4);
693 memcpy(&lrlat, &
data[4 * (dims_w[jds][0] * dims_w[jds][1] - 1)], 4);
695 memcpy(&cclat, &
data[4 * (dims_w[jds][1] * dims_w[jds][0] / 2 -
696 dims_w[jds][1] / 2)], 4);
697 memcpy(&sclat, &
data[4 * (dims_w[jds][1] / 2)], 4);
698 memcpy(&eclat, &
data[4 * (dims_w[jds][1] * dims_w[jds][0] -
699 dims_w[jds][1] / 2)], 4);
703 if (strcmp(fieldname,
"lon") == 0) {
704 memcpy(&ullon, &
data[0], 4);
705 memcpy(&lllon, &
data[4 * (dims_w[jds][0] - 1) * dims_w[jds][1]], 4);
707 memcpy(&urlon, &
data[4 * (dims_w[jds][1] - 1)], 4);
708 memcpy(&lrlon, &
data[4 * ((dims_w[jds][0] - 1) * dims_w[jds][1]
709 + dims_w[jds][1] - 1)], 4);
711 memcpy(&cclon, &
data[4 * ((dims_w[jds][0] / 2) * dims_w[jds][1]
712 + dims_w[jds][1] / 2)], 4);
713 memcpy(&sclon, &
data[4 * (dims_w[jds][1] / 2)], 4);
714 memcpy(&eclon, &
data[4 * ((dims_w[jds][0] - 1) * dims_w[jds][1]
715 + dims_w[jds][1] / 2)], 4);
718 if (strcmp(fieldname,
"lat") == 0) {
719 memcpy(&ullat, &
data[0], 4);
720 memcpy(&lllat, &
data[4 * (dims_w[jds][0] - 1) * dims_w[jds][1]], 4);
722 memcpy(&urlat, &
data[4 * (dims_w[jds][1] - 1)], 4);
723 memcpy(&lrlat, &
data[4 * ((dims_w[jds][0] - 1) * dims_w[jds][1]
724 + dims_w[jds][1] - 1)], 4);
726 memcpy(&cclat, &
data[4 * ((dims_w[jds][0] / 2) * dims_w[jds][1]
727 + dims_w[jds][1] / 2)], 4);
728 memcpy(&sclat, &
data[4 * (dims_w[jds][1] / 2)], 4);
729 memcpy(&eclat, &
data[4 * ((dims_w[jds][0] - 1) * dims_w[jds][1]
730 + dims_w[jds][1] / 2)], 4);
734 if (strcmp(fieldname,
"csol_z") == 0) {
735 memcpy(&csolz, &
data[4 * (dims_w[jds][0] / 2)], 4);
738 if (strcmp(fieldname,
"ntilts") == 0) {
739 memcpy(&ntilts,
data, 4);
742 if (strcmp(fieldname,
"tilt_flags") == 0) {
743 memcpy(old_tilt_flags,
data, 2 * 20);
746 if (strcmp(fieldname,
"tilt_ranges") == 0) {
748 memset(new_tilt_flags, 0, 2 * 20);
749 memset(new_tilt_ranges, 0, 2 * 2 * 20);
750 memcpy(old_tilt_ranges,
data, 2 * 2 * 20);
752 for (
i = 0;
i < ntilts;
i++) {
753 if (sscan >= old_tilt_ranges[
i][0] &&
754 sscan <= old_tilt_ranges[
i][1]) {
758 if (escan >= old_tilt_ranges[
i][0] &&
759 escan <= old_tilt_ranges[
i][1]) {
763 ntilts = etilt - stilt + 1;
765 for (
i = 0;
i < ntilts;
i++) {
766 new_tilt_ranges[
i][0] = old_tilt_ranges[stilt +
i][0] - sscan + 1;
767 new_tilt_ranges[
i][1] = old_tilt_ranges[stilt +
i][1] - sscan + 1;
769 if (new_tilt_ranges[
i][0] < 1) new_tilt_ranges[
i][0] = 1;
770 if (new_tilt_ranges[
i][1] < 1) new_tilt_ranges[
i][0] = 1;
772 if (new_tilt_ranges[
i][0] >
nscan) new_tilt_ranges[
i][0] =
nscan;
773 if (new_tilt_ranges[
i][1] >
nscan) new_tilt_ranges[
i][1] =
nscan;
775 new_tilt_flags[
i] = old_tilt_flags[stilt +
i];
776 new_tilt_flags[
i] = old_tilt_flags[stilt +
i];
779 memcpy(
data, new_tilt_ranges, 2 * 2 * 20);
785 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP)
data);
787 printf(
"write status: %d\n\n",
status);
794 if (strcmp(fieldname,
"longitude") == 0) {
795 data2 = (
char *) calloc(dims_w[jds][0], DFKNTsize(
dtype));
798 for (
j = 0;
j < dims_w[jds][0];
j++) {
800 memcpy(&data2[
k *
j], &
data[
k *
j * dims_w[jds][1]], DFKNTsize(
dtype));
802 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"slon"));
803 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
805 printf(
"write status: %d\n\n",
status);
810 for (
j = 0;
j < dims_w[jds][0];
j++) {
812 memcpy(&data2[
k *
j], &
data[
k * (
j * dims_w[jds][1] + dims_w[jds][1] - 1)], DFKNTsize(
dtype));
814 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"elon"));
815 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
817 printf(
"write status: %d\n\n",
status);
822 for (
j = 0;
j < dims_w[jds][0];
j++) {
824 memcpy(&data2[
k *
j], &
data[
k * (
j * dims_w[jds][1] + dims_w[jds][1] / 2)], DFKNTsize(
dtype));
826 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"clon"));
827 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
829 printf(
"write status: %d\n\n",
status);
838 if (strcmp(fieldname,
"latitude") == 0) {
839 data2 = (
char *) calloc(dims_w[jds][0], DFKNTsize(
dtype));
842 for (
j = 0;
j < dims_w[jds][0];
j++) {
844 memcpy(&data2[
k *
j], &
data[
k *
j * dims_w[jds][1]], DFKNTsize(
dtype));
846 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"slat"));
847 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
849 printf(
"write status: %d\n\n",
status);
854 for (
j = 0;
j < dims_w[jds][0];
j++) {
856 memcpy(&data2[
k *
j], &
data[
k * (
j * dims_w[jds][1] + dims_w[jds][1] - 1)], DFKNTsize(
dtype));
858 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"elat"));
859 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
861 printf(
"write status: %d\n\n",
status);
866 for (
j = 0;
j < dims_w[jds][0];
j++) {
868 memcpy(&data2[
k *
j], &
data[
k * (
j * dims_w[jds][1] + dims_w[jds][1] / 2)], DFKNTsize(
dtype));
870 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"clat"));
871 status = SDwritedata(sds_id_w, start_w,
NULL, dims_w[jds], (VOIDP) data2);
873 printf(
"write status: %d\n\n",
status);
883 SDendaccess(sds_id_w);
891 sds_id = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"ntilts"));
894 status = SDwritedata(sds_id, &zero,
NULL, dims, (VOIDP) & ntilts);
896 printf(
"write ntilts status: %d\n\n",
status);
901 sds_id = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"tilt_flags"));
904 status = SDwritedata(sds_id, &zero,
NULL, dims,
905 (VOIDP) new_tilt_flags);
907 printf(
"write tilt_flags status: %d for %d\n\n",
status, jds);
919 data2 = (
char *) calloc(dims_w[0][0],
sizeof (
float));
921 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"slon"));
922 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
924 memcpy(&ullon, &data2[0],
sizeof (
float));
925 memcpy(&lllon, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
927 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"clon"));
928 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
930 memcpy(&sclon, &data2[0],
sizeof (
float));
931 memcpy(&eclon, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
932 memcpy(&cclon, &data2[
sizeof (
float)*(
epix -
spix) / 2],
sizeof (
float));
934 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"elon"));
935 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
937 memcpy(&urlon, &data2[0],
sizeof (
float));
938 memcpy(&lrlon, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
940 eastern_lon = -180.0;
941 western_lon = +180.0;
942 if (ullon > eastern_lon) eastern_lon = ullon;
943 if (lllon > eastern_lon) eastern_lon = lllon;
944 if (sclon > eastern_lon) eastern_lon = sclon;
945 if (eclon > eastern_lon) eastern_lon = eclon;
946 if (urlon > eastern_lon) eastern_lon = urlon;
947 if (lrlon > eastern_lon) eastern_lon = lrlon;
949 if (ullon < western_lon) western_lon = ullon;
950 if (lllon < western_lon) western_lon = lllon;
951 if (sclon < western_lon) western_lon = sclon;
952 if (eclon < western_lon) western_lon = eclon;
953 if (urlon < western_lon) western_lon = urlon;
954 if (lrlon < western_lon) western_lon = lrlon;
958 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"slat"));
959 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
961 memcpy(&ullat, &data2[0],
sizeof (
float));
962 memcpy(&lllat, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
964 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"clat"));
965 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
967 memcpy(&sclat, &data2[0],
sizeof (
float));
968 memcpy(&eclat, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
969 memcpy(&cclat, &data2[
sizeof (
float)*(
epix -
spix) / 2],
sizeof (
float));
971 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"elat"));
972 status = SDreaddata(sds_id_w, start_w,
NULL, dims_w[0], (VOIDP) data2);
974 memcpy(&urlat, &data2[0],
sizeof (
float));
975 memcpy(&lrlat, &data2[
sizeof (
float)*(
epix -
spix)],
sizeof (
float));
977 northern_lat = -90.0;
978 southern_lat = +90.0;
979 if (ullat > northern_lat) northern_lat = ullat;
980 if (lllat > northern_lat) northern_lat = lllat;
981 if (sclat > northern_lat) northern_lat = sclat;
982 if (eclat > northern_lat) northern_lat = eclat;
983 if (urlat > northern_lat) northern_lat = urlat;
984 if (lrlat > northern_lat) northern_lat = lrlat;
986 if (ullat < southern_lat) southern_lat = ullat;
987 if (lllat < southern_lat) southern_lat = lllat;
988 if (sclat < southern_lat) southern_lat = sclat;
989 if (eclat < southern_lat) southern_lat = eclat;
990 if (urlat < southern_lat) southern_lat = urlat;
991 if (lrlat < southern_lat) southern_lat = lrlat;
1007 if (datelinecross == 1) {
1008 eastern_lon = lllon;
1009 western_lon = lrlon;
1016 for (
i = 0;
i < nglobal_attr;
i++) {
1023 if (strcmp(buffer,
"Number of Scan Lines") == 0) {
1025 i32 = (escan - sscan + 1) / 2;
1027 i32 = escan - sscan + 1;
1028 memcpy(
data, &i32, 4);
1031 if (strcmp(buffer,
"Pixels per Scan Line") == 0) {
1033 memcpy(
data, &i32, 4);
1036 if (strcmp(buffer,
"Number of Scan Control Points") == 0 && lonlatinterp == 1) {
1037 i32 = escan - sscan + 1;
1038 memcpy(
data, &i32, 4);
1041 if (strcmp(buffer,
"Number of Pixel Control Points") == 0 && lonlatinterp == 1) {
1043 memcpy(
data, &i32, 4);
1046 if (strcmp(buffer,
"Scene Center Scan Line") == 0) {
1047 i32 = (escan - sscan + 1) / 2 + 1;
1048 memcpy(
data, &i32, 4);
1051 if (strcmp(buffer,
"Start Time") == 0) {
1052 if (startyear != 0) {
1053 utime =
yds2unix(startyear, startday, startmsec / ((
double) 1000.0));
1057 if (strcmp(buffer,
"Start Year") == 0) {
1058 if (startyear != 0) memcpy(
data, &startyear, 4);
1060 if (strcmp(buffer,
"Start Day") == 0) {
1061 if (startday != 0) memcpy(
data, &startday, 4);
1063 if (strcmp(buffer,
"Start Millisec") == 0) {
1064 if (startmsec != 0) memcpy(
data, &startmsec, 4);
1068 if (strcmp(buffer,
"End Time") == 0) {
1070 utime =
yds2unix(endyear, endday, endmsec / ((
double) 1000.0));
1074 if (strcmp(buffer,
"End Year") == 0) {
1075 if (endyear != 0) memcpy(
data, &endyear, 4);
1077 if (strcmp(buffer,
"End Day") == 0) {
1078 if (endday != 0) memcpy(
data, &endday, 4);
1080 if (strcmp(buffer,
"End Millisec") == 0) {
1081 if (endmsec != 0) memcpy(
data, &endmsec, 4);
1084 if (strcmp(buffer,
"Scene Center Time") == 0) {
1086 utime =
yds2unix(cenyear, cenday, cenmsec / ((
double) 1000.0));
1092 if (strcmp(buffer,
"Upper Left Longitude") == 0) {
1093 memcpy(
data, &ullon, 4);
1095 if (strcmp(buffer,
"Upper Right Longitude") == 0) {
1096 memcpy(
data, &urlon, 4);
1098 if (strcmp(buffer,
"Upper Left Latitude") == 0) {
1099 memcpy(
data, &ullat, 4);
1101 if (strcmp(buffer,
"Upper Right Latitude") == 0) {
1102 memcpy(
data, &urlat, 4);
1104 if (strcmp(buffer,
"Start Center Longitude") == 0) {
1105 memcpy(
data, &sclon, 4);
1107 if (strcmp(buffer,
"Start Center Latitude") == 0) {
1108 memcpy(
data, &sclat, 4);
1110 if (strcmp(buffer,
"Scene Center Longitude") == 0) {
1111 memcpy(
data, &cclon, 4);
1113 if (strcmp(buffer,
"Scene Center Latitude") == 0) {
1114 memcpy(
data, &cclat, 4);
1116 if (strcmp(buffer,
"Scene Center Solar Zenith") == 0) {
1117 memcpy(
data, &csolz, 4);
1119 if (strcmp(buffer,
"Lower Left Longitude") == 0) {
1120 memcpy(
data, &lllon, 4);
1122 if (strcmp(buffer,
"Lower Right Longitude") == 0) {
1123 memcpy(
data, &lrlon, 4);
1125 if (strcmp(buffer,
"Lower Left Latitude") == 0) {
1126 memcpy(
data, &lllat, 4);
1128 if (strcmp(buffer,
"Lower Right Latitude") == 0) {
1129 memcpy(
data, &lrlat, 4);
1131 if (strcmp(buffer,
"End Center Longitude") == 0) {
1132 memcpy(
data, &eclon, 4);
1134 if (strcmp(buffer,
"End Center Latitude") == 0) {
1135 memcpy(
data, &eclat, 4);
1138 if (strcmp(buffer,
"Northernmost Latitude") == 0 && lonlatinterp == 1) {
1139 memcpy(
data, &northern_lat, 4);
1141 if (strcmp(buffer,
"Southernmost Latitude") == 0 && lonlatinterp == 1) {
1142 memcpy(
data, &southern_lat, 4);
1144 if (strcmp(buffer,
"Easternmost Longitude") == 0 && lonlatinterp == 1) {
1145 memcpy(
data, &eastern_lon, 4);
1147 if (strcmp(buffer,
"Westernmost Longitude") == 0 && lonlatinterp == 1) {
1148 memcpy(
data, &western_lon, 4);
1151 if (strcmp(buffer,
"LAC Pixel Start Number") == 0) {
1152 status = SDreadattr(sd_id_r,
i + 1, (VOIDP) & i32);
1153 memcpy(&LAC_start,
data, 4);
1154 LAC_start += i32 * (
spix - 1);
1155 memcpy(
data, &LAC_start, 4);
1162 if (strcmp(buffer,
"Processing Time") == 0) {
1174 for (
i = 0;
i < nglobal_attr;
i++) {
1181 if (strcmp(buffer,
"Title") == 0) {
1183 if (strstr(
data,
"Level-1A") !=
NULL) {
1205 i32 = escan - sscan + 1;
1217 for (
j = 0;
j < nvgrp;
j++) {
1218 vg_ref = Vfind(HDFfid_r, vgrpname[
j]);
1219 vgid_r = Vattach(HDFfid_r, vg_ref,
"r");
1220 vgid_w = Vattach(HDFfid_w, -1,
"w");
1221 Vgetname(vgid_r, buffer);
1222 Vsetname(vgid_w, buffer);
1223 Vgetclass(vgid_r, buffer);
1224 Vsetclass(vgid_w, buffer);
1226 for (
i = 0;
i < Vntagrefs(vgid_r);
i++) {
1228 sds_id = SDselect(sd_id_r, SDreftoindex(sd_id_r,
ref));
1235 strcmp(vgrpname[
j],
"Geophysical Data") == 0) {
1238 strcat(buf2, fieldname);
1244 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w, fieldname));
1245 Vaddtagref(vgid_w, DFTAG_NDG, SDidtoref(sds_id_w));
1247 SDendaccess(sds_id_w);
1249 SDendaccess(sds_id);