41 int dims[10], ncid, varid;
43 size_t start[10], count[10];
51 ERRMSG(
"Give parameters: <ctl> <met.nc>");
60 if (!
read_met(argv[2], &ctl, clim, met))
61 ERRMSG(
"Cannot open file!");
64 if (nc_open(argv[2], NC_WRITE, &ncid) != NC_NOERR)
65 ERRMSG(
"Cannot open file!");
71 NC(nc_inq_dimid(ncid,
"time", &dims[0]));
72 NC(nc_inq_dimid(ncid,
"lat", &dims[1]));
73 NC(nc_inq_dimid(ncid,
"lon", &dims[2]));
80 "convective available potential energy",
"J kg**-1", 0, 0);
82 "convective inhibition",
"J kg**-1", 0, 0);
84 "pressure at equilibrium level",
"hPa", 0, 0);
87 time_t t = time(NULL);
88 struct tm tm = *localtime(&t);
89 sprintf(tstr,
"%d-%02d-%02d %02d:%02d:%02d",
90 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
91 tm.tm_hour, tm.tm_min, tm.tm_sec);
94 NC_PUT_ATT(
"CAPE_MPT",
"creator_of_parameter",
"MPTRAC");
95 NC_PUT_ATT(
"CIN_MPT",
"creator_of_parameter",
"MPTRAC");
96 NC_PUT_ATT(
"PEL_MPT",
"creator_of_parameter",
"MPTRAC");
98 NC_PUT_ATT(
"CAPE_MPT",
"param_creation_time", tstr);
99 NC_PUT_ATT(
"CIN_MPT",
"param_creation_time", tstr);
100 NC_PUT_ATT(
"PEL_MPT",
"param_creation_time", tstr);
102 NC_PUT_ATT(
"CAPE_MPT",
"param_modification_time", tstr);
103 NC_PUT_ATT(
"CIN_MPT",
"param_modification_time", tstr);
104 NC_PUT_ATT(
"PEL_MPT",
"param_modification_time", tstr);
110 float miss[1] = { NAN };
111 NC(nc_inq_varid(ncid,
"CAPE_MPT", &varid));
112 NC(nc_put_att_float(ncid, varid,
"missing_value", NC_FLOAT, 1, miss));
113 NC(nc_inq_varid(ncid,
"CIN_MPT", &varid));
114 NC(nc_put_att_float(ncid, varid,
"missing_value", NC_FLOAT, 1, miss));
115 NC(nc_inq_varid(ncid,
"PEL_MPT", &varid));
116 NC(nc_put_att_float(ncid, varid,
"missing_value", NC_FLOAT, 1, miss));
122 for (
int ix = 0; ix < met->
nx - 1; ix++)
123 for (
int iy = 0; iy < met->
ny; iy++)
127 for (
int ix = 0; ix < met->
nx - 1; ix++)
128 for (
int iy = 0; iy < met->
ny; iy++)
132 for (
int ix = 0; ix < met->
nx - 1; ix++)
133 for (
int iy = 0; iy < met->
ny; iy++)
int main(int argc, char *argv[])
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.
int read_met(const char *filename, ctl_t *ctl, clim_t *clim, met_t *met)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
MPTRAC library declarations.
#define LEN
Maximum length of ASCII data lines.
#define NC(cmd)
Execute a NetCDF command and check for errors.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define EY
Maximum number of latitudes for meteo data.
#define ARRAY_2D(ix, iy, ny)
Macro for computing the linear index of a 2D array element.
#define EX
Maximum number of longitudes for meteo data.
#define NC_PUT_ATT(varname, attname, text)
Add a text attribute to a NetCDF variable.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define NC_INQ_DIM(dimname, ptr, min, max)
Inquire the length of a dimension in a NetCDF file.
#define NC_PUT_FLOAT(varname, ptr, hyperslab)
Write a float array to a NetCDF file.
#define NC_DEF_VAR(varname, type, ndims, dims, long_name, units, level, quant)
Define a NetCDF variable with attributes.
float cape[EX][EY]
Convective available potential energy [J/kg].
int nx
Number of longitudes.
int ny
Number of latitudes.
float pel[EX][EY]
Pressure at equilibrium level [hPa].
float cin[EX][EY]
Convective inhibition [J/kg].