Skip to content

Commit

Permalink
Per #2187, update met_file.cc, pinterp_file.cc, and nccf_file.cc to m…
Browse files Browse the repository at this point in the history
…ake calls to the new utility functions.
  • Loading branch information
JohnHalleyGotway committed Jun 15, 2022
1 parent aaead48 commit 3a1a1ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 72 deletions.
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

0 comments on commit 3a1a1ae

Please sign in to comment.