45 static float *tablewavelengths;
46 static float *tablephaseangles;
47 static float *tablealphas;
48 static float *tableomegas;
49 static float *tableaerphasefunc;
52 float *aerphasefunc,
float *
omega,
float *modelAngstrom) {
54 float phaseangle = l2rec->l1rec->scattang[ip];
55 float distx, dista,
p1, p2;
56 int i,
j, ix1=0, ix2, ia1=0, ia2, widx;
58 static int firstCall =
TRUE;
62 int ii[12] = {1, 0, 5, 4, 8, 7, 3, 2, 6, 11, 10, 9};
79 tablealphas, tableomegas, tableaerphasefunc);
84 if (phaseangle < tablephaseangles[0]) {
86 phaseangle = tablephaseangles[0];
88 }
else if (phaseangle >= tablephaseangles[
NPHASE - 1]) {
91 phaseangle = tablephaseangles[
NPHASE - 1];
95 if (phaseangle >= tablephaseangles[
i]) {
103 distx = (tablephaseangles[ix2] - phaseangle)
104 / (tablephaseangles[ix2] - tablephaseangles[ix1]);
110 if (angstrom < tablealphas[widx *
NMODEL + ii[0]]) {
111 angstrom = tablealphas[widx *
NMODEL + ii[0]];
113 }
else if (angstrom >= tablealphas[widx *
NMODEL + ii[
NMODEL - 1]]) {
118 if (angstrom >= tablealphas[widx *
NMODEL + ii[
j]]) {
125 dista = (tablealphas[widx *
NMODEL + ii[ia2]] - angstrom)
126 / (tablealphas[widx *
NMODEL + ii[ia2]]
127 - tablealphas[widx *
NMODEL + ii[ia1]]);
133 + (tableomegas[
i *
NMODEL + ii[ia2]] * (1.0 - dista));
135 modelAngstrom[
i] = (tablealphas[
i *
NMODEL + ii[ia1]] * dista)
136 + (tablealphas[
i *
NMODEL + ii[ia2]] * (1.0 - dista));
142 + ii[ia1] *
NPHASE + ix2] * (1.0 - distx));
148 + ii[ia2] *
NPHASE + ix2] * (1.0 - distx));
150 aerphasefunc[
i] = (
p1 * dista) + (p2 * (1.0 - dista));
175 float *tablephaseangles,
float *tablealphas,
float *tableomegas,
176 float *tableaerphasefunc) {
180 char aerosolfilename[FILENAME_MAX] =
"";
184 if ((dataroot = getenv(
"OCDATAROOT")) ==
NULL) {
185 printf(
"OCDATAROOT environment variable is not defined.\n");
188 sprintf(aerosolfilename,
"%s/%s/%s_aerosol_par.dat", dataroot,
193 if ((aerosoldata = fopen(aerosolfilename,
"r")) ==
NULL) {
194 printf(
"Error reading aerosol table for PAR from %s.\n", aerosolfilename);
197 printf(
"Loading aerosol properties for PAR from %s.\n", aerosolfilename);
201 for (jj = 0; jj <
NPHASE; jj++) {
202 if ((fscanf(aerosoldata,
"%f", &tablephaseangles[jj])) == 0) {
203 printf(
"Problem reading phase angles from %s.\n", aerosolfilename);
208 for (iph = 0; iph <
NMODEL; iph++) {
209 if ((fscanf(aerosoldata,
"%d %d %f", &imodel[iph], &num_model,
210 &tablewavelengths[
j])) == 0) {
211 printf(
"Problem reading model number and wavelength from %s.\n",
215 if ((fscanf(aerosoldata,
"%f %f", &tableomegas[
j *
NMODEL + iph],
216 &tablealphas[
j *
NMODEL + iph])) == 0) {
217 printf(
"Problem reading SSA and Angstrom from %s.\n",
221 for (jj = 0; jj <
NPHASE; jj++) {
222 if ((fscanf(aerosoldata,
"%f",
225 printf(
"Problem reading phase function values from %s.\n",
253 float daymid, d1, d2;
254 float t, t1, t2,
fac, fac2, difflat;
257 int tabdobson[12][35] = {
258 { 395, 395, 395, 395, 395, 392, 390, 387, 376,
259 354, 322, 292, 269, 254, 248, 246, 247, 251, 255, 260, 266, 271,
260 277, 286, 295, 306, 319, 334, 344, 344, 338, 331, 324, 320, 316},
262 { 433, 433, 433, 436, 432, 428, 426, 418, 402, 374, 338, 303, 278, 261, 251,
263 246, 248, 250, 254, 258, 262, 265, 270, 278, 286, 294, 303, 313,
264 322, 325, 324, 317, 306, 299, 294},
266 { 467, 470, 460, 459, 451, 441, 433, 420, 401, 377, 347, 316, 291, 271, 260,
267 254, 254, 255, 257, 259, 261, 264, 269, 277, 284, 289, 296, 305,
268 312, 315, 317, 312, 305, 299, 295},
270 { 467, 465, 462, 455, 444, 431, 421, 410, 395, 373, 348, 325, 304, 287, 275,
271 267, 261, 259, 258, 259, 260, 263, 271, 278, 284, 289, 297, 306,
272 314, 318, 319, 313, 302, 302, 302},
274 { 411, 414, 416, 415, 410, 406, 402, 394, 382, 363, 342, 324, 307, 291, 279,
275 271, 264, 260, 258, 257, 258, 264, 271, 281, 291, 303, 312, 318,
276 322, 323, 322, 322, 322, 322, 322},
278 { 371, 371, 370, 368, 367, 372, 375, 372, 360, 341, 323, 311, 301, 290, 282,
279 275, 268, 263, 259, 256, 258, 264, 273, 289, 306, 319, 327, 328,
280 328, 337, 337, 337, 337, 337, 337},
282 { 333, 332, 332, 334, 338, 346, 350, 346, 335, 321, 310, 302, 296, 289, 284,
283 280, 274, 268, 262, 259, 261, 268, 279, 295, 315, 331, 340, 342,
284 338, 344, 340, 340, 340, 340, 340},
286 { 311, 308, 308, 313, 320, 327, 330, 326, 319, 310, 303, 298, 291, 286, 283,
287 281, 277, 273, 268, 264, 266, 274, 288, 306, 327, 343, 353, 355,
288 351, 339, 325, 307, 294, 294, 294},
290 { 283, 291, 302, 308, 312, 317, 318, 313, 307, 300, 295, 290, 284, 279, 279,
291 279, 278, 276, 272, 270, 273, 282, 295, 313, 333, 348, 360, 367,
292 368, 353, 324, 291, 267, 253, 230},
294 { 299, 299, 299, 309, 315, 317, 317, 312, 302, 291, 283, 280, 275, 270, 268,
295 267, 263, 263, 265, 269, 277, 287, 301, 317, 336, 354, 371, 387,
296 402, 402, 374, 333, 294, 274, 259},
298 { 314, 314, 314, 314, 332, 332, 327, 322, 311, 297, 284, 276, 270, 263, 261,
299 260, 258, 259, 264, 270, 278, 286, 298, 311, 323, 335, 350, 366,
300 381, 390, 388, 376, 357, 346, 341},
302 { 358, 358, 358, 358, 358, 358, 353, 349, 338, 320, 299, 281, 267, 256, 252,
303 251, 251, 253, 257, 264, 272, 279, 287, 297, 307, 318, 332, 347,
304 358, 365, 366, 364, 358, 356, 353}
307 int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
312 days[1] = days[1] + 1;
314 daymid = days[month - 1] / 2.0;
331 t2 = days[m1] + (days[m2] / 2.0);
336 d1 = tabdobson[m1][1];
337 d2 = tabdobson[m2][1];
338 }
else if (
lat <= -85.0) {
339 d1 = tabdobson[m1][34];
340 d2 = tabdobson[m2][34];
342 i1 = 17 - (
int) (
lat / 5.0);
344 fac = (tabdobson[month][i2] - tabdobson[month][i1]) / (-5.0);
345 difflat =
lat - (90.0 - (i1 * 5.0));
346 d1 = tabdobson[m1][i1] + (
fac * difflat);
347 d2 = tabdobson[m2][i1] + (
fac * difflat);
352 fac2 = (d2 - d1) / (t2 - t1);
354 dobson = d1 + (
t - t1) * fac2;
385 float daymid, d1, d2;
386 float t, t1, t2,
fac, fac2, difflat;
389 float tabwv[12][35] = {
390 { 0.42, 0.47, 0.52, 0.56, 0.61, 0.66, 0.71, 0.75,
391 0.80, 0.85, 1.26, 1.67, 2.08, 2.48, 2.89, 3.30, 3.71, 4.12, 3.97,
392 3.82, 3.67, 3.53, 3.38, 3.23, 3.08, 2.93, 2.84, 2.75, 2.65, 2.56,
393 2.47, 2.38, 2.28, 2.19, 2.10},
395 { 0.70, 0.76, 0.81, 0.87, 0.92, 0.98, 1.03, 1.09, 1.14, 1.20, 1.56, 1.93,
396 2.29, 2.66, 3.02, 3.39, 3.75, 4.12, 3.93, 3.74, 3.54, 3.35, 3.16,
397 2.97, 2.78, 2.58, 2.50, 2.41, 2.33, 2.24, 2.16, 2.07, 1.99, 1.90,
400 { 0.98, 1.04, 1.11, 1.17, 1.23, 1.29, 1.36, 1.42, 1.48, 1.54, 1.87, 2.19,
401 2.51, 2.83, 3.15, 3.48, 3.80, 4.12, 3.88, 3.65, 3.41, 3.18, 2.94,
402 2.71, 2.47, 2.24, 2.16, 2.08, 2.00, 1.93, 1.85, 1.77, 1.69, 1.62,
405 { 1.26, 1.33, 1.40, 1.47, 1.54, 1.61, 1.68, 1.75, 1.82, 1.89, 2.17, 2.45,
406 2.73, 3.01, 3.28, 3.56, 3.84, 4.12, 3.84, 3.56, 3.28, 3.01, 2.73,
407 2.45, 2.17, 1.89, 1.82, 1.75, 1.68, 1.61, 1.54, 1.47, 1.40, 1.33,
410 { 1.54, 1.62, 1.69, 1.77, 1.85, 1.93, 2.00, 2.08, 2.16, 2.24, 2.47, 2.71,
411 2.94, 3.18, 3.41, 3.65, 3.88, 4.12, 3.80, 3.48, 3.15, 2.83, 2.51,
412 2.19, 1.87, 1.54, 1.48, 1.42, 1.36, 1.29, 1.23, 1.17, 1.11, 1.04,
415 { 1.82, 1.90, 1.99, 2.07, 2.16, 2.24, 2.33, 2.41, 2.50, 2.58, 2.78, 2.97,
416 3.16, 3.35, 3.54, 3.74, 3.93, 4.12, 3.75, 3.39, 3.02, 2.66, 2.29,
417 1.93, 1.56, 1.20, 1.14, 1.09, 1.03, 0.98, 0.92, 0.87, 0.81, 0.76,
420 { 2.10, 2.19, 2.28, 2.38, 2.47, 2.56, 2.65, 2.75, 2.84, 2.93, 3.08, 3.23,
421 3.38, 3.53, 3.67, 3.82, 3.97, 4.12, 3.71, 3.30, 2.89, 2.49, 2.08,
422 1.67, 1.26, 0.85, 0.80, 0.75, 0.71, 0.66, 0.61, 0.56, 0.52, 0.47,
425 { 1.82, 1.90, 1.99, 2.07, 2.16, 2.24, 2.33, 2.41, 2.50, 2.58, 2.78, 2.97,
426 3.16, 3.35, 3.54, 3.74, 3.93, 4.12, 3.75, 3.39, 3.02, 2.66, 2.29,
427 1.93, 1.56, 1.20, 1.14, 1.09, 1.03, 0.98, 0.92, 0.87, 0.81, 0.76,
430 { 1.54, 1.62, 1.69, 1.77, 1.85, 1.93, 2.00, 2.08, 2.16, 2.24, 2.47, 2.71,
431 2.94, 3.18, 3.41, 3.65, 3.88, 4.12, 3.80, 3.48, 3.15, 2.83, 2.51,
432 2.19, 1.87, 1.54, 1.48, 1.42, 1.36, 1.29, 1.23, 1.17, 1.11, 1.04,
435 { 1.26, 1.33, 1.40, 1.47, 1.54, 1.61, 1.68, 1.75, 1.82, 1.89, 2.17, 2.45,
436 2.73, 3.01, 3.28, 3.56, 3.84, 4.12, 3.84, 3.56, 3.28, 3.01, 2.73,
437 2.45, 2.17, 1.89, 1.82, 1.75, 1.68, 1.61, 1.54, 1.47, 1.40, 1.33,
440 { 0.98, 1.04, 1.11, 1.17, 1.23, 1.29, 1.36, 1.42, 1.48, 1.54, 1.87, 2.19,
441 2.51, 2.83, 3.15, 3.48, 3.80, 4.12, 3.88, 3.65, 3.41, 3.18, 2.94,
442 2.71, 2.47, 2.24, 2.16, 2.08, 2.00, 1.93, 1.85, 1.77, 1.69, 1.62,
445 { 0.70, 0.76, 0.81, 0.87, 0.92, 0.98, 1.03, 1.09, 1.14, 1.20, 1.56, 1.93,
446 2.29, 2.66, 3.02, 3.39, 3.75, 4.12, 3.93, 3.74, 3.54, 3.35, 3.16,
447 2.97, 2.78, 2.58, 2.50, 2.41, 2.33, 2.24, 2.16, 2.07, 1.99, 1.90,
451 int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
456 days[1] = days[1] + 1;
458 daymid = days[month] / 2.0;
475 t2 = days[m1] + (days[m2] / 2.0);
482 }
else if (
lat <= (-85.0)) {
487 i1 = 16 - (
int) (
lat / 5.0);
489 fac = (tabwv[month][i2] - tabwv[month][i1]) / (-5.0);
490 difflat =
lat - (90.0 - (i1 * 5.0));
491 d1 = tabwv[m1][i1] + (
fac * difflat);
492 d2 = tabwv[m2][i1] + (
fac * difflat);
497 fac2 = (d2 - d1) / (t2 - t1);
499 watvap = d1 + (
t - t1) * fac2;
520 dsol = 1.f / powf((1.
f - .01673
f * cosf(om)), 2.
f);
531 float fac, xlo, xla, xj, a1, a2, et, a3,
delta, cosah, ah1, ah2, tsv1, tsv2,
540 a1 = (1.00554f * xj - 6.28306f) *
fac;
541 a2 = (1.93946f * xj + 23.35089f) *
fac;
542 et = -7.67825f * sinf(a1) - 10.09176f * sinf(a2);
543 a3 = (0.9683f * xj - 78.00878f) *
fac;
546 cosah = (-(sinf(xla) * sinf(
delta))) / (cosf(xla) * cosf(
delta));
548 if ((cosah < -1.
f) || (cosah > 1.f)) {
557 tsv1 = ah1 / (15.f *
fac);
558 tsv2 = ah2 / (15.f *
fac);
559 tsm1 = tsv1 + 12.f - et / 60.f;
560 tsm2 = tsv2 + 12.f - et / 60.f;
562 *trise = tsm2 - (xlo / (15.f *
fac));
563 *tset = tsm1 - (xlo / (15.f *
fac));
574 double tsm, xla, xj, tet, a1, a2, a3, a4, a5, et, tsv, ah,
b1, b2, b3, b4,
575 b5, b6, b7,
delta, amuzero, elev, az, caz, azim, pi2;
585 tet = 2. *
M_PI * xj / 365.;
593 et = a1 + a2 * cos(tet) - a3 * sin(tet) - a4 * cos(2. * tet)
594 - a5 * sin(2. * tet);
595 et = et * 12. * 60. /
M_PI;
599 tsv = tsm + et / 60.;
604 ah = tsv * 15. *
fac;
615 delta =
b1 - b2 * cos(tet) + b3 * sin(tet) - b4 * cos(2. * tet)
616 + b5 * sin(2. * tet) - b6 * cos(3. * tet) + b7 * sin(3.
f * tet);
620 amuzero = sin(xla) * sin(
delta) + cos(xla) * cos(
delta) * cos(ah);
621 elev = asin(amuzero);
622 az = cos(
delta) * sin(ah) / cos(elev);
623 if ((
fabs(az) - 1.000) > 0.00000)
624 az = copysign(az, 1.);
626 caz = (-cos(xla) * sin(
delta) + sin(xla) * cos(
delta) * cos(ah))
633 if (caz > 0. && az <= 0.)
634 azim = 2. *
M_PI + azim;
646 asol = (
float) (90. - elev);
663 int s1, s2, t1, t2,
i;
665 float stot, sdist, ttot, tdist,
slope, alb1[2],
as;
667 float cszt[
NS] = {0.05, 0.09, 0.15, 0.21, 0.27, 0.33, 0.39, 0.45, 0.52,
668 0.60, 0.68, 0.76, 0.84, 0.92, 1.00};
670 float taut[
NT] = {0.00, 0.05, 0.10, 0.16, 0.24, 0.35, 0.50, 0.70, 0.99};
675 float ast[
NS][
NT] = {
676 { 0.1592253, 0.1258933, 0.1088253, 0.0968594,
677 0.0880966, 0.0815492, 0.0766266, 0.0721790, 0.0679746},
679 0.1944972, 0.1637040, 0.1432702, 0.1240363, 0.1066057, 0.0922638,
680 0.0826043, 0.0757601, 0.0700167
682 { 0.1978650, 0.1785707,
683 0.1643212, 0.1482773, 0.1304572, 0.1119496, 0.0963537, 0.0839010,
685 { 0.1785221, 0.1673987, 0.1589092, 0.1486409,
686 0.1359193, 0.1209508, 0.1061981, 0.0920763, 0.0793196},
688 0.1531512, 0.1473233, 0.1426633, 0.1366985, 0.1289257, 0.1188203,
689 0.1078114, 0.0957847, 0.0831087
691 { 0.1281988, 0.1255739,
692 0.1234628, 0.1204020, 0.1161201, 0.1101539, 0.1030820, 0.0943791,
694 { 0.1061354, 0.1052812, 0.1048179, 0.1036617,
695 0.1016918, 0.0986726, 0.0948040, 0.0894514, 0.0822926},
697 0.0877530, 0.0881279, 0.0883850, 0.0884469, 0.0880587, 0.0870923,
698 0.0854952, 0.0826607, 0.0782380
700 { 0.0708031, 0.0720173,
701 0.0727886, 0.0736250, 0.0741367, 0.0746769, 0.0747173, 0.0741294,
703 { 0.0567974, 0.0582123, 0.0593260, 0.0604172,
704 0.0615151, 0.0627740, 0.0639047, 0.0647193, 0.0650727},
706 0.0472026, 0.0485713, 0.0495830, 0.0507434, 0.0519943, 0.0536504,
707 0.0551176, 0.0566950, 0.0581553
709 { 0.0406631, 0.0419177,
710 0.0429259, 0.0440614, 0.0451823, 0.0467889, 0.0483670, 0.0501810,
712 { 0.0366926, 0.0377500, 0.0384530, 0.0393431,
713 0.0404503, 0.0419569, 0.0434430, 0.0451987, 0.0473454},
715 0.0343793, 0.0352937, 0.0358116, 0.0364891, 0.0374246, 0.0385732,
716 0.0398924, 0.0414707, 0.0435983
718 { 0.0331561, 0.0337733,
719 0.0341567, 0.0346916, 0.0354239, 0.0364011, 0.0374280, 0.0387133,
729 for (
i = 0;
i <
NS - 1;
i++) {
730 if (csz < cszt[
i + 1]) {
738 for (
i = 0;
i <
NT - 1;
i++) {
739 if (tau < taut[
i + 1]) {
746 stot = cszt[s2] - cszt[s1];
747 sdist = csz - cszt[s1];
748 ttot = taut[t2] - taut[t1];
749 tdist = tau - taut[t1];
751 slope = (ast[s2][t1] - ast[s1][t1]) / stot;
752 alb1[0] = ast[s1][t1] + (
slope * sdist);
753 slope = (ast[s2][t2] - ast[s1][t2]) / stot;
754 alb1[1] = ast[s1][t2] + (
slope * sdist);
756 slope = (alb1[1] - alb1[0]) / ttot;
757 as = alb1[0] + (
slope * tdist);
775 float cszt[
NS] = {0.05, 0.09, 0.15, 0.21, 0.27, 0.33, 0.39, 0.45, 0.52,
776 0.60, 0.68, 0.76, 0.84, 0.92, 1.00};
778 float ast[
NS] = {0.0623166, 0.0630070, 0.0640739, 0.0650397, 0.0657760,
779 0.0661690, 0.0659415, 0.0651271, 0.0635101, 0.0610652, 0.0583470,
780 0.0556146, 0.0530646, 0.0509498, 0.0490149};
788 for (
i = 0;
i <
NS;
i++) {
789 if (csz < cszt[
i + 1]) {
796 stot = cszt[s2] - cszt[s1];
797 sdist = csz - cszt[s1];
799 slope = (ast[s2] - ast[s1]) / stot;
800 as = ast[s1] + (
slope * sdist);