JURASSIC
kernel.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-2025 Forschungszentrum Juelich GmbH
18*/
19
25#include "jurassic.h"
26
27/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32void call_kernel(
33 const ctl_t * ctl,
34 const tbl_t * tbl,
35 const char *wrkdir,
36 const char *obsfile,
37 const char *atmfile,
38 const char *kernelfile);
39
40/* ------------------------------------------------------------
41 Main...
42 ------------------------------------------------------------ */
43
44int main(
45 int argc,
46 char *argv[]) {
47
48 static ctl_t ctl;
49
50 char dirlist[LEN];
51
52 /* Check arguments... */
53 if (argc < 5)
54 ERRMSG("Give parameters: <ctl> <obs> <atm> <kernel>");
55
56 /* Read control parameters... */
57 read_ctl(argc, argv, &ctl);
58
59 /* Initialize look-up tables... */
60 tbl_t *tbl = read_tbl(&ctl);
61
62 /* Get dirlist... */
63 scan_ctl(argc, argv, "DIRLIST", -1, "-", dirlist);
64
65 /* Set flags... */
66 ctl.write_matrix = 1;
67
68 /* Single kernel calculation... */
69 if (dirlist[0] == '-')
70 call_kernel(&ctl, tbl, NULL, argv[2], argv[3], argv[4]);
71
72 /* Work on directory list... */
73 else {
74
75 /* Open directory list... */
76 FILE *in;
77 if (!(in = fopen(dirlist, "r")))
78 ERRMSG("Cannot open directory list!");
79
80 /* Loop over directories... */
81 char wrkdir[LEN];
82 while (fscanf(in, "%4999s", wrkdir) != EOF) {
83
84 /* Write info... */
85 LOG(1, "\nWorking directory: %s", wrkdir);
86
87 /* Call forward model... */
88 call_kernel(&ctl, tbl, wrkdir, argv[2], argv[3], argv[4]);
89 }
90
91 /* Close dirlist... */
92 fclose(in);
93 }
94
95 /* Free... */
96 free(tbl);
97
98 return EXIT_SUCCESS;
99}
100
101/*****************************************************************************/
102
104 const ctl_t *ctl,
105 const tbl_t *tbl,
106 const char *wrkdir,
107 const char *obsfile,
108 const char *atmfile,
109 const char *kernelfile) {
110
111 static atm_t atm;
112 static obs_t obs;
113
114 /* Read observation geometry... */
115 read_obs(wrkdir, obsfile, ctl, &obs);
116
117 /* Read atmospheric data... */
118 read_atm(wrkdir, atmfile, ctl, &atm);
119
120 /* Get sizes... */
121 const size_t n = atm2x(ctl, &atm, NULL, NULL, NULL);
122 const size_t m = obs2y(ctl, &obs, NULL, NULL, NULL);
123
124 /* Check sizes... */
125 if (n == 0)
126 ERRMSG("No state vector elements!");
127 if (m == 0)
128 ERRMSG("No measurement vector elements!");
129
130 /* Allocate... */
131 gsl_matrix *k = gsl_matrix_alloc(m, n);
132
133 /* Compute kernel matrix... */
134 kernel(ctl, tbl, &atm, &obs, k);
135
136 /* Write matrix to file... */
137 write_matrix(wrkdir, kernelfile, ctl, k, &atm, &obs, "y", "x", "r");
138
139 /* Free... */
140 gsl_matrix_free(k);
141}
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read forward model control parameters.
Definition: jurassic.c:4686
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data.
Definition: jurassic.c:4581
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs)
Read observation data.
Definition: jurassic.c:4842
void kernel(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs, gsl_matrix *k)
Compute Jacobians.
Definition: jurassic.c:4142
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
Definition: jurassic.c:5278
tbl_t * read_tbl(const ctl_t *ctl)
Read look-up table data.
Definition: jurassic.c:5104
size_t obs2y(const ctl_t *ctl, const obs_t *obs, gsl_vector *y, int *ida, int *ira)
Compose measurement vector.
Definition: jurassic.c:4312
size_t atm2x(const ctl_t *ctl, const atm_t *atm, gsl_vector *x, int *iqa, int *ipa)
Compose state vector or parameter vector.
Definition: jurassic.c:29
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)
Write matrix.
Definition: jurassic.c:5656
JURASSIC library declarations.
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:394
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:238
#define LOG(level,...)
Print log message.
Definition: jurassic.h:222
int main(int argc, char *argv[])
Definition: kernel.c:44
void call_kernel(const ctl_t *ctl, const tbl_t *tbl, const char *wrkdir, const char *obsfile, const char *atmfile, const char *kernelfile)
Perform kernel calculations in a single directory.
Definition: kernel.c:103
Atmospheric data.
Definition: jurassic.h:494
Forward model control parameters.
Definition: jurassic.h:547
int write_matrix
Write matrix file (0=no, 1=yes).
Definition: jurassic.h:688
Observation geometry and radiance data.
Definition: jurassic.h:761
Emissivity look-up tables.
Definition: jurassic.h:805