From 0a0841b7dc85c5442d57fa7fddfb9d947fe80606 Mon Sep 17 00:00:00 2001 From: hsoh-u Date: Sat, 14 Nov 2020 13:25:15 -0700 Subject: [PATCH] 1528 Consider making the plotting options of plot_point_obs more configurable (#1559) * #1528 Added get_dim_size * #1528 Added qty_list * #1528 Get the quality flag string. Get the character dimensions from the variable --- met/src/libcode/vx_nc_util/nc_utils.cc | 21 +++++-- met/src/libcode/vx_nc_util/nc_utils.h | 1 + .../other/plot_point_obs/plot_point_obs.cc | 57 ++++++++++++++++--- .../other/plot_point_obs/plot_point_obs.h | 1 + 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/met/src/libcode/vx_nc_util/nc_utils.cc b/met/src/libcode/vx_nc_util/nc_utils.cc index 7953777396..eebd06a820 100644 --- a/met/src/libcode/vx_nc_util/nc_utils.cc +++ b/met/src/libcode/vx_nc_util/nc_utils.cc @@ -1431,8 +1431,7 @@ bool get_nc_data(NcVar *var, float *data) { else { int cell_count = 1; for (int idx=0; idxgetDimCount();idx++) { - NcDim dim = var->getDim(idx); - cell_count *= get_dim_size(&dim); + cell_count *= get_dim_size(var, idx); } float add_offset = 0.; @@ -1715,8 +1714,7 @@ bool get_nc_data(NcVar *var, double *data) { else { int cell_count = 1; for (int idx=0; idxgetDimCount();idx++) { - NcDim dim = var->getDim(idx); - cell_count *= get_dim_size(&dim); + cell_count *= get_dim_size(var, idx); } double add_offset = 0.; @@ -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; idxgetDimCount(); 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); @@ -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; diff --git a/met/src/libcode/vx_nc_util/nc_utils.h b/met/src/libcode/vx_nc_util/nc_utils.h index b1af9cd5c4..9945afc563 100644 --- a/met/src/libcode/vx_nc_util/nc_utils.h +++ b/met/src/libcode/vx_nc_util/nc_utils.h @@ -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); diff --git a/met/src/tools/other/plot_point_obs/plot_point_obs.cc b/met/src/tools/other/plot_point_obs/plot_point_obs.cc index ef43727085..3de727992b 100644 --- a/met/src/tools/other/plot_point_obs/plot_point_obs.cc +++ b/met/src/tools/other/plot_point_obs/plot_point_obs.cc @@ -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]; @@ -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 @@ -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"; @@ -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 DEF_NC_BUFFER_SIZE) ? DEF_NC_BUFFER_SIZE : (nobs_count-i_start); @@ -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], @@ -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 " + << "trouble getting obs_qty\n\n"; + exit(1); + } + } } int typ_idx, sid_idx, vld_idx; @@ -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 @@ -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 diff --git a/met/src/tools/other/plot_point_obs/plot_point_obs.h b/met/src/tools/other/plot_point_obs/plot_point_obs.h index 6fda5f2208..ed9bc5a2e7 100644 --- a/met/src/tools/other/plot_point_obs/plot_point_obs.h +++ b/met/src/tools/other/plot_point_obs/plot_point_obs.h @@ -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;