Skip to content

Commit

Permalink
Merge pull request #2126 from dtcenter/bugfix_2123_main_v10.1_nccf_va…
Browse files Browse the repository at this point in the history
…lid_time

Bugfix 2123 main v10.1 nccf valid time
  • Loading branch information
hsoh-u authored Apr 6, 2022
2 parents 71f3d42 + aed022d commit 62376a8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
15 changes: 5 additions & 10 deletions met/src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,15 @@ bool NcCfFile::open(const char * filepath)
}

// Parse the units for the time variable.
ut = sec_per_unit = 0;
NcVarAtt *units_att = get_nc_att(valid_time_var, (string)"units", false);
if (IS_VALID_NC_P(units_att))
{
get_att_value_chars(units_att, units);

if (units.length() == 0)
if (!get_att_value_chars(units_att, units) || units.length() == 0)
{
mlog << Warning << "\n" << method_name
<< "the \"time\" variable must contain a \"units\" attribute. "
<< "Using valid time of 0\n\n";
ut = sec_per_unit = 0;
}
else
{
Expand All @@ -315,14 +313,10 @@ bool NcCfFile::open(const char * filepath)
parse_cf_time_string(units.c_str(), ut, sec_per_unit);
}
}
else
{
ut = sec_per_unit = 0;
}
if (units_att) delete units_att;

NcVar bounds_time_var;
NcVar *nc_time_var = (NcVar *)0;
nc_time_var = valid_time_var;
bool use_bounds_var = false;
ConcatString bounds_var_name;
nc_time_var = valid_time_var;
Expand All @@ -338,12 +332,12 @@ bool NcCfFile::open(const char * filepath)
}
if (bounds_att) delete bounds_att;

if (units_att) delete units_att;
// Determine the number of times present.
int n_times = (int) get_data_size(valid_time_var);
int tim_buf_size = n_times;
if (use_bounds_var) tim_buf_size *= 2;
double *time_values = new double[tim_buf_size];

if( get_nc_data(nc_time_var, time_values) ) {
bool no_leap_year = get_att_no_leap_year(valid_time_var);
if( time_dim_count > 1 ) {
Expand Down Expand Up @@ -375,6 +369,7 @@ bool NcCfFile::open(const char * filepath)
}
}
}
else ValidTime.add(0); //Initialize
delete [] time_values;
}

Expand Down
57 changes: 47 additions & 10 deletions met/src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,7 @@ bool get_nc_data(NcVar *var, float *data) {
// Note: missing data was checked here
//
int type_id = GET_NC_TYPE_ID_P(var);
return_status = true;
if (NcType::nc_FLOAT == type_id) {
var->getVar(data);
}
Expand Down Expand Up @@ -1565,9 +1566,26 @@ bool get_nc_data(NcVar *var, float *data) {
if (IS_VALID_NC_P(att_scale_factor)) scale_factor = get_att_value_float(att_scale_factor);
mlog << Debug(4) << method_name << "add_offset = " << add_offset
<< ", scale_factor=" << scale_factor << ", cell_count=" << cell_count
<< ", is_unsigned_value: " << unsigned_value << "\n";
<< ", is_unsigned_value: " << unsigned_value << " for " << GET_NC_NAME_P(var) << "\n";

switch ( type_id ) {
case NcType::nc_INT64:
{
long long fill_value = bad_data_int;
long long min_value = 2147483647;
long long max_value = -2147483648;
long long *packed_data = new long long[cell_count];

if (IS_VALID_NC_P(att_fill_value))
fill_value = get_att_value_int(att_fill_value);

var->getVar(packed_data);
_apply_scale_factor(data, packed_data, cell_count,
fill_value, min_value, max_value, "int64",
add_offset, scale_factor);
delete [] packed_data;
}
break;
case NcType::nc_INT:
{
int fill_value = bad_data_int;
Expand Down Expand Up @@ -1720,15 +1738,15 @@ bool get_nc_data(NcVar *var, float *data) {
}
break;
default:
mlog << Debug(1) << method_name << "type_id: "
<< type_id << " type name: " << GET_NC_TYPE_NAME_P(var)
<< "\n";
return_status = false;
mlog << Debug(1) << method_name << "Did not read data because of unsupported data type ("
<< type_id << ", type name: " << GET_NC_TYPE_NAME_P(var)
<< ") for " << GET_NC_NAME_P(var) << "\n";
}
if(att_add_offset) delete att_add_offset;
if(att_scale_factor) delete att_scale_factor;
if(att_fill_value) delete att_fill_value;
}
return_status = true;
}

mlog << Debug(6) << method_name << "took "
Expand Down Expand Up @@ -1821,6 +1839,7 @@ bool get_nc_data(NcVar *var, double *data) {
//
int unpacked_count = 0;
int type_id = GET_NC_TYPE_ID_P(var);
return_status = true;
if ((NcType::nc_DOUBLE == type_id) || (NcType::nc_FLOAT == type_id)){
var->getVar(data);
}
Expand All @@ -1844,9 +1863,26 @@ bool get_nc_data(NcVar *var, double *data) {
}
mlog << Debug(4) << method_name << "add_offset = " << add_offset
<< ", scale_factor=" << scale_factor << ", cell_count=" << cell_count
<< ", is_unsigned_value: " << unsigned_value << "\n";
<< ", is_unsigned_value: " << unsigned_value << " for " << GET_NC_NAME_P(var) << "\n";

switch ( type_id ) {
case NcType::nc_INT64:
{
long long fill_value = bad_data_int;
long long min_value = 2147483647;
long long max_value = -2147483648;
long long *packed_data = new long long[cell_count];

if (IS_VALID_NC_P(att_fill_value))
fill_value = get_att_value_int(att_fill_value);

var->getVar(packed_data);
_apply_scale_factor(data, packed_data, cell_count,
fill_value, min_value, max_value, "int64",
add_offset, scale_factor);
delete [] packed_data;
}
break;
case NcType::nc_INT:
{
int fill_value = bad_data_int;
Expand Down Expand Up @@ -2001,15 +2037,16 @@ bool get_nc_data(NcVar *var, double *data) {
}
break;
default:
mlog << Debug(1) << method_name << "type_id: "
<< type_id << " type name: " << GET_NC_TYPE_NAME_P(var)
<< "\n";
return_status = false;
mlog << Debug(1) << method_name << "Did not read data because of unsupported data type ("
<< type_id << ", type name: " << GET_NC_TYPE_NAME_P(var)
<< ") for " << GET_NC_NAME_P(var) << "\n";

}
if(att_add_offset) delete att_add_offset;
if(att_scale_factor) delete att_scale_factor;
if(att_fill_value) delete att_fill_value;
}
return_status = true;
}
return(return_status);
}
Expand Down

0 comments on commit 62376a8

Please sign in to comment.