43 NC(nc_def_var(ncid, varname, type, ndims, dimid, varid));
46 NC(nc_put_att_text(ncid, *varid,
"long_name", strlen(longname), longname));
49 NC(nc_put_att_text(ncid, *varid,
"units", strlen(unit), unit));
52 NC(nc_put_att_double(ncid, *varid,
"_FillValue", type, 1, &dp));
67 ALLOC(met0,
met_t, 1);
68 ALLOC(met1,
met_t, 1);
71 for (
int ids = 0; ids < gps->
nds; ids++) {
74 for (
int iz = 0; iz < gps->
nz[ids]; iz++) {
77 get_met(metbase, dt_met, gps->
time[ids], met0, met1);
81 gps->
lon[ids][iz], gps->
lat[ids][iz], &t);
84 gps->
pt[ids][iz] = gps->
t[ids][iz] - t;
101 for (
int ids = 0; ids < gps->
nds; ids++) {
105 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
106 gps->
pt[ids][iz] = 0;
109 const double dlat = dx * 180. / (M_PI * RE) / 2.3548;
110 const double dlon = dy * 180. / 2.3548
111 / (M_PI * RE * cos(gps->
lat[ids][gps->
nz[ids] / 2] * M_PI / 180.));
114 for (
int ids2 = 0; ids2 < gps->
nds; ids2++) {
115 const double w = exp(-0.5 * gsl_pow_2((gps->
lon[ids][gps->
nz[ids] / 2]
116 - gps->
lon[ids2][gps->
nz[ids2] / 2]) / dlon)
117 - 0.5 * gsl_pow_2((gps->
lat[ids][gps->
nz[ids] / 2]
118 - gps->
lat[ids2][gps->
nz[ids2] / 2]) / dlat));
120 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
121 gps->
pt[ids][iz] += w * gps->
t[ids2][iz];
126 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
127 gps->
pt[ids][iz] = gps->
t[ids][iz] - gps->
pt[ids][iz] / wsum;
143 ERRMSG(
"Too many altitudes!");
146 for (
int ids = 0; ids < gps->
nds; ids++) {
149 for (
int iz = 0; iz < nz; iz++) {
152 z[iz] = LIN(0.0, zmin, nz - 1.0, zmax, (
double) iz);
155 const int iz2 = locate_irr(gps->
z[ids], gps->
nz[ids], z[iz]);
158 lon[iz] = LIN(gps->
z[ids][iz2], gps->
lon[ids][iz2],
159 gps->
z[ids][iz2 + 1], gps->
lon[ids][iz2 + 1], z[iz]);
160 lat[iz] = LIN(gps->
z[ids][iz2], gps->
lat[ids][iz2],
161 gps->
z[ids][iz2 + 1], gps->
lat[ids][iz2 + 1], z[iz]);
162 p[iz] = LIN(gps->
z[ids][iz2], gps->
p[ids][iz2],
163 gps->
z[ids][iz2 + 1], gps->
p[ids][iz2 + 1], z[iz]);
164 t[iz] = LIN(gps->
z[ids][iz2], gps->
t[ids][iz2],
165 gps->
z[ids][iz2 + 1], gps->
t[ids][iz2 + 1], z[iz]);
166 wv[iz] = LIN(gps->
z[ids][iz2], gps->
wv[ids][iz2],
167 gps->
z[ids][iz2 + 1], gps->
wv[ids][iz2 + 1], z[iz]);
168 pt[iz] = LIN(gps->
z[ids][iz2], gps->
pt[ids][iz2],
169 gps->
z[ids][iz2 + 1], gps->
pt[ids][iz2 + 1], z[iz]);
174 for (
int iz = 0; iz < nz; iz++) {
175 gps->
z[ids][iz] = z[iz];
176 gps->
lon[ids][iz] = lon[iz];
177 gps->
lat[ids][iz] = lat[iz];
178 gps->
p[ids][iz] = p[iz];
179 gps->
t[ids][iz] = t[iz];
180 gps->
wv[ids][iz] = wv[iz];
181 gps->
pt[ids][iz] = pt[iz];
211 if (t > met1->
time) {
212 memcpy(met0, met1,
sizeof(
met_t));
229 int year, mon, day, hour, min, sec;
233 t6 = floor(t / dt_met) * dt_met;
235 t6 = ceil(t / dt_met) * dt_met;
238 jsec2time(t6, &year, &mon, &day, &hour, &min, &sec, &r);
241 sprintf(filename,
"%s_%d_%02d_%02d_%02d.nc", metbase, year, mon, day, hour);
257 double aux00 = wp * (array[ix][iy][ip] - array[ix][iy][ip + 1])
258 + array[ix][iy][ip + 1];
259 double aux01 = wp * (array[ix][iy + 1][ip] - array[ix][iy + 1][ip + 1])
260 + array[ix][iy + 1][ip + 1];
261 double aux10 = wp * (array[ix + 1][iy][ip] - array[ix + 1][iy][ip + 1])
262 + array[ix + 1][iy][ip + 1];
263 double aux11 = wp * (array[ix + 1][iy + 1][ip] - array[ix + 1][iy + 1][ip + 1])
264 + array[ix + 1][iy + 1][ip + 1];
267 aux00 = wy * (aux00 - aux01) + aux01;
268 aux11 = wy * (aux10 - aux11) + aux11;
269 *var = wx * (aux00 - aux11) + aux11;
282 if (met->
lon[met->
nx - 1] > 180 && lon < 0)
286 const int ip = locate_irr(met->
p, met->
np, p);
287 const int ix = locate_reg(met->
lon, met->
nx, lon);
288 const int iy = locate_reg(met->
lat, met->
ny, lat);
291 const double wp = (met->
p[ip + 1] - p) / (met->
p[ip + 1] - met->
p[ip]);
292 const double wx = (met->
lon[ix + 1] - lon) / (met->
lon[ix + 1] - met->
lon[ix]);
293 const double wy = (met->
lat[iy + 1] - lat) / (met->
lat[iy + 1] - met->
lat[iy]);
317 const double wt = (met1->
time - ts) / (met1->
time - met0->
time);
320 *t = wt * (t0 - t1) + t1;
332 for (
int ids = 0; ids < gps->
nds; ids++) {
335 int nham = (int) (dz / fabs((gps->
z[ids][0] - gps->
z[ids][gps->
nz[ids] - 1])
336 / (gps->
nz[ids] - 1.0)) + 0.5);
337 nham = GSL_MAX(GSL_MIN(nham,
NZ), 2);
338 for (
int iham = 0; iham < nham; iham++)
339 ham[iham] = 0.54 + 0.46 * cos(M_PI * iham / (nham - 1.0));
342 for (
int iz = 0; iz < gps->
nz[ids]; iz++) {
345 gps->
pt[ids][iz] = ham[0] * gps->
t[ids][iz];
346 double wsum = ham[0];
349 for (
int iham = 1; iham < nham; iham++) {
352 if (iz - iham < 0 || iz + iham >= gps->
nz[ids])
356 if (!gsl_finite(gps->
t[ids][iz - iham]) ||
357 !gsl_finite(gps->
t[ids][iz + iham]))
361 if (gsl_finite(gps->
th[ids]) && gps->
th[ids] > 0)
362 if ((gps->
z[ids][iz] >= gps->
th[ids]
363 && gps->
z[ids][iz - iham] < gps->
th[ids])
364 || (gps->
z[ids][iz] <= gps->
th[ids]
365 && gps->
z[ids][iz + iham] > gps->
th[ids]))
370 += ham[iham] * (gps->
t[ids][iz - iham] + gps->
t[ids][iz + iham]);
371 wsum += 2 * ham[iham];
375 gps->
pt[ids][iz] = gps->
t[ids][iz] - gps->
pt[ids][iz] / wsum;
386 double ham[
NZ], pt[
NZ];
389 for (
int ids = 0; ids < gps->
nds; ids++) {
392 int nham = (int) (dz / fabs((gps->
z[ids][0] - gps->
z[ids][gps->
nz[ids] - 1])
393 / (gps->
nz[ids] - 1.0)) + 0.5);
394 nham = GSL_MAX(GSL_MIN(nham,
NZ), 2);
395 for (
int iham = 0; iham < nham; iham++)
396 ham[iham] = 0.54 + 0.46 * cos(M_PI * iham / (nham - 1.0));
399 for (
int iz = 0; iz < gps->
nz[ids]; iz++) {
402 pt[iz] = ham[0] * gps->
pt[ids][iz];
403 double wsum = ham[0];
406 for (
int iham = 1; iham < nham; iham++) {
409 if (iz - iham < 0 || iz + iham >= gps->
nz[ids])
413 if (!gsl_finite(gps->
t[ids][iz - iham]) ||
414 !gsl_finite(gps->
t[ids][iz + iham]))
419 += ham[iham] * (gps->
pt[ids][iz - iham] + gps->
pt[ids][iz + iham]);
420 wsum += 2 * ham[iham];
428 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
429 gps->
pt[ids][iz] = pt[iz];
444 for (
int ids = 0; ids < gps->
nds; ids++) {
447 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
448 bg[iz] = gps->
pt[ids][iz];
451 poly_help(gps->
z[ids], bg, gps->
nz[ids], dim, zmin, zmax);
454 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
455 gps->
pt[ids][iz] -= bg[iz];
469 gsl_multifit_linear_workspace *work;
471 gsl_vector *c, *x, *y;
473 double chisq, xx2[
NZ], yy2[
NZ];
475 size_t i, i2, n2 = 0;
478 for (i = 0; i < (size_t) n; i++)
479 if (xx[i] >= xmin && xx[i] <= xmax && gsl_finite(yy[i])) {
484 if ((
int) n2 < dim) {
485 for (i = 0; i < (size_t) n; i++)
491 work = gsl_multifit_linear_alloc((
size_t) n2, (
size_t) dim);
492 cov = gsl_matrix_alloc((
size_t) dim, (
size_t) dim);
493 X = gsl_matrix_alloc((
size_t) n2, (
size_t) dim);
494 c = gsl_vector_alloc((
size_t) dim);
495 x = gsl_vector_alloc((
size_t) n2);
496 y = gsl_vector_alloc((
size_t) n2);
499 for (i = 0; i < (size_t) n2; i++) {
500 gsl_vector_set(x, i, xx2[i]);
501 gsl_vector_set(y, i, yy2[i]);
502 for (i2 = 0; i2 < (size_t) dim; i2++)
503 gsl_matrix_set(X, i, i2, pow(gsl_vector_get(x, i), (
double) i2));
505 gsl_multifit_linear(X, y, c, cov, &chisq, work);
506 for (i = 0; i < (size_t) n; i++)
507 yy[i] = gsl_poly_eval(c->data, (
int) dim, xx[i]);
510 gsl_multifit_linear_free(work);
511 gsl_matrix_free(cov);
526 double t0, t1, zmin = 1e100, zmax = -1e100;
528 int ncid, dimid, varid;
533 printf(
"Read GPS-RO profile: %s\n", filename);
534 NC(nc_open(filename, NC_NOWRITE, &ncid));
537 NC(nc_inq_dimid(ncid,
"MSL_alt", &dimid));
538 NC(nc_inq_dimlen(ncid, dimid, &nz));
539 gps->
nz[gps->
nds] = (int) nz;
541 ERRMSG(
"Too many altitudes!");
544 NC(nc_get_att_text(ncid, NC_GLOBAL,
"bad", bad));
551 NC(nc_get_att_double(ncid, NC_GLOBAL,
"start_time", &t0));
552 NC(nc_get_att_double(ncid, NC_GLOBAL,
"stop_time", &t1));
553 gps->
time[gps->
nds] = 0.5 * (t0 + t1) - 630720000.0;
556 NC(nc_inq_varid(ncid,
"MSL_alt", &varid));
557 NC(nc_get_var_double(ncid, varid, gps->
z[gps->
nds]));
558 NC(nc_inq_varid(ncid,
"Lon", &varid));
559 NC(nc_get_var_double(ncid, varid, gps->
lon[gps->
nds]));
560 NC(nc_inq_varid(ncid,
"Lat", &varid));
561 NC(nc_get_var_double(ncid, varid, gps->
lat[gps->
nds]));
562 NC(nc_inq_varid(ncid,
"Pres", &varid));
563 NC(nc_get_var_double(ncid, varid, gps->
p[gps->
nds]));
564 NC(nc_inq_varid(ncid,
"Temp", &varid));
565 NC(nc_get_var_double(ncid, varid, gps->
t[gps->
nds]));
566 if (nc_inq_varid(ncid,
"Vp", &varid) == NC_NOERR)
567 NC(nc_get_var_double(ncid, varid, gps->
wv[gps->
nds]));
570 for (iz = 0; iz < nz; iz++)
571 if (gps->
p[gps->
nds][iz] != -999 && gps->
t[gps->
nds][iz] != -999) {
572 zmin = GSL_MIN(zmin, gps->
z[gps->
nds][iz]);
573 zmax = GSL_MAX(zmax, gps->
z[gps->
nds][iz]);
575 if (zmin > 5 || zmax < 35) {
581 for (iz = 0; iz < nz; iz++)
582 if (gps->
lon[gps->
nds][iz] == -999 ||
583 gps->
lat[gps->
nds][iz] == -999 ||
584 gps->
p[gps->
nds][iz] == -999 ||
585 gps->
t[gps->
nds][iz] == -999 || gps->
wv[gps->
nds][iz] == -999) {
586 gps->
lon[gps->
nds][iz] = GSL_NAN;
587 gps->
lat[gps->
nds][iz] = GSL_NAN;
588 gps->
p[gps->
nds][iz] = GSL_NAN;
589 gps->
t[gps->
nds][iz] = GSL_NAN;
590 gps->
wv[gps->
nds][iz] = GSL_NAN;
594 for (iz = 0; iz < nz; iz++)
595 gps->
t[gps->
nds][iz] += 273.15;
598 for (iz = 0; iz < nz; iz++)
599 gps->
wv[gps->
nds][iz] /= gps->
p[gps->
nds][iz];
606 ERRMSG(
"Too many profiles!");
615 int ids, ncid, dimid, varid;
617 size_t start[2], count[2], nds, nz;
620 printf(
"Read GPS-RO file: %s\n", filename);
621 NC(nc_open(filename, NC_NOWRITE, &ncid));
624 NC(nc_inq_dimid(ncid,
"NDS", &dimid));
625 NC(nc_inq_dimlen(ncid, dimid, &nds));
626 gps->
nds = (int) nds;
628 ERRMSG(
"Too many profiles!");
630 NC(nc_inq_dimid(ncid,
"NZ", &dimid));
631 NC(nc_inq_dimlen(ncid, dimid, &nz));
633 ERRMSG(
"Too many profiles!");
636 for (ids = 0; ids < gps->
nds; ids++) {
639 start[0] = (size_t) ids;
645 gps->
nz[ids] = (int) nz;
648 NC(nc_inq_varid(ncid,
"time", &varid));
649 NC(nc_get_vara_double(ncid, varid, start, count, &gps->
time[ids]));
651 NC(nc_inq_varid(ncid,
"z", &varid));
652 NC(nc_get_vara_double(ncid, varid, start, count, gps->
z[ids]));
654 NC(nc_inq_varid(ncid,
"lon", &varid));
655 NC(nc_get_vara_double(ncid, varid, start, count, gps->
lon[ids]));
657 NC(nc_inq_varid(ncid,
"lat", &varid));
658 NC(nc_get_vara_double(ncid, varid, start, count, gps->
lat[ids]));
660 NC(nc_inq_varid(ncid,
"p", &varid));
661 NC(nc_get_vara_double(ncid, varid, start, count, gps->
p[ids]));
663 NC(nc_inq_varid(ncid,
"t", &varid));
664 NC(nc_get_vara_double(ncid, varid, start, count, gps->
t[ids]));
666 NC(nc_inq_varid(ncid,
"wv", &varid));
667 NC(nc_get_vara_double(ncid, varid, start, count, gps->
wv[ids]));
669 NC(nc_inq_varid(ncid,
"pt", &varid));
670 NC(nc_get_vara_double(ncid, varid, start, count, gps->
pt[ids]));
672 NC(nc_inq_varid(ncid,
"th", &varid));
673 NC(nc_get_vara_double(ncid, varid, start, count, &gps->
th[ids]));
688 int ip, dimid, ncid, varid, year, mon, day, hour;
693 printf(
"Read meteorological data: %s\n", filename);
696 sprintf(tstr,
"%.4s", &filename[strlen(filename) - 16]);
698 sprintf(tstr,
"%.2s", &filename[strlen(filename) - 11]);
700 sprintf(tstr,
"%.2s", &filename[strlen(filename) - 8]);
702 sprintf(tstr,
"%.2s", &filename[strlen(filename) - 5]);
704 time2jsec(year, mon, day, hour, 0, 0, 0, &met->
time);
707 NC(nc_open(filename, NC_NOWRITE, &ncid));
710 NC(nc_inq_dimid(ncid,
"lon", &dimid));
711 NC(nc_inq_dimlen(ncid, dimid, &nx));
713 ERRMSG(
"Too many longitudes!");
715 NC(nc_inq_dimid(ncid,
"lat", &dimid));
716 NC(nc_inq_dimlen(ncid, dimid, &ny));
718 ERRMSG(
"Too many latitudes!");
720 NC(nc_inq_dimid(ncid,
"lev", &dimid));
721 NC(nc_inq_dimlen(ncid, dimid, &np));
723 ERRMSG(
"Too many levels!");
731 NC(nc_inq_varid(ncid,
"lon", &varid));
732 NC(nc_get_var_double(ncid, varid, met->
lon));
733 NC(nc_inq_varid(ncid,
"lat", &varid));
734 NC(nc_get_var_double(ncid, varid, met->
lat));
740 NC(nc_inq_varid(ncid,
"lev", &varid));
741 NC(nc_get_var_double(ncid, varid, met->
p));
742 for (ip = 0; ip < met->
np; ip++)
749 for (ip = 1; ip < met->
np; ip++)
750 if (met->
p[ip - 1] < met->
p[ip])
751 ERRMSG(
"Pressure levels must be descending!");
768 for (
int ix = 0; ix < met->
nx; ix++)
769 for (
int iy = 0; iy < met->
ny; iy++) {
772 for (ip0 = met->
np - 1; ip0 >= 0; ip0--)
773 if (!gsl_finite(met->
t[ix][iy][ip0]))
777 for (
int ip = ip0; ip >= 0; ip--)
778 met->
t[ix][iy][ip] = met->
t[ix][iy][ip + 1];
792 static float help[
EX *
EY *
EP];
797 if (nc_inq_varid(ncid, varname, &varid) != NC_NOERR)
798 if (nc_inq_varid(ncid, varname2, &varid) != NC_NOERR)
802 NC(nc_get_var_float(ncid, varid, help));
805 for (
int ip = 0; ip < met->
np; ip++)
806 for (
int iy = 0; iy < met->
ny; iy++)
807 for (
int ix = 0; ix < met->
nx; ix++) {
808 dest[ix][iy][ip] = scl * help[n++];
809 if (fabs(dest[ix][iy][ip] / scl) > 1e14)
810 dest[ix][iy][ip] = GSL_NAN;
820 if (!(fabs(met->
lon[met->
nx - 1] - met->
lon[0]
821 + met->
lon[1] - met->
lon[0] - 360) < 0.01))
825 if ((++met->
nx) >
EX)
826 ERRMSG(
"Cannot create periodic boundary conditions!");
832 for (
int iy = 0; iy < met->
ny; iy++)
833 for (
int ip = 0; ip < met->
np; ip++)
834 met->
t[met->
nx - 1][iy][ip] = met->
t[0][iy][ip];
852 gsl_interp_accel *acc = gsl_interp_accel_alloc();
853 gsl_spline *s = gsl_spline_alloc(gsl_interp_cspline, (
size_t) n);
856 gsl_spline_init(s, x, y, (
size_t) n);
857 for (
int i = 0; i < n2; i++)
860 else if (x2[i] >= x[n - 1])
863 y2[i] = gsl_spline_eval(s, x2[i], acc);
867 gsl_interp_accel_free(acc);
872 for (
int i = 0; i < n2; i++)
875 else if (x2[i] >= x[n - 1])
878 int idx = locate_irr(x, n, x2[i]);
879 y2[i] = LIN(x[idx], y[idx], x[idx + 1], y[idx + 1], x2[i]);
892 for (
int ids = 0; ids < gps->
nds; ids++) {
895 gps->
th[ids] = GSL_NAN;
899 8 - 4 * fabs(cos((90 - gps->
lat[ids][gps->
nz[ids] / 2]) * M_PI / 180));
902 for (iz = 0; iz < gps->
nz[ids]; iz++)
903 if (gps->
z[ids][iz] >= zmin && gps->
z[ids][iz] <= 20.0) {
905 for (iz2 = iz + 1; iz2 < gps->
nz[ids]; iz2++)
906 if (gps->
z[ids][iz2] - gps->
z[ids][iz] <= 2.0)
907 if (!gsl_finite(gps->
t[ids][iz]) ||
908 !gsl_finite(gps->
t[ids][iz2]) ||
909 (gps->
t[ids][iz2] - gps->
t[ids][iz])
910 / (gps->
z[ids][iz2] - gps->
z[ids][iz]) < -2.0)
913 gps->
th[ids] = gps->
z[ids][iz];
927#pragma omp parallel for default(shared)
928 for (
int ids = 0; ids < gps->
nds; ids++) {
935 gps->
tlon[ids] = NAN;
936 gps->
tlat[ids] = NAN;
941 for (
int iz = 0; iz < gps->
nz[ids]; iz++)
942 if (gsl_finite(gps->
p[ids][iz]) && gsl_finite(gps->
t[ids][iz])
943 && gsl_finite(gps->
z[ids][iz])
944 && gps->
z[ids][iz] >= 4.0 && gps->
z[ids][iz] <= 24.0) {
945 h[nz] = gps->
z[ids][iz];
946 t[nz] = gps->
t[ids][iz];
947 z[nz] =
Z(gps->
p[ids][iz]);
948 q[nz] = gps->
wv[ids][iz];
949 lon[nz] = gps->
lon[ids][iz];
950 lat[nz] = gps->
lat[ids][iz];
951 if (nz > 0 && z[nz] <= z[nz - 1])
952 ERRMSG(
"Profiles must be ascending!");
954 ERRMSG(
"Too many height levels!");
956 if (z[0] > 4.5 || z[nz - 1] < 23.5)
957 WARN(
"Vertical profile is incomplete!");
960 double h2[200], p2[200], t2[200], z2[200], q2[200];
961 for (
int iz = 0; iz <= 190; iz++) {
962 z2[iz] = 4.5 + 0.1 * iz;
967 spline(z, t, nz, z2, t2, 191, 1);
968 spline(z, h, nz, z2, h2, 191, 1);
969 spline(z, q, nz, z2, q2, 191, 1);
972 if (met_tropo == 2) {
975 int iz = (int) gsl_stats_min_index(t2, 1, 171);
976 if (iz > 0 && iz < 170) {
977 gps->
tp[ids] = p2[iz];
978 gps->
th[ids] = h2[iz];
979 gps->
tt[ids] = t2[iz];
980 gps->
tq[ids] = q2[iz];
985 else if (met_tropo == 3 || met_tropo == 4) {
989 for (iz = 0; iz <= 170; iz++) {
991 for (
int iz2 = iz + 1; iz2 <= iz + 20; iz2++)
992 if (
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]) > 2.0) {
997 if (iz > 0 && iz < 170) {
998 gps->
tp[ids] = p2[iz];
999 gps->
th[ids] = h2[iz];
1000 gps->
tt[ids] = t2[iz];
1001 gps->
tq[ids] = q2[iz];
1008 if (met_tropo == 4) {
1017 for (; iz <= 170; iz++) {
1019 for (
int iz2 = iz + 1; iz2 <= iz + 10; iz2++)
1020 if (
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]) < 3.0) {
1027 for (; iz <= 170; iz++) {
1029 for (
int iz2 = iz + 1; iz2 <= iz + 20; iz2++)
1030 if (
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]) > 2.0) {
1035 if (iz > 0 && iz < 170) {
1036 gps->
tp[ids] = p2[iz];
1037 gps->
th[ids] = h2[iz];
1038 gps->
tt[ids] = t2[iz];
1039 gps->
tq[ids] = q2[iz];
1048 if (gsl_finite(gps->
th[ids]))
1049 for (
int iz = 0; iz < nz - 1; iz++)
1050 if (gps->
th[ids] >= h[iz] && gps->
th[ids] < h[iz + 1]) {
1051 gps->
tlon[ids] = lon[iz];
1052 gps->
tlat[ids] = lat[iz];
1064 static double help[
NDS *
NZ];
1066 int ids, iz, ncid, dimid[2], time_id, z_id, lon_id, lat_id, p_id, t_id,
1067 pt_id, wv_id, th_id, nzmax = 0;
1070 printf(
"Write GPS-RO file: %s\n", filename);
1071 NC(nc_create(filename, NC_CLOBBER, &ncid));
1074 NC(nc_def_dim(ncid,
"NDS", (
size_t) gps->
nds, &dimid[0]));
1075 for (ids = 0; ids < gps->
nds; ids++)
1076 nzmax = GSL_MAX(nzmax, gps->
nz[ids]);
1077 NC(nc_def_dim(ncid,
"NZ", (
size_t) nzmax, &dimid[1]));
1080 add_var(ncid,
"time",
"s",
"time (seconds since 2000-01-01T00:00Z)",
1081 NC_DOUBLE, dimid, &time_id, 1);
1082 add_var(ncid,
"z",
"km",
"altitude", NC_FLOAT, dimid, &z_id, 2);
1083 add_var(ncid,
"lon",
"deg",
"longitude", NC_FLOAT, dimid, &lon_id, 2);
1084 add_var(ncid,
"lat",
"deg",
"latitude", NC_FLOAT, dimid, &lat_id, 2);
1085 add_var(ncid,
"p",
"hPa",
"pressure", NC_FLOAT, dimid, &p_id, 2);
1086 add_var(ncid,
"t",
"K",
"temperature", NC_FLOAT, dimid, &t_id, 2);
1087 add_var(ncid,
"wv",
"ppv",
"water vapor volume mixing ratio",
1088 NC_FLOAT, dimid, &wv_id, 2);
1089 add_var(ncid,
"pt",
"K",
"temperature perturbation",
1090 NC_FLOAT, dimid, &pt_id, 2);
1091 add_var(ncid,
"th",
"km",
"tropopause height", NC_FLOAT, dimid, &th_id, 1);
1094 NC(nc_enddef(ncid));
1097 NC(nc_put_var_double(ncid, time_id, gps->
time));
1098 NC(nc_put_var_double(ncid, th_id, gps->
th));
1099 for (ids = 0; ids < gps->
nds; ids++)
1100 for (iz = 0; iz < gps->
nz[ids]; iz++)
1101 help[ids * nzmax + iz] = gps->
z[ids][iz];
1102 NC(nc_put_var_double(ncid, z_id, help));
1103 for (ids = 0; ids < gps->
nds; ids++)
1104 for (iz = 0; iz < gps->
nz[ids]; iz++)
1105 help[ids * nzmax + iz] = gps->
lon[ids][iz];
1106 NC(nc_put_var_double(ncid, lon_id, help));
1107 for (ids = 0; ids < gps->
nds; ids++)
1108 for (iz = 0; iz < gps->
nz[ids]; iz++)
1109 help[ids * nzmax + iz] = gps->
lat[ids][iz];
1110 NC(nc_put_var_double(ncid, lat_id, help));
1111 for (ids = 0; ids < gps->
nds; ids++)
1112 for (iz = 0; iz < gps->
nz[ids]; iz++)
1113 help[ids * nzmax + iz] = gps->
p[ids][iz];
1114 NC(nc_put_var_double(ncid, p_id, help));
1115 for (ids = 0; ids < gps->
nds; ids++)
1116 for (iz = 0; iz < gps->
nz[ids]; iz++)
1117 help[ids * nzmax + iz] = gps->
t[ids][iz];
1118 NC(nc_put_var_double(ncid, t_id, help));
1119 for (ids = 0; ids < gps->
nds; ids++)
1120 for (iz = 0; iz < gps->
nz[ids]; iz++)
1121 help[ids * nzmax + iz] = gps->
wv[ids][iz];
1122 NC(nc_put_var_double(ncid, wv_id, help));
1123 for (ids = 0; ids < gps->
nds; ids++)
1124 for (iz = 0; iz < gps->
nz[ids]; iz++)
1125 help[ids * nzmax + iz] = gps->
pt[ids][iz];
1126 NC(nc_put_var_double(ncid, pt_id, help));
void read_met_extrapolate(met_t *met)
Extrapolate meteorological data at lower boundary.
void intpol_met_space(met_t *met, double p, double lon, double lat, double *t)
Spatial interpolation of meteorological data.
void write_gps(char *filename, gps_t *gps)
Write GPS-RO data file.
void read_met_periodic(met_t *met)
Create meteorological data with periodic boundary conditions.
void gauss(gps_t *gps, double dx, double dy)
Calculate horizontal Gaussian mean to extract perturbations.
void read_met(char *filename, met_t *met)
Read meteorological data file.
void intpol_met_time(met_t *met0, met_t *met1, double ts, double p, double lon, double lat, double *t)
Temporal interpolation of meteorological data.
void spline(const double *x, const double *y, const int n, const double *x2, double *y2, const int n2, const int method)
Performs spline interpolation or linear interpolation.
void poly(gps_t *gps, int dim, double zmin, double zmax)
Remove polynomial fit from perturbation profile.
void grid_gps(gps_t *gps, double zmin, double zmax, int nz)
Interpolate GPS data to regular altitude grid.
void intpol_met_3d(float array[EX][EY][EP], int ip, int ix, int iy, double wp, double wx, double wy, double *var)
Linear interpolation of 3-D meteorological data.
void add_var(int ncid, const char *varname, const char *unit, const char *longname, int type, int dimid[], int *varid, int ndims)
Add variable to netCDF file.
void get_met(char *metbase, double dt_met, double t, met_t *met0, met_t *met1)
Get meteorological data for given timestep.
void read_gps(char *filename, gps_t *gps)
Read GPS-RO data file.
void hamming_low_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to extract perturbations.
void detrend_met(gps_t *gps, char *metbase, double dt_met)
Detrending by means of meteo data.
void read_gps_prof(char *filename, gps_t *gps)
Read GPS-RO profile.
void get_met_help(double t, int direct, char *metbase, double dt_met, char *filename)
Get meteorological data for timestep.
void hamming_high_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to reduce noise.
void tropopause_spline(gps_t *gps, int met_tropo)
Find tropopause height using cubic spline interpolation.
void poly_help(double *xx, double *yy, int n, int dim, double xmin, double xmax)
Auxiliary function for polynomial interpolation.
void read_met_help(int ncid, char *varname, char *varname2, met_t *met, float dest[EX][EY][EP], float scl)
Read and convert variable from meteorological data file.
void tropopause(gps_t *gps)
Find tropopause height.
GPS Code Collection library declarations.
#define LAPSE(p1, t1, p2, t2)
Calculate lapse rate.
#define NC(cmd)
Execute netCDF library command and check result.
#define EY
Maximum number of latitudes for meteorological data.
#define Z(p)
Convert pressure to altitude.
#define P(z)
Compute pressure at given altitude.
#define NZ
Maximum number of altitudes per GPS-RO profile.
#define EX
Maximum number of longitudes for meteorological data.
#define NDS
Maximum number of GPS-RO profiles.
#define EP
Maximum number of pressure levels for meteorological data.
double time[NDS]
Time (seconds since 2000-01-01T00:00Z).
double pt[NDS][NZ]
Temperature perturbation [K].
double tlon[NDS]
Tropopause longitude [deg].
double tt[NDS]
Tropopause temperature [K].
double t[NDS][NZ]
Temperature [K].
double tp[NDS]
Tropopause pressure [hPa].
double wv[NDS][NZ]
Water vapor volume mixing ratio [ppm].
int nz[NDS]
Number of altitudes per profile.
double lon[NDS][NZ]
Longitude [deg].
int nds
Number of profiles.
double p[NDS][NZ]
Pressure [hPa].
double th[NDS]
Tropopause height [km].
double z[NDS][NZ]
Altitude [km].
double tlat[NDS]
Tropopause latitude [deg].
double lat[NDS][NZ]
Latitude [deg].
double tq[NDS]
Tropopause water vapor [ppmv].
int nx
Number of longitudes.
int ny
Number of latitudes.
int np
Number of pressure levels.
float t[EX][EY][EP]
Temperature [K].
double lon[EX]
Longitude [deg].
double lat[EY]
Latitude [deg].
double p[EP]
Pressure [hPa].