7 int viirs_straylt(ctl_struc *ctl, in_rec_struc *in_rec,
int stray_stop)
27 int ibnd, ilin, ipix, idet, lpsf, ppsf, pdat;
28 static int nbnd_s,
npix,
nlin, npix_s, nlin_s, lin_margin;
29 static vir_straylt_struc stlt;
30 static int stray_init = 0;
31 static float *bnd_store;
33 float sum_psf, sum_rad, psf_val;
38 if (stray_stop == 1) {
41 printf(
"%s: Shutting down the stray light artifact addition\n",
47 if (stray_init == 0) {
50 printf(
"%s, %d: Entering routine viirs_straylt\n", __FILE__, __LINE__);
51 printf(
"stray_tbl = %s\n", ctl->stray_tbl);
60 nlin = in_rec->ndet_scan;
62 lin_margin = in_rec->margin[0];
66 if ((bnd_store = (
float *) malloc(
nlin *
npix *
sizeof (
float)))
69 "%s, %d: Unable to allocate band storage for stray light artifact\n",
78 for (ibnd = 0; ibnd < nbnd_s; ibnd++) {
82 memcpy(bnd_store, in_rec->bnd_lt[ibnd],
nlin *
npix * sizeof (
float));
84 for (idet = 0; idet < nlin_s; idet++) {
85 ilin = idet + lin_margin;
90 psf_bd = stlt.psf + (npix_s * nlin_s) * (ibnd + nbnd_s * idet);
92 for (ipix = 0; ipix <
npix; ipix++) {
97 if (*(in_rec->bnd_q[ibnd] + ipix +
npix * ilin) == 0) {
105 for (lpsf = 0; lpsf < nlin_s; lpsf++) {
106 for (ppsf = 0; ppsf < npix_s; ppsf++) {
111 pdat = ipix + ppsf - stlt.csamp;
112 if ((pdat >= 0) && (pdat <
npix)) {
116 if (*(in_rec->bnd_q[ibnd] + ipix + ilin *
npix) == 0) {
117 psf_val = *(psf_bd + ppsf + npix_s * lpsf);
119 sum_rad += psf_val * *(bnd_store + pdat +
120 (lpsf + lin_margin) *
npix);
128 *(in_rec->bnd_lt[ibnd] + ipix + ilin *
npix) = sum_rad / sum_psf;
169 if (strcmp(
file,
"Unspecified") != 0) {
171 printf(
"%s, %d, Unable to open stray light table file: \n%s\n",
172 __FILE__, __LINE__,
file);
175 if (
h5io_rd_attr(&fid,
"nbands", (
void *) &(stlt->nbands)) != 0) {
177 "%s, %d, Unable to read nbands attr from stray light file: \n%s\n",
178 __FILE__, __LINE__,
file);
181 if (
h5io_rd_attr(&fid,
"nrec_det", (
void *) &(stlt->nrec_det)) != 0) {
183 "%s, %d, Unable to read nrec_det attr from stray light file: \n%s\n",
184 __FILE__, __LINE__,
file);
187 if (
h5io_rd_attr(&fid,
"nsamp", (
void *) &(stlt->nsamp)) != 0) {
189 "%s, %d, Unable to read nsamp attr from stray light file: \n%s\n",
190 __FILE__, __LINE__,
file);
193 if (
h5io_rd_attr(&fid,
"ndet", (
void *) &(stlt->ndet)) != 0) {
195 "%s, %d, Unable to read ndet attr from stray light file: \n%s\n",
196 __FILE__, __LINE__,
file);
199 if (
h5io_rd_attr(&fid,
"csamp", (
void *) &(stlt->csamp)) != 0) {
201 "%s, %d, Unable to read csamp attr from stray light file: \n%s\n",
202 __FILE__, __LINE__,
file);
209 if ((stlt->nrec_det !=
nrec_det) || (stlt->ndet !=
ndet)) {
211 "%s, %d, Unexpected stray light array dimensions found in file: \n%s\n",
212 __FILE__, __LINE__,
file);
213 printf(
" nrec_det: %d, expected: %d\n", stlt->nrec_det,
nrec_det);
214 printf(
" ndet: %d, expected: %d\n", stlt->ndet,
ndet);
218 printf(
"%s, %d: Unexpectedly found Unspecified file stray light table\n",
225 if ((stlt->psf = (
float *)
227 printf(
"%s, %d: Error allocating the stlt->psf\n", __FILE__, __LINE__);
231 if (
h5io_grab_ds(&fid,
"psf", (
void *) stlt->psf) != 0) {
233 "%s, %d, Unable to read psf dataset from stray light table file: \n%s\n",
234 __FILE__, __LINE__,
file);
239 printf(
"%s, %d, Error closing the stray light table:\n%s\n", __FILE__,