10 #define NFIELDS (hsize_t) 28
11 #define NRECORDS (hsize_t) 128
12 #define NAV_GRP "HDFEOS/POINTS/Navigation for GOCI/Data"
13 #define TABLE_NAME "Navigation for GOCI"
16 static int numcomp(
const void *
p1,
const void *p2) {
17 return *(
char *)
p1 - *(
char *) p2;
21 unsigned char *slot_asg, int32_t *slot_nav_avail)
49 slot_nav_str *slot_nav;
54 if ((slot_nav = (slot_nav_str *)
56 printf(
"%s,%d-E Unable to allocate the slot navigation structure\n",
62 size_t nav_size =
sizeof ( slot_nav_str);
63 size_t nav_offset[
NFIELDS] = {HOFFSET(slot_nav_str, band_num),
64 HOFFSET(slot_nav_str, slot_num),
65 HOFFSET(slot_nav_str, rel_time),
66 HOFFSET(slot_nav_str,
sc_att),
67 HOFFSET(slot_nav_str, xo),
68 HOFFSET(slot_nav_str, yo),
69 HOFFSET(slot_nav_str, xs),
70 HOFFSET(slot_nav_str,
ys),
71 HOFFSET(slot_nav_str, xpo),
72 HOFFSET(slot_nav_str, ypo),
73 HOFFSET(slot_nav_str, xps),
74 HOFFSET(slot_nav_str, yps),
75 HOFFSET(slot_nav_str, num_a_parm),
76 HOFFSET(slot_nav_str, a_parm),
77 HOFFSET(slot_nav_str, num_b_parm),
78 HOFFSET(slot_nav_str, b_parm),
79 HOFFSET(slot_nav_str, num_c_parm),
80 HOFFSET(slot_nav_str, c_parm),
81 HOFFSET(slot_nav_str, num_d_parm),
82 HOFFSET(slot_nav_str, d_parm),
83 HOFFSET(slot_nav_str, num_ap_parm),
84 HOFFSET(slot_nav_str, ap_parm),
85 HOFFSET(slot_nav_str, num_bp_parm),
86 HOFFSET(slot_nav_str, bp_parm),
87 HOFFSET(slot_nav_str, num_cp_parm),
88 HOFFSET(slot_nav_str, cp_parm),
89 HOFFSET(slot_nav_str, num_dp_parm),
90 HOFFSET(slot_nav_str, dp_parm)};
92 size_t nav_sizes[
NFIELDS] = {
sizeof ( slot_nav[0].band_num),
93 sizeof ( slot_nav[0].slot_num),
94 sizeof ( slot_nav[0].rel_time),
95 sizeof ( slot_nav[0].
sc_att),
96 sizeof ( slot_nav[0].xo),
97 sizeof ( slot_nav[0].yo),
98 sizeof ( slot_nav[0].xs),
99 sizeof ( slot_nav[0].
ys),
100 sizeof ( slot_nav[0].xpo),
101 sizeof ( slot_nav[0].ypo),
102 sizeof ( slot_nav[0].xps),
103 sizeof ( slot_nav[0].yps),
104 sizeof ( slot_nav[0].num_a_parm),
105 sizeof ( slot_nav[0].a_parm),
106 sizeof ( slot_nav[0].num_b_parm),
107 sizeof ( slot_nav[0].b_parm),
108 sizeof ( slot_nav[0].num_c_parm),
109 sizeof ( slot_nav[0].c_parm),
110 sizeof ( slot_nav[0].num_d_parm),
111 sizeof ( slot_nav[0].d_parm),
112 sizeof ( slot_nav[0].num_ap_parm),
113 sizeof ( slot_nav[0].ap_parm),
114 sizeof ( slot_nav[0].num_bp_parm),
115 sizeof ( slot_nav[0].bp_parm),
116 sizeof ( slot_nav[0].num_cp_parm),
117 sizeof ( slot_nav[0].cp_parm),
118 sizeof ( slot_nav[0].num_dp_parm),
119 sizeof ( slot_nav[0].dp_parm)};
125 int32_t
npix,
nlin, step, nsx, nsy, trg_bnd, ix, iy;
126 int32_t itile, ipix, ilin, lin_st, lin_en, pix_st, pix_en;
127 hsize_t nfields, nrecords,
nbnd, nslot;
128 unsigned char *slot_asg_sml, *bnd_tile_lut, curtil;
129 unsigned char box_pts[4];
131 float min_t, max_t, rel_t;
143 if ((grp_id = H5Gopen1(file_id,
NAV_GRP)) < 0) {
144 printf(
"%s,%d:E Unable to open group: %s\n", __FILE__, __LINE__,
NAV_GRP);
151 if (H5TBget_table_info(grp_id,
TABLE_NAME, &nfields, &nrecords) < 0) {
152 printf(
"%s,%d:E Unable to get table info for: %s\n", __FILE__,
156 printf(
"# fields: %d, # records: %d\n", (
int) nfields, (
int) nrecords);
159 printf(
"%s,%d:W L1B GOCI input file\n does not have %d fields or %d records\n",
164 if (H5TBread_table(grp_id,
TABLE_NAME, nav_size, nav_offset,
165 nav_sizes, slot_nav) < 0) {
166 printf(
"%s,%d:E Unable to read table info for: %s\n", __FILE__,
171 if (*slot_nav_avail == 1) {
175 printf(
"Begin GOCI slot assignment\n");
179 nsx = 2 +
npix / step;
180 nsy = 2 +
nlin / step;
181 if ((slot_asg_sml = (
unsigned char *)
182 malloc(nsx * nsy *
sizeof (
unsigned char))) ==
NULL) {
183 printf(
"%s,%d:E Unable to allocate space for slot_asg_sml array\n",
188 if ((bnd_tile_lut = (
unsigned char *)
189 malloc(
nbnd * nslot *
sizeof (
unsigned char))) ==
NULL) {
190 printf(
"%s,%d:E Unable to allocate space for bnd_tile_lut array\n",
197 for (iy = 0; iy < nsy; iy++) {
199 for (ix = 0; ix < nsx; ix++) {
202 for (itile = 0; itile < 16; itile++) {
204 bnd_tile_lut, &crad);
206 *(slot_asg_sml + ix + nsx * iy) = itile;
212 printf(
"GOCI supergrid made, starting full slot assignment\n");
216 for (iy = 0; iy < (nsy - 1); iy++) {
218 lin_en = (iy + 1) * step;
220 for (ix = 0; ix < (nsx - 1); ix++) {
222 pix_en = (ix + 1) * step;
228 box_pts[0] = *(slot_asg_sml + ix + nsx * iy);
229 box_pts[1] = *(slot_asg_sml + (ix + 1) + nsx * iy);
230 box_pts[2] = *(slot_asg_sml + ix + nsx * (iy + 1));
231 box_pts[3] = *(slot_asg_sml + (ix + 1) + nsx * (iy + 1));
232 qsort(box_pts, 4,
sizeof (
char), numcomp);
234 if (box_pts[0] == box_pts[3]) {
238 for (ilin = lin_st; ilin < lin_en; ilin++)
239 for (ipix = pix_st; ipix < pix_en; ipix++)
240 *(slot_asg + ipix +
npix * ilin) = box_pts[0];
246 for (ilin = lin_st; ilin < lin_en; ilin++) {
247 for (ipix = pix_st; ipix < pix_en; ipix++) {
250 for (itile = 0; itile < 4; itile++) {
251 if (box_pts[itile] != curtil) {
252 curtil = box_pts[itile];
254 nbnd, nslot, bnd_tile_lut, &crad);
256 *(slot_asg + ipix +
npix * ilin) = curtil;
280 for (itile = 0; itile < nslot; itile++) {
283 for (ibnd = 0; ibnd <
nbnd; ibnd++) {
284 ilut = *(bnd_tile_lut + ibnd +
nbnd * itile);
285 rel_t = slot_nav[ilut].rel_time;
286 if (rel_t > max_t) max_t = rel_t;
287 if (rel_t < min_t) min_t = rel_t;
289 slot_rel_time[itile] = (min_t + max_t) / 2.;
291 printf(
"GOCI slot, time assignments completed\n");
303 slot_nav_str *slot_nav, int32_t
nbnd, int32_t nslot,
304 unsigned char *bnd_tile_lut,
float *lindist)
342 int i, num_a_parm, num_b_parm, num_c_parm, num_d_parm;
343 float xo, yo, xs,
ys, *a_parm, *b_parm, *c_parm, *d_parm;
345 double xn, yn, vec[16], xpn, ypn,
numer,
denom;
351 if (*bnd_tile_lut == 254) {
352 for (ilut = 0; ilut < nlut; ilut++)
353 *(bnd_tile_lut + slot_nav[ilut].band_num +
354 nbnd * slot_nav[ilut].slot_num) = ilut;
359 ilut = *(bnd_tile_lut + bnd +
nbnd * itile);
360 xo = slot_nav[ilut].xo;
361 yo = slot_nav[ilut].yo;
362 xs = slot_nav[ilut].xs;
363 ys = slot_nav[ilut].ys;
367 num_a_parm = slot_nav[ilut].num_a_parm;
368 a_parm = slot_nav[ilut].a_parm;
369 num_b_parm = slot_nav[ilut].num_b_parm;
370 b_parm = slot_nav[ilut].b_parm;
371 num_c_parm = slot_nav[ilut].num_c_parm;
372 c_parm = slot_nav[ilut].c_parm;
373 num_d_parm = slot_nav[ilut].num_d_parm;
374 d_parm = slot_nav[ilut].d_parm;
378 xn = ((
double) ipix - (
double) xo) / (
double) xs;
379 yn = ((
double) ilin - (
double) yo) / (
double)
ys;
383 for (
i = 0;
i < nslot;
i++)
389 vec[4] = pow(xn, 2.);
390 vec[5] = pow(yn, 2.);
391 vec[6] = pow(xn, 2.) * yn;
392 vec[7] = pow(yn, 2.) * xn;
393 vec[8] = pow(yn, 2.) * pow(xn, 2.);
395 for (
i = 0,
numer = 0.;
i < num_a_parm;
i++)
397 for (
i = 0,
denom = 1.;
i < num_b_parm;
i++)
398 denom += vec[
i + 1] * b_parm[
i];
403 for (
i = 0,
numer = 0.;
i < num_c_parm;
i++)
405 for (
i = 0,
denom = 1.;
i < num_d_parm;
i++)
406 denom += vec[
i + 1] * d_parm[
i];
420 *lindist = (dist < *lindist) ? dist : *lindist;
423 *lindist = (dist < *lindist) ? dist : *lindist;
426 *lindist = (dist < *lindist) ? dist : *lindist;
429 *lindist = (dist < *lindist) ? dist : *lindist;
432 *lindist = 1. - *lindist;
461 unsigned char p_slot;