JURASSIC
Functions
kernel.c File Reference

Calculate kernel functions. More...

#include "jurassic.h"

Go to the source code of this file.

Functions

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. More...
 
void usage (void)
 Print command-line help. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Calculate kernel functions.

Definition in file kernel.c.

Function Documentation

◆ call_kernel()

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 at line 160 of file kernel.c.

166 {
167
168 static atm_t atm;
169 static obs_t obs;
170
171 /* Read observation geometry... */
172 SELECT_TIMER("READ_OBS", "INPUT");
173 read_obs(wrkdir, obsfile, ctl, &obs, 0);
174
175 /* Read atmospheric data... */
176 SELECT_TIMER("READ_ATM", "INPUT");
177 read_atm(wrkdir, atmfile, ctl, &atm, 0);
178
179 /* Get sizes... */
180 const size_t n = atm2x(ctl, &atm, NULL, NULL, NULL);
181 const size_t m = obs2y(ctl, &obs, NULL, NULL, NULL);
182
183 /* Check sizes... */
184 if (n == 0)
185 ERRMSG("No state vector elements!");
186 if (m == 0)
187 ERRMSG("No measurement vector elements!");
188
189 /* Allocate... */
190 gsl_matrix *k = gsl_matrix_alloc(m, n);
191
192 /* Compute kernel matrix... */
193 SELECT_TIMER("KERNEL", "FORWARD");
194 kernel(ctl, tbl, &atm, &obs, k);
195
196 /* Write matrix to file... */
197 SELECT_TIMER("WRITE_MATRIX", "OUTPUT");
198 write_matrix(wrkdir, kernelfile, ctl, k, &atm, &obs, "y", "x", "r", 0);
199
200 /* Free... */
201 gsl_matrix_free(k);
202}
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:5810
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:7753
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:5193
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:4387
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:4627
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 SELECT_TIMER(id, group)
Switch to a named aggregated timer.
Definition: jurassic.h:1158
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1325
Atmospheric profile data.
Definition: jurassic.h:1375
Observation geometry and radiance data.
Definition: jurassic.h:1657
Here is the call graph for this function:

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 117 of file kernel.c.

118 {
119
120 printf("\nJURASSIC kernel tool.\n\n");
121 printf("Compute Jacobian or kernel matrices for the configured channels\n");
122 printf
123 ("from observation geometry, atmospheric state, and control settings.\n\n");
124 printf("Usage:\n");
125 printf(" kernel <ctl> <obs> <atm> <kernel> [KEY VALUE ...]\n\n");
126 printf("Arguments:\n");
127 printf(" <ctl> Control file.\n");
128 printf(" <obs> Observation geometry input file.\n");
129 printf(" <atm> Atmospheric state input file.\n");
130 printf(" <kernel> Output file for the kernel matrix.\n");
131 printf(" [KEY VALUE] Optional control parameters.\n\n");
132 printf("Tool-specific control parameters:\n");
133 printf
134 (" DIRLIST <file> Read working directories from <file> and run one case\n");
135 printf
136 (" per directory using the same <obs>, <atm>, and\n");
137 printf
138 (" <kernel> filenames relative to each listed directory.\n");
139 printf("\n");
140 printf("Common control parameters:\n");
141 printf
142 (" TBLBASE, TBLFMT Lookup-table base name and format.\n");
143 printf(" ATMFMT, OBSFMT, MATRIXFMT Input/output file formats.\n");
144 printf(" NG, EMITTER[i] Active emitters.\n");
145 printf(" ND, NU[i], NW, WINDOW[i] Spectral channels and windows.\n");
146 printf
147 (" NCL, CLNU[i], NSF, SFNU[i] Cloud and surface spectral grids.\n");
148 printf(" RET*_ZMIN, RET*_ZMAX State-vector altitude limits.\n");
149 printf
150 (" WRITE_BBT, FORMOD Output units and forward-model selection.\n");
151 printf(" CTM_*, REFRAC Continua and refractivity.\n");
152 printf
153 (" RAYDS, RAYDZ, FOV Ray tracing and field of view.\n\n");
154 printf("Further information:\n");
155 printf(" Manual: https://slcs-jsc.github.io/jurassic/\n");
156}

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 48 of file kernel.c.

50 {
51
52 static ctl_t ctl;
53
54 char dirlist[LEN];
55
56 /* Print usage information... */
57 USAGE;
58
59 /* Check arguments... */
60 if (argc < 5)
61 ERRMSG("Missing or invalid command-line arguments.\n\n"
62 "Usage: kernel <ctl> <obs> <atm> <kernel> [KEY VALUE ...]\n\n"
63 "Use -h for full help.");
64
65 /* Read control parameters... */
66 SELECT_TIMER("READ_CTL", "INPUT");
67 read_ctl(argc, argv, &ctl);
68
69 /* Initialize look-up tables... */
70 SELECT_TIMER("READ_TBL", "INPUT");
71 tbl_t *tbl = read_tbl(&ctl);
72
73 /* Get dirlist... */
74 SELECT_TIMER("READ_DIRLIST", "INPUT");
75 scan_ctl(argc, argv, "DIRLIST", -1, "-", dirlist);
76
77 /* Set flags... */
78 ctl.write_matrix = 1;
79
80 /* Single kernel calculation... */
81 if (dirlist[0] == '-')
82 call_kernel(&ctl, tbl, NULL, argv[2], argv[3], argv[4]);
83
84 /* Work on directory list... */
85 else {
86
87 /* Open directory list... */
88 FILE *in;
89 if (!(in = fopen(dirlist, "r")))
90 ERRMSG("Cannot open directory list!");
91
92 /* Loop over directories... */
93 char wrkdir[LEN];
94 while (fscanf(in, "%4999s", wrkdir) != EOF) {
95
96 /* Write info... */
97 LOG(1, "\nWorking directory: %s", wrkdir);
98
99 /* Call forward model... */
100 call_kernel(&ctl, tbl, wrkdir, argv[2], argv[3], argv[4]);
101 }
102
103 /* Close dirlist... */
104 fclose(in);
105 }
106
107 /* Free... */
108 SELECT_TIMER("FINALIZE", "OVERHEAD");
109 tbl_free(&ctl, tbl);
111
112 return EXIT_SUCCESS;
113}
void tbl_free(const ctl_t *ctl, tbl_t *tbl)
Free lookup table and all internally allocated memory.
Definition: jurassic.c:7002
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:5516
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:6612
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
Definition: jurassic.c:6332
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:268
#define USAGE
Print usage information on -h or --help.
Definition: jurassic.h:1206
#define PRINT_TIMERS
Print aggregated timer statistics.
Definition: jurassic.h:1168
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: jurassic.h:1255
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:160
Control parameters.
Definition: jurassic.h:1428
int write_matrix
Write matrix file (0=no, 1=yes).
Definition: jurassic.h:1572
Emissivity look-up tables.
Definition: jurassic.h:1842
Here is the call graph for this function: