37 int nc_result=(cmd); \
38 if(nc_result!=NC_NOERR) \
39 ERRMSG("%s", nc_strerror(nc_result)); \
134 double err_formod[
ND];
137 double err_noise[
ND];
186 const char *longname,
196 gsl_matrix * s_a_inv,
197 gsl_vector * sig_eps_inv);
260 gsl_vector * sig_noise,
261 gsl_vector * sig_formod,
262 gsl_vector * sig_eps_inv);
273 static atm_t atm_apr, atm_clim, atm_i;
274 static obs_t obs_i, obs_meas;
278 static FILE *in, *out;
280 static char filename[
LEN], filename2[2 *
LEN];
285 static int channel[
ND], n, ntask = -1, rank, size;
292 MPI_Init(&argc, &argv);
293 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
294 MPI_Comm_size(MPI_COMM_WORLD, &size);
301 ERRMSG(
"Give parameters: <ctl> <filelist>");
308 const int nz = (int)
scan_ctl(argc, argv,
"NZ", -1,
"", NULL);
310 ERRMSG(
"Too many altitudes!");
311 for (
int iz = 0; iz < nz; iz++)
312 z[iz] =
scan_ctl(argc, argv,
"Z", iz,
"", NULL);
315 const int track0 = (int)
scan_ctl(argc, argv,
"TRACK_MIN", -1,
"0", NULL);
316 const int track1 = (int)
scan_ctl(argc, argv,
"TRACK_MAX", -1,
"134", NULL);
319 const int xtrack0 = (int)
scan_ctl(argc, argv,
"XTRACK_MIN", -1,
"0", NULL);
321 (int)
scan_ctl(argc, argv,
"XTRACK_MAX", -1,
"89", NULL);
324 const double sx =
scan_ctl(argc, argv,
"SX", -1,
"8", NULL);
325 const double sy =
scan_ctl(argc, argv,
"SY", -1,
"2", NULL);
332 printf(
"Read filelist: %s\n", argv[2]);
333 if (!(in = fopen(argv[2],
"r")))
334 ERRMSG(
"Cannot open filelist!");
337 while (fscanf(in,
"%s", filename) != EOF) {
340 if ((++ntask) % size != rank)
344 printf(
"Retrieve file %s on rank %d of %d (with %d threads)...\n",
345 filename, rank + 1, size, omp_get_max_threads());
355 for (
int id = 0;
id < ctl.
nd;
id++) {
358 if (fabs(ctl.
nu[
id] - ncd.
l1_nu[i]) < 0.1)
361 ERRMSG(
"Cannot identify radiance channel!");
370 for (
int iz = 0; iz < nz; iz++)
371 atm_clim.
z[iz] = z[iz];
379 for (
int track = track0; track <= track1; track++) {
382 TIMER(
"retrieval", 1);
385 for (
int xtrack = xtrack0; xtrack <= xtrack1; xtrack++) {
395 for (
int id = 0;
id < ctl.
nd;
id++)
396 obs_meas.
rad[
id][0] = ncd.
l1_rad[track][xtrack][channel[
id]];
399 for (
int id = 0;
id < ctl.
nd;
id++)
400 if (ctl.
nu[
id] >= 2000)
401 obs_meas.
rad[id][0] = GSL_NAN;
404 copy_atm(&ctl, &atm_apr, &atm_clim, 0);
405 for (
int ip = 0; ip < atm_apr.
np; ip++) {
406 atm_apr.
time[ip] = obs_meas.
time[0];
407 atm_apr.
lon[ip] = obs_meas.
vplon[0];
408 atm_apr.
lat[ip] = obs_meas.
vplat[0];
412 init_l2(&ncd, track, xtrack, &ctl, &atm_apr);
416 &atm_apr, &atm_i, &chisq[track][xtrack]);
419 for (
int id = 0;
id < ctl.
nd;
id++)
420 obs_meas.
rad[
id][0] = obs_i.
rad[
id][0]
421 = ncd.
l1_rad[track][xtrack][channel[
id]];
422 formod(&ctl, &atm_i, &obs_i);
426 ni[track][xtrack] = 0;
427 for (
int id = 0;
id < ctl.
nd;
id++)
428 if (ctl.
nu[
id] >= 2000 && gsl_finite(obs_meas.
rad[
id][0])) {
434 ni[track][xtrack] /= n;
438 TIMER(
"retrieval", 3);
446 sprintf(filename2,
"%s.nlte.tab", filename);
449 printf(
"Write non-LTE data: %s\n", filename2);
450 if (!(out = fopen(filename2,
"w")))
451 ERRMSG(
"Cannot create file!");
455 "# $1 = time (seconds since 2000-01-01, 00:00 UTC)\n"
456 "# $2 = longitude [deg]\n"
457 "# $3 = latitude [deg]\n"
458 "# $4 = solar zenith angle [deg]\n"
459 "# $5 = non-LTE index [K]\n" "# $6 = chi^2 of retrieval fit\n");
462 for (
int track = track0; track <= track1; track++) {
464 for (
int xtrack = xtrack0; xtrack <= xtrack1; xtrack++)
465 fprintf(out,
"%.2f %g %g %g %g %g\n",
467 ncd.
l1_lon[track][xtrack],
468 ncd.
l1_lat[track][xtrack],
470 ncd.
l1_lat[track][xtrack]), ni[track][xtrack],
471 chisq[track][xtrack]);
478 printf(
"Retrieval finished on rank %d of %d!\n", rank, size);
488 printf(
"MEMORY_ATM = %g MByte\n", 4. *
sizeof(
atm_t) / 1024. / 1024.);
489 printf(
"MEMORY_CTL = %g MByte\n", 1. *
sizeof(
ctl_t) / 1024. / 1024.);
490 printf(
"MEMORY_NCD = %g MByte\n", 1. *
sizeof(
ncd_t) / 1024. / 1024.);
491 printf(
"MEMORY_OBS = %g MByte\n", 3. *
sizeof(
atm_t) / 1024. / 1024.);
492 printf(
"MEMORY_RET = %g MByte\n", 1. *
sizeof(
ret_t) / 1024. / 1024.);
493 printf(
"MEMORY_TBL = %g MByte\n", 1. *
sizeof(
tbl_t) / 1024. / 1024.);
496 printf(
"SIZE_TASKS = %d\n", size);
497 printf(
"SIZE_THREADS = %d\n", omp_get_max_threads());
511 const char *longname,
518 if (nc_inq_varid(ncid, varname, varid) != NC_NOERR) {
521 NC(nc_def_var(ncid, varname, type, ndims, dimid, varid));
525 (ncid, *varid,
"long_name", strlen(longname), longname));
528 NC(nc_put_att_text(ncid, *varid,
"units", strlen(unit), unit));
538 gsl_vector *sig_eps_inv) {
540 double chisq_a, chisq_m = 0;
543 const size_t m = dy->size;
544 const size_t n = dx->size;
547 gsl_vector *x_aux = gsl_vector_alloc(n);
548 gsl_vector *y_aux = gsl_vector_alloc(m);
552 for (
size_t i = 0; i < m; i++)
554 gsl_pow_2(gsl_vector_get(dy, i) * gsl_vector_get(sig_eps_inv, i));
555 gsl_blas_dgemv(CblasNoTrans, 1.0, s_a_inv, dx, 0.0, x_aux);
556 gsl_blas_ddot(dx, x_aux, &chisq_a);
559 gsl_vector_free(x_aux);
560 gsl_vector_free(y_aux);
563 return (chisq_m + chisq_a) / (double) m;
576 for (
int lay = 0; lay <
L2_NLAY; lay++) {
579 for (
int track = 0; track <
L2_NTRACK; track++)
580 for (
int xtrack = 0; xtrack <
L2_NXTRACK; xtrack++) {
583 help[track][xtrack] = 0;
587 for (
int track2 = 0; track2 <
L2_NTRACK; track2++)
588 for (
int xtrack2 = 0; xtrack2 <
L2_NXTRACK; xtrack2++)
589 if (gsl_finite(x[track2][xtrack2][lay])
590 && x[track2][xtrack2][lay] > 0) {
591 const double w = exp(-gsl_pow_2((xtrack - xtrack2) / cx)
592 - gsl_pow_2((track - track2) / cy));
593 help[track][xtrack] += w * x[track2][xtrack2][lay];
599 help[track][xtrack] /= wsum;
601 help[track][xtrack] = GSL_NAN;
605 for (
int track = 0; track <
L2_NTRACK; track++)
606 for (
int xtrack = 0; xtrack <
L2_NXTRACK; xtrack++)
607 x[track][xtrack][lay] = help[track][xtrack];
620 static atm_t atm_airs;
622 double k[
NW], p, q[
NG], t, zmax = 0, zmin = 1000;
630 for (
int lay = 0; lay <
L2_NLAY; lay++)
631 if (gsl_finite(ncd->
l2_z[track][xtrack][lay])) {
632 atm_airs.
z[atm_airs.
np] = ncd->
l2_z[track][xtrack][lay];
633 atm_airs.
p[atm_airs.
np] = ncd->
l2_p[lay];
634 atm_airs.
t[atm_airs.
np] = ncd->
l2_t[track][xtrack][lay];
635 if ((++atm_airs.
np) >
NP)
636 ERRMSG(
"Too many layers!");
640 if (atm_airs.
np <= 0)
644 for (
int ip = 0; ip < atm_airs.
np; ip++) {
645 zmax = GSL_MAX(zmax, atm_airs.
z[ip]);
646 zmin = GSL_MIN(zmin, atm_airs.
z[ip]);
650 for (
int ip = 0; ip < atm->
np; ip++) {
653 intpol_atm(ctl, &atm_airs, atm->
z[ip], &p, &t, q, k);
657 if (atm->
z[ip] > zmax)
658 w = GSL_MAX(1 - (atm->
z[ip] - zmax) / 50, 0);
659 if (atm->
z[ip] < zmin)
660 w = GSL_MAX(1 - (zmin - atm->
z[ip]) / 50, 0);
663 atm->
t[ip] = w * t + (1 - w) * atm->
t[ip];
664 atm->
p[ip] = w * p + (1 - w) * atm->
p[ip];
676 const size_t n = a->size1;
679 for (
size_t i = 0; i < n && diag; i++)
680 for (
size_t j = i + 1; j < n; j++)
681 if (gsl_matrix_get(a, i, j) != 0) {
688 for (
size_t i = 0; i < n; i++)
689 gsl_matrix_set(a, i, i, 1 / gsl_matrix_get(a, i, i));
693 gsl_linalg_cholesky_decomp(a);
694 gsl_linalg_cholesky_invert(a);
707 const size_t m = a->size1;
708 const size_t n = a->size2;
711 gsl_matrix *aux = gsl_matrix_alloc(m, n);
714 if (transpose == 1) {
717 for (
size_t i = 0; i < m; i++)
718 for (
size_t j = 0; j < n; j++)
719 gsl_matrix_set(aux, i, j,
720 gsl_vector_get(b, i) * gsl_matrix_get(a, i, j));
723 gsl_blas_dgemm(CblasTrans, CblasNoTrans, 1.0, aux, aux, 0.0, c);
727 else if (transpose == 2) {
730 for (
size_t i = 0; i < m; i++)
731 for (
size_t j = 0; j < n; j++)
732 gsl_matrix_set(aux, i, j,
733 gsl_matrix_get(a, i, j) * gsl_vector_get(b, j));
736 gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, aux, aux, 0.0, c);
740 gsl_matrix_free(aux);
754 static int ipa[
N], iqa[
N];
756 double disq = 0, lmpar = 0.001;
763 const size_t m =
obs2y(ctl, obs_meas, NULL, NULL, NULL);
764 const size_t n =
atm2x(ctl, atm_apr, NULL, iqa, ipa);
765 if (m == 0 || n == 0) {
771 gsl_matrix *a = gsl_matrix_alloc(n, n);
772 gsl_matrix *cov = gsl_matrix_alloc(n, n);
773 gsl_matrix *k_i = gsl_matrix_alloc(m, n);
774 gsl_matrix *s_a_inv = gsl_matrix_alloc(n, n);
776 gsl_vector *b = gsl_vector_alloc(n);
777 gsl_vector *dx = gsl_vector_alloc(n);
778 gsl_vector *dy = gsl_vector_alloc(m);
779 gsl_vector *sig_eps_inv = gsl_vector_alloc(m);
780 gsl_vector *sig_formod = gsl_vector_alloc(m);
781 gsl_vector *sig_noise = gsl_vector_alloc(m);
782 gsl_vector *x_a = gsl_vector_alloc(n);
783 gsl_vector *x_i = gsl_vector_alloc(n);
784 gsl_vector *x_step = gsl_vector_alloc(n);
785 gsl_vector *y_aux = gsl_vector_alloc(m);
786 gsl_vector *y_i = gsl_vector_alloc(m);
787 gsl_vector *y_m = gsl_vector_alloc(m);
792 formod(ctl, atm_i, obs_i);
795 atm2x(ctl, atm_apr, x_a, NULL, NULL);
796 atm2x(ctl, atm_i, x_i, NULL, NULL);
797 obs2y(ctl, obs_meas, y_m, NULL, NULL);
798 obs2y(ctl, obs_i, y_i, NULL, NULL);
805 set_cov_meas(ret, ctl, obs_meas, sig_noise, sig_formod, sig_eps_inv);
808 gsl_vector_memcpy(dx, x_i);
809 gsl_vector_sub(dx, x_a);
810 gsl_vector_memcpy(dy, y_m);
811 gsl_vector_sub(dy, y_i);
817 kernel(ctl, atm_i, obs_i, k_i);
824 for (
int it = 1; it <= ret->
conv_itmax; it++) {
827 double chisq_old = *chisq;
831 kernel(ctl, atm_i, obs_i, k_i);
838 for (
size_t i = 0; i < m; i++)
839 gsl_vector_set(y_aux, i, gsl_vector_get(dy, i)
840 * gsl_pow_2(gsl_vector_get(sig_eps_inv, i)));
841 gsl_blas_dgemv(CblasTrans, 1.0, k_i, y_aux, 0.0, b);
842 gsl_blas_dgemv(CblasNoTrans, -1.0, s_a_inv, dx, 1.0, b);
845 for (
int it2 = 0; it2 < 20; it2++) {
848 gsl_matrix_memcpy(a, s_a_inv);
849 gsl_matrix_scale(a, 1 + lmpar);
850 gsl_matrix_add(a, cov);
853 gsl_linalg_cholesky_decomp(a);
854 gsl_linalg_cholesky_solve(a, b, x_step);
857 gsl_vector_add(x_i, x_step);
860 x2atm(ctl, x_i, atm_i);
863 for (
int ip = 0; ip < atm_i->
np; ip++) {
864 atm_i->
p[ip] = GSL_MIN(GSL_MAX(atm_i->
p[ip], 5e-7), 5e4);
865 atm_i->
t[ip] = GSL_MIN(GSL_MAX(atm_i->
t[ip], 100), 400);
866 for (
int ig = 0; ig < ctl->
ng; ig++)
867 atm_i->
q[ig][ip] = GSL_MIN(GSL_MAX(atm_i->
q[ig][ip], 0), 1);
868 for (
int iw = 0; iw < ctl->
nw; iw++)
869 atm_i->
k[iw][ip] = GSL_MAX(atm_i->
k[iw][ip], 0);
873 formod(ctl, atm_i, obs_i);
874 obs2y(ctl, obs_i, y_i, NULL, NULL);
877 gsl_vector_memcpy(dx, x_i);
878 gsl_vector_sub(dx, x_a);
879 gsl_vector_memcpy(dy, y_m);
880 gsl_vector_sub(dy, y_i);
886 if (*chisq > chisq_old) {
888 gsl_vector_sub(x_i, x_step);
896 gsl_blas_ddot(x_step, b, &disq);
909 gsl_matrix_free(cov);
910 gsl_matrix_free(k_i);
911 gsl_matrix_free(s_a_inv);
916 gsl_vector_free(sig_eps_inv);
917 gsl_vector_free(sig_formod);
918 gsl_vector_free(sig_noise);
919 gsl_vector_free(x_a);
920 gsl_vector_free(x_i);
921 gsl_vector_free(x_step);
922 gsl_vector_free(y_aux);
923 gsl_vector_free(y_i);
924 gsl_vector_free(y_m);
936 printf(
"Read netCDF file: %s\n", filename);
937 NC(nc_open(filename, NC_WRITE, &ncd->
ncid));
940 NC(nc_inq_varid(ncd->
ncid,
"l1_time", &varid));
942 NC(nc_inq_varid(ncd->
ncid,
"l1_lon", &varid));
943 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l1_lon[0]));
944 NC(nc_inq_varid(ncd->
ncid,
"l1_lat", &varid));
945 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l1_lat[0]));
946 NC(nc_inq_varid(ncd->
ncid,
"l1_sat_z", &varid));
948 NC(nc_inq_varid(ncd->
ncid,
"l1_sat_lon", &varid));
950 NC(nc_inq_varid(ncd->
ncid,
"l1_sat_lat", &varid));
952 NC(nc_inq_varid(ncd->
ncid,
"l1_nu", &varid));
953 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l1_nu));
954 NC(nc_inq_varid(ncd->
ncid,
"l1_rad", &varid));
955 NC(nc_get_var_float(ncd->
ncid, varid, ncd->
l1_rad[0][0]));
958 NC(nc_inq_varid(ncd->
ncid,
"l2_z", &varid));
959 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l2_z[0][0]));
960 NC(nc_inq_varid(ncd->
ncid,
"l2_press", &varid));
961 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l2_p));
962 NC(nc_inq_varid(ncd->
ncid,
"l2_temp", &varid));
963 NC(nc_get_var_double(ncd->
ncid, varid, ncd->
l2_t[0][0]));
976 (int)
scan_ctl(argc, argv,
"KERNEL_RECOMP", -1,
"3", NULL);
980 for (
int id = 0;
id < ctl->
nd;
id++)
983 for (
int id = 0;
id < ctl->
nd;
id++)
994 for (
int ig = 0; ig < ctl->
ng; ig++) {
995 ret->
err_q[ig] =
scan_ctl(argc, argv,
"ERR_Q", ig,
"0", NULL);
1000 for (
int iw = 0; iw < ctl->
nw; iw++) {
1001 ret->
err_k[iw] =
scan_ctl(argc, argv,
"ERR_K", iw,
"0", NULL);
1018 const size_t n = s_a->size1;
1021 gsl_vector *x_a = gsl_vector_alloc(n);
1024 atm2x(ctl, atm, x_a, NULL, NULL);
1025 for (
size_t i = 0; i < n; i++) {
1027 gsl_vector_set(x_a, i, ret->
err_press / 100 * gsl_vector_get(x_a, i));
1029 gsl_vector_set(x_a, i, ret->
err_temp);
1030 for (
int ig = 0; ig < ctl->
ng; ig++)
1031 if (iqa[i] ==
IDXQ(ig))
1032 gsl_vector_set(x_a, i, ret->
err_q[ig] / 100 * gsl_vector_get(x_a, i));
1033 for (
int iw = 0; iw < ctl->
nw; iw++)
1034 if (iqa[i] ==
IDXK(iw))
1035 gsl_vector_set(x_a, i, ret->
err_k[iw]);
1039 for (
size_t i = 0; i < n; i++)
1040 if (gsl_pow_2(gsl_vector_get(x_a, i)) <= 0)
1041 ERRMSG(
"Check a priori data (zero standard deviation)!");
1044 gsl_matrix_set_zero(s_a);
1045 for (
size_t i = 0; i < n; i++)
1046 gsl_matrix_set(s_a, i, i, gsl_pow_2(gsl_vector_get(x_a, i)));
1049 for (
size_t i = 0; i < n; i++)
1050 for (
size_t j = 0; j < n; j++)
1051 if (i != j && iqa[i] == iqa[j]) {
1054 double cz = 0, ch = 0;
1057 if (iqa[i] ==
IDXP) {
1063 if (iqa[i] ==
IDXT) {
1069 for (
int ig = 0; ig < ctl->
ng; ig++)
1070 if (iqa[i] ==
IDXQ(ig)) {
1076 for (
int iw = 0; iw < ctl->
nw; iw++)
1077 if (iqa[i] ==
IDXK(iw)) {
1083 if (cz > 0 && ch > 0) {
1086 double x0[3], x1[3];
1092 exp(-
DIST(x0, x1) / ch -
1093 fabs(atm->
z[ipa[i]] - atm->
z[ipa[j]]) / cz);
1096 gsl_matrix_set(s_a, i, j, gsl_vector_get(x_a, i)
1097 * gsl_vector_get(x_a, j) * rho);
1102 gsl_vector_free(x_a);
1111 gsl_vector *sig_noise,
1112 gsl_vector *sig_formod,
1113 gsl_vector *sig_eps_inv) {
1115 static obs_t obs_err;
1118 const size_t m = sig_eps_inv->size;
1122 for (
int ir = 0; ir < obs_err.
nr; ir++)
1123 for (
int id = 0;
id < ctl->
nd;
id++)
1125 = (gsl_finite(obs->
rad[
id][ir]) ? ret->
err_noise[
id] : GSL_NAN);
1126 obs2y(ctl, &obs_err, sig_noise, NULL, NULL);
1130 for (
int ir = 0; ir < obs_err.
nr; ir++)
1131 for (
int id = 0;
id < ctl->
nd;
id++)
1134 obs2y(ctl, &obs_err, sig_formod, NULL, NULL);
1137 for (
size_t i = 0; i < m; i++)
1138 gsl_vector_set(sig_eps_inv, i,
1139 1 / sqrt(gsl_pow_2(gsl_vector_get(sig_noise, i))
1140 + gsl_pow_2(gsl_vector_get(sig_formod, i))));
1143 for (
size_t i = 0; i < m; i++)
1144 if (gsl_vector_get(sig_eps_inv, i) <= 0)
1145 ERRMSG(
"Check measurement errors (zero standard deviation)!");
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read forward model control parameters.
void x2atm(const ctl_t *ctl, const gsl_vector *x, atm_t *atm)
Decompose parameter vector or state vector.
void intpol_atm(const ctl_t *ctl, const atm_t *atm, const double z, double *p, double *t, double *q, double *k)
Interpolate atmospheric data.
double sza(const double sec, const double lon, const double lat)
Calculate solar zenith angle.
void formod(const ctl_t *ctl, atm_t *atm, obs_t *obs)
Determine ray paths and compute radiative transfer.
void copy_obs(const ctl_t *ctl, obs_t *obs_dest, const obs_t *obs_src, const int init)
Copy and initialize observation data.
double scan_ctl(int argc, char *argv[], const char *varname, int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
void copy_atm(const ctl_t *ctl, atm_t *atm_dest, const atm_t *atm_src, const int init)
Copy and initialize atmospheric data.
size_t obs2y(const ctl_t *ctl, const obs_t *obs, gsl_vector *y, int *ida, int *ira)
Compose measurement vector.
size_t atm2x(const ctl_t *ctl, const atm_t *atm, gsl_vector *x, int *iqa, int *ipa)
Compose state vector or parameter vector.
void climatology(const ctl_t *ctl, atm_t *atm)
Interpolate climatological data.
void geo2cart(const double z, const double lon, const double lat, double *x)
Convert geolocation to Cartesian coordinates.
void kernel(ctl_t *ctl, atm_t *atm, obs_t *obs, gsl_matrix *k)
Compute Jacobians.
JURASSIC library declarations.
#define N
Maximum size of state vector.
#define LEN
Maximum length of ASCII data lines.
#define BRIGHT(rad, nu)
Compute brightness temperature.
#define ERRMSG(...)
Print error message and quit program.
#define IDXK(iw)
Indices for extinction.
#define ND
Maximum number of radiance channels.
#define TIMER(name, mode)
Start or stop a timer.
#define IDXP
Index for pressure.
#define NP
Maximum number of atmospheric data points.
#define NG
Maximum number of emitters.
#define DIST(a, b)
Compute Cartesian distance between two vectors.
#define IDXQ(ig)
Indices for volume mixing ratios.
#define NW
Maximum number of spectral windows.
#define IDXT
Index for temperature.
void matrix_product(gsl_matrix *a, gsl_vector *b, int transpose, gsl_matrix *c)
Compute matrix product A^TBA or ABA^T for diagonal matrix B.
int main(int argc, char *argv[])
#define NC(cmd)
Execute netCDF library command and check result.
void set_cov_apr(ret_t *ret, ctl_t *ctl, atm_t *atm, int *iqa, int *ipa, gsl_matrix *s_a)
Set a priori covariance.
void optimal_estimation(ret_t *ret, ctl_t *ctl, obs_t *obs_meas, obs_t *obs_i, atm_t *atm_apr, atm_t *atm_i, double *chisq)
Carry out optimal estimation retrieval.
void fill_gaps(double x[L2_NTRACK][L2_NXTRACK][L2_NLAY], double cx, double cy)
Fill data gaps in L2 data.
#define L1_NXTRACK
Across-track size of AIRS radiance granule (don't change).
#define L1_NTRACK
Along-track size of AIRS radiance granule (don't change).
#define L2_NXTRACK
Across-track size of AIRS retrieval granule (don't change).
void read_nc(char *filename, ncd_t *ncd)
Read netCDF file.
void add_var(int ncid, const char *varname, const char *unit, const char *longname, int type, int dimid[], int *varid, int ndims)
Create variable in netCDF file.
#define L2_NLAY
Number of AIRS pressure layers (don't change).
void set_cov_meas(ret_t *ret, ctl_t *ctl, obs_t *obs, gsl_vector *sig_noise, gsl_vector *sig_formod, gsl_vector *sig_eps_inv)
Set measurement errors.
void read_ret_ctl(int argc, char *argv[], ctl_t *ctl, ret_t *ret)
Read retrieval control parameters.
void matrix_invert(gsl_matrix *a)
Invert symmetric matrix.
#define L1_NCHAN
Number of AIRS radiance channels (don't change).
#define L2_NTRACK
Along-track size of AIRS retrieval granule (don't change).
double cost_function(gsl_vector *dx, gsl_vector *dy, gsl_matrix *s_a_inv, gsl_vector *sig_eps_inv)
Compute cost function.
void init_l2(ncd_t *ncd, int track, int xtrack, ctl_t *ctl, atm_t *atm)
Initialize with AIRS Level-2 data.
double time[NP]
Time (seconds since 2000-01-01T00:00Z).
double k[NW][NP]
Extinction [km^-1].
double lat[NP]
Latitude [deg].
double lon[NP]
Longitude [deg].
double t[NP]
Temperature [K].
int np
Number of data points.
double z[NP]
Altitude [km].
double q[NG][NP]
Volume mixing ratio [ppv].
double p[NP]
Pressure [hPa].
Forward model control parameters.
int nw
Number of spectral windows.
double nu[ND]
Centroid wavenumber of each channel [cm^-1].
int ng
Number of emitters.
int nd
Number of radiance channels.
double l1_lat[L1_NTRACK][L1_NXTRACK]
Footprint latitude [deg].
double l1_lon[L1_NTRACK][L1_NXTRACK]
Footprint longitude [deg].
double l2_z[L2_NTRACK][L2_NXTRACK][L2_NLAY]
Altitude [km].
double l1_sat_lat[L1_NTRACK]
Satellite latitude [deg].
double l1_sat_lon[L1_NTRACK]
Satellite longitude [deg].
double l2_p[L2_NLAY]
Pressure [hPa].
double l2_t[L2_NTRACK][L2_NXTRACK][L2_NLAY]
Temperature [K].
double l1_nu[L1_NCHAN]
Channel frequencies [cm^-1].
double l1_sat_z[L1_NTRACK]
Satellite altitude [km].
float l1_rad[L1_NTRACK][L1_NXTRACK][L1_NCHAN]
Radiance [W/(m^2 sr cm^-1)].
double l1_time[L1_NTRACK][L1_NXTRACK]
Time (seconds since 2000-01-01T00:00Z).
Observation geometry and radiance data.
double rad[ND][NR]
Radiance [W/(m^2 sr cm^-1)].
double vplat[NR]
View point latitude [deg].
double obslon[NR]
Observer longitude [deg].
double obslat[NR]
Observer latitude [deg].
double obsz[NR]
Observer altitude [km].
double vplon[NR]
View point longitude [deg].
double time[NR]
Time (seconds since 2000-01-01T00:00Z).
int nr
Number of ray paths.
double err_k_ch[NW]
Horizontal correlation length for extinction error [km].
double err_press_cz
Vertical correlation length for pressure error [km].
double err_k_cz[NW]
Vertical correlation length for extinction error [km].
double err_press
Pressure error [%].
double err_q_ch[NG]
Horizontal correlation length for volume mixing ratio error [km].
double err_noise[ND]
Noise error [W/(m^2 sr cm^-1)].
double err_formod[ND]
Forward model error [%].
double err_q_cz[NG]
Vertical correlation length for volume mixing ratio error [km].
double err_temp_cz
Vertical correlation length for temperature error [km].
double conv_dmin
Minimum normalized step size in state space.
double err_temp
Temperature error [K].
double err_temp_ch
Horizontal correlation length for temperature error [km].
int kernel_recomp
Recomputation of kernel matrix (number of iterations).
int conv_itmax
Maximum number of iterations.
double err_press_ch
Horizontal correlation length for pressure error [km].
double err_q[NG]
Volume mixing ratio error [%].
double err_k[NW]
Extinction error [1/km].
Emissivity look-up tables.