JURASSIC
retrieval.c
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
25#include "jurassic.h"
26
27#ifdef MPI
28#include <mpi.h>
29#endif
30
31/* ------------------------------------------------------------
32 Main...
33 ------------------------------------------------------------ */
34
35int main(
36 int argc,
37 char *argv[]) {
38
39 static atm_t atm_i, atm_apr;
40 static ctl_t ctl;
41 static obs_t obs_i, obs_meas;
42 static ret_t ret;
43
44 FILE *dirlist;
45
46 /* MPI task distribution (optional)... */
47 int ntask = -1;
48 int rank = 0;
49 int size = 1;
50
51#ifdef MPI
52 MPI_Init(&argc, &argv);
53 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
54 MPI_Comm_size(MPI_COMM_WORLD, &size);
55#endif
56
57 /* Check arguments... */
58 if (argc < 3)
59 ERRMSG("Give parameters: <ctl> <dirlist>");
60
61 /* Measure CPU-time... */
62 TIMER("total", 1);
63
64 /* Read control parameters... */
65 read_ctl(argc, argv, &ctl);
66 read_ret(argc, argv, &ctl, &ret);
67
68 /* Initialize look-up tables... */
69 tbl_t *tbl = read_tbl(&ctl);
70
71 /* Open directory list... */
72 if (!(dirlist = fopen(argv[2], "r")))
73 ERRMSG("Cannot open directory list!");
74
75 /* Loop over directories... */
76 while (fscanf(dirlist, "%4999s", ret.dir) != EOF) {
77
78 /* Distribute directories with MPI (optional)... */
79 if ((++ntask) % size != rank)
80 continue;
81
82 /* Write info... */
83 if (size > 1) {
84 LOG(1, "\nRetrieve in directory %s on rank %d of %d...\n",
85 ret.dir, rank + 1, size);
86 } else
87 LOG(1, "\nRetrieve in directory %s...\n", ret.dir);
88
89 /* Read atmospheric data... */
90 read_atm(ret.dir, "atm_apr.tab", &ctl, &atm_apr);
91
92 /* Read observation data... */
93 read_obs(ret.dir, "obs_meas.tab", &ctl, &obs_meas);
94
95 /* Run retrieval... */
96 double chisq;
97 optimal_estimation(&ret, &ctl, tbl, &obs_meas, &obs_i, &atm_apr, &atm_i,
98 &chisq);
99
100 /* Measure CPU-time... */
101 TIMER("total", 2);
102 }
103
104 /* Write info... */
105 LOG(1, "\nRetrieval done...");
106
107 /* Measure CPU-time... */
108 TIMER("total", 3);
109
110 /* Free... */
111 tbl_free(&ctl, tbl);
112
113#ifdef MPI
114 MPI_Finalize();
115#endif
116
117 return EXIT_SUCCESS;
118}
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
Definition: jurassic.c:6648
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:5450
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:4617
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric input data from a file.
Definition: jurassic.c:5126
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs)
Read observation data from an input file.
Definition: jurassic.c:5614
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
Definition: jurassic.c:5950
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
Definition: jurassic.c:6106
JURASSIC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1194
#define TIMER(name, mode)
Start or stop a named timer.
Definition: jurassic.h:1059
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: jurassic.h:1124
int main(int argc, char *argv[])
Definition: retrieval.c:35
Atmospheric profile data.
Definition: jurassic.h:1244
Control parameters.
Definition: jurassic.h:1297
Observation geometry and radiance data.
Definition: jurassic.h:1523
Retrieval control parameters.
Definition: jurassic.h:1575
char dir[LEN]
Working directory.
Definition: jurassic.h:1578
Emissivity look-up tables.
Definition: jurassic.h:1657