JURASSIC
climatology.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/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32static void usage(
33 void);
34
35/* ------------------------------------------------------------
36 Main...
37 ------------------------------------------------------------ */
38
39int main(
40 int argc,
41 char *argv[]) {
42
43 static atm_t atm;
44 static ctl_t ctl;
45
46 double clk[NCL], sfeps[NSF];
47
48 /* Print usage information... */
49 USAGE;
50
51 /* Check arguments... */
52 if (argc < 3)
53 ERRMSG("Missing or invalid command-line arguments.\n\n"
54 "Usage: climatology <ctl> <atm> [KEY VALUE ...]\n\n"
55 "Use -h for full help.");
56
57 /* Read control parameters... */
58 read_ctl(argc, argv, &ctl);
59 const double t0 = scan_ctl(argc, argv, "T0", -1, "0", NULL);
60 const double t1 = scan_ctl(argc, argv, "T1", -1, "0", NULL);
61 const double dt = scan_ctl(argc, argv, "DT", -1, "1", NULL);
62 const double z0 = scan_ctl(argc, argv, "Z0", -1, "0", NULL);
63 const double z1 = scan_ctl(argc, argv, "Z1", -1, "90", NULL);
64 const double dz = scan_ctl(argc, argv, "DZ", -1, "1", NULL);
65 const double lat = scan_ctl(argc, argv, "LAT", -1, "0", NULL);
66 const int zsurf = (int) scan_ctl(argc, argv, "ZSURF", -1, "0", NULL);
67 const double clz = scan_ctl(argc, argv, "CLZ", -1, "0", NULL);
68 const double cldz = scan_ctl(argc, argv, "CLDZ", -1, "0", NULL);
69 for (int icl = 0; icl < ctl.ncl; icl++)
70 clk[icl] = scan_ctl(argc, argv, "CLK", icl, "0", NULL);
71 const double sft = scan_ctl(argc, argv, "SFT", -1, "0", NULL);
72 for (int isf = 0; isf < ctl.nsf; isf++)
73 sfeps[isf] = scan_ctl(argc, argv, "SFEPS", isf, "1", NULL);
74
75 /* Loop over time steps... */
76 for (double t = t0; t <= t1 + 0.5 * dt; t += dt) {
77
78 /* Init... */
79 atm.np = 0;
80
81 /* Refine near-surface layer... */
82 if (zsurf) {
83 atm.np = 4;
84 atm.z[0] = z0;
85 atm.z[1] = z0 + 0.01;
86 atm.z[2] = z0 + 0.02;
87 atm.z[3] = z0 + 0.05;
88 if (dz > 0.1)
89 for (double z = 0.1; z <= 1.0 + 1e-9; z += 0.1)
90 atm.z[atm.np++] = z0 + z;
91 if (dz > 0.2)
92 for (double z = 1.2; z <= 2.0 + 1e-9; z += 0.2)
93 atm.z[atm.np++] = z0 + z;
94 if (atm.np >= NP)
95 ERRMSG("Too many atmospheric grid points!");
96 }
97
98 /* Add heights... */
99 for (double z = z0; z <= z1; z += dz)
100 if (atm.np == 0 || z > atm.z[atm.np - 1] + 1e-9) {
101 atm.z[atm.np] = z;
102 if ((++atm.np) >= NP)
103 ERRMSG("Too many atmospheric grid points!");
104 }
105
106 /* Set time and latitude... */
107 for (int ip = 0; ip < atm.np; ip++) {
108 atm.time[ip] = t;
109 atm.lat[ip] = lat;
110 }
111 }
112
113 /* Read JuMACS climatology, if requested... */
114 clim_t *clim = read_clim(&ctl);
115
116 /* Interpolate climatological data... */
117 climatology(&ctl, clim, &atm);
118
119 /* Set cloud layer... */
120 atm.clz = clz;
121 atm.cldz = cldz;
122 for (int icl = 0; icl < ctl.ncl; icl++)
123 atm.clk[icl] = clk[icl];
124
125 /* Set surface layer... */
126 atm.sft = sft;
127 for (int isf = 0; isf < ctl.nsf; isf++)
128 atm.sfeps[isf] = sfeps[isf];
129
130 /* Write data to disk... */
131 write_atm(NULL, argv[2], &ctl, &atm, 0);
132
133 /* Free climatology... */
134 free(clim);
135
136 return EXIT_SUCCESS;
137}
138
139/*****************************************************************************/
140
141static void usage(
142 void) {
143 printf("\nJURASSIC climatology tool.\n\n");
144 printf("Prepare an atmospheric profile from climatological data and\n");
145 printf("write it to an atmospheric output file.\n\n");
146 printf("Usage:\n");
147 printf(" climatology <ctl> <atm> [KEY VALUE ...]\n\n");
148 printf("Arguments:\n");
149 printf(" <ctl> Control file.\n");
150 printf(" <atm> Output atmospheric data file.\n");
151 printf(" [KEY VALUE] Optional control parameters.\n\n");
152 printf("Tool-specific control parameters:\n");
153 printf(" T0, T1, DT Time range and spacing.\n");
154 printf(" Z0, Z1, DZ Altitude range and spacing.\n");
155 printf(" LAT Latitude of the profile.\n");
156 printf(" ZSURF Refine the near-surface grid if set.\n");
157 printf(" CLZ, CLDZ, CLK Cloud-layer settings.\n");
158 printf(" SFT, SFEPS Surface temperature and emissivity.\n\n");
159 printf("Common control parameters:\n");
160 printf(" ATMFMT Output atmospheric file format.\n");
161 printf(" NG, EMITTER[i] Active emitters.\n");
162 printf(" NW, WINDOW[i] Extinction-window layout.\n");
163 printf(" NCL, CLNU[i] Cloud spectral grid.\n");
164 printf(" NSF, SFNU[i] Surface spectral grid.\n\n");
165 printf("Further information:\n");
166 printf(" Manual: https://slcs-jsc.github.io/jurassic/\n");
167}
int main(int argc, char *argv[])
Definition: climatology.c:39
void write_atm(const char *dirname, const char *filename, const ctl_t *ctl, const atm_t *atm, int profile)
Write atmospheric data to a file.
Definition: jurassic.c:8044
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:6271
void climatology(const ctl_t *ctl, const clim_t *clim, atm_t *atm)
Initializes atmospheric climatology profiles.
Definition: jurassic.c:215
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:7349
clim_t * read_clim(const ctl_t *ctl)
Reads a JuMACS climatology file into an allocated climatology structure.
Definition: jurassic.c:1361
JURASSIC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1450
#define USAGE
Print usage information on -h or --help.
Definition: jurassic.h:1331
#define NP
Maximum number of atmospheric data points.
Definition: jurassic.h:392
#define NSF
Maximum number of surface layer spectral grid points.
Definition: jurassic.h:407
#define NCL
Maximum number of cloud layer spectral grid points.
Definition: jurassic.h:350
Atmospheric profile data.
Definition: jurassic.h:1500
double time[NP]
Time (seconds since 2000-01-01T00:00Z).
Definition: jurassic.h:1506
double sfeps[NSF]
Surface emissivity.
Definition: jurassic.h:1542
double lat[NP]
Latitude [deg].
Definition: jurassic.h:1515
double clz
Cloud layer height [km].
Definition: jurassic.h:1530
int np
Number of data points.
Definition: jurassic.h:1503
double cldz
Cloud layer depth [km].
Definition: jurassic.h:1533
double sft
Surface temperature [K].
Definition: jurassic.h:1539
double z[NP]
Altitude [km].
Definition: jurassic.h:1509
double clk[NCL]
Cloud layer extinction [km^-1].
Definition: jurassic.h:1536
JuMACS climatology on a fixed grid.
Definition: jurassic.h:1552
Control parameters.
Definition: jurassic.h:1592
int ncl
Number of cloud layer spectral grid points.
Definition: jurassic.h:1625
int nsf
Number of surface layer spectral grid points.
Definition: jurassic.h:1631