11 #include <gsl/gsl_errno.h>
12 #include <gsl/gsl_interp2d.h>
13 #include <gsl/gsl_spline2d.h>
17 #define ANC_STAT_2T_END 4
19 #define ANC_STAT_2T_START 2
22 #define ANC_STAT_CLIM 0
25 #define OZ_KG_M2_TO_DU 1. / 2.1415e-5
29 #define ANC_SRC_TYP_ECMWF 0
30 #define ANC_SRC_TYP_STD_HDF 1
31 #define ANC_SRC_TYP_OLCI 2
32 #define ANC_SRC_TYP_GMAO 3
33 #define ANC_SRC_TYP_BAD -1
74 static met_sto_str met_sto[
NPRM];
120 char *prm_nm_met[] = {
"sp",
"tcwv",
"msl",
"u10",
"v10",
"t2m",
"d2m"};
121 char *prm_nm_oz[] = {
"tco3"};
122 int32_t n_prm_met = 7, n_prm_oz = 1, sto_ix;
123 static char file_olci_str[FILENAME_MAX];
124 char *file_olci = (
char *) 0;
130 char* ptr = strrchr(file_olci_str,
'/');
133 strcat(file_olci_str,
"/tie_meteo.nc");
135 strcpy(file_olci_str,
"tie_meteo.nc");
137 file_olci = file_olci_str;
139 proc_land =
input->proc_land;
146 if ((anc_id[0] == -1) || (anc_id[1] == -1))
169 if ((anc_id[0] == -1) || (anc_id[1] == -1))
201 int status, ncid, fstat, tie_pt;
202 char *str_attr, lcl_fil[FILENAME_MAX];
208 fprintf(
stderr,
"-E- %s %d: First anc file name is null\n",
218 if ((file_olci != (
char *) 0) &&
219 (strcmp(
upcase(lcl_fil),
"OLCI_TIE_METEO") == 0)) {
221 "-I- %s %d: Ancillary file will be taken from OLCI metadata tie point meteo file: %s\n",
222 __FILE__, __LINE__, file_olci);
233 if (nc_open(
file, 0, &ncid) != NC_NOERR) {
241 if (file_olci != (
char *) 0) {
242 status = nc_inq_attlen(ncid, NC_GLOBAL,
"title", &attlen);
244 str_attr = (
char *) calloc(attlen + 1,
sizeof (
char));
245 status = nc_get_att_text(ncid, NC_GLOBAL,
"title", str_attr);
247 fprintf(
stderr,
"-I- %s %d: nc_get_att_string error, file: %s\n",
248 __FILE__, __LINE__,
file);
252 if (strcmp(str_attr,
"OLCI Level 1b Product, Tie-Point Meteo Data Set")
266 status = nc_inq_attlen(ncid, NC_GLOBAL,
"title", &attlen);
269 str_attr = (
char *) calloc(attlen + 1,
sizeof (
char));
270 status = nc_get_att_text(ncid, NC_GLOBAL,
"title", str_attr);
272 fprintf(
stderr,
"-I- %s %d: nc_get_att_string error, file: %s\n",
273 __FILE__, __LINE__,
file);
276 if (strstr(str_attr,
"GMAO") != 0) {
329 if (strcmp(
files[0],
files[1]) == 0) f12_mtch = 1;
332 if (strcmp(
files[1],
files[2]) == 0) f23_mtch = 1;
334 if ((strcmp(
files[0],
files[2]) == 0) && (f12_mtch == 0)) {
335 printf(
"%s, %d E: ANC1 and 3 match while ANC2 different\n",
341 else if ((f12_mtch == 0) && (f23_mtch == 1))
351 }
else if (n_anc == 2) {
360 if (prioritize_files) {
397 static int32_t firstcall = 0;
398 static int32_t ntim_int;
399 static float r2d = 57.29577951;
400 static int32_t anc_id = -1;
401 static gen_int_str *met_int, *met_tim;
404 static char file_olci_str[FILENAME_MAX];
405 char *file_olci = (
char *) 0;
407 int32_t nlvl_int = 1;
408 int32_t ilvl = 0, nlvl = 1;
409 int32_t itim, ilon,
npix, iprm, t_interp, data_ix[2];
410 float val, wt_t1, uwnd, vwnd, unc, u_unc, v_unc, ws_2;
411 double l_time, anc_times[3],
lat,
lon, last_time;
414 if (firstcall == 0) {
421 char* ptr = strrchr(file_olci_str,
'/');
424 strcat(file_olci_str,
"/tie_meteo.nc");
426 strcpy(file_olci_str,
"tie_meteo.nc");
428 file_olci = file_olci_str;
442 if ((met_int = (gen_int_str *) malloc(n_met * nlvl_int * ntim_int *
443 sizeof (gen_int_str))) ==
NULL) {
445 "-E- %s %d: Unable to allocate met interpolation array\n",
459 for (itim = 0; itim < ntim_int; itim++) {
460 met_tim = met_int + itim * n_met;
464 if (last_time > met_tim[0].anc_time) {
466 "-E- %s %d: met file times are out of sequence\n",
470 last_time = met_tim[0].anc_time;
476 "-E- %s %d: Error reading ancillary file: %s\n",
477 __FILE__, __LINE__,
files[0]);
486 l_time =
l1rec->scantime;
490 for (iprm = 0; iprm < n_met; iprm++) {
492 for (itim = 0; itim < ntim_int; itim++)
493 anc_times[itim] = met_int[ iprm + n_met * itim ].anc_time;
497 data_ix, &wt_t1) != 0)
return 1;
500 for (ilon = 0; ilon <
npix; ilon++) {
504 if (lon < -180.0 || lon > 180.0 ||
505 lat <-90.0 || lat > 90.0 ||
506 isnan(
lat) || isnan(
lon)) {
510 data_ix, wt_t1, ntim_int, nlvl, n_met, &
val, &unc) != 0) {
512 "-E- %s %d: Error interpolating to file: %s\n",
513 __FILE__, __LINE__,
files[0]);
520 l1rec->zw_unc[ilon] = unc;
524 l1rec->mw_unc[ilon] = unc;
526 uwnd =
l1rec->zw[ilon];
527 vwnd =
l1rec->mw[ilon];
528 u_unc =
l1rec->zw_unc[ilon];
529 v_unc =
l1rec->mw_unc[ilon];
530 if (
input->windspeed != -2000)
l1rec->ws[ilon] =
531 sqrt(pow(uwnd, 2.) + pow(vwnd, 2.));
532 if (
input->windangle != -2000)
l1rec->wd[ilon] = atan2f(-uwnd, -vwnd)
537 ws_2 = uwnd * uwnd + vwnd * vwnd;
538 if ((uwnd + vwnd) > 0.05 * (u_unc + v_unc)) {
539 l1rec->ws_unc[ilon] = sqrt((uwnd * uwnd * u_unc * u_unc +
540 vwnd * vwnd * v_unc * v_unc) / ws_2);
541 l1rec->wd_unc[ilon] = sqrt(vwnd * vwnd * u_unc * u_unc +
542 uwnd * uwnd * v_unc * v_unc) / ws_2;
545 l1rec->ws_unc[ilon] = sqrt(0.5 * (u_unc * u_unc + v_unc * v_unc));
548 l1rec->wd_unc[ilon] *= r2d;
551 if (
input->pressure != -2000) {
552 if (proc_land && (
l1rec->height[ilon] != 0))
553 val *= exp(-
l1rec->height[ilon] / 8434.);
555 l1rec->pr_unc[ilon] = unc;
559 if (
input->watervapor != -2000)
561 l1rec->wv_unc[ilon] = unc / 10.;
564 if (
input->relhumid != -2000)
566 l1rec->rh_unc[ilon] = unc;
589 static int32_t firstcall = 0;
590 static int32_t ntim_int;
591 static gen_int_str *aer_int, *aer_tim;
595 int32_t itim, ilon,
npix, iprm, t_interp, data_ix[2];
596 int32_t ilvl = 0, nlvl = 1;
598 float val, wt_t1, unc;
599 double l_time, anc_times[3],
lat,
lon, last_time;
600 anc_aer_struc *anc_aerosol;
604 if (firstcall == 0) {
611 printf(
"\nOpening ancillary aerosol files.\n");
612 printf(
" anc_aerosol1 = %s\n",
input->anc_aerosol1);
613 printf(
" anc_aerosol2 = %s\n",
input->anc_aerosol2);
614 printf(
" anc_aerosol3 = %s\n",
input->anc_aerosol3);
626 "-E- %s %d: Ancillary met profile climatology not implemented yet\n",
632 if ((aer_int = (gen_int_str *) malloc(n_met * nlvl * ntim_int *
633 sizeof (gen_int_str))) ==
NULL) {
635 "-E- %s %d: Unable to allocate profile interpolation array\n",
642 for (itim = 0; itim < ntim_int; itim++) {
643 aer_tim = aer_int + itim * n_met;
647 if (last_time > aer_tim[0].anc_time) {
649 "-E- %s %d: met file times are out of sequence\n",
653 last_time = aer_tim[0].anc_time;
658 anc_aerosol =
l1rec->anc_aerosol;
659 if (anc_aerosol ==
NULL) {
667 l_time =
l1rec->scantime;
671 for (iprm = 0; iprm < n_met; iprm++) {
673 for (itim = 0; itim < ntim_int; itim++)
674 anc_times[itim] = aer_int[ iprm + n_met * itim ].anc_time;
678 data_ix, &wt_t1) != 0)
return 1;
681 for (ilon = 0; ilon <
npix; ilon++) {
685 if (lon < -180.0 || lon > 180.0 ||
686 lat <-90.0 || lat > 90.0 ||
687 isnan(
lat) || isnan(
lon)){
691 data_ix, wt_t1, ntim_int, nlvl, n_met, &
val, &unc) != 0) {
693 "-E- %s %d: Error interpolating to file: %s\n",
694 __FILE__, __LINE__,
files[0]);
700 l1rec->anc_aerosol->black_carbon_ext[ilon] =
val;
703 l1rec->anc_aerosol->black_carbon_scat[ilon] =
val;
706 l1rec->anc_aerosol->dust_ext[ilon] =
val;
709 l1rec->anc_aerosol->dust_scat[ilon] =
val;
712 l1rec->anc_aerosol->sea_salt_ext[ilon] =
val;
715 l1rec->anc_aerosol->sea_salt_scat[ilon] =
val;
718 l1rec->anc_aerosol->sulphur_ext[ilon] =
val;
721 l1rec->anc_aerosol->sulphur_scat[ilon] =
val;
724 l1rec->anc_aerosol->organic_carbon_ext[ilon] =
val;
727 l1rec->anc_aerosol->organic_carbon_scat[ilon] =
val;
730 l1rec->anc_aerosol->total_aerosol_ext[ilon] =
val;
733 l1rec->anc_aerosol->total_aerosol_scat[ilon] =
val;
763 static int32_t firstcall = 0;
764 static int32_t ntim_int;
765 static gen_int_str *prof_int, *prof_tim;
769 int32_t nlvl =
l1rec->l1file->nlvl;
771 int32_t itim, ilon, ilvl,
npix, iprm,
loc, t_interp, data_ix[2];
772 float val, wt_t1, unc;
773 double l_time, anc_times[3],
lat,
lon, last_time;
778 if (firstcall == 0) {
785 printf(
"\nOpening meteorological profile files.\n");
786 printf(
" anc_profile1 = %s\n",
input->anc_profile1);
787 printf(
" anc_profile2 = %s\n",
input->anc_profile2);
788 printf(
" anc_profile3 = %s\n",
input->anc_profile3);
800 "-E- %s %d: Ancillary met profile climatology not implemented yet\n",
807 if ((prof_int = (gen_int_str *) malloc(n_met * nlvl * ntim_int *
808 sizeof (gen_int_str))) ==
NULL) {
810 "-E- %s %d: Unable to allocate profile interpolation array\n",
818 for (itim = 0; itim < ntim_int; itim++) {
819 prof_tim = prof_int + n_met * nlvl * itim;
823 if (last_time > prof_tim[0].anc_time) {
825 "-E- %s %d: met file times are out of sequence\n",
829 last_time = prof_tim[0].anc_time;
834 anc_add =
l1rec->anc_add;
835 if (anc_add ==
NULL) {
844 l_time =
l1rec->scantime;
847 for (iprm = 0; iprm < n_met; iprm++) {
848 for (ilvl = 0; ilvl < nlvl; ilvl++) {
850 for (itim = 0; itim < ntim_int; itim++) {
851 loc = iprm + n_met * (ilvl + nlvl * itim);
852 anc_times[itim] = prof_int[
loc ].anc_time;
857 data_ix, &wt_t1) != 0)
return 1;
860 for (ilon = 0; ilon <
npix; ilon++) {
864 if (lon < -180.0 || lon > 180.0 ||
865 lat <-90.0 || lat > 90.0 ||
866 isnan(
lat) || isnan(
lon)){
870 data_ix, wt_t1, ntim_int, nlvl, n_met, &
val, &unc) != 0) {
872 "-E- %s %d: Error interpolating file: %s\n",
873 __FILE__, __LINE__,
files[0]);
877 loc = ilvl + nlvl * ilon;
904 if ((
l1rec->anc_aerosol =
905 (anc_aer_struc *) malloc(
sizeof ( anc_aer_struc))) ==
NULL) {
907 "-E- %s %d: Unable to allocate additional ancillary data storage 1\n",
911 if (((
l1rec->anc_aerosol->black_carbon_ext =
912 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
913 ((
l1rec->anc_aerosol->black_carbon_scat =
914 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
915 ((
l1rec->anc_aerosol->dust_ext =
916 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
917 ((
l1rec->anc_aerosol->dust_scat =
918 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
919 ((
l1rec->anc_aerosol->sea_salt_ext =
920 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
921 ((
l1rec->anc_aerosol->sea_salt_scat =
922 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
923 ((
l1rec->anc_aerosol->sulphur_ext =
924 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
925 ((
l1rec->anc_aerosol->sulphur_scat =
926 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
927 ((
l1rec->anc_aerosol->organic_carbon_ext =
928 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
929 ((
l1rec->anc_aerosol->organic_carbon_scat =
930 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
931 ((
l1rec->anc_aerosol->total_aerosol_ext =
932 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL) ||
933 ((
l1rec->anc_aerosol->total_aerosol_scat =
934 (
float *) malloc(
l1rec->npix * sizeof (
float))) ==
NULL)) {
936 "-E- %s %d: Unable to allocate additional ancillary data storage 2\n",
963 int32_t
npix, nlvl = 42;
967 if ((
l1rec->anc_add =
968 (anc_struc *) malloc(
sizeof ( anc_struc))) ==
NULL) {
970 "-E- %s %d: Unable to allocate additional ancillary data storage 1\n",
974 if (((
l1rec->anc_add->prof_temp =
975 (
float *) malloc(nlvl *
npix *
sizeof (
float))) ==
NULL) ||
976 ((
l1rec->anc_add->prof_rh =
977 (
float *) malloc(nlvl *
npix *
sizeof (
float))) ==
NULL) ||
978 ((
l1rec->anc_add->prof_height =
979 (
float *) malloc(nlvl *
npix *
sizeof (
float))) ==
NULL) ||
980 ((
l1rec->anc_add->prof_q =
981 (
float *) malloc(nlvl *
npix *
sizeof (
float))) ==
NULL) ||
982 ((
l1rec->anc_add->prof_o3 =
983 (
float *) malloc(nlvl *
npix *
sizeof (
float))) ==
NULL)) {
985 "-E- %s %d: Unable to allocate additional ancillary data storage 2\n",
1013 static int32_t firstcall = 0;
1014 static int32_t ntim_int;
1015 static int32_t anc_id = -1;
1016 static gen_int_str *oz_int, *oz_tim;
1019 static char file_olci_str[FILENAME_MAX];
1020 char *file_olci = (
char *) 0;
1022 int32_t nlvl_int = 1;
1023 int32_t ilvl = 0, nlvl = 1;
1024 int32_t itim, ilon,
npix, iprm, t_interp, data_ix[2];
1025 float val, wt_t1, unc;
1026 double l_time, anc_times[3],
lat,
lon, last_time;
1029 if (firstcall == 0) {
1036 char* ptr = strrchr(file_olci_str,
'/');
1039 strcat(file_olci_str,
"/tie_meteo.nc");
1041 strcpy(file_olci_str,
"tie_meteo.nc");
1043 file_olci = file_olci_str;
1057 if ((oz_int = (gen_int_str *) malloc(n_oz * nlvl_int * ntim_int *
1058 sizeof (gen_int_str))) ==
NULL) {
1060 "-E- %s %d: Unable to allocate met interpolation array\n",
1061 __FILE__, __LINE__);
1074 for (itim = 0; itim < ntim_int; itim++) {
1075 oz_tim = oz_int + itim * n_oz;
1079 if (last_time > oz_tim[0].anc_time) {
1081 "-E- %s %d: ozone file times are out of sequence\n",
1082 __FILE__, __LINE__);
1085 last_time = oz_tim[0].anc_time;
1091 "-E- %s %d: Error reading file: %s\n",
1092 __FILE__, __LINE__,
files[0]);
1101 l_time =
l1rec->scantime;
1105 for (iprm = 0; iprm < n_oz; iprm++) {
1107 for (itim = 0; itim < ntim_int; itim++)
1108 anc_times[itim] = oz_int[ iprm + n_oz * itim ].anc_time;
1112 data_ix, &wt_t1) != 0)
return 1;
1115 if (
input->ozone != -2000) {
1116 for (ilon = 0; ilon <
npix; ilon++) {
1120 if (lon < -180.0 || lon > 180.0 ||
1121 lat <-90.0 || lat > 90.0 ||
1122 isnan(
lat) || isnan(
lon)){
1126 data_ix, wt_t1, ntim_int, nlvl, n_oz, &
val, &unc) != 0) {
1128 "-E- %s %d: Error interpolating file: %s\n",
1129 __FILE__, __LINE__,
files[0]);
1135 l1rec->oz_unc[ilon] = unc / 1000.;
1170 char *ob_gmao_grp[] = {
"met",
"met",
"met",
"met",
"met",
"met",
"met",
"met",
"ocn_ice"};
1171 char *ob_gmao_prm_nm[] = {
"U10M",
"V10M",
"SLP",
"TQV",
"PS",
"PS",
"PS",
"T10M",
"FRSEAICE"};
1174 int32_t n_raw_gmao = 9;
1175 int32_t iprm,
nlat,
nlon, nlvl, iv, nv;
1176 float *data2, *data3, *data_rh, p_lcl;
1177 unsigned char *
qual, *qual2;
1178 double time, *lat_coord, *lon_coord, *
ddata;
1179 double *lat_coord2, *lon_coord2;
1180 static float *
data = 0;
1199 for (iprm = 0; iprm < n_raw_gmao; iprm++) {
1207 if ((
ddata = (
double *) malloc(nv *
sizeof (
double))) ==
NULL) {
1208 fprintf(
stderr,
"-E- %s %d: Unable to allocate array ddata\n",
1209 __FILE__, __LINE__);
1220 for (iv = 0; iv < nv; iv++) {
1221 if (*(
qual + iv) == 0) {
1222 p_lcl = *(
data + iv);
1224 *(
data + iv) = p_lcl;
1230 &
nlon, &
nlat, &nlvl, &lon_coord2, &lat_coord2) != 0)
1234 for (iv = 0; iv < nv; iv++)
1235 *(
qual + iv) = *(
qual + iv) | *(qual2 + iv);
1239 &
nlon, &
nlat, &nlvl, &lon_coord2, &lat_coord2) != 0)
1243 for (iv = 0; iv < nv; iv++)
1244 *(
qual + iv) = *(
qual + iv) | *(qual2 + iv);
1247 if ((data_rh = (
float *) malloc(
nlon *
nlat *
sizeof (
float)))
1249 fprintf(
stderr,
"-E- %s, %d: malloc failure\n", __FILE__, __LINE__);
1257 for (iv = 0; iv < nv; iv++)
1258 *(
data + iv) = *(data_rh + iv);
1262 for (iv = 0; iv < nv; iv++) {
1263 if (*(
qual + iv) == 0) {
1264 p_lcl = *(
data + iv);
1266 *(
data + iv) = p_lcl;
1272 &
nlon, &
nlat, &nlvl, &lon_coord2, &lat_coord2) != 0)
1276 for (iv = 0; iv < nv; iv++)
1277 *(
qual + iv) = *(
qual + iv) | *(qual2 + iv);
1281 &
nlon, &
nlat, &nlvl, &lon_coord2, &lat_coord2) != 0)
1285 for (iv = 0; iv < nv; iv++)
1286 *(
qual + iv) = *(
qual + iv) | *(qual2 + iv);
1289 if ((data_rh = (
float *) malloc(
nlon *
nlat *
sizeof (
float)))
1291 fprintf(
stderr,
"-E- %s, %d: malloc failure\n", __FILE__, __LINE__);
1299 for (iv = 0; iv < nv; iv++)
1300 *(
data + iv) = *(data_rh + iv);
1304 for (iv = 0; iv < nv; iv++) {
1305 if (*(
qual + iv) == 0) {
1306 p_lcl = *(
data + iv);
1308 *(
data + iv) = p_lcl;
1316 &
time, &
nlon, &
nlat, &nlvl, &lon_coord2, &lat_coord2) != 0)
1320 for (iv = 0; iv < nv; iv++)
1321 *(
qual + iv) = *(
qual + iv) | *(qual2 + iv);
1324 for (iv = 0; iv < nv; iv++) {
1325 if (*(qual2 + iv) == 0)
1326 *(
data + iv) = *(data2 + iv);
1332 fprintf(
stderr,
"-E- %s %d: Unknown output identifier: %d\n",
1333 __FILE__, __LINE__, iprm);
1339 met_int[iprm].accel_lat = gsl_interp_accel_alloc();
1340 met_int[iprm].accel_lon = gsl_interp_accel_alloc();
1341 met_int[iprm].int_id = gsl_spline2d_alloc(gsl_interp2d_bilinear,
nlon,
nlat);
1342 met_int[iprm].lat_coord = lat_coord;
1343 met_int[iprm].lon_coord = lon_coord;
1345 for (iv = 0; iv < nv; iv++)
1347 if (gsl_spline2d_init(met_int[iprm].int_id, met_int[iprm].lon_coord,
1349 fprintf(
stderr,
"-E- %s %d: GSL 2-D initialization failed, file: %s\n",
1350 __FILE__, __LINE__,
file);
1357 met_int[iprm].anc_time =
time;
1358 met_int[iprm].qual =
qual;
1359 met_int[iprm].nlat =
nlat;
1360 met_int[iprm].nlon =
nlon;
1368 int32_t nlvl_expect)
1395 char *ob_gmao_prm_nm[] = {
"T",
"RH",
"H",
"QV",
"O3"};
1396 int32_t n_raw_gmao = 5;
1397 int32_t iprm,
nlat,
nlon, nlvl, ilvl,
loc, iv, nv, ntot;
1399 unsigned char *
qual;
1400 double time, *lat_coord, *lon_coord, *
ddata;
1401 static float *
data = 0;
1413 for (iprm = 0; iprm < n_raw_gmao; iprm++) {
1416 &
time, &
nlon, &
nlat, &nlvl, &lon_coord, &lat_coord) != 0)
1420 if (nlvl != nlvl_expect) {
1422 "-E- %s %d: unexpected # profile levels: %d were read from file: %s\n",
1423 __FILE__, __LINE__, nlvl,
file);
1427 if (iprm ==
TPROF) {
1429 for (iv = 0; iv < ntot; iv++) {
1430 if (*(
qual + iv) == 0) {
1431 p_lcl = *(
data + iv);
1433 *(
data + iv) = p_lcl;
1437 else if (iprm ==
RHPROF) {
1439 for (iv = 0; iv < ntot; iv++) {
1440 if (*(
qual + iv) == 0) {
1441 *(
data + iv) *= 100.;
1447 if ((
ddata = (
double *) malloc(nv *
sizeof (
double))) ==
NULL) {
1448 fprintf(
stderr,
"-E- %s %d: Unable to allocate array ddata\n",
1449 __FILE__, __LINE__);
1452 for (ilvl = 0; ilvl < nlvl; ilvl++) {
1453 loc = iprm + n_raw_gmao * ilvl;
1458 prof_int[
loc].accel_lat = gsl_interp_accel_alloc();
1459 prof_int[
loc].accel_lon = gsl_interp_accel_alloc();
1460 prof_int[
loc].int_id = gsl_spline2d_alloc(gsl_interp2d_bilinear,
1462 prof_int[
loc].lat_coord = lat_coord;
1463 prof_int[
loc].lon_coord = lon_coord;
1465 for (iv = 0; iv < nv; iv++)
1467 if (gsl_spline2d_init(prof_int[
loc].int_id, prof_int[
loc].lon_coord,
1469 fprintf(
stderr,
"-E- %s %d: GSL 2-D initialization failed, file: %s\n",
1470 __FILE__, __LINE__,
file);
1473 prof_int[
loc].anc_time =
time;
1474 prof_int[
loc].qual =
qual + nv * ilvl;
1514 unsigned char *
qual;
1515 double time, *lat_coord, *lon_coord, *
ddata;
1516 static float *
data = 0;
1520 &
nlat, &nlvl, &lon_coord, &lat_coord) != 0)
1524 if ((
ddata = (
double *) malloc(nv *
sizeof (
double))) ==
NULL) {
1525 fprintf(
stderr,
"-E- %s %d: Unable to allocate array ddata\n",
1526 __FILE__, __LINE__);
1533 oz_int[iprm].accel_lat = gsl_interp_accel_alloc();
1534 oz_int[iprm].accel_lon = gsl_interp_accel_alloc();
1535 oz_int[iprm].int_id = gsl_spline2d_alloc(gsl_interp2d_bilinear,
nlon,
nlat);
1536 oz_int[iprm].lat_coord = lat_coord;
1537 oz_int[iprm].lon_coord = lon_coord;
1539 for (iv = 0; iv < nv; iv++)
1541 if (gsl_spline2d_init(oz_int[iprm].int_id, oz_int[iprm].lon_coord,
1543 fprintf(
stderr,
"-E- %s %d: GSL 2-D initialization failed, file: %s\n",
1544 __FILE__, __LINE__,
file);
1550 oz_int[iprm].anc_time =
time;
1551 oz_int[iprm].qual =
qual;
1552 oz_int[iprm].nlat =
nlat;
1553 oz_int[iprm].nlon =
nlon;
1564 unsigned char *
qual;
1565 double time, *lat_coord, *lon_coord, *
ddata;
1566 static float *
data = 0;
1569 char *ob_gmao_prm_nm[] = {
"BCEXTTAU",
"BCSCATAU",
"DUEXTTAU",
"DUSCATAU",
1570 "SSEXTTAU",
"SSSCATAU",
"SUEXTTAU",
"SUSCATAU",
"OCEXTTAU",
"OCSCATAU",
1571 "TOTEXTTAU",
"TOTSCATAU"};
1573 int32_t n_raw_gmao = 12;
1575 for (iprm = 0; iprm < n_raw_gmao; iprm++) {
1577 &
time, &
nlon, &
nlat, &nlvl, &lon_coord, &lat_coord) != 0)
1581 if ((
ddata = (
double *) malloc(nv *
sizeof (
double))) ==
NULL) {
1582 fprintf(
stderr,
"-E- %s %d: Unable to allocate array ddata\n",
1583 __FILE__, __LINE__);
1590 aer_int[iprm].accel_lat = gsl_interp_accel_alloc();
1591 aer_int[iprm].accel_lon = gsl_interp_accel_alloc();
1592 aer_int[iprm].int_id = gsl_spline2d_alloc(gsl_interp2d_bilinear,
nlon,
nlat);
1593 aer_int[iprm].lat_coord = lat_coord;
1594 aer_int[iprm].lon_coord = lon_coord;
1596 for (iv = 0; iv < nv; iv++)
1598 if (gsl_spline2d_init(aer_int[iprm].int_id, aer_int[iprm].lon_coord,
1600 fprintf(
stderr,
"-E- %s %d: GSL 2-D initialization failed, file: %s\n",
1601 __FILE__, __LINE__,
file);
1607 aer_int[iprm].anc_time =
time;
1608 aer_int[iprm].qual =
qual;
1609 aer_int[iprm].nlat =
nlat;
1610 aer_int[iprm].nlon =
nlon;
1618 int32_t
anc_acq_eval_pt(gen_int_str *met_int, int32_t iprm, int32_t ilvl,
1619 float lat,
float lon, int32_t t_interp, int32_t *data_ix,
float wt_t1,
1620 int32_t ntim_int, int32_t nlvl, int32_t nprm,
float *final_val,
float *unc)
1662 gsl_interp_accel *accel_lat, *accel_lon;
1663 int32_t met_ptr, tim_ix, itim, ntim;
1669 ntim = t_interp + 1;
1671 for (itim = 0; itim < ntim; itim++) {
1672 tim_ix = data_ix[itim];
1673 met_ptr = iprm + nprm * (ilvl + nlvl * tim_ix);
1674 accel_lon = met_int[met_ptr].accel_lon;
1675 accel_lat = met_int[met_ptr].accel_lat;
1676 nlat = met_int[met_ptr].nlat;
1677 nlon = met_int[met_ptr].nlon;
1679 if (gsl_spline2d_eval_e(met_int[met_ptr].int_id,
lon,
lat, accel_lon,
1680 accel_lat, &
val) != 0) {
1681 fprintf(
stderr,
"-E- %s %d: gsl_spline2d_eval_e error: %d, %d, %d\n",
1682 __FILE__, __LINE__, itim, iprm, ilvl);
1686 ilat = gsl_interp_accel_find(accel_lat,
1687 met_int[met_ptr].lat_coord,
nlat,
lat);
1688 ilon = gsl_interp_accel_find(accel_lon,
1689 met_int[met_ptr].lon_coord,
nlon,
lon);
1691 if ((met_int[met_ptr].
qual[ilon +
nlon * ilat ] == 1) ||
1692 (met_int[met_ptr].
qual[ilon + 1 +
nlon * ilat ] == 1) ||
1693 (met_int[met_ptr].
qual[ilon +
nlon * (ilat + 1) ] == 1) ||
1694 (met_int[met_ptr].
qual[ilon + 1 +
nlon * (ilat + 1) ] == 1))
1704 *unc = fabsf(*final_val - (
float)
val);
1705 *final_val = *final_val * wt_t1 +
val * wt_t2;
1716 int32_t
anc_f_stat, int32_t *t_interp, int32_t *data_ix,
float *wt)
1753 int32_t data1_ix=0, data2_ix=0;
1762 if (s_time < anc_time[0]) {
1767 }
else if (s_time > anc_time[1]) {
1776 *wt = (anc_time[1] - s_time) / (anc_time[1] - anc_time[0]);
1779 if (s_time < anc_time[0]) {
1783 }
else if (s_time > anc_time[2]) {
1793 *wt = (anc_time[2] - s_time) / (anc_time[2] - anc_time[0]);
1796 if (s_time < anc_time[0]) {
1800 }
else if (s_time > anc_time[2]) {
1804 }
else if (s_time < anc_time[1]) {
1809 *wt = (anc_time[1] - s_time) / (anc_time[1] - anc_time[0]);
1815 *wt = (anc_time[2] - s_time) / (anc_time[2] - anc_time[1]);
1820 printf(
"%s, %d: Undefined anc_f_stat - should not happen\n",
1821 __FILE__, __LINE__);
1824 *data_ix = data1_ix;
1825 *(data_ix + 1) = data2_ix;
1831 float **
data,
unsigned char **qa,
double *
time, int32_t *
nlon, int32_t *
nlat,
1832 int32_t *nlvl,
double **lon_coord,
double **lat_coord)
1867 static char lcl_fil[FILENAME_MAX] =
"";
1869 int var_id, var2_id, var3_id, dim_id;
1871 int32_t nv, ilvl, nlon_pre, il, ip;
1873 float *data_tmp, fillv, missv;
1876 if (strcmp(
file, lcl_fil) != 0) {
1877 if (lcl_fil[0] != 0) {
1878 if (nc_close(ncid) != NC_NOERR) {
1879 fprintf(
stderr,
"-E- %s %d: nc_close error, file: %s\n",
1880 __FILE__, __LINE__,
file);
1884 if (nc_open(
file, 0, &ncid) != NC_NOERR) {
1886 "-E- %s %d: file: %s is not netcdf, not acceptable GMAO file\n",
1887 __FILE__, __LINE__,
file);
1896 "-E- %s %d: file: %s error reading lat, lon dimension size\n",
1897 __FILE__, __LINE__,
file);
1901 if (nc_inq_dimid(ncid,
"lev", &dim_id) != NC_NOERR) {
1904 if (nc_inq_dimlen(ncid, dim_id, &tlvl) != NC_NOERR) {
1906 "-E- %s %d: file: %s error reading level dimension size\n",
1907 __FILE__, __LINE__,
file);
1912 *
nlon = nlon_pre + 1;
1917 memset( isodate,
'\0', 32 );
1918 nc_get_att_text(ncid, NC_GLOBAL,
"time_coverage_start", isodate);
1922 if (((*
data = (
float *) malloc(nv *
sizeof (
float))) ==
NULL) ||
1923 ((*lon_coord = (
double *) malloc(*
nlon *
sizeof (
double))) ==
NULL) ||
1924 ((*lat_coord = (
double *) malloc(*
nlat *
sizeof (
double))) ==
NULL) ||
1925 ((*qa = (
unsigned char *) calloc(nv,
sizeof (
char))) ==
NULL) ||
1926 ((data_tmp = (
float *) malloc(nlon_pre * *
nlat * *nlvl *
sizeof (
float))) ==
NULL)) {
1928 "-E- %s %d: file: %s error allocating gmao parameter allocation\n",
1929 __FILE__, __LINE__,
file);
1934 if ((nc_inq_varid(ncid, ds_name, &var_id) != NC_NOERR) ||
1935 (nc_inq_varid(ncid,
"lat", &var2_id) != NC_NOERR) ||
1936 (nc_inq_varid(ncid,
"lon", &var3_id) != NC_NOERR)) {
1938 "-E- %s %d: file: %s error setting an id for product: %s\n",
1939 __FILE__, __LINE__,
file, ds_name);
1943 if (((nc_get_var_double(ncid, var2_id, *lat_coord)) != NC_NOERR) ||
1944 ((nc_get_var_double(ncid, var3_id, *lon_coord)) != NC_NOERR)) {
1946 "-E- %s %d: file: %s error reading the scales and parameter\n",
1947 __FILE__, __LINE__,
file);
1953 if ((nc_get_att_float(ncid, var_id,
"_FillValue", &fillv) != NC_NOERR) ||
1954 (nc_get_att_float(ncid, var_id,
"missing_value", &missv) != NC_NOERR)) {
1955 printf(
"%s, %d: nc_get_att_float error for parm %s\n",
1956 __FILE__, __LINE__, ds_name);
1962 if (nc_get_var_float(ncid, var_id, data_tmp) != NC_NOERR) {
1963 printf(
"%s, %d: nc_get_var_float error for parm %s\n",
1964 __FILE__, __LINE__, ds_name);
1967 for (ilvl = 0; ilvl < *nlvl; ilvl++) {
1968 for (il = 0; il < *
nlat; il++) {
1969 for (ip = 0; ip < *
nlon; ip++) {
1971 if (ip < nlon_pre) {
1973 *(data_tmp + ip + nlon_pre * (il + *
nlat * ilvl));
1975 *(*
data +
loc) = *(data_tmp + nlon_pre * (il + *
nlat * ilvl));
1977 if ((*(*
data +
loc) == missv) ||
1987 (*lon_coord)[nlon_pre] = 180.;
2059 int ids, iprm,
npix,
nlin, ilin, ipix;
2060 int t_days, t_hrs, lon_gt_180, ird;
2061 int dstpix, npix0, nlin0,
status;
2062 int npix_ext, nlin_ext, ntim, f12_mtch, f23_mtch,
anc_f_stat;
2063 int ncid, iprm_sto, nprm_sto;
2067 float *base_data, *
lat, *
lon, *comp1, *comp2;
2071 nprm_sto = (n_prm > 1) ? n_prm - 1 : n_prm;
2092 for (ids = 0; ids < 3; ids++) {
2098 if ((ids == 1) && (f12_mtch == 1))
continue;
2099 if ((ids == 2) && (f23_mtch == 1))
break;
2101 if(Hishdf(
files[ids]))
2106 if (
status != NC_NOERR) {
2115 printf(
"%s, %d: nc_open failed on file: %s\n", __FILE__, __LINE__,
2117 printf(
" Mismatch or bad ECMWF file\n");
2125 if (((npix0 =
ncio_dim_siz(ncid,
"longitude")) == -1) ||
2129 "%s, %d: ncio_dim_siz error reading longitude, latitude or time datasets\n",
2130 __FILE__, __LINE__);
2137 if ((
npix != npix0) || (
nlin != nlin0)) {
2138 printf(
"%s, %d: mismatch in size of MET array[%d]\n", __FILE__,
2147 printf(
"%s, %d: Number of times > 1, can't deal with at this time\n",
2148 __FILE__, __LINE__);
2151 npix_ext =
npix + 2;
2152 nlin_ext =
nlin + 2;
2156 for (iprm = 0; iprm < nprm_sto; iprm++) {
2157 if ((met_sto[iprm + sto_ix].
data[ids] = (
float *)
2158 malloc(npix_ext * nlin_ext *
sizeof (
float))) ==
NULL) {
2159 printf(
"%s, %d: malloc failed for data[%d] in met_sto %d\n", __FILE__,
2160 __LINE__, ids, iprm);
2169 if (((base_data = (
float *)
2175 printf(
"%s, %d: malloc failed for base_data or comp arrays\n",
2176 __FILE__, __LINE__);
2180 if ((
lat = (
float *) malloc(
nlin *
sizeof (
float))) ==
NULL) {
2181 printf(
"%s, %d: malloc failed for latitude\n", __FILE__,
2185 if ((
lon = (
float *) malloc(
npix *
sizeof (
float))) ==
NULL) {
2186 printf(
"%s, %d: malloc failed for longitude\n", __FILE__,
2191 printf(
"%s, %d: ncio_grab_f_ds failed on latitude\n",
2192 __FILE__, __LINE__);
2196 printf(
"%s, %d: ncio_grab_f_ds failed on longitude\n",
2197 __FILE__, __LINE__);
2209 for (ipix = 0; ipix <
npix; ipix++) {
2210 if (
lon[ipix] > 180.) {
2223 printf(
"%s, %d: error reading the time in\n", __FILE__, __LINE__);
2236 for (iprm = 0; iprm < nprm_sto; iprm++) {
2237 iprm_sto = iprm + sto_ix;
2240 prm_bad[ird], base_data) != 0) {
2241 printf(
"%s, %d: ncio_grab_stdsclf_ds failed on %s\n",
2242 __FILE__, __LINE__, prm_nm[ird]);
2248 prm_bad[ird + sto_ix], comp1) != 0) ||
2250 prm_bad[ird + sto_ix + 1], comp2) != 0)) {
2251 printf(
"%s, %d: ncio_grab_stdsclf_ds failed on %s or %s\n",
2252 __FILE__, __LINE__, prm_nm[ird], prm_nm[ird + 1]);
2261 printf(
"met_cvt_ttd_to_rh had an error\n");
2262 printf(
"%s, %d: met_cvt_ttd_to_rh failure\n",
2263 __FILE__, __LINE__);
2268 for (ilin = 0; ilin <
nlin; ilin++) {
2269 for (ipix = 0; ipix <
npix; ipix++) {
2270 dstpix = ipix - lon_gt_180;
2271 if (dstpix < 0) dstpix +=
npix;
2272 *(met_sto[ iprm_sto ].data[ids]
2273 + dstpix + 1 + (ilin + 1) * npix_ext) =
2274 *(base_data + ipix +
npix * ilin);
2279 for (ipix = 0; ipix <
npix; ipix++) {
2280 *(met_sto[iprm_sto].data[ids] + ipix + 1) =
2281 *(met_sto[iprm_sto].
data[ids] + ipix + 1 + npix_ext);
2282 *(met_sto[iprm_sto].data[ids] + ipix + 1 + (
nlin + 1) * npix_ext) =
2283 *(met_sto[iprm_sto].data[ids] + ipix + 1 +
nlin * npix_ext);
2286 for (ilin = 0; ilin < nlin_ext; ilin++) {
2287 *(met_sto[iprm_sto].data[ids] + ilin * npix_ext) =
2288 *(met_sto[iprm_sto].
data[ids] +
npix + ilin * npix_ext);
2289 *(met_sto[iprm_sto].data[ids] +
npix + 1 + ilin * npix_ext) =
2290 *(met_sto[iprm_sto].
data[ids] + 1 + ilin * npix_ext);
2293 met_sto[iprm_sto].s_lon =
s_lon;
2294 met_sto[iprm_sto].lon_step =
lon_step;
2295 met_sto[iprm_sto].nlon =
npix;
2296 met_sto[iprm_sto].e_lon =
e_lon;
2297 met_sto[iprm_sto].s_lat =
s_lat;
2298 met_sto[iprm_sto].lat_step =
lat_step;
2299 met_sto[iprm_sto].nlat =
nlin;
2300 met_sto[iprm_sto].e_lat =
e_lat;
2301 met_sto[iprm_sto].data_time[ids] =
data_time;
2337 float data_val, uwnd, vwnd, data_val1, data_val2, dx, dy, lon_frac, lat_frac;
2338 float trg_lon, trg_lat, wt_t1, wt_t2,
s_lon,
s_lat;
2340 int iprm, xbox_st, ybox_st, nx, ny, t_interp, data1_ix, data2_ix,
anc_f_stat;
2341 int npix, ipix, sto_st, sto_en;
2342 static float r2d = 57.29577951;
2346 if (anc_class == 0) {
2360 l_time += sec / 86400.0;
2379 if (l_time < met_sto[sto_st].
data_time[0]) {
2380 printf(
"%s, %d: data time is before the ancillary data start time\n",
2381 __FILE__, __LINE__);
2383 }
else if (l_time > met_sto[sto_st].
data_time[1]) {
2392 wt_t1 = (met_sto[sto_st].data_time[1] - l_time) /
2394 wt_t2 = (l_time - met_sto[sto_st].data_time[0]) /
2398 if (l_time < met_sto[sto_st].
data_time[0]) {
2402 }
else if (l_time > met_sto[sto_st].
data_time[2]) {
2404 printf(
"%s, %d: data time is after the ancillary data end time\n",
2405 __FILE__, __LINE__);
2412 wt_t1 = (met_sto[sto_st].data_time[2] - l_time) /
2414 wt_t2 = (l_time - met_sto[sto_st].data_time[0]) /
2418 if (l_time < met_sto[sto_st].
data_time[0]) {
2419 printf(
"%s, %d: data time is before the ancillary data start time\n",
2420 __FILE__, __LINE__);
2422 }
else if (l_time > met_sto[sto_st].
data_time[2]) {
2423 printf(
"%s, %d: data time is after the ancillary data end time\n",
2424 __FILE__, __LINE__);
2426 }
else if (l_time < met_sto[sto_st].
data_time[1]) {
2431 wt_t1 = (met_sto[sto_st].data_time[1] - l_time) /
2433 wt_t2 = (l_time - met_sto[sto_st].data_time[0]) /
2440 wt_t1 = (met_sto[sto_st].data_time[2] - l_time) /
2442 wt_t2 = (l_time - met_sto[sto_st].data_time[1]) /
2448 printf(
"%s, %d: Undefined anc_f_stat - should not happen\n",
2449 __FILE__, __LINE__);
2460 dx = met_sto[sto_st].lon_step;
2461 dy = met_sto[sto_st].lat_step;
2462 s_lon = met_sto[sto_st].s_lon;
2463 s_lat = met_sto[sto_st].s_lat;
2464 nx = met_sto[sto_st].nlon;
2465 ny = met_sto[sto_st].nlat;
2466 for (ipix = 0; ipix <
npix; ipix++) {
2467 trg_lat =
l1rec->lat[ipix];
2468 trg_lon =
l1rec->lon[ipix];
2480 xbox_st =
MAX(
MIN((
int) ((trg_lon -
s_lon + dx) / dx), nx + 1), 0);
2481 ybox_st =
MAX(
MIN((
int) ((trg_lat -
s_lat + dy) / dy), ny + 1), 0);
2483 lon_frac = (trg_lon -
s_lon) / dx - (
float) (xbox_st - 1);
2484 lat_frac = (trg_lat -
s_lat) / dy - (
float) (ybox_st - 1);
2486 for (iprm = sto_st; iprm < (sto_en + 1); iprm++) {
2487 data = met_sto[iprm].data[data1_ix];
2491 if (t_interp == 1) {
2492 data = met_sto[iprm].data[data2_ix];
2499 if (data_val1 <
ANCBAD + 1) {
2500 if (data_val2 <
ANCBAD + 1)
2503 data_val = data_val2;
2505 data_val = wt_t1 * data_val1 + wt_t2 * data_val2;
2507 data_val = data_val1;
2520 if (
input->pressure != -2000) {
2521 data_val = (data_val <
ANCBAD + 1) ?
ANCBAD : data_val / 100.;
2522 if (data_val < 0)
l1rec->pr[ipix] = 1013.25;
2523 else if (data_val < 250.)
l1rec->pr[ipix] = 250.;
2524 else if (data_val > 1100.)
l1rec->pr[ipix] = 1100.;
2525 else l1rec->pr[ipix] = data_val;
2531 if (
input->watervapor != -2000)
2532 l1rec->wv[ipix] = (data_val <
ANCBAD + 1) ? 0. : data_val / 10.;
2539 if (
input->pressure != -2000) {
2540 data_val = (data_val <
ANCBAD + 1) ?
ANCBAD : data_val / 100.;
2541 if (data_val < 0)
l1rec->pr[ipix] = 1013.25;
2542 else if (data_val < 900.)
l1rec->pr[ipix] = 900.;
2543 else if (data_val > 1100.)
l1rec->pr[ipix] = 1100.;
2544 else l1rec->pr[ipix] = data_val;
2548 if (proc_land &&
l1rec->height[ipix] != 0.0)
2549 l1rec->pr[ipix] *= exp(-
l1rec->height[ipix] / 8434);
2553 uwnd = (data_val <
ANCBAD + 1) ? 0. : data_val;
2554 l1rec->zw[ipix] = uwnd;
2557 vwnd = (data_val <
ANCBAD + 1) ? 0. : data_val;
2558 l1rec->mw[ipix] = vwnd;
2559 if (
input->windspeed != -2000)
2560 l1rec->ws[ipix] = sqrt(pow(uwnd, 2.) + pow(vwnd, 2.));
2561 if (
input->windangle != -2000)
2562 l1rec->wd[ipix] = atan2f(-uwnd, vwnd) * r2d;
2565 if (
input->relhumid != -2000)
2566 l1rec->rh[ipix] = (data_val <
ANCBAD + 1) ? 0. : data_val;
2569 if (
input->ozone != -2000) {
2606 static int ncid[2], varid[5];
2616 static int32_t firstcalls[2] = {1, 1}, pix_smp[2];
2617 static int32_t
npix, *
qual, *qual_met, *qual_oz;
2619 static size_t tie_nlin[2], tie_npix[2];
2620 static float *tie_data, *tie_met, *tie_oz;
2621 static float r2d = 57.29577951;
2622 int32_t anc_field_per_parm[5] = {1, 2, 1, 1, 1};
2623 int32_t anc_class_n_ds[2] = {4, 1}, class_off, n_ds_prm, ptr_prm;
2624 int32_t n_field_per_parm, ifld, ipx, px_tie1, px_tie2;
2625 int nid, lin_smp, ids, stat, ipx_dat;
2627 char *anc_prm_nm[] = {
"humidity",
"horizontal_wind",
"sea_level_pressure",
2628 "total_columnar_water_vapour",
"total_ozone"};
2629 float *ar, fr_dist, w1, w2;
2640 n_ds_prm = anc_class_n_ds[anc_class];
2642 if (firstcalls[anc_class]) {
2650 if (nc_open(
file, NC_NOWRITE, (ncid + anc_class)) != NC_NOERR) {
2652 "-E- %s %d: Unable to open OLCI tie point anc file: %s\n",
2653 __FILE__, __LINE__,
file);
2656 if (nc_get_att_int(ncid[anc_class], NC_GLOBAL,
"ac_subsampling_factor",
2657 &pix_smp[anc_class]) != NC_NOERR) {
2659 "-E- %s %d: Unable to read column sampling attrib from OLCI tie point anc file: %s\n",
2660 __FILE__, __LINE__,
file);
2663 if (nc_get_att_int(ncid[anc_class], NC_GLOBAL,
"al_subsampling_factor",
2664 &lin_smp) != NC_NOERR) {
2666 "-E- %s %d: Unable to read row sampling attrib from OLCI tie point anc file: %s\n",
2667 __FILE__, __LINE__,
file);
2673 if (nc_inq_dimid(ncid[anc_class],
"tie_columns", &nid) != NC_NOERR) {
2675 "-E- %s %d: Unable to get OLCI tie point meteo # pixels\n",
2676 __FILE__, __LINE__);
2679 if (nc_inq_dimlen(ncid[anc_class], nid, &tie_npix[anc_class])
2682 "-E- %s %d: Unable to get OLCI tie point meteo # pixels\n",
2683 __FILE__, __LINE__);
2687 if (nc_inq_dimid(ncid[anc_class],
"tie_rows", &nid) != NC_NOERR) {
2689 "-E- %s %d: Unable to get OLCI tie point meteo # lines\n",
2690 __FILE__, __LINE__);
2693 if (nc_inq_dimlen(ncid[anc_class], nid, &tie_nlin[anc_class]) != NC_NOERR) {
2695 "-E- %s %d: Unable to get OLCI tie point meteo # lines\n",
2696 __FILE__, __LINE__);
2704 "-E- %s %d: OLCI and tie point line sampling: %d, not = 1\n",
2705 __FILE__, __LINE__, lin_smp);
2708 tie_epix = pix_smp[anc_class] * (tie_npix[anc_class] - 1) + 1;
2709 if (tie_epix <
epix) {
2711 "-E- %s %d: tie point range out to pixel %d is < data range of %d\n",
2712 __FILE__, __LINE__, tie_epix,
epix);
2714 "tie point sampling: %d and # pixels: %d\n",
2715 pix_smp[anc_class], (
int) tie_npix[anc_class]);
2731 if ((tie_data = (
float *) malloc(tie_npix[anc_class] *
sizeof (
float)))
2734 "-E- %s %d: Unable to allocate tie point data array\n",
2735 __FILE__, __LINE__);
2739 if (anc_class == 0) tie_met = tie_data;
2740 else tie_oz = tie_data;
2742 if ((
qual = (int32_t *) malloc(tie_npix[anc_class] *
sizeof (int32_t)))
2745 "-E- %s %d: Unable to allocate tie point quality array\n",
2746 __FILE__, __LINE__);
2749 if (anc_class == 0) qual_met =
qual;
2750 else qual_oz =
qual;
2755 for (ids = 0; ids < n_ds_prm; ids++) {
2756 ptr_prm = ids + class_off;
2757 if (nc_inq_varid(ncid[anc_class], anc_prm_nm[ptr_prm], &varid[ptr_prm])
2760 "-E- %s %d: Can't find id for OLCI anc tie point dataset: %s\n",
2761 __FILE__, __LINE__, anc_prm_nm[ptr_prm]);
2764 if (nc_get_att_float(ncid[anc_class], varid[ptr_prm],
"_FillValue",
2765 &fill[ptr_prm]) != NC_NOERR) {
2767 "-E- %s %d: Can't get _FillValue for OLCI anc tie point dataset: %s\n",
2768 __FILE__, __LINE__, anc_prm_nm[ptr_prm]);
2772 if (nc_get_att_float(ncid[anc_class], varid[ptr_prm],
"valid_min",
2775 "-E- %s %d: Can't get valid_min for OLCI anc tie point dataset: %s\n",
2776 __FILE__, __LINE__, anc_prm_nm[ptr_prm]);
2779 if (nc_get_att_float(ncid[anc_class], varid[ptr_prm],
"valid_max",
2782 "-E- %s %d: Can't get valid_max for OLCI anc tie point dataset: %s\n",
2783 __FILE__, __LINE__, anc_prm_nm[ptr_prm]);
2787 firstcalls[anc_class] = 0;
2795 for (ids = 0; ids < n_ds_prm; ids++) {
2796 ptr_prm = ids + class_off;
2803 case 0: ar =
l1rec->rh;
2805 case 1: ar =
l1rec->zw;
2807 case 2: ar =
l1rec->pr;
2809 case 3: ar =
l1rec->wv;
2811 case 4: ar =
l1rec->oz;
2818 count[1] = tie_npix[anc_class];
2822 tie_data = (anc_class == 0) ? tie_met : tie_oz;
2823 qual = (anc_class == 0) ? qual_met : qual_oz;
2825 n_field_per_parm = anc_field_per_parm[ptr_prm];
2826 for (ifld = 0; ifld < n_field_per_parm; ifld++) {
2835 if (
iscan < tie_nlin[anc_class]) {
2837 if ((stat = nc_get_vara_float(ncid[anc_class], varid[ptr_prm],
2840 "-E- %s %d: Can't read OLCI anc tie point line, dataset: %s\n",
2841 __FILE__, __LINE__, anc_prm_nm[ptr_prm]);
2845 for (ipx = 0; ipx < tie_npix[anc_class]; ipx++) {
2846 if ((*(tie_data + ipx) == fill[ptr_prm]) ||
2847 (*(tie_data + ipx) <
valid_min[ptr_prm]) ||
2848 (*(tie_data + ipx) >
valid_max[ptr_prm]))
2852 if (ptr_prm == 3) *(tie_data + ipx) *= 0.1;
2854 if (ptr_prm == 4) *(tie_data + ipx) *= 46.698;
2859 for (ipx = 0; ipx <
npix; ipx++) {
2862 px_tie1 = ipx_dat / pix_smp[anc_class];
2863 px_tie2 = px_tie1 + 1;
2865 if (px_tie2 > (tie_npix[anc_class] - 1)) {
2869 if ((*(
qual + px_tie1) == 1) || (*(
qual + px_tie2) == 1)) {
2875 fr_dist = (
float) (ipx_dat - px_tie1 * pix_smp[anc_class]) /
2876 (
float) pix_smp[anc_class];
2877 *(ar + ipx) = tie_data[px_tie1] * (1. - fr_dist) +
2878 tie_data[px_tie2] * fr_dist;
2883 for (ipx = 0; ipx <
npix; ipx++) {
2893 for (ipx = 0; ipx <
npix; ipx++) {
2894 w1 =
l1rec->zw[ipx];
2895 w2 =
l1rec->mw[ipx];
2896 if (
input->windspeed != -2000)
2897 l1rec->ws[ipx] = sqrt(w1 * w1 + w2 * w2);
2898 if (
input->windangle != -2000)
2899 l1rec->wd[ipx] = atan2f(-w1, w2) * r2d;
2906 for (ipx = 0; ipx <
npix; ipx++) {
2907 if (
l1rec->height[ipx] != 0.0)
2908 l1rec->pr[ipx] *= exp(-
l1rec->height[ipx] / 8434);
2943 case 2: fill = 1013.;
2947 case 4: fill = 0.36;
2954 float xfrac,
float yfrac)
2985 if ((*(
data + xbox_st + nx * ybox_st) < (
ANCBAD + 1)) ||
2986 (*(
data + xbox_st + nx * (ybox_st + 1)) < (
ANCBAD + 1)) ||
2987 (*(
data + (xbox_st + 1) + nx * ybox_st) < (
ANCBAD + 1)) ||
2988 (*(
data + (xbox_st + 1) + nx * (ybox_st + 1)) < (
ANCBAD + 1)))
2992 (1 - xfrac) * (1 - yfrac) *
2993 *(
data + xbox_st + nx * ybox_st) +
2994 (1 - xfrac) * yfrac *
2995 *(
data + xbox_st + nx * (ybox_st + 1)) +
2996 xfrac * (1 - yfrac) *
2997 *(
data + (xbox_st + 1) + nx * ybox_st) +
2999 *(
data + (xbox_st + 1) + nx * (ybox_st + 1));
3027 int64_t lyear, lmonth, lday,
jday;
3029 lyear = (int64_t)
year;
3030 lmonth = (int64_t) month;
3031 lday = (int64_t)
day;
3032 jday = (367 * lyear - 7 * (lyear + (lmonth + 9) / 12) / 4
3033 + 275 * lmonth / 9 + lday + 1721014);
3038 jday =
jday + 15 - 3 * ((lyear + (lmonth - 9) / 7) / 100 + 1) / 4;
3067 int64_t v1,
v2, v3, v4;
3069 v2 = 4 * v1 / 146097;
3070 v1 = v1 - (146097 *
v2 + 3) / 4;
3071 v3 = 4000 * (v1 + 1) / 1461001;
3072 v1 = v1 - 1461 * v3 / 4 + 31;
3073 v4 = 80 * v1 / 2447;
3074 *
day = v1 - 2447 * v4 / 80;
3076 *month = v4 + 2 - 12 * v1;
3077 *
year = 100 * (
v2 - 49) + v3 + v1;