45 {
46
47 static atm_t atm_i, atm_apr;
49 static obs_t obs_i, obs_meas;
51
52 FILE *dirlist;
53 FILE *proflist = NULL;
54
55
56 int ntask = -1;
57 int rank = 0;
58 int size = 1;
59
60#ifdef MPI
61 MPI_Init(&argc, &argv);
62 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
63 MPI_Comm_size(MPI_COMM_WORLD, &size);
64#endif
65
66
68
69
70 if (argc < 3)
71 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
72 "Usage: retrieval <ctl> <dirlist> [KEY VALUE ...]\n\n"
73 "Use -h for full help.");
74
75
80
81
84
85
87 dirlist = NULL;
88 if (argv[2][0] != '-') {
89 if (!(dirlist = fopen(argv[2], "r")))
90 ERRMSG(
"Cannot open directory list!");
91 }
94 ERRMSG(
"Cannot open profile list!");
95 if (dirlist == NULL && proflist == NULL)
96 ERRMSG(
"Give a directory list or set SHARED_IO_PROFLIST!");
97
98
99 while (1) {
100
101 int have_dir = 0, have_profile = 0;
102
103 if (dirlist != NULL)
104 have_dir = fscanf(dirlist,
"%4999s", ret.
dir) == 1;
105 else {
106 sprintf(ret.
dir,
".");
107 have_dir = 1;
108 }
109
110 if (proflist != NULL)
112 else {
114 have_profile = 1;
115 }
116
117 if ((dirlist != NULL && !have_dir) || (proflist != NULL && !have_profile)) {
118 if ((dirlist != NULL && have_dir) || (proflist != NULL && have_profile))
119 ERRMSG(
"DIRLIST and SHARED_IO_PROFLIST have different lengths!");
120 break;
121 }
122
123
124 if ((++ntask) % size != rank)
125 continue;
126
127
128 if (size > 1 && proflist != NULL && dirlist != NULL) {
130 "\nRetrieve profile %d in directory %s on rank %d of %d...\n",
132 } else if (size > 1 && proflist != NULL) {
133 LOG(1,
"\nRetrieve profile %d on rank %d of %d...\n",
135 } else if (size > 1) {
136 LOG(1,
"\nRetrieve in directory %s on rank %d of %d...\n",
137 ret.
dir, rank + 1, size);
138 } else if (proflist != NULL && dirlist != NULL) {
139 LOG(1,
"\nRetrieve profile %d in directory %s...\n",
141 } else if (proflist != NULL) {
143 } else
144 LOG(1,
"\nRetrieve in directory %s...\n", ret.
dir);
145
146
148 const char *dirname;
149 int profile;
150 const char *filename =
152 &dirname, &profile);
153 read_atm(dirname, filename, &ctl, &atm_apr, profile);
154
155
157 filename =
159 "obs_meas.tab", &dirname, &profile);
160 read_obs(dirname, filename, &ctl, &obs_meas, profile);
161
162
163 double chisq;
165 &chisq);
166 }
167
168
170 LOG(1,
"\nRetrieval done...");
171
172
173 if (dirlist != NULL)
174 fclose(dirlist);
175 if (proflist != NULL)
176 fclose(proflist);
178
179#ifdef MPI
180 MPI_Finalize();
181#endif
182
184
185 return EXIT_SUCCESS;
186}
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
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.
const char * shared_io_input_target(const ret_t *ret, const char *shared_file, const char *legacy_file, const char **dirname, int *profile)
Resolve retrieval input target for legacy-directory and shared-file modes.
void 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.
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.
void read_ret(int argc, char *argv[], const ctl_t *ctl, ret_t *ret)
Read retrieval configuration and error parameters.
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
#define SELECT_TIMER(id, group)
Switch to a named aggregated timer.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
#define PRINT_TIMERS
Print aggregated timer statistics.
#define LOG(level,...)
Print a log message with a specified logging level.
Atmospheric profile data.
Observation geometry and radiance data.
Retrieval control parameters.
char shared_io_proflist[LEN]
Optional file containing retrieval profile indices.
char shared_io_obs_meas_file[LEN]
Optional shared measured-observation input file.
char shared_io_atm_apr_file[LEN]
Optional shared atmospheric a priori input file.
char dir[LEN]
Working directory.
int shared_io_profile
Profile index used for shared netCDF retrieval inputs and outputs.
Emissivity look-up tables.