JURASSIC
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 {
165
166/* ------------------------------------------------------------
167 Constants...
168 ------------------------------------------------------------ */
169
171#ifndef C1
172#define C1 1.19104259e-8
173#endif
174
176#ifndef C2
177#define C2 1.43877506
178#endif
179
181#ifndef EPSMIN
182#define EPSMIN 0
183#endif
184
186#ifndef EPSMAX
187#define EPSMAX 1
188#endif
189
191#ifndef G0
192#define G0 9.80665
193#endif
194
196#ifndef H0
197#define H0 7.0
198#endif
199
201#ifndef KB
202#define KB 1.3806504e-23
203#endif
204
206#ifndef ME
207#define ME 5.976e24
208#endif
209
211#ifndef NA
212#define NA 6.02214199e23
213#endif
214
216#ifndef N2
217#define N2 0.78084
218#endif
219
221#ifndef O2
222#define O2 0.20946
223#endif
224
226#ifndef P0
227#define P0 1013.25
228#endif
229
231#ifndef RE
232#define RE 6367.421
233#endif
234
236#ifndef RI
237#define RI 8.3144598
238#endif
239
241#ifndef T0
242#define T0 273.15
243#endif
244
246#ifndef TMAX
247#define TMAX 400.
248#endif
249
251#ifndef TMIN
252#define TMIN 100.
253#endif
254
256#ifndef TSUN
257#define TSUN 5780.
258#endif
259
261#ifndef UMIN
262#define UMIN 0
263#endif
264
266#ifndef UMAX
267#define UMAX 1e30
268#endif
269
270/* ------------------------------------------------------------
271 Kernel finite-difference perturbations...
272 ------------------------------------------------------------ */
273
275#ifndef KERNEL_P_REL
276#define KERNEL_P_REL 0.01
277#endif
278
280#ifndef KERNEL_P_MIN
281#define KERNEL_P_MIN 1e-7
282#endif
283
285#ifndef KERNEL_T_ABS
286#define KERNEL_T_ABS 1.0
287#endif
288
290#ifndef KERNEL_Q_REL
291#define KERNEL_Q_REL 0.01
292#endif
293
295#ifndef KERNEL_Q_MIN
296#define KERNEL_Q_MIN 1e-15
297#endif
298
300#ifndef KERNEL_K_ABS
301#define KERNEL_K_ABS 1e-4
302#endif
303
305#ifndef KERNEL_CLZ_ABS
306#define KERNEL_CLZ_ABS 0.1
307#endif
308
310#ifndef KERNEL_CLDZ_ABS
311#define KERNEL_CLDZ_ABS 0.1
312#endif
313
315#ifndef KERNEL_CLK_ABS
316#define KERNEL_CLK_ABS 1e-4
317#endif
318
320#ifndef KERNEL_SFT_ABS
321#define KERNEL_SFT_ABS 1.0
322#endif
323
325#ifndef KERNEL_SFEPS_ABS
326#define KERNEL_SFEPS_ABS 1e-2
327#endif
328
329/* ------------------------------------------------------------
330 Dimensions...
331 ------------------------------------------------------------ */
332
334#ifndef LEN
335#define LEN 10000
336#endif
337
339#ifndef M
340#define M (NR*ND)
341#endif
342
344#ifndef N
345#define N ((2 + NG + NW) * NP + NCL + NSF + 3)
346#endif
347
349#ifndef NCL
350#define NCL 8
351#endif
352
354#ifndef ND
355#define ND 128
356#endif
357
359#ifndef NFOV
360#define NFOV 5
361#endif
362
364#ifndef NG
365#define NG 8
366#endif
367
369#ifndef CT
370#define CT 12
371#endif
372
375#ifndef CZ
376#define CZ 151
377#endif
378
381#ifndef CLAT
382#define CLAT 36
383#endif
384
386#ifndef NLOS
387#define NLOS 4096
388#endif
389
391#ifndef NP
392#define NP 256
393#endif
394
396#ifndef NQ
397#define NQ (5 + NG + NW + NCL + NSF)
398#endif
399
401#ifndef NR
402#define NR 256
403#endif
404
406#ifndef NSF
407#define NSF 8
408#endif
409
411#ifndef NSHAPE
412#define NSHAPE 20000
413#endif
414
416#ifndef NTIMER
417#define NTIMER 100
418#endif
419
421#ifndef NW
422#define NW 4
423#endif
424
426#ifndef RFMNPTS
427#define RFMNPTS 10000000
428#endif
429
431#ifndef TBLNP
432#define TBLNP 41
433#endif
434
436#ifndef TBLNS
437#define TBLNS 1200
438#endif
439
441#ifndef TBLNT
442#define TBLNT 30
443#endif
444
446#ifndef TBLNU
447#define TBLNU 512
448#endif
449
450/* ------------------------------------------------------------
451 Quantity indices...
452 ------------------------------------------------------------ */
453
455#define IDXP 0
456
458#define IDXT 1
459
461#define IDXQ(ig) (2 + (ig))
462
464#define IDXK(iw) (2 + (ctl->ng) + (iw))
465
467#define IDXCLZ (2 + (ctl->ng) + (ctl->nw))
468
470#define IDXCLDZ (3 + (ctl->ng) + (ctl->nw))
471
473#define IDXCLK(icl) (4 + (ctl->ng) + (ctl->nw) + (icl))
474
476#define IDXSFT (4 + (ctl->ng) + (ctl->nw) + (ctl->ncl))
477
479#define IDXSFEPS(isf) (5 + (ctl->ng) + (ctl->nw) + (ctl->ncl) + (isf))
480
481/* ------------------------------------------------------------
482 Macros...
483 ------------------------------------------------------------ */
484
502#define ALLOC(ptr, type, n) \
503 if((ptr=calloc((size_t)(n), sizeof(type)))==NULL) \
504 ERRMSG("Out of memory!");
505
532#define BRIGHT(rad, nu) \
533 (C2 * (nu) / gsl_log1p(C1 * POW3(nu) / (rad)))
534
554#define CLAMP(v, lo, hi) \
555 (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v)))
556
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.)))
574
589#define DEG2RAD(deg) ((deg) * (M_PI / 180.0))
590
607#define DIST(a, b) sqrt(DIST2(a, b))
608
624#define 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]))
626
642#define DOTP(a, b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
643
659#define FMOD(x, y) \
660 ((x) - (int) ((x) / (y)) * (y))
661
680#define FREAD(ptr, type, size, out) { \
681 if(fread(ptr, sizeof(type), size, out)!=size) \
682 ERRMSG("Error while reading!"); \
683 }
684
703#define FWRITE(ptr, type, size, out) { \
704 if(fwrite(ptr, sizeof(type), size, out)!=size) \
705 ERRMSG("Error while writing!"); \
706 }
707
726#define LIN(x0, y0, x1, y1, x) \
727 ((y0)+((y1)-(y0))/((x1)-(x0))*((x)-(x0)))
728
747#define LOGY(x0, y0, x1, y1, x) \
748 (((y1)/(y0)>0) \
749 ? ((y0)*exp(log((y1)/(y0))/((x1)-(x0))*((x)-(x0)))) \
750 : LIN(x0, y0, x1, y1, x))
751
768#define MAX(a,b) (((a)>(b))?(a):(b))
769
786#define MIN(a,b) (((a)<(b))?(a):(b))
787
799#define NC(cmd) { \
800 int nc_result=(cmd); \
801 if(nc_result!=NC_NOERR) \
802 ERRMSG("%s", nc_strerror(nc_result)); \
803 }
804
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); \
834 if((level) != 0) { \
835 NC(nc_def_var_deflate(ncid, varid, 1, 1, level)); \
836 /* unsigned int ulevel = (unsigned int)level; */ \
837 /* NC(nc_def_var_filter(ncid, varid, 32015, 1, (unsigned int[]){ulevel})); */ \
838 } \
839 }
840
852#ifdef NC_QUANTIZE_GRANULARBR
853#define NC_DEF_VAR_QUANTIZE(quant) do { \
854 if((quant) > 0) \
855 NC(nc_def_var_quantize(ncid, varid, NC_QUANTIZE_GRANULARBR, quant)); \
856 } while(0)
857#else
858#define NC_DEF_VAR_QUANTIZE(quant) do { \
859 if((quant) > 0) \
860 ERRMSG("NetCDF quantization is not supported by this NetCDF version"); \
861 } while(0)
862#endif
863
881#define NC_GET_DOUBLE(varname, ptr, force) { \
882 if(force) { \
883 NC(nc_inq_varid(ncid, varname, &varid)); \
884 NC(nc_get_var_double(ncid, varid, ptr)); \
885 } else { \
886 if(nc_inq_varid(ncid, varname, &varid) == NC_NOERR) { \
887 NC(nc_get_var_double(ncid, varid, ptr)); \
888 } else \
889 WARN("netCDF variable %s is missing!", varname); \
890 } \
891 }
892
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)); \
914 *ptr = (int)naux; \
915 if (check) \
916 if ((*ptr) < (min) || (*ptr) > (max)) \
917 ERRMSG("Dimension %s is out of range!", dimname); \
918 }
919
934#define NC_PUT_DOUBLE(varname, ptr, hyperslab) { \
935 NC(nc_inq_varid(ncid, varname, &varid)); \
936 if(hyperslab) { \
937 NC(nc_put_vara_double(ncid, varid, start, count, ptr)); \
938 } else { \
939 NC(nc_put_var_double(ncid, varid, ptr)); \
940 } \
941 }
942
958#define NC_PUT_FLOAT(varname, ptr, hyperslab) { \
959 NC(nc_inq_varid(ncid, varname, &varid)); \
960 if(hyperslab) { \
961 NC(nc_put_vara_float(ncid, varid, start, count, ptr)); \
962 } else { \
963 NC(nc_put_var_float(ncid, varid, ptr)); \
964 } \
965 }
966
981#define NC_PUT_INT(varname, ptr, hyperslab) { \
982 NC(nc_inq_varid(ncid, varname, &varid)); \
983 if(hyperslab) { \
984 NC(nc_put_vara_int(ncid, varid, start, count, ptr)); \
985 } else { \
986 NC(nc_put_var_int(ncid, varid, ptr)); \
987 } \
988 }
989
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)); \
1006 }
1007
1020#define NC_PUT_ATT_GLOBAL(attname, text) \
1021 NC(nc_put_att_text(ncid, NC_GLOBAL, attname, strnlen(text, LEN), text));
1022
1052#define NEDT(t_bg, nesr, nu) \
1053 (BRIGHT(PLANCK((t_bg), (nu)) + (nesr), (nu)) - (t_bg))
1054
1081#define NESR(t_bg, nedt, nu) \
1082 (PLANCK((t_bg) + (nedt), (nu)) - PLANCK((t_bg), (nu)))
1083
1098#define NORM(a) sqrt(DOTP(a, a))
1099
1129#define PLANCK(T, nu) \
1130 (C1 * POW3(nu) / gsl_expm1(C2 * (nu) / (T)))
1131
1143#define POW2(x) ((x)*(x))
1144
1156#define POW3(x) ((x)*(x)*(x))
1157
1172#define RAD2DEG(rad) ((rad) * (180.0 / M_PI))
1173
1202#define REFRAC_SW53(p, T, h2o) \
1203 (1e-6 * (77.6 * (p) / (T) + 3.73e5 * (h2o) * (p) / ((T) * (T))))
1204
1229#define REFRAC_EDLEN(p, T) \
1230 ((1e-8 \
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)))
1234
1249#define TBL_LOG(tbl, id, ig) \
1250 do { \
1251 for (int ip = 0; ip < (tbl)->np[(id)][(ig)]; ip++) \
1252 LOG(2, \
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", \
1256 (ip), \
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])); \
1270 } while (0)
1271
1283#define SELECT_TIMER(id, group) \
1284 {timer_group(id, group, 0);}
1285
1293#define PRINT_TIMERS \
1294 {timer_group("END", "END", 1);}
1295
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!"); \
1318 }
1319
1331#define USAGE \
1332 do { \
1333 int iusage; \
1334 for (iusage = 1; iusage < argc; iusage++) \
1335 if (!strcmp(argv[iusage], "-h") \
1336 || !strcmp(argv[iusage], "--help")) { \
1337 usage(); \
1338 return EXIT_SUCCESS; \
1339 } \
1340 } while (0)
1341
1342/* ------------------------------------------------------------
1343 Log messages...
1344 ------------------------------------------------------------ */
1345
1347#ifndef LOGLEV
1348#define LOGLEV 2
1349#endif
1350
1380#define LOG(level, ...) { \
1381 if(level >= 2) \
1382 printf(" "); \
1383 if(level <= LOGLEV) { \
1384 printf(__VA_ARGS__); \
1385 printf("\n"); \
1386 } \
1387 }
1388
1417#define WARN(...) { \
1418 printf("\nWarning (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1419 LOG(0, __VA_ARGS__); \
1420 }
1421
1450#define ERRMSG(...) { \
1451 printf("\nError (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1452 LOG(0, __VA_ARGS__); \
1453 exit(EXIT_FAILURE); \
1454 }
1455
1485#define PRINT(format, var) \
1486 printf("Print (%s, %s, l%d): %s= "format"\n", \
1487 __FILE__, __func__, __LINE__, #var, var);
1488
1489/* ------------------------------------------------------------
1490 Structs...
1491 ------------------------------------------------------------ */
1492
1500typedef struct {
1501
1503 int np;
1504
1506 double time[NP];
1507
1509 double z[NP];
1510
1512 double lon[NP];
1513
1515 double lat[NP];
1516
1518 double p[NP];
1519
1521 double t[NP];
1522
1524 double q[NG][NP];
1525
1527 double k[NW][NP];
1528
1530 double clz;
1531
1533 double cldz;
1534
1536 double clk[NCL];
1537
1539 double sft;
1540
1542 double sfeps[NSF];
1543
1544} atm_t;
1545
1552typedef struct {
1554 int nalt;
1555
1557 int nlat;
1558
1561
1563 double alt[CZ];
1564
1566 double lat[CLAT];
1567
1569 double time[CT];
1570
1572 double t[CT][CZ][CLAT];
1573
1575 double q[NG][CT][CZ][CLAT];
1576
1579
1581 int has_q[NG];
1582
1583} clim_t;
1584
1592typedef struct {
1593
1595 int ng;
1596
1598 char emitter[NG][LEN];
1599
1602
1605
1608
1611
1613 int nd;
1614
1616 double nu[ND];
1617
1619 int nw;
1620
1622 int window[ND];
1623
1625 int ncl;
1626
1628 double clnu[NCL];
1629
1631 int nsf;
1632
1634 double sfnu[NSF];
1635
1638
1640 double sfsza;
1641
1643 char tblbase[LEN];
1644
1647
1649 char climfile[LEN];
1650
1653
1656
1659
1661 double hydz;
1662
1665
1668
1671
1674
1677
1679 double rayds;
1680
1682 double raydz;
1683
1685 char fov[LEN];
1686
1688 double fov_dz[NSHAPE];
1689
1691 double fov_w[NSHAPE];
1692
1695
1698
1701
1704
1707
1709 double retq_zmin[NG];
1710
1712 double retq_zmax[NG];
1713
1715 double retk_zmin[NW];
1716
1718 double retk_zmax[NW];
1719
1722
1725
1728
1731
1734
1737
1740
1743
1745 char rfmbin[LEN];
1746
1748 char rfmhit[LEN];
1749
1751 char rfmxsc[NG][LEN];
1752
1753} ctl_t;
1754
1762typedef struct {
1763
1765 int np;
1766
1768 double z[NLOS];
1769
1771 double lon[NLOS];
1772
1774 double lat[NLOS];
1775
1777 double p[NLOS];
1778
1780 double t[NLOS];
1781
1783 double q[NLOS][NG];
1784
1786 double k[NLOS][ND];
1787
1789 double sft;
1790
1792 double sfeps[ND];
1793
1795 double ds[NLOS];
1796
1798 double u[NLOS][NG];
1799
1801 double cgp[NLOS][NG];
1802
1804 double cgt[NLOS][NG];
1805
1807 double cgu[NLOS][NG];
1808
1810 double eps[NLOS][ND];
1811
1813 double src[NLOS][ND];
1814
1815} los_t;
1816
1824typedef struct {
1825
1827 int nr;
1828
1830 double time[NR];
1831
1833 double obsz[NR];
1834
1836 double obslon[NR];
1837
1839 double obslat[NR];
1840
1842 double vpz[NR];
1843
1845 double vplon[NR];
1846
1848 double vplat[NR];
1849
1851 double tpz[NR];
1852
1854 double tplon[NR];
1855
1857 double tplat[NR];
1858
1860 double tau[ND][NR];
1861
1863 double rad[ND][NR];
1864
1866 int mask[ND][NR];
1867
1868} obs_t;
1869
1879typedef struct {
1880
1882 char dir[LEN];
1883
1886
1889
1892
1895
1897 double err_formod[ND];
1898
1900 double err_noise[ND];
1901
1904
1907
1910
1912 double err_temp;
1913
1916
1919
1921 double err_q[NG];
1922
1924 double err_q_cz[NG];
1925
1927 double err_q_ch[NG];
1928
1930 double err_k[NW];
1931
1933 double err_k_cz[NW];
1934
1936 double err_k_ch[NW];
1937
1939 double err_clz;
1940
1942 double err_cldz;
1943
1945 double err_clk[NCL];
1946
1948 double err_sft;
1949
1951 double err_sfeps[NSF];
1952
1955
1957 char shared_io_proflist[LEN];
1958
1960 char shared_io_atm_apr_file[LEN];
1961
1963 char shared_io_obs_meas_file[LEN];
1964
1966 char shared_io_atm_final_file[LEN];
1967
1969 char shared_io_obs_final_file[LEN];
1970
1972 char shared_io_matrix_cov_apr_file[LEN];
1973
1975 char shared_io_matrix_kernel_file[LEN];
1976
1978 char shared_io_matrix_cov_ret_file[LEN];
1979
1981 char shared_io_matrix_corr_file[LEN];
1982
1984 char shared_io_matrix_gain_file[LEN];
1985
1987 char shared_io_matrix_avk_file[LEN];
1988
1990 char shared_io_atm_err_total_file[LEN];
1991
1993 char shared_io_atm_err_noise_file[LEN];
1994
1996 char shared_io_atm_err_formod_file[LEN];
1997
1999 char shared_io_atm_cont_file[LEN];
2000
2002 char shared_io_atm_res_file[LEN];
2003
2004} ret_t;
2005
2012typedef struct {
2013
2015 int np[ND][NG];
2016
2018 int nt[ND][NG][TBLNP];
2019
2021 int nu[ND][NG][TBLNP][TBLNT];
2022
2024 double p[ND][NG][TBLNP];
2025
2027 double lnp[ND][NG][TBLNP];
2028
2030 double t[ND][NG][TBLNP][TBLNT];
2031
2033 float *logu[ND][NG][TBLNP][TBLNT];
2034
2036 float *logeps[ND][NG][TBLNP][TBLNT];
2037
2039 int filt_n[ND];
2040
2042 double filt_nu[ND][NSHAPE];
2043
2045 double filt_f[ND][NSHAPE];
2046
2048 double st[TBLNS];
2049
2051 double sr[TBLNS][ND];
2052
2053} tbl_t;
2054
2055/* ------------------------------------------------------------
2056 Functions...
2057 ------------------------------------------------------------ */
2058
2110void analyze_avk(
2111 const ret_t * ret,
2112 const ctl_t * ctl,
2113 const atm_t * atm,
2114 const int *iqa,
2115 const int *ipa,
2116 const gsl_matrix * avk);
2117
2174 const gsl_matrix * avk,
2175 const int iq,
2176 const int *ipa,
2177 const size_t *n0,
2178 const size_t *n1,
2179 double *cont,
2180 double *res);
2181
2208size_t atm2x(
2209 const ctl_t * ctl,
2210 const atm_t * atm,
2211 gsl_vector * x,
2212 int *iqa,
2213 int *ipa);
2214
2236void atm2x_help(
2237 const double value,
2238 const int value_iqa,
2239 const int value_ip,
2240 gsl_vector * x,
2241 int *iqa,
2242 int *ipa,
2243 size_t *n);
2244
2259void cart2geo(
2260 const double *x,
2261 double *z,
2262 double *lon,
2263 double *lat);
2264
2283void climatology(
2284 const ctl_t * ctl,
2285 const clim_t * clim,
2286 atm_t * atm);
2287
2316int read_clim_field(
2317 const char *filename,
2318 const char *varname,
2319 const int ncid,
2320 const int dim_month,
2321 const int dim_alt,
2322 const int dim_lat,
2323 const int nalt,
2324 const int nlat,
2325 double field[CT][CZ][CLAT],
2326 double *vmin,
2327 double *vmax);
2328
2361 const clim_t * clim,
2362 const atm_t * atm,
2363 const double field[CT][CZ][CLAT],
2364 const int top_policy,
2365 double *out);
2366
2395 const ctl_t * ctl);
2396
2413 const ctl_t * ctl,
2414 const clim_t * clim,
2415 atm_t * atm);
2416
2441double cos_sza(
2442 const double sec,
2443 const double lon,
2444 const double lat);
2445
2485double cost_function(
2486 const gsl_vector * dx,
2487 const gsl_vector * dy,
2488 const gsl_matrix * s_a_inv,
2489 const gsl_vector * sig_eps_inv);
2490
2512double ctmco2(
2513 const double nu,
2514 const double p,
2515 const double t,
2516 const double u);
2517
2523double ctmh2o(
2524 const double nu,
2525 const double p,
2526 const double t,
2527 const double q,
2528 const double u);
2529
2561double ctmn2(
2562 const double nu,
2563 const double p,
2564 const double t);
2565
2595double ctmo2(
2596 const double nu,
2597 const double p,
2598 const double t);
2599
2624void copy_atm(
2625 const ctl_t * ctl,
2626 atm_t * atm_dest,
2627 const atm_t * atm_src,
2628 const int init);
2629
2654void copy_obs(
2655 const ctl_t * ctl,
2656 obs_t * obs_dest,
2657 const obs_t * obs_src,
2658 const int init);
2659
2680void day2doy(
2681 int year,
2682 int mon,
2683 int day,
2684 int *doy);
2685
2708void doy2day(
2709 int year,
2710 int doy,
2711 int *mon,
2712 int *day);
2713
2733int find_emitter(
2734 const ctl_t * ctl,
2735 const char *emitter);
2736
2772int formod(
2773 const ctl_t * ctl,
2774 const tbl_t * tbl,
2775 atm_t * atm,
2776 obs_t * obs,
2777 los_t * los_scratch,
2778 obs_t * obs_scratch);
2779
2799void formod_batch(
2800 const ctl_t * ctl,
2801 const tbl_t * tbl,
2802 atm_t * atm,
2803 obs_t * obs,
2804 const int nbatch,
2805 int *status,
2806 los_t * los_scratch,
2807 obs_t * obs_scratch);
2808
2834void formod_continua(
2835 const ctl_t * ctl,
2836 const los_t * los,
2837 const int ip,
2838 double *beta);
2839
2863int formod_fov(
2864 const ctl_t * ctl,
2865 obs_t * obs,
2866 obs_t * obs_scratch);
2867
2900int formod_pencil(
2901 const ctl_t * ctl,
2902 const tbl_t * tbl,
2903 const atm_t * atm,
2904 obs_t * obs,
2905 const int ir,
2906 los_t * los);
2907
2959void formod_rfm(
2960 const ctl_t * ctl,
2961 const tbl_t * tbl,
2962 const atm_t * atm,
2963 obs_t * obs);
2964
2989void formod_srcfunc(
2990 const ctl_t * ctl,
2991 const tbl_t * tbl,
2992 const double t,
2993 double *src);
2994
3021void geo2cart(
3022 const double z,
3023 const double lon,
3024 const double lat,
3025 double *x);
3026
3054void hydrostatic(
3055 const ctl_t * ctl,
3056 atm_t * atm);
3057
3081void idx2name(
3082 const ctl_t * ctl,
3083 const int idx,
3084 char *quantity);
3085
3115void init_srcfunc(
3116 const ctl_t * ctl,
3117 tbl_t * tbl);
3118
3143void intpol_atm(
3144 const ctl_t * ctl,
3145 const atm_t * atm,
3146 const double z,
3147 double *p,
3148 double *t,
3149 double *q,
3150 double *k);
3151
3185void intpol_tbl_cga(
3186 const ctl_t * ctl,
3187 const tbl_t * tbl,
3188 const los_t * los,
3189 const int ip,
3190 double tau_path[ND][NG],
3191 double tau_seg[ND]);
3192
3231void intpol_tbl_ega(
3232 const ctl_t * ctl,
3233 const tbl_t * tbl,
3234 const los_t * los,
3235 const int ip,
3236 double tau_path[ND][NG],
3237 double tau_seg[ND]);
3238
3265double intpol_tbl_eps(
3266 const tbl_t * tbl,
3267 const int ig,
3268 const int id,
3269 const int ip,
3270 const int it,
3271 const double logu);
3272
3303double intpol_tbl_u(
3304 const tbl_t * tbl,
3305 const int ig,
3306 const int id,
3307 const int ip,
3308 const int it,
3309 const double logeps);
3310
3337void jsec2time(
3338 const double jsec,
3339 int *year,
3340 int *mon,
3341 int *day,
3342 int *hour,
3343 int *min,
3344 int *sec,
3345 double *remain);
3346
3393void kernel(
3394 const ctl_t * ctl,
3395 const tbl_t * tbl,
3396 atm_t * atm,
3397 obs_t * obs,
3398 gsl_matrix * k);
3399
3426int locate_irr(
3427 const double *xx,
3428 const int n,
3429 const double x);
3430
3457int locate_reg(
3458 const double *xx,
3459 const int n,
3460 const double x);
3461
3487int locate_tbl(
3488 const float *xx,
3489 const int n,
3490 const double x);
3491
3530void matrix_invert(
3531 gsl_matrix * a);
3532
3577void matrix_product(
3578 const gsl_matrix * a,
3579 const gsl_vector * b,
3580 const int transpose,
3581 gsl_matrix * c);
3582
3610size_t obs2y(
3611 const ctl_t * ctl,
3612 const obs_t * obs,
3613 gsl_vector * y,
3614 int *ida,
3615 int *ira);
3616
3668 ret_t * ret,
3669 ctl_t * ctl,
3670 tbl_t * tbl,
3671 obs_t * obs_meas,
3672 obs_t * obs_i,
3673 atm_t * atm_apr,
3674 atm_t * atm_i,
3675 double *chisq);
3676
3724int raytrace(
3725 const ctl_t * ctl,
3726 const atm_t * atm,
3727 obs_t * obs,
3728 los_t * los,
3729 const int ir);
3730
3780void read_atm(
3781 const char *dirname,
3782 const char *filename,
3783 const ctl_t * ctl,
3784 atm_t * atm,
3785 int profile);
3786
3833void read_atm_asc(
3834 const char *filename,
3835 const ctl_t * ctl,
3836 atm_t * atm);
3837
3887void read_atm_bin(
3888 const char *filename,
3889 const ctl_t * ctl,
3890 atm_t * atm);
3891
3933void read_atm_nc(
3934 const char *filename,
3935 const ctl_t * ctl,
3936 atm_t * atm,
3937 int profile);
3938
3979void read_ctl(
3980 int argc,
3981 char *argv[],
3982 ctl_t * ctl);
3983
4002void read_matrix(
4003 const char *dirname,
4004 const char *filename,
4005 const ctl_t * ctl,
4006 gsl_matrix * matrix,
4007 int dataset);
4008
4040void read_matrix_asc(
4041 const char *dirname,
4042 const char *filename,
4043 gsl_matrix * matrix);
4044
4062void read_matrix_bin(
4063 const char *dirname,
4064 const char *filename,
4065 gsl_matrix * matrix);
4066
4088void read_matrix_nc(
4089 const char *dirname,
4090 const char *filename,
4091 gsl_matrix * matrix,
4092 int dataset);
4093
4130void read_obs(
4131 const char *dirname,
4132 const char *filename,
4133 const ctl_t * ctl,
4134 obs_t * obs,
4135 int profile);
4136
4174void read_obs_asc(
4175 const char *filename,
4176 const ctl_t * ctl,
4177 obs_t * obs);
4178
4220void read_obs_bin(
4221 const char *filename,
4222 const ctl_t * ctl,
4223 obs_t * obs);
4224
4257void read_obs_nc(
4258 const char *filename,
4259 const ctl_t * ctl,
4260 obs_t * obs,
4261 const int profile);
4262
4302double read_obs_rfm(
4303 const char *basename,
4304 const double z,
4305 const double *nu,
4306 const double *f,
4307 const int n);
4308
4383void read_ret(
4384 int argc,
4385 char *argv[],
4386 const ctl_t * ctl,
4387 ret_t * ret);
4388
4430void read_rfm_spec(
4431 const char *filename,
4432 double *nu,
4433 double *rad,
4434 int *npts);
4435
4469void read_shape(
4470 const char *filename,
4471 double *x,
4472 double *y,
4473 int *n);
4474
4511 const ctl_t * ctl);
4512
4548void read_tbl_asc(
4549 const ctl_t * ctl,
4550 tbl_t * tbl,
4551 const int id,
4552 const int ig);
4553
4585void read_tbl_bin(
4586 const ctl_t * ctl,
4587 tbl_t * tbl,
4588 const int id,
4589 const int ig);
4590
4634 const ctl_t * ctl,
4635 tbl_t * tbl,
4636 int id,
4637 int ig,
4638 int ncid);
4639
4694double scan_ctl(
4695 int argc,
4696 char *argv[],
4697 const char *varname,
4698 const int arridx,
4699 const char *defvalue,
4700 char *value);
4701
4755void set_cov_apr(
4756 const ret_t * ret,
4757 const ctl_t * ctl,
4758 const atm_t * atm,
4759 const int *iqa,
4760 const int *ipa,
4761 gsl_matrix * s_a);
4762
4816void set_cov_meas(
4817 const ret_t * ret,
4818 const ctl_t * ctl,
4819 const obs_t * obs,
4820 gsl_vector * sig_noise,
4821 gsl_vector * sig_formod,
4822 gsl_vector * sig_eps_inv);
4823
4850const char *shared_io_input_target(
4851 const ret_t * ret,
4852 const char *shared_file,
4853 const char *legacy_file,
4854 const char **dirname,
4855 int *profile);
4856
4883const char *shared_io_output_target(
4884 const ret_t * ret,
4885 const char *shared_file,
4886 const char *legacy_file,
4887 const char **dirname,
4888 int *profile);
4889
4910int shared_io_lock(
4911 const ret_t * ret);
4912
4927void shared_io_unlock(
4928 int fd);
4929
4950const char *shared_io_output_file(
4951 const ret_t * ret);
4952
4992void tangent_point(
4993 const los_t * los,
4994 double *tpz,
4995 double *tplon,
4996 double *tplat);
4997
5019void tbl_free(
5020 const ctl_t * ctl,
5021 tbl_t * tbl);
5022
5062void tbl_pack(
5063 const tbl_t * tbl,
5064 int id,
5065 int ig,
5066 uint8_t * buf,
5067 size_t *bytes_used);
5068
5079size_t tbl_packed_size(
5080 const tbl_t * tbl,
5081 int id,
5082 int ig);
5083
5122size_t tbl_unpack(
5123 tbl_t * tbl,
5124 int id,
5125 int ig,
5126 const uint8_t * buf);
5127
5128
5153void time2jsec(
5154 const int year,
5155 const int mon,
5156 const int day,
5157 const int hour,
5158 const int min,
5159 const int sec,
5160 const double remain,
5161 double *jsec);
5162
5177void timer_group(
5178 const char *name,
5179 const char *group,
5180 int output);
5181
5230void write_atm(
5231 const char *dirname,
5232 const char *filename,
5233 const ctl_t * ctl,
5234 const atm_t * atm,
5235 int profile);
5236
5288void write_atm_asc(
5289 const char *filename,
5290 const ctl_t * ctl,
5291 const atm_t * atm);
5292
5346void write_atm_bin(
5347 const char *filename,
5348 const ctl_t * ctl,
5349 const atm_t * atm);
5350
5398void write_atm_nc(
5399 const char *filename,
5400 const ctl_t * ctl,
5401 const atm_t * atm,
5402 int profile);
5403
5455void write_atm_rfm(
5456 const char *filename,
5457 const ctl_t * ctl,
5458 const atm_t * atm);
5459
5483void write_matrix(
5484 const char *dirname,
5485 const char *filename,
5486 const ctl_t * ctl,
5487 const gsl_matrix * matrix,
5488 const atm_t * atm,
5489 const obs_t * obs,
5490 const char *rowspace,
5491 const char *colspace,
5492 const char *sort,
5493 int dataset);
5494
5542void write_matrix_asc(
5543 const char *dirname,
5544 const char *filename,
5545 const ctl_t * ctl,
5546 const gsl_matrix * matrix,
5547 const atm_t * atm,
5548 const obs_t * obs,
5549 const char *rowspace,
5550 const char *colspace,
5551 const char *sort);
5552
5567void write_matrix_bin(
5568 const char *dirname,
5569 const char *filename,
5570 const gsl_matrix * matrix);
5571
5598void write_matrix_nc(
5599 const char *dirname,
5600 const char *filename,
5601 const ctl_t * ctl,
5602 const gsl_matrix * matrix,
5603 const atm_t * atm,
5604 const obs_t * obs,
5605 const char *rowspace,
5606 const char *colspace,
5607 const char *sort,
5608 int dataset);
5609
5645void write_obs(
5646 const char *dirname,
5647 const char *filename,
5648 const ctl_t * ctl,
5649 const obs_t * obs,
5650 int profile);
5651
5690void write_obs_asc(
5691 const char *filename,
5692 const ctl_t * ctl,
5693 const obs_t * obs);
5694
5732void write_obs_bin(
5733 const char *filename,
5734 const ctl_t * ctl,
5735 const obs_t * obs);
5736
5774void write_obs_nc(
5775 const char *filename,
5776 const ctl_t * ctl,
5777 const obs_t * obs,
5778 const int profile);
5779
5814void write_shape(
5815 const char *filename,
5816 const double *x,
5817 const double *y,
5818 const int n);
5819
5865void write_stddev(
5866 const char *quantity,
5867 const ret_t * ret,
5868 const ctl_t * ctl,
5869 const atm_t * atm,
5870 const gsl_matrix * s);
5871
5907void write_tbl(
5908 const ctl_t * ctl,
5909 const tbl_t * tbl);
5910
5936void write_tbl_asc(
5937 const ctl_t * ctl,
5938 const tbl_t * tbl,
5939 const int id,
5940 const int ig);
5941
5969void write_tbl_bin(
5970 const ctl_t * ctl,
5971 const tbl_t * tbl,
5972 const int id,
5973 const int ig);
5974
6007void write_tbl_nc(
6008 const ctl_t * ctl,
6009 const tbl_t * tbl,
6010 const int id,
6011 const int ig);
6012
6059void x2atm(
6060 const ctl_t * ctl,
6061 const gsl_vector * x,
6062 atm_t * atm);
6063
6092void x2atm_help(
6093 double *value,
6094 const gsl_vector * x,
6095 size_t *n);
6096
6129void y2obs(
6130 const ctl_t * ctl,
6131 const gsl_vector * y,
6132 obs_t * obs);
6133
6134#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:4967
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:29
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:7268
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:335
@ 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
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:1639
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:6844
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:8044
void read_rfm_spec(const char *filename, double *nu, double *rad, int *npts)
Read a Reference Forward Model (RFM) ASCII spectrum.
Definition: jurassic.c:6966
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:7778
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:6519
double cos_sza(const double sec, const double lon, const double lat)
Calculates the cosine of the solar zenith angle.
Definition: jurassic.c:1598
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:5715
void read_atm_bin(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in binary format.
Definition: jurassic.c:6073
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:9083
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:4362
int locate_reg(const double *xx, const int n, const double x)
Locate index for interpolation on a regular (uniform) grid.
Definition: jurassic.c:5248
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:4865
double ctmo2(const double nu, const double p, const double t)
Compute O₂ collision-induced absorption coefficient.
Definition: jurassic.c:3772
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:9207
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
Definition: jurassic.c:7739
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:9502
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:9586
void idx2name(const ctl_t *ctl, const int idx, char *quantity)
Convert a quantity index to a descriptive name string.
Definition: jurassic.c:4661
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:6271
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:4080
void climatology(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Initializes atmospheric climatology profiles.
Definition: jurassic.c:215
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:6687
int shared_io_lock(const ret_t *ret)
Acquire an exclusive lock for shared retrieval output files.
Definition: jurassic.c:7617
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:6568
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:5319
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:4178
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:1578
int locate_irr(const double *xx, const int n, const double x)
Locate index for interpolation on an irregular grid.
Definition: jurassic.c:5218
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:7577
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:8527
void day2doy(int year, int mon, int day, int *doy)
Convert a calendar date to day-of-year.
Definition: jurassic.c:3922
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:8266
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:8490
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:7942
void x2atm(const ctl_t *ctl, const gsl_vector *x, atm_t *atm)
Map retrieval state vector back to atmospheric structure.
Definition: jurassic.c:9651
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:179
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:2533
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:9544
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:4772
void shared_io_unlock(int fd)
Release a shared retrieval output lock.
Definition: jurassic.c:7644
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:8453
#define ND
Maximum number of radiance channels.
Definition: jurassic.h:355
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:7528
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:9012
#define NSHAPE
Maximum number of shape function grid points.
Definition: jurassic.h:412
void write_tbl(const ctl_t *ctl, const tbl_t *tbl)
Write emissivity lookup tables to disk.
Definition: jurassic.c:9459
#define CT
Maximum number of time steps for climatological data.
Definition: jurassic.h:370
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:7866
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:6401
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:4747
int find_emitter(const ctl_t *ctl, const char *emitter)
Find gas species index by name.
Definition: jurassic.c:3972
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:5391
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:5012
void timer_group(const char *name, const char *group, int output)
Aggregate wall-clock timings for named code phases.
Definition: jurassic.c:7973
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:7696
double ctmco2(const double nu, const double p, const double t, const double u)
Compute carbon dioxide continuum optical depth.
Definition: jurassic.c:1670
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:5948
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:4116
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:8749
#define CLAT
Maximum number of latitudes for climatological data (JuMACS: 36 area-weighted 5-degree bands).
Definition: jurassic.h:382
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:8115
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:8700
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:3884
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:4036
#define TBLNT
Maximum number of temperatures in emissivity tables.
Definition: jurassic.h:442
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:9139
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:9701
void cart2geo(const double *x, double *z, double *lon, double *lat)
Converts Cartesian coordinates to geographic coordinates.
Definition: jurassic.c:200
#define NP
Maximum number of atmospheric data points.
Definition: jurassic.h:392
void doy2day(int year, int doy, int *mon, int *day)
Convert a day-of-year value to a calendar date.
Definition: jurassic.c:3942
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:5091
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:6765
void init_srcfunc(const ctl_t *ctl, tbl_t *tbl)
Initialize source function lookup tables from emissivity data.
Definition: jurassic.c:4700
void matrix_invert(gsl_matrix *a)
Invert a square matrix, optimized for diagonal or symmetric positive-definite matrices.
Definition: jurassic.c:5289
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
Definition: jurassic.c:6878
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:7349
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:9387
void read_atm_asc(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in ASCII format.
Definition: jurassic.c:6022
#define NG
Maximum number of emitters.
Definition: jurassic.h:365
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:7145
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:4566
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:101
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:5058
#define TBLNS
Maximum number of source function temperature levels.
Definition: jurassic.h:437
void read_matrix_asc(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from an ASCII file.
Definition: jurassic.c:6427
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
Definition: jurassic.c:7069
void read_matrix_bin(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from a binary file.
Definition: jurassic.c:6466
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:7312
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:7597
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:6167
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:3834
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:5364
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:9713
void hydrostatic(const ctl_t *ctl, atm_t *atm)
Adjust pressure profile using the hydrostatic equation.
Definition: jurassic.c:4601
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:7028
double ctmn2(const double nu, const double p, const double t)
Compute N₂ collision-induced absorption coefficient.
Definition: jurassic.c:3703
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:1258
#define CZ
Maximum number of altitudes for climatological data (JuMACS: 0...150 km at 1 km spacing).
Definition: jurassic.h:376
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:125
#define TBLNP
Maximum number of pressure levels in emissivity tables.
Definition: jurassic.h:432
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:4583
#define NSF
Maximum number of surface layer spectral grid points.
Definition: jurassic.h:407
#define NCL
Maximum number of cloud layer spectral grid points.
Definition: jurassic.h:350
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:7417
const char * shared_io_output_file(const ret_t *ret)
Return the primary shared retrieval output file configured for locking.
Definition: jurassic.c:7662
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:9416
#define NLOS
Maximum number of LOS points.
Definition: jurassic.h:387
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:3985
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:7832
clim_t * read_clim(const ctl_t *ctl)
Reads a JuMACS climatology file into an allocated climatology structure.
Definition: jurassic.c:1361
#define NR
Maximum number of ray paths.
Definition: jurassic.h:402
int locate_tbl(const float *xx, const int n, const double x)
Locate index for interpolation within emissivity table grids.
Definition: jurassic.c:5267
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:8182
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:6643
#define NW
Maximum number of spectral windows.
Definition: jurassic.h:422
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:1166
Atmospheric profile data.
Definition: jurassic.h:1500
double clz
Cloud layer height [km].
Definition: jurassic.h:1530
int np
Number of data points.
Definition: jurassic.h:1503
double cldz
Cloud layer depth [km].
Definition: jurassic.h:1533
double sft
Surface temperature [K].
Definition: jurassic.h:1539
JuMACS climatology on a fixed grid.
Definition: jurassic.h:1552
int ntime
Number of climatological time coordinates.
Definition: jurassic.h:1560
int has_t
Set if a temperature field was read.
Definition: jurassic.h:1578
int nalt
Number of altitude levels.
Definition: jurassic.h:1554
int nlat
Number of latitude bands.
Definition: jurassic.h:1557
Control parameters.
Definition: jurassic.h:1592
int write_matrix
Write matrix file (0=no, 1=yes).
Definition: jurassic.h:1739
int nw
Number of spectral windows.
Definition: jurassic.h:1619
int atmfmt
Atmospheric data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1652
double retp_zmin
Minimum altitude for pressure retrieval [km].
Definition: jurassic.h:1697
int ig_co2
Emitter index of CO2.
Definition: jurassic.h:1601
double hydz
Reference height for hydrostatic pressure profile (-999 to skip) [km].
Definition: jurassic.h:1661
int ctm_co2
Compute CO2 continuum (0=no, 1=yes).
Definition: jurassic.h:1664
double rett_zmax
Maximum altitude for temperature retrieval [km].
Definition: jurassic.h:1706
int ret_sfeps
Retrieve surface layer emissivity (0=no, 1=yes).
Definition: jurassic.h:1733
int ret_sft
Retrieve surface layer temperature (0=no, 1=yes).
Definition: jurassic.h:1730
int ret_clz
Retrieve cloud layer height (0=no, 1=yes).
Definition: jurassic.h:1721
int ctm_n2
Compute N2 continuum (0=no, 1=yes).
Definition: jurassic.h:1670
int ctm_h2o
Compute H2O continuum (0=no, 1=yes).
Definition: jurassic.h:1667
int formod
Forward model (0=CGA, 1=EGA, 2=RFM).
Definition: jurassic.h:1742
int ng
Number of emitters.
Definition: jurassic.h:1595
int refrac
Take into account refractivity (0=no, 1=yes).
Definition: jurassic.h:1676
int ig_o2
Emitter index of O2.
Definition: jurassic.h:1610
double rett_zmin
Minimum altitude for temperature retrieval [km].
Definition: jurassic.h:1703
double sfsza
Solar zenith angle at the surface [deg] (-999=auto).
Definition: jurassic.h:1640
int nd
Number of radiance channels.
Definition: jurassic.h:1613
int fov_n
Field-of-view number of data points.
Definition: jurassic.h:1694
int sftype
Surface treatment (0=none, 1=emissions, 2=downward, 3=solar).
Definition: jurassic.h:1637
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1658
int ncl
Number of cloud layer spectral grid points.
Definition: jurassic.h:1625
int ig_n2
Emitter index of N2.
Definition: jurassic.h:1607
int obsfmt
Observation data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1655
int ctm_o2
Compute O2 continuum (0=no, 1=yes).
Definition: jurassic.h:1673
int ret_clk
Retrieve cloud layer extinction (0=no, 1=yes).
Definition: jurassic.h:1727
int nsf
Number of surface layer spectral grid points.
Definition: jurassic.h:1631
double rayds
Maximum step length for raytracing [km].
Definition: jurassic.h:1679
int ret_cldz
Retrieve cloud layer depth (0=no, 1=yes).
Definition: jurassic.h:1724
int ig_h2o
Emitter index of H2O.
Definition: jurassic.h:1604
int tblfmt
Look-up table file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1646
double raydz
Vertical step length for raytracing [km].
Definition: jurassic.h:1682
int write_bbt
Use brightness temperature instead of radiance (0=no, 1=yes).
Definition: jurassic.h:1736
double retp_zmax
Maximum altitude for pressure retrieval [km].
Definition: jurassic.h:1700
Line-of-sight data.
Definition: jurassic.h:1762
double sft
Surface temperature [K].
Definition: jurassic.h:1789
int np
Number of LOS points.
Definition: jurassic.h:1765
Observation geometry and radiance data.
Definition: jurassic.h:1824
int nr
Number of ray paths.
Definition: jurassic.h:1827
Retrieval control parameters.
Definition: jurassic.h:1879
double err_press_cz
Vertical correlation length for pressure error [km].
Definition: jurassic.h:1906
double err_press
Pressure error [%].
Definition: jurassic.h:1903
int err_ana
Carry out error analysis (0=no, 1=yes).
Definition: jurassic.h:1894
double err_temp_cz
Vertical correlation length for temperature error [km].
Definition: jurassic.h:1915
double conv_dmin
Minimum normalized step size in state space.
Definition: jurassic.h:1891
double err_temp
Temperature error [K].
Definition: jurassic.h:1912
double err_clz
Cloud height error [km].
Definition: jurassic.h:1939
double err_sft
Surface temperature error [K].
Definition: jurassic.h:1948
double err_temp_ch
Horizontal correlation length for temperature error [km].
Definition: jurassic.h:1918
int kernel_recomp
Re-computation of kernel matrix (number of iterations).
Definition: jurassic.h:1885
int conv_itmax
Maximum number of iterations.
Definition: jurassic.h:1888
double err_cldz
Cloud depth error [km].
Definition: jurassic.h:1942
double err_press_ch
Horizontal correlation length for pressure error [km].
Definition: jurassic.h:1909
int shared_io_profile
Profile index used for shared netCDF retrieval inputs and outputs.
Definition: jurassic.h:1954
Emissivity look-up tables.
Definition: jurassic.h:2012