Skip to content

Commit

Permalink
Per #1866, switch all the vectors of type integer (<int>) to vectors …
Browse files Browse the repository at this point in the history
…of type long long (<long long>) to avoid integer overflow in the grid_diag tool. Also, update grid_diag to write int64 NetCDF variables instead of int.
  • Loading branch information
JohnHalleyGotway committed Aug 20, 2021
1 parent 6d7b55c commit eeb440a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
double delta = (max - min) / nbin;
double width = 10;

vector<int> pdf;
vector<long long> pdf;

init_pdf(nbin, pdf);

Expand Down
14 changes: 7 additions & 7 deletions met/src/libcode/vx_series_data/series_pdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

void init_pdf(
int n,
vector<int>& pdf) {
vector<long long>& pdf) {

for(int k = 0; k < n; k++) {
pdf.push_back(0);
Expand All @@ -35,7 +35,7 @@ void init_pdf(
double min,
double max,
double delta,
vector<int>& pdf) {
vector<long long>& pdf) {

int n = (max - min) / delta;
for(int k = 0; k < n; k++) {
Expand All @@ -48,7 +48,7 @@ void init_pdf(
void init_joint_pdf(
int n_A,
int n_B,
vector<int>& pdf) {
vector<long long>& pdf) {

for(int k = 0; k < n_A * n_B; k++) {
pdf.push_back(0);
Expand All @@ -60,7 +60,7 @@ void init_joint_pdf(
void update_pdf(
double min,
double delta,
vector<int>& pdf,
vector<long long>& pdf,
const DataPlane& dp,
const MaskPlane& mp) {

Expand All @@ -86,7 +86,7 @@ void update_joint_pdf(
double min_B,
double delta_A,
double delta_B,
vector<int>& pdf,
vector<long long>& pdf,
const DataPlane& dp_A,
const DataPlane& dp_B,
const MaskPlane& mp) {
Expand Down Expand Up @@ -115,7 +115,7 @@ void update_joint_pdf(
void print_pdf(
double min,
double delta,
const vector<int>& pdf) {
const vector<long long>& pdf) {

for(int k = 0; k < pdf.size(); k++) {
double bin_min = min + k * delta;
Expand All @@ -132,7 +132,7 @@ void write_nc_pdf(
const VarInfo& info,
double min,
double delta,
const vector<int>& pdf) {
const vector<long long>& pdf) {

vector<double> bin_min;
vector<double> bin_max;
Expand Down
14 changes: 7 additions & 7 deletions met/src/libcode/vx_series_data/series_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ using namespace netCDF;

void init_pdf(
int n,
vector<int>& pdf);
vector<long long>& pdf);

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

void init_pdf(
double min,
double max,
double delta,
vector<int>& pdf);
vector<long long>& pdf);

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

void init_joint_pdf(
int n_A,
int n_B,
vector<int>& pdf);
vector<long long>& pdf);

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

void update_pdf(
double min,
double delta,
vector<int>& pdf,
vector<long long>& pdf,
const DataPlane&,
const MaskPlane&);

Expand All @@ -65,7 +65,7 @@ void update_joint_pdf(
double min_B,
double delta_A,
double delta_B,
vector<int>& pdf,
vector<long long>& pdf,
const DataPlane&,
const DataPlane&,
const MaskPlane&);
Expand All @@ -75,7 +75,7 @@ void update_joint_pdf(
void print_pdf(
double min,
double delta,
const vector<int>& pdf);
const vector<long long>& pdf);

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

Expand All @@ -84,7 +84,7 @@ void write_nc_pdf(
const VarInfo& info,
double min,
double delta,
const vector<int>& pdf);
const vector<long long>& pdf);

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

Expand Down
14 changes: 7 additions & 7 deletions met/src/tools/other/grid_diag/grid_diag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void setup_histograms(void) {
<< "Initializing " << data_info->magic_str_attr()
<< " histogram with " << n_bins << " bins from "
<< min << " to " << max << ".\n";
histograms[i_var_str] = vector<int>();
histograms[i_var_str] = vector<long long>();
init_pdf(n_bins, histograms[i_var_str]);
} // for i_var
}
Expand Down Expand Up @@ -456,7 +456,7 @@ void setup_joint_histograms(void) {
<< "Initializing " << data_info->magic_str_attr() << "_"
<< joint_info->magic_str_attr() << " joint histogram with "
<< n_bins << " x " << n_joint_bins << " bins.\n";
joint_histograms[ij_var_str] = vector<int>();
joint_histograms[ij_var_str] = vector<long long>();

init_joint_pdf(n_bins, n_joint_bins,
joint_histograms[ij_var_str]);
Expand Down Expand Up @@ -568,7 +568,7 @@ void setup_nc_file(void) {
ConcatString hist_name("hist_");
hist_name.add(var_name);
NcDim var_dim = data_var_dims[i_var];
NcVar hist_var = add_var(nc_out, hist_name, ncInt, var_dim,
NcVar hist_var = add_var(nc_out, hist_name, ncInt64, var_dim,
deflate_level);
hist_vars.push_back(hist_var);

Expand Down Expand Up @@ -602,7 +602,7 @@ void setup_nc_file(void) {
dims.push_back(var_dim);
dims.push_back(joint_dim);

NcVar hist_var = add_var(nc_out, hist_name, ncInt, dims,
NcVar hist_var = add_var(nc_out, hist_name, ncInt64, dims,
deflate_level);
joint_hist_vars.push_back(hist_var);

Expand All @@ -620,7 +620,7 @@ void write_nc_var_int(const char *var_name, const char *long_name,
int n) {

// Add the variable
NcVar var = add_var(nc_out, var_name, ncInt);
NcVar var = add_var(nc_out, var_name, ncInt64);
add_att(&var, "long_name", long_name);

if(!put_nc_data(&var, &n)) {
Expand Down Expand Up @@ -650,7 +650,7 @@ void write_histograms(void) {
VarInfo *data_info = conf_info.data_info[i_var];
NcVar hist_var = hist_vars[i_var];

int *hist = histograms[i_var_str].data();
long long *hist = histograms[i_var_str].data();

hist_var.putVar(hist);
}
Expand All @@ -676,7 +676,7 @@ void write_joint_histograms(void) {
<< "VAR" << i_var << "_"
<< "VAR" << j_var;

int *hist = joint_histograms[ij_var_str].data();
long long *hist = joint_histograms[ij_var_str].data();

offsets.clear();
counts.clear();
Expand Down
4 changes: 2 additions & 2 deletions met/src/tools/other/grid_diag/grid_diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ vector<double> var_mins;
vector<double> var_maxs;

// Variable histogram map
map<ConcatString, vector<int> > histograms;
map<ConcatString, vector<int> > joint_histograms;
map<ConcatString, vector<long long> > histograms;
map<ConcatString, vector<long long> > joint_histograms;
map<ConcatString, vector<double> > bin_mins;
map<ConcatString, vector<double> > bin_maxs;
map<ConcatString, vector<double> > bin_mids;
Expand Down

0 comments on commit eeb440a

Please sign in to comment.