Skip to content

Commit

Permalink
#2123 Initialize ValidTime if failed to read time variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Apr 5, 2022
1 parent 71f3d42 commit d62ab38
Showing 1 changed file with 5 additions and 10 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

0 comments on commit d62ab38

Please sign in to comment.