MPTRAC
Functions
met_check_dt.c File Reference

Check model time step based on given meteorological data. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

void usage (void)
 Print command-line help. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Check model time step based on given meteorological data.

Definition in file met_check_dt.c.

Function Documentation

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 148 of file met_check_dt.c.

149 {
150
151 printf("\nMPTRAC met_check_dt tool.\n\n");
152 printf("Check model time-step constraints for meteorological data.\n");
153 printf("\n");
154 printf("Usage:\n");
155 printf(" met_check_dt <ctl> <dt_file> <met> [KEY VALUE ...]\n");
156 printf("\n");
157 printf("Arguments:\n");
158 printf(" <ctl> Control file.\n");
159 printf(" <dt_file> Output table for time-step diagnostics.\n");
160 printf(" <met> Meteorological input file.\n");
161 printf(" [KEY VALUE] Optional control parameters.\n");
162 printf("\nFurther information:\n");
163 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
164}

◆ main()

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

Definition at line 39 of file met_check_dt.c.

41 {
42
43 ctl_t ctl;
44
45 clim_t *clim;
46
47 met_t *met;
48
49 dd_t *dd;
50
51 /* Print usage information... */
52 USAGE;
53
54 /* Check arguments... */
55 if (argc < 4)
56 ERRMSG("Missing or invalid command-line arguments.\n\n"
57 "Usage: met_check_dt <ctl> <dt_file> <met> [KEY VALUE ...]\n\n"
58 "Use -h for full help.");
59
60 /* Allocate... */
61 ALLOC(clim, clim_t, 1);
62 ALLOC(met, met_t, 1);
63 ALLOC(dd, dd_t, 1);
64
65 /* Read control parameters... */
66 mptrac_read_ctl(argv[1], argc, argv, &ctl);
67 const double kx = scan_ctl(argv[1], argc, argv, "KX", -1, "50.0", NULL);
68 const double kz = scan_ctl(argv[1], argc, argv, "KZ", -1, "0.1", NULL);
69 const double dx = 1e3 * scan_ctl(argv[1], argc, argv, "DX", -1, "", NULL);
70 const double c_max = scan_ctl(argv[1], argc, argv, "CMAX", -1, "0.5", NULL);
71 const double n_max = scan_ctl(argv[1], argc, argv, "NMAX", -1, "0.3", NULL);
72
73 /* Read climatological data... */
74 mptrac_read_clim(&ctl, clim);
75
76 /* Read meteo data... */
77 if (!mptrac_read_met(argv[3], &ctl, clim, met, dd))
78 ERRMSG("Cannot open file!");
79
80 /* Create output file... */
81 FILE *out;
82 LOG(1, "Write time step data file: %s", argv[2]);
83 if (!(out = fopen(argv[2], "w")))
84 ERRMSG("Cannot create file!");
85
86 /* Write header... */
87 fprintf(out,
88 "# $1 = height [km]\n"
89 "# $2 = time step for horizontal advection [s]\n"
90 "# $3 = time step for vertical advection [s]\n"
91 "# $4 = time step for horizontal diffusion [s]\n"
92 "# $5 = time step for vertical diffusion [s]\n\n");
93
94 /* Loop over pressure levels... */
95 for (int ip = 1; ip < met->np - 1; ip++) {
96
97 /* Init... */
98 double dt_x_min = 1e100;
99 double dt_p_min = 1e100;
100 double dt_dx_min = 1e100;
101 double dt_dp_min = 1e100;
102
103 /* Loop over columns... */
104#pragma omp parallel for default(shared) collapse(2) reduction(min:dt_x_min,dt_p_min,dt_dx_min,dt_dp_min)
105 for (int ix = 0; ix < met->nx; ix++)
106 for (int iy = 1; iy < met->ny - 1; iy++) {
107
108 /* Check advection... */
109 const double vh =
110 sqrt(SQR(met->u[ix][iy][ip]) + SQR(met->v[ix][iy][ip]));
111 const double dt_x = fabs(c_max * dx / vh);
112 if (vh != 0)
113 dt_x_min = MIN(dt_x, dt_x_min);
114
115 const double dp = 0.5 * fabs(met->p[ip + 1] - met->p[ip - 1]);
116 const double dt_p = fabs(c_max * dp / met->w[ix][iy][ip]);
117 if (met->w[ix][iy][ip] != 0)
118 dt_p_min = MIN(dt_p, dt_p_min);
119
120 /* Check diffusion... */
121 const double dt_dx = 0.5 * SQR(n_max * dx) / kx;
122 dt_dx_min = MIN(dt_dx, dt_dx_min);
123
124 const double dt_dp =
125 0.5 * SQR(n_max * dp) / (SQR(met->p[ip] / (100. * H0)) * kz);
126 dt_dp_min = MIN(dt_dp, dt_dp_min);
127 }
128
129 /* Write output... */
130 fprintf(out, "%g %g %g %g %g\n", Z(met->p[ip]), dt_x_min, dt_p_min,
131 dt_dx_min, dt_dp_min);
132 }
133
134 /* Close output file... */
135 fclose(out);
136
137 /* Free... */
138 free(clim);
139 free(met);
140 free(dd);
141
142 return EXIT_SUCCESS;
143}
double scan_ctl(const char *filename, int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scans a control file or command-line arguments for a specified variable.
Definition: mptrac.c:10745
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:5188
int mptrac_read_met(const char *filename, const ctl_t *ctl, const clim_t *clim, met_t *met, dd_t *dd)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
Definition: mptrac.c:6151
void mptrac_read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
Definition: mptrac.c:5248
#define H0
Scale height [km].
Definition: mptrac.h:266
#define MIN(a, b)
Macro to determine the minimum of two values.
Definition: mptrac.h:1175
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2102
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:1909
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:1939
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:453
#define SQR(x)
Compute the square of a value.
Definition: mptrac.h:1733
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:2032
Climatological data.
Definition: mptrac.h:3436
Control parameters.
Definition: mptrac.h:2190
Domain decomposition data structure.
Definition: mptrac.h:3669
Meteo data structure.
Definition: mptrac.h:3495
float w[EX][EY][EP]
Vertical velocity [hPa/s].
Definition: mptrac.h:3618
int nx
Number of longitudes.
Definition: mptrac.h:3501
int ny
Number of latitudes.
Definition: mptrac.h:3504
int np
Number of pressure levels.
Definition: mptrac.h:3507
float u[EX][EY][EP]
Zonal wind [m/s].
Definition: mptrac.h:3612
float v[EX][EY][EP]
Meridional wind [m/s].
Definition: mptrac.h:3615
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3519
Here is the call graph for this function: