Skip to content

Commit

Permalink
#2763 Handle a variable without dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Oct 8, 2024
1 parent b22381e commit 5f8709f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,13 @@ bool get_nc_data_ptr(NcVar *var, float *data) {
// Note: missing data was checked here
//
int type_id = GET_NC_TYPE_ID_P(var);
// Handle the variable without dimension, for example, "float t ;"
int cell_count = (0 == get_dim_count(var)) ? 1 : get_data_size(var);
int cell_count = get_data_size(var);
if (cell_count <= 0) {
mlog << Warning << "\n\n" << method_name
<< " Adjusted the data size to 1 (was " << cell_count << ") of the variable \""
<< GET_NC_NAME_P(var) << "\"\n\n";
cell_count = 1;
}

return_status = true;
if (NcType::nc_FLOAT == type_id) {
Expand Down Expand Up @@ -1570,8 +1575,13 @@ bool get_nc_data_ptr(NcVar *var, double *data) {
//
int unpacked_count = 0;
int type_id = GET_NC_TYPE_ID_P(var);
// Handle the variable without dimension, for example, "double t ;"
const int cell_count = (0 == get_dim_count(var)) ? 1 : get_data_size(var);
int cell_count = get_data_size(var);
if (cell_count <= 0) {
mlog << Warning << "\n\n" << method_name
<< " Adjusted the data size to 1 (was " << cell_count << ") of the variable \""
<< GET_NC_NAME_P(var) << "\"\n\n";
cell_count = 1;
}

return_status = true;
if (NcType::nc_DOUBLE == type_id) {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/other/point2grid/point2grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,8 @@ static unixtime find_valid_time(NcVar time_var) {

if( IS_VALID_NC(time_var) || get_dim_count(&time_var) < 2) {
// Handle the variable without dimension
int time_count = (0 == get_dim_count(&time_var)) ? 1 : get_dim_size(&time_var, 0);
int time_count = get_dim_size(&time_var, 0);
if (time_count == 0) time_count = get_data_size(&time_var);

vector<double> time_values(time_count+1);
if (get_nc_data(&time_var, time_values)) {
Expand Down

0 comments on commit 5f8709f

Please sign in to comment.