Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix 2123 develop nccf valid time #2127

Merged
merged 7 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions test/xml/unit_plot_data_plane.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@
</output>
</test>

<test name="plot_data_plane_NCCF_time_int64">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&DATA_DIR_MODEL;/nccf/precipitation_int64_time.nc \
&OUTPUT_DIR;/plot_data_plane/plot_data_plane_NCCF_int64_time.ps \
'name="precipitation"; level="(*,*)";' \
-title "Observation precipitation" \
-v 1
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/plot_data_plane_NCCF_int64_time.ps</ps>
</output>
</test>

<test name="plot_data_plane_NCCF_rotlatlon">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
Expand Down