diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 90aa8c59..0d7863b4 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1092,7 +1092,6 @@ void Phreeqc::init(void) OPRESS = -100.; A0 = 0; aphi = NULL; - spec = NULL; cations = NULL; anions = NULL; neutrals = NULL; @@ -1137,9 +1136,6 @@ void Phreeqc::init(void) sit_MAXCATIONS = 0; sit_FIRSTANION = 0; sit_MAXNEUTRAL = 0; - sit_IPRSNT = NULL; - sit_M = NULL; - sit_LGAMMA = NULL; /* tidy.cpp ------------------------------- */ a0 = 0; a1 = 0; diff --git a/Phreeqc.h b/Phreeqc.h index f96ad816..177d64e4 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1802,7 +1802,8 @@ protected: LDBLE OTEMP, OPRESS; LDBLE A0; struct pitz_param* aphi; - struct species **spec, **cations, **anions, **neutrals; + std::vector spec; + struct species ** cations, ** anions, ** neutrals; // pointers to spec int count_cations, count_anions, count_neutrals; int MAXCATIONS, FIRSTANION, MAXNEUTRAL; struct pitz_param *mcb0, *mcb1, *mcc0; @@ -1836,8 +1837,8 @@ protected: LDBLE sit_A0; int sit_count_cations, sit_count_anions, sit_count_neutrals; int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; - int *sit_IPRSNT; - LDBLE *sit_M, *sit_LGAMMA; + std::vector sit_IPRSNT; + std::vector sit_M, sit_LGAMMA; std::vector s_list, cation_list, neutral_list, anion_list, ion_list, param_list; /* tidy.cpp ------------------------------- */ diff --git a/pitzer.cpp b/pitzer.cpp index 6e1a1a33..4da1eafd 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -56,15 +56,9 @@ pitzer_tidy(void) /* * allocate pointers to species structures */ - if (spec != NULL) - spec = (struct species **) free_check_null(spec); - spec = (struct species **) - PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *))); - if (spec == NULL) - malloc_error(); - for (i = 0; i < 3 * (int)s.size(); i++) - spec[i] = NULL; - cations = spec; + spec.clear(); + spec.resize(3 * s.size(), NULL); + cations = &spec[0]; neutrals = &(spec[s.size()]); anions = &(spec[2 * s.size()]); MAXCATIONS = (int)s.size(); @@ -1649,7 +1643,7 @@ pitzer_clean_up(void) theta_params.clear(); LGAMMA.clear(); IPRSNT.clear(); - spec = (struct species **) free_check_null(spec); + spec.clear(); aphi = (struct pitz_param *) free_check_null(aphi); M.clear(); diff --git a/prep.cpp b/prep.cpp index 0bfb091e..eda023b0 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5814,9 +5814,8 @@ save_model(void) } /* charge */ last_model.count_surface_charge = (int) use.Get_surface_ptr()->Get_surface_charges().size(); - last_model.surface_charge = - (const char **) PHRQ_malloc( use.Get_surface_ptr()->Get_surface_charges().size() * - sizeof(char *)); + last_model.surface_charge =(const char **) PHRQ_malloc( use.Get_surface_ptr()->Get_surface_charges().size() * + sizeof(char *)); if (last_model.surface_charge == NULL) malloc_error(); for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) diff --git a/sit.cpp b/sit.cpp index a92a8313..74455f0e 100644 --- a/sit.cpp +++ b/sit.cpp @@ -35,12 +35,10 @@ sit_tidy(void) /* * allocate pointers to species structures */ - if (spec != NULL) spec = (struct species **) free_check_null(spec); - spec = (struct species **) PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *))); - if (spec == NULL) malloc_error(); - for (i = 0; i < 3 * (int)s.size(); i++) spec[i] = NULL; + spec.clear(); + spec.resize(3 * s.size(), NULL); - cations = spec; + cations = &spec[0]; neutrals = &(spec[s.size()]); anions = &(spec[2 * s.size()]); sit_MAXCATIONS = (int)s.size(); @@ -53,16 +51,9 @@ sit_tidy(void) /* * allocate other arrays for SIT */ - if (sit_IPRSNT != NULL) sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); - sit_IPRSNT = (int *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(int))); - if (sit_IPRSNT == NULL) malloc_error(); - if (sit_M != NULL) sit_M = (LDBLE *) free_check_null(sit_M); - sit_M = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); - if (sit_M == NULL) malloc_error(); - if (sit_LGAMMA != NULL) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); - sit_LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE))); - if (sit_LGAMMA == NULL) malloc_error(); - + sit_IPRSNT.resize(3 * s.size()); + sit_M.resize(3 * s.size()); + sit_LGAMMA.resize(3 * s.size()); for (i = 0; i < (int)s.size(); i++) { @@ -509,11 +500,11 @@ sit_clean_up(void) } sit_params.clear(); sit_param_map.clear(); - sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); - sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); - spec = (struct species **) free_check_null(spec); + sit_LGAMMA.clear(); + sit_IPRSNT.clear(); + spec.clear(); aphi = (struct pitz_param *) free_check_null(aphi); - sit_M = (LDBLE *) free_check_null(sit_M); + sit_M.clear(); return OK; } @@ -805,7 +796,7 @@ int Phreeqc:: jacobian_sit(void) /* ---------------------------------------------------------------------- */ { - LDBLE *base; + std::vector base; LDBLE d, d1, d2; int i, j; Restart: @@ -817,16 +808,7 @@ Restart: sit(); residuals(); } - base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); - if (base == NULL) - { - malloc_error(); - return OK; - } - for (i = 0; i < count_unknowns; i++) - { - base[i] = residual[i]; - } + base = residual; // std::vectors d = 0.0001; d1 = d * LOG_10; d2 = 0; @@ -900,7 +882,6 @@ Restart: molalities(TRUE); if (max_unknowns > pz_max_unknowns) { - base = (LDBLE *) free_check_null(base); gammas_sit(); jacobian_sums(); goto Restart; @@ -960,7 +941,6 @@ Restart: sit(); mb_sums(); residuals(); - free_check_null(base); return OK; }