JURASSIC
Loading...
Searching...
No Matches
jurassic.h
Go to the documentation of this file.
1/*
2 This file is part of JURASSIC.
3
4 JURASSIC is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 JURASSIC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with JURASSIC. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright (C) 2003-2026 Forschungszentrum Juelich GmbH
18*/
19
133#ifndef JURASSIC_H
134#define JURASSIC_H
135
136/* ------------------------------------------------------------
137 Includes...
138 ------------------------------------------------------------ */
139
140#include <errno.h>
141#include <fcntl.h>
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>
148#include <math.h>
149#include <netcdf.h>
150#include <omp.h>
151#include <stdint.h>
152#include <stdio.h>
153#include <stdlib.h>
154#include <string.h>
155#include <time.h>
156#include <unistd.h>
157
158enum {
166
167/* ------------------------------------------------------------
168 Constants...
169 ------------------------------------------------------------ */
170
172#ifndef C1
173#define C1 1.19104259e-8
174#endif
175
177#ifndef C2
178#define C2 1.43877506
179#endif
180
182#ifndef EPSMIN
183#define EPSMIN 0
184#endif
185
187#ifndef EPSMAX
188#define EPSMAX 1
189#endif
190
192#ifndef G0
193#define G0 9.80665
194#endif
195
197#ifndef H0
198#define H0 7.0
199#endif
200
202#ifndef KB
203#define KB 1.3806504e-23
204#endif
205
207#ifndef ME
208#define ME 5.976e24
209#endif
210
212#ifndef NA
213#define NA 6.02214199e23
214#endif
215
217#ifndef N2
218#define N2 0.78084
219#endif
220
222#ifndef O2
223#define O2 0.20946
224#endif
225
227#ifndef P0
228#define P0 1013.25
229#endif
230
232#ifndef RE
233#define RE 6367.421
234#endif
235
237#ifndef RI
238#define RI 8.3144598
239#endif
240
242#ifndef T0
243#define T0 273.15
244#endif
245
247#ifndef TMAX
248#define TMAX 400.
249#endif
250
252#ifndef TMIN
253#define TMIN 100.
254#endif
255
257#ifndef TSUN
258#define TSUN 5780.
259#endif
260
262#ifndef UMIN
263#define UMIN 0
264#endif
265
267#ifndef UMAX
268#define UMAX 1e30
269#endif
270
271/* ------------------------------------------------------------
272 Kernel finite-difference perturbations...
273 ------------------------------------------------------------ */
274
276#ifndef KERNEL_P_REL
277#define KERNEL_P_REL 0.01
278#endif
279
281#ifndef KERNEL_P_MIN
282#define KERNEL_P_MIN 1e-7
283#endif
284
286#ifndef KERNEL_T_ABS
287#define KERNEL_T_ABS 1.0
288#endif
289
291#ifndef KERNEL_Q_REL
292#define KERNEL_Q_REL 0.01
293#endif
294
296#ifndef KERNEL_Q_MIN
297#define KERNEL_Q_MIN 1e-15
298#endif
299
301#ifndef KERNEL_K_ABS
302#define KERNEL_K_ABS 1e-4
303#endif
304
306#ifndef KERNEL_CLZ_ABS
307#define KERNEL_CLZ_ABS 0.1
308#endif
309
311#ifndef KERNEL_CLDZ_ABS
312#define KERNEL_CLDZ_ABS 0.1
313#endif
314
316#ifndef KERNEL_CLK_ABS
317#define KERNEL_CLK_ABS 1e-4
318#endif
319
321#ifndef KERNEL_SFT_ABS
322#define KERNEL_SFT_ABS 1.0
323#endif
324
326#ifndef KERNEL_SFEPS_ABS
327#define KERNEL_SFEPS_ABS 1e-2
328#endif
329
330/* ------------------------------------------------------------
331 Dimensions...
332 ------------------------------------------------------------ */
333
335#ifndef LEN
336#define LEN 10000
337#endif
338
340#ifndef M
341#define M (NR*ND)
342#endif
343
345#ifndef N
346#define N ((2 + NG + NW) * NP + NCL + NSF + 3)
347#endif
348
350#ifndef NCL
351#define NCL 8
352#endif
353
355#ifndef ND
356#define ND 128
357#endif
358
360#ifndef NFOV
361#define NFOV 5
362#endif
363
365#ifndef NG
366#define NG 8
367#endif
368
370#ifndef CT
371#define CT 12
372#endif
373
376#ifndef CZ
377#define CZ 151
378#endif
379
382#ifndef CLAT
383#define CLAT 36
384#endif
385
387#ifndef NLOS
388#define NLOS 4096
389#endif
390
392#ifndef NP
393#define NP 256
394#endif
395
397#ifndef NQ
398#define NQ (5 + NG + NW + NCL + NSF)
399#endif
400
402#ifndef NR
403#define NR 256
404#endif
405
407#ifndef NSF
408#define NSF 8
409#endif
410
412#ifndef NSHAPE
413#define NSHAPE 20000
414#endif
415
417#ifndef NTIMER
418#define NTIMER 100
419#endif
420
422#ifndef NW
423#define NW 4
424#endif
425
427#ifndef RFMNPTS
428#define RFMNPTS 10000000
429#endif
430
432#ifndef TBLNP
433#define TBLNP 41
434#endif
435
437#ifndef TBLNS
438#define TBLNS 1200
439#endif
440
442#ifndef TBLNT
443#define TBLNT 30
444#endif
445
447#ifndef TBLNU
448#define TBLNU 512
449#endif
450
451/* ------------------------------------------------------------
452 Quantity indices...
453 ------------------------------------------------------------ */
454
456#define IDXP 0
457
459#define IDXT 1
460
462#define IDXQ(ig) (2 + (ig))
463
465#define IDXK(iw) (2 + (ctl->ng) + (iw))
466
468#define IDXCLZ (2 + (ctl->ng) + (ctl->nw))
469
471#define IDXCLDZ (3 + (ctl->ng) + (ctl->nw))
472
474#define IDXCLK(icl) (4 + (ctl->ng) + (ctl->nw) + (icl))
475
477#define IDXSFT (4 + (ctl->ng) + (ctl->nw) + (ctl->ncl))
478
480#define IDXSFEPS(isf) (5 + (ctl->ng) + (ctl->nw) + (ctl->ncl) + (isf))
481
482/* ------------------------------------------------------------
483 Macros...
484 ------------------------------------------------------------ */
485
503#define ALLOC(ptr, type, n) do { \
504 if((ptr=calloc((size_t)(n), sizeof(type)))==NULL) \
505 ERRMSG("Out of memory!"); \
506 } while (0)
507
534#define BRIGHT(rad, nu) \
535 (C2 * (nu) / gsl_log1p(C1 * POW3(nu) / (rad)))
536
556#define CLAMP(v, lo, hi) \
557 (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v)))
558
571#define CO2_FIT(TIME) \
572 (373.87884731310215e-6 \
573 + 1.9021498612395775e-6 * (((TIME) - 94694400.) / 31557600.) \
574 + 0.016490044598136553e-6 \
575 * POW2((((TIME) - 94694400.) / 31557600.)))
576
591#define DEG2RAD(deg) ((deg) * (M_PI / 180.0))
592
609#define DIST(a, b) sqrt(DIST2(a, b))
610
626#define DIST2(a, b) \
627 ((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])+(a[2]-b[2])*(a[2]-b[2]))
628
644#define DOTP(a, b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
645
661#define FMOD(x, y) \
662 ((x) - (int) ((x) / (y)) * (y))
663
682#define FREAD(ptr, type, size, out) do { \
683 if(fread(ptr, sizeof(type), size, out)!=size) \
684 ERRMSG("Error while reading!"); \
685 } while (0)
686
705#define FWRITE(ptr, type, size, out) do { \
706 if(fwrite(ptr, sizeof(type), size, out)!=size) \
707 ERRMSG("Error while writing!"); \
708 } while (0)
709
728#define LIN(x0, y0, x1, y1, x) \
729 ((y0)+((y1)-(y0))/((x1)-(x0))*((x)-(x0)))
730
749#define LOGY(x0, y0, x1, y1, x) \
750 (((y1)/(y0)>0) \
751 ? ((y0)*exp(log((y1)/(y0))/((x1)-(x0))*((x)-(x0)))) \
752 : LIN(x0, y0, x1, y1, x))
753
770#define MAX(a,b) (((a)>(b))?(a):(b))
771
788#define MIN(a,b) (((a)<(b))?(a):(b))
789
801#define NC(cmd) do { \
802 int nc_result=(cmd); \
803 if(nc_result!=NC_NOERR) \
804 ERRMSG("%s", nc_strerror(nc_result)); \
805 } while (0)
806
831#define NC_DEF_VAR(varname, type, ndims, dims, long_name, units, level, quant) do { \
832 NC(nc_def_var(ncid, varname, type, ndims, dims, &varid)); \
833 NC(nc_put_att_text(ncid, varid, "long_name", strnlen(long_name, LEN), long_name)); \
834 NC(nc_put_att_text(ncid, varid, "units", strnlen(units, LEN), units)); \
835 NC_DEF_VAR_QUANTIZE(quant); \
836 if((level) != 0) { \
837 NC(nc_def_var_deflate(ncid, varid, 1, 1, level)); \
838 /* unsigned int ulevel = (unsigned int)level; */ \
839 /* NC(nc_def_var_filter(ncid, varid, 32015, 1, (unsigned int[]){ulevel})); */ \
840 } \
841 } while (0)
842
854#ifdef NC_QUANTIZE_GRANULARBR
855#define NC_DEF_VAR_QUANTIZE(quant) do { \
856 if((quant) > 0) \
857 NC(nc_def_var_quantize(ncid, varid, NC_QUANTIZE_GRANULARBR, quant)); \
858 } while(0)
859#else
860#define NC_DEF_VAR_QUANTIZE(quant) do { \
861 if((quant) > 0) \
862 ERRMSG("NetCDF quantization is not supported by this NetCDF version"); \
863 } while(0)
864#endif
865
883#define NC_GET_DOUBLE(varname, ptr, force) do { \
884 if(force) { \
885 NC(nc_inq_varid(ncid, varname, &varid)); \
886 NC(nc_get_var_double(ncid, varid, ptr)); \
887 } else { \
888 if(nc_inq_varid(ncid, varname, &varid) == NC_NOERR) { \
889 NC(nc_get_var_double(ncid, varid, ptr)); \
890 } else \
891 WARN("netCDF variable %s is missing!", varname); \
892 } \
893 } while (0)
894
912#define NC_INQ_DIM(dimname, ptr, min, max, check) do { \
913 int dimid; size_t naux; \
914 NC(nc_inq_dimid(ncid, dimname, &dimid)); \
915 NC(nc_inq_dimlen(ncid, dimid, &naux)); \
916 *ptr = (int)naux; \
917 if (check) \
918 if ((*ptr) < (min) || (*ptr) > (max)) \
919 ERRMSG("Dimension %s is out of range!", dimname); \
920 } while (0)
921
936#define NC_PUT_DOUBLE(varname, ptr, hyperslab) do { \
937 NC(nc_inq_varid(ncid, varname, &varid)); \
938 if(hyperslab) { \
939 NC(nc_put_vara_double(ncid, varid, start, count, ptr)); \
940 } else { \
941 NC(nc_put_var_double(ncid, varid, ptr)); \
942 } \
943 } while (0)
944
960#define NC_PUT_FLOAT(varname, ptr, hyperslab) do { \
961 NC(nc_inq_varid(ncid, varname, &varid)); \
962 if(hyperslab) { \
963 NC(nc_put_vara_float(ncid, varid, start, count, ptr)); \
964 } else { \
965 NC(nc_put_var_float(ncid, varid, ptr)); \
966 } \
967 } while (0)
968
983#define NC_PUT_INT(varname, ptr, hyperslab) do { \
984 NC(nc_inq_varid(ncid, varname, &varid)); \
985 if(hyperslab) { \
986 NC(nc_put_vara_int(ncid, varid, start, count, ptr)); \
987 } else { \
988 NC(nc_put_var_int(ncid, varid, ptr)); \
989 } \
990 } while (0)
991
1005#define NC_PUT_ATT(varname, attname, text) do { \
1006 NC(nc_inq_varid(ncid, varname, &varid)); \
1007 NC(nc_put_att_text(ncid, varid, attname, strnlen(text, LEN), text)); \
1008 } while (0)
1009
1022#define NC_PUT_ATT_GLOBAL(attname, text) do { \
1023 NC(nc_put_att_text(ncid, NC_GLOBAL, attname, strnlen(text, LEN), text)); \
1024 } while (0)
1025
1055#define NEDT(t_bg, nesr, nu) \
1056 (BRIGHT(PLANCK((t_bg), (nu)) + (nesr), (nu)) - (t_bg))
1057
1084#define NESR(t_bg, nedt, nu) \
1085 (PLANCK((t_bg) + (nedt), (nu)) - PLANCK((t_bg), (nu)))
1086
1101#define NORM(a) sqrt(DOTP(a, a))
1102
1132#define PLANCK(T, nu) \
1133 (C1 * POW3(nu) / gsl_expm1(C2 * (nu) / (T)))
1134
1146#define POW2(x) ((x)*(x))
1147
1159#define POW3(x) ((x)*(x)*(x))
1160
1175#define RAD2DEG(rad) ((rad) * (180.0 / M_PI))
1176
1205#define REFRAC_SW53(p, T, h2o) \
1206 (1e-6 * (77.6 * (p) / (T) + 3.73e5 * (h2o) * (p) / ((T) * (T))))
1207
1232#define REFRAC_EDLEN(p, T) \
1233 ((1e-8 \
1234 * (8342.54 + 2406147.0 / (130.0 - 1.0 / (10.0 * 10.0)) \
1235 + 15998.0 / (38.9 - 1.0 / (10.0 * 10.0)))) \
1236 * ((p) / 1013.25) * (288.15 / (T)))
1237
1252#define TBL_LOG(tbl, id, ig) \
1253 do { \
1254 for (int ip = 0; ip < (tbl)->np[(id)][(ig)]; ip++) \
1255 LOG(2, \
1256 "p[%2d]= %.5e hPa | T[0:%2d]= %.2f ... %.2f K | " \
1257 "u[0:%3d]= %.5e ... %.5e molec/cm^2 | " \
1258 "eps[0:%3d]= %.5e ... %.5e", \
1259 (ip), \
1260 (tbl)->p[(id)][(ig)][(ip)], \
1261 (tbl)->nt[(id)][(ig)][(ip)] - 1, \
1262 (tbl)->t[(id)][(ig)][(ip)][0], \
1263 (tbl)->t[(id)][(ig)][(ip)] \
1264 [(tbl)->nt[(id)][(ig)][(ip)] - 1], \
1265 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1266 exp((tbl)->logu[(id)][(ig)][(ip)][0][0]), \
1267 exp((tbl)->logu[(id)][(ig)][(ip)][0] \
1268 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1]), \
1269 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1270 exp((tbl)->logeps[(id)][(ig)][(ip)][0][0]), \
1271 exp((tbl)->logeps[(id)][(ig)][(ip)][0] \
1272 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1])); \
1273 } while (0)
1274
1286#define SELECT_TIMER(id, group) \
1287 do {timer_group(id, group, 0);} while (0)
1288
1296#define PRINT_TIMERS \
1297 do {timer_group("END", "END", 1);} while (0)
1298
1317#define TOK(line, tok, format, var) { \
1318 if(((tok)=strtok((line), " \t"))) { \
1319 if(sscanf(tok, format, &(var))!=1) continue; \
1320 } else ERRMSG("Error while reading!"); \
1321 }
1322
1334#define USAGE \
1335 do { \
1336 int iusage; \
1337 for (iusage = 1; iusage < argc; iusage++) \
1338 if (!strcmp(argv[iusage], "-h") \
1339 || !strcmp(argv[iusage], "--help")) { \
1340 usage(); \
1341 return EXIT_SUCCESS; \
1342 } \
1343 } while (0)
1344
1345/* ------------------------------------------------------------
1346 Log messages...
1347 ------------------------------------------------------------ */
1348
1350#ifndef LOGLEV
1351#define LOGLEV 2
1352#endif
1353
1383#define LOG(level, ...) do { \
1384 if(level >= 2) \
1385 printf(" "); \
1386 if(level <= LOGLEV) { \
1387 printf(__VA_ARGS__); \
1388 printf("\n"); \
1389 } \
1390 } while (0)
1391
1420#define WARN(...) do { \
1421 printf("\nWarning (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1422 LOG(0, __VA_ARGS__); \
1423 } while (0)
1424
1453#define ERRMSG(...) do { \
1454 printf("\nError (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1455 LOG(0, __VA_ARGS__); \
1456 exit(EXIT_FAILURE); \
1457 } while (0)
1458
1488#define PRINT(format, var) do { \
1489 printf("Print (%s, %s, l%d): %s= "format"\n", \
1490 __FILE__, __func__, __LINE__, #var, var); \
1491 } while (0)
1492
1493/* ------------------------------------------------------------
1494 Structs...
1495 ------------------------------------------------------------ */
1496
1504typedef struct {
1505
1507 int np;
1508
1510 double time[NP];
1511
1513 double z[NP];
1514
1516 double lon[NP];
1517
1519 double lat[NP];
1520
1522 double p[NP];
1523
1525 double t[NP];
1526
1528 double q[NG][NP];
1529
1531 double k[NW][NP];
1532
1534 double clz;
1535
1537 double cldz;
1538
1540 double clk[NCL];
1541
1543 double sft;
1544
1546 double sfeps[NSF];
1547
1548} atm_t;
1549
1556typedef struct {
1558 int nalt;
1559
1561 int nlat;
1562
1565
1567 double alt[CZ];
1568
1570 double lat[CLAT];
1571
1573 double time[CT];
1574
1576 double t[CT][CZ][CLAT];
1577
1579 double p[CT][CZ][CLAT];
1580
1582 double q[NG][CT][CZ][CLAT];
1583
1586
1589
1591 int has_q[NG];
1592
1593} clim_t;
1594
1602typedef struct {
1603
1605 int ng;
1606
1608 char emitter[NG][LEN];
1609
1612
1615
1618
1621
1623 int nd;
1624
1626 double nu[ND];
1627
1629 int nw;
1630
1632 int window[ND];
1633
1635 int ncl;
1636
1638 double clnu[NCL];
1639
1641 int nsf;
1642
1644 double sfnu[NSF];
1645
1648
1650 double sfsza;
1651
1653 char tblbase[LEN];
1654
1657
1659 char climfile[LEN];
1660
1663
1666
1669
1671 double hydz;
1672
1675
1678
1681
1684
1687
1689 double rayds;
1690
1692 double raydz;
1693
1695 char fov[LEN];
1696
1698 double fov_dz[NSHAPE];
1699
1701 double fov_w[NSHAPE];
1702
1705
1708
1711
1714
1717
1719 double retq_zmin[NG];
1720
1722 double retq_zmax[NG];
1723
1725 double retk_zmin[NW];
1726
1728 double retk_zmax[NW];
1729
1732
1735
1738
1741
1744
1747
1750
1753
1755 char rfmbin[LEN];
1756
1758 char rfmtmp[LEN];
1759
1761 char rfmhit[LEN];
1762
1764 char rfmxsc[NG][LEN];
1765
1766} ctl_t;
1767
1775typedef struct {
1776
1778 int np;
1779
1781 double z[NLOS];
1782
1784 double lon[NLOS];
1785
1787 double lat[NLOS];
1788
1790 double p[NLOS];
1791
1793 double t[NLOS];
1794
1796 double q[NLOS][NG];
1797
1799 double k[NLOS][ND];
1800
1802 double sft;
1803
1805 double sfeps[ND];
1806
1808 double ds[NLOS];
1809
1811 double u[NLOS][NG];
1812
1814 double cgp[NLOS][NG];
1815
1817 double cgt[NLOS][NG];
1818
1820 double cgu[NLOS][NG];
1821
1823 double eps[NLOS][ND];
1824
1826 double src[NLOS][ND];
1827
1828} los_t;
1829
1837typedef struct {
1838
1840 int nr;
1841
1843 double time[NR];
1844
1846 double obsz[NR];
1847
1849 double obslon[NR];
1850
1852 double obslat[NR];
1853
1855 double vpz[NR];
1856
1858 double vplon[NR];
1859
1861 double vplat[NR];
1862
1864 double tpz[NR];
1865
1867 double tplon[NR];
1868
1870 double tplat[NR];
1871
1873 double tau[ND][NR];
1874
1876 double rad[ND][NR];
1877
1879 int mask[ND][NR];
1880
1881} obs_t;
1882
1892typedef struct {
1893
1895 char dir[LEN];
1896
1899
1902
1905
1908
1910 double err_formod[ND];
1911
1913 double err_noise[ND];
1914
1917
1920
1923
1925 double err_temp;
1926
1929
1932
1934 double err_q[NG];
1935
1937 double err_q_cz[NG];
1938
1940 double err_q_ch[NG];
1941
1943 double err_k[NW];
1944
1946 double err_k_cz[NW];
1947
1949 double err_k_ch[NW];
1950
1952 double err_clz;
1953
1955 double err_cldz;
1956
1958 double err_clk[NCL];
1959
1961 double err_sft;
1962
1964 double err_sfeps[NSF];
1965
1968
1970 char shared_io_proflist[LEN];
1971
1973 char shared_io_atm_apr_file[LEN];
1974
1976 char shared_io_obs_meas_file[LEN];
1977
1979 char shared_io_atm_final_file[LEN];
1980
1982 char shared_io_obs_final_file[LEN];
1983
1985 char shared_io_matrix_cov_apr_file[LEN];
1986
1988 char shared_io_matrix_kernel_file[LEN];
1989
1991 char shared_io_matrix_cov_ret_file[LEN];
1992
1994 char shared_io_matrix_corr_file[LEN];
1995
1997 char shared_io_matrix_gain_file[LEN];
1998
2000 char shared_io_matrix_avk_file[LEN];
2001
2003 char shared_io_atm_err_total_file[LEN];
2004
2006 char shared_io_atm_err_noise_file[LEN];
2007
2009 char shared_io_atm_err_formod_file[LEN];
2010
2012 char shared_io_atm_cont_file[LEN];
2013
2015 char shared_io_atm_res_file[LEN];
2016
2017} ret_t;
2018
2025typedef struct {
2026
2028 int np[ND][NG];
2029
2031 int nt[ND][NG][TBLNP];
2032
2034 int nu[ND][NG][TBLNP][TBLNT];
2035
2037 double p[ND][NG][TBLNP];
2038
2040 double lnp[ND][NG][TBLNP];
2041
2043 double t[ND][NG][TBLNP][TBLNT];
2044
2046 float *logu[ND][NG][TBLNP][TBLNT];
2047
2049 float *logeps[ND][NG][TBLNP][TBLNT];
2050
2052 int filt_n[ND];
2053
2055 double filt_nu[ND][NSHAPE];
2056
2058 double filt_f[ND][NSHAPE];
2059
2061 double st[TBLNS];
2062
2064 double sr[TBLNS][ND];
2065
2066} tbl_t;
2067
2068/* ------------------------------------------------------------
2069 Functions...
2070 ------------------------------------------------------------ */
2071
2123void analyze_avk(
2124 const ret_t * ret,
2125 const ctl_t * ctl,
2126 const atm_t * atm,
2127 const int *iqa,
2128 const int *ipa,
2129 const gsl_matrix * avk);
2130
2187 const gsl_matrix * avk,
2188 const int iq,
2189 const int *ipa,
2190 const size_t *n0,
2191 const size_t *n1,
2192 double *cont,
2193 double *res);
2194
2221size_t atm2x(
2222 const ctl_t * ctl,
2223 const atm_t * atm,
2224 gsl_vector * x,
2225 int *iqa,
2226 int *ipa);
2227
2249void atm2x_help(
2250 const double value,
2251 const int value_iqa,
2252 const int value_ip,
2253 gsl_vector * x,
2254 int *iqa,
2255 int *ipa,
2256 size_t *n);
2257
2272void cart2geo(
2273 const double *x,
2274 double *z,
2275 double *lon,
2276 double *lat);
2277
2296void climatology(
2297 const ctl_t * ctl,
2298 const clim_t * clim,
2299 atm_t * atm);
2300
2329int read_clim_field(
2330 const char *filename,
2331 const char *varname,
2332 const int ncid,
2333 const int dim_month,
2334 const int dim_alt,
2335 const int dim_lat,
2336 const int nalt,
2337 const int nlat,
2338 double field[CT][CZ][CLAT],
2339 double *vmin,
2340 double *vmax);
2341
2377 const clim_t * clim,
2378 const atm_t * atm,
2379 const double field[CT][CZ][CLAT],
2380 const int top_policy,
2381 double *out);
2382
2413 const ctl_t * ctl);
2414
2432 const ctl_t * ctl,
2433 const clim_t * clim,
2434 atm_t * atm);
2435
2460double cos_sza(
2461 const double sec,
2462 const double lon,
2463 const double lat);
2464
2504double cost_function(
2505 const gsl_vector * dx,
2506 const gsl_vector * dy,
2507 const gsl_matrix * s_a_inv,
2508 const gsl_vector * sig_eps_inv);
2509
2531double ctmco2(
2532 const double nu,
2533 const double p,
2534 const double t,
2535 const double u);
2536
2542double ctmh2o(
2543 const double nu,
2544 const double p,
2545 const double t,
2546 const double q,
2547 const double u);
2548
2580double ctmn2(
2581 const double nu,
2582 const double p,
2583 const double t);
2584
2614double ctmo2(
2615 const double nu,
2616 const double p,
2617 const double t);
2618
2643void copy_atm(
2644 const ctl_t * ctl,
2645 atm_t * atm_dest,
2646 const atm_t * atm_src,
2647 const int init);
2648
2673void copy_obs(
2674 const ctl_t * ctl,
2675 obs_t * obs_dest,
2676 const obs_t * obs_src,
2677 const int init);
2678
2699void day2doy(
2700 int year,
2701 int mon,
2702 int day,
2703 int *doy);
2704
2727void doy2day(
2728 int year,
2729 int doy,
2730 int *mon,
2731 int *day);
2732
2752int find_emitter(
2753 const ctl_t * ctl,
2754 const char *emitter);
2755
2791int formod(
2792 const ctl_t * ctl,
2793 const tbl_t * tbl,
2794 atm_t * atm,
2795 obs_t * obs,
2796 los_t * los_scratch,
2797 obs_t * obs_scratch);
2798
2818void formod_batch(
2819 const ctl_t * ctl,
2820 const tbl_t * tbl,
2821 atm_t * atm,
2822 obs_t * obs,
2823 const int nbatch,
2824 int *status,
2825 los_t * los_scratch,
2826 obs_t * obs_scratch);
2827
2853void formod_continua(
2854 const ctl_t * ctl,
2855 const los_t * los,
2856 const int ip,
2857 double *beta);
2858
2882int formod_fov(
2883 const ctl_t * ctl,
2884 obs_t * obs,
2885 obs_t * obs_scratch);
2886
2919int formod_pencil(
2920 const ctl_t * ctl,
2921 const tbl_t * tbl,
2922 const atm_t * atm,
2923 obs_t * obs,
2924 const int ir,
2925 los_t * los);
2926
2979void formod_rfm(
2980 const ctl_t * ctl,
2981 const tbl_t * tbl,
2982 const atm_t * atm,
2983 obs_t * obs);
2984
3009void formod_srcfunc(
3010 const ctl_t * ctl,
3011 const tbl_t * tbl,
3012 const double t,
3013 double *src);
3014
3041void geo2cart(
3042 const double z,
3043 const double lon,
3044 const double lat,
3045 double *x);
3046
3074void hydrostatic(
3075 const ctl_t * ctl,
3076 atm_t * atm);
3077
3101void idx2name(
3102 const ctl_t * ctl,
3103 const int idx,
3104 char *quantity);
3105
3135void init_srcfunc(
3136 const ctl_t * ctl,
3137 tbl_t * tbl);
3138
3163void intpol_atm(
3164 const ctl_t * ctl,
3165 const atm_t * atm,
3166 const double z,
3167 double *p,
3168 double *t,
3169 double *q,
3170 double *k);
3171
3205void intpol_tbl_cga(
3206 const ctl_t * ctl,
3207 const tbl_t * tbl,
3208 const los_t * los,
3209 const int ip,
3210 double tau_path[ND][NG],
3211 double tau_seg[ND]);
3212
3251void intpol_tbl_ega(
3252 const ctl_t * ctl,
3253 const tbl_t * tbl,
3254 const los_t * los,
3255 const int ip,
3256 double tau_path[ND][NG],
3257 double tau_seg[ND]);
3258
3285double intpol_tbl_eps(
3286 const tbl_t * tbl,
3287 const int ig,
3288 const int id,
3289 const int ip,
3290 const int it,
3291 const double logu);
3292
3323double intpol_tbl_u(
3324 const tbl_t * tbl,
3325 const int ig,
3326 const int id,
3327 const int ip,
3328 const int it,
3329 const double logeps);
3330
3357void jsec2time(
3358 const double jsec,
3359 int *year,
3360 int *mon,
3361 int *day,
3362 int *hour,
3363 int *min,
3364 int *sec,
3365 double *remain);
3366
3413void kernel(
3414 const ctl_t * ctl,
3415 const tbl_t * tbl,
3416 atm_t * atm,
3417 obs_t * obs,
3418 gsl_matrix * k);
3419
3447int locate_irr(
3448 const double *xx,
3449 const int n,
3450 const double x);
3451
3478int locate_reg(
3479 const double *xx,
3480 const int n,
3481 const double x);
3482
3508int locate_tbl(
3509 const float *xx,
3510 const int n,
3511 const double x);
3512
3551void matrix_invert(
3552 gsl_matrix * a);
3553
3598void matrix_product(
3599 const gsl_matrix * a,
3600 const gsl_vector * b,
3601 const int transpose,
3602 gsl_matrix * c);
3603
3631size_t obs2y(
3632 const ctl_t * ctl,
3633 const obs_t * obs,
3634 gsl_vector * y,
3635 int *ida,
3636 int *ira);
3637
3689 ret_t * ret,
3690 ctl_t * ctl,
3691 tbl_t * tbl,
3692 obs_t * obs_meas,
3693 obs_t * obs_i,
3694 atm_t * atm_apr,
3695 atm_t * atm_i,
3696 double *chisq);
3697
3746int raytrace(
3747 const ctl_t * ctl,
3748 const atm_t * atm,
3749 obs_t * obs,
3750 los_t * los,
3751 const int ir);
3752
3802void read_atm(
3803 const char *dirname,
3804 const char *filename,
3805 const ctl_t * ctl,
3806 atm_t * atm,
3807 int profile);
3808
3855void read_atm_asc(
3856 const char *filename,
3857 const ctl_t * ctl,
3858 atm_t * atm);
3859
3909void read_atm_bin(
3910 const char *filename,
3911 const ctl_t * ctl,
3912 atm_t * atm);
3913
3955void read_atm_nc(
3956 const char *filename,
3957 const ctl_t * ctl,
3958 atm_t * atm,
3959 int profile);
3960
4001void read_ctl(
4002 int argc,
4003 char *argv[],
4004 ctl_t * ctl);
4005
4024void read_matrix(
4025 const char *dirname,
4026 const char *filename,
4027 const ctl_t * ctl,
4028 gsl_matrix * matrix,
4029 int dataset);
4030
4062void read_matrix_asc(
4063 const char *dirname,
4064 const char *filename,
4065 gsl_matrix * matrix);
4066
4084void read_matrix_bin(
4085 const char *dirname,
4086 const char *filename,
4087 gsl_matrix * matrix);
4088
4110void read_matrix_nc(
4111 const char *dirname,
4112 const char *filename,
4113 gsl_matrix * matrix,
4114 int dataset);
4115
4152void read_obs(
4153 const char *dirname,
4154 const char *filename,
4155 const ctl_t * ctl,
4156 obs_t * obs,
4157 int profile);
4158
4196void read_obs_asc(
4197 const char *filename,
4198 const ctl_t * ctl,
4199 obs_t * obs);
4200
4242void read_obs_bin(
4243 const char *filename,
4244 const ctl_t * ctl,
4245 obs_t * obs);
4246
4279void read_obs_nc(
4280 const char *filename,
4281 const ctl_t * ctl,
4282 obs_t * obs,
4283 const int profile);
4284
4324double read_obs_rfm(
4325 const char *basename,
4326 const double z,
4327 const double *nu,
4328 const double *f,
4329 const int n);
4330
4405void read_ret(
4406 int argc,
4407 char *argv[],
4408 const ctl_t * ctl,
4409 ret_t * ret);
4410
4452void read_rfm_spec(
4453 const char *filename,
4454 double *nu,
4455 double *rad,
4456 int *npts);
4457
4491void read_shape(
4492 const char *filename,
4493 double *x,
4494 double *y,
4495 int *n);
4496
4533 const ctl_t * ctl);
4534
4570void read_tbl_asc(
4571 const ctl_t * ctl,
4572 tbl_t * tbl,
4573 const int id,
4574 const int ig);
4575
4607void read_tbl_bin(
4608 const ctl_t * ctl,
4609 tbl_t * tbl,
4610 const int id,
4611 const int ig);
4612
4656 const ctl_t * ctl,
4657 tbl_t * tbl,
4658 int id,
4659 int ig,
4660 int ncid);
4661
4716double scan_ctl(
4717 int argc,
4718 char *argv[],
4719 const char *varname,
4720 const int arridx,
4721 const char *defvalue,
4722 char *value);
4723
4777void set_cov_apr(
4778 const ret_t * ret,
4779 const ctl_t * ctl,
4780 const atm_t * atm,
4781 const int *iqa,
4782 const int *ipa,
4783 gsl_matrix * s_a);
4784
4838void set_cov_meas(
4839 const ret_t * ret,
4840 const ctl_t * ctl,
4841 const obs_t * obs,
4842 gsl_vector * sig_noise,
4843 gsl_vector * sig_formod,
4844 gsl_vector * sig_eps_inv);
4845
4872const char *shared_io_input_target(
4873 const ret_t * ret,
4874 const char *shared_file,
4875 const char *legacy_file,
4876 const char **dirname,
4877 int *profile);
4878
4905const char *shared_io_output_target(
4906 const ret_t * ret,
4907 const char *shared_file,
4908 const char *legacy_file,
4909 const char **dirname,
4910 int *profile);
4911
4932int shared_io_lock(
4933 const ret_t * ret);
4934
4949void shared_io_unlock(
4950 int fd);
4951
4972const char *shared_io_output_file(
4973 const ret_t * ret);
4974
5014void tangent_point(
5015 const los_t * los,
5016 double *tpz,
5017 double *tplon,
5018 double *tplat);
5019
5041void tbl_free(
5042 const ctl_t * ctl,
5043 tbl_t * tbl);
5044
5084void tbl_pack(
5085 const tbl_t * tbl,
5086 int id,
5087 int ig,
5088 uint8_t * buf,
5089 size_t *bytes_used);
5090
5101size_t tbl_packed_size(
5102 const tbl_t * tbl,
5103 int id,
5104 int ig);
5105
5144size_t tbl_unpack(
5145 tbl_t * tbl,
5146 int id,
5147 int ig,
5148 const uint8_t * buf);
5149
5150
5175void time2jsec(
5176 const int year,
5177 const int mon,
5178 const int day,
5179 const int hour,
5180 const int min,
5181 const int sec,
5182 const double remain,
5183 double *jsec);
5184
5199void timer_group(
5200 const char *name,
5201 const char *group,
5202 int output);
5203
5252void write_atm(
5253 const char *dirname,
5254 const char *filename,
5255 const ctl_t * ctl,
5256 const atm_t * atm,
5257 int profile);
5258
5310void write_atm_asc(
5311 const char *filename,
5312 const ctl_t * ctl,
5313 const atm_t * atm);
5314
5368void write_atm_bin(
5369 const char *filename,
5370 const ctl_t * ctl,
5371 const atm_t * atm);
5372
5420void write_atm_nc(
5421 const char *filename,
5422 const ctl_t * ctl,
5423 const atm_t * atm,
5424 int profile);
5425
5477void write_atm_rfm(
5478 const char *filename,
5479 const ctl_t * ctl,
5480 const atm_t * atm);
5481
5505void write_matrix(
5506 const char *dirname,
5507 const char *filename,
5508 const ctl_t * ctl,
5509 const gsl_matrix * matrix,
5510 const atm_t * atm,
5511 const obs_t * obs,
5512 const char *rowspace,
5513 const char *colspace,
5514 const char *sort,
5515 int dataset);
5516
5564void write_matrix_asc(
5565 const char *dirname,
5566 const char *filename,
5567 const ctl_t * ctl,
5568 const gsl_matrix * matrix,
5569 const atm_t * atm,
5570 const obs_t * obs,
5571 const char *rowspace,
5572 const char *colspace,
5573 const char *sort);
5574
5589void write_matrix_bin(
5590 const char *dirname,
5591 const char *filename,
5592 const gsl_matrix * matrix);
5593
5620void write_matrix_nc(
5621 const char *dirname,
5622 const char *filename,
5623 const ctl_t * ctl,
5624 const gsl_matrix * matrix,
5625 const atm_t * atm,
5626 const obs_t * obs,
5627 const char *rowspace,
5628 const char *colspace,
5629 const char *sort,
5630 int dataset);
5631
5667void write_obs(
5668 const char *dirname,
5669 const char *filename,
5670 const ctl_t * ctl,
5671 const obs_t * obs,
5672 int profile);
5673
5712void write_obs_asc(
5713 const char *filename,
5714 const ctl_t * ctl,
5715 const obs_t * obs);
5716
5754void write_obs_bin(
5755 const char *filename,
5756 const ctl_t * ctl,
5757 const obs_t * obs);
5758
5796void write_obs_nc(
5797 const char *filename,
5798 const ctl_t * ctl,
5799 const obs_t * obs,
5800 const int profile);
5801
5836void write_shape(
5837 const char *filename,
5838 const double *x,
5839 const double *y,
5840 const int n);
5841
5887void write_stddev(
5888 const char *quantity,
5889 const ret_t * ret,
5890 const ctl_t * ctl,
5891 const atm_t * atm,
5892 const gsl_matrix * s);
5893
5929void write_tbl(
5930 const ctl_t * ctl,
5931 const tbl_t * tbl);
5932
5958void write_tbl_asc(
5959 const ctl_t * ctl,
5960 const tbl_t * tbl,
5961 const int id,
5962 const int ig);
5963
5991void write_tbl_bin(
5992 const ctl_t * ctl,
5993 const tbl_t * tbl,
5994 const int id,
5995 const int ig);
5996
6029void write_tbl_nc(
6030 const ctl_t * ctl,
6031 const tbl_t * tbl,
6032 const int id,
6033 const int ig);
6034
6081void x2atm(
6082 const ctl_t * ctl,
6083 const gsl_vector * x,
6084 atm_t * atm);
6085
6114void x2atm_help(
6115 double *value,
6116 const gsl_vector * x,
6117 size_t *n);
6118
6151void y2obs(
6152 const ctl_t * ctl,
6153 const gsl_vector * y,
6154 obs_t * obs);
6155
6156#endif
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.
Definition jurassic.c:5109
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.
Definition jurassic.c:31
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.
Definition jurassic.c:7436
#define LEN
Maximum length of ASCII data lines.
Definition jurassic.h:336
@ FORMOD_STATUS_TOO_MANY_LOS_POINTS
Definition jurassic.h:163
@ FORMOD_STATUS_OK
Definition jurassic.h:159
@ FORMOD_STATUS_FOV_DATA_MISSING
Definition jurassic.h:161
@ FORMOD_STATUS_RFM_UNSUPPORTED
Definition jurassic.h:160
@ FORMOD_STATUS_OBSERVER_BELOW_SURFACE
Definition jurassic.h:162
@ FORMOD_STATUS_NO_ATMOSPHERE_INTERSECTION
Definition jurassic.h:164
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.
Definition jurassic.c:1703
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.
Definition jurassic.c:7006
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.
Definition jurassic.c:8212
void read_rfm_spec(const char *filename, double *nu, double *rad, int *npts)
Read a Reference Forward Model (RFM) ASCII spectrum.
Definition jurassic.c:7128
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.
Definition jurassic.c:7946
void read_matrix_nc(const char *dirname, const char *filename, gsl_matrix *matrix, int dataset)
Read a numerical matrix from a netCDF file.
Definition jurassic.c:6676
double cos_sza(const double sec, const double lon, const double lat)
Calculates the cosine of the solar zenith angle.
Definition jurassic.c:1662
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.
Definition jurassic.c:5857
void read_atm_bin(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in binary format.
Definition jurassic.c:6223
void write_obs_asc(const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data to an ASCII text file.
Definition jurassic.c:9251
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).
Definition jurassic.c:4434
int locate_reg(const double *xx, const int n, const double x)
Locate index for interpolation on a regular (uniform) grid.
Definition jurassic.c:5390
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).
Definition jurassic.c:5007
double ctmo2(const double nu, const double p, const double t)
Compute O₂ collision-induced absorption coefficient.
Definition jurassic.c:3836
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.
Definition jurassic.c:9375
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
Definition jurassic.c:7907
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.
Definition jurassic.c:9670
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.
Definition jurassic.c:9754
void idx2name(const ctl_t *ctl, const int idx, char *quantity)
Convert a quantity index to a descriptive name string.
Definition jurassic.c:4803
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition jurassic.c:6421
void formod_continua(const ctl_t *ctl, const los_t *los, const int ip, double *beta)
Compute total extinction including gaseous continua.
Definition jurassic.c:4144
void climatology(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Initializes atmospheric climatology profiles.
Definition jurassic.c:217
void read_obs_bin(const char *filename, const ctl_t *ctl, obs_t *obs)
Read binary-formatted observation data from a file.
Definition jurassic.c:6849
int shared_io_lock(const ret_t *ret)
Acquire an exclusive lock for shared retrieval output files.
Definition jurassic.c:7785
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.
Definition jurassic.c:6725
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 .
Definition jurassic.c:5461
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.
Definition jurassic.c:4242
void climatology_external(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Overwrites the built-in climatology with a JuMACS climatology.
Definition jurassic.c:1637
int locate_irr(const double *xx, const int n, const double x)
Locate index for interpolation on an irregular grid.
Definition jurassic.c:5360
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.
Definition jurassic.c:7745
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.
Definition jurassic.c:8695
void day2doy(int year, int mon, int day, int *doy)
Convert a calendar date to day-of-year.
Definition jurassic.c:3986
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.
Definition jurassic.c:8434
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.
Definition jurassic.c:8658
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.
Definition jurassic.c:8110
void x2atm(const ctl_t *ctl, const gsl_vector *x, atm_t *atm)
Map retrieval state vector back to atmospheric structure.
Definition jurassic.c:9819
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.
Definition jurassic.c:181
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).
Definition jurassic.c:2597
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.
Definition jurassic.c:9712
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).
Definition jurassic.c:4914
void shared_io_unlock(int fd)
Release a shared retrieval output lock.
Definition jurassic.c:7812
void write_atm_rfm(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric profile in RFM-compatible format.
Definition jurassic.c:8621
#define ND
Maximum number of radiance channels.
Definition jurassic.h:356
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.
Definition jurassic.c:7696
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.
Definition jurassic.c:9180
#define NSHAPE
Maximum number of shape function grid points.
Definition jurassic.h:413
void write_tbl(const ctl_t *ctl, const tbl_t *tbl)
Write emissivity lookup tables to disk.
Definition jurassic.c:9627
#define CT
Maximum number of time steps for climatological data.
Definition jurassic.h:371
size_t tbl_unpack(tbl_t *tbl, int id, int ig, const uint8_t *buf)
Unpack a lookup table from a contiguous binary buffer.
Definition jurassic.c:8034
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.
Definition jurassic.c:6558
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.
Definition jurassic.c:4889
int find_emitter(const ctl_t *ctl, const char *emitter)
Find gas species index by name.
Definition jurassic.c:4036
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.
Definition jurassic.c:5533
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.
Definition jurassic.c:5154
void timer_group(const char *name, const char *group, int output)
Aggregate wall-clock timings for named code phases.
Definition jurassic.c:8141
void tangent_point(const los_t *los, double *tpz, double *tplon, double *tplat)
Determine the tangent point along a line of sight (LOS).
Definition jurassic.c:7864
double ctmco2(const double nu, const double p, const double t, const double u)
Compute carbon dioxide continuum optical depth.
Definition jurassic.c:1734
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.
Definition jurassic.c:6093
int formod_fov(const ctl_t *ctl, obs_t *obs, obs_t *obs_scratch)
Apply field-of-view (FOV) convolution to modeled radiances.
Definition jurassic.c:4180
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.
Definition jurassic.c:8917
#define CLAT
Maximum number of latitudes for climatological data (JuMACS: 36 area-weighted 5-degree bands).
Definition jurassic.h:383
void write_atm_asc(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric data to an ASCII file.
Definition jurassic.c:8283
void write_matrix_bin(const char *dirname, const char *filename, const gsl_matrix *matrix)
Write a numerical matrix to a binary file.
Definition jurassic.c:8868
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.
Definition jurassic.c:3948
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.
Definition jurassic.c:4100
#define TBLNT
Maximum number of temperatures in emissivity tables.
Definition jurassic.h:443
void write_obs_bin(const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data in binary format to a file.
Definition jurassic.c:9307
void x2atm_help(double *value, const gsl_vector *x, size_t *n)
Helper function to extract a single value from the retrieval state vector.
Definition jurassic.c:9869
void cart2geo(const double *x, double *z, double *lon, double *lat)
Converts Cartesian coordinates to geographic coordinates.
Definition jurassic.c:202
#define NP
Maximum number of atmospheric data points.
Definition jurassic.h:393
void doy2day(int year, int doy, int *mon, int *day)
Convert a day-of-year value to a calendar date.
Definition jurassic.c:4006
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.
Definition jurassic.c:5233
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.
Definition jurassic.c:6927
void init_srcfunc(const ctl_t *ctl, tbl_t *tbl)
Initialize source function lookup tables from emissivity data.
Definition jurassic.c:4842
void matrix_invert(gsl_matrix *a)
Invert a square matrix, optimized for diagonal or symmetric positive-definite matrices.
Definition jurassic.c:5431
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
Definition jurassic.c:7040
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.
Definition jurassic.c:7517
void write_shape(const char *filename, const double *x, const double *y, const int n)
Write tabulated shape function data to a text file.
Definition jurassic.c:9555
void read_atm_asc(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in ASCII format.
Definition jurassic.c:6167
#define NG
Maximum number of emitters.
Definition jurassic.h:366
void read_tbl_asc(const ctl_t *ctl, tbl_t *tbl, const int id, const int ig)
Read a single ASCII emissivity lookup table.
Definition jurassic.c:7313
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.
Definition jurassic.c:4708
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.
Definition jurassic.c:103
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.
Definition jurassic.c:5200
#define TBLNS
Maximum number of source function temperature levels.
Definition jurassic.h:438
void read_matrix_asc(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from an ASCII file.
Definition jurassic.c:6584
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
Definition jurassic.c:7237
void read_matrix_bin(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from a binary file.
Definition jurassic.c:6623
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.
Definition jurassic.c:7480
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.
Definition jurassic.c:7765
void read_atm_nc(const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read one atmospheric profile from a netCDF file.
Definition jurassic.c:6317
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.
Definition jurassic.c:3898
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.
Definition jurassic.c:5506
void y2obs(const ctl_t *ctl, const gsl_vector *y, obs_t *obs)
Copy elements from the measurement vector y into the observation structure.
Definition jurassic.c:9881
void hydrostatic(const ctl_t *ctl, atm_t *atm)
Adjust pressure profile using the hydrostatic equation.
Definition jurassic.c:4743
void read_shape(const char *filename, double *x, double *y, int *n)
Read a two-column shape function from an ASCII file.
Definition jurassic.c:7190
double ctmn2(const double nu, const double p, const double t)
Compute N₂ collision-induced absorption coefficient.
Definition jurassic.c:3767
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.
Definition jurassic.c:1261
#define CZ
Maximum number of altitudes for climatological data (JuMACS: 0...150 km at 1 km spacing).
Definition jurassic.h:377
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.
Definition jurassic.c:127
#define TBLNP
Maximum number of pressure levels in emissivity tables.
Definition jurassic.h:433
void geo2cart(const double z, const double lon, const double lat, double *x)
Converts geographic coordinates (longitude, latitude, altitude) to Cartesian coordinates.
Definition jurassic.c:4725
#define NSF
Maximum number of surface layer spectral grid points.
Definition jurassic.h:408
#define NCL
Maximum number of cloud layer spectral grid points.
Definition jurassic.h:351
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.
Definition jurassic.c:7585
const char * shared_io_output_file(const ret_t *ret)
Return the primary shared retrieval output file configured for locking.
Definition jurassic.c:7830
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.
Definition jurassic.c:9584
#define NLOS
Maximum number of LOS points.
Definition jurassic.h:388
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.
Definition jurassic.c:4049
size_t tbl_packed_size(const tbl_t *tbl, int id, int ig)
Compute required buffer size (in bytes) for tbl_pack().
Definition jurassic.c:8000
clim_t * read_clim(const ctl_t *ctl)
Reads a JuMACS climatology file into an allocated climatology structure.
Definition jurassic.c:1378
#define NR
Maximum number of ray paths.
Definition jurassic.h:403
int locate_tbl(const float *xx, const int n, const double x)
Locate index for interpolation within emissivity table grids.
Definition jurassic.c:5409
void write_atm_bin(const char *filename, const ctl_t *ctl, const atm_t *atm)
Write atmospheric data to a binary file.
Definition jurassic.c:8350
void read_obs_asc(const char *filename, const ctl_t *ctl, obs_t *obs)
Read ASCII-formatted observation data from a file.
Definition jurassic.c:6800
#define NW
Maximum number of spectral windows.
Definition jurassic.h:423
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.
Definition jurassic.c:1168
Atmospheric profile data.
Definition jurassic.h:1504
double clz
Cloud layer height [km].
Definition jurassic.h:1534
int np
Number of data points.
Definition jurassic.h:1507
double cldz
Cloud layer depth [km].
Definition jurassic.h:1537
double sft
Surface temperature [K].
Definition jurassic.h:1543
JuMACS climatology on a fixed grid.
Definition jurassic.h:1556
int ntime
Number of climatological time coordinates.
Definition jurassic.h:1564
int has_t
Set if a temperature field was read.
Definition jurassic.h:1585
int nalt
Number of altitude levels.
Definition jurassic.h:1558
int has_p
Set if a pressure field was read.
Definition jurassic.h:1588
int nlat
Number of latitude bands.
Definition jurassic.h:1561
Control parameters.
Definition jurassic.h:1602
int write_matrix
Write matrix file (0=no, 1=yes).
Definition jurassic.h:1749
int nw
Number of spectral windows.
Definition jurassic.h:1629
int atmfmt
Atmospheric data file format (1=ASCII, 2=binary, 3=netCDF).
Definition jurassic.h:1662
double retp_zmin
Minimum altitude for pressure retrieval [km].
Definition jurassic.h:1707
int ig_co2
Emitter index of CO2.
Definition jurassic.h:1611
double hydz
Reference height for hydrostatic pressure profile (-999 to skip) [km].
Definition jurassic.h:1671
int ctm_co2
Compute CO2 continuum (0=no, 1=yes).
Definition jurassic.h:1674
double rett_zmax
Maximum altitude for temperature retrieval [km].
Definition jurassic.h:1716
int ret_sfeps
Retrieve surface layer emissivity (0=no, 1=yes).
Definition jurassic.h:1743
int ret_sft
Retrieve surface layer temperature (0=no, 1=yes).
Definition jurassic.h:1740
int ret_clz
Retrieve cloud layer height (0=no, 1=yes).
Definition jurassic.h:1731
int ctm_n2
Compute N2 continuum (0=no, 1=yes).
Definition jurassic.h:1680
int ctm_h2o
Compute H2O continuum (0=no, 1=yes).
Definition jurassic.h:1677
int formod
Forward model (0=CGA, 1=EGA, 2=RFM).
Definition jurassic.h:1752
int ng
Number of emitters.
Definition jurassic.h:1605
int refrac
Take into account refractivity (0=no, 1=yes).
Definition jurassic.h:1686
int ig_o2
Emitter index of O2.
Definition jurassic.h:1620
double rett_zmin
Minimum altitude for temperature retrieval [km].
Definition jurassic.h:1713
double sfsza
Solar zenith angle at the surface [deg] (-999=auto).
Definition jurassic.h:1650
int nd
Number of radiance channels.
Definition jurassic.h:1623
int fov_n
Field-of-view number of data points.
Definition jurassic.h:1704
int sftype
Surface treatment (0=none, 1=emissions, 2=downward, 3=solar).
Definition jurassic.h:1647
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
Definition jurassic.h:1668
int ncl
Number of cloud layer spectral grid points.
Definition jurassic.h:1635
int ig_n2
Emitter index of N2.
Definition jurassic.h:1617
int obsfmt
Observation data file format (1=ASCII, 2=binary, 3=netCDF).
Definition jurassic.h:1665
int ctm_o2
Compute O2 continuum (0=no, 1=yes).
Definition jurassic.h:1683
int ret_clk
Retrieve cloud layer extinction (0=no, 1=yes).
Definition jurassic.h:1737
int nsf
Number of surface layer spectral grid points.
Definition jurassic.h:1641
double rayds
Maximum step length for raytracing [km].
Definition jurassic.h:1689
int ret_cldz
Retrieve cloud layer depth (0=no, 1=yes).
Definition jurassic.h:1734
int ig_h2o
Emitter index of H2O.
Definition jurassic.h:1614
int tblfmt
Look-up table file format (1=ASCII, 2=binary, 3=netCDF).
Definition jurassic.h:1656
double raydz
Vertical step length for raytracing [km].
Definition jurassic.h:1692
int write_bbt
Use brightness temperature instead of radiance (0=no, 1=yes).
Definition jurassic.h:1746
double retp_zmax
Maximum altitude for pressure retrieval [km].
Definition jurassic.h:1710
Line-of-sight data.
Definition jurassic.h:1775
double sft
Surface temperature [K].
Definition jurassic.h:1802
int np
Number of LOS points.
Definition jurassic.h:1778
Observation geometry and radiance data.
Definition jurassic.h:1837
int nr
Number of ray paths.
Definition jurassic.h:1840
Retrieval control parameters.
Definition jurassic.h:1892
double err_press_cz
Vertical correlation length for pressure error [km].
Definition jurassic.h:1919
double err_press
Pressure error [%].
Definition jurassic.h:1916
int err_ana
Carry out error analysis (0=no, 1=yes).
Definition jurassic.h:1907
double err_temp_cz
Vertical correlation length for temperature error [km].
Definition jurassic.h:1928
double conv_dmin
Minimum normalized step size in state space.
Definition jurassic.h:1904
double err_temp
Temperature error [K].
Definition jurassic.h:1925
double err_clz
Cloud height error [km].
Definition jurassic.h:1952
double err_sft
Surface temperature error [K].
Definition jurassic.h:1961
double err_temp_ch
Horizontal correlation length for temperature error [km].
Definition jurassic.h:1931
int kernel_recomp
Re-computation of kernel matrix (number of iterations).
Definition jurassic.h:1898
int conv_itmax
Maximum number of iterations.
Definition jurassic.h:1901
double err_cldz
Cloud depth error [km].
Definition jurassic.h:1955
double err_press_ch
Horizontal correlation length for pressure error [km].
Definition jurassic.h:1922
int shared_io_profile
Profile index used for shared netCDF retrieval inputs and outputs.
Definition jurassic.h:1967
Emissivity look-up tables.
Definition jurassic.h:2025