From ba2601a32fd1d236da21972025e902e89dccc715 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:36:07 -0600 Subject: [PATCH] vector isotope_ratio --- Phreeqc.cpp | 5 +---- Phreeqc.h | 4 +--- basicsubs.cpp | 8 ++++---- isotopes.cpp | 13 ++++--------- mainsubs.cpp | 6 +----- structures.cpp | 5 ++--- tidy.cpp | 2 +- 7 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 766a0ba2..235d0ac9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -980,9 +980,6 @@ void Phreeqc::init(void) * ---------------------------------------------------------------------- */ initial_solution_isotopes = FALSE; calculate_value_hash_table = NULL; - count_isotope_ratio = 0; - isotope_ratio = 0; - max_isotope_ratio = MAX_ELTS; isotope_ratio_hash_table = 0; count_isotope_alpha = 0; isotope_alpha = 0; @@ -2308,7 +2305,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } - for (int i = 0; i < pSrc->count_isotope_ratio; i++) + for (int i = 0; i < (int)pSrc->isotope_ratio.size(); i++) { struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); isotope_ratio_ptr->name = string_hsave(pSrc->isotope_ratio[i]->name); diff --git a/Phreeqc.h b/Phreeqc.h index 03698287..00d2ed9a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1729,9 +1729,7 @@ protected: int initial_solution_isotopes; std::vector calculate_value; HashTable *calculate_value_hash_table; - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; + std::vector isotope_ratio; HashTable *isotope_ratio_hash_table; int count_isotope_alpha; struct isotope_alpha **isotope_alpha; diff --git a/basicsubs.cpp b/basicsubs.cpp index f66ef510..20ed0e80 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -4011,7 +4011,7 @@ iso_value(const char *total_name) strcpy(token, ""); strcpy(my_total_name, total_name); while (replace(" ","_",my_total_name)); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4025,7 +4025,7 @@ iso_value(const char *total_name) strcat(token,"R("); strcat(token,my_total_name); strcat(token,")"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4047,7 +4047,7 @@ iso_unit(const char *total_name) strcpy(my_total_name, total_name); while (replace(" ","_",my_total_name)); strcpy(unit, "unknown"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -4066,7 +4066,7 @@ iso_unit(const char *total_name) strcat(token,"R("); strcat(token,my_total_name); strcat(token,")"); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; diff --git a/isotopes.cpp b/isotopes.cpp index d5585d03..8e0db9b2 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -1011,7 +1011,7 @@ print_isotope_ratios(void) output_msg(sformatf( "%25s\t%12s\t%15s\n\n", "Isotope Ratio", "Ratio", "Input Units")); - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { if (isotope_ratio[j]->ratio == MISSING) continue; @@ -1135,7 +1135,7 @@ calculate_values(void) } if (pr.isotope_ratios == TRUE) { - for (j = 0; j < count_isotope_ratio; j++) + for (j = 0; j < (int)isotope_ratio.size(); j++) { isotope_ratio_ptr = isotope_ratio[j]; master_isotope_ptr = @@ -1699,13 +1699,8 @@ isotope_ratio_store(const char *name, int replace_if_found) } else { - n = count_isotope_ratio++; - /* make sure there is space in s */ - if (count_isotope_ratio >= max_isotope_ratio) - { - space((void **) ((void *) &isotope_ratio), count_isotope_ratio, - &max_isotope_ratio, sizeof(struct isotope_ratio *)); - } + n = (int)isotope_ratio.size(); + isotope_ratio.resize((size_t)n + 1); /* Make new isotope_ratio structure */ isotope_ratio[n] = isotope_ratio_alloc(); isotope_ratio_ptr = isotope_ratio[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index d069c736..6afdfdd8 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -178,11 +178,7 @@ initialize(void) &calculate_value_hash_table); /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, - sizeof(struct isotope_ratio *)); - hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); + hcreate_multi((unsigned) MAX_ELTS, &isotope_ratio_hash_table); /* isotope_value */ max_isotope_alpha = MAX_ELTS; diff --git a/structures.cpp b/structures.cpp index de7c1e50..1ba32193 100644 --- a/structures.cpp +++ b/structures.cpp @@ -243,12 +243,12 @@ clean_up(void) calculate_value_hash_table = NULL; /* isotope_ratio */ - for (i = 0; i < count_isotope_ratio; i++) + for (i = 0; i < (int)isotope_ratio.size(); i++) { isotope_ratio[i] = (struct isotope_ratio *) free_check_null(isotope_ratio[i]); } - isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); + //isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); hdestroy_multi(isotope_ratio_hash_table); isotope_ratio_hash_table = NULL; @@ -328,7 +328,6 @@ clean_up(void) llnl_count_bdot = 0; llnl_count_co2_coefs = 0; - count_isotope_ratio = 0; count_isotope_alpha = 0; default_data_base = (char *) free_check_null(default_data_base); diff --git a/tidy.cpp b/tidy.cpp index be3f71b3..603f8f2c 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -5543,7 +5543,7 @@ tidy_isotope_ratios(void) struct master_isotope *master_isotope_ptr; struct calculate_value *calculate_value_ptr; - for (i = 0; i < count_isotope_ratio; i++) + for (i = 0; i < (int)isotope_ratio.size(); i++) { /* * Mark master species list as minor isotope