47 static float *tablewavelengths;
48 static float *tablephaseangles;
49 static float *tablealphas;
50 static float *tableomegas;
51 static float *tableaerphasefunc;
53 #define FILE_ERROR(str, name) { if (str.fid == -1) { \
54 printf("-Error--: could not open \"%s\" for reading.\n, See line %d in %s. Exiting...", name, __LINE__, __FILE__); \
59 float CosSZ = cos(
solz *
M_PI / 180.0);
60 return (1.003198 * CosSZ + 0.101632) /
61 (CosSZ * CosSZ + 0.090560 * CosSZ + 0.003198);
64 size_t search(
const float *arr,
size_t s,
size_t e,
float val,
size_t *i_s,
66 const bool acsending = arr[
s] < arr[e];
91 size_t m = (
s + e) / 2;
115 for (
size_t i = 0;
i < n_dims;
i++) {
122 const size_t *indexes) {
134 float ans = (hyper_cube[1] - hyper_cube[0]) * width[0] + hyper_cube[0];
137 size_t total_index = pow(2, n_dims - 1);
138 float *small_hypercube = (
float *) calloc(total_index,
sizeof(
float));
139 for (
size_t ind = 0; ind < total_index; ind++) {
140 small_hypercube[ind] =
141 (hyper_cube[ind + total_index] - hyper_cube[ind]) * width[0] +
153 free(small_hypercube);
158 float interpnd(
size_t n_dims,
const size_t *dims,
const float *point,
159 float **grid,
const float *lut) {
160 size_t *st_pts = (
size_t *) calloc(n_dims,
sizeof(
size_t));
161 size_t *end_pts = (
size_t *) calloc(n_dims,
sizeof(
size_t));;
162 for (
size_t i_dim = 0; i_dim < n_dims; i_dim++) {
163 size_t dim_size = dims[i_dim];
165 size_t end = dim_size - 1;
168 end_pts[i_dim] =
end;
170 size_t total_index = pow(2, n_dims);
171 float *hypercube = (
float *) calloc(total_index,
sizeof(
float));
172 float *width = (
float *) calloc(n_dims,
sizeof(
float));
173 size_t *indexes = (
size_t *) calloc(n_dims,
sizeof(
size_t));
174 for (
size_t i_dim = 0; i_dim < n_dims; i_dim++) {
175 size_t st = st_pts[i_dim];
176 size_t end = end_pts[i_dim];
178 width[i_dim] = (point[i_dim] - grid[i_dim][
st]) /
179 (grid[i_dim][
end] - grid[i_dim][
st]);
185 for (
size_t i = 0;
i < total_index;
i++) {
186 size_t hyper_cube_index = 0;
187 for (
size_t i_dim = 0; i_dim < n_dims; i_dim++) {
188 size_t bit = (
i >> i_dim) & 1;
190 indexes[i_dim] = end_pts[i_dim];
191 hyper_cube_index += pow(2, n_dims - i_dim - 1);
193 indexes[i_dim] = st_pts[i_dim];
201 hypercube[hyper_cube_index] = lut[index_lut];
219 int status = nc_inq_dimid((*struct_nc).fid,
name, &dim_id);
220 if (
status == 0)
status = nc_inq_dimlen((*struct_nc).fid, dim_id, len);
222 printf(
"--Error--: Dimension %s could not be read. See line %d in %s. Exiting...",
name, __LINE__, __FILE__);
230 int status = nc_inq_varid((*struct_nc).fid,
name, &var_id);
234 printf(
"--Error--: Variable %s could not be read. See line %d in %s. Exiting...",
name, __LINE__, __FILE__);
245 const char *dataroot = getenv(
"OCDATAROOT");
246 char lut_rho_path[FILENAME_MAX] =
"";
247 char lut_tg_path[FILENAME_MAX] =
"";
248 char lut_td_path[FILENAME_MAX] =
"";
249 char lut_dobson_path[FILENAME_MAX] =
"";
250 char lut_watvap_path[FILENAME_MAX] =
"";
251 char lut_surfoceanalbedo[FILENAME_MAX] =
"";
252 char luts_scalar_par_path[FILENAME_MAX] =
"";
253 char luts_scalar_inst_par_path[FILENAME_MAX] =
"";
254 sprintf(lut_rho_path,
"%s/common/LUT_rho.nc", dataroot);
255 sprintf(lut_td_path,
"%s/common/LUT_td.nc", dataroot);
256 sprintf(lut_tg_path,
"%s/common/LUT_tg.nc", dataroot);
257 sprintf(lut_dobson_path,
"%s/common/LUT_dobson.nc", dataroot);
258 sprintf(lut_watvap_path,
"%s/common/LUT_watvap.nc", dataroot);
259 sprintf(lut_surfoceanalbedo,
"%s/common/LUT_ocean_surface_albedo.nc",
261 sprintf(luts_scalar_par_path,
"%s/common/LUT_scalar_PAR.nc", dataroot);
262 sprintf(luts_scalar_inst_par_path,
"%s/common/LUT_scalar_inst_PAR.nc", dataroot);
263 int16_t year, month, mday, doy;
265 unix2yds(l2rec->l1rec->scantime, &year, &doy, &sec);
266 unix2ymds(l2rec->l1rec->scantime, &year, &month, &mday, &sec);
272 angstrom_coefficients, optical_depth_at_550_nm,
wavelength;
274 get_nc_dim(&luts_rho_struct,
"view_zenith_angle", &view_zenith_angle);
275 get_nc_dim(&luts_rho_struct,
"relative_azimuth_angle",
277 get_nc_dim(&luts_rho_struct,
"angstrom_coefficients",
278 &angstrom_coefficients);
279 get_nc_dim(&luts_rho_struct,
"optical_depth_at_550_nm",
280 &optical_depth_at_550_nm);
282 size_t start[] = {0, 0, 0, 0, 0, 0};
289 luts_data->lut_rho = calloc(size_all,
sizeof(
float));
292 luts_data->rhodims.dimview_zenith_angle = view_zenith_angle;
294 luts_data->rhodims.dimangstrom_coefficients = angstrom_coefficients;
295 luts_data->rhodims.dimoptical_depth_at_550_nm = optical_depth_at_550_nm;
301 calloc(view_zenith_angle,
sizeof(
float));
302 luts_data->rhodims.relative_azimuth_angle =
304 luts_data->rhodims.angstrom_coefficients =
305 calloc(angstrom_coefficients,
sizeof(
float));
306 luts_data->rhodims.optical_depth_at_550_nm =
307 calloc(optical_depth_at_550_nm,
sizeof(
float));
311 size_t start_dim[] = {0};
312 size_t count_dim[] = {0};
314 get_nc_var(&luts_rho_struct,
"solar_zenith_angle",
315 luts_data->rhodims.solar_zenith_angle, start_dim, count_dim);
317 count_dim[0] = view_zenith_angle;
318 get_nc_var(&luts_rho_struct,
"view_zenith_angle",
319 luts_data->rhodims.view_zenith_angle, start_dim, count_dim);
322 get_nc_var(&luts_rho_struct,
"relative_azimuth_angle",
323 luts_data->rhodims.relative_azimuth_angle, start_dim,
326 count_dim[0] = angstrom_coefficients;
327 get_nc_var(&luts_rho_struct,
"angstrom_coefficients",
328 luts_data->rhodims.angstrom_coefficients, start_dim,
331 count_dim[0] = optical_depth_at_550_nm;
332 get_nc_var(&luts_rho_struct,
"optical_depth_at_550_nm",
333 luts_data->rhodims.optical_depth_at_550_nm, start_dim,
338 luts_data->rhodims.wavelength, start_dim, count_dim);
340 endDS(luts_rho_struct);
346 size_t wavelength, air_mass, ozone_concentration, water_vapor_pressure;
348 get_nc_dim(&luts_tg_struct,
"air_mass", &air_mass);
349 get_nc_dim(&luts_tg_struct,
"ozone_concentration",
350 &ozone_concentration);
351 get_nc_dim(&luts_tg_struct,
"water_vapor_pressure",
352 &water_vapor_pressure);
353 size_t start[] = {0, 0, 0, 0};
355 ozone_concentration};
356 const size_t size_all =
357 wavelength * air_mass * ozone_concentration * water_vapor_pressure;
358 luts_data->tgdims.dimair_mass = air_mass;
359 luts_data->tgdims.dimozone_concentration = ozone_concentration;
361 luts_data->tgdims.dimwater_vapor_pressure = water_vapor_pressure;
362 luts_data->lut_tg = calloc(size_all,
sizeof(
float));
363 luts_data->tgdims.air_mass = calloc(air_mass,
sizeof(
float));
366 calloc(ozone_concentration,
sizeof(
float));
368 calloc(water_vapor_pressure,
sizeof(
float));
372 size_t start_dim[] = {0};
373 size_t count_dim[] = {0};
377 start_dim, count_dim);
379 count_dim[0] = water_vapor_pressure;
380 get_nc_var(&luts_tg_struct,
"water_vapor_pressure",
381 luts_data->tgdims.water_vapor_pressure, start_dim,
384 count_dim[0] = ozone_concentration;
385 get_nc_var(&luts_tg_struct,
"ozone_concentration",
386 luts_data->tgdims.ozone_concentration, start_dim, count_dim);
388 count_dim[0] = air_mass;
390 start_dim, count_dim);
391 endDS(luts_tg_struct);
397 size_t wavelength, air_mass, angstrom_coefficients,
398 optical_depth_at_550_nm;
400 get_nc_dim(&luts_td_struct,
"air_mass", &air_mass);
401 get_nc_dim(&luts_td_struct,
"angstrom_coefficients",
402 &angstrom_coefficients);
403 get_nc_dim(&luts_td_struct,
"optical_depth_at_550_nm",
404 &optical_depth_at_550_nm);
406 size_t start[] = {0, 0, 0, 0};
408 optical_depth_at_550_nm};
409 const size_t size_all =
wavelength * air_mass * angstrom_coefficients *
410 optical_depth_at_550_nm;
412 luts_data->tddims.dimair_mass = air_mass;
413 luts_data->tddims.dimoptical_depth_at_550_nm = optical_depth_at_550_nm;
415 luts_data->tddims.dimangstrom_coefficients = angstrom_coefficients;
416 luts_data->lut_td = calloc(size_all,
sizeof(
float));
418 luts_data->tddims.air_mass = calloc(air_mass,
sizeof(
float));
420 luts_data->tddims.angstrom_coefficients =
421 calloc(angstrom_coefficients,
sizeof(
float));
422 luts_data->tddims.optical_depth_at_550_nm =
423 calloc(optical_depth_at_550_nm,
sizeof(
float));
426 size_t start_dim[] = {0};
427 size_t count_dim[] = {0};
431 start_dim, count_dim);
433 count_dim[0] = angstrom_coefficients;
434 get_nc_var(&luts_td_struct,
"angstrom_coefficients",
435 luts_data->tddims.angstrom_coefficients, start_dim,
438 count_dim[0] = optical_depth_at_550_nm;
439 get_nc_var(&luts_td_struct,
"optical_depth_at_550_nm",
440 luts_data->tddims.optical_depth_at_550_nm, start_dim,
443 count_dim[0] = air_mass;
445 start_dim, count_dim);
446 endDS(luts_td_struct);
451 idDS luts_dobson_struct =
openDS(lut_dobson_path);
452 FILE_ERROR(luts_dobson_struct, lut_dobson_path)
454 get_nc_dim(&luts_dobson_struct,
"days", &days);
463 const size_t size_all = days *
latitude;
464 luts_data->lut_dobson = calloc(size_all,
sizeof(
float));
466 luts_data->ozonedims.days = calloc(days,
sizeof(
float));
469 size_t start_dim[] = {0};
470 size_t count_dim[] = {0};
473 luts_data->ozonedims.latitude, start_dim, count_dim);
477 luts_data->ozonedims.days, start_dim, count_dim);
479 get_nc_var(&luts_dobson_struct,
"days_no_leap",
480 luts_data->ozonedims.days, start_dim, count_dim);
481 endDS(luts_dobson_struct);
485 idDS luts_watvap_struct =
openDS(lut_watvap_path);
486 FILE_ERROR(luts_watvap_struct, lut_watvap_path)
488 get_nc_dim(&luts_watvap_struct,
"days", &days);
497 const size_t size_all = days *
latitude;
498 luts_data->lut_watvap = calloc(size_all,
sizeof(
float));
500 luts_data->watvapdims.days = calloc(days,
sizeof(
float));
503 size_t start_dim[] = {0};
504 size_t count_dim[] = {0};
507 luts_data->watvapdims.latitude, start_dim, count_dim);
511 luts_data->watvapdims.days, start_dim, count_dim);
513 get_nc_var(&luts_watvap_struct,
"days_no_leap",
514 luts_data->watvapdims.days, start_dim, count_dim);
515 endDS(luts_watvap_struct);
519 idDS luts_soa_struct =
openDS(lut_surfoceanalbedo);
520 FILE_ERROR(luts_soa_struct, lut_surfoceanalbedo)
521 size_t dim_jwvl, dim_wv1, dim_wv3, dim_wlt_reft;
522 get_nc_dim(&luts_soa_struct,
"dim_jwvl", &dim_jwvl);
523 get_nc_dim(&luts_soa_struct,
"dim_wv1", &dim_wv1);
524 get_nc_dim(&luts_soa_struct,
"dim_wv3", &dim_wv3);
525 get_nc_dim(&luts_soa_struct,
"dim_wlt_reft", &dim_wlt_reft);
530 luts_data->soa_lut.dim_wlt_reft = dim_wlt_reft;
532 luts_data->soa_lut.jwl = (
float *) calloc(dim_jwvl,
sizeof(
float));
533 luts_data->soa_lut.achl = (
float *) calloc(dim_jwvl,
sizeof(
float));
535 luts_data->soa_lut.wv1 = (
float *) calloc(dim_wv1,
sizeof(
float));
536 luts_data->soa_lut.bw1 = (
float *) calloc(dim_wv1,
sizeof(
float));
538 luts_data->soa_lut.wv3 = (
float *) calloc(dim_wv3,
sizeof(
float));
539 luts_data->soa_lut.aw3 = (
float *) calloc(dim_wv3,
sizeof(
float));
542 (
float *) calloc(dim_wlt_reft,
sizeof(
float));
543 luts_data->soa_lut.reft = (
float *) calloc(dim_wlt_reft,
sizeof(
float));
545 size_t start_dim[] = {0};
546 size_t count_dim[] = {0};
548 count_dim[0] = dim_jwvl;
554 count_dim[0] = dim_wv1;
560 count_dim[0] = dim_wv3;
566 count_dim[0] = dim_wlt_reft;
568 start_dim, count_dim);
571 endDS(luts_soa_struct);
575 idDS luts_scalar_par_struct =
openDS(luts_scalar_par_path);
576 FILE_ERROR(luts_scalar_par_struct, luts_scalar_par_path)
577 size_t dim_wind_speed, dim_doy, dim_latitude;
578 get_nc_dim(&luts_scalar_par_struct,
"wind_speed", &dim_wind_speed);
579 get_nc_dim(&luts_scalar_par_struct,
"doy", &dim_doy);
580 get_nc_dim(&luts_scalar_par_struct,
"latitude", &dim_latitude);
581 luts_data->scalar_luts.dim_latitude = dim_latitude;
582 luts_data->scalar_luts.dim_wind_speed = dim_wind_speed;
583 luts_data->scalar_luts.dim_doy = dim_doy;
585 (
float *) calloc(dim_latitude,
sizeof(
float));
586 luts_data->scalar_luts.doy = (
float *) calloc(dim_doy,
sizeof(
float));
588 (
float *) calloc(dim_wind_speed,
sizeof(
float));
589 size_t start_dim[] = {0};
590 size_t count_dim[] = {0};
591 count_dim[0] = dim_latitude;
592 get_nc_var(&luts_scalar_par_struct,
"latitude",
593 luts_data->scalar_luts.latitude, start_dim, count_dim);
594 count_dim[0] = dim_wind_speed;
595 get_nc_var(&luts_scalar_par_struct,
"wind_speed",
596 luts_data->scalar_luts.wind_speed, start_dim, count_dim);
597 count_dim[0] = dim_doy;
599 start_dim, count_dim);
601 size_t start[] = {0, 0, 0};
602 size_t count[] = {dim_wind_speed, dim_doy, dim_latitude};
603 const size_t size_all = dim_wind_speed * dim_doy * dim_latitude;
604 luts_data->scalar_luts.CF = (
float *) calloc(size_all,
sizeof(
float));
606 (
float *) calloc(size_all,
sizeof(
float));
608 (
float *) calloc(size_all,
sizeof(
float));
609 luts_data->scalar_luts.PARo = (
float *) calloc(size_all,
sizeof(
float));
611 (
float *) calloc(size_all,
sizeof(
float));
613 (
float *) calloc(size_all,
sizeof(
float));
616 get_nc_var(&luts_scalar_par_struct,
"mu_cosine",
618 get_nc_var(&luts_scalar_par_struct,
"mu_cosine_c",
624 get_nc_var(&luts_scalar_par_struct,
"PARc_above",
630 idDS luts_scalar_par_inst_struct =
openDS(luts_scalar_inst_par_path);
631 FILE_ERROR(luts_scalar_par_inst_struct, luts_scalar_inst_par_path)
632 size_t dim_wind_speed, dim_solz, dim_cot;
633 get_nc_dim(&luts_scalar_par_inst_struct,
"wind_speed", &dim_wind_speed);
634 get_nc_dim(&luts_scalar_par_inst_struct,
"solz", &dim_solz);
635 get_nc_dim(&luts_scalar_par_inst_struct,
"cot", &dim_cot);
636 luts_data->scalar_inst_luts.dim_wind_speed = dim_wind_speed;
637 luts_data->scalar_inst_luts.dim_solz = dim_solz;
638 luts_data->scalar_inst_luts.dim_cot = dim_cot;
639 luts_data->scalar_inst_luts.wind_speed = (
float *) calloc(dim_wind_speed,
sizeof(
float));
640 luts_data->scalar_inst_luts.cos_solz = (
float *) calloc(dim_solz,
sizeof(
float));
641 luts_data->scalar_inst_luts.cot = (
float *) calloc(dim_cot,
sizeof(
float));
642 luts_data->scalar_inst_luts.pard_m_cs = (
float *) calloc(dim_wind_speed * dim_solz,
sizeof(
float));
643 luts_data->scalar_inst_luts.pard_p_cs = (
float *) calloc(dim_wind_speed * dim_solz,
sizeof(
float));
644 luts_data->scalar_inst_luts.pard_m_oc = (
float *) calloc(dim_wind_speed * dim_solz,
sizeof(
float));
645 luts_data->scalar_inst_luts.cf_pard_m = (
float *) calloc(dim_wind_speed * dim_solz * dim_cot,
sizeof(
float));
646 luts_data->scalar_inst_luts.cf_pard_p = (
float *) calloc(dim_wind_speed * dim_solz * dim_cot,
sizeof(
float));
650 size_t start[] = {0};
651 size_t count[] = {dim_wind_speed};
652 get_nc_var(&luts_scalar_par_inst_struct,
"wind_speed",
luts_data->scalar_inst_luts.wind_speed,
663 size_t start[] = {0, 0, 0};
664 size_t count[] = {dim_wind_speed, dim_solz, dim_cot};
665 get_nc_var(&luts_scalar_par_inst_struct,
"PARo_below_clear_sky",
luts_data->scalar_inst_luts.pard_m_cs,
667 get_nc_var(&luts_scalar_par_inst_struct,
"PARd_above_clear_sky",
luts_data->scalar_inst_luts.pard_p_cs,
669 get_nc_var(&luts_scalar_par_inst_struct,
"PARo_below_overcast",
luts_data->scalar_inst_luts.pard_m_oc,
672 get_nc_var(&luts_scalar_par_inst_struct,
"CF_PARo_below",
luts_data->scalar_inst_luts.cf_pard_m,
674 get_nc_var(&luts_scalar_par_inst_struct,
"CF_PARd_above",
luts_data->scalar_inst_luts.cf_pard_p,
681 float *aerphasefunc,
float *
omega,
float *modelAngstrom) {
682 float phaseangle = l2rec->l1rec->scattang[ip];
683 float distx, dista,
p1, p2;
684 int i,
j, ix1 = 0, ix2, ia1 = 0, ia2, widx;
686 static int firstCall =
TRUE;
691 int ii[12] = {1, 0, 5, 4, 8, 7, 3, 2, 6, 11, 10, 9};
708 tablealphas, tableomegas, tableaerphasefunc);
713 if (phaseangle < tablephaseangles[0]) {
716 phaseangle = tablephaseangles[0];
718 }
else if (phaseangle >= tablephaseangles[
NPHASE - 1]) {
721 phaseangle = tablephaseangles[
NPHASE - 1];
725 if (phaseangle >= tablephaseangles[
i]) {
733 distx = (tablephaseangles[ix2] - phaseangle) /
734 (tablephaseangles[ix2] - tablephaseangles[ix1]);
740 if (angstrom < tablealphas[widx *
NMODEL + ii[0]]) {
741 angstrom = tablealphas[widx *
NMODEL + ii[0]];
743 }
else if (angstrom >= tablealphas[widx *
NMODEL + ii[
NMODEL - 1]]) {
748 if (angstrom >= tablealphas[widx *
NMODEL + ii[
j]]) {
755 dista = (tablealphas[widx *
NMODEL + ii[ia2]] - angstrom) /
756 (tablealphas[widx *
NMODEL + ii[ia2]] -
757 tablealphas[widx *
NMODEL + ii[ia1]]);
763 (tableomegas[
i *
NMODEL + ii[ia2]] * (1.0 - dista));
765 modelAngstrom[
i] = (tablealphas[
i *
NMODEL + ii[ia1]] * dista) +
766 (tablealphas[
i *
NMODEL + ii[ia2]] * (1.0 - dista));
778 aerphasefunc[
i] = (
p1 * dista) + (p2 * (1.0 - dista));
803 float *tablephaseangles,
float *tablealphas,
804 float *tableomegas,
float *tableaerphasefunc) {
807 char aerosolfilename[FILENAME_MAX] =
"";
811 if ((dataroot = getenv(
"OCDATAROOT")) ==
NULL) {
812 printf(
"OCDATAROOT environment variable is not defined.\n");
815 sprintf(aerosolfilename,
"%s/%s/%s_aerosol_par.dat", dataroot,
820 if ((aerosoldata = fopen(aerosolfilename,
"r")) ==
NULL) {
821 printf(
"Error reading aerosol table for PAR from %s.\n",
825 printf(
"Loading aerosol properties for PAR from %s.\n", aerosolfilename);
828 for (jj = 0; jj <
NPHASE; jj++) {
829 if ((fscanf(aerosoldata,
"%f", &tablephaseangles[jj])) == 0) {
830 printf(
"Problem reading phase angles from %s.\n", aerosolfilename);
835 for (iph = 0; iph <
NMODEL; iph++) {
836 if ((fscanf(aerosoldata,
"%d %d %f", &imodel[iph], &num_model,
837 &tablewavelengths[
j])) == 0) {
838 printf(
"Problem reading model number and wavelength from %s.\n",
842 if ((fscanf(aerosoldata,
"%f %f", &tableomegas[
j *
NMODEL + iph],
843 &tablealphas[
j *
NMODEL + iph])) == 0) {
844 printf(
"Problem reading SSA and Angstrom from %s.\n",
848 for (jj = 0; jj <
NPHASE; jj++) {
849 if ((fscanf(aerosoldata,
"%f",
851 iph *
NPHASE + jj])) == 0) {
852 printf(
"Problem reading phase function values from %s.\n",
878 float daymid, d1, d2;
879 float t, t1, t2,
fac, fac2, difflat;
882 int tabdobson[12][35] = {
883 {395, 395, 395, 395, 395, 392, 390, 387, 376, 354, 322, 292,
884 269, 254, 248, 246, 247, 251, 255, 260, 266, 271, 277, 286,
885 295, 306, 319, 334, 344, 344, 338, 331, 324, 320, 316},
887 {433, 433, 433, 436, 432, 428, 426, 418, 402, 374, 338, 303,
888 278, 261, 251, 246, 248, 250, 254, 258, 262, 265, 270, 278,
889 286, 294, 303, 313, 322, 325, 324, 317, 306, 299, 294},
891 {467, 470, 460, 459, 451, 441, 433, 420, 401, 377, 347, 316,
892 291, 271, 260, 254, 254, 255, 257, 259, 261, 264, 269, 277,
893 284, 289, 296, 305, 312, 315, 317, 312, 305, 299, 295},
895 {467, 465, 462, 455, 444, 431, 421, 410, 395, 373, 348, 325,
896 304, 287, 275, 267, 261, 259, 258, 259, 260, 263, 271, 278,
897 284, 289, 297, 306, 314, 318, 319, 313, 302, 302, 302},
899 {411, 414, 416, 415, 410, 406, 402, 394, 382, 363, 342, 324,
900 307, 291, 279, 271, 264, 260, 258, 257, 258, 264, 271, 281,
901 291, 303, 312, 318, 322, 323, 322, 322, 322, 322, 322},
903 {371, 371, 370, 368, 367, 372, 375, 372, 360, 341, 323, 311,
904 301, 290, 282, 275, 268, 263, 259, 256, 258, 264, 273, 289,
905 306, 319, 327, 328, 328, 337, 337, 337, 337, 337, 337},
907 {333, 332, 332, 334, 338, 346, 350, 346, 335, 321, 310, 302,
908 296, 289, 284, 280, 274, 268, 262, 259, 261, 268, 279, 295,
909 315, 331, 340, 342, 338, 344, 340, 340, 340, 340, 340},
911 {311, 308, 308, 313, 320, 327, 330, 326, 319, 310, 303, 298,
912 291, 286, 283, 281, 277, 273, 268, 264, 266, 274, 288, 306,
913 327, 343, 353, 355, 351, 339, 325, 307, 294, 294, 294},
915 {283, 291, 302, 308, 312, 317, 318, 313, 307, 300, 295, 290,
916 284, 279, 279, 279, 278, 276, 272, 270, 273, 282, 295, 313,
917 333, 348, 360, 367, 368, 353, 324, 291, 267, 253, 230},
919 {299, 299, 299, 309, 315, 317, 317, 312, 302, 291, 283, 280,
920 275, 270, 268, 267, 263, 263, 265, 269, 277, 287, 301, 317,
921 336, 354, 371, 387, 402, 402, 374, 333, 294, 274, 259},
923 {314, 314, 314, 314, 332, 332, 327, 322, 311, 297, 284, 276,
924 270, 263, 261, 260, 258, 259, 264, 270, 278, 286, 298, 311,
925 323, 335, 350, 366, 381, 390, 388, 376, 357, 346, 341},
927 {358, 358, 358, 358, 358, 358, 353, 349, 338, 320, 299, 281,
928 267, 256, 252, 251, 251, 253, 257, 264, 272, 279, 287, 297,
929 307, 318, 332, 347, 358, 365, 366, 364, 358, 356, 353}};
931 int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
935 if (year % 4 == 0) days[1] = days[1] + 1;
937 daymid = days[month - 1] / 2.0;
952 t2 = days[m1] + (days[m2] / 2.0);
957 d1 = tabdobson[m1][1];
958 d2 = tabdobson[m2][1];
959 }
else if (
lat <= -85.0) {
960 d1 = tabdobson[m1][34];
961 d2 = tabdobson[m2][34];
963 i1 = 17 - (
int) (
lat / 5.0);
965 fac = (tabdobson[month][i2] - tabdobson[month][i1]) / (-5.0);
966 difflat =
lat - (90.0 - (i1 * 5.0));
967 d1 = tabdobson[m1][i1] + (
fac * difflat);
968 d2 = tabdobson[m2][i1] + (
fac * difflat);
973 fac2 = (d2 - d1) / (t2 - t1);
975 dobson = d1 + (
t - t1) * fac2;
1005 float daymid, d1, d2;
1006 float t, t1, t2,
fac, fac2, difflat;
1009 float tabwv[12][35] = {
1010 {0.42, 0.47, 0.52, 0.56, 0.61, 0.66, 0.71, 0.75, 0.80, 0.85, 1.26, 1.67,
1011 2.08, 2.48, 2.89, 3.30, 3.71, 4.12, 3.97, 3.82, 3.67, 3.53, 3.38, 3.23,
1012 3.08, 2.93, 2.84, 2.75, 2.65, 2.56, 2.47, 2.38, 2.28, 2.19, 2.10},
1014 {0.70, 0.76, 0.81, 0.87, 0.92, 0.98, 1.03, 1.09, 1.14, 1.20, 1.56, 1.93,
1015 2.29, 2.66, 3.02, 3.39, 3.75, 4.12, 3.93, 3.74, 3.54, 3.35, 3.16, 2.97,
1016 2.78, 2.58, 2.50, 2.41, 2.33, 2.24, 2.16, 2.07, 1.99, 1.90, 1.82},
1018 {0.98, 1.04, 1.11, 1.17, 1.23, 1.29, 1.36, 1.42, 1.48, 1.54, 1.87, 2.19,
1019 2.51, 2.83, 3.15, 3.48, 3.80, 4.12, 3.88, 3.65, 3.41, 3.18, 2.94, 2.71,
1020 2.47, 2.24, 2.16, 2.08, 2.00, 1.93, 1.85, 1.77, 1.69, 1.62, 1.54},
1022 {1.26, 1.33, 1.40, 1.47, 1.54, 1.61, 1.68, 1.75, 1.82, 1.89, 2.17, 2.45,
1023 2.73, 3.01, 3.28, 3.56, 3.84, 4.12, 3.84, 3.56, 3.28, 3.01, 2.73, 2.45,
1024 2.17, 1.89, 1.82, 1.75, 1.68, 1.61, 1.54, 1.47, 1.40, 1.33, 1.26},
1026 {1.54, 1.62, 1.69, 1.77, 1.85, 1.93, 2.00, 2.08, 2.16, 2.24, 2.47, 2.71,
1027 2.94, 3.18, 3.41, 3.65, 3.88, 4.12, 3.80, 3.48, 3.15, 2.83, 2.51, 2.19,
1028 1.87, 1.54, 1.48, 1.42, 1.36, 1.29, 1.23, 1.17, 1.11, 1.04, 0.98},
1030 {1.82, 1.90, 1.99, 2.07, 2.16, 2.24, 2.33, 2.41, 2.50, 2.58, 2.78, 2.97,
1031 3.16, 3.35, 3.54, 3.74, 3.93, 4.12, 3.75, 3.39, 3.02, 2.66, 2.29, 1.93,
1032 1.56, 1.20, 1.14, 1.09, 1.03, 0.98, 0.92, 0.87, 0.81, 0.76, 0.70},
1034 {2.10, 2.19, 2.28, 2.38, 2.47, 2.56, 2.65, 2.75, 2.84, 2.93, 3.08, 3.23,
1035 3.38, 3.53, 3.67, 3.82, 3.97, 4.12, 3.71, 3.30, 2.89, 2.49, 2.08, 1.67,
1036 1.26, 0.85, 0.80, 0.75, 0.71, 0.66, 0.61, 0.56, 0.52, 0.47, 0.42},
1038 {1.82, 1.90, 1.99, 2.07, 2.16, 2.24, 2.33, 2.41, 2.50, 2.58, 2.78, 2.97,
1039 3.16, 3.35, 3.54, 3.74, 3.93, 4.12, 3.75, 3.39, 3.02, 2.66, 2.29, 1.93,
1040 1.56, 1.20, 1.14, 1.09, 1.03, 0.98, 0.92, 0.87, 0.81, 0.76, 0.70},
1042 {1.54, 1.62, 1.69, 1.77, 1.85, 1.93, 2.00, 2.08, 2.16, 2.24, 2.47, 2.71,
1043 2.94, 3.18, 3.41, 3.65, 3.88, 4.12, 3.80, 3.48, 3.15, 2.83, 2.51, 2.19,
1044 1.87, 1.54, 1.48, 1.42, 1.36, 1.29, 1.23, 1.17, 1.11, 1.04, 0.98},
1046 {1.26, 1.33, 1.40, 1.47, 1.54, 1.61, 1.68, 1.75, 1.82, 1.89, 2.17, 2.45,
1047 2.73, 3.01, 3.28, 3.56, 3.84, 4.12, 3.84, 3.56, 3.28, 3.01, 2.73, 2.45,
1048 2.17, 1.89, 1.82, 1.75, 1.68, 1.61, 1.54, 1.47, 1.40, 1.33, 1.26},
1050 {0.98, 1.04, 1.11, 1.17, 1.23, 1.29, 1.36, 1.42, 1.48, 1.54, 1.87, 2.19,
1051 2.51, 2.83, 3.15, 3.48, 3.80, 4.12, 3.88, 3.65, 3.41, 3.18, 2.94, 2.71,
1052 2.47, 2.24, 2.16, 2.08, 2.00, 1.93, 1.85, 1.77, 1.69, 1.62, 1.54},
1054 {0.70, 0.76, 0.81, 0.87, 0.92, 0.98, 1.03, 1.09, 1.14, 1.20, 1.56, 1.93,
1055 2.29, 2.66, 3.02, 3.39, 3.75, 4.12, 3.93, 3.74, 3.54, 3.35, 3.16, 2.97,
1056 2.78, 2.58, 2.50, 2.41, 2.33, 2.24, 2.16, 2.07, 1.99, 1.90, 1.82}};
1058 int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
1062 if (year % 4 == 0) days[1] = days[1] + 1;
1064 daymid = days[month] / 2.0;
1066 if (
day >= daymid) {
1069 if (m2 > 11) m2 = 0;
1074 if (m1 < 0) m1 = 11;
1078 t1 = days[m1] / 2.0;
1079 t2 = days[m1] + (days[m2] / 2.0);
1086 }
else if (
lat <= (-85.0)) {
1090 i1 = 16 - (
int) (
lat / 5.0);
1092 fac = (tabwv[month][i2] - tabwv[month][i1]) / (-5.0);
1093 difflat =
lat - (90.0 - (i1 * 5.0));
1094 d1 = tabwv[m1][i1] + (
fac * difflat);
1095 d2 = tabwv[m2][i1] + (
fac * difflat);
1100 fac2 = (d2 - d1) / (t2 - t1);
1102 watvap = d1 + (
t - t1) * fac2;
1121 dsol = 1.f / powf((1.
f - .01673
f * cosf(om)), 2.
f);
1132 float fac, xlo, xla, xj, a1, a2, et, a3,
delta, cosah, ah1, ah2, tsv1, tsv2,
1141 a1 = (1.00554f * xj - 6.28306f) *
fac;
1142 a2 = (1.93946f * xj + 23.35089f) *
fac;
1143 et = -7.67825f * sinf(a1) - 10.09176f * sinf(a2);
1144 a3 = (0.9683f * xj - 78.00878f) *
fac;
1147 cosah = (-(sinf(xla) * sinf(
delta))) / (cosf(xla) * cosf(
delta));
1149 if ((cosah < -1.
f) || (cosah > 1.f)) {
1158 tsv1 = ah1 / (15.f *
fac);
1159 tsv2 = ah2 / (15.f *
fac);
1160 tsm1 = tsv1 + 12.f - et / 60.f;
1161 tsm2 = tsv2 + 12.f - et / 60.f;
1163 *trise = tsm2 - (xlo / (15.f *
fac));
1164 *tset = tsm1 - (xlo / (15.f *
fac));
1174 double tsm, xla, xj, tet, a1, a2, a3, a4, a5, et, tsv, ah,
b1, b2, b3, b4,
1175 b5, b6, b7,
delta, amuzero, elev, az, caz, azim, pi2;
1185 tet = 2. *
M_PI * xj / 365.;
1193 et = a1 + a2 * cos(tet) - a3 * sin(tet) - a4 * cos(2. * tet) -
1195 et = et * 12. * 60. /
M_PI;
1199 tsv = tsm + et / 60.;
1204 ah = tsv * 15. *
fac;
1215 delta =
b1 - b2 * cos(tet) + b3 * sin(tet) - b4 * cos(2. * tet) +
1216 b5 * sin(2. * tet) - b6 * cos(3. * tet) + b7 * sin(3. * tet);
1220 amuzero = sin(xla) * sin(
delta) + cos(xla) * cos(
delta) * cos(ah);
1221 if ((
fabs(amuzero) - 1.000) > 0.00000) amuzero = copysign(amuzero, 1.);
1222 elev = asin(amuzero);
1223 az = cos(
delta) * sin(ah) / cos(elev);
1224 if ((
fabs(az) - 1.000) > 0.00000) az = copysign(az, 1.);
1227 (-cos(xla) * sin(
delta) + sin(xla) * cos(
delta) * cos(ah)) / cos(elev);
1230 if (caz <= 0.) azim =
M_PI - azim;
1232 if (caz > 0. && az <= 0.) azim = 2. *
M_PI + azim;
1237 if (azim > pi2) azim -= pi2;
1243 asol = (
float) (90. - elev);
1259 int s1, s2, t1, t2,
i;
1261 float stot, sdist, ttot, tdist,
slope, alb1[2],
as;
1263 float cszt[
NS] = {0.05, 0.09, 0.15, 0.21, 0.27, 0.33, 0.39, 0.45,
1264 0.52, 0.60, 0.68, 0.76, 0.84, 0.92, 1.00};
1266 float taut[
NT] = {0.00, 0.05, 0.10, 0.16, 0.24, 0.35, 0.50, 0.70, 0.99};
1271 float ast[
NS][
NT] = {{0.1592253, 0.1258933, 0.1088253, 0.0968594, 0.0880966,
1272 0.0815492, 0.0766266, 0.0721790, 0.0679746},
1273 {0.1944972, 0.1637040, 0.1432702, 0.1240363, 0.1066057,
1274 0.0922638, 0.0826043, 0.0757601, 0.0700167},
1275 {0.1978650, 0.1785707, 0.1643212, 0.1482773, 0.1304572,
1276 0.1119496, 0.0963537, 0.0839010, 0.0740948},
1277 {0.1785221, 0.1673987, 0.1589092, 0.1486409, 0.1359193,
1278 0.1209508, 0.1061981, 0.0920763, 0.0793196},
1279 {0.1531512, 0.1473233, 0.1426633, 0.1366985, 0.1289257,
1280 0.1188203, 0.1078114, 0.0957847, 0.0831087},
1281 {0.1281988, 0.1255739, 0.1234628, 0.1204020, 0.1161201,
1282 0.1101539, 0.1030820, 0.0943791, 0.0841410},
1283 {0.1061354, 0.1052812, 0.1048179, 0.1036617, 0.1016918,
1284 0.0986726, 0.0948040, 0.0894514, 0.0822926},
1285 {0.0877530, 0.0881279, 0.0883850, 0.0884469, 0.0880587,
1286 0.0870923, 0.0854952, 0.0826607, 0.0782380},
1287 {0.0708031, 0.0720173, 0.0727886, 0.0736250, 0.0741367,
1288 0.0746769, 0.0747173, 0.0741294, 0.0722523},
1289 {0.0567974, 0.0582123, 0.0593260, 0.0604172, 0.0615151,
1290 0.0627740, 0.0639047, 0.0647193, 0.0650727},
1291 {0.0472026, 0.0485713, 0.0495830, 0.0507434, 0.0519943,
1292 0.0536504, 0.0551176, 0.0566950, 0.0581553},
1293 {0.0406631, 0.0419177, 0.0429259, 0.0440614, 0.0451823,
1294 0.0467889, 0.0483670, 0.0501810, 0.0522433},
1295 {0.0366926, 0.0377500, 0.0384530, 0.0393431, 0.0404503,
1296 0.0419569, 0.0434430, 0.0451987, 0.0473454},
1297 {0.0343793, 0.0352937, 0.0358116, 0.0364891, 0.0374246,
1298 0.0385732, 0.0398924, 0.0414707, 0.0435983},
1299 {0.0331561, 0.0337733, 0.0341567, 0.0346916, 0.0354239,
1300 0.0364011, 0.0374280, 0.0387133, 0.0405543}};
1308 for (
i = 0;
i <
NS - 1;
i++) {
1309 if (csz < cszt[
i + 1]) {
1317 for (
i = 0;
i <
NT - 1;
i++) {
1318 if (tau < taut[
i + 1]) {
1325 stot = cszt[s2] - cszt[s1];
1326 sdist = csz - cszt[s1];
1327 ttot = taut[t2] - taut[t1];
1328 tdist = tau - taut[t1];
1330 slope = (ast[s2][t1] - ast[s1][t1]) / stot;
1331 alb1[0] = ast[s1][t1] + (
slope * sdist);
1332 slope = (ast[s2][t2] - ast[s1][t2]) / stot;
1333 alb1[1] = ast[s1][t2] + (
slope * sdist);
1335 slope = (alb1[1] - alb1[0]) / ttot;
1336 as = alb1[0] + (
slope * tdist);
1354 float cszt[
NS] = {0.05, 0.09, 0.15, 0.21, 0.27, 0.33, 0.39, 0.45,
1355 0.52, 0.60, 0.68, 0.76, 0.84, 0.92, 1.00};
1357 float ast[
NS] = {0.0623166, 0.0630070, 0.0640739, 0.0650397, 0.0657760,
1358 0.0661690, 0.0659415, 0.0651271, 0.0635101, 0.0610652,
1359 0.0583470, 0.0556146, 0.0530646, 0.0509498, 0.0490149};
1367 for (
i = 0;
i <
NS;
i++) {
1368 if (csz < cszt[
i + 1]) {
1375 stot = cszt[s2] - cszt[s1];
1376 sdist = csz - cszt[s1];
1378 slope = (ast[s2] - ast[s1]) / stot;
1379 as = ast[s1] + (
slope * sdist);
1384 void getcldalbe(
float *TauCld,
float *CF,
float cosSZ,
float t_obs,
1385 float *t_range,
float *albe_obs,
float *TauCld_obs,
1386 float *CF_obs,
size_t t_step,
float *wl,
size_t bands_num) {
1387 float wave[] = {370., 440., 560., 650., 720.};
1388 float a1[] = {0.78, 0.65, 0.53, 0.49, 0.51};
1389 float b1[] = {0.31, 0.59, 0.79, 0.88, 0.82};
1390 float b2[] = {-0.0782, -0.1212, -0.1054, -0.1276, -0.1054};
1391 float b3[] = {-0.9218, -0.8788, -0.8946, -0.8724, -0.8946};
1392 float k1[] = {1.3, 1.3, 1.3, 1.3, 1.3};
1393 float k2[] = {0.2000, 0.0229, 0.0409, 0.0436, 0.0575};
1394 float k3[] = {0.8000, 1.1754, 1.2436, 1.1836, 1.3637};
1395 float cc[] = {0.0835, 0.1008, 0.1153, 0.1215, 0.1307};
1396 float dd[] = {0.0759, 0.0954, 0.1126, 0.1192, 0.1218};
1403 float Stot, Sdist,
slope;
1405 search(t_range, 0, t_step - 1, t_obs, &s1, &s2);
1407 Stot = t_range[s2] - t_range[s1];
1408 Sdist = t_obs - t_range[s1];
1410 if (t_obs <= t_range[0]) Sdist = 0;
1411 if (t_obs >= t_range[t_step - 1]) Sdist = Stot;
1413 slope = (TauCld[s2] - TauCld[s1]) / Stot;
1416 *TauCld_obs = TauCld[s1] + (
slope * Sdist);
1418 slope = (CF[s2] - CF[s1]) / Stot;
1421 *CF_obs = CF[s1] + (
slope * Sdist);
1433 for (
size_t i = 0;
i < 5;
i++) {
1434 aa = a1[
i] + (1 - a1[
i]) * exp(-*TauCld_obs * k1[
i]);
1435 bb =
b1[
i] * (1 + b2[
i] * exp(-*TauCld_obs * k2[
i]) +
1436 b3[
i] * exp(-*TauCld_obs * k3[
i]));
1439 (aa + cosSZ * bb) / (1 + *TauCld_obs * (cc[
i] - dd[
i] *
alpha));
1443 Stot = wave[s2] - wave[s1];
1444 float Sdist = wl[
band] - wave[s1];
1445 float slope = (trc[s2] - trc[s1]) / Stot;
1446 if (s1 == s2)
slope = 0.0;
1447 float trc_obs = trc[s1] + (
slope * Sdist);
1448 albe_obs[
band] = (1 - trc_obs) * (*CF_obs);
1462 float p[] = {0.0152, -1.7873, 6.8972, -8.5778, 4.071, -7.6446,
1463 0.1643, -7.8409, -3.5639, -2.3588, 10.0538};
1465 (
p[0] +
p[1] *
u +
p[2] * pow(
u, 2) +
p[3] * pow(
u, 3) +
p[4] *
v +
1467 exp(
p[6] +
p[7] *
u +
p[8] * pow(
u, 2) +
p[9] *
v +
p[10] *
u *
v);
1476 size_t dims[] = {
luts_data->soa_lut.dim_wlt_reft};
1479 float point[] = {wl};
1481 if (refm > 1.34) refm = 1.34;
1487 float point[] = {wl};
1488 float chlabs, bw, aw;
1491 size_t dims[] = {
luts_data->soa_lut.dim_jwvl};
1498 size_t dims[] = {
luts_data->soa_lut.dim_wv1};
1505 size_t dims[] = {
luts_data->soa_lut.dim_wv3};
1509 const float ylmd = exp(0.014 * (440.0 - wl));
1510 const float aw440 = 0.00635;
1511 const float ap = 0.06 * chlabs * pow(chl, 0.65) +
1512 0.2 * (aw440 + 0.06 * pow(chl, 0.65)) * ylmd;
1514 const float bp550 = 0.416 * pow(chl, 0.766);
1520 bbp = (0.002 + 0.01 * (0.5 - 0.25 * log10(chl))) * bp550;
1523 v = 0.5 * (log10(chl) - 0.3);
1525 (0.002 + 0.01 * (0.5 - 0.25 * log10(chl)) * pow(wl / 550.,
v)) *
1528 bbp = 0.019 * (550. / wl) * bp550;
1533 float hb = 0.5 * bw / (0.5 * bw + bbp);
1538 0.6279 - 0.2227 * hb - 0.0513 * hb * hb + (-0.3119 + 0.2465 * hb) * u0;
1540 float r0 =
f * (0.5 * bw + bbp) / (aw + ap);
1544 float getosa(
float wl,
float sza,
float wind,
float chl,
float fr,
1550 const float sig = sqrt(0.003 + 0.00512 * wind);
1554 const float csz = cos(
sza *
M_PI / 180.);
1556 const float xx2 = sqrt(1.0 - (1.0 - csz * csz) / refm / refm);
1558 float rr0 = (0.5 * (pow(((xx2 - csz * refm) / (xx2 + csz * refm)), 2) +
1559 pow(((csz - refm * xx2) / (csz + refm * xx2)), 2)));
1561 float rrr = 0.5 * (pow(((xx2 - 1.34 * csz) / (xx2 + 1.34 * csz)), 2) +
1562 pow(((csz - 1.34 * xx2) / (csz + 1.34 * xx2)), 2));
1564 const float r11 = rr0 -
ff(csz, sig) * rr0 / rrr;
1568 const float r22 = 0.48168549 - 0.014894708 * sig - 0.20703885 * sig * sig;
1572 const float rw = r00 * (1. - r22) * (1. - r11) /
1577 const float ue2 = sqrt(1.0 - (1.0 - ue * ue) / refm / refm);
1579 rr0 = 0.5 * (pow(((ue2 - refm * ue) / (ue2 + refm * ue)), 2) +
1580 pow(((ue - refm * ue2) / (ue + refm * ue2)), 2));
1581 rrr = 0.5 * (pow(((ue2 - 1.34 * ue) / (ue2 + 1.34 * ue)), 2) +
1582 pow(((ue - 1.34 * ue2) / (ue + 1.34 * ue2)), 2));
1584 float r11df = rr0 -
ff(ue, sig) * rr0 / rrr;
1588 float rwdf = r00 * (1. - r22) * (1. - r11df) /
1591 float pc[] = {-0.1482, -0.012, 0.1609, -0.0244};
1595 rdf = -0.1479 + 0.1502 * refm - 0.0176 * sig * refm;
1597 rdf = pc[0] + pc[1] * sig + pc[2] * refm +
1604 float albt = (1. - fr) * (r11 + rw) +
1608 float fwc = (2.95e-6) * pow(wind, 3.52);
1610 float osa = (1. - fwc) * albt + fwc * 0.55;
1614 float SunGlint(
float sz,
float vz,
float ra,
float ws) {
1615 const float ssz = sin(sz *
M_PI / 180.);
1616 const float svz = sin(vz *
M_PI / 180.);
1617 const float csz = cos(sz *
M_PI / 180.);
1618 const float cvz = cos(vz *
M_PI / 180.);
1619 const float cra = cos(ra *
M_PI / 180.);
1622 const float cos_2omega = csz * cvz + ssz * svz * cra;
1623 const float omega = acos(cos_2omega) / 2.0;
1624 const float sOmega = sin(
omega);
1625 const float cOmega = cos(
omega);
1626 const float omegaP = asin(sOmega / 1.34);
1627 const float omegaDp =
omega + omegaP;
1628 const float omegaDm =
omega - omegaP;
1630 const float term1 = sin(omegaDm) / sin(omegaDp);
1631 const float term2 = tan(omegaDm) / tan(omegaDp);
1632 float r_omega = 0.5 * (term1 * term1 + term2 * term2);
1633 if (
omega < 0.0174533) r_omega = 0.0211119;
1635 const float beta = acos((csz + cvz) / (2.0 * cOmega));
1636 const float cBeta = cos(
beta);
1637 const float tBeta = tan(
beta);
1638 const float sig2 = 0.003 + 0.00512 * ws;
1639 const float P_V_beta =
1640 (1.0 / (2.0 * sig2 *
M_PI)) * exp(-tBeta * tBeta / (2.0 * sig2));
1642 M_PI * P_V_beta * r_omega / (4.0 * csz * cvz * pow((cBeta), 4));
1647 const size_t *dims,
const float *point,
float **grid) {
1648 for (
size_t i_dim = 0; i_dim < ndims; i_dim++) {
1649 size_t dim_size = dims[i_dim];
1651 size_t end = dim_size - 1;
1654 pts[i_dim][1] =
end;
1656 for (
size_t i_dim = 0; i_dim < ndims; i_dim++) {
1657 size_t st = pts[i_dim][0];
1658 size_t end = pts[i_dim][1];
1660 width[i_dim] = (point[i_dim] - grid[i_dim][
st]) /
1661 (grid[i_dim][
end] - grid[i_dim][
st]);
1669 return point[0] * dims[1] * dims[2] * dims[3] * dims[4] * dims[5] +
1670 point[1] * dims[2] * dims[3] * dims[4] * dims[5] +
1671 point[2] * dims[3] * dims[4] * dims[5] +
1672 point[3] * dims[4] * dims[5] + point[4] * dims[5] + point[5];
1675 float interp6d(
const size_t *dims,
const float *point,
float **grid,
1677 const size_t ndims = 6;
1678 size_t pts[ndims][2];
1681 float temp0[2][2][2][2][2][2];
1682 for (
size_t i0 = 0; i0 < 2; i0++)
1683 for (
size_t i1 = 0; i1 < 2; i1++)
1684 for (
size_t i2 = 0; i2 < 2; i2++)
1685 for (
size_t i3 = 0; i3 < 2; i3++)
1686 for (
size_t i4 = 0; i4 < 2; i4++)
1687 for (
size_t i5 = 0; i5 < 2; i5++) {
1688 size_t point_pos[] = {pts[0][i0], pts[1][i1],
1689 pts[2][i2], pts[3][i3],
1690 pts[4][i4], pts[5][i5]};
1691 temp0[i0][i1][i2][i3][i4][i5] =
1694 float temp1[2][2][2][2][2];
1695 for (
size_t i1 = 0; i1 < 2; i1++)
1696 for (
size_t i2 = 0; i2 < 2; i2++)
1697 for (
size_t i3 = 0; i3 < 2; i3++)
1698 for (
size_t i4 = 0; i4 < 2; i4++)
1699 for (
size_t i5 = 0; i5 < 2; i5++) {
1700 temp1[i1][i2][i3][i4][i5] =
1701 (temp0[1][i1][i2][i3][i4][i5] -
1702 temp0[0][i1][i2][i3][i4][i5]) *
1704 temp0[0][i1][i2][i3][i4][i5];
1707 float temp2[2][2][2][2];
1708 for (
size_t i2 = 0; i2 < 2; i2++)
1709 for (
size_t i3 = 0; i3 < 2; i3++)
1710 for (
size_t i4 = 0; i4 < 2; i4++)
1711 for (
size_t i5 = 0; i5 < 2; i5++) {
1712 temp2[i2][i3][i4][i5] =
1713 (temp1[1][i2][i3][i4][i5] - temp1[0][i2][i3][i4][i5]) *
1715 temp1[0][i2][i3][i4][i5];
1718 float temp3[2][2][2];
1719 for (
size_t i3 = 0; i3 < 2; i3++)
1720 for (
size_t i4 = 0; i4 < 2; i4++)
1721 for (
size_t i5 = 0; i5 < 2; i5++) {
1723 (temp2[1][i3][i4][i5] - temp2[0][i3][i4][i5]) * width[2] +
1724 temp2[0][i3][i4][i5];
1727 for (
size_t i4 = 0; i4 < 2; i4++)
1728 for (
size_t i5 = 0; i5 < 2; i5++) {
1729 temp4[i4][i5] = (temp3[1][i4][i5] - temp3[0][i4][i5]) * width[3] +
1734 for (
size_t i5 = 0; i5 < 2; i5++) {
1735 temp5[i5] = (temp4[1][i5] - temp4[0][i5]) * width[4] + temp4[0][i5];
1739 temp6 = (temp5[1] - temp5[0]) * width[5] + temp5[0];
1745 return point[0] * dims[1] * dims[2] * dims[3] +
1746 point[1] * dims[2] * dims[3] + point[2] * dims[3] + point[3];
1749 float interp4d(
const size_t *dims,
const float *point,
float **grid,
1751 const size_t ndims = 4;
1752 size_t pts[ndims][2];
1755 float temp0[2][2][2][2];
1756 for (
size_t i0 = 0; i0 < 2; i0++)
1757 for (
size_t i1 = 0; i1 < 2; i1++)
1758 for (
size_t i2 = 0; i2 < 2; i2++)
1759 for (
size_t i3 = 0; i3 < 2; i3++) {
1760 size_t point_pos[] = {pts[0][i0], pts[1][i1], pts[2][i2],
1762 temp0[i0][i1][i2][i3] = lut[
get4dindex(point_pos, dims)];
1764 float temp1[2][2][2];
1765 for (
size_t i1 = 0; i1 < 2; i1++)
1766 for (
size_t i2 = 0; i2 < 2; i2++)
1767 for (
size_t i3 = 0; i3 < 2; i3++) {
1769 (temp0[1][i1][i2][i3] - temp0[0][i1][i2][i3]) * width[0] +
1770 temp0[0][i1][i2][i3];
1774 for (
size_t i2 = 0; i2 < 2; i2++)
1775 for (
size_t i3 = 0; i3 < 2; i3++) {
1776 temp2[i2][i3] = (temp1[1][i2][i3] - temp1[0][i2][i3]) * width[1] +
1781 for (
size_t i3 = 0; i3 < 2; i3++) {
1782 temp3[i3] = (temp2[1][i3] - temp2[0][i3]) * width[2] + temp2[0][i3];
1786 temp4 = (temp3[1] - temp3[0]) * width[3] + temp3[0];
1792 return point[0] * dims[1] * dims[2] + point[1] * dims[2] + point[2];
1795 float interp3d(
const size_t *dims,
const float *point,
float **grid,
1797 const size_t ndims = 3;
1798 size_t pts[ndims][2];
1801 float temp0[2][2][2];
1802 for (
size_t i0 = 0; i0 < 2; i0++)
1803 for (
size_t i1 = 0; i1 < 2; i1++)
1804 for (
size_t i2 = 0; i2 < 2; i2++) {
1805 size_t point_pos[] = {pts[0][i0], pts[1][i1], pts[2][i2]};
1806 temp0[i0][i1][i2] = lut[
get3dindex(point_pos, dims)];
1809 for (
size_t i1 = 0; i1 < 2; i1++)
1810 for (
size_t i2 = 0; i2 < 2; i2++) {
1811 temp1[i1][i2] = (temp0[1][i1][i2] - temp0[0][i1][i2]) * width[0] +
1816 for (
size_t i2 = 0; i2 < 2; i2++) {
1817 temp2[i2] = (temp1[1][i2] - temp1[0][i2]) * width[1] + temp1[0][i2];
1820 float temp3 = (temp2[1] - temp2[0]) * width[2] + temp2[0];
1825 size_t get1dindex(
const size_t *point,
const size_t *dims) {
return point[0]; }
1827 float interp1d(
const size_t *dims,
const float *point,
float **grid,
1829 const size_t ndims = 1;
1830 size_t pts[ndims][2];
1834 for (
size_t i0 = 0; i0 < 2; i0++) {
1835 size_t point_pos[] = {pts[0][i0]};
1836 temp0[i0] = lut[
get1dindex(point_pos, dims)];
1840 temp1 = (temp0[1] - temp0[0]) * width[0] + temp0[0];