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 #2187 develop ao_sf #2188

Closed
wants to merge 2 commits into from
Closed
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
42 changes: 13 additions & 29 deletions src/libcode/vx_data2d_nc_met/met_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ using namespace std;
////////////////////////////////////////////////////////////////////////


static const char x_dim_name [] = "lon";
static const char y_dim_name [] = "lat";
static const char x_dim_name [] = "lon";
static const char y_dim_name [] = "lat";

static const string valid_time_att_name = "valid_time";
static const string init_time_att_name = "init_time";
static const string valid_time_ut_att_name = "valid_time_ut";
static const string init_time_ut_att_name = "init_time_ut";
static const string accum_time_att_name = "accum_time_sec";
static const string valid_time_att_name = "valid_time";
static const string init_time_att_name = "init_time";
static const string valid_time_ut_att_name = "valid_time_ut";
static const string init_time_ut_att_name = "init_time_ut";
static const string accum_time_att_name = "accum_time_sec";

static const int max_met_args = 30;
static const int max_met_args = 30;

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -446,18 +446,10 @@ short s;
float f;
double d = bad_data_double;
bool status;
float add_offset = 0.f;
float scale_factor = 1.f;
double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
NcVarAtt *att_add_offset = get_nc_att(var, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(var, (string)"scale_factor");
if (!IS_INVALID_NC_P(att_add_offset) && !IS_INVALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;
float add_offset = get_var_add_offset_value(var);
float scale_factor = get_var_scale_factor_value(var);

status = false;
switch ( GET_NC_TYPE_ID_P(var) ) {
Expand Down Expand Up @@ -641,11 +633,13 @@ const int x_slot = x_slot_tmp;
const int y_slot = y_slot_tmp;

//
// get the bad data value
// get the attributes
//

double missing_value = get_var_missing_value(v);
double fill_value = get_var_fill_value(v);
float add_offset = get_var_add_offset_value(v);
float scale_factor = get_var_scale_factor_value(v);

//
// set up the DataPlane object
Expand All @@ -659,16 +653,6 @@ plane.set_size(Nx, Ny);
//
clock_t clock_time;
double nc_time;
float add_offset = 0.f;
float scale_factor = 1.f;
NcVarAtt *att_add_offset = get_nc_att(v, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(v, (string)"scale_factor");
if (!IS_INVALID_NC_P(att_add_offset) && !IS_INVALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;

int type_id = GET_NC_TYPE_ID_P(v);
long dim[dimCount], cur[dimCount];
Expand Down
24 changes: 4 additions & 20 deletions src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,18 +567,10 @@ int i;
short s;
float f;
double d = bad_data_double;
float add_offset = 0.f;
float scale_factor = 1.f;
double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
NcVarAtt *att_add_offset = get_nc_att(var, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(var, (string)"scale_factor");
if (!IS_INVALID_NC_P(att_add_offset) && !IS_INVALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;
float add_offset = get_var_add_offset_value(var);
float scale_factor = get_var_scale_factor_value(var);

switch ( GET_NC_TYPE_ID_P(var) ) {

Expand Down Expand Up @@ -790,16 +782,8 @@ float f[Ny];

long offsets[dim_count];
long lengths[dim_count];
float add_offset = 0.f;
float scale_factor = 1.f;
NcVarAtt *att_add_offset = get_nc_att(v, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(v, (string)"scale_factor");
if (!IS_INVALID_NC_P(att_add_offset) && !IS_INVALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;
float add_offset = get_var_add_offset_value(var->var);
float scale_factor = get_var_scale_factor_value(var->var);

for (int k=0; k<dim_count; k++) {
offsets[k] = (a[k] == vx_data2d_star) ? 0 : a[k];
Expand Down
28 changes: 5 additions & 23 deletions src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,19 +848,10 @@ double NcCfFile::getData(NcVar * var, const LongArray & a) const

bool status = false;
double d = bad_data_double;
float add_offset = 0.f;
float scale_factor = 1.f;
NcVarAtt *att_add_offset = get_nc_att(var, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(var, (string)"scale_factor");
if (IS_VALID_NC_P(att_add_offset) && IS_VALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;

double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
float add_offset = get_var_add_offset_value(var);
float scale_factor = get_var_scale_factor_value(var);

switch (GET_NC_TYPE_ID_P(var))
{
Expand Down Expand Up @@ -1025,11 +1016,13 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
const int y_slot = y_slot_tmp;

//
// get the bad data values
// get the attributes
//

double missing_value = get_var_missing_value(v);
double fill_value = get_var_fill_value(v);
float add_offset = get_var_add_offset_value(v);
float scale_factor = get_var_scale_factor_value(v);

// set up the DataPlane object

Expand Down Expand Up @@ -1073,17 +1066,6 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
offsets[y_slot] = 0;
lengths[y_slot] = ny;

float add_offset = 0.f;
float scale_factor = 1.f;
NcVarAtt *att_add_offset = get_nc_att(v, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(v, (string)"scale_factor");
if (IS_VALID_NC_P(att_add_offset) && IS_VALID_NC_P(att_scale_factor)) {
add_offset = get_att_value_float(att_add_offset);
scale_factor = get_att_value_float(att_scale_factor);
}
if (att_add_offset) delete att_add_offset;
if (att_scale_factor) delete att_scale_factor;

int type_id = GET_NC_TYPE_ID_P(v);
bool do_scale_factor = add_offset != 0.0 || scale_factor != 1.0;

Expand Down
50 changes: 29 additions & 21 deletions src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,30 @@ double get_var_fill_value(const NcVar *var) {

////////////////////////////////////////////////////////////////////////

float get_var_add_offset_value(const NcVar *var) {
float v;

if(!get_var_att_float(var, add_offset_att_name, v)) {
v = 0.f;
}

return(v);
}

////////////////////////////////////////////////////////////////////////

float get_var_scale_factor_value(const NcVar *var) {
float v;

if(!get_var_att_float(var, scale_factor_att_name, v)) {
v = 1.f;
}

return(v);
}

////////////////////////////////////////////////////////////////////////

char get_char_val(NcFile * nc, const char * var_name, const int index) {
NcVar var = get_var(nc, var_name);
return (get_char_val(&var, index));
Expand Down Expand Up @@ -1553,15 +1577,11 @@ bool get_nc_data(NcVar *var, float *data) {
cell_count *= get_dim_size(var, idx);
}

float add_offset = 0.;
float scale_factor = 1.;
float add_offset = get_var_add_offset_value(var);
float scale_factor = get_var_scale_factor_value(var);
int unpacked_count = 0;
bool unsigned_value = has_unsigned_attribute(var);
NcVarAtt *att_add_offset = get_nc_att(var, string("add_offset"));
NcVarAtt *att_scale_factor = get_nc_att(var, string("scale_factor"));
NcVarAtt *att_fill_value = get_nc_att(var, string("_FillValue"));
if (IS_VALID_NC_P(att_add_offset)) add_offset = get_att_value_float(att_add_offset);
if (IS_VALID_NC_P(att_scale_factor)) scale_factor = get_att_value_float(att_scale_factor);
NcVarAtt *att_fill_value = get_nc_att(var, string("_FillValue"));
mlog << Debug(4) << method_name << "add_offset = " << add_offset
<< ", scale_factor=" << scale_factor << ", cell_count=" << cell_count
<< ", is_unsigned_value: " << unsigned_value << " for " << GET_NC_NAME_P(var) << "\n";
Expand Down Expand Up @@ -1741,8 +1761,6 @@ bool get_nc_data(NcVar *var, float *data) {
<< 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;
}
}
Expand Down Expand Up @@ -1847,18 +1865,10 @@ bool get_nc_data(NcVar *var, double *data) {
cell_count *= get_dim_size(var, idx);
}

double add_offset = 0.;
double scale_factor = 1.;
double add_offset = get_var_add_offset_value(var);
double scale_factor = get_var_scale_factor_value(var);
bool unsigned_value = has_unsigned_attribute(var);
NcVarAtt *att_add_offset = get_nc_att(var, (string)"add_offset");
NcVarAtt *att_scale_factor = get_nc_att(var, (string)"scale_factor");
NcVarAtt *att_fill_value = get_nc_att(var, (string)"_FillValue");
if (IS_VALID_NC_P(att_add_offset)) {
add_offset = get_att_value_double(att_add_offset);
}
if (IS_VALID_NC_P(att_scale_factor)) {
scale_factor = get_att_value_double(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 << " for " << GET_NC_NAME_P(var) << "\n";
Expand Down Expand Up @@ -2041,8 +2051,6 @@ bool get_nc_data(NcVar *var, double *data) {
<< ") 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;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/libcode/vx_nc_util/nc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static const char nc_att_met_point_nccf[] = "MET_point_NCCF";

static const string description_att_name = "description";
static const string fill_value_att_name = "_FillValue";
static const string add_offset_att_name = "add_offset";
static const string scale_factor_att_name = "scale_factor";
static const string level_att_name = "level";
static const string long_name_att_name = "long_name";
static const string missing_value_att_name = "missing_value";
Expand Down Expand Up @@ -218,6 +220,9 @@ extern bool get_var_level(const NcVar *, ConcatString &);
extern double get_var_missing_value(const NcVar *);
extern double get_var_fill_value(const NcVar *);

extern float get_var_add_offset_value(const NcVar *);
extern float get_var_scale_factor_value(const NcVar *);

extern bool args_ok(const LongArray &);

extern char get_char_val(NcFile *, const char * var_name, const int index);
Expand Down