5 int viirs_ext(ctl_struc *ctl, in_rec_struc *in_rec)
23 static int ext_init = 0;
27 int nsgain, nsbnd, nsdet, nrgain, nrbnd, nrdet, nrpix, nrlin, nspix;
28 int irbnd, irlin, irpix, ispix, isdet, isbnd, isgain, irgain, irdet;
30 int16_t nsfgain, nsfbnd, nsfdet, nrfgain, nrfbnd, nrfdet;
36 static int snd_off[] = {0, -3, -9, -6, -18, -21, -15, -12, -14};
42 static int gain_lut[] = {0, 1};
44 nrlin = in_rec->ndet_scan;
58 if (in_rec->lat ==
NULL) {
60 for (irbnd = 0; irbnd < nrbnd; irbnd++)
70 printf(
"%s, %d: Entering routine viirs_ext\n", __FILE__, __LINE__);
71 printf(
"ext_coef = %s\n", ctl->ext_coeff_file);
75 for (irbnd = 0; irbnd < nrbnd; irbnd++)
76 if ((dn_tmp[irbnd] = (
float *) malloc(nrlin * nrpix *
sizeof (
float)))
78 printf(
"%s, %d: Unable to allocate dn tmp storage\n", __FILE__,
85 nval = nsgain * nrgain * nsbnd * nsdet * nrbnd * nrdet;
86 if ((coeff = (
double *) calloc(nval,
sizeof (
double))) ==
NULL) {
87 printf(
"%s, %d: Unable to allocate electronic crosstalk storage\n",
91 if (strcmp(ctl->ext_coeff_file,
"Unspecified") == 0) {
98 if (
h5io_openr(ctl->ext_coeff_file, 0, &ext_fid) != 0) {
99 printf(
"%s, %d - could not open HDF 5 Electrical crosstalk file: %s\n",
100 __FILE__, __LINE__, ctl->ext_coeff_file);
104 strcpy(tstr,
"number of sender gains");
106 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
107 __FILE__, __LINE__, tstr);
110 strcpy(tstr,
"number of receiver gains");
112 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
113 __FILE__, __LINE__, tstr);
116 strcpy(tstr,
"number of sender bands");
118 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
119 __FILE__, __LINE__, tstr);
122 strcpy(tstr,
"number of sender detectors");
124 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
125 __FILE__, __LINE__, tstr);
128 strcpy(tstr,
"number of receiver bands");
130 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
131 __FILE__, __LINE__, tstr);
134 strcpy(tstr,
"number of receiver detectors");
136 printf(
"%s, %d - failed to read Electrical Xtalk attrib %s\n",
137 __FILE__, __LINE__, tstr);
143 if (nsfgain != nsgain) {
145 "%s, %d - Electrical crosstalk # sender gains: %d != expected #: %d\n",
146 __FILE__, __LINE__, nsfgain, nsgain);
149 if (nrfgain != nrgain) {
151 "%s, %d - Electrical crosstalk # receiver gains: %d != expected #: %d\n",
152 __FILE__, __LINE__, nrfgain, nrgain);
155 if (nsfbnd != nsbnd) {
157 "%s, %d - Electrical crosstalk # sender bands: %d != expected #: %d\n",
158 __FILE__, __LINE__, nsfbnd, nsbnd);
161 if (nrfbnd != nrbnd) {
163 "%s, %d - Electrical crosstalk # receiver bands: %d != expected #: %d\n",
164 __FILE__, __LINE__, nrfbnd, nrbnd);
167 if (nsfdet != nsdet) {
169 "%s, %d - Electrical crosstalk # sender detectors: %d != expected #: %d\n",
170 __FILE__, __LINE__, nsfdet, nsdet);
173 if (nrfdet != nrdet) {
175 "%s, %d - Electrical crosstalk # receiver detectors: %d != expected #: %d\n",
176 __FILE__, __LINE__, nrfdet, nrdet);
182 if (
h5io_grab_ds(&ext_fid,
"electronic crosstalk coefficients",
183 (
void *) coeff) != 0) {
184 printf(
"%s, %d: Unable to read electronic crosstalk coefficients\n",
192 "%s, %d: Unable to close electronic crosstalk coefficient file\n",
202 nval = nrpix * nrlin *
sizeof (
float);
203 for (irbnd = 0; irbnd < nrbnd; irbnd++)
204 memcpy(dn_tmp[irbnd], in_rec->dn[irbnd], nval);
208 for (irlin = 0; irlin < nrlin; irlin++) {
209 irdet = irlin - in_rec->margin[0];
210 if (irdet < 0) irdet = 0;
211 if (irdet >=
NDET) irdet =
NDET - 1;
212 for (irpix = 0; irpix < in_rec->npix; irpix++) {
213 for (irbnd = 0; irbnd < nrbnd; irbnd++) {
219 for (isbnd = 0; isbnd < nsbnd; isbnd++) {
220 reg_off = snd_off[isbnd] - snd_off[irbnd];
221 ispix = irpix + reg_off;
222 if ((ispix >= 0) && (ispix < in_rec->npix)) {
223 for (isdet = 0; isdet < nsdet; isdet++) {
224 isgain = gain_lut[ *(in_rec-> gain_bit[isbnd] +
225 ispix + nspix * isdet) ];
226 irgain = gain_lut[ *(in_rec-> gain_bit[irbnd] +
227 irpix + nspix * irlin) ];
229 dn_mod += *(dn_tmp[isbnd] + ispix + isdet * nspix) *
230 *(coeff + isgain + nsgain * (irgain + nrgain *
231 (isbnd + nsbnd * (isdet + nsdet *
232 (irbnd + nrbnd * irdet)))));
239 *(in_rec->dn[irbnd] + irpix + nrpix * irlin) =
240 *(dn_tmp[irbnd] + irpix + nrpix * irlin) + dn_mod;