From e91357027367ed8943f54acf0a1e00c1ef26fde2 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Mon, 20 Feb 2023 10:52:14 -0700 Subject: [PATCH] Per #2402, rollback changes to set.h/.cc which continue to cause runtime errors in MODE. --- src/libcode/vx_shapedata/set.cc | 96 ++++++++++++++++++++++----------- src/libcode/vx_shapedata/set.h | 16 +++--- 2 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/libcode/vx_shapedata/set.cc b/src/libcode/vx_shapedata/set.cc index ec1c6fbabb..882aa29bd0 100644 --- a/src/libcode/vx_shapedata/set.cc +++ b/src/libcode/vx_shapedata/set.cc @@ -94,7 +94,9 @@ void FcstObsSet::init_from_scratch() { -n_fcst = n_obs = 0; +fcst_number = 0; + + obs_number = 0; all_clear(); @@ -113,13 +115,18 @@ void FcstObsSet::clear() { +// if ( fcst_number ) { delete [] fcst_number; fcst_number = 0; } +// if ( obs_number ) { delete [] obs_number; obs_number = 0; } + int j; -for (j=0; j 0 ) { +if ( s.n_fcst_alloc > 0 ) { extend_fcst (s.n_fcst_alloc); - fcst_number = s.fcst_number; + memcpy(fcst_number, s.fcst_number, (s.n_fcst_alloc)*sizeof(int)); } -if ( s.n_obs > 0 ) { +if ( s.n_obs_alloc > 0 ) { extend_obs (s.n_obs_alloc); - obs_number = s.obs_number; + memcpy(obs_number, s.obs_number, (s.n_obs_alloc)*sizeof(int)); } @@ -213,19 +220,30 @@ return; /////////////////////////////////////////////////////////////////////////////// -void FcstObsSet::extend(std::vector & a, int & n_alloc, const int N) +void FcstObsSet::extend(int * & a, int & n_alloc, const int N) { if ( N <= n_alloc ) return; -int k = N/fcst_obs_set_alloc_inc; +int j, k; +int * u = 0; + +k = N/fcst_obs_set_alloc_inc; if ( N%fcst_obs_set_alloc_inc ) ++k; k *= fcst_obs_set_alloc_inc; -a.reserve(k); +u = new int [k]; + +if ( a ) memcpy(u, a, n_alloc*sizeof(int)); + +for (j=n_alloc; j - - -/////////////////////////////////////////////////////////////////////////////// - - static const int fcst_obs_set_alloc_inc = 50; @@ -46,7 +40,7 @@ class FcstObsSet { void assign(const FcstObsSet &); - void extend(std::vector &, int & n_alloc, const int n_new); + void extend(int * &, int & n_alloc, const int n_new); public: @@ -54,8 +48,8 @@ class FcstObsSet { // data // - std::vector fcst_number; - std::vector obs_number; + int * fcst_number; // allocated + int * obs_number; // allocated int n_fcst; int n_obs; @@ -102,6 +96,8 @@ extern std::ostream & operator<<(std::ostream &, const FcstObsSet &); /////////////////////////////////////////////////////////////////////////////// +// static const int max_fcst_obs_sets = 300; + static const int set_alloc_inc = 50; @@ -122,7 +118,7 @@ class SetCollection { // data // - std::vector set; + FcstObsSet * set; // allocated int n_sets;