9 int viirs_oxt(ctl_struc *ctl, in_rec_struc *in_rec)
27 static int oxt_init = 0, n_vis_asg = 7;
28 static int vis_asg[] = {1, 3, 5, 7, 10, 12, 14}, ib_status[
N_INT_RNG];
31 int irng, last_ib2, last_ib, iend, ib_targ, ib_ct, ib_pair[2];
33 int loc1, loc2, ilin, ipix;
34 float rad0, rad1, rad2, lam0, lam1, lam2, r_bnd1, r_bnd2, rfill;
42 printf(
"OXT parms:\n");
43 printf(
"oxt_mode = %d\n", ctl->oxt_mode);
44 printf(
"oxt_coef = %s\n", ctl->oxt_coef);
45 printf(
"inter_band = %s\n", ctl->inter_band);
54 for (irng = 0; irng <
N_INT_RNG; irng++) {
55 if ((ib_field[irng] = (
float *)
56 malloc(in_rec->npix *
NDET * sizeof (
float))) ==
NULL) {
57 printf(
"%s, %d: unable to allocate interband field storage\n",
68 for (irng = 0; irng < n_vis_asg; irng++)
69 ib_status[ vis_asg[irng] ] = 1;
79 for (irng = 0; irng <
N_INT_RNG; irng++) {
80 if (ib_status[irng] == 0) {
92 if (ib_status[ib_targ] == 1) ib_pair[ib_ct++] = ib_targ;
93 if (ib_ct == 2) iend = 1;
99 if ((last_ib != -1) && (ib_ct >= 1)) {
100 ib_pair[1] = ib_pair[0];
101 ib_pair[0] = last_ib;
102 }
else if ((ib_ct == 0) && (last_ib2 != -1)) {
103 ib_pair[0] = last_ib2;
104 ib_pair[1] = last_ib;
105 }
else if ((ib_ct == 2) && (last_ib == -1)) {
108 printf(
"%s, %d: insufficient data to interpolate\n",
112 int_low_loc[irng] = ib_pair[0];
113 int_hi_loc[irng] = ib_pair[1];
124 in_loc = in_rec->margin[0] * in_rec->npix;
125 nval =
sizeof (
float) * in_rec->npix *
NDET;
126 for (irng = 0; irng < n_vis_asg; irng++) {
127 memcpy(ib_field[vis_asg[irng]], in_rec->bnd_lt[irng] + in_loc, nval);
133 for (ilin = 0; ilin <
NDET; ilin++)
134 for (ipix = 0; ipix < in_rec->npix; ipix++)
135 for (irng = 0; irng <
N_INT_RNG; irng++) {
136 if (ib_status[irng] == 0) {
137 loc1 = int_low_loc[irng];
138 loc2 = int_hi_loc[irng];
145 r_bnd1 = *(ib_field[loc1] + ipix + ilin * in_rec->npix);
146 r_bnd2 = *(ib_field[loc2] + ipix + ilin * in_rec->npix);
147 rfill = rad0 / (lam2 - lam1) *
148 (r_bnd1 * (lam2 - lam0) / rad1 +
149 r_bnd2 * (lam0 - lam1) / rad2);
150 *(ib_field[irng] + ipix + ilin * in_rec->npix) = rfill;
189 int items_set[
N_INT_RNG * 2], ipar, ip1, ip2;
192 char *ib_par_nm[] = {
"CW_WAVE",
"AV_RAD"};
193 char *ib_par_rng[] = {
"[IB01]",
"[M1]",
"[IB12]",
"[M2]",
"[IB23]",
"[M3]",
194 "[IB34]",
"[M4]",
"[IB4I1]",
"[I1]",
"[M5]",
"[IB56]",
"[M6]",
"[IB67]",
197 for (ipar = 0; ipar <
N_INT_RNG * 2; ipar++)
202 if ((fp = fopen(ib_file,
"r")) ==
NULL) {
203 printf(
"%s, line %d: unable to open inter-band file: %s\n",
204 __FILE__, __LINE__, ib_file);
210 while (fgets(
line, 80, fp)) {
217 if (
line[0] ==
'#' ||
line[0] ==
'\n')
219 if (!(
p = strchr(
line,
'=')))
243 printf(
"int band values are: %s = %s\n",
name,
value);
248 for (ipar = 0; ipar <
N_INT_RNG * 2; ipar++) {
253 sprintf(parm,
"%s%s", ib_par_nm[ip1], ib_par_rng[ip2]);
257 if (strcmp(
name, parm) == 0) {
271 for (ipar = 0; ipar <
N_INT_RNG * 2; ipar++)
272 if (items_set[ipar] == 0) {
273 printf(
"%s, %d: An item in the file %s was not set\n",
274 __FILE__, __LINE__, ib_file);
304 static int ifirst = 0, n_rec_bnd, n_rec_det, n_int_rng, n_snd_rng, n_snd_det;
308 static int snd_off[] = {0, -3, -9, -6, -18, -21, -15, -12, -14};
309 static float *oxt_coeff;
311 int irlin, irpix, irbnd, ilam, isbnd, isdet, reg_off, isoff;
321 if (
h5io_openr(ctl->oxt_coef, 0, &oxt_fid) != 0) {
322 printf(
"%s, %d - could not open HDF 5 Optical Xtalk file: %s\n",
323 __FILE__, __LINE__, ctl->oxt_coef);
329 if (
h5io_rd_attr(&oxt_fid,
"number of receiver bands", &n_rec_bnd) != 0) {
330 printf(
"%s, %d - failed to read Optical Xtalk attrib n_rec_bnd\n",
334 if (
h5io_rd_attr(&oxt_fid,
"number of receiver detectors", &n_rec_det)
336 printf(
"%s, %d - failed to read Optical Xtalk attrib n_rec_det\n",
340 if (
h5io_rd_attr(&oxt_fid,
"number of inter-band ranges", &n_int_rng)
342 printf(
"%s, %d - failed to read Optical Xtalk attrib n_int_rng\n",
346 if (
h5io_rd_attr(&oxt_fid,
"number of sender bands", &n_snd_rng) != 0) {
347 printf(
"%s, %d - failed to read Optical Xtalk attrib n_snd_rng\n",
351 if (
h5io_rd_attr(&oxt_fid,
"number of sender detectors", &n_snd_det)
353 printf(
"%s, %d - failed to read Optical Xtalk attrib n_snd_det\n",
357 printf(
"%s, %d: optical crosstalk array dimensions\n",
359 printf(
" n_rec_bnd = %d, n_rec_det = %d, n_int_rng = %d\n",
360 n_rec_bnd, n_rec_det, n_int_rng);
361 printf(
" n_snd_rng = %d, n_snd_det = %d\n", n_snd_rng, n_snd_det);
365 if ((oxt_coeff = malloc(n_rec_bnd * n_rec_det * n_int_rng *
366 n_snd_rng * n_snd_det *
sizeof (
float))) ==
NULL) {
367 printf(
"%s, %d: Unable to allocate optical crosstalk coeff storage\n",
372 if (
h5io_grab_ds(&oxt_fid,
"optical crosstalk coefficients",
373 (
void *) oxt_coeff) != 0) {
374 printf(
"%s, %d: Unable to read crosstalk coefficients\n",
382 printf(
"%s, %d: Unable to close crosstalk coefficient file\n",
391 for (irlin = 0; irlin <
NDET; irlin++) {
392 for (irpix = 0; irpix < in_rec->npix; irpix++) {
393 for (irbnd = 0; irbnd <
N_VNIR_BND; irbnd++) {
395 for (isdet = 0; isdet <
NDET; isdet++) {
396 for (isbnd = 0; isbnd < 9; isbnd++) {
406 reg_off = snd_off[ isbnd ] - snd_off[ irbnd ];
410 if ((reg_off + irpix >= 0) && (reg_off + irpix < in_rec->
npix)) {
411 isoff = isdet * in_rec->npix + irpix + reg_off;
412 for (ilam = 0; ilam < 16; ilam++) {
418 (ilam + 16 * (isbnd + 9 * isdet)))) *
419 *(ib_field[ilam] + isoff);
427 *(in_rec->bnd_lt[irbnd] + irpix +
428 in_rec->npix * (irlin + in_rec->margin[0])) += mod_rad;