27 #define basename(s) (strrchr((s), '/') == NULL ? (s) : strrchr((s), '/') + 1)
30 #define VERSION "1.45"
33 printf(
"This is version %s of %s (compiled on %s %s)\n",
34 VERSION, progname, __DATE__, __TIME__);
36 printf(
"\nUsage: %s ifile ofile\n", progname);
37 printf(
" ifile = input filename\n");
38 printf(
" ofile = output filename\n");
42 int main(
int argc,
char *argv[]) {
66 int32 daynotneeded[] = {11, 12, 13, -1};
67 int32 ngtnotneeded[] = {1, 4, 10, 13, 14, 15, 16, -1};
76 float32 *median_250_500;
77 float32 sumx, sumy, sumx2, sumxy,
a,
b, scale_parm[2];
79 float32 rescale_parm[8];
81 static char buffer[2 * 2048];
82 static char buf2[2048];
99 int32
start[3] = {0, 0, 0};
100 int32 start_w[3] = {0, 0, 0};
124 tmnow = gmtime(&tnow);
125 strftime(prodtime, 80,
"%Y-%m-%dT%XZ", tmnow);
127 HDFfid_r = Hopen(argv[1], DFACC_READ, 0);
128 status = Vstart(HDFfid_r);
129 sd_id_r = SDstart(argv[1], DFACC_RDONLY);
133 HDFfid_w = Hopen(argv[2], DFACC_CREATE, 0);
134 status = Vstart(HDFfid_w);
135 sd_id_w = SDstart(argv[2], DFACC_RDWR);
137 printf(
"argc: %d\n", argc);
146 rescale = atoi(argv[3]);
151 SDfileinfo(sd_id_r, &ndatasets, &nglobal_attr);
154 for (
j = 0;
j < ndatasets;
j++) {
155 sds_id = SDselect(sd_id_r,
j);
158 if (strcmp(buffer,
"SD_250m") == 0)
continue;
159 if (strcmp(buffer,
"SD_500m") == 0)
continue;
161 if (strcmp(buffer,
"SRCA_250m") == 0)
continue;
162 if (strcmp(buffer,
"SRCA_500m") == 0)
continue;
164 if (strcmp(buffer,
"BB_250m") == 0)
continue;
165 if (strcmp(buffer,
"BB_500m") == 0)
continue;
167 if (strcmp(buffer,
"SV_250m") == 0)
continue;
168 if (strcmp(buffer,
"SV_500m") == 0)
continue;
170 if (strcmp(buffer,
"EV_250m") == 0)
continue;
171 if (strcmp(buffer,
"EV_500m") == 0)
continue;
179 sds_id_w = SDcreate(sd_id_w, buffer,
dtype,
rank, dims);
180 if (sds_id_w == -1) {
181 printf(
"Field: %s cannot be created\n", buffer);
185 for (
i = 0;
i < nattrs;
i++) {
186 status = SDreadattr(sds_id,
i, (VOIDP) buf2);
192 dim_id_r = SDgetdimid(sds_id,
i);
193 dim_id_w = SDgetdimid(sds_id_w,
i);
194 SDdiminfo(dim_id_r, buffer, &
count, &
dtype, &nattrs);
195 SDsetdimname(dim_id_w, buffer);
198 SDendaccess(sds_id_w);
206 for (
j = 0;
j < ndatasets;
j++) {
207 sds_id = SDselect(sd_id_r,
j);
210 if (strcmp(buffer,
"SD_250m") == 0)
continue;
211 if (strcmp(buffer,
"SD_500m") == 0)
continue;
213 if (strcmp(buffer,
"SRCA_250m") == 0)
continue;
214 if (strcmp(buffer,
"SRCA_500m") == 0)
continue;
216 if (strcmp(buffer,
"BB_250m") == 0)
continue;
217 if (strcmp(buffer,
"BB_500m") == 0)
continue;
219 if (strcmp(buffer,
"SV_250m") == 0)
continue;
220 if (strcmp(buffer,
"SV_500m") == 0)
continue;
222 if (strcmp(buffer,
"EV_250m") == 0)
continue;
223 if (strcmp(buffer,
"EV_500m") == 0)
continue;
225 sds_id_w = SDselect(sd_id_w, n++);
233 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
235 data = (
char *) calloc(nelem, DFKNTsize(
dtype));
243 if (strcmp(buffer,
"Frame count array") == 0 && last_bad == 0) {
244 memcpy(&i16, &
data[(6 * 202 + 1)*2], 2);
245 if (i16 == 0) last_bad = 1;
246 printf(
"last_bad: %d\n", last_bad);
253 if (strcmp(buffer,
"EV_1km_day") == 0) {
254 printf(
"Masking Unneeded Day Bands\n");
255 for (
k = 0;
k < dims[0];
k++) {
257 while (daynotneeded[l] != -1) {
258 if (
k == 0) printf(
"%d\n", daynotneeded[l]);
259 memset(&
data[
k * 2 * dims[1] * dims[2] + daynotneeded[l]*2 * dims[2]],
268 if (strcmp(buffer,
"EV_1km_night") == 0) {
269 printf(
"Masking Unneeded Night Bands\n");
270 for (
k = 0;
k < dims[0];
k++) {
272 while (ngtnotneeded[l] != -1) {
273 if (
k == 0) printf(
"%d\n", ngtnotneeded[l]);
274 memset(&
data[
k * 2 * dims[1] * dims[2] + ngtnotneeded[l]*2 * dims[2]],
282 status = SDwritedata(sds_id_w, start_w,
NULL, dims, (VOIDP)
data);
284 printf(
"write status: %d\n\n",
status);
291 SDendaccess(sds_id_w);
295 if (SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_250m")) == -1 ||
296 SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_500m")) == -1) {
297 printf(
"No 250/500 EV field found.\n");
302 printf(
"No rescaling performed\n");
310 if ((tmp_str = getenv(
"OCDATAROOT")) ==
NULL) {
311 printf(
"OCDATAROOT environment variable is not defined.\n");
316 strcat(buf2,
"/modisa/l1a_scaling.dat");
318 if ((fp = fopen(buf2,
"r")) ==
NULL) {
319 printf(
"Error: Unable to open rescaling parameter file: %s.\n", buf2);
323 for (
i = 0;
i < 4;
i++) {
324 if (fscanf(fp,
"%f %f\n",
325 &rescale_parm[2 *
i], &rescale_parm[2 *
i + 1]) == EOF) {
326 printf(
"Error: Insufficent number of scaling parameters: %s.\n",
336 printf(
"Rescale saturated 1km B pixels (B10) using 500m B pixels (B3)\n");
338 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"EV_1km_day"));
344 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
349 data_1km = (
int16 *) calloc(nelem, sz);
350 median_250_500 = (float32 *) calloc(nelem,
sizeof (float32));
354 sds_id = SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_500m"));
362 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
364 data = (
char *) calloc(nelem, sz);
371 for (
i = 0;
i < nlines;
i++) {
375 if (
i % 400 == 0) printf(
"i: %d\n",
i);
379 memcpy(&idata_HR[0], &
data[sz * 2 * (
j + 0 *
npix)], 2 * sz);
380 memcpy(&idata_HR[2], &
data[sz * 2 * (
j + 1 *
npix)], 2 * sz);
382 qsort((
void *) idata_HR, dims[0] * dims[0],
sizeof (
int16),
385 for (
k = 0;
k < 4;
k++) {
386 if (idata_HR[
k] > 0) {
389 median_250_500[
i *
npix +
j] =
390 0.5 * (idata_HR[(2 +
k) / 2] + idata_HR[(4 +
k) / 2]);
392 median_250_500[
i *
npix +
j] = (float32) idata_HR[(3 +
k) / 2];
394 if (data_1km[
i *
npix +
j] > 0 && data_1km[
i *
npix +
j] < 4095) {
396 sumx += median_250_500[
i *
npix +
j];
397 sumy += data_1km[
i *
npix +
j];
398 sumx2 += median_250_500[
i *
npix +
j] * median_250_500[
i *
npix +
j];
399 sumxy += median_250_500[
i *
npix +
j] * data_1km[
i *
npix +
j];
406 a = (sumxy - sumx * sumy / n) / (sumx2 - sumx * sumx / n);
407 b = (sumy / n) -
a * (sumx / n);
417 (VOIDP) & rescale_parm[0]);
422 printf(
"a: %f b: %f\n",
a,
b);
424 for (
i = 0;
i < nlines;
i++)
426 if (data_1km[
i *
npix +
j] == 4095) {
428 if (data_1km[
i *
npix +
j] >= 0 && data_1km[
i *
npix +
j] < 4095)
429 data_1km[
i *
npix +
j] = 4095;
431 if (data_1km[
i *
npix +
j] < 0) data_1km[
i *
npix +
j] = 32767;
442 free(median_250_500);
445 SDendaccess(sds_id_w);
451 printf(
"Rescale saturated 1km G pixels (B12) using 500m G pixels (B4)\n");
453 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"EV_1km_day"));
459 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
464 data_1km = (
int16 *) calloc(nelem, sz);
465 median_250_500 = (float32 *) calloc(nelem,
sizeof (float32));
469 sds_id = SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_500m"));
477 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
479 data = (
char *) calloc(nelem, sz);
486 for (
i = 0;
i < nlines;
i++) {
490 if (
i % 400 == 0) printf(
"i: %d\n",
i);
494 memcpy(&idata_HR[0], &
data[sz * 2 * (
j + 0 *
npix)], 2 * sz);
495 memcpy(&idata_HR[2], &
data[sz * 2 * (
j + 1 *
npix)], 2 * sz);
497 qsort((
void *) idata_HR, dims[0] * dims[0],
sizeof (
int16),
500 for (
k = 0;
k < 4;
k++) {
501 if (idata_HR[
k] > 0) {
504 median_250_500[
i *
npix +
j] =
505 0.5 * (idata_HR[(2 +
k) / 2] + idata_HR[(4 +
k) / 2]);
507 median_250_500[
i *
npix +
j] = (float32) idata_HR[(3 +
k) / 2];
509 if (data_1km[
i *
npix +
j] > 0 && data_1km[
i *
npix +
j] < 4095) {
511 sumx += median_250_500[
i *
npix +
j];
512 sumy += data_1km[
i *
npix +
j];
513 sumx2 += median_250_500[
i *
npix +
j] * median_250_500[
i *
npix +
j];
514 sumxy += median_250_500[
i *
npix +
j] * data_1km[
i *
npix +
j];
521 a = (sumxy - sumx * sumy / n) / (sumx2 - sumx * sumx / n);
522 b = (sumy / n) -
a * (sumx / n);
532 (VOIDP) & rescale_parm[2]);
537 printf(
"a: %f b: %f\n",
a,
b);
539 for (
i = 0;
i < nlines;
i++)
541 if (data_1km[
i *
npix +
j] == 4095) {
543 if (data_1km[
i *
npix +
j] >= 0 && data_1km[
i *
npix +
j] < 4095)
544 data_1km[
i *
npix +
j] = 4095;
546 if (data_1km[
i *
npix +
j] < 0) data_1km[
i *
npix +
j] = 32767;
557 free(median_250_500);
560 SDendaccess(sds_id_w);
565 printf(
"Rescale saturated 1km R pixels (B13) using 250m R pixels (B1)\n");
567 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"EV_1km_day"));
573 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
578 data_1km = (
int16 *) calloc(nelem, sz);
579 median_250_500 = (float32 *) calloc(nelem,
sizeof (float32));
583 sds_id = SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_250m"));
591 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
593 data = (
char *) calloc(nelem, sz);
600 for (
i = 0;
i < nlines;
i++) {
604 if (
i % 400 == 0) printf(
"i: %d\n",
i);
608 memcpy(&idata_HR[0], &
data[sz * 4 * (
j + 0 *
npix)], 4 * sz);
609 memcpy(&idata_HR[4], &
data[sz * 4 * (
j + 1 *
npix)], 4 * sz);
610 memcpy(&idata_HR[8], &
data[sz * 4 * (
j + 2 *
npix)], 4 * sz);
611 memcpy(&idata_HR[12], &
data[sz * 4 * (
j + 3 *
npix)], 4 * sz);
613 qsort((
void *) idata_HR, dims[0] * dims[0],
sizeof (
int16),
616 for (
k = 0;
k < dims[0] * dims[0];
k++) {
617 if (idata_HR[
k] > 0) {
620 median_250_500[
i *
npix +
j] =
621 0.5 * (idata_HR[(14 +
k) / 2] + idata_HR[(16 +
k) / 2]);
623 median_250_500[
i *
npix +
j] = (float32) idata_HR[(15 +
k) / 2];
625 if (data_1km[
i *
npix +
j] > 0 && data_1km[
i *
npix +
j] < 4095) {
627 sumx += median_250_500[
i *
npix +
j];
628 sumy += data_1km[
i *
npix +
j];
629 sumx2 += median_250_500[
i *
npix +
j] * median_250_500[
i *
npix +
j];
630 sumxy += median_250_500[
i *
npix +
j] * data_1km[
i *
npix +
j];
637 a = (sumxy - sumx * sumy / n) / (sumx2 - sumx * sumx / n);
638 b = (sumy / n) -
a * (sumx / n);
648 (VOIDP) & rescale_parm[4]);
653 printf(
"a: %f b: %f\n",
a,
b);
655 for (
i = 0;
i < nlines;
i++)
657 if (data_1km[
i *
npix +
j] == 4095) {
659 if (data_1km[
i *
npix +
j] >= 0 && data_1km[
i *
npix +
j] < 4095)
660 data_1km[
i *
npix +
j] = 4095;
663 if (data_1km[
i *
npix +
j] < 0) data_1km[
i *
npix +
j] = 32767;
674 free(median_250_500);
677 SDendaccess(sds_id_w);
683 printf(
"Rescale saturated 1km IR pixels (B16) using 250m IR pixels (B2)\n");
685 sds_id_w = SDselect(sd_id_w, SDnametoindex(sd_id_w,
"EV_1km_day"));
691 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
696 data_1km = (
int16 *) calloc(nelem, sz);
697 median_250_500 = (float32 *) calloc(nelem,
sizeof (float32));
701 sds_id = SDselect(sd_id_r, SDnametoindex(sd_id_r,
"EV_250m"));
709 for (
k = 1;
k <
rank;
k++) nelem *= dims[
k];
711 data = (
char *) calloc(nelem, sz);
718 for (
i = 0;
i < nlines;
i++) {
722 if (
i % 400 == 0) printf(
"i: %d\n",
i);
726 memcpy(&idata_HR[0], &
data[sz * 4 * (
j + 0 *
npix)], 4 * sz);
727 memcpy(&idata_HR[4], &
data[sz * 4 * (
j + 1 *
npix)], 4 * sz);
728 memcpy(&idata_HR[8], &
data[sz * 4 * (
j + 2 *
npix)], 4 * sz);
729 memcpy(&idata_HR[12], &
data[sz * 4 * (
j + 3 *
npix)], 4 * sz);
731 qsort((
void *) idata_HR, dims[0] * dims[0],
sizeof (
int16),
734 for (
k = 0;
k < dims[0] * dims[0];
k++) {
735 if (idata_HR[
k] > 0) {
738 median_250_500[
i *
npix +
j] =
739 0.5 * (idata_HR[(14 +
k) / 2] + idata_HR[(16 +
k) / 2]);
741 median_250_500[
i *
npix +
j] = (float32) idata_HR[(15 +
k) / 2];
743 if (data_1km[
i *
npix +
j] > 0 && data_1km[
i *
npix +
j] < 4095) {
745 sumx += median_250_500[
i *
npix +
j];
746 sumy += data_1km[
i *
npix +
j];
747 sumx2 += median_250_500[
i *
npix +
j] * median_250_500[
i *
npix +
j];
748 sumxy += median_250_500[
i *
npix +
j] * data_1km[
i *
npix +
j];
755 a = (sumxy - sumx * sumy / n) / (sumx2 - sumx * sumx / n);
756 b = (sumy / n) -
a * (sumx / n);
766 (VOIDP) & rescale_parm[6]);
771 printf(
"a: %f b: %f\n",
a,
b);
773 for (
i = 0;
i < nlines;
i++)
775 if (data_1km[
i *
npix +
j] == 4095) {
777 if (data_1km[
i *
npix +
j] >= 0 && data_1km[
i *
npix +
j] < 4095)
778 data_1km[
i *
npix +
j] = 4095;
780 if (data_1km[
i *
npix +
j] < 0) data_1km[
i *
npix +
j] = 32767;
791 free(median_250_500);
794 SDendaccess(sds_id_w);
801 maxsize = VSlone(HDFfid_r,
NULL, 0);
802 lonebuf = (int32 *) calloc(maxsize,
sizeof (int32));
803 maxsize = VSlone(HDFfid_r, lonebuf, maxsize);
808 for (
i = 0;
i < maxsize;
i++) {
809 vdid = VSattach(HDFfid_r, lonebuf[
i],
"r");
810 vdid_w = VSattach(HDFfid_w, -1,
"w");
811 VSgetname(vdid, buffer);
812 VSsetname(vdid_w, buffer);
815 VSsetinterlace(vdid_w, VSgetinterlace(vdid));
820 nflds = VSgetfields(vdid, buf2);
822 for (
j = 0;
j <
k;
j++)
if (buf2[
j] ==
',') buf2[
j] = 0;
828 for (
j = 0;
j < nflds;
j++) {
829 VSfdefine(vdid_w, cptr, VFfieldtype(vdid,
j), VFfieldorder(vdid,
j));
840 for (
j = 0;
j <
k - 1;
j++)
if (buf2[
j] == 0) buf2[
j] =
',';
841 status = VSsetfields(vdid, buf2);
842 status = VSsetfields(vdid_w, buf2);
844 VSQuerycount(vdid, &nrec);
846 data = (
char *) calloc(nrec * VSsizeof(vdid, buf2), 1);
848 nread = VSread(vdid, (uint8*)
data, nrec, VSgetinterlace(vdid));
849 nwrite = VSwrite(vdid_w, (uint8*)
data, nrec, VSgetinterlace(vdid_w));
852 if (nread != nwrite) {
853 printf(
"%d %d %d\n",
i, nread, nwrite);
865 for (
i = 0;
i < nglobal_attr;
i++) {
868 if (strcmp(buffer,
"CoreMetadata.0") == 0) {
872 if (strcmp(buffer,
"Number of scans") == 0) {
873 strcpy(buffer,
"Number of Scans");
881 if (strcmp(buffer,
"Number of Scans") == 0 && last_bad == 1) {
883 memcpy(
data, &i32,
sizeof (i32));
891 if (strcmp(buffer,
"Satellite") == 0) {
902 strcpy(buf2, getenv(
"SIMBIOS_ROOT"));
903 strcat(buf2,
"/data/modis/static/");
905 strcat(buf2,
"/coremeta.txt");
906 printf(
"%s\n", buf2);
907 fp = fopen(buf2,
"r");
910 printf(
"\"coremeta.txt\" cannot be found.\n");
915 while (fgets(buf2, 80, fp) !=
NULL) {
916 strcat(buffer, buf2);
919 status = SDsetattr(sd_id_w,
"CoreMetadata.0", DFNT_CHAR,
920 strlen(buffer) + 1, (VOIDP) buffer);
926 strcat(buffer,
"GROUP = INVENTORYMETADATA\n");
927 strcat(buffer,
" GROUPTYPE = MASTERGROUP\n");
929 strcat(buffer,
" GROUP = ECSDATAGRANULE\n");
931 strcat(buffer,
" OBJECT = LOCALGRANULEID\n");
932 strcat(buffer,
" NUM_VAL = 1\n");
935 memset(buf2, 0,
sizeof (buf2));
936 strcpy(buf2, getenv(
"L0File"));
939 strcat(buffer,
" VALUE = ");
940 strcat(buffer,
"\"");
941 strcat(buffer, buf2);
942 strcat(buffer,
"\"\n");
943 strcat(buffer,
" END_OBJECT = LOCALGRANULEID\n");
945 strcat(buffer,
" OBJECT = PRODUCTIONDATETIME\n");
946 strcat(buffer,
" NUM_VAL = 1\n");
947 strcat(buffer,
" VALUE = ");
948 strcat(buffer,
"\"");
949 strcat(buffer, prodtime);
950 strcat(buffer,
"\"\n");
951 strcat(buffer,
" END_OBJECT = PRODUCTIONDATETIME\n");
953 strcat(buffer,
" OBJECT = DAYNIGHTFLAG\n");
954 strcat(buffer,
" NUM_VAL = 1\n");
955 strcat(buffer,
" VALUE = ");
956 memset(buf2, 0,
sizeof (buf2));
957 if ((
i = SDfindattr(sd_id_r,
"DAYNIGHTFLAG")) != -1)
958 status = SDreadattr(sd_id_r,
i, buf2);
959 strcat(buffer,
"\"");
960 strcat(buffer, buf2);
961 strcat(buffer,
"\"\n");
962 strcat(buffer,
" END_OBJECT = DAYNIGHTFLAG\n");
964 strcat(buffer,
" OBJECT = REPROCESSINGACTUAL\n");
965 strcat(buffer,
" NUM_VAL = 1\n");
966 strcat(buffer,
" VALUE = ");
967 strcat(buffer,
"\"processed once\"");
968 strcat(buffer,
"\n");
969 strcat(buffer,
" END_OBJECT = REPROCESSINGACTUAL\n");
971 strcat(buffer,
" END_GROUP = ECSDATAGRANULE\n");
973 strcat(buffer,
" GROUP = ORBITCALCULATEDSPATIALDOMAIN\n");
975 strcat(buffer,
" OBJECT = ORBITCALCULATEDSPATIALDOMAINCONTAINER\n");
976 strcat(buffer,
" CLASS = \"1\"\n");
977 strcat(buffer,
" OBJECT = EQUATORCROSSINGDATE\n");
978 strcat(buffer,
" CLASS = \"1\"\n");
979 strcat(buffer,
" NUM_VAL = 1\n");
980 memset(buf2, 0,
sizeof (buf2));
981 if ((
i = SDfindattr(sd_id_r,
"EQUATORCROSSINGDATE")) != -1)
982 status = SDreadattr(sd_id_r,
i, buf2);
983 strcat(buffer,
" VALUE = ");
984 strcat(buffer,
"\"");
985 strcat(buffer, buf2);
986 strcat(buffer,
"\"\n");
987 strcat(buffer,
" END_OBJECT = EQUATORCROSSINGDATE\n");
989 strcat(buffer,
" OBJECT = EQUATORCROSSINGTIME\n");
990 strcat(buffer,
" CLASS = \"1\"\n");
991 strcat(buffer,
" NUM_VAL = 1\n");
992 memset(buf2, 0,
sizeof (buf2));
993 if ((
i = SDfindattr(sd_id_r,
"EQUATORCROSSINGTIME")) != -1)
994 status = SDreadattr(sd_id_r,
i, buf2);
995 strcat(buffer,
" VALUE = ");
996 strcat(buffer,
"\"");
997 strcat(buffer, buf2);
998 strcat(buffer,
"\"\n");
999 strcat(buffer,
" END_OBJECT = EQUATORCROSSINGTIME\n");
1001 strcat(buffer,
" OBJECT = ORBITNUMBER\n");
1002 strcat(buffer,
" CLASS = \"1\"\n");
1003 strcat(buffer,
" NUM_VAL = 1\n");
1004 strcat(buffer,
" VALUE = ");
1005 memset(buf2, 0,
sizeof (buf2));
1006 if ((
i = SDfindattr(sd_id_r,
"ORBITNUMBER")) != -1) {
1007 status = SDreadattr(sd_id_r,
i, &i32);
1008 sprintf(buf2,
"%6d\n", i32);
1009 }
else sprintf(buf2,
"%6d\n", -1);
1010 strcat(buffer, buf2);
1011 strcat(buffer,
" END_OBJECT = ORBITNUMBER\n");
1013 strcat(buffer,
" OBJECT = EQUATORCROSSINGLONGITUDE\n");
1014 strcat(buffer,
" CLASS = \"1\"\n");
1015 strcat(buffer,
" NUM_VAL = 1\n");
1016 strcat(buffer,
" VALUE = ");
1017 memset(buf2, 0,
sizeof (buf2));
1018 if ((
i = SDfindattr(sd_id_r,
"EQUATORCROSSINGLONGITUDE")) != -1) {
1020 sprintf(buf2,
"%8.5f\n",
f32);
1021 }
else sprintf(buf2,
"%8.5f\n", 999.0);
1022 strcat(buffer, buf2);
1023 strcat(buffer,
" END_OBJECT = EQUATORCROSSINGLONGITUDE\n");
1025 strcat(buffer,
" END_OBJECT = ORBITCALCULATEDSPATIALDOMAINCONTAINER\n");
1026 strcat(buffer,
" END_GROUP = ORBITCALCULATEDSPATIALDOMAIN\n");
1028 strcat(buffer,
" GROUP = PGEVERSIONCLASS\n");
1029 strcat(buffer,
" OBJECT = PGEVERSION\n");
1030 strcat(buffer,
" NUM_VAL = 1\n");
1031 strcat(buffer,
" VALUE = ");
1032 strcat(buffer,
"\"4.0.3\"\n");
1033 strcat(buffer,
" END_OBJECT = PGEVERSION\n");
1034 strcat(buffer,
" END_GROUP = PGEVERSIONCLASS\n");
1036 strcat(buffer,
" GROUP = SPATIALDOMAINCONTAINER\n");
1037 strcat(buffer,
" GROUP = HORIZONTALSPATIALDOMAINCONTAINER\n");
1038 strcat(buffer,
" GROUP = GPOLYGON\n");
1039 strcat(buffer,
" OBJECT = GPOLYGONCONTAINER\n");
1040 strcat(buffer,
" CLASS = \"1\"\n");
1042 strcat(buffer,
" GROUP = GRINGPOINT\n");
1043 strcat(buffer,
" CLASS = \"1\"\n");
1044 strcat(buffer,
" OBJECT = GRINGPOINTLONGITUDE\n");
1045 strcat(buffer,
" NUM_VAL= 4\n");
1046 strcat(buffer,
" CLASS = \"1\"\n");
1047 strcat(buffer,
" VALUE = ");
1048 memset(buf2, 0,
sizeof (buf2));
1049 sprintf(buf2,
"(%8.5f, %8.5f, %8.5f, %8.5f)\n", -1., -1., -1., -1.);
1050 strcat(buffer, buf2);
1051 strcat(buffer,
" END_OBJECT= GRINGPOINTLONGITUDE\n");
1053 strcat(buffer,
" OBJECT = GRINGPOINTLATITUDE\n");
1054 strcat(buffer,
" NUM_VAL= 4\n");
1055 strcat(buffer,
" CLASS = \"1\"\n");
1056 strcat(buffer,
" VALUE = ");
1057 memset(buf2, 0,
sizeof (buf2));
1058 sprintf(buf2,
"(%8.5f, %8.5f, %8.5f, %8.5f)\n", -1., -1., -1., -1.);
1059 strcat(buffer, buf2);
1060 strcat(buffer,
" END_OBJECT= GRINGPOINTLATITUDE\n");
1062 strcat(buffer,
" OBJECT = GRINGPOINTSEQUENCENO\n");
1063 strcat(buffer,
" NUM_VAL= 4\n");
1064 strcat(buffer,
" CLASS = \"1\"\n");
1065 strcat(buffer,
" VALUE = ");
1066 memset(buf2, 0,
sizeof (buf2));
1067 sprintf(buf2,
"(%4d, %4d, %4d, %4d)\n", 1, 2, 3, 4);
1068 strcat(buffer, buf2);
1069 strcat(buffer,
" END_OBJECT= GRINGPOINTSEQUENCENO\n");
1070 strcat(buffer,
" END_GROUP = GRINGPOINT\n");
1072 strcat(buffer,
" GROUP = GRING\n");
1073 strcat(buffer,
" CLASS = \"1\"\n");
1074 strcat(buffer,
" OBJECT = EXCLUSIONGRINGFLAG\n");
1075 strcat(buffer,
" NUM_VAL= 1\n");
1076 strcat(buffer,
" CLASS = \"1\"\n");
1077 strcat(buffer,
" VALUE = ");
1078 memset(buf2, 0,
sizeof (buf2));
1079 if ((
i = SDfindattr(sd_id_r,
"EXCLUSIONGRINGFLAG")) != -1)
1080 status = SDreadattr(sd_id_r,
i, buf2);
1081 strcat(buffer,
"\"");
1082 strcat(buffer, buf2);
1083 strcat(buffer,
"\"\n");
1084 strcat(buffer,
" END_OBJECT= EXCLUSIONGRINGFLAG\n");
1085 strcat(buffer,
" END_GROUP = GRING\n");
1086 strcat(buffer,
" END_OBJECT = GPOLYGONCONTAINER\n");
1087 strcat(buffer,
" END_GROUP = GPOLYGON\n");
1088 strcat(buffer,
" END_GROUP = HORIZONTALSPATIALDOMAINCONTAINER\n");
1089 strcat(buffer,
" END_GROUP = SPATIALDOMAINCONTAINER\n");
1091 strcat(buffer,
" GROUP = RANGEDATETIME\n");
1093 strcat(buffer,
" OBJECT = RANGEENDINGDATE\n");
1094 strcat(buffer,
" NUM_VAL = 1\n");
1095 strcat(buffer,
" VALUE = ");
1096 memset(buf2, 0,
sizeof (buf2));
1097 if ((
i = SDfindattr(sd_id_r,
"RANGEENDINGDATE")) != -1)
1098 status = SDreadattr(sd_id_r,
i, buf2);
1099 strcat(buffer,
"\"");
1100 strcat(buffer, buf2);
1101 strcat(buffer,
"\"\n");
1102 strcat(buffer,
" END_OBJECT = RANGEENDINGDATE\n");
1104 strcat(buffer,
" OBJECT = RANGEENDINGTIME\n");
1105 strcat(buffer,
" NUM_VAL = 1\n");
1106 strcat(buffer,
" VALUE = ");
1107 memset(buf2, 0,
sizeof (buf2));
1108 if ((
i = SDfindattr(sd_id_r,
"RANGEENDINGTIME")) != -1)
1109 status = SDreadattr(sd_id_r,
i, buf2);
1110 strcat(buffer,
"\"");
1111 strcat(buffer, buf2);
1112 strcat(buffer,
"\"\n");
1113 strcat(buffer,
" END_OBJECT = RANGEENDINGTIME\n");
1115 strcat(buffer,
" OBJECT = RANGEBEGINNINGDATE\n");
1116 strcat(buffer,
" NUM_VAL = 1\n");
1117 strcat(buffer,
" VALUE = ");
1118 memset(buf2, 0,
sizeof (buf2));
1119 if ((
i = SDfindattr(sd_id_r,
"RANGEBEGINNINGDATE")) != -1)
1120 status = SDreadattr(sd_id_r,
i, buf2);
1121 strcat(buffer,
"\"");
1122 strcat(buffer, buf2);
1123 strcat(buffer,
"\"\n");
1124 strcat(buffer,
" END_OBJECT = RANGEBEGINNINGDATE\n");
1126 strcat(buffer,
" OBJECT = RANGEBEGINNINGTIME\n");
1127 strcat(buffer,
" NUM_VAL = 1\n");
1128 strcat(buffer,
" VALUE = ");
1129 memset(buf2, 0,
sizeof (buf2));
1130 if ((
i = SDfindattr(sd_id_r,
"RANGEBEGINNINGTIME")) != -1)
1131 status = SDreadattr(sd_id_r,
i, buf2);
1132 strcat(buffer,
"\"");
1133 strcat(buffer, buf2);
1134 strcat(buffer,
"\"\n");
1135 strcat(buffer,
" END_OBJECT = RANGEBEGINNINGTIME\n");
1137 strcat(buffer,
" END_GROUP = RANGEDATETIME\n");
1139 strcat(buffer,
" GROUP = ADDITIONALATTRIBUTES\n");
1141 strcat(buffer,
" OBJECT = ADDITIONALATTRIBUTESCONTAINER\n");
1142 strcat(buffer,
" CLASS = \"1\"\n");
1144 strcat(buffer,
" OBJECT = ADDITIONALATTRIBUTENAME\n");
1145 strcat(buffer,
" CLASS = \"1\"\n");
1146 strcat(buffer,
" NUM_VAL = 1\n");
1147 strcat(buffer,
" VALUE = GRANULENUMBER\n");
1148 strcat(buffer,
" END_OBJECT = ADDITIONALATTRIBUTENAME\n");
1150 strcat(buffer,
" END_OBJECT = ADDITIONALATTRIBUTESCONTAINER\n");
1151 strcat(buffer,
" END_GROUP = ADDITIONALATTRIBUTES\n");
1154 strcat(buffer,
" GROUP = CollectionDescriptionClass\n");
1155 strcat(buffer,
" OBJECT = SHORTNAME\n");
1156 strcat(buffer,
" NUM_VAL = 1\n");
1157 strcat(buffer,
" VALUE = ");
1158 strcat(buffer,
"\"MYD01SS\"\n");
1159 strcat(buffer,
" END_OBJECT = SHORTNAME\n");
1160 strcat(buffer,
" END_GROUP = CollectionDescriptionClass\n");
1162 strcat(buffer,
"END_GROUP = INVENTORYMETADATA\n");
1163 strcat(buffer,
"END\n");
1166 status = SDsetattr(sd_id_w,
"CoreMetadata.0", DFNT_CHAR, strlen(buffer) + 1,
1196 float32
a = *((float32 *)
p1);
1197 float32
b = *((float32 *) p2);
1245 if (strncmp(buffer,
"EV", 2) == 0 && masking == 1) {
1246 printf(
"Masking %s\n", buffer);
1247 for (
k = 0;
k < dims[0];
k++) {
1248 if (
k % scan_incr != 0) {
1249 memset(&
data[
k * 2 * dims[1] * dims[2]], 255, 2 * dims[1] * dims[2]);
1252 for (l = 0; l < dims[1]; l++)
1253 for (
i = 0;
i < dims[2];
i++)
1254 if ((
i % pixl_incr) != 0)
1255 memset(&
data[
k * 2 * dims[1] * dims[2] + l * 2 * dims[2] +
i * 2], 255, 2);