Skip to content

Commit

Permalink
1528 Consider making the plotting options of plot_point_obs more conf…
Browse files Browse the repository at this point in the history
…igurable (#1559)

* #1528 Added get_dim_size

* #1528 Added qty_list

* #1528 Get the quality flag string. Get the character dimensions from the variable
  • Loading branch information
hsoh-u authored Nov 14, 2020
1 parent f0dfe00 commit 0a0841b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
21 changes: 15 additions & 6 deletions met/src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,7 @@ bool get_nc_data(NcVar *var, float *data) {
else {
int cell_count = 1;
for (int idx=0; idx<var->getDimCount();idx++) {
NcDim dim = var->getDim(idx);
cell_count *= get_dim_size(&dim);
cell_count *= get_dim_size(var, idx);
}

float add_offset = 0.;
Expand Down Expand Up @@ -1715,8 +1714,7 @@ bool get_nc_data(NcVar *var, double *data) {
else {
int cell_count = 1;
for (int idx=0; idx<var->getDimCount();idx++) {
NcDim dim = var->getDim(idx);
cell_count *= get_dim_size(&dim);
cell_count *= get_dim_size(var, idx);
}

double add_offset = 0.;
Expand Down Expand Up @@ -1952,8 +1950,7 @@ bool get_nc_data(NcVar *var, uchar *data) {
else if (NC_BYTE == data_type && has_unsigned_attribute(var)) {
int cell_count = 1;
for (int idx=0; idx<var->getDimCount(); idx++) {
NcDim dim = var->getDim(idx);
cell_count *= get_dim_size(&dim);
cell_count *= get_dim_size(var, idx);
}
ncbyte *signed_data = new ncbyte[cell_count];
return_status = _get_nc_data(var, signed_data);
Expand Down Expand Up @@ -3156,6 +3153,18 @@ int get_dim_size(const NcDim *dim) {

////////////////////////////////////////////////////////////////////////

int get_dim_size(const NcVar *var, const int dim_offset) {
int dim_size = -1;
if(IS_VALID_NC_P(var)) {
NcDim nc_dim = get_nc_dim(var, dim_offset);
if (IS_VALID_NC(nc_dim)) dim_size = nc_dim.getSize();
}

return( dim_size );
}

////////////////////////////////////////////////////////////////////////

int get_dim_value(const NcFile *nc, const string &dim_name, const bool error_out) {
NcDim dim;
int dim_val;
Expand Down
1 change: 1 addition & 0 deletions met/src/libcode/vx_nc_util/nc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ extern bool get_dim(const NcFile *, const ConcatString &, int &, bool error_ou
extern int get_dim_count(const NcVar *);
extern int get_dim_count(const NcFile *);
extern int get_dim_size(const NcDim *);
extern int get_dim_size(const NcVar *, const int dim_offset);
extern int get_dim_value(const NcFile *, const string &, const bool error_out = false);
extern NcDim get_nc_dim(const NcFile *, const string &dim_name);
extern NcDim get_nc_dim(const NcVar *, const string &dim_name);
Expand Down
57 changes: 50 additions & 7 deletions met/src/tools/other/plot_point_obs/plot_point_obs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ void process_point_obs(const char *point_obs_filename) {
int i, h, v;
int obs_hid_block[DEF_NC_BUFFER_SIZE];
int obs_vid_block[DEF_NC_BUFFER_SIZE];
int obs_qty_block[DEF_NC_BUFFER_SIZE];
float obs_lvl_block[DEF_NC_BUFFER_SIZE];
float obs_hgt_block[DEF_NC_BUFFER_SIZE];
float obs_val_block[DEF_NC_BUFFER_SIZE];
Expand Down Expand Up @@ -199,6 +200,7 @@ void process_point_obs(const char *point_obs_filename) {
NetcdfObsVars obsVars;
read_nc_dims_vars(obsVars, f_in);
bool use_var_id = obsVars.use_var_id;
bool use_qty_idx = IS_VALID_NC(obsVars.obs_qty_tbl_var);

//
// Print warning about ineffective command line arguments
Expand Down Expand Up @@ -278,13 +280,13 @@ void process_point_obs(const char *point_obs_filename) {
long lengths_1D[1] = { 1 };

if(use_var_id) {
NcDim bufr_var_dim = get_nc_dim(f_in, nc_dim_nvar);
long var_count = get_dim_size(&bufr_var_dim);
char obs_var_str[var_count][strl_len];
NcVar obs_var_var = get_nc_var(f_in, nc_var_obs_var);
long var_count = get_dim_size(&obs_var_var, 0);
long var_len = get_dim_size(&obs_var_var, 1);
char obs_var_str[var_count][var_len];

lengths[0] = var_count;
lengths[1] = strl_len;
lengths[1] = var_len;
if(!get_nc_data(&obs_var_var, (char *)&obs_var_str[0], lengths, offsets)) {
mlog << Error << "\nprocess_point_obs() -> "
<< "trouble getting " << nc_var_obs_var << "\n\n";
Expand All @@ -295,6 +297,28 @@ void process_point_obs(const char *point_obs_filename) {
}
}

long qty_len;
if(use_qty_idx) {
qty_len = get_dim_size(&obsVars.obs_qty_tbl_var, 1);
long qty_count = get_dim_size(&obsVars.obs_qty_tbl_var, 0);
char obs_var_str[qty_count][qty_len];

lengths[0] = qty_count;
lengths[1] = qty_len;
if(!get_nc_data(&obsVars.obs_qty_tbl_var, (char *)obs_var_str, lengths, offsets)) {
mlog << Error << "\nprocess_point_obs() -> "
<< "trouble getting " << nc_var_obs_qty_tbl << "\n\n";
exit(1);
}
for(int index=0; index<qty_count; index++) {
qty_list.add(obs_var_str[index]);
}
}
else {
qty_len = get_dim_size(&obsVars.obs_qty_var, 1);
}

char qty_str_block[DEF_NC_BUFFER_SIZE][qty_len];
for(int i_start=0; i_start<nobs_count; i_start+=buf_size) {
buf_size = ((nobs_count-i_start) > DEF_NC_BUFFER_SIZE) ?
DEF_NC_BUFFER_SIZE : (nobs_count-i_start);
Expand All @@ -304,7 +328,7 @@ void process_point_obs(const char *point_obs_filename) {
offsets_1D[0] = i_start;
lengths_1D[0] = buf_size;
if(use_obs_arr) {
lengths[1] = obs_arr_len;
lengths[1] = obs_arr_len;

// Read the current observation message
if(!get_nc_data(&obsVars.obs_arr_var, (float *) &obs_arr_block[0],
Expand All @@ -313,6 +337,18 @@ void process_point_obs(const char *point_obs_filename) {
<< "trouble getting obs_arr\n\n";
exit(1);
}

lengths[1] = qty_len;
if(!get_nc_data(&obsVars.obs_qty_var, (char *)qty_str_block, lengths, offsets)) {
mlog << Error << "\nprocess_point_obs() -> "
<< "trouble getting obs_qty\n\n";
exit(1);
}
qty_list.clear();
for(int index=0; index<buf_size; index++) {
qty_list.add(qty_str_block[index]);
}
lengths[1] = obs_arr_len;
}
else {
// Read the current observation message
Expand Down Expand Up @@ -343,6 +379,13 @@ void process_point_obs(const char *point_obs_filename) {
<< "trouble getting obs_val\n\n";
exit(1);
}
if (use_qty_idx) {
if(!get_nc_data(&obsVars.obs_qty_var, (int *)obs_qty_block, lengths_1D, offsets_1D)) {
mlog << Error << "\nprocess_point_obs() -> "
<< "trouble getting obs_qty\n\n";
exit(1);
}
}
}

int typ_idx, sid_idx, vld_idx;
Expand Down Expand Up @@ -373,7 +416,7 @@ void process_point_obs(const char *point_obs_filename) {
typ_idx = (use_obs_arr ? h : header_data.typ_idx_array[h]);
sid_idx = (use_obs_arr ? h : header_data.sid_idx_array[h]);
vld_idx = (use_obs_arr ? h : header_data.vld_idx_array[h]);

// Store data in an observation object
Observation cur_obs(
header_data.typ_array[typ_idx], // message type
Expand All @@ -385,7 +428,7 @@ void process_point_obs(const char *point_obs_filename) {
header_data.elv_array[h], // elevation
// TODO: need to parse quality
// string instead of using na_str!
na_string, // quality flag
(use_qty_idx ? qty_list[obs_qty_block[i_offset]] : qty_list[i_offset]), // quality flag
(use_var_id ? bad_data_int : v), // grib code
(double) obs_arr[2], // pressure
(double) obs_arr[3], // height
Expand Down
1 change: 1 addition & 0 deletions met/src/tools/other/plot_point_obs/plot_point_obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static StringArray ityp;
static IntArray ivar;
static StringArray svar;
static StringArray var_list;
static StringArray qty_list;

static ConcatString config_filename;
static PlotPointObsConfInfo conf_info;
Expand Down

0 comments on commit 0a0841b

Please sign in to comment.