37 float dn_trans_pct = 0.83;
39 float c0, c1, c2, dark, lt_max, dn, big_dn, dn_max = 4095.;
46 int iham, idet, igain, ibnd, ext_gain = 0;
47 int nham = 2,
ndet = 16, ngain = 2,
nbnd = 11;
48 char gain_ct[] = {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1};
63 float m_gains[22] = {6.4, 4.90, 4.44, 4.76, 5.15, -1., 9.97,
65 27.26, 23.84, 27.35, 37.13, 50.97, 109.37, 84.19,
66 28.11, 41.99, 49.52, 91.49};
71 if (strcmp(
file,
"Unspecified") != 0) {
74 printf(
"%s, %d, Unable to open gain calibration file: \n%s\n",
75 __FILE__, __LINE__,
file);
79 printf(
"%s, %d, Unable to read ngain attr from calibration file: \n%s\n",
80 __FILE__, __LINE__,
file);
84 printf(
"%s, %d, Unable to read nham attr from calibration file: \n%s\n",
85 __FILE__, __LINE__,
file);
89 printf(
"%s, %d, Unable to read ndet attr from calibration file: \n%s\n",
90 __FILE__, __LINE__,
file);
94 printf(
"%s, %d, Unable to read nbnd attr from calibration file: \n%s\n",
95 __FILE__, __LINE__,
file);
98 if ((
gain->ngain != ngain) || (
gain->nham != nham) ||
100 printf(
"%s, %d, Unexpected gain array dimensions found in file: \n%s\n",
101 __FILE__, __LINE__,
file);
102 printf(
" ngain: %d, expected: %d\n",
gain->ngain, ngain);
103 printf(
" nham: %d, expected: %d\n",
gain->nham, nham);
104 printf(
" ndet: %d, expected: %d\n",
gain->ndet,
ndet);
105 printf(
" nbnd: %d, expected: %d\n",
gain->nbnd,
nbnd);
117 if ((
gain->c0 = (
float *)
118 malloc(nham *
ndet * ngain *
nbnd *
sizeof (
float))) ==
NULL) {
119 printf(
"%s, %d: Error allocating the gain->c0\n", __FILE__, __LINE__);
122 if ((
gain->c1 = (
float *)
123 malloc(nham *
ndet * ngain *
nbnd *
sizeof (
float))) ==
NULL) {
124 printf(
"%s, %d: Error allocating the gain->c1\n", __FILE__, __LINE__);
127 if ((
gain->c2 = (
float *)
128 malloc(nham *
ndet * ngain *
nbnd *
sizeof (
float))) ==
NULL) {
129 printf(
"%s, %d: Error allocating the gain->c2\n", __FILE__, __LINE__);
132 if ((
gain->dark = (
float *)
133 malloc(nham *
ndet * ngain *
nbnd *
sizeof (
float))) ==
NULL) {
134 printf(
"%s, %d: Error allocating the gain->dark\n", __FILE__, __LINE__);
141 for (ibnd = 0; ibnd <
nbnd; ibnd++) {
142 min_hg_lim[ibnd] = 999.;
143 max_hg_lim[ibnd] = -999.;
144 min_lg_lim[ibnd] = 999.;
145 max_lg_lim[ibnd] = -999.;
146 min_dn_lg[ibnd] = 9999.;
147 max_dn_lg[ibnd] = -9999.;
148 min_dn_hg[ibnd] = 9999.;
149 max_dn_hg[ibnd] = -9999.;
150 min_big_dn_lg[ibnd] = 9999.;
151 max_big_dn_lg[ibnd] = -9999.;
152 min_big_dn_hg[ibnd] = 9999.;
153 max_big_dn_hg[ibnd] = -9999.;
155 dn = dn_max * dn_trans_pct;
161 printf(
"%s, %d, Unable to read c0 dataset from calibration file: \n%s\n",
162 __FILE__, __LINE__,
file);
166 printf(
"%s, %d, Unable to read c1 dataset from calibration file: \n%s\n",
167 __FILE__, __LINE__,
file);
171 printf(
"%s, %d, Unable to read c2 dataset from calibration file: \n%s\n",
172 __FILE__, __LINE__,
file);
177 "%s, %d, Unable to read dark dataset from calibration file: \n%s\n",
178 __FILE__, __LINE__,
file);
185 for (iham = 0; iham < nham; iham++) {
186 for (idet = 0; idet <
ndet; idet++) {
187 for (ibnd = 0; ibnd <
nbnd; ibnd++) {
188 for (igain = 0; igain < ngain; igain++) {
189 if ((gain_ct[ibnd] == 1) && (igain == 0))
continue;
193 c1 = 1. / *(m_gains + ibnd + igain *
nbnd);
196 *(
gain->c0 + ibnd +
nbnd * (igain + ngain *
197 (idet +
ndet * iham))) = c0;
198 *(
gain->c1 + ibnd +
nbnd * (igain + ngain *
199 (idet +
ndet * iham))) = c1;
200 *(
gain->c2 + ibnd +
nbnd * (igain + ngain *
201 (idet +
ndet * iham))) = c2;
202 *(
gain->dark + ibnd +
nbnd * (igain + ngain *
203 (idet +
ndet * iham))) = dark;
212 for (iham = 0; iham < nham; iham++) {
213 for (idet = 0; idet <
ndet; idet++) {
214 for (ibnd = 0; ibnd <
nbnd; ibnd++) {
215 for (igain = 0; igain < ngain; igain++) {
216 if ((gain_ct[ibnd] == 1) && (igain == 0))
continue;
217 big_dn = dn + *(
gain->dark + ibnd +
nbnd * (igain + ngain *
218 (idet +
ndet * iham)));
219 c0 = *(
gain->c0 + ibnd +
nbnd * (igain + ngain *
220 (idet +
ndet * iham)));
221 c1 = *(
gain->c1 + ibnd +
nbnd * (igain + ngain *
222 (idet +
ndet * iham)));
223 c2 = *(
gain->c2 + ibnd +
nbnd * (igain + ngain *
224 (idet +
ndet * iham)));
225 lt_max = c0 + c1 * dn + c2 * dn * dn;
227 if (lt_max < min_lg_lim[ibnd]) min_lg_lim[ibnd] = lt_max;
228 if (lt_max > max_lg_lim[ibnd]) max_lg_lim[ibnd] = lt_max;
229 if (dn < min_dn_lg[ibnd]) min_dn_lg[ibnd] = dn;
230 if (dn > max_dn_lg[ibnd]) max_dn_lg[ibnd] = dn;
231 if (big_dn < min_big_dn_lg[ibnd]) min_big_dn_lg[ibnd] = big_dn;
232 if (big_dn > max_big_dn_lg[ibnd]) max_big_dn_lg[ibnd] = big_dn;
234 if (lt_max < min_hg_lim[ibnd]) min_hg_lim[ibnd] = lt_max;
235 if (lt_max > max_hg_lim[ibnd]) max_hg_lim[ibnd] = lt_max;
236 if (dn < min_dn_hg[ibnd]) min_dn_hg[ibnd] = dn;
237 if (dn > max_dn_hg[ibnd]) max_dn_hg[ibnd] = dn;
238 if (big_dn < min_big_dn_hg[ibnd]) min_big_dn_hg[ibnd] = big_dn;
239 if (big_dn > max_big_dn_hg[ibnd]) max_big_dn_hg[ibnd] = big_dn;
242 printf(
"%s, %d: lt_max < 0 at ham: %d, det: %d, bnd: %d, gain:%d\n",
243 __FILE__, __LINE__, iham, idet, ibnd, igain);
252 printf(
"\n\n%s, %d: info:\n", __FILE__, __LINE__);
253 printf(
"\nRadiance, dn limit min and max per band\n");
254 printf(
"(file: %s)\n",
file);
255 if (strcmp(
file,
"Unspecified") == 0)
256 printf(
"Using the general gains from TVAC tests\n");
257 printf(
"For HIGH GAIN setting\n");
259 "\nM band Min rad Max rad Min dn Max dn Min DN Max DN\n");
260 for (ibnd = 0; ibnd <
nbnd; ibnd++)
261 printf(
" %3d %9.4f %9.4f %8.2f %8.2f %8.2f %8.2f\n", ibnd + 1,
262 min_hg_lim[ibnd], max_hg_lim[ibnd], min_dn_hg[ibnd], max_dn_hg[ibnd],
263 min_big_dn_hg[ibnd], max_big_dn_hg[ibnd]);
264 printf(
"\nFor LOW GAIN setting\n");
266 "\nM band Min rad Max rad Min dn Max dn Min DN Max DN\n");
267 for (ibnd = 0; ibnd <
nbnd; ibnd++)
268 printf(
" %3d %9.4f %9.4f %8.2f %8.2f %8.2f %8.2f\n", ibnd + 1,
269 min_lg_lim[ibnd], max_lg_lim[ibnd], min_dn_lg[ibnd], max_dn_lg[ibnd],
270 min_big_dn_lg[ibnd], max_big_dn_lg[ibnd]);
271 printf(
"----------------------------------------\n\n");
275 for (ibnd = 0; ibnd <
nbnd; ibnd++)
276 *(
gain->gain_ct + ibnd) = gain_ct[ibnd];
304 int ibnd, iham, idet, bnd_lambda[16];
305 int nbnd = 11, npoly = 3, nham = 2,
ndet = 1;;
322 printf(
"%s, %d: Error in getting lambda, Exiting\n", __FILE__, __LINE__);
331 if ((rvs->a0 = (
float *) malloc(nham *
ndet *
nbnd *
sizeof (
float)))
333 printf(
"%s, %d: Error in allocating rvs->a0\n", __FILE__, __LINE__);
336 if ((rvs->a1 = (
float *) malloc(nham *
ndet *
nbnd *
sizeof (
float)))
338 printf(
"%s, %d: Error in allocating rvs->a1\n", __FILE__, __LINE__);
341 if ((rvs->a2 = (
float *) malloc(nham *
ndet *
nbnd *
sizeof (
float)))
343 printf(
"%s, %d: Error in allocating rvs->a2\n", __FILE__, __LINE__);
349 printf(
"%s, %d, RVS file input: %s\n", __FILE__, __LINE__,
file);
353 if (strcmp(
file,
"Unspecified") == 0) {
354 printf(
"%s, %d: Note that unit RVS will be used\n", __FILE__, __LINE__);
355 for (ibnd = 0; ibnd <
nbnd; ibnd++)
356 for (iham = 0; iham < nham; iham++)
357 for (idet = 0; idet <
ndet; idet++) {
358 *(rvs->a0 + ibnd +
nbnd * (idet +
ndet * iham)) = 1.;
359 *(rvs->a1 + ibnd +
nbnd * (idet +
ndet * iham)) = 0.;
360 *(rvs->a2 + ibnd +
nbnd * (idet +
ndet * iham)) = 0.;
367 if ((lcl_buf = (
float *) malloc(npoly * nham *
ndet *
sizeof (
float)))
369 printf(
"%s, %d: Error in allocating lcl read buffer\n",
376 for (ibnd = 0; ibnd <
nbnd; ibnd++) {
380 sprintf(hfile,
"%s%s%d%s",
file,
"_", bnd_lambda[ibnd],
".hdf");
382 printf(
"%s, %d, opening RVS file %s\n", __FILE__, __LINE__, hfile);
386 if (
hio_open(hfile, DFACC_RDONLY, &finfo) != 0) {
387 printf(
"%s, %d: Error, Unable to open the HDF file: %s\n",
388 __FILE__, __LINE__, hfile);
395 printf(
"%s, %d: Error, Unable to read the 'rvs' SDS for HDF file: %s\n",
396 __FILE__, __LINE__, hfile);
405 "%s, %d: Error, Unable to read the 'aoirange' SDS for HDF file: %s\n",
406 __FILE__, __LINE__, hfile);
409 printf(
"%s, %d: Info: aoi range is: %f %f\n", __FILE__, __LINE__,
410 rvs->aoi_range[0], rvs->aoi_range[1]);
418 for (iham = 0; iham < nham; iham++) {
419 for (idet = 0; idet <
ndet; idet++) {
420 *(rvs->a0 + ibnd +
nbnd * (idet +
ndet * iham)) =
421 *(lcl_buf + idet +
ndet * (iham + nham * 0));
422 *(rvs->a1 + ibnd +
nbnd * (idet +
ndet * iham)) =
423 *(lcl_buf + idet +
ndet * (iham + nham * 1));
424 *(rvs->a2 + ibnd +
nbnd * (idet +
ndet * iham)) =
425 *(lcl_buf + idet +
ndet * (iham + nham * 2));