42 ERRMSG(
"Give parameters: <ctl> <atm_out>");
46 double t0 =
scan_ctl(argv[1], argc, argv,
"INIT_T0", -1,
"0", NULL);
47 double t1 =
scan_ctl(argv[1], argc, argv,
"INIT_T1", -1,
"0", NULL);
48 double dt =
scan_ctl(argv[1], argc, argv,
"INIT_DT", -1,
"1", NULL);
49 double z0 =
scan_ctl(argv[1], argc, argv,
"INIT_Z0", -1,
"0", NULL);
50 double z1 =
scan_ctl(argv[1], argc, argv,
"INIT_Z1", -1,
"0", NULL);
51 double dz =
scan_ctl(argv[1], argc, argv,
"INIT_DZ", -1,
"1", NULL);
52 double lon0 =
scan_ctl(argv[1], argc, argv,
"INIT_LON0", -1,
"0", NULL);
53 double lon1 =
scan_ctl(argv[1], argc, argv,
"INIT_LON1", -1,
"0", NULL);
54 double dlon =
scan_ctl(argv[1], argc, argv,
"INIT_DLON", -1,
"1", NULL);
55 double lat0 =
scan_ctl(argv[1], argc, argv,
"INIT_LAT0", -1,
"0", NULL);
56 double lat1 =
scan_ctl(argv[1], argc, argv,
"INIT_LAT1", -1,
"0", NULL);
57 double dlat =
scan_ctl(argv[1], argc, argv,
"INIT_DLAT", -1,
"1", NULL);
58 double st =
scan_ctl(argv[1], argc, argv,
"INIT_ST", -1,
"0", NULL);
59 double sz =
scan_ctl(argv[1], argc, argv,
"INIT_SZ", -1,
"0", NULL);
60 double slon =
scan_ctl(argv[1], argc, argv,
"INIT_SLON", -1,
"0", NULL);
61 double slat =
scan_ctl(argv[1], argc, argv,
"INIT_SLAT", -1,
"0", NULL);
62 double sx =
scan_ctl(argv[1], argc, argv,
"INIT_SX", -1,
"0", NULL);
63 double ut =
scan_ctl(argv[1], argc, argv,
"INIT_UT", -1,
"0", NULL);
64 double uz =
scan_ctl(argv[1], argc, argv,
"INIT_UZ", -1,
"0", NULL);
65 double ulon =
scan_ctl(argv[1], argc, argv,
"INIT_ULON", -1,
"0", NULL);
66 double ulat =
scan_ctl(argv[1], argc, argv,
"INIT_ULAT", -1,
"0", NULL);
68 (int)
scan_ctl(argv[1], argc, argv,
"INIT_EVENLY", -1,
"0", NULL);
69 int rep = (int)
scan_ctl(argv[1], argc, argv,
"INIT_REP", -1,
"1", NULL);
70 double m =
scan_ctl(argv[1], argc, argv,
"INIT_MASS", -1,
"0", NULL);
71 double vmr =
scan_ctl(argv[1], argc, argv,
"INIT_VMR", -1,
"0", NULL);
73 scan_ctl(argv[1], argc, argv,
"INIT_BELLRAD", -1,
"0", NULL);
77 rng = gsl_rng_alloc(gsl_rng_default);
80 for (
double t = t0; t <= t1; t += dt)
81 for (
double z = z0; z <= z1; z += dz)
82 for (
double lon = lon0; lon <= lon1; lon += dlon)
83 for (
double lat = lat0; lat <= lat1; lat += dlat)
84 for (
int irep = 0; irep < rep; irep++) {
87 double rg = gsl_ran_gaussian_ziggurat(rng, st / 2.3548);
88 double ru = ut * (gsl_rng_uniform(rng) - 0.5);
89 atm->
time[atm->
np] = (t + rg + ru);
91 rg = gsl_ran_gaussian_ziggurat(rng, sz / 2.3548);
92 ru = uz * (gsl_rng_uniform(rng) - 0.5);
93 atm->
p[atm->
np] =
P(z + rg + ru);
95 rg = gsl_ran_gaussian_ziggurat(rng, slon / 2.3548);
97 gsl_ran_gaussian_ziggurat(rng,
DX2DEG(sx, lat) / 2.3548);
98 ru = ulon * (gsl_rng_uniform(rng) - 0.5);
99 atm->
lon[atm->
np] = (lon + rg + rx + ru);
102 rg = gsl_ran_gaussian_ziggurat(rng, slat / 2.3548);
103 rx = gsl_ran_gaussian_ziggurat(rng,
DY2DEG(sx) / 2.3548);
104 ru = ulat * (gsl_rng_uniform(rng) - 0.5);
105 atm->
lat[atm->
np] = (lat + rg + rx + ru);
106 }
while (even && gsl_rng_uniform(rng) >
112 geo2cart(0.0, 0.5 * (lon0 + lon1), 0.5 * (lat0 + lat1), x0);
119 0.5 * (1. + cos(M_PI * rad / bellrad));
122 0.5 * (1. + cos(M_PI * rad / bellrad));
126 if ((++atm->
np) >
NP)
127 ERRMSG(
"Too many particles!");
132 ERRMSG(
"Did not create any air parcels!");
135 if (ctl.
qnt_m >= 0 && bellrad <= 0)
136 for (
int ip = 0; ip < atm->
np; ip++)
137 atm->
q[ctl.
qnt_m][ip] = m / atm->
np;
140 if (ctl.
qnt_vmr >= 0 && bellrad <= 0)
141 for (
int ip = 0; ip < atm->
np; ip++)
146 for (
int ip = 0; ip < atm->
np; ip++)
151 for (
int ip = 0; ip < atm->
np; ip++)
int main(int argc, char *argv[])
void write_atm(const char *filename, const ctl_t *ctl, const atm_t *atm, const double t)
Writes air parcel data to a file in various formats.
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 read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
void geo2cart(const double z, const double lon, const double lat, double *x)
Converts geographic coordinates (longitude, latitude, altitude) to Cartesian coordinates.
MPTRAC library declarations.
#define RE
Mean radius of Earth [km].
#define DOTP(a, b)
Calculate the dot product of two vectors.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define P(z)
Compute pressure at given altitude.
#define DX2DEG(dx, lat)
Convert a distance in kilometers to degrees longitude at a given latitude.
#define NORM(a)
Compute the norm (magnitude) of a vector.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define DEG2RAD(deg)
Converts degrees to radians.
#define NP
Maximum number of atmospheric data points.
#define DY2DEG(dy)
Convert a distance in kilometers to degrees latitude.
double lat[NP]
Latitude [deg].
double lon[NP]
Longitude [deg].
int np
Number of air parcels.
double q[NQ][NP]
Quantity data (for various, user-defined attributes).
double p[NP]
Pressure [hPa].
int qnt_m
Quantity array index for mass.
int qnt_aoa
Quantity array index for age of air.
int qnt_vmr
Quantity array index for volume mixing ratio.
int qnt_idx
Quantity array index for air parcel IDs.