142#include <gsl/gsl_math.h>
143#include <gsl/gsl_blas.h>
144#include <gsl/gsl_linalg.h>
145#include <gsl/gsl_randist.h>
146#include <gsl/gsl_rng.h>
147#include <gsl/gsl_statistics.h>
172#define C1 1.19104259e-8
202#define KB 1.3806504e-23
212#define NA 6.02214199e23
276#define KERNEL_P_REL 0.01
281#define KERNEL_P_MIN 1e-7
286#define KERNEL_T_ABS 1.0
291#define KERNEL_Q_REL 0.01
296#define KERNEL_Q_MIN 1e-15
301#define KERNEL_K_ABS 1e-4
305#ifndef KERNEL_CLZ_ABS
306#define KERNEL_CLZ_ABS 0.1
310#ifndef KERNEL_CLDZ_ABS
311#define KERNEL_CLDZ_ABS 0.1
315#ifndef KERNEL_CLK_ABS
316#define KERNEL_CLK_ABS 1e-4
320#ifndef KERNEL_SFT_ABS
321#define KERNEL_SFT_ABS 1.0
325#ifndef KERNEL_SFEPS_ABS
326#define KERNEL_SFEPS_ABS 1e-2
345#define N ((2 + NG + NW) * NP + NCL + NSF + 3)
397#define NQ (5 + NG + NW + NCL + NSF)
427#define RFMNPTS 10000000
461#define IDXQ(ig) (2 + (ig))
464#define IDXK(iw) (2 + (ctl->ng) + (iw))
467#define IDXCLZ (2 + (ctl->ng) + (ctl->nw))
470#define IDXCLDZ (3 + (ctl->ng) + (ctl->nw))
473#define IDXCLK(icl) (4 + (ctl->ng) + (ctl->nw) + (icl))
476#define IDXSFT (4 + (ctl->ng) + (ctl->nw) + (ctl->ncl))
479#define IDXSFEPS(isf) (5 + (ctl->ng) + (ctl->nw) + (ctl->ncl) + (isf))
502#define ALLOC(ptr, type, n) \
503 if((ptr=calloc((size_t)(n), sizeof(type)))==NULL) \
504 ERRMSG("Out of memory!");
532#define BRIGHT(rad, nu) \
533 (C2 * (nu) / gsl_log1p(C1 * POW3(nu) / (rad)))
554#define CLAMP(v, lo, hi) \
555 (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v)))
569#define CO2_FIT(TIME) \
570 (373.87884731310215e-6 \
571 + 1.9021498612395775e-6 * (((TIME) - 94694400.) / 31557600.) \
572 + 0.016490044598136553e-6 \
573 * POW2((((TIME) - 94694400.) / 31557600.)))
589#define DEG2RAD(deg) ((deg) * (M_PI / 180.0))
607#define DIST(a, b) sqrt(DIST2(a, b))
625 ((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])+(a[2]-b[2])*(a[2]-b[2]))
642#define DOTP(a, b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
660 ((x) - (int) ((x) / (y)) * (y))
680#define FREAD(ptr, type, size, out) { \
681 if(fread(ptr, sizeof(type), size, out)!=size) \
682 ERRMSG("Error while reading!"); \
703#define FWRITE(ptr, type, size, out) { \
704 if(fwrite(ptr, sizeof(type), size, out)!=size) \
705 ERRMSG("Error while writing!"); \
726#define LIN(x0, y0, x1, y1, x) \
727 ((y0)+((y1)-(y0))/((x1)-(x0))*((x)-(x0)))
747#define LOGY(x0, y0, x1, y1, x) \
749 ? ((y0)*exp(log((y1)/(y0))/((x1)-(x0))*((x)-(x0)))) \
750 : LIN(x0, y0, x1, y1, x))
768#define MAX(a,b) (((a)>(b))?(a):(b))
786#define MIN(a,b) (((a)<(b))?(a):(b))
800 int nc_result=(cmd); \
801 if(nc_result!=NC_NOERR) \
802 ERRMSG("%s", nc_strerror(nc_result)); \
829#define NC_DEF_VAR(varname, type, ndims, dims, long_name, units, level, quant) { \
830 NC(nc_def_var(ncid, varname, type, ndims, dims, &varid)); \
831 NC(nc_put_att_text(ncid, varid, "long_name", strnlen(long_name, LEN), long_name)); \
832 NC(nc_put_att_text(ncid, varid, "units", strnlen(units, LEN), units)); \
833 NC_DEF_VAR_QUANTIZE(quant); \
835 NC(nc_def_var_deflate(ncid, varid, 1, 1, level)); \
852#ifdef NC_QUANTIZE_GRANULARBR
853#define NC_DEF_VAR_QUANTIZE(quant) do { \
855 NC(nc_def_var_quantize(ncid, varid, NC_QUANTIZE_GRANULARBR, quant)); \
858#define NC_DEF_VAR_QUANTIZE(quant) do { \
860 ERRMSG("NetCDF quantization is not supported by this NetCDF version"); \
881#define NC_GET_DOUBLE(varname, ptr, force) { \
883 NC(nc_inq_varid(ncid, varname, &varid)); \
884 NC(nc_get_var_double(ncid, varid, ptr)); \
886 if(nc_inq_varid(ncid, varname, &varid) == NC_NOERR) { \
887 NC(nc_get_var_double(ncid, varid, ptr)); \
889 WARN("netCDF variable %s is missing!", varname); \
910#define NC_INQ_DIM(dimname, ptr, min, max, check) { \
911 int dimid; size_t naux; \
912 NC(nc_inq_dimid(ncid, dimname, &dimid)); \
913 NC(nc_inq_dimlen(ncid, dimid, &naux)); \
916 if ((*ptr) < (min) || (*ptr) > (max)) \
917 ERRMSG("Dimension %s is out of range!", dimname); \
934#define NC_PUT_DOUBLE(varname, ptr, hyperslab) { \
935 NC(nc_inq_varid(ncid, varname, &varid)); \
937 NC(nc_put_vara_double(ncid, varid, start, count, ptr)); \
939 NC(nc_put_var_double(ncid, varid, ptr)); \
958#define NC_PUT_FLOAT(varname, ptr, hyperslab) { \
959 NC(nc_inq_varid(ncid, varname, &varid)); \
961 NC(nc_put_vara_float(ncid, varid, start, count, ptr)); \
963 NC(nc_put_var_float(ncid, varid, ptr)); \
981#define NC_PUT_INT(varname, ptr, hyperslab) { \
982 NC(nc_inq_varid(ncid, varname, &varid)); \
984 NC(nc_put_vara_int(ncid, varid, start, count, ptr)); \
986 NC(nc_put_var_int(ncid, varid, ptr)); \
1003#define NC_PUT_ATT(varname, attname, text) { \
1004 NC(nc_inq_varid(ncid, varname, &varid)); \
1005 NC(nc_put_att_text(ncid, varid, attname, strnlen(text, LEN), text)); \
1020#define NC_PUT_ATT_GLOBAL(attname, text) \
1021 NC(nc_put_att_text(ncid, NC_GLOBAL, attname, strnlen(text, LEN), text));
1052#define NEDT(t_bg, nesr, nu) \
1053 (BRIGHT(PLANCK((t_bg), (nu)) + (nesr), (nu)) - (t_bg))
1081#define NESR(t_bg, nedt, nu) \
1082 (PLANCK((t_bg) + (nedt), (nu)) - PLANCK((t_bg), (nu)))
1098#define NORM(a) sqrt(DOTP(a, a))
1129#define PLANCK(T, nu) \
1130 (C1 * POW3(nu) / gsl_expm1(C2 * (nu) / (T)))
1143#define POW2(x) ((x)*(x))
1156#define POW3(x) ((x)*(x)*(x))
1172#define RAD2DEG(rad) ((rad) * (180.0 / M_PI))
1202#define REFRAC_SW53(p, T, h2o) \
1203 (1e-6 * (77.6 * (p) / (T) + 3.73e5 * (h2o) * (p) / ((T) * (T))))
1229#define REFRAC_EDLEN(p, T) \
1231 * (8342.54 + 2406147.0 / (130.0 - 1.0 / (10.0 * 10.0)) \
1232 + 15998.0 / (38.9 - 1.0 / (10.0 * 10.0)))) \
1233 * ((p) / 1013.25) * (288.15 / (T)))
1249#define TBL_LOG(tbl, id, ig) \
1251 for (int ip = 0; ip < (tbl)->np[(id)][(ig)]; ip++) \
1253 "p[%2d]= %.5e hPa | T[0:%2d]= %.2f ... %.2f K | " \
1254 "u[0:%3d]= %.5e ... %.5e molec/cm^2 | " \
1255 "eps[0:%3d]= %.5e ... %.5e", \
1257 (tbl)->p[(id)][(ig)][(ip)], \
1258 (tbl)->nt[(id)][(ig)][(ip)] - 1, \
1259 (tbl)->t[(id)][(ig)][(ip)][0], \
1260 (tbl)->t[(id)][(ig)][(ip)] \
1261 [(tbl)->nt[(id)][(ig)][(ip)] - 1], \
1262 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1263 exp((tbl)->logu[(id)][(ig)][(ip)][0][0]), \
1264 exp((tbl)->logu[(id)][(ig)][(ip)][0] \
1265 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1]), \
1266 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1267 exp((tbl)->logeps[(id)][(ig)][(ip)][0][0]), \
1268 exp((tbl)->logeps[(id)][(ig)][(ip)][0] \
1269 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1])); \
1283#define SELECT_TIMER(id, group) \
1284 {timer_group(id, group, 0);}
1293#define PRINT_TIMERS \
1294 {timer_group("END", "END", 1);}
1314#define TOK(line, tok, format, var) { \
1315 if(((tok)=strtok((line), " \t"))) { \
1316 if(sscanf(tok, format, &(var))!=1) continue; \
1317 } else ERRMSG("Error while reading!"); \
1334 for (iusage = 1; iusage < argc; iusage++) \
1335 if (!strcmp(argv[iusage], "-h") \
1336 || !strcmp(argv[iusage], "--help")) { \
1338 return EXIT_SUCCESS; \
1380#define LOG(level, ...) { \
1383 if(level <= LOGLEV) { \
1384 printf(__VA_ARGS__); \
1417#define WARN(...) { \
1418 printf("\nWarning (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1419 LOG(0, __VA_ARGS__); \
1450#define ERRMSG(...) { \
1451 printf("\nError (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1452 LOG(0, __VA_ARGS__); \
1453 exit(EXIT_FAILURE); \
1485#define PRINT(format, var) \
1486 printf("Print (%s, %s, l%d): %s= "format"\n", \
1487 __FILE__, __func__, __LINE__, #var, var);
1960 char shared_io_atm_apr_file[
LEN];
1963 char shared_io_obs_meas_file[
LEN];
1966 char shared_io_atm_final_file[
LEN];
1969 char shared_io_obs_final_file[
LEN];
1972 char shared_io_matrix_cov_apr_file[
LEN];
1975 char shared_io_matrix_kernel_file[
LEN];
1978 char shared_io_matrix_cov_ret_file[
LEN];
1981 char shared_io_matrix_corr_file[
LEN];
1984 char shared_io_matrix_gain_file[
LEN];
1987 char shared_io_matrix_avk_file[
LEN];
1990 char shared_io_atm_err_total_file[
LEN];
1993 char shared_io_atm_err_noise_file[
LEN];
1996 char shared_io_atm_err_formod_file[
LEN];
1999 char shared_io_atm_cont_file[
LEN];
2002 char shared_io_atm_res_file[
LEN];
2116 const gsl_matrix * avk);
2174 const gsl_matrix * avk,
2238 const int value_iqa,
2317 const char *filename,
2318 const char *varname,
2320 const int dim_month,
2364 const int top_policy,
2486 const gsl_vector * dx,
2487 const gsl_vector * dy,
2488 const gsl_matrix * s_a_inv,
2489 const gsl_vector * sig_eps_inv);
2627 const atm_t * atm_src,
2657 const obs_t * obs_src,
2735 const char *emitter);
2777 los_t * los_scratch,
2778 obs_t * obs_scratch);
2806 los_t * los_scratch,
2807 obs_t * obs_scratch);
2866 obs_t * obs_scratch);
3190 double tau_path[
ND][
NG],
3191 double tau_seg[
ND]);
3236 double tau_path[
ND][
NG],
3237 double tau_seg[
ND]);
3309 const double logeps);
3578 const gsl_matrix * a,
3579 const gsl_vector * b,
3580 const int transpose,
3781 const char *dirname,
3782 const char *filename,
3834 const char *filename,
3888 const char *filename,
3934 const char *filename,
4003 const char *dirname,
4004 const char *filename,
4006 gsl_matrix * matrix,
4041 const char *dirname,
4042 const char *filename,
4043 gsl_matrix * matrix);
4063 const char *dirname,
4064 const char *filename,
4065 gsl_matrix * matrix);
4089 const char *dirname,
4090 const char *filename,
4091 gsl_matrix * matrix,
4131 const char *dirname,
4132 const char *filename,
4175 const char *filename,
4221 const char *filename,
4258 const char *filename,
4303 const char *basename,
4431 const char *filename,
4470 const char *filename,
4697 const char *varname,
4699 const char *defvalue,
4820 gsl_vector * sig_noise,
4821 gsl_vector * sig_formod,
4822 gsl_vector * sig_eps_inv);
4852 const char *shared_file,
4853 const char *legacy_file,
4854 const char **dirname,
4885 const char *shared_file,
4886 const char *legacy_file,
4887 const char **dirname,
5067 size_t *bytes_used);
5126 const uint8_t * buf);
5160 const double remain,
5231 const char *dirname,
5232 const char *filename,
5289 const char *filename,
5347 const char *filename,
5399 const char *filename,
5456 const char *filename,
5484 const char *dirname,
5485 const char *filename,
5487 const gsl_matrix * matrix,
5490 const char *rowspace,
5491 const char *colspace,
5543 const char *dirname,
5544 const char *filename,
5546 const gsl_matrix * matrix,
5549 const char *rowspace,
5550 const char *colspace,
5568 const char *dirname,
5569 const char *filename,
5570 const gsl_matrix * matrix);
5599 const char *dirname,
5600 const char *filename,
5602 const gsl_matrix * matrix,
5605 const char *rowspace,
5606 const char *colspace,
5646 const char *dirname,
5647 const char *filename,
5691 const char *filename,
5733 const char *filename,
5775 const char *filename,
5815 const char *filename,
5866 const char *quantity,
5870 const gsl_matrix * s);
6061 const gsl_vector * x,
6094 const gsl_vector * x,
6131 const gsl_vector * y,
double intpol_tbl_eps(const tbl_t *tbl, const int ig, const int id, const int ip, const int it, const double logu)
Interpolate gas emissivity as a function of column amount.
void analyze_avk(const ret_t *ret, const ctl_t *ctl, const atm_t *atm, const int *iqa, const int *ipa, const gsl_matrix *avk)
Analyze averaging kernel (AVK) matrix for retrieval diagnostics.
void read_tbl_bin(const ctl_t *ctl, tbl_t *tbl, const int id, const int ig)
Read a single compact binary emissivity lookup table.
#define LEN
Maximum length of ASCII data lines.
@ FORMOD_STATUS_TOO_MANY_LOS_POINTS
@ FORMOD_STATUS_FOV_DATA_MISSING
@ FORMOD_STATUS_RFM_UNSUPPORTED
@ FORMOD_STATUS_OBSERVER_BELOW_SURFACE
double cost_function(const gsl_vector *dx, const gsl_vector *dy, const gsl_matrix *s_a_inv, const gsl_vector *sig_eps_inv)
Compute the normalized quadratic cost function for optimal estimation.
double read_obs_rfm(const char *basename, const double z, const double *nu, const double *f, const int n)
Read and spectrally convolve an RFM output spectrum.
void write_atm(const char *dirname, const char *filename, const ctl_t *ctl, const atm_t *atm, int profile)
Write atmospheric data to a file.
void read_rfm_spec(const char *filename, double *nu, double *rad, int *npts)
Read a Reference Forward Model (RFM) ASCII spectrum.
void tbl_pack(const tbl_t *tbl, int id, int ig, uint8_t *buf, size_t *bytes_used)
Pack a lookup table into a contiguous binary buffer.
void read_matrix_nc(const char *dirname, const char *filename, gsl_matrix *matrix, int dataset)
Read a numerical matrix from a netCDF file.
double cos_sza(const double sec, const double lon, const double lat)
Calculates the cosine of the solar zenith angle.
int raytrace(const ctl_t *ctl, const atm_t *atm, obs_t *obs, los_t *los, const int ir)
Perform line-of-sight (LOS) ray tracing through the atmosphere.
void read_atm_bin(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in binary format.
void write_obs_asc(const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data to an ASCII text file.
void formod_rfm(const ctl_t *ctl, const tbl_t *tbl, const atm_t *atm, obs_t *obs)
Forward-model radiance and transmittance with the Reference Forward Model (RFM).
int locate_reg(const double *xx, const int n, const double x)
Locate index for interpolation on a regular (uniform) grid.
void intpol_tbl_ega(const ctl_t *ctl, const tbl_t *tbl, const los_t *los, const int ip, double tau_path[ND][NG], double tau_seg[ND])
Interpolate emissivities and transmittances using the Emissivity Growth Approximation (EGA).
double ctmo2(const double nu, const double p, const double t)
Compute O₂ collision-induced absorption coefficient.
void write_obs_nc(const char *filename, const ctl_t *ctl, const obs_t *obs, const int profile)
Write one observation profile to a NetCDF file.
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
void write_tbl_asc(const ctl_t *ctl, const tbl_t *tbl, const int id, const int ig)
Write one emissivity lookup table in human-readable ASCII format.
void write_tbl_nc(const ctl_t *ctl, const tbl_t *tbl, const int id, const int ig)
Write one packed lookup table to a NetCDF file.
void idx2name(const ctl_t *ctl, const int idx, char *quantity)
Convert a quantity index to a descriptive name string.
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
void formod_continua(const ctl_t *ctl, const los_t *los, const int ip, double *beta)
Compute total extinction including gaseous continua.
void climatology(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Initializes atmospheric climatology profiles.
void read_obs_bin(const char *filename, const ctl_t *ctl, obs_t *obs)
Read binary-formatted observation data from a file.
int shared_io_lock(const ret_t *ret)
Acquire an exclusive lock for shared retrieval output files.
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs, int profile)
Read observation data from an input file.
void matrix_product(const gsl_matrix *a, const gsl_vector *b, const int transpose, gsl_matrix *c)
Compute structured matrix products of the form or .
int formod_pencil(const ctl_t *ctl, const tbl_t *tbl, const atm_t *atm, obs_t *obs, const int ir, los_t *los)
Compute line-of-sight radiances using the pencil-beam forward model.
void climatology_external(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Overwrites the built-in climatology with a JuMACS climatology.
int locate_irr(const double *xx, const int n, const double x)
Locate index for interpolation on an irregular grid.
const char * shared_io_input_target(const ret_t *ret, const char *shared_file, const char *legacy_file, const char **dirname, int *profile)
Resolve retrieval input target for legacy-directory and shared-file modes.
void write_matrix_asc(const char *dirname, const char *filename, const ctl_t *ctl, const gsl_matrix *matrix, const atm_t *atm, const obs_t *obs, const char *rowspace, const char *colspace, const char *sort)
Write a fully annotated matrix (e.g., Jacobian or gain matrix) to an ASCII file.
void day2doy(int year, int mon, int day, int *doy)
Convert a calendar date to day-of-year.
void write_atm_nc(const char *filename, const ctl_t *ctl, const atm_t *atm, int profile)
Write one atmospheric profile to a netCDF file.
void write_matrix(const char *dirname, const char *filename, const ctl_t *ctl, const gsl_matrix *matrix, const atm_t *atm, const obs_t *obs, const char *rowspace, const char *colspace, const char *sort, int dataset)
Write a fully annotated matrix (e.g., Jacobian or gain matrix) to file.
void time2jsec(const int year, const int mon, const int day, const int hour, const int min, const int sec, const double remain, double *jsec)
Converts time components to seconds since January 1, 2000, 12:00:00 UTC.
void x2atm(const ctl_t *ctl, const gsl_vector *x, atm_t *atm)
Map retrieval state vector back to atmospheric structure.
void atm2x_help(const double value, const int value_iqa, const int value_ip, gsl_vector *x, int *iqa, int *ipa, size_t *n)
Append a single atmospheric value to the state vector.
double ctmh2o(const double nu, const double p, const double t, const double q, const double u)
Compute the MT_CKD 4.1 water vapor continuum (optical depth).
void write_tbl_bin(const ctl_t *ctl, const tbl_t *tbl, const int id, const int ig)
Write one emissivity lookup table in compact binary format.
void intpol_tbl_cga(const ctl_t *ctl, const tbl_t *tbl, const los_t *los, const int ip, double tau_path[ND][NG], double tau_seg[ND])
Interpolate emissivities and transmittances using the Curtis–Godson approximation (CGA).
void shared_io_unlock(int fd)
Release a shared retrieval output lock.
void write_atm_rfm(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric profile in RFM-compatible format.
#define ND
Maximum number of radiance channels.
void set_cov_meas(const ret_t *ret, const ctl_t *ctl, const obs_t *obs, gsl_vector *sig_noise, gsl_vector *sig_formod, gsl_vector *sig_eps_inv)
Construct measurement error standard deviations and their inverse.
void write_obs(const char *dirname, const char *filename, const ctl_t *ctl, const obs_t *obs, int profile)
Write observation data to an output file in ASCII or binary format.
#define NSHAPE
Maximum number of shape function grid points.
void write_tbl(const ctl_t *ctl, const tbl_t *tbl)
Write emissivity lookup tables to disk.
#define CT
Maximum number of time steps for climatological data.
size_t tbl_unpack(tbl_t *tbl, int id, int ig, const uint8_t *buf)
Unpack a lookup table from a contiguous binary buffer.
void read_matrix(const char *dirname, const char *filename, const ctl_t *ctl, gsl_matrix *matrix, int dataset)
Read a numerical matrix from a file.
void intpol_atm(const ctl_t *ctl, const atm_t *atm, const double z, double *p, double *t, double *q, double *k)
Interpolate atmospheric state variables at a given altitude.
int find_emitter(const ctl_t *ctl, const char *emitter)
Find gas species index by name.
void optimal_estimation(ret_t *ret, ctl_t *ctl, tbl_t *tbl, obs_t *obs_meas, obs_t *obs_i, atm_t *atm_apr, atm_t *atm_i, double *chisq)
Perform optimal estimation retrieval using Levenberg–Marquardt minimization.
double intpol_tbl_u(const tbl_t *tbl, const int ig, const int id, const int ip, const int it, const double logeps)
Interpolate column amount as a function of emissivity.
void timer_group(const char *name, const char *group, int output)
Aggregate wall-clock timings for named code phases.
void tangent_point(const los_t *los, double *tpz, double *tplon, double *tplat)
Determine the tangent point along a line of sight (LOS).
double ctmco2(const double nu, const double p, const double t, const double u)
Compute carbon dioxide continuum optical depth.
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read atmospheric input data from a file.
int formod_fov(const ctl_t *ctl, obs_t *obs, obs_t *obs_scratch)
Apply field-of-view (FOV) convolution to modeled radiances.
void write_matrix_nc(const char *dirname, const char *filename, const ctl_t *ctl, const gsl_matrix *matrix, const atm_t *atm, const obs_t *obs, const char *rowspace, const char *colspace, const char *sort, int dataset)
Write a numerical matrix to a netCDF file.
#define CLAT
Maximum number of latitudes for climatological data (JuMACS: 36 area-weighted 5-degree bands).
void write_atm_asc(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric data to an ASCII file.
void write_matrix_bin(const char *dirname, const char *filename, const gsl_matrix *matrix)
Write a numerical matrix to a binary file.
void copy_obs(const ctl_t *ctl, obs_t *obs_dest, const obs_t *obs_src, const int init)
Copy or initialize observation geometry and radiance data.
void formod_batch(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs, const int nbatch, int *status, los_t *los_scratch, obs_t *obs_scratch)
Execute the forward model for a batch of independent cases.
#define TBLNT
Maximum number of temperatures in emissivity tables.
void write_obs_bin(const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data in binary format to a file.
void x2atm_help(double *value, const gsl_vector *x, size_t *n)
Helper function to extract a single value from the retrieval state vector.
void cart2geo(const double *x, double *z, double *lon, double *lat)
Converts Cartesian coordinates to geographic coordinates.
#define NP
Maximum number of atmospheric data points.
void doy2day(int year, int doy, int *mon, int *day)
Convert a day-of-year value to a calendar date.
void kernel(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs, gsl_matrix *k)
Compute the Jacobian (kernel) matrix by finite differences.
void read_obs_nc(const char *filename, const ctl_t *ctl, obs_t *obs, const int profile)
Read one observation profile from a NetCDF file.
void init_srcfunc(const ctl_t *ctl, tbl_t *tbl)
Initialize source function lookup tables from emissivity data.
void matrix_invert(gsl_matrix *a)
Invert a square matrix, optimized for diagonal or symmetric positive-definite matrices.
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scan control file or command-line arguments for a configuration variable.
void write_shape(const char *filename, const double *x, const double *y, const int n)
Write tabulated shape function data to a text file.
void read_atm_asc(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in ASCII format.
#define NG
Maximum number of emitters.
void read_tbl_asc(const ctl_t *ctl, tbl_t *tbl, const int id, const int ig)
Read a single ASCII emissivity lookup table.
void formod_srcfunc(const ctl_t *ctl, const tbl_t *tbl, const double t, double *src)
Interpolate the source function (Planck radiance) at a given temperature.
void analyze_avk_quantity(const gsl_matrix *avk, const int iq, const int *ipa, const size_t *n0, const size_t *n1, double *cont, double *res)
Analyze averaging kernel submatrix for a specific retrieved quantity.
void jsec2time(const double jsec, int *year, int *mon, int *day, int *hour, int *min, int *sec, double *remain)
Converts Julian seconds to calendar date and time components.
#define TBLNS
Maximum number of source function temperature levels.
void read_matrix_asc(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from an ASCII file.
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
void read_matrix_bin(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from a binary file.
void read_tbl_nc_channel(const ctl_t *ctl, tbl_t *tbl, int id, int ig, int ncid)
Read one packed emissivity lookup table from an open NetCDF file.
const char * shared_io_output_target(const ret_t *ret, const char *shared_file, const char *legacy_file, const char **dirname, int *profile)
Resolve retrieval output target for legacy-directory and shared-file modes.
void read_atm_nc(const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read one atmospheric profile from a netCDF file.
void copy_atm(const ctl_t *ctl, atm_t *atm_dest, const atm_t *atm_src, const int init)
Copy or initialize atmospheric profile data.
size_t obs2y(const ctl_t *ctl, const obs_t *obs, gsl_vector *y, int *ida, int *ira)
Convert observation radiances into a measurement vector.
void y2obs(const ctl_t *ctl, const gsl_vector *y, obs_t *obs)
Copy elements from the measurement vector y into the observation structure.
void hydrostatic(const ctl_t *ctl, atm_t *atm)
Adjust pressure profile using the hydrostatic equation.
void read_shape(const char *filename, double *x, double *y, int *n)
Read a two-column shape function from an ASCII file.
double ctmn2(const double nu, const double p, const double t)
Compute N₂ collision-induced absorption coefficient.
void climatology_external_interp(const clim_t *clim, const atm_t *atm, const double field[CT][CZ][CLAT], const int top_policy, double *out)
Interpolates a JuMACS climatology field onto atmospheric profiles.
#define CZ
Maximum number of altitudes for climatological data (JuMACS: 0...150 km at 1 km spacing).
size_t atm2x(const ctl_t *ctl, const atm_t *atm, gsl_vector *x, int *iqa, int *ipa)
Convert atmospheric data to state vector elements.
#define TBLNP
Maximum number of pressure levels in emissivity tables.
void geo2cart(const double z, const double lon, const double lat, double *x)
Converts geographic coordinates (longitude, latitude, altitude) to Cartesian coordinates.
#define NSF
Maximum number of surface layer spectral grid points.
#define NCL
Maximum number of cloud layer spectral grid points.
void set_cov_apr(const ret_t *ret, const ctl_t *ctl, const atm_t *atm, const int *iqa, const int *ipa, gsl_matrix *s_a)
Construct the a priori covariance matrix for retrieval parameters.
const char * shared_io_output_file(const ret_t *ret)
Return the primary shared retrieval output file configured for locking.
void write_stddev(const char *quantity, const ret_t *ret, const ctl_t *ctl, const atm_t *atm, const gsl_matrix *s)
Write retrieval standard deviation profiles to disk.
#define NLOS
Maximum number of LOS points.
int formod(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs, los_t *los_scratch, obs_t *obs_scratch)
Execute one complete forward-model calculation.
size_t tbl_packed_size(const tbl_t *tbl, int id, int ig)
Compute required buffer size (in bytes) for tbl_pack().
clim_t * read_clim(const ctl_t *ctl)
Reads a JuMACS climatology file into an allocated climatology structure.
#define NR
Maximum number of ray paths.
int locate_tbl(const float *xx, const int n, const double x)
Locate index for interpolation within emissivity table grids.
void write_atm_bin(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric data to a binary file.
void read_obs_asc(const char *filename, const ctl_t *ctl, obs_t *obs)
Read ASCII-formatted observation data from a file.
#define NW
Maximum number of spectral windows.
int read_clim_field(const char *filename, const char *varname, const int ncid, const int dim_month, const int dim_alt, const int dim_lat, const int nalt, const int nlat, double field[CT][CZ][CLAT], double *vmin, double *vmax)
Reads and validates one JuMACS climatology field.
Atmospheric profile data.
double clz
Cloud layer height [km].
int np
Number of data points.
double cldz
Cloud layer depth [km].
double sft
Surface temperature [K].
JuMACS climatology on a fixed grid.
int ntime
Number of climatological time coordinates.
int has_t
Set if a temperature field was read.
int nalt
Number of altitude levels.
int nlat
Number of latitude bands.
int write_matrix
Write matrix file (0=no, 1=yes).
int nw
Number of spectral windows.
int atmfmt
Atmospheric data file format (1=ASCII, 2=binary, 3=netCDF).
double retp_zmin
Minimum altitude for pressure retrieval [km].
int ig_co2
Emitter index of CO2.
double hydz
Reference height for hydrostatic pressure profile (-999 to skip) [km].
int ctm_co2
Compute CO2 continuum (0=no, 1=yes).
double rett_zmax
Maximum altitude for temperature retrieval [km].
int ret_sfeps
Retrieve surface layer emissivity (0=no, 1=yes).
int ret_sft
Retrieve surface layer temperature (0=no, 1=yes).
int ret_clz
Retrieve cloud layer height (0=no, 1=yes).
int ctm_n2
Compute N2 continuum (0=no, 1=yes).
int ctm_h2o
Compute H2O continuum (0=no, 1=yes).
int formod
Forward model (0=CGA, 1=EGA, 2=RFM).
int ng
Number of emitters.
int refrac
Take into account refractivity (0=no, 1=yes).
int ig_o2
Emitter index of O2.
double rett_zmin
Minimum altitude for temperature retrieval [km].
double sfsza
Solar zenith angle at the surface [deg] (-999=auto).
int nd
Number of radiance channels.
int fov_n
Field-of-view number of data points.
int sftype
Surface treatment (0=none, 1=emissions, 2=downward, 3=solar).
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
int ncl
Number of cloud layer spectral grid points.
int ig_n2
Emitter index of N2.
int obsfmt
Observation data file format (1=ASCII, 2=binary, 3=netCDF).
int ctm_o2
Compute O2 continuum (0=no, 1=yes).
int ret_clk
Retrieve cloud layer extinction (0=no, 1=yes).
int nsf
Number of surface layer spectral grid points.
double rayds
Maximum step length for raytracing [km].
int ret_cldz
Retrieve cloud layer depth (0=no, 1=yes).
int ig_h2o
Emitter index of H2O.
int tblfmt
Look-up table file format (1=ASCII, 2=binary, 3=netCDF).
double raydz
Vertical step length for raytracing [km].
int write_bbt
Use brightness temperature instead of radiance (0=no, 1=yes).
double retp_zmax
Maximum altitude for pressure retrieval [km].
double sft
Surface temperature [K].
int np
Number of LOS points.
Observation geometry and radiance data.
int nr
Number of ray paths.
Retrieval control parameters.
double err_press_cz
Vertical correlation length for pressure error [km].
double err_press
Pressure error [%].
int err_ana
Carry out error analysis (0=no, 1=yes).
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_clz
Cloud height error [km].
double err_sft
Surface temperature error [K].
double err_temp_ch
Horizontal correlation length for temperature error [km].
int kernel_recomp
Re-computation of kernel matrix (number of iterations).
int conv_itmax
Maximum number of iterations.
double err_cldz
Cloud depth error [km].
double err_press_ch
Horizontal correlation length for pressure error [km].
int shared_io_profile
Profile index used for shared netCDF retrieval inputs and outputs.
Emissivity look-up tables.