117 #define L1ADATA "l1a_data"
152 regen(
char *
infile, int32 *ssamp, int32 *esamp, int32 *srec, int32 *erec,
153 int32 px_sub, int32 sc_sub,
char *parm_list,
char *outfile) {
154 int32 subsc_samps, subsc_recs;
155 int32 ifid, ofid, isdfid, osdfid;
156 int32 xsub = px_sub, ysub = sc_sub;
157 int32 nvgps, nsamp, nrec;
158 int32 max_samp_used, max_rec_used;
159 int32 pix_start, pix_sub;
165 tilt_Type oldtilt_params, newtilt_params;
166 FilemetricsType fm_rec;
169 if ((isdfid = SDstart(
infile, DFACC_RDONLY)) < 0) {
170 sprintf(
ERR_MSG,
"regen: File open unsuccessful");
173 ifid = Hopen(
infile, DFACC_READ, 0);
177 osdfid = SDstart(outfile, DFACC_CREATE);
178 ofid = Hopen(outfile, DFACC_RDWR, 0);
182 if ((nvgps = Hnumber(ifid, DFTAG_VG)) < 0) {
183 sprintf(
ERR_MSG,
"\n No vgps found\n");
204 &subsc_samps, &subsc_recs, &max_samp_used,
212 if ((
dupHDF(ifid, ofid, isdfid, osdfid, ssamp, esamp, srec, erec,
213 xsub, ysub, subsc_samps, subsc_recs, nvgps, parm_list)) < 0)
232 if ((
get_geodata(pix_start, pix_sub, *srec, *ssamp, max_rec_used, subsc_samps,
233 ysub, xsub,
dtype, &nav_rec, &geo_rec)) < 0)
242 if ((
set_tiltdata(osdfid, *srec, max_rec_used, ysub, geo_rec.slat,
243 geo_rec.slon, geo_rec.elat, geo_rec.elon,
244 &oldtilt_params, &newtilt_params)) < 0)
248 if ((strcmp(
title,
"SeaWiFS Level-2 Data") == 0) ||
249 (strcmp(
title,
"SeaWiFS Level-2 Q/C Data") == 0)) {
254 if ((strcmp(
title,
"SeaWiFS Level-1A Data")) == 0)
261 if ((
set_l1adata(isdfid, osdfid, nrec, nsamp, subsc_recs, subsc_samps,
262 *srec, *ssamp, *erec, *esamp, xsub, ysub, &fm_rec)) < 0)
267 if ((
set_globalattrs(outfile, osdfid, l1aflag, subsc_recs, subsc_samps,
268 *ssamp, xsub,
flags, &geo_rec, &fm_rec)) < 0)
319 int32 *ssamp, int32 *esamp, int32 *srec, int32 *erec,
320 int32 *subsc_samps, int32 *subsc_recs, int32 *max_samp_used,
321 int32 *max_rec_used) {
331 if (*ssamp < 0 || *ssamp >= nsamp) {
333 printf(
"\n***** The given start sample is in error");
334 printf(
"\n\tresetting ssamp to zero\n\n");
337 if (*srec < 0 || *srec >= nrec) {
339 printf(
"\n***** The given start record is in error");
340 printf(
"\n\tresetting srec to zero \n\n");
343 if (*esamp >= nsamp || *esamp < *ssamp) {
345 printf(
"\n****** The given end sample is in error ");
346 printf(
"\n\tresetting esamp to nsamp = %d\n\n", nsamp);
349 if (*erec >= nrec || *erec < *srec) {
351 printf(
"\n****** The given end record is in error ");
352 printf(
"\n\tresetting erec to nrec = %d \n\n", nrec);
357 *subsc_recs = ((*erec + 1) - (*srec + 1)) / ysub + 1;
358 *subsc_samps = ((*esamp + 1) - (*ssamp + 1)) / xsub + 1;
364 *max_rec_used = (*subsc_recs - 1) * ysub + *srec;
365 *max_samp_used = (*subsc_samps - 1) * xsub + *ssamp;
392 int32 ndatasets, nglobal_attrs;
403 if ((SDfileinfo(isdfid, &ndatasets, &nglobal_attrs)) < 0)
406 for (
i = 0;
i < nglobal_attrs;
i++) {
407 if ((SDattrinfo(isdfid,
i, &attr_name[
i][0], &numtype[
i], &cnt[
i])) < 0)
410 switch (numtype[
i]) {
413 charbuf = (
char *) calloc(cnt[
i] + 1,
sizeof (
char));
415 charbuf = &char_data[0];
416 if ((SDreadattr(isdfid,
i, charbuf)) < 0) {
418 "get_globalattrs: SDreadattr not successful for attribute %s", attr_name[
i]);
421 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
422 (VOIDP) charbuf)) < 0) {
424 "get_globalattrs: SDsetattr not successful for attribute %s",
432 if ((SDreadattr(isdfid,
i, i32buf)) < 0) {
434 "get_globalattrs: SDreadattr not successful for attribute %s",
438 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
439 (VOIDP) i32buf)) < 0) {
441 "get_globalattrs: SDsetattr not successful for attribute %s",
447 if ((SDreadattr(isdfid,
i, i16buf)) < 0) {
449 "get_globalattrs:SDreadattr not successful for attribute %s", attr_name[
i]);
452 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
453 (VOIDP) i16buf)) < 0) {
455 "get_globalattrs: SDsetattr not successful for attribute %s", attr_name[
i]);
461 if ((SDreadattr(isdfid,
i, i8buf)) < 0) {
463 "get_globalattrs: SDreadattr not successful for attribute %s",
467 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
468 (VOIDP) i8buf)) < 0) {
470 "get_globalattrs: SDsetattr not successful for attribute %s",
476 if ((SDreadattr(isdfid,
i, ui8buf)) < 0) {
478 "get_globalattrs:SDreadattr unsuccessful for attribute %s",
482 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
483 (VOIDP) ui8buf)) < 0) {
485 "get_globalattrs:SDsetattr unsuccessful for attribute %s",
491 if ((SDreadattr(isdfid,
i, f32buf)) < 0) {
493 "get_globalattrs: SDreadattr unsuccessful for attr %s",
497 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
498 (VOIDP) f32buf)) < 0) {
500 "get_globalattrs:SDsetattr unsuccessful for attr %s",
506 if ((SDreadattr(isdfid,
i, f64buf)) < 0) {
508 "get_globalattrs: SDreadattr unsuccessful for attr %s",
512 if ((SDsetattr(osdfid, attr_name[
i], numtype[
i], cnt[
i],
513 (VOIDP) f64buf)) < 0) {
515 "get_globalattrs:SDsetattr unsuccessful for attr %s",
521 sprintf(
ERR_MSG,
"getset_gattrs: Unkown data type - %d\n",
569 int32
dupHDF(int32 ifid, int32 ofid, int32 isdfid, int32 osdfid, int32 *ssamp,
570 int32 *esamp, int32 *srec, int32 *erec, int32 xsub,
571 int32 ysub, int32 subsc_samps, int32 subsc_recs, int32 nvgps,
573 int32
i,
j, n_entries;
574 int32 vref, ivid, ovid;
575 int32 isdsid, osdsid;
577 char vgname[VGNAMELENMAX];
578 char vgclass[VGNAMELENMAX];
581 for (
i = 0;
i < nvgps;
i++) {
582 if ((vref = Vgetid(ifid, vref)) < 0)
584 ivid = Vattach(ifid, vref,
"r");
586 if ((Vinquire(ivid, &n_entries, vgname)) < 0) {
587 printf(
"\nError: Vinquire failed for vid = %d\n", ivid);
590 Vgetclass(ivid, vgclass);
592 if ((strcmp(vgclass,
"Dim0.0") != 0) &&
593 (strcmp(vgclass,
"Var0.0") != 0) &&
594 (strcmp(vgclass,
"CDF0.0") != 0)) {
595 ovid = Vattach(ofid, -1,
"w");
596 Vsetclass(ovid, vgclass);
597 Vsetname(ovid, vgname);
598 if ((Vgettagrefs(ivid, tag_list, ref_list,
MAXVAL)) < 0)
600 for (
j = 0;
j < n_entries;
j++) {
601 switch (tag_list[
j]) {
604 if ((
set_sds(isdfid, osdfid, vgname, ovid, tag_list[
j],
605 ref_list[
j], subsc_samps, subsc_recs, parm_list,
606 &isdsid, &osdsid)) < 0)
return FAIL;
607 if ((
write_data(isdfid, osdfid, isdsid, osdsid, *ssamp, *srec,
608 *esamp, *erec, xsub, ysub)) < 0)
return FAIL;
612 printf(
"\n not processed -- tag = %d", tag_list[
j]);
661 int32
set_sds(int32 isdfid, int32 osdfid,
char *vgname, int32 ovid,
662 int32 tag, int32
ref, int32 subsc_samps, int32 subsc_recs,
663 char *parm_list, int32 *in_sdsid, int32 *out_sdsid) {
665 int32 isdsid, osdsid;
666 int32 sdsref,
rank, num_type, nattrs, attr_nt;
667 int32
count, idim_id, odim_id, dim_count, dim_num, dim_attrs;
668 int32 olddims[3] = {0, 0, 0}, newdims[3] = {0, 0, 0};
669 int32
start[3] = {0, 0, 0}, edge[3] = {0, 0, 0};
671 char dim_name[3][
MAXVAL], buf[100];
674 if ((
index = SDreftoindex(isdfid,
ref)) < 0)
676 isdsid = SDselect(isdfid,
index);
677 if ((ret = SDgetinfo(isdsid, sdsname, &
rank, olddims, &num_type, &nattrs)) < 0)
680 if (((strcmp(vgname,
"Geophysical Data")) == 0) &&
681 ((strcmp(parm_list,
"ALL")) != 0) &&
682 ((strcmp(sdsname,
"l2_flags")) != 0)) {
685 parm = strtok(
str,
" ");
686 while (parm !=
NULL) {
687 if ((strcmp(parm, sdsname)) == 0) {
691 parm = strtok(
NULL,
" ");
701 newdims[
i] = olddims[
i];
702 idim_id = SDgetdimid(isdsid,
i);
703 if ((ret = SDdiminfo(idim_id, dim_name[
i], &dim_count, &dim_num,
704 &dim_attrs)) < 0)
return FAIL;
709 if ((strcmp(dim_name[
i],
"Number of Scan Lines") == 0 ||
710 (strcmp(dim_name[
i],
"rec")) == 0))
711 newdims[
i] = subsc_recs;
712 if ((strcmp(dim_name[
i],
"Pixels per Scan Line") == 0 ||
713 (strcmp(dim_name[
i],
"nsamp")) == 0))
714 newdims[
i] = subsc_samps;
718 if ((osdsid = SDcreate(osdfid, sdsname, num_type,
rank, newdims)) < 0)
721 if ((ret = SDwritedata(osdsid,
start,
NULL, edge, (VOIDP) buf)) < 0)
725 odim_id = SDgetdimid(osdsid,
i);
726 ret = SDsetdimname(odim_id, dim_name[
i]);
734 for (ret = 0,
i = 0; ret >= 0;
i++) {
735 ret = SDattrinfo(isdsid,
i, attr_name, &attr_nt, &
count);
737 if ((
rdattr(isdsid, attr_name, (VOIDP)
str)) < 0) {
738 printf(
"Error: Unsuccessful reading attribute:%s", attr_name);
741 if ((SDsetattr(osdsid, attr_name, attr_nt,
count, (VOIDP)
str)) < 0) {
742 printf(
"Error: Unsuccessful writing attribute %s", attr_name);
749 if ((sdsref = SDidtoref(osdsid)) < 0)
return FAIL;
750 if ((Vaddtagref(ovid, tag, sdsref)) < 0)
return FAIL;
788 int32
write_data(int32 isdfid, int32 osdfid, int32 isdsid, int32 osdsid,
789 int32 ssamp, int32 srec, int32 esamp, int32 erec,
790 int32 xsub, int32 ysub) {
793 int32
rank, num_type, nattrs;
794 int32 idims[3] = {0, 0, 0}, odims[3] = {0, 0, 0};
795 int32 istart[3] = {0, 0, 0}, iedge[3] = {1, 1, 1};
796 int32 ostart[3] = {0, 0, 0}, oedge[3] = {1, 1, 1};
798 int32 *ii32p, *oi32p;
799 int16 *ii16p, *oi16p;
801 uint8 *iui8p, *oui8p;
802 float32 *if32p, *of32p;
803 float64 *if64p, *of64p;
804 char *icharp, *ocharp;
806 if ((SDgetinfo(isdsid, sdsname, &
rank, idims, &num_type, &nattrs)) < 0)
809 if ((SDgetinfo(osdsid, sdsname, &
rank, odims, &num_type, &nattrs)) < 0)
812 if (strcmp(sdsname,
L1ADATA) == 0)
822 if ((icharp = (
char *) calloc(iedge[0] * iedge[1] * iedge[2],
823 sizeof (
char))) ==
NULL)
825 if ((ocharp = (
char *) calloc(oedge[0] * oedge[1] * oedge[2],
826 sizeof (
char))) ==
NULL)
829 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) icharp)) < 0)
832 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
834 ssamp, esamp, xsub, ysub, icharp, ocharp);
836 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) ocharp)) < 0)
839 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) icharp)) < 0)
848 if ((ii32p = (int32 *) calloc(iedge[0] * iedge[1] * iedge[2],
849 sizeof (int32))) ==
NULL)
851 if ((oi32p = (int32 *) calloc(oedge[0] * oedge[1] * oedge[2],
852 sizeof (int32))) ==
NULL)
855 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) ii32p)) < 0)
858 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
860 ssamp, esamp, xsub, ysub, ii32p, oi32p);
862 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) oi32p)) < 0)
865 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) ii32p)) < 0)
874 if ((ii16p = (
int16 *) calloc(iedge[0] * iedge[1] * iedge[2],
877 if ((oi16p = (
int16 *) calloc(oedge[0] * oedge[1] * oedge[2],
881 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) ii16p)) < 0)
884 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
886 ssamp, esamp, xsub, ysub, ii16p, oi16p);
887 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) oi16p)) < 0)
890 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) ii16p)) < 0)
898 if ((ii8p = (int8 *) calloc(iedge[0] * iedge[1] * iedge[2],
899 sizeof (int8))) ==
NULL)
901 if ((oi8p = (int8 *) calloc(oedge[0] * oedge[1] * oedge[2],
902 sizeof (int8))) ==
NULL)
905 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) ii8p)) < 0)
908 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
910 ssamp, esamp, xsub, ysub, ii8p, oi8p);
912 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) oi8p)) < 0)
915 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) ii8p)) < 0)
922 if ((iui8p = (uint8 *) calloc(iedge[0] * iedge[1] * iedge[2],
923 sizeof (uint8))) ==
NULL)
925 if ((oui8p = (uint8 *) calloc(oedge[0] * oedge[1] * oedge[2],
926 sizeof (uint8))) ==
NULL)
929 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) iui8p)) < 0)
932 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
934 ssamp, esamp, xsub, ysub, iui8p, oui8p);
936 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) oui8p)) < 0)
939 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) iui8p)) < 0)
947 if ((if32p = (float32 *) calloc(iedge[0] * iedge[1] * iedge[2],
948 sizeof (float32))) ==
NULL)
950 if ((of32p = (float32 *) calloc(oedge[0] * oedge[1] * oedge[2],
951 sizeof (float32))) ==
NULL)
954 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) if32p)) < 0)
957 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
959 ssamp, esamp, xsub, ysub, if32p, of32p);
961 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) of32p)) < 0)
964 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) if32p)) < 0)
973 if ((if64p = (float64 *) calloc(iedge[0] * iedge[1] * iedge[2],
974 sizeof (float64))) ==
NULL)
976 if ((of64p = (float64 *) calloc(oedge[0] * oedge[1] * oedge[2],
977 sizeof (float64))) ==
NULL)
980 if ((
rdslice(isdfid, sdsname, istart, idims, (VOIDP) if64p)) < 0)
983 if ((idims[0] != odims[0]) || (idims[1] != odims[1])) {
985 ssamp, esamp, xsub, ysub, if64p, of64p);
987 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) of64p)) < 0)
990 if ((
update_sds(osdfid, sdsname, ostart, odims, (VOIDP) if64p)) < 0)
999 "write_data: sds %s not processed - unkonwn data type - %d",
1040 int32 srec, int32 erec, int32 ssamp, int32 esamp,
1041 int32 xsub, int32 ysub,
void *ibuf,
void *obuf) {
1049 subsc_recs = ((erec + 1) - (srec + 1)) / ysub + 1;
1053 maxrec = (subsc_recs - 1) * ysub + srec;
1055 if (idims[1] == odims[1]) {
1056 if ((
subsamp_rec(srec, maxrec,
rank, odims, ysub, num_type, ibuf, obuf))
1059 subsamp_2D(ssamp, srec, esamp, erec, idims[1], xsub, ysub, num_type,
1087 int32
rdattr(int32 sdfid,
char *attr_name,
void *buf) {
1090 attrnum = SDfindattr(sdfid, attr_name);
1091 if ((SDreadattr(sdfid, attrnum, buf)) < 0) {
1092 sprintf(
ERR_MSG,
"rdattr: SDreadattr not successful for attribute %s",
1127 int32
index, sdsid,
rank, num_type, nattrs;
1132 if ((
index = SDnametoindex(sdfid,
name)) < 0) {
1133 sprintf(
ERR_MSG,
"rdslice: Cannot locate sds \"%s\" ",
name);
1136 if ((sdsid = SDselect(sdfid,
index)) < 0) {
1137 sprintf(
ERR_MSG,
"rdslice: SDselect failed for sds \"%s\" ",
name);
1141 if (edge[0] == 0 && edge[1] == 0 && edge[2] == 0)
1142 if ((SDgetinfo(sdsid, sdsname, &
rank, edge, &num_type, &nattrs)) < 0)
1147 if ((SDreaddata(sdsid,
start,
NULL, edge, buf)) < 0) {
1149 "rdslice: SDreaddata error while reading \"%s\" ",
name);
1190 int32
rank, num_type, nattrs;
1193 if ((
index = SDnametoindex(sdfid,
name)) < 0) {
1194 sprintf(
ERR_MSG,
"update_sds: Cannot locate sds \"%s\" ",
name);
1197 if ((sdsid = SDselect(sdfid,
index)) < 0) {
1198 sprintf(
ERR_MSG,
"update_sds: SDselect failed for sds \"%s\" ",
name);
1202 if (edge[0] == 0 && edge[1] == 0 && edge[2] == 0)
1203 if ((SDgetinfo(sdsid, sdsname, &
rank, edge, &num_type, &nattrs)) < 0)
1206 if ((SDwritedata(sdsid,
start,
NULL, edge, buf)) < 0) {
1208 "update_sds: SDwritedata error while writing \"%s\" ",
name);
1239 if ((geo_rec->slat = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1242 if ((geo_rec->slon = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1245 if ((geo_rec->elat = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1248 if ((geo_rec->elon = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1251 if ((geo_rec->clat = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1254 if ((geo_rec->clon = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1257 if ((geo_rec->csol_z = (float32 *) calloc(nrec,
sizeof (float32))) ==
NULL)
1283 free(geo_rec->slat);
1284 free(geo_rec->slon);
1285 free(geo_rec->elat);
1286 free(geo_rec->elon);
1287 free(geo_rec->clat);
1288 free(geo_rec->clon);
1289 free(geo_rec->csol_z);
1326 int32
get_geodata(int32 pix_start, int32 pix_sub, int32 srec, int32 ssamp,
1327 int32 max_rec_used, int32 subsc_samps, int32 ysub, int32 xsub,
1328 char *
dtype, NavType *nav_rec, GeoType *geo_rec) {
1330 int32
i,
j,
k, row, col, rec,
scan, st_px, px_sub,
npix;
1333 float32
pos[3], smat[3][3], coef[6], sunref[3];
1335 if (strcmp(
dtype,
"GAC") == 0) {
1336 st_px = pix_start + ssamp * 4;
1337 px_sub = ((subsc_samps - 1) * xsub * pix_sub) / 2;
1339 st_px = pix_start + ssamp;
1340 px_sub = ((subsc_samps - 1) * xsub * pix_sub) / 2;
1348 for (
scan = 0, rec = srec; rec <= max_rec_used; rec += ysub,
scan++) {
1349 for (
j = rec * 3, row = 0; row < 3; row++,
j++) {
1350 pos[row] = nav_rec->orb_vec[
j];
1351 sunref[row] = nav_rec->sun_ref[
j];
1352 for (
k =
j * 3, col = 0; col < 3; col++,
k++)
1353 smat[row][col] = nav_rec->sen_mat[
k];
1356 for (
i = rec * 6, row = 0; row < 6; row++,
i++)
1357 coef[row] = nav_rec->scan_ell[
i];
1399 int32
start[3] = {0, 0, 0}, edge[3] = {0, 0, 0};
1447 int32
start[3] = {0, 0, 0}, edge[3];
1449 edge[0] = edge[1] = edge[2] = 0;
1453 edge[0] = edge[1] = edge[2] = 0;
1457 edge[0] = edge[1] = edge[2] = 0;
1461 edge[0] = edge[1] = edge[2] = 0;
1465 edge[0] = edge[1] = edge[2] = 0;
1504 float32 *slatrec, float32 *slonrec, float32 *elatrec,
1505 float32 *elonrec, tilt_Type *old_tiltrec,
1506 tilt_Type *new_tiltrec) {
1508 int16 lsrec, oranges[20][2], nranges[20][2];
1509 int32 oi, ni, ontilts, erange, subsc_recs;
1510 int32 slat = 0, elat = 1, sscan = 0, escan = 1;
1511 int32 slon = 0, elon = 1;
1512 int32 edge[3] = {0, 0, 0},
start[3] = {0, 0, 0};
1514 subsc_recs = ((erec + 1) - (srec + 1)) / ysub + 1;
1516 new_tiltrec->ntilts = 0;
1517 for (
i = 0;
i < 20;
i++) {
1518 new_tiltrec->tilt_flags[
i] = 0;
1519 new_tiltrec->tilt_ranges[
i][0] = 0;
1520 new_tiltrec->tilt_ranges[
i][1] = 0;
1521 for (
j = 0;
j < 2;
j++) {
1522 for (
k = 0;
k < 2;
k++) {
1523 new_tiltrec->tilt_lats[
i][
j][
k] = 0;
1524 new_tiltrec->tilt_lons[
i][
j][
k] = 0;
1529 for (
i = 0;
i < 20;
i++)
1530 for (
j = 0;
j < 2;
j++)
1531 oranges[
i][
j] = nranges[
i][
j] = 0;
1535 ontilts = old_tiltrec->ntilts;
1537 for (
i = 0;
i < ontilts;
i++)
1538 for (
j = 0;
j < 2;
j++)
1539 oranges[
i][
j] = old_tiltrec->tilt_ranges[
i][
j];
1541 for (ni = 0, oi = 0; ((oi < ontilts) && (lsrec > oranges[oi][1])); oi++)
1545 if (erec <= oranges[oi][1]) {
1546 nranges[ni][1] = subsc_recs;
1547 new_tiltrec->tilt_flags[ni] = old_tiltrec->tilt_flags[oi];
1548 new_tiltrec->ntilts++;
1550 if (oranges[oi][1] == oranges[oi][0])
1551 nranges[ni][1] = oranges[oi][1];
1553 nranges[ni][1] = ((oranges[oi][1] - lsrec) / ysub + 1);
1554 nranges[ni + 1][0] = nranges[ni][1] + 1;
1555 new_tiltrec->tilt_flags[ni] = old_tiltrec->tilt_flags[oi];
1556 new_tiltrec->ntilts++;
1557 for (++ni, ++oi; oi < ontilts; oi++) {
1558 nranges[ni][0] = nranges[ni - 1][1] + 1;
1559 if (erec >= oranges[oi][0]) {
1560 if (erec <= oranges[oi][1]) {
1561 nranges[ni][1] = subsc_recs;
1562 new_tiltrec->tilt_flags[ni] = old_tiltrec->tilt_flags[oi];
1563 new_tiltrec->ntilts++;
1566 erange = (oranges[oi][1] - oranges[oi][0]);
1567 if (erange >= ysub) {
1568 erange = erange / ysub;
1569 nranges[ni][1] = nranges[oi][0] + erange;
1570 new_tiltrec->tilt_flags[ni] = old_tiltrec->tilt_flags[oi];
1571 new_tiltrec->ntilts++;
1578 for (
i = 0;
i < new_tiltrec->ntilts;
i++)
1579 for (
j = 0;
j < 2;
j++)
1580 new_tiltrec->tilt_ranges[
i][
j] = nranges[
i][
j];
1582 for (
i = 0;
i < new_tiltrec->ntilts;
i++) {
1583 new_tiltrec->tilt_lats[
i][sscan][slat] = slatrec[nranges[
i][0] - 1];
1584 new_tiltrec->tilt_lats[
i][sscan][elat] = elatrec[nranges[
i][0] - 1];
1586 new_tiltrec->tilt_lats[
i][escan][slat] = slatrec[nranges[
i][1] - 1];
1587 new_tiltrec->tilt_lats[
i][escan][elat] = elatrec[nranges[
i][1] - 1];
1589 new_tiltrec->tilt_lons[
i][sscan][slon] = slonrec[nranges[
i][0] - 1];
1590 new_tiltrec->tilt_lons[
i][sscan][elon] = elonrec[nranges[
i][0] - 1];
1592 new_tiltrec->tilt_lons[
i][escan][slon] = slonrec[nranges[
i][1] - 1];
1593 new_tiltrec->tilt_lons[
i][escan][elon] = elonrec[nranges[
i][1] - 1];
1596 edge[0] = edge[1] = edge[2] = 0;
1598 (VOIDP) & new_tiltrec->ntilts)) < 0)
return FAIL;
1600 edge[0] = edge[1] = edge[2] = 0;
1602 (VOIDP) new_tiltrec->tilt_flags)) < 0)
return FAIL;
1604 edge[0] = edge[1] = edge[2] = 0;
1606 (VOIDP) new_tiltrec->tilt_ranges)) < 0)
return FAIL;
1608 edge[0] = edge[1] = edge[2] = 0;
1610 (VOIDP) new_tiltrec->tilt_lats)) < 0)
return FAIL;
1612 edge[0] = edge[1] = edge[2] = 0;
1614 (VOIDP) new_tiltrec->tilt_lons)) < 0)
return FAIL;
1646 int32
i,
j,
start[3] = {0, 0, 0}, edge[3] = {0, 0, 0};
1650 if ((l2flags = (
int16 *) calloc(nrec * nsamp,
sizeof (
int16))) ==
NULL)
1656 for (
flags[0] = 0, masks[0] = 1,
i = 1;
i < 16;
i++) {
1657 masks[
i] = (masks[
i - 1] * 2);
1661 for (
i = 0;
i < nrec * nsamp;
i++)
1662 for (
j = 0;
j < 16;
j++) {
1663 if ((l2flags[
i] & masks[
j]) == masks[
j])
1692 if ((nav_rec->orb_vec = (float32 *) calloc(nrec * 3,
sizeof (float32))) ==
NULL)
1695 if ((nav_rec->l_vert = (float32 *) calloc(nrec * 3,
sizeof (float32))) ==
NULL)
1698 if ((nav_rec->sun_ref = (float32 *) calloc(nrec * 3,
sizeof (float32))) ==
NULL)
1701 if ((nav_rec->att_ang = (float32 *) calloc(nrec * 3,
sizeof (float32))) ==
NULL)
1704 if ((nav_rec->sen_mat = (float32 *) calloc(nrec * 3 * 3,
sizeof (float32))) ==
NULL)
1707 if ((nav_rec->scan_ell = (float32 *) calloc(nrec * 6,
sizeof (float32))) ==
NULL)
1710 if ((nav_rec->nflag = (int32 *) calloc(nrec * 8,
sizeof (int32))) ==
NULL)
1742 int32
start[3] = {0, 0, 0}, edge[3] = {0, 0, 0};
1817 free(nav_rec->orb_vec);
1818 free(nav_rec->l_vert);
1819 free(nav_rec->sun_ref);
1820 free(nav_rec->att_ang);
1821 free(nav_rec->sen_mat);
1822 free(nav_rec->scan_ell);
1823 free(nav_rec->nflag);
1857 int32 ysub, int32 nt,
void *obuf,
void *nbuf) {
1858 int32
i,
j, nv, ni, oi;
1859 int32 *i32_obuf, *i32_nbuf;
1860 int16 *i16_obuf, *i16_nbuf;
1861 uint8 *ui8_obuf, *ui8_nbuf;
1862 float32 *f32_obuf, *f32_nbuf;
1865 for (nv = 1,
i = 1;
i <
rank;
i++)
1868 for (ni = 0, oi = nv * srec; oi <= maxrec * nv; oi += ysub * nv) {
1870 i32_obuf = (int32 *) obuf;
1871 i32_nbuf = (int32 *) nbuf;
1872 for (
j = 0;
j < nv;
j++)
1873 i32_nbuf[ni++] = i32_obuf[oi +
j];
1876 i16_obuf = (
int16 *) obuf;
1877 i16_nbuf = (
int16 *) nbuf;
1878 for (
j = 0;
j < nv;
j++)
1879 i16_nbuf[ni++] = i16_obuf[oi +
j];
1881 if (nt == DFNT_UINT8) {
1882 ui8_obuf = (uint8 *) obuf;
1883 ui8_nbuf = (uint8 *) nbuf;
1884 for (
j = 0;
j < nv;
j++)
1885 ui8_nbuf[ni++] = ui8_obuf[oi +
j];
1888 f32_obuf = (float32 *) obuf;
1889 f32_nbuf = (float32 *) nbuf;
1890 for (
j = 0;
j < nv;
j++)
1891 f32_nbuf[ni++] = f32_obuf[oi +
j];
1930 int32 xsub, int32 ysub, int32 nt,
void *inbuf,
void *outbuf) {
1931 int32 newrec, rec, px, newpx, newrow,
npix = xdim;
1932 int32 max_rec_used, subsc_samps, subsc_recs;
1933 int32 *i32_obuf, *i32_ibuf;
1934 int16 *i16_obuf, *i16_ibuf;
1935 uint8 *ui8_obuf, *ui8_ibuf;
1936 float32 *f32_obuf, *f32_ibuf;
1940 subsc_recs = ((escan + 1) - (sscan + 1)) / ysub + 1;
1941 subsc_samps = ((
epix + 1) - (
spix + 1)) / xsub + 1;
1946 max_rec_used = (subsc_recs - 1) * ysub + sscan;
1951 i32_obuf = (int32 *) outbuf;
1952 i32_ibuf = (int32 *) inbuf;
1953 for (newrec = 0, rec = sscan; rec <= max_rec_used; rec += ysub, newrec++) {
1954 newrow = newrec * subsc_samps;
1955 for (px = rec *
npix + (
spix), newpx = newrow;
1956 newpx < newrow + subsc_samps; px += xsub, newpx++) {
1957 i32_obuf[newpx] = i32_ibuf[px];
1962 i16_obuf = (
int16 *) outbuf;
1963 i16_ibuf = (
int16 *) inbuf;
1964 for (newrec = 0, rec = sscan; rec <= max_rec_used; rec += ysub, newrec++) {
1965 newrow = newrec * subsc_samps;
1966 for (px = rec *
npix + (
spix), newpx = newrow;
1967 newpx < newrow + subsc_samps; px += xsub, newpx++) {
1968 i16_obuf[newpx] = i16_ibuf[px];
1972 if (nt == DFNT_UINT8) {
1973 ui8_obuf = (uint8 *) outbuf;
1974 ui8_ibuf = (uint8 *) inbuf;
1975 for (newrec = 0, rec = sscan; rec <= max_rec_used;
1976 rec += ysub, newrec++) {
1977 newrow = newrec * subsc_samps;
1978 for (px = rec *
npix + (
spix), newpx = newrow;
1979 newpx < newrow + subsc_samps; px += xsub, newpx++) {
1980 ui8_obuf[newpx] = ui8_ibuf[px];
1985 f32_obuf = (float32 *) outbuf;
1986 f32_ibuf = (float32 *) inbuf;
1987 for (newrec = 0, rec = sscan; rec <= max_rec_used;
1988 rec += ysub, newrec++) {
1989 newrow = newrec * subsc_samps;
1990 for (px = rec *
npix + (
spix), newpx = newrow;
1991 newpx < newrow + subsc_samps; px += xsub, newpx++) {
1992 f32_obuf[newpx] = f32_ibuf[px];
2039 set_l1adata(int32 isdfid, int32 osdfid, int32 num_recs, int32 num_samps,
2040 int32 subsc_recs, int32 subsc_samps, int32 srec, int32 ssamp,
2041 int32 erec, int32 esamp, int32 xsub, int32 ysub,
2042 FilemetricsType *fm_rec) {
2043 int32 nsamp, nrec, last_rec_used, new_buf_recs;
2044 int32 old_start[3] = {0, 0, 0}, new_start[3] = {0, 0, 0};
2045 int32 old_edge[3], new_edge[3], rd_recs, buf_srec, buf_erec;
2047 int16 *s_satp, *s_zerop;
2048 int32
start[3] = {0, 0, 0}, edge[3];
2054 old_edge[1] = nsamp;
2057 new_edge[0] = subsc_recs;
2058 new_edge[1] = subsc_samps;
2074 edge[0] = edge[1] = edge[2] = 0;
2078 edge[0] = edge[1] = edge[2] = 0;
2082 nrec = erec - srec + 1;
2083 old_start[0] = srec;
2094 sprintf(
ERR_MSG,
"Calloc error - cannot allocate memory for reading %s",
2102 sprintf(
ERR_MSG,
"calloc error - cannot allocate memory for writing %s",
2107 while (rd_recs > 0) {
2108 old_edge[0] = rd_recs;
2109 if ((
rdslice(isdfid,
L1ADATA, old_start, old_edge, (VOIDP) inbuf)) < 0)
2112 buf_erec = rd_recs - 1;
2113 last_rec_used =
subsamp_l1adata(buf_srec, buf_erec, ssamp, esamp, xsub,
2115 s_satp, s_zerop, &new_buf_recs);
2116 old_start[0] += ysub + last_rec_used;
2117 nrec -= last_rec_used + ysub;
2121 if (new_start[0] == -1) {
2123 new_edge[0] = new_buf_recs;
2125 new_start[0] += new_edge[0];
2126 new_edge[0] = new_buf_recs;
2132 new_start[0] = new_start[1] = new_start[2] = 0;
2133 new_edge[0] = subsc_recs;
2136 if ((
update_sds(osdfid,
SSATP, new_start, new_edge, (VOIDP) s_satp)) < 0)
2138 if ((
update_sds(osdfid,
SZEROP, new_start, new_edge, (VOIDP) s_zerop)) < 0)
2188 int32 xsub, int32 ysub, int32 nsamp,
int16 *
gain,
2191 int16 *s_zerop, int32 *new_buf_recs) {
2192 int32 rec_sz,
band, px_index, out_index, rec, rec_index;
2193 int32 subsc_recs, subsc_samps;
2195 int32 last_rec_used, last_samp_used;
2198 static int32 first_call = 1, gn_index;
2204 fm_rec->satg1[
i] = fm_rec->satg2[
i] = 0;
2205 fm_rec->nsatg1[
i] = fm_rec->nsatg2[
i] = 0;
2206 fm_rec->zeroes[
i] = 0;
2207 fm_rec->meanr1[
i] = fm_rec->meanr2[
i] = 0;
2208 gn1px[
i] = gn2px[
i] = 0;
2209 gainr1[
i] = gainr2[
i] = 0;
2213 *new_buf_recs = subsc_recs = ((erec + 1) - (srec + 1)) / ysub + 1;
2214 subsc_samps = ((esamp + 1) - (ssamp + 1)) / xsub + 1;
2216 last_rec_used = (subsc_recs - 1) * ysub + srec;
2217 last_samp_used = (subsc_samps - 1) * xsub + ssamp;
2220 for (out_index = 0, rec = srec; rec <= last_rec_used;
2221 rec += ysub, gn_index++) {
2222 rec_index = rec * rec_sz;
2223 for (px_index = rec_index + (ssamp *
NBANDS);
2224 px_index <= (rec_index + last_samp_used *
NBANDS);
2225 px_index += (xsub *
NBANDS)) {
2227 radiance = outbuf[out_index++] = inbuf[px_index +
band];
2229 gainr1[
band] += radiance;
2231 if (radiance >= 1023) {
2233 fm_rec->satg1[
band]++;
2235 fm_rec->nsatg1[
band]++;
2238 gainr2[
band] += radiance;
2240 if (radiance >= 1023) {
2241 s_satp[gn_index +
band]++;
2242 fm_rec->satg2[
band]++;
2244 fm_rec->nsatg2[
band]++;
2248 fm_rec->zeroes[
band]++;
2254 if (gn1px[
band] > 0)
2256 if (gn2px[
band] > 0)
2260 return last_rec_used;
2297 int32 nsamp, int32 ssamp, int32 xsub, int32 *
flags,
2298 GeoType *geo_rec, FilemetricsType *fm_rec) {
2301 int16 subsc_syear, subsc_sday, subsc_eyear, subsc_eday;
2303 int32
i, rec, cmsec, FSlines = 0;
2304 int32 *
msec, cscan, *nflag, xfirst, xlast, xcenter;
2305 int32
start[3] = {0, 0, 0}, edge[3] = {0, 0, 0};
2306 div_t quot1, quot2, quot3;
2307 char string[
MAXVAL], ptime[17], *prod_name;
2308 float32 maxlat = -999, minlat = 999, maxlon = -999, minlon = 999;
2309 float32 pct_flags[16];
2312 if ((
msec = (int32 *) calloc(nrec,
sizeof (int32))) ==
NULL)
2318 if ((s_flags = (uint8 *) calloc(nrec * 4,
sizeof (uint8))) ==
NULL)
2321 edge[0] = edge[1] = edge[2] = 0;
2328 if ((nflag = (int32 *) calloc(nrec * 8,
sizeof (int32))) ==
NULL)
2331 edge[0] = edge[1] = edge[2] = 0;
2356 cscan = (nrec + 1) / 2;
2357 cmsec = (
msec[cscan - 1]);
2362 subsc_syear =
eyear;
2364 subsc_eyear =
eyear;
2367 subsc_syear =
syear;
2370 subsc_eyear =
eyear;
2373 subsc_eyear =
syear;
2383 quot2 = div(quot1.rem,
MSECMIN);
2384 quot3 = div(quot2.rem,
MSECSEC);
2385 sprintf(
string,
"%4.4d%3.3d%2.2d%2.2d%2.2d%3.3d", subsc_syear,
2386 subsc_sday, quot1.quot, quot2.quot, quot3.quot, quot3.rem);
2387 SDsetattr(sdfid,
"Start Time", DFNT_CHAR, strlen(
string) + 1,
2390 quot2 = div(quot1.rem,
MSECMIN);
2391 quot3 = div(quot2.rem,
MSECSEC);
2392 sprintf(
string,
"%4.4d%3.3d%2.2d%2.2d%2.2d%3.3d", subsc_eyear,
2393 subsc_eday, quot1.quot, quot2.quot, quot3.quot, quot3.rem);
2394 SDsetattr(sdfid,
"End Time", DFNT_CHAR, strlen(
string) + 1,
2404 dyear = subsc_syear;
2406 if (subsc_sday != subsc_eday || subsc_syear != subsc_eyear) {
2407 if (cmsec < 43200000) {
2409 dyear = subsc_eyear;
2413 quot2 = div(quot1.rem,
MSECMIN);
2414 quot3 = div(quot2.rem,
MSECSEC);
2415 sprintf(
string,
"%4.4d%3.3d%2.2d%2.2d%2.2d%3.3d", dyear, dday,
2416 quot1.quot, quot2.quot, quot3.quot, quot3.rem);
2417 SDsetattr(sdfid,
CTIME, DFNT_CHAR, strlen(
string) + 1,
2426 pix_start = pix_start + (ssamp * pix_sub);
2429 pix_sub = pix_sub * xsub;
2433 for (
i = 0;
i < 16;
i++) {
2435 pct_flags[
i] =
flags[
i] / (nsamp * nrec * 1.0) * 100;
2463 xcenter = cscan - 1;
2464 for (
i = 0;
i < nrec;
i++) {
2465 if (nflag[
i * 8] == 0) {
2473 xcenter = (xlast + xfirst) / 2;
2474 while ((xcenter > xfirst) && (nflag[xcenter * 8]) != 0)
2482 xcenter = (nrec + 1) / 2;
2483 printf(
"\nWarning - No good navigation record found for the data extracted\n");
2497 for (rec = 0; rec < nrec; rec++) {
2498 if (geo_rec->slat[rec] > maxlat)
2499 maxlat = geo_rec->slat[rec];
2500 if (geo_rec->elat[rec] < minlat)
2501 minlat = geo_rec->elat[rec];
2504 if (s_flags[rec * 4 + 1] > 0)
2509 if ((geo_rec->slon[0] < 0) && (geo_rec->slon[nrec - 1] >= 0)) {
2510 for (rec = 0; rec < nrec; rec++) {
2511 if ((geo_rec->slon[rec] < minlon) && (geo_rec->slon[rec] > 0))
2512 minlon = geo_rec->slon[rec];
2513 if ((geo_rec->elon[rec] > maxlon) && (geo_rec->elon[rec] < 0))
2514 maxlon = geo_rec->elon[rec];
2517 for (rec = 0; rec < nrec; rec++) {
2518 if (geo_rec->slon[rec] < minlon)
2519 minlon = geo_rec->slon[rec];
2520 if (geo_rec->elon[rec] > maxlon)
2521 maxlon = geo_rec->elon[rec];
2543 SDsetattr(sdfid,
PTIME, DFNT_CHAR, strlen(ptime) + 1, (VOIDP) ptime);
2545 if ((prod_name = strrchr(outfile,
'/')) !=
NULL)
2548 prod_name = outfile;
2549 SDsetattr(sdfid,
PROD_NAME, DFNT_CHAR, strlen(prod_name) + 1, (VOIDP) prod_name);