32static void copy_density(
72 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
73 "Usage: tblrdc <ctl> <tblbase_in> <tblfmt_in> <tblbase_out> <tblfmt_out> [KEY VALUE ...]\n\n"
74 "Use -h for full help.");
78 const double atol =
scan_ctl(argc, argv,
"ATOL", -1,
"1e-9", NULL);
79 const double rtol =
scan_ctl(argc, argv,
"RTOL", -1,
"0.01", NULL);
82 sprintf(ctl.
tblbase,
"%s", argv[2]);
83 ctl.
tblfmt = atoi(argv[3]);
87 for (
int id = 0;
id < ctl.
nd;
id++)
88 for (
int ig = 0; ig < ctl.
ng; ig++) {
95 for (
int ip = 0; ip < tbl->
np[id][ig]; ip++) {
96 for (
int it = 0; it < tbl->
nt[id][ig][ip]; it++) {
98 const int num_points = tbl->
nu[id][ig][ip][it];
105 reduction(tbl,
id, ig, ip, it, 0, num_points - 1, &write_idx,
109 if (num_points > 1) {
110 copy_density(tbl,
id, ig, ip, it, write_idx, num_points - 1);
115 tbl->
nu[id][ig][ip][it] = write_idx;
116 total_input += num_points;
117 total_output += write_idx;
122 LOG(1,
"Reduction: %s | %.4f cm^-1 | n= %d | CR= %g", ctl.
emitter[ig],
123 ctl.
nu[
id], total_input,
124 total_output > 0 ? (
double) total_input / total_output : NAN);
129 sprintf(ctl.
tblbase,
"%s", argv[4]);
130 ctl.
tblfmt = atoi(argv[5]);
143 printf(
"\nJURASSIC lookup-table reduction tool.\n\n");
144 printf(
"Reduce look-up table size by adaptive interpolation with\n");
145 printf(
"absolute and relative error thresholds.\n\n");
148 (
" tblrdc <ctl> <tblbase_in> <tblfmt_in> <tblbase_out> <tblfmt_out>\n");
149 printf(
" [KEY VALUE ...]\n\n");
150 printf(
"Arguments:\n");
151 printf(
" <ctl> Control file.\n");
152 printf(
" <tblbase_in> Input table base name.\n");
153 printf(
" <tblfmt_in> Input table format identifier.\n");
154 printf(
" <tblbase_out> Output table base name.\n");
155 printf(
" <tblfmt_out> Output table format identifier.\n");
156 printf(
" [KEY VALUE] Optional control parameters.\n\n");
157 printf(
"Tool-specific control parameters:\n");
158 printf(
" ATOL <x> Absolute interpolation-error threshold.\n");
159 printf(
" RTOL <x> Relative interpolation-error threshold.\n\n");
160 printf(
"Common control parameters:\n");
161 printf(
" NG, EMITTER[i] Active emitters.\n");
162 printf(
" ND, NU[i] Spectral channels.\n\n");
163 printf(
"Further information:\n");
164 printf(
" Manual: https://slcs-jsc.github.io/jurassic/\n");
169static void copy_density(
178 tbl->
logu[id][ig][ip][it][dst] = tbl->
logu[id][ig][ip][it][src];
179 tbl->
logeps[id][ig][ip][it][dst] = tbl->
logeps[id][ig][ip][it][src];
184static void reduction(
197 double max_err = 0.0;
200 for (
int iu = left + 1; iu < right; iu++) {
203 const double interp_logeps =
204 LIN(tbl->
logu[
id][ig][ip][it][left], tbl->
logeps[
id][ig][ip][it][left],
205 tbl->
logu[
id][ig][ip][it][right],
206 tbl->
logeps[
id][ig][ip][it][right],
207 tbl->
logu[
id][ig][ip][it][iu]);
210 const double eps_i = exp((
double) tbl->
logeps[
id][ig][ip][it][iu]);
211 const double interp_eps = exp(interp_logeps);
212 const double diff = fabs(eps_i - interp_eps);
215 if (diff > atol + rtol * fabs(eps_i) && diff > max_err) {
222 if (worstindex != -1) {
225 if (worstindex - left > 1)
226 reduction(tbl,
id, ig, ip, it, left, worstindex, write_idx, atol, rtol);
229 copy_density(tbl,
id, ig, ip, it, *write_idx, worstindex);
233 if (right - worstindex > 1)
234 reduction(tbl,
id, ig, ip, it, worstindex, right, write_idx, atol,
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 write_tbl(const ctl_t *ctl, const tbl_t *tbl)
Write emissivity lookup tables to disk.
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.
tbl_t * read_tbl(const ctl_t *ctl)
Read emissivity lookup tables from disk.
JURASSIC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
#define LOG(level,...)
Print a log message with a specified logging level.
#define LIN(x0, y0, x1, y1, x)
Compute linear interpolation.
double nu[ND]
Centroid wavenumber of each channel [cm^-1].
char tblbase[LEN]
Basename for table files and filter function files.
int ng
Number of emitters.
int nd
Number of radiance channels.
char emitter[NG][LEN]
Name of each emitter.
int tblfmt
Look-up table file format (1=ASCII, 2=binary, 3=netCDF).
Emissivity look-up tables.
float * logu[ND][NG][TBLNP][TBLNT]
Logarithm of column density [molecules/cm^2].
int nu[ND][NG][TBLNP][TBLNT]
Number of column densities.
int nt[ND][NG][TBLNP]
Number of temperatures.
float * logeps[ND][NG][TBLNP][TBLNT]
Logarithm of emissivity.
int np[ND][NG]
Number of pressure levels.
int main(int argc, char *argv[])