41 ERRMSG(
"Give parameters: <ctl> <dt_file> <met>");
50 const double kx =
scan_ctl(argv[1], argc, argv,
"KX", -1,
"50.0", NULL);
51 const double kz =
scan_ctl(argv[1], argc, argv,
"KZ", -1,
"0.1", NULL);
52 const double dx = 1e3 *
scan_ctl(argv[1], argc, argv,
"DX", -1,
"", NULL);
53 const double c_max =
scan_ctl(argv[1], argc, argv,
"CMAX", -1,
"0.5", NULL);
54 const double n_max =
scan_ctl(argv[1], argc, argv,
"NMAX", -1,
"0.3", NULL);
61 ERRMSG(
"Cannot open file!");
65 LOG(1,
"Write time step data file: %s", argv[2]);
66 if (!(out = fopen(argv[2],
"w")))
67 ERRMSG(
"Cannot create file!");
71 "# $1 = height [km]\n"
72 "# $2 = time step for horizontal advection [s]\n"
73 "# $3 = time step for vertical advection [s]\n"
74 "# $4 = time step for horizontal diffusion [s]\n"
75 "# $5 = time step for vertical diffusion [s]\n\n");
78 for (
int ip = 1; ip < met->
np - 1; ip++) {
81 double dt_x_min = 1e100;
82 double dt_p_min = 1e100;
83 double dt_dx_min = 1e100;
84 double dt_dp_min = 1e100;
87#pragma omp parallel for default(shared) collapse(2) reduction(min:dt_x_min,dt_p_min,dt_dx_min,dt_dp_min)
88 for (
int ix = 0; ix < met->
nx; ix++)
89 for (
int iy = 1; iy < met->
ny - 1; iy++) {
93 sqrt(
SQR(met->
u[ix][iy][ip]) +
SQR(met->
v[ix][iy][ip]));
94 const double dt_x = fabs(c_max * dx / vh);
96 dt_x_min =
MIN(dt_x, dt_x_min);
98 const double dp = 0.5 * fabs(met->
p[ip + 1] - met->
p[ip - 1]);
99 const double dt_p = fabs(c_max * dp / met->
w[ix][iy][ip]);
100 if (met->
w[ix][iy][ip])
101 dt_p_min =
MIN(dt_p, dt_p_min);
104 const double dt_dx = 0.5 *
SQR(n_max * dx) / kx;
105 dt_dx_min =
MIN(dt_dx, dt_dx_min);
108 0.5 *
SQR(n_max * dp) / (
SQR(met->
p[ip] / (100. *
H0)) * kz);
109 dt_dp_min =
MIN(dt_dp, dt_dp_min);
113 fprintf(out,
"%g %g %g %g %g\n",
Z(met->
p[ip]), dt_x_min, dt_p_min,
114 dt_dx_min, dt_dp_min);
int main(int argc, char *argv[])
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.
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
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.
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.
MPTRAC library declarations.
#define H0
Scale height [km].
#define MIN(a, b)
Macro to determine the minimum of two values.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define Z(p)
Convert pressure to altitude.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define SQR(x)
Compute the square of a value.
#define LOG(level,...)
Print a log message with a specified logging level.
Domain decomposition data structure.
float w[EX][EY][EP]
Vertical velocity [hPa/s].
int nx
Number of longitudes.
int ny
Number of latitudes.
int np
Number of pressure levels.
float u[EX][EY][EP]
Zonal wind [m/s].
float v[EX][EY][EP]
Meridional wind [m/s].
double p[EP]
Pressure levels [hPa].