Skip to content

Commit

Permalink
Revised code to read surface data.
Browse files Browse the repository at this point in the history
  • Loading branch information
lars2015 committed Nov 3, 2024
1 parent caf2fdf commit 86b94d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 76 deletions.
132 changes: 56 additions & 76 deletions src/mptrac.c
Original file line number Diff line number Diff line change
Expand Up @@ -6845,6 +6845,8 @@ int read_met_nc_2d(
const char *varname2,
const char *varname3,
const char *varname4,
const char *varname5,
const char *varname6,
const ctl_t *ctl,
const met_t *met,
float dest[EX][EY],
Expand All @@ -6869,6 +6871,12 @@ int read_met_nc_2d(
else if (varname4 != NULL
&& nc_inq_varid(ncid, varname4, &varid) == NC_NOERR)
sprintf(varsel, "%s", varname4);
else if (varname5 != NULL
&& nc_inq_varid(ncid, varname5, &varid) == NC_NOERR)
sprintf(varsel, "%s", varname5);
else if (varname6 != NULL
&& nc_inq_varid(ncid, varname6, &varid) == NC_NOERR)
sprintf(varsel, "%s", varname6);
else
return 0;

Expand Down Expand Up @@ -7612,71 +7620,39 @@ void read_met_surface(
SELECT_TIMER("READ_MET_SURFACE", "INPUT", NVTX_READ);
LOG(2, "Read surface data...");

/* Read surface pressure... */
if (read_met_nc_2d
(ncid, "lnsp", "LNSP", NULL, NULL, NULL, NULL, ctl, met, met->ps, 1.0f,
1)) {
for (int ix = 0; ix < met->nx; ix++)
for (int iy = 0; iy < met->ny; iy++)
met->ps[ix][iy] = (float) (exp(met->ps[ix][iy]) / 100.);
} else
if (!read_met_nc_2d
(ncid, "ps", "PS", "sp", "SP", NULL, NULL, ctl, met, met->ps, 0.01f,
1)) {
WARN("Cannot not read surface pressure data (use lowest level)!");
for (int ix = 0; ix < met->nx; ix++)
for (int iy = 0; iy < met->ny; iy++)
met->ps[ix][iy] = (float) met->p[0];
}

/* MPTRAC meteo data... */
if (ctl->met_clams == 0) {

/* Read surface pressure... */
if (read_met_nc_2d
(ncid, "lnsp", "LNSP", NULL, NULL, ctl, met, met->ps, 1.0f, 1)) {
for (int ix = 0; ix < met->nx; ix++)
for (int iy = 0; iy < met->ny; iy++)
met->ps[ix][iy] = (float) (exp(met->ps[ix][iy]) / 100.);
} else
if (!read_met_nc_2d
(ncid, "ps", "PS", "sp", "SP", ctl, met, met->ps, 0.01f, 1)) {
WARN("Cannot not read surface pressure data (use lowest level)!");
for (int ix = 0; ix < met->nx; ix++)
for (int iy = 0; iy < met->ny; iy++)
met->ps[ix][iy] = (float) met->p[0];
}

/* Read geopotential height at the surface... */
if (!read_met_nc_2d
(ncid, "z", "Z", NULL, NULL, ctl, met, met->zs,
(ncid, "z", "Z", NULL, NULL, NULL, NULL, ctl, met, met->zs,
(float) (1. / (1000. * G0)), 1))
if (!read_met_nc_2d
(ncid, "zm", "ZM", NULL, NULL, ctl, met, met->zs,
(ncid, "zm", "ZM", NULL, NULL, NULL, NULL, ctl, met, met->zs,
(float) (1. / 1000.), 1))
WARN("Cannot read surface geopotential height!");

/* Read temperature at the surface... */
if (!read_met_nc_2d
(ncid, "t2m", "T2M", "2t", "2T", ctl, met, met->ts, 1.0, 1))
WARN("Cannot read surface temperature!");

/* Read zonal wind at the surface... */
if (!read_met_nc_2d
(ncid, "u10m", "U10M", "10u", "10U", ctl, met, met->us, 1.0, 1))
WARN("Cannot read surface zonal wind!");

/* Read meridional wind at the surface... */
if (!read_met_nc_2d
(ncid, "v10m", "V10M", "10v", "10V", ctl, met, met->vs, 1.0, 1))
WARN("Cannot read surface meridional wind!");

/* Read land-sea mask... */
if (!read_met_nc_2d
(ncid, "lsm", "LSM", NULL, NULL, ctl, met, met->lsm, 1.0, 1))
WARN("Cannot read land-sea mask!");

/* Read sea surface temperature... */
if (!read_met_nc_2d
(ncid, "sstk", "SSTK", "sst", "SST", ctl, met, met->sst, 1.0, 1))
WARN("Cannot read sea surface temperature!");
}

/* CLaMS meteo data... */
else {

/* Read surface pressure... */
if (!read_met_nc_2d
(ncid, "ps", "PS", NULL, NULL, ctl, met, met->ps, 0.01f, 1)) {
WARN("Cannot not read surface pressure data (use lowest level)!");
for (int ix = 0; ix < met->nx; ix++)
for (int iy = 0; iy < met->ny; iy++)
met->ps[ix][iy] = (float) met->p[0];
}

/* Read geopotential height at the surface
(use lowermost level of 3-D data field)... */
float *help;
Expand All @@ -7692,32 +7668,36 @@ void read_met_surface(
met->zs[ix][iy] = met->pl[ix][iy][0];
memcpy(met->pl, help, sizeof(met->pl));
free(help);

/* Read temperature at the surface... */
if (!read_met_nc_2d
(ncid, "t2", "T2", NULL, NULL, ctl, met, met->ts, 1.0, 1))
WARN("Cannot read surface temperature!");

/* Read zonal wind at the surface... */
if (!read_met_nc_2d
(ncid, "u10", "U10", NULL, NULL, ctl, met, met->us, 1.0, 1))
WARN("Cannot read surface zonal wind!");

/* Read meridional wind at the surface... */
if (!read_met_nc_2d
(ncid, "v10", "V10", NULL, NULL, ctl, met, met->vs, 1.0, 1))
WARN("Cannot read surface meridional wind!");

/* Read land-sea mask... */
if (!read_met_nc_2d
(ncid, "lsm", "LSM", NULL, NULL, ctl, met, met->lsm, 1.0, 1))
WARN("Cannot read land-sea mask!");

/* Read sea surface temperature... */
if (!read_met_nc_2d
(ncid, "sstk", "SSTK", NULL, NULL, ctl, met, met->sst, 1.0, 1))
WARN("Cannot read sea surface temperature!");
}

/* Read temperature at the surface... */
if (!read_met_nc_2d
(ncid, "t2m", "T2M", "2t", "2T", "t2", "T2", ctl, met, met->ts, 1.0, 1))
WARN("Cannot read surface temperature!");

/* Read zonal wind at the surface... */
if (!read_met_nc_2d
(ncid, "u10m", "U10M", "10u", "10U", "u10", "U10", ctl, met, met->us,
1.0, 1))
WARN("Cannot read surface zonal wind!");

/* Read meridional wind at the surface... */
if (!read_met_nc_2d
(ncid, "v10m", "V10M", "10v", "10V", "v10", "V10", ctl, met, met->vs,
1.0, 1))
WARN("Cannot read surface meridional wind!");

/* Read land-sea mask... */
if (!read_met_nc_2d
(ncid, "lsm", "LSM", NULL, NULL, NULL, NULL, ctl, met, met->lsm, 1.0,
1))
WARN("Cannot read land-sea mask!");

/* Read sea surface temperature... */
if (!read_met_nc_2d
(ncid, "sstk", "SSTK", "sst", "SST", NULL, NULL, ctl, met, met->sst,
1.0, 1))
WARN("Cannot read sea surface temperature!");
}

/*****************************************************************************/
Expand Down
4 changes: 4 additions & 0 deletions src/mptrac.h
Original file line number Diff line number Diff line change
Expand Up @@ -6579,6 +6579,8 @@ int read_met_nc_2d(
const char *varname2,
const char *varname3,
const char *varname4,
const char *varname5,
const char *varname6,
const ctl_t * ctl,
const met_t * met,
float dest[EX][EY],
Expand All @@ -6599,6 +6601,8 @@ int read_met_nc_2d(
* @param varname2 An alternative name of the variable to read (in case varname is not found).
* @param varname3 An alternative name of the variable to read (in case varname2 is not found).
* @param varname4 An alternative name of the variable to read (in case varname3 is not found).
* @param varname5 An alternative name of the variable to read (in case varname4 is not found).
* @param varname6 An alternative name of the variable to read (in case varname5 is not found).
* @param ctl A pointer to a structure containing control parameters.
* @param met A pointer to a structure containing meteorological data.
* @param dest The destination array to store the read data.
Expand Down

0 comments on commit 86b94d8

Please sign in to comment.