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 Dimensions...
272 ------------------------------------------------------------ */
273
275#ifndef LEN
276#define LEN 10000
277#endif
278
280#ifndef M
281#define M (NR*ND)
282#endif
283
285#ifndef N
286#define N ((2 + NG + NW) * NP + NCL + NSF + 3)
287#endif
288
290#ifndef NCL
291#define NCL 8
292#endif
293
295#ifndef ND
296#define ND 128
297#endif
298
300#ifndef NFOV
301#define NFOV 5
302#endif
303
305#ifndef NG
306#define NG 8
307#endif
308
310#ifndef NLOS
311#define NLOS 4096
312#endif
313
315#ifndef NP
316#define NP 256
317#endif
318
320#ifndef NQ
321#define NQ (5 + NG + NW + NCL + NSF)
322#endif
323
325#ifndef NR
326#define NR 256
327#endif
328
330#ifndef NSF
331#define NSF 8
332#endif
333
335#ifndef NSHAPE
336#define NSHAPE 20000
337#endif
338
340#ifndef NTIMER
341#define NTIMER 100
342#endif
343
345#ifndef NW
346#define NW 4
347#endif
348
350#ifndef RFMNPTS
351#define RFMNPTS 10000000
352#endif
353
355#ifndef TBLNP
356#define TBLNP 41
357#endif
358
360#ifndef TBLNS
361#define TBLNS 1200
362#endif
363
365#ifndef TBLNT
366#define TBLNT 30
367#endif
368
370#ifndef TBLNU
371#define TBLNU 512
372#endif
373
374/* ------------------------------------------------------------
375 Quantity indices...
376 ------------------------------------------------------------ */
377
379#define IDXP 0
380
382#define IDXT 1
383
385#define IDXQ(ig) (2 + (ig))
386
388#define IDXK(iw) (2 + (ctl->ng) + (iw))
389
391#define IDXCLZ (2 + (ctl->ng) + (ctl->nw))
392
394#define IDXCLDZ (3 + (ctl->ng) + (ctl->nw))
395
397#define IDXCLK(icl) (4 + (ctl->ng) + (ctl->nw) + (icl))
398
400#define IDXSFT (4 + (ctl->ng) + (ctl->nw) + (ctl->ncl))
401
403#define IDXSFEPS(isf) (5 + (ctl->ng) + (ctl->nw) + (ctl->ncl) + (isf))
404
405/* ------------------------------------------------------------
406 Macros...
407 ------------------------------------------------------------ */
408
426#define ALLOC(ptr, type, n) \
427 if((ptr=calloc((size_t)(n), sizeof(type)))==NULL) \
428 ERRMSG("Out of memory!");
429
456#define BRIGHT(rad, nu) \
457 (C2 * (nu) / gsl_log1p(C1 * POW3(nu) / (rad)))
458
478#define CLAMP(v, lo, hi) \
479 (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v)))
480
493#define CO2_FIT(TIME) \
494 (373.87884731310215e-6 \
495 + 1.9021498612395775e-6 * (((TIME) - 94694400.) / 31557600.) \
496 + 0.016490044598136553e-6 \
497 * POW2((((TIME) - 94694400.) / 31557600.)))
498
513#define DEG2RAD(deg) ((deg) * (M_PI / 180.0))
514
531#define DIST(a, b) sqrt(DIST2(a, b))
532
548#define DIST2(a, b) \
549 ((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])+(a[2]-b[2])*(a[2]-b[2]))
550
566#define DOTP(a, b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
567
586#define FREAD(ptr, type, size, out) { \
587 if(fread(ptr, sizeof(type), size, out)!=size) \
588 ERRMSG("Error while reading!"); \
589 }
590
609#define FWRITE(ptr, type, size, out) { \
610 if(fwrite(ptr, sizeof(type), size, out)!=size) \
611 ERRMSG("Error while writing!"); \
612 }
613
632#define LIN(x0, y0, x1, y1, x) \
633 ((y0)+((y1)-(y0))/((x1)-(x0))*((x)-(x0)))
634
653#define LOGY(x0, y0, x1, y1, x) \
654 (((y1)/(y0)>0) \
655 ? ((y0)*exp(log((y1)/(y0))/((x1)-(x0))*((x)-(x0)))) \
656 : LIN(x0, y0, x1, y1, x))
657
674#define MAX(a,b) (((a)>(b))?(a):(b))
675
692#define MIN(a,b) (((a)<(b))?(a):(b))
693
705#define NC(cmd) { \
706 int nc_result=(cmd); \
707 if(nc_result!=NC_NOERR) \
708 ERRMSG("%s", nc_strerror(nc_result)); \
709 }
710
735#define NC_DEF_VAR(varname, type, ndims, dims, long_name, units, level, quant) { \
736 NC(nc_def_var(ncid, varname, type, ndims, dims, &varid)); \
737 NC(nc_put_att_text(ncid, varid, "long_name", strnlen(long_name, LEN), long_name)); \
738 NC(nc_put_att_text(ncid, varid, "units", strnlen(units, LEN), units)); \
739 NC_DEF_VAR_QUANTIZE(quant); \
740 if((level) != 0) { \
741 NC(nc_def_var_deflate(ncid, varid, 1, 1, level)); \
742 /* unsigned int ulevel = (unsigned int)level; */ \
743 /* NC(nc_def_var_filter(ncid, varid, 32015, 1, (unsigned int[]){ulevel})); */ \
744 } \
745 }
746
758#ifdef NC_QUANTIZE_GRANULARBR
759#define NC_DEF_VAR_QUANTIZE(quant) do { \
760 if((quant) > 0) \
761 NC(nc_def_var_quantize(ncid, varid, NC_QUANTIZE_GRANULARBR, quant)); \
762 } while(0)
763#else
764#define NC_DEF_VAR_QUANTIZE(quant) do { \
765 if((quant) > 0) \
766 ERRMSG("NetCDF quantization is not supported by this NetCDF version"); \
767 } while(0)
768#endif
769
787#define NC_GET_DOUBLE(varname, ptr, force) { \
788 if(force) { \
789 NC(nc_inq_varid(ncid, varname, &varid)); \
790 NC(nc_get_var_double(ncid, varid, ptr)); \
791 } else { \
792 if(nc_inq_varid(ncid, varname, &varid) == NC_NOERR) { \
793 NC(nc_get_var_double(ncid, varid, ptr)); \
794 } else \
795 WARN("netCDF variable %s is missing!", varname); \
796 } \
797 }
798
816#define NC_INQ_DIM(dimname, ptr, min, max, check) { \
817 int dimid; size_t naux; \
818 NC(nc_inq_dimid(ncid, dimname, &dimid)); \
819 NC(nc_inq_dimlen(ncid, dimid, &naux)); \
820 *ptr = (int)naux; \
821 if (check) \
822 if ((*ptr) < (min) || (*ptr) > (max)) \
823 ERRMSG("Dimension %s is out of range!", dimname); \
824 }
825
840#define NC_PUT_DOUBLE(varname, ptr, hyperslab) { \
841 NC(nc_inq_varid(ncid, varname, &varid)); \
842 if(hyperslab) { \
843 NC(nc_put_vara_double(ncid, varid, start, count, ptr)); \
844 } else { \
845 NC(nc_put_var_double(ncid, varid, ptr)); \
846 } \
847 }
848
864#define NC_PUT_FLOAT(varname, ptr, hyperslab) { \
865 NC(nc_inq_varid(ncid, varname, &varid)); \
866 if(hyperslab) { \
867 NC(nc_put_vara_float(ncid, varid, start, count, ptr)); \
868 } else { \
869 NC(nc_put_var_float(ncid, varid, ptr)); \
870 } \
871 }
872
887#define NC_PUT_INT(varname, ptr, hyperslab) { \
888 NC(nc_inq_varid(ncid, varname, &varid)); \
889 if(hyperslab) { \
890 NC(nc_put_vara_int(ncid, varid, start, count, ptr)); \
891 } else { \
892 NC(nc_put_var_int(ncid, varid, ptr)); \
893 } \
894 }
895
909#define NC_PUT_ATT(varname, attname, text) { \
910 NC(nc_inq_varid(ncid, varname, &varid)); \
911 NC(nc_put_att_text(ncid, varid, attname, strnlen(text, LEN), text)); \
912 }
913
926#define NC_PUT_ATT_GLOBAL(attname, text) \
927 NC(nc_put_att_text(ncid, NC_GLOBAL, attname, strnlen(text, LEN), text));
928
958#define NEDT(t_bg, nesr, nu) \
959 (BRIGHT(PLANCK((t_bg), (nu)) + (nesr), (nu)) - (t_bg))
960
987#define NESR(t_bg, nedt, nu) \
988 (PLANCK((t_bg) + (nedt), (nu)) - PLANCK((t_bg), (nu)))
989
1004#define NORM(a) sqrt(DOTP(a, a))
1005
1035#define PLANCK(T, nu) \
1036 (C1 * POW3(nu) / gsl_expm1(C2 * (nu) / (T)))
1037
1049#define POW2(x) ((x)*(x))
1050
1062#define POW3(x) ((x)*(x)*(x))
1063
1078#define RAD2DEG(rad) ((rad) * (180.0 / M_PI))
1079
1108#define REFRAC_SW53(p, T, h2o) \
1109 (1e-6 * (77.6 * (p) / (T) + 3.73e5 * (h2o) * (p) / ((T) * (T))))
1110
1135#define REFRAC_EDLEN(p, T) \
1136 ((1e-8 \
1137 * (8342.54 + 2406147.0 / (130.0 - 1.0 / (10.0 * 10.0)) \
1138 + 15998.0 / (38.9 - 1.0 / (10.0 * 10.0)))) \
1139 * ((p) / 1013.25) * (288.15 / (T)))
1140
1155#define TBL_LOG(tbl, id, ig) \
1156 do { \
1157 for (int ip = 0; ip < (tbl)->np[(id)][(ig)]; ip++) \
1158 LOG(2, \
1159 "p[%2d]= %.5e hPa | T[0:%2d]= %.2f ... %.2f K | " \
1160 "u[0:%3d]= %.5e ... %.5e molec/cm^2 | " \
1161 "eps[0:%3d]= %.5e ... %.5e", \
1162 (ip), \
1163 (tbl)->p[(id)][(ig)][(ip)], \
1164 (tbl)->nt[(id)][(ig)][(ip)] - 1, \
1165 (tbl)->t[(id)][(ig)][(ip)][0], \
1166 (tbl)->t[(id)][(ig)][(ip)] \
1167 [(tbl)->nt[(id)][(ig)][(ip)] - 1], \
1168 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1169 exp((tbl)->logu[(id)][(ig)][(ip)][0][0]), \
1170 exp((tbl)->logu[(id)][(ig)][(ip)][0] \
1171 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1]), \
1172 (tbl)->nu[(id)][(ig)][(ip)][0] - 1, \
1173 exp((tbl)->logeps[(id)][(ig)][(ip)][0][0]), \
1174 exp((tbl)->logeps[(id)][(ig)][(ip)][0] \
1175 [(tbl)->nu[(id)][(ig)][(ip)][0] - 1])); \
1176 } while (0)
1177
1189#define SELECT_TIMER(id, group) \
1190 {timer_group(id, group, 0);}
1191
1199#define PRINT_TIMERS \
1200 {timer_group("END", "END", 1);}
1201
1220#define TOK(line, tok, format, var) { \
1221 if(((tok)=strtok((line), " \t"))) { \
1222 if(sscanf(tok, format, &(var))!=1) continue; \
1223 } else ERRMSG("Error while reading!"); \
1224 }
1225
1237#define USAGE \
1238 do { \
1239 int iusage; \
1240 for (iusage = 1; iusage < argc; iusage++) \
1241 if (!strcmp(argv[iusage], "-h") \
1242 || !strcmp(argv[iusage], "--help")) { \
1243 usage(); \
1244 return EXIT_SUCCESS; \
1245 } \
1246 } while (0)
1247
1248/* ------------------------------------------------------------
1249 Log messages...
1250 ------------------------------------------------------------ */
1251
1253#ifndef LOGLEV
1254#define LOGLEV 2
1255#endif
1256
1286#define LOG(level, ...) { \
1287 if(level >= 2) \
1288 printf(" "); \
1289 if(level <= LOGLEV) { \
1290 printf(__VA_ARGS__); \
1291 printf("\n"); \
1292 } \
1293 }
1294
1323#define WARN(...) { \
1324 printf("\nWarning (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1325 LOG(0, __VA_ARGS__); \
1326 }
1327
1356#define ERRMSG(...) { \
1357 printf("\nError (%s, %s, l%d): ", __FILE__, __func__, __LINE__); \
1358 LOG(0, __VA_ARGS__); \
1359 exit(EXIT_FAILURE); \
1360 }
1361
1391#define PRINT(format, var) \
1392 printf("Print (%s, %s, l%d): %s= "format"\n", \
1393 __FILE__, __func__, __LINE__, #var, var);
1394
1395/* ------------------------------------------------------------
1396 Structs...
1397 ------------------------------------------------------------ */
1398
1406typedef struct {
1407
1409 int np;
1410
1412 double time[NP];
1413
1415 double z[NP];
1416
1418 double lon[NP];
1419
1421 double lat[NP];
1422
1424 double p[NP];
1425
1427 double t[NP];
1428
1430 double q[NG][NP];
1431
1433 double k[NW][NP];
1434
1436 double clz;
1437
1439 double cldz;
1440
1442 double clk[NCL];
1443
1445 double sft;
1446
1448 double sfeps[NSF];
1449
1450} atm_t;
1451
1459typedef struct {
1460
1462 int ng;
1463
1465 char emitter[NG][LEN];
1466
1469
1472
1475
1478
1480 int nd;
1481
1483 double nu[ND];
1484
1486 int nw;
1487
1489 int window[ND];
1490
1492 int ncl;
1493
1495 double clnu[NCL];
1496
1498 int nsf;
1499
1501 double sfnu[NSF];
1502
1505
1507 double sfsza;
1508
1510 char tblbase[LEN];
1511
1514
1517
1520
1523
1525 double hydz;
1526
1529
1532
1535
1538
1541
1543 double rayds;
1544
1546 double raydz;
1547
1549 char fov[LEN];
1550
1552 double fov_dz[NSHAPE];
1553
1555 double fov_w[NSHAPE];
1556
1559
1562
1565
1568
1571
1573 double retq_zmin[NG];
1574
1576 double retq_zmax[NG];
1577
1579 double retk_zmin[NW];
1580
1582 double retk_zmax[NW];
1583
1586
1589
1592
1595
1598
1601
1604
1607
1609 char rfmbin[LEN];
1610
1612 char rfmhit[LEN];
1613
1615 char rfmxsc[NG][LEN];
1616
1617} ctl_t;
1618
1626typedef struct {
1627
1629 int np;
1630
1632 double z[NLOS];
1633
1635 double lon[NLOS];
1636
1638 double lat[NLOS];
1639
1641 double p[NLOS];
1642
1644 double t[NLOS];
1645
1647 double q[NLOS][NG];
1648
1650 double k[NLOS][ND];
1651
1653 double sft;
1654
1656 double sfeps[ND];
1657
1659 double ds[NLOS];
1660
1662 double u[NLOS][NG];
1663
1665 double cgp[NLOS][NG];
1666
1668 double cgt[NLOS][NG];
1669
1671 double cgu[NLOS][NG];
1672
1674 double eps[NLOS][ND];
1675
1677 double src[NLOS][ND];
1678
1679} los_t;
1680
1688typedef struct {
1689
1691 int nr;
1692
1694 double time[NR];
1695
1697 double obsz[NR];
1698
1700 double obslon[NR];
1701
1703 double obslat[NR];
1704
1706 double vpz[NR];
1707
1709 double vplon[NR];
1710
1712 double vplat[NR];
1713
1715 double tpz[NR];
1716
1718 double tplon[NR];
1719
1721 double tplat[NR];
1722
1724 double tau[ND][NR];
1725
1727 double rad[ND][NR];
1728
1730 int mask[ND][NR];
1731
1732} obs_t;
1733
1743typedef struct {
1744
1746 char dir[LEN];
1747
1750
1753
1756
1759
1761 double err_formod[ND];
1762
1764 double err_noise[ND];
1765
1768
1771
1774
1776 double err_temp;
1777
1780
1783
1785 double err_q[NG];
1786
1788 double err_q_cz[NG];
1789
1791 double err_q_ch[NG];
1792
1794 double err_k[NW];
1795
1797 double err_k_cz[NW];
1798
1800 double err_k_ch[NW];
1801
1803 double err_clz;
1804
1806 double err_cldz;
1807
1809 double err_clk[NCL];
1810
1812 double err_sft;
1813
1815 double err_sfeps[NSF];
1816
1819
1821 char shared_io_proflist[LEN];
1822
1824 char shared_io_atm_apr_file[LEN];
1825
1827 char shared_io_obs_meas_file[LEN];
1828
1830 char shared_io_atm_final_file[LEN];
1831
1833 char shared_io_obs_final_file[LEN];
1834
1836 char shared_io_matrix_cov_apr_file[LEN];
1837
1839 char shared_io_matrix_kernel_file[LEN];
1840
1842 char shared_io_matrix_cov_ret_file[LEN];
1843
1845 char shared_io_matrix_corr_file[LEN];
1846
1848 char shared_io_matrix_gain_file[LEN];
1849
1851 char shared_io_matrix_avk_file[LEN];
1852
1854 char shared_io_atm_err_total_file[LEN];
1855
1857 char shared_io_atm_err_noise_file[LEN];
1858
1860 char shared_io_atm_err_formod_file[LEN];
1861
1863 char shared_io_atm_cont_file[LEN];
1864
1866 char shared_io_atm_res_file[LEN];
1867
1868} ret_t;
1869
1876typedef struct {
1877
1879 int np[ND][NG];
1880
1882 int nt[ND][NG][TBLNP];
1883
1885 int nu[ND][NG][TBLNP][TBLNT];
1886
1888 double p[ND][NG][TBLNP];
1889
1891 double lnp[ND][NG][TBLNP];
1892
1894 double t[ND][NG][TBLNP][TBLNT];
1895
1897 float *logu[ND][NG][TBLNP][TBLNT];
1898
1900 float *logeps[ND][NG][TBLNP][TBLNT];
1901
1903 int filt_n[ND];
1904
1906 double filt_nu[ND][NSHAPE];
1907
1909 double filt_f[ND][NSHAPE];
1910
1912 double st[TBLNS];
1913
1915 double sr[TBLNS][ND];
1916
1917} tbl_t;
1918
1919/* ------------------------------------------------------------
1920 Functions...
1921 ------------------------------------------------------------ */
1922
1974void analyze_avk(
1975 const ret_t * ret,
1976 const ctl_t * ctl,
1977 const atm_t * atm,
1978 const int *iqa,
1979 const int *ipa,
1980 const gsl_matrix * avk);
1981
2038 const gsl_matrix * avk,
2039 const int iq,
2040 const int *ipa,
2041 const size_t *n0,
2042 const size_t *n1,
2043 double *cont,
2044 double *res);
2045
2072size_t atm2x(
2073 const ctl_t * ctl,
2074 const atm_t * atm,
2075 gsl_vector * x,
2076 int *iqa,
2077 int *ipa);
2078
2100void atm2x_help(
2101 const double value,
2102 const int value_iqa,
2103 const int value_ip,
2104 gsl_vector * x,
2105 int *iqa,
2106 int *ipa,
2107 size_t *n);
2108
2123void cart2geo(
2124 const double *x,
2125 double *z,
2126 double *lon,
2127 double *lat);
2128
2144void climatology(
2145 const ctl_t * ctl,
2146 atm_t * atm);
2147
2172double cos_sza(
2173 const double sec,
2174 const double lon,
2175 const double lat);
2176
2216double cost_function(
2217 const gsl_vector * dx,
2218 const gsl_vector * dy,
2219 const gsl_matrix * s_a_inv,
2220 const gsl_vector * sig_eps_inv);
2221
2243double ctmco2(
2244 const double nu,
2245 const double p,
2246 const double t,
2247 const double u);
2248
2254double ctmh2o(
2255 const double nu,
2256 const double p,
2257 const double t,
2258 const double q,
2259 const double u);
2260
2292double ctmn2(
2293 const double nu,
2294 const double p,
2295 const double t);
2296
2326double ctmo2(
2327 const double nu,
2328 const double p,
2329 const double t);
2330
2355void copy_atm(
2356 const ctl_t * ctl,
2357 atm_t * atm_dest,
2358 const atm_t * atm_src,
2359 const int init);
2360
2385void copy_obs(
2386 const ctl_t * ctl,
2387 obs_t * obs_dest,
2388 const obs_t * obs_src,
2389 const int init);
2390
2411void day2doy(
2412 int year,
2413 int mon,
2414 int day,
2415 int *doy);
2416
2439void doy2day(
2440 int year,
2441 int doy,
2442 int *mon,
2443 int *day);
2444
2464int find_emitter(
2465 const ctl_t * ctl,
2466 const char *emitter);
2467
2503int formod(
2504 const ctl_t * ctl,
2505 const tbl_t * tbl,
2506 atm_t * atm,
2507 obs_t * obs,
2508 los_t * los_scratch,
2509 obs_t * obs_scratch);
2510
2530void formod_batch(
2531 const ctl_t * ctl,
2532 const tbl_t * tbl,
2533 atm_t * atm,
2534 obs_t * obs,
2535 const int nbatch,
2536 int *status,
2537 los_t * los_scratch,
2538 obs_t * obs_scratch);
2539
2565void formod_continua(
2566 const ctl_t * ctl,
2567 const los_t * los,
2568 const int ip,
2569 double *beta);
2570
2594int formod_fov(
2595 const ctl_t * ctl,
2596 obs_t * obs,
2597 obs_t * obs_scratch);
2598
2631int formod_pencil(
2632 const ctl_t * ctl,
2633 const tbl_t * tbl,
2634 const atm_t * atm,
2635 obs_t * obs,
2636 const int ir,
2637 los_t * los);
2638
2690void formod_rfm(
2691 const ctl_t * ctl,
2692 const tbl_t * tbl,
2693 const atm_t * atm,
2694 obs_t * obs);
2695
2720void formod_srcfunc(
2721 const ctl_t * ctl,
2722 const tbl_t * tbl,
2723 const double t,
2724 double *src);
2725
2752void geo2cart(
2753 const double z,
2754 const double lon,
2755 const double lat,
2756 double *x);
2757
2785void hydrostatic(
2786 const ctl_t * ctl,
2787 atm_t * atm);
2788
2812void idx2name(
2813 const ctl_t * ctl,
2814 const int idx,
2815 char *quantity);
2816
2846void init_srcfunc(
2847 const ctl_t * ctl,
2848 tbl_t * tbl);
2849
2874void intpol_atm(
2875 const ctl_t * ctl,
2876 const atm_t * atm,
2877 const double z,
2878 double *p,
2879 double *t,
2880 double *q,
2881 double *k);
2882
2916void intpol_tbl_cga(
2917 const ctl_t * ctl,
2918 const tbl_t * tbl,
2919 const los_t * los,
2920 const int ip,
2921 double tau_path[ND][NG],
2922 double tau_seg[ND]);
2923
2962void intpol_tbl_ega(
2963 const ctl_t * ctl,
2964 const tbl_t * tbl,
2965 const los_t * los,
2966 const int ip,
2967 double tau_path[ND][NG],
2968 double tau_seg[ND]);
2969
2996double intpol_tbl_eps(
2997 const tbl_t * tbl,
2998 const int ig,
2999 const int id,
3000 const int ip,
3001 const int it,
3002 const double logu);
3003
3034double intpol_tbl_u(
3035 const tbl_t * tbl,
3036 const int ig,
3037 const int id,
3038 const int ip,
3039 const int it,
3040 const double logeps);
3041
3068void jsec2time(
3069 const double jsec,
3070 int *year,
3071 int *mon,
3072 int *day,
3073 int *hour,
3074 int *min,
3075 int *sec,
3076 double *remain);
3077
3124void kernel(
3125 const ctl_t * ctl,
3126 const tbl_t * tbl,
3127 atm_t * atm,
3128 obs_t * obs,
3129 gsl_matrix * k);
3130
3157int locate_irr(
3158 const double *xx,
3159 const int n,
3160 const double x);
3161
3188int locate_reg(
3189 const double *xx,
3190 const int n,
3191 const double x);
3192
3218int locate_tbl(
3219 const float *xx,
3220 const int n,
3221 const double x);
3222
3261void matrix_invert(
3262 gsl_matrix * a);
3263
3308void matrix_product(
3309 const gsl_matrix * a,
3310 const gsl_vector * b,
3311 const int transpose,
3312 gsl_matrix * c);
3313
3341size_t obs2y(
3342 const ctl_t * ctl,
3343 const obs_t * obs,
3344 gsl_vector * y,
3345 int *ida,
3346 int *ira);
3347
3399 ret_t * ret,
3400 ctl_t * ctl,
3401 tbl_t * tbl,
3402 obs_t * obs_meas,
3403 obs_t * obs_i,
3404 atm_t * atm_apr,
3405 atm_t * atm_i,
3406 double *chisq);
3407
3455int raytrace(
3456 const ctl_t * ctl,
3457 const atm_t * atm,
3458 obs_t * obs,
3459 los_t * los,
3460 const int ir);
3461
3511void read_atm(
3512 const char *dirname,
3513 const char *filename,
3514 const ctl_t * ctl,
3515 atm_t * atm,
3516 int profile);
3517
3564void read_atm_asc(
3565 const char *filename,
3566 const ctl_t * ctl,
3567 atm_t * atm);
3568
3618void read_atm_bin(
3619 const char *filename,
3620 const ctl_t * ctl,
3621 atm_t * atm);
3622
3664void read_atm_nc(
3665 const char *filename,
3666 const ctl_t * ctl,
3667 atm_t * atm,
3668 int profile);
3669
3710void read_ctl(
3711 int argc,
3712 char *argv[],
3713 ctl_t * ctl);
3714
3733void read_matrix(
3734 const char *dirname,
3735 const char *filename,
3736 const ctl_t * ctl,
3737 gsl_matrix * matrix,
3738 int dataset);
3739
3771void read_matrix_asc(
3772 const char *dirname,
3773 const char *filename,
3774 gsl_matrix * matrix);
3775
3793void read_matrix_bin(
3794 const char *dirname,
3795 const char *filename,
3796 gsl_matrix * matrix);
3797
3819void read_matrix_nc(
3820 const char *dirname,
3821 const char *filename,
3822 gsl_matrix * matrix,
3823 int dataset);
3824
3861void read_obs(
3862 const char *dirname,
3863 const char *filename,
3864 const ctl_t * ctl,
3865 obs_t * obs,
3866 int profile);
3867
3905void read_obs_asc(
3906 const char *filename,
3907 const ctl_t * ctl,
3908 obs_t * obs);
3909
3951void read_obs_bin(
3952 const char *filename,
3953 const ctl_t * ctl,
3954 obs_t * obs);
3955
3988void read_obs_nc(
3989 const char *filename,
3990 const ctl_t * ctl,
3991 obs_t * obs,
3992 const int profile);
3993
4033double read_obs_rfm(
4034 const char *basename,
4035 const double z,
4036 const double *nu,
4037 const double *f,
4038 const int n);
4039
4114void read_ret(
4115 int argc,
4116 char *argv[],
4117 const ctl_t * ctl,
4118 ret_t * ret);
4119
4160void read_rfm_spec(
4161 const char *filename,
4162 double *nu,
4163 double *rad,
4164 int *npts);
4165
4199void read_shape(
4200 const char *filename,
4201 double *x,
4202 double *y,
4203 int *n);
4204
4241 const ctl_t * ctl);
4242
4278void read_tbl_asc(
4279 const ctl_t * ctl,
4280 tbl_t * tbl,
4281 const int id,
4282 const int ig);
4283
4315void read_tbl_bin(
4316 const ctl_t * ctl,
4317 tbl_t * tbl,
4318 const int id,
4319 const int ig);
4320
4364 const ctl_t * ctl,
4365 tbl_t * tbl,
4366 int id,
4367 int ig,
4368 int ncid);
4369
4424double scan_ctl(
4425 int argc,
4426 char *argv[],
4427 const char *varname,
4428 const int arridx,
4429 const char *defvalue,
4430 char *value);
4431
4485void set_cov_apr(
4486 const ret_t * ret,
4487 const ctl_t * ctl,
4488 const atm_t * atm,
4489 const int *iqa,
4490 const int *ipa,
4491 gsl_matrix * s_a);
4492
4546void set_cov_meas(
4547 const ret_t * ret,
4548 const ctl_t * ctl,
4549 const obs_t * obs,
4550 gsl_vector * sig_noise,
4551 gsl_vector * sig_formod,
4552 gsl_vector * sig_eps_inv);
4553
4580const char *shared_io_input_target(
4581 const ret_t * ret,
4582 const char *shared_file,
4583 const char *legacy_file,
4584 const char **dirname,
4585 int *profile);
4586
4613const char *shared_io_output_target(
4614 const ret_t * ret,
4615 const char *shared_file,
4616 const char *legacy_file,
4617 const char **dirname,
4618 int *profile);
4619
4640int shared_io_lock(
4641 const ret_t * ret);
4642
4657void shared_io_unlock(
4658 int fd);
4659
4680const char *shared_io_output_file(
4681 const ret_t * ret);
4682
4722void tangent_point(
4723 const los_t * los,
4724 double *tpz,
4725 double *tplon,
4726 double *tplat);
4727
4749void tbl_free(
4750 const ctl_t * ctl,
4751 tbl_t * tbl);
4752
4792void tbl_pack(
4793 const tbl_t * tbl,
4794 int id,
4795 int ig,
4796 uint8_t * buf,
4797 size_t *bytes_used);
4798
4809size_t tbl_packed_size(
4810 const tbl_t * tbl,
4811 int id,
4812 int ig);
4813
4852size_t tbl_unpack(
4853 tbl_t * tbl,
4854 int id,
4855 int ig,
4856 const uint8_t * buf);
4857
4858
4883void time2jsec(
4884 const int year,
4885 const int mon,
4886 const int day,
4887 const int hour,
4888 const int min,
4889 const int sec,
4890 const double remain,
4891 double *jsec);
4892
4907void timer_group(
4908 const char *name,
4909 const char *group,
4910 int output);
4911
4960void write_atm(
4961 const char *dirname,
4962 const char *filename,
4963 const ctl_t * ctl,
4964 const atm_t * atm,
4965 int profile);
4966
5018void write_atm_asc(
5019 const char *filename,
5020 const ctl_t * ctl,
5021 const atm_t * atm);
5022
5076void write_atm_bin(
5077 const char *filename,
5078 const ctl_t * ctl,
5079 const atm_t * atm);
5080
5128void write_atm_nc(
5129 const char *filename,
5130 const ctl_t * ctl,
5131 const atm_t * atm,
5132 int profile);
5133
5185void write_atm_rfm(
5186 const char *filename,
5187 const ctl_t * ctl,
5188 const atm_t * atm);
5189
5213void write_matrix(
5214 const char *dirname,
5215 const char *filename,
5216 const ctl_t * ctl,
5217 const gsl_matrix * matrix,
5218 const atm_t * atm,
5219 const obs_t * obs,
5220 const char *rowspace,
5221 const char *colspace,
5222 const char *sort,
5223 int dataset);
5224
5272void write_matrix_asc(
5273 const char *dirname,
5274 const char *filename,
5275 const ctl_t * ctl,
5276 const gsl_matrix * matrix,
5277 const atm_t * atm,
5278 const obs_t * obs,
5279 const char *rowspace,
5280 const char *colspace,
5281 const char *sort);
5282
5297void write_matrix_bin(
5298 const char *dirname,
5299 const char *filename,
5300 const gsl_matrix * matrix);
5301
5328void write_matrix_nc(
5329 const char *dirname,
5330 const char *filename,
5331 const ctl_t * ctl,
5332 const gsl_matrix * matrix,
5333 const atm_t * atm,
5334 const obs_t * obs,
5335 const char *rowspace,
5336 const char *colspace,
5337 const char *sort,
5338 int dataset);
5339
5375void write_obs(
5376 const char *dirname,
5377 const char *filename,
5378 const ctl_t * ctl,
5379 const obs_t * obs,
5380 int profile);
5381
5420void write_obs_asc(
5421 const char *filename,
5422 const ctl_t * ctl,
5423 const obs_t * obs);
5424
5462void write_obs_bin(
5463 const char *filename,
5464 const ctl_t * ctl,
5465 const obs_t * obs);
5466
5504void write_obs_nc(
5505 const char *filename,
5506 const ctl_t * ctl,
5507 const obs_t * obs,
5508 const int profile);
5509
5544void write_shape(
5545 const char *filename,
5546 const double *x,
5547 const double *y,
5548 const int n);
5549
5595void write_stddev(
5596 const char *quantity,
5597 const ret_t * ret,
5598 const ctl_t * ctl,
5599 const atm_t * atm,
5600 const gsl_matrix * s);
5601
5637void write_tbl(
5638 const ctl_t * ctl,
5639 const tbl_t * tbl);
5640
5666void write_tbl_asc(
5667 const ctl_t * ctl,
5668 const tbl_t * tbl,
5669 const int id,
5670 const int ig);
5671
5699void write_tbl_bin(
5700 const ctl_t * ctl,
5701 const tbl_t * tbl,
5702 const int id,
5703 const int ig);
5704
5737void write_tbl_nc(
5738 const ctl_t * ctl,
5739 const tbl_t * tbl,
5740 const int id,
5741 const int ig);
5742
5789void x2atm(
5790 const ctl_t * ctl,
5791 const gsl_vector * x,
5792 atm_t * atm);
5793
5822void x2atm_help(
5823 double *value,
5824 const gsl_vector * x,
5825 size_t *n);
5826
5859void y2obs(
5860 const ctl_t * ctl,
5861 const gsl_vector * y,
5862 obs_t * obs);
5863
5864#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:4243
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:6532
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:276
@ 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:1193
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:6112
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:7308
void read_rfm_spec(const char *filename, double *nu, double *rad, int *npts)
Read a Reference Forward Model (RFM) ASCII spectrum.
Definition: jurassic.c:6232
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:7042
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:5787
double cos_sza(const double sec, const double lon, const double lat)
Calculates the cosine of the solar zenith angle.
Definition: jurassic.c:1152
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:4986
void read_atm_bin(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in binary format.
Definition: jurassic.c:5344
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:8347
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:3642
int locate_reg(const double *xx, const int n, const double x)
Locate index for interpolation on a regular (uniform) grid.
Definition: jurassic.c:4519
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:4141
double ctmo2(const double nu, const double p, const double t)
Compute O₂ collision-induced absorption coefficient.
Definition: jurassic.c:3052
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:8471
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
Definition: jurassic.c:7003
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:8766
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:8850
void idx2name(const ctl_t *ctl, const int idx, char *quantity)
Convert a quantity index to a descriptive name string.
Definition: jurassic.c:3937
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:5542
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:3360
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:5955
int shared_io_lock(const ret_t *ret)
Acquire an exclusive lock for shared retrieval output files.
Definition: jurassic.c:6881
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:5836
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:4590
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:3458
int locate_irr(const double *xx, const int n, const double x)
Locate index for interpolation on an irregular grid.
Definition: jurassic.c:4489
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:6841
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:7791
void day2doy(int year, int mon, int day, int *doy)
Convert a calendar date to day-of-year.
Definition: jurassic.c:3202
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:7530
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:7754
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:7206
void x2atm(const ctl_t *ctl, const gsl_vector *x, atm_t *atm)
Map retrieval state vector back to atmospheric structure.
Definition: jurassic.c:8915
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:2087
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:8808
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:4048
void shared_io_unlock(int fd)
Release a shared retrieval output lock.
Definition: jurassic.c:6908
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:7717
#define ND
Maximum number of radiance channels.
Definition: jurassic.h:296
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:6792
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:8276
#define NSHAPE
Maximum number of shape function grid points.
Definition: jurassic.h:336
void write_tbl(const ctl_t *ctl, const tbl_t *tbl)
Write emissivity lookup tables to disk.
Definition: jurassic.c:8723
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:7130
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:5669
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:4023
int find_emitter(const ctl_t *ctl, const char *emitter)
Find gas species index by name.
Definition: jurassic.c:3252
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:4662
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:4288
void timer_group(const char *name, const char *group, int output)
Aggregate wall-clock timings for named code phases.
Definition: jurassic.c:7237
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:6960
double ctmco2(const double nu, const double p, const double t, const double u)
Compute carbon dioxide continuum optical depth.
Definition: jurassic.c:1224
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:5219
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:3396
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:8013
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:7379
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:7964
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:3164
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:3316
#define TBLNT
Maximum number of temperatures in emissivity tables.
Definition: jurassic.h:366
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:8403
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:8965
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:316
void doy2day(int year, int doy, int *mon, int *day)
Convert a day-of-year value to a calendar date.
Definition: jurassic.c:3222
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:4367
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:6033
void init_srcfunc(const ctl_t *ctl, tbl_t *tbl)
Initialize source function lookup tables from emissivity data.
Definition: jurassic.c:3976
void matrix_invert(gsl_matrix *a)
Invert a square matrix, optimized for diagonal or symmetric positive-definite matrices.
Definition: jurassic.c:4560
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
Definition: jurassic.c:6144
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:6613
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:8651
void read_atm_asc(const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data in ASCII format.
Definition: jurassic.c:5293
#define NG
Maximum number of emitters.
Definition: jurassic.h:306
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:6409
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:3842
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:4334
#define TBLNS
Maximum number of source function temperature levels.
Definition: jurassic.h:361
void read_matrix_asc(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from an ASCII file.
Definition: jurassic.c:5695
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
Definition: jurassic.c:6333
void read_matrix_bin(const char *dirname, const char *filename, gsl_matrix *matrix)
Read a numerical matrix from a binary file.
Definition: jurassic.c:5734
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:6576
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:6861
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:5438
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:3114
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:4635
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:8977
void hydrostatic(const ctl_t *ctl, atm_t *atm)
Adjust pressure profile using the hydrostatic equation.
Definition: jurassic.c:3877
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:6292
double ctmn2(const double nu, const double p, const double t)
Compute N₂ collision-induced absorption coefficient.
Definition: jurassic.c:2983
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:356
void climatology(const ctl_t *ctl, atm_t *atm)
Initializes atmospheric climatology profiles.
Definition: jurassic.c:215
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:3859
#define NSF
Maximum number of surface layer spectral grid points.
Definition: jurassic.h:331
#define NCL
Maximum number of cloud layer spectral grid points.
Definition: jurassic.h:291
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:6681
const char * shared_io_output_file(const ret_t *ret)
Return the primary shared retrieval output file configured for locking.
Definition: jurassic.c:6926
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:8680
#define NLOS
Maximum number of LOS points.
Definition: jurassic.h:311
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:3265
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:7096
#define NR
Maximum number of ray paths.
Definition: jurassic.h:326
int locate_tbl(const float *xx, const int n, const double x)
Locate index for interpolation within emissivity table grids.
Definition: jurassic.c:4538
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:7446
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:5911
#define NW
Maximum number of spectral windows.
Definition: jurassic.h:346
Atmospheric profile data.
Definition: jurassic.h:1406
double clz
Cloud layer height [km].
Definition: jurassic.h:1436
int np
Number of data points.
Definition: jurassic.h:1409
double cldz
Cloud layer depth [km].
Definition: jurassic.h:1439
double sft
Surface temperature [K].
Definition: jurassic.h:1445
Control parameters.
Definition: jurassic.h:1459
int write_matrix
Write matrix file (0=no, 1=yes).
Definition: jurassic.h:1603
int nw
Number of spectral windows.
Definition: jurassic.h:1486
int atmfmt
Atmospheric data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1516
double retp_zmin
Minimum altitude for pressure retrieval [km].
Definition: jurassic.h:1561
int ig_co2
Emitter index of CO2.
Definition: jurassic.h:1468
double hydz
Reference height for hydrostatic pressure profile (-999 to skip) [km].
Definition: jurassic.h:1525
int ctm_co2
Compute CO2 continuum (0=no, 1=yes).
Definition: jurassic.h:1528
double rett_zmax
Maximum altitude for temperature retrieval [km].
Definition: jurassic.h:1570
int ret_sfeps
Retrieve surface layer emissivity (0=no, 1=yes).
Definition: jurassic.h:1597
int ret_sft
Retrieve surface layer temperature (0=no, 1=yes).
Definition: jurassic.h:1594
int ret_clz
Retrieve cloud layer height (0=no, 1=yes).
Definition: jurassic.h:1585
int ctm_n2
Compute N2 continuum (0=no, 1=yes).
Definition: jurassic.h:1534
int ctm_h2o
Compute H2O continuum (0=no, 1=yes).
Definition: jurassic.h:1531
int formod
Forward model (0=CGA, 1=EGA, 2=RFM).
Definition: jurassic.h:1606
int ng
Number of emitters.
Definition: jurassic.h:1462
int refrac
Take into account refractivity (0=no, 1=yes).
Definition: jurassic.h:1540
int ig_o2
Emitter index of O2.
Definition: jurassic.h:1477
double rett_zmin
Minimum altitude for temperature retrieval [km].
Definition: jurassic.h:1567
double sfsza
Solar zenith angle at the surface [deg] (-999=auto).
Definition: jurassic.h:1507
int nd
Number of radiance channels.
Definition: jurassic.h:1480
int fov_n
Field-of-view number of data points.
Definition: jurassic.h:1558
int sftype
Surface treatment (0=none, 1=emissions, 2=downward, 3=solar).
Definition: jurassic.h:1504
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1522
int ncl
Number of cloud layer spectral grid points.
Definition: jurassic.h:1492
int ig_n2
Emitter index of N2.
Definition: jurassic.h:1474
int obsfmt
Observation data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1519
int ctm_o2
Compute O2 continuum (0=no, 1=yes).
Definition: jurassic.h:1537
int ret_clk
Retrieve cloud layer extinction (0=no, 1=yes).
Definition: jurassic.h:1591
int nsf
Number of surface layer spectral grid points.
Definition: jurassic.h:1498
double rayds
Maximum step length for raytracing [km].
Definition: jurassic.h:1543
int ret_cldz
Retrieve cloud layer depth (0=no, 1=yes).
Definition: jurassic.h:1588
int ig_h2o
Emitter index of H2O.
Definition: jurassic.h:1471
int tblfmt
Look-up table file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1513
double raydz
Vertical step length for raytracing [km].
Definition: jurassic.h:1546
int write_bbt
Use brightness temperature instead of radiance (0=no, 1=yes).
Definition: jurassic.h:1600
double retp_zmax
Maximum altitude for pressure retrieval [km].
Definition: jurassic.h:1564
Line-of-sight data.
Definition: jurassic.h:1626
double sft
Surface temperature [K].
Definition: jurassic.h:1653
int np
Number of LOS points.
Definition: jurassic.h:1629
Observation geometry and radiance data.
Definition: jurassic.h:1688
int nr
Number of ray paths.
Definition: jurassic.h:1691
Retrieval control parameters.
Definition: jurassic.h:1743
double err_press_cz
Vertical correlation length for pressure error [km].
Definition: jurassic.h:1770
double err_press
Pressure error [%].
Definition: jurassic.h:1767
int err_ana
Carry out error analysis (0=no, 1=yes).
Definition: jurassic.h:1758
double err_temp_cz
Vertical correlation length for temperature error [km].
Definition: jurassic.h:1779
double conv_dmin
Minimum normalized step size in state space.
Definition: jurassic.h:1755
double err_temp
Temperature error [K].
Definition: jurassic.h:1776
double err_clz
Cloud height error [km].
Definition: jurassic.h:1803
double err_sft
Surface temperature error [K].
Definition: jurassic.h:1812
double err_temp_ch
Horizontal correlation length for temperature error [km].
Definition: jurassic.h:1782
int kernel_recomp
Re-computation of kernel matrix (number of iterations).
Definition: jurassic.h:1749
int conv_itmax
Maximum number of iterations.
Definition: jurassic.h:1752
double err_cldz
Cloud depth error [km].
Definition: jurassic.h:1806
double err_press_ch
Horizontal correlation length for pressure error [km].
Definition: jurassic.h:1773
int shared_io_profile
Profile index used for shared netCDF retrieval inputs and outputs.
Definition: jurassic.h:1818
Emissivity look-up tables.
Definition: jurassic.h:1876