mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
Merge commit '4ca2e4e1f403f232428f1010ddaa422088b2f474'
This commit is contained in:
commit
f911f658ce
@ -660,10 +660,8 @@ void Phreeqc::init(void)
|
||||
count_ad_shifts = 1;
|
||||
print_ad_modulus = 1;
|
||||
punch_ad_modulus = 1;
|
||||
advection_punch = NULL;
|
||||
advection_kin_time = 0.0;
|
||||
advection_kin_time_defined = FALSE;
|
||||
advection_print = NULL;
|
||||
advection_warnings = TRUE;
|
||||
/*----------------------------------------------------------------------
|
||||
* Tidy data
|
||||
@ -906,27 +904,10 @@ void Phreeqc::init(void)
|
||||
remove_unstable_phases = FALSE;
|
||||
// auto screen_string;
|
||||
spread_length = 10;
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Hash definitions
|
||||
*/
|
||||
// auto strings_map;
|
||||
#ifdef HASH
|
||||
// auto strings_hash;
|
||||
#endif
|
||||
elements_hash_table = NULL;
|
||||
species_hash_table = NULL;
|
||||
phases_hash_table = NULL;
|
||||
logk_hash_table = NULL;
|
||||
master_isotope_hash_table = NULL;
|
||||
/* ----------------------------------------------------------------------
|
||||
* ISOTOPES
|
||||
* ---------------------------------------------------------------------- */
|
||||
initial_solution_isotopes = FALSE;
|
||||
calculate_value_hash_table = NULL;
|
||||
isotope_ratio_hash_table = 0;
|
||||
isotope_alpha_hash_table = 0;
|
||||
|
||||
|
||||
phreeqc_mpi_myself = 0;
|
||||
first_read_input = TRUE;
|
||||
@ -1517,22 +1498,10 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
count_ad_shifts = pSrc->count_ad_shifts;
|
||||
print_ad_modulus = pSrc->print_ad_modulus;
|
||||
punch_ad_modulus = pSrc->punch_ad_modulus;
|
||||
/* advection_punch */
|
||||
if (count_ad_cells > 0)
|
||||
{
|
||||
advection_punch = (int *) free_check_null(advection_punch);
|
||||
advection_punch = (int *) PHRQ_malloc((size_t) (count_ad_cells * sizeof(int)));
|
||||
if (advection_punch == NULL) malloc_error();
|
||||
memcpy(advection_punch, pSrc->advection_punch, (size_t) (count_ad_cells * sizeof(int)));
|
||||
}
|
||||
/* advection_print */
|
||||
if (count_ad_cells > 0)
|
||||
{
|
||||
advection_print = (int *) free_check_null(advection_print);
|
||||
advection_print = (int *) PHRQ_malloc((size_t) (count_ad_cells * sizeof(int)));
|
||||
if (advection_print == NULL) malloc_error();
|
||||
memcpy(advection_print, pSrc->advection_print, (size_t) (count_ad_cells * sizeof(int)));
|
||||
}
|
||||
/* advection_punch, advection_print */
|
||||
advection_punch = pSrc->advection_punch;
|
||||
advection_print = pSrc->advection_print;
|
||||
|
||||
advection_kin_time = pSrc->advection_kin_time;
|
||||
advection_kin_time_defined = pSrc->advection_kin_time_defined;
|
||||
advection_warnings = pSrc->advection_warnings;
|
||||
@ -1607,23 +1576,14 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
|
||||
for (int i = 0; i < (int)pSrc->logk.size(); i++)
|
||||
{
|
||||
char * name = string_duplicate(pSrc->logk[i]->name);
|
||||
struct logk *logk_ptr = logk_store(name, FALSE);
|
||||
free_check_null(name);
|
||||
struct logk *logk_ptr = logk_store(pSrc->logk[i]->name, FALSE);
|
||||
memcpy(logk_ptr, pSrc->logk[i], sizeof(struct logk));
|
||||
logk_ptr->name = string_hsave(pSrc->logk[i]->name);
|
||||
logk_ptr->add_logk = NULL;
|
||||
if (logk_ptr->count_add_logk > 0)
|
||||
logk_ptr->add_logk.resize(pSrc->logk[i]->add_logk.size());
|
||||
for (size_t j = 0; j < logk_ptr->add_logk.size(); j++)
|
||||
{
|
||||
logk_ptr->add_logk = (struct name_coef *) free_check_null(logk_ptr->add_logk);
|
||||
logk_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->logk[i]->count_add_logk * sizeof(struct name_coef));
|
||||
if (logk[i]->add_logk == NULL) malloc_error();
|
||||
for (int j = 0; j < logk_ptr->count_add_logk; j++)
|
||||
{
|
||||
logk_ptr->add_logk[j].coef = pSrc->logk[i]->add_logk[j].coef;
|
||||
logk_ptr->add_logk[j].name = string_hsave( pSrc->logk[i]->add_logk[j].name);
|
||||
}
|
||||
}
|
||||
logk_ptr->add_logk[j].coef = pSrc->logk[i]->add_logk[j].coef;
|
||||
logk_ptr->add_logk[j].name = string_hsave(pSrc->logk[i]->add_logk[j].name);
|
||||
}
|
||||
}
|
||||
|
||||
// s, species
|
||||
@ -1631,7 +1591,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
{
|
||||
struct species *s_ptr = s_store(pSrc->s[i]->name, pSrc->s[i]->z, FALSE);
|
||||
memcpy(s_ptr, pSrc->s[i], sizeof(struct species));
|
||||
s_ptr->name = string_hsave(pSrc->s[i]->name);
|
||||
// fix up all pointers
|
||||
s_ptr->mole_balance = NULL;
|
||||
if (pSrc->s[i]->mole_balance != NULL)
|
||||
@ -1641,16 +1600,11 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
s_ptr->primary = NULL;
|
||||
s_ptr->secondary = NULL;
|
||||
//add_logk
|
||||
s_ptr->add_logk = NULL;
|
||||
if (s_ptr->count_add_logk > 0)
|
||||
s_ptr->add_logk.resize(pSrc->s[i]->add_logk.size());
|
||||
for (size_t j = 0; j < s_ptr->add_logk.size(); j++)
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) s_ptr->count_add_logk * sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL) malloc_error();
|
||||
for (int j = 0; j < s_ptr->count_add_logk; j++)
|
||||
{
|
||||
s_ptr->add_logk[j].coef = pSrc->s[i]->add_logk[j].coef;
|
||||
s_ptr->add_logk[j].name = string_hsave( pSrc->s[i]->add_logk[j].name);
|
||||
}
|
||||
s_ptr->add_logk[j].coef = pSrc->s[i]->add_logk[j].coef;
|
||||
s_ptr->add_logk[j].name = string_hsave(pSrc->s[i]->add_logk[j].name);
|
||||
}
|
||||
//next_elt
|
||||
s_ptr->next_elt = NULL;
|
||||
@ -1716,19 +1670,13 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
struct phase *phase_ptr = phase_store(pSrc->phases[i]->name);
|
||||
memcpy(phase_ptr, pSrc->phases[i], sizeof(struct phase));
|
||||
// clean up pointers
|
||||
phase_ptr->name = string_hsave(pSrc->phases[i]->name);
|
||||
phase_ptr->formula = string_hsave(pSrc->phases[i]->formula);
|
||||
//add_logk
|
||||
phase_ptr->add_logk = NULL;
|
||||
if (phase_ptr->count_add_logk > 0)
|
||||
phase_ptr->add_logk.resize(pSrc->phases[i]->add_logk.size());
|
||||
for (size_t j = 0; j < phase_ptr->add_logk.size(); j++)
|
||||
{
|
||||
phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->phases[i]->count_add_logk * sizeof(struct name_coef));
|
||||
if (phase_ptr->add_logk == NULL) malloc_error();
|
||||
for (int j = 0; j < phase_ptr->count_add_logk; j++)
|
||||
{
|
||||
phase_ptr->add_logk[j].coef = pSrc->phases[i]->add_logk[j].coef;
|
||||
phase_ptr->add_logk[j].name = string_hsave( pSrc->phases[i]->add_logk[j].name);
|
||||
}
|
||||
phase_ptr->add_logk[j].coef = pSrc->phases[i]->add_logk[j].coef;
|
||||
phase_ptr->add_logk[j].name = string_hsave(pSrc->phases[i]->add_logk[j].name);
|
||||
}
|
||||
//next_elt
|
||||
phase_ptr->next_elt = NULL;
|
||||
@ -2113,10 +2061,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
|
||||
/*
|
||||
* Hash definitions
|
||||
*/
|
||||
// auto strings_map;
|
||||
#ifdef HASH
|
||||
// auto strings_hash;
|
||||
#endif
|
||||
/*
|
||||
elements_hash_table = NULL;
|
||||
species_hash_table = NULL;
|
||||
|
||||
@ -17,9 +17,6 @@ typedef unsigned char boolean;
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#ifdef HASH
|
||||
#include <hash_map>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -494,7 +491,6 @@ public:
|
||||
int revise_guesses(void);
|
||||
int ss_binary(cxxSS *ss_ptr);
|
||||
int ss_ideal(cxxSS *ss_ptr);
|
||||
void ineq_init(int max_row_count, int max_column_count);
|
||||
|
||||
// parse.cpp -------------------------------
|
||||
int check_eqn(int association);
|
||||
@ -881,7 +877,7 @@ public:
|
||||
protected:
|
||||
struct logk *logk_alloc(void);
|
||||
int logk_copy2orig(struct logk *logk_ptr);
|
||||
struct logk *logk_store(char *name, int replace_if_found);
|
||||
struct logk *logk_store(const char *name, int replace_if_found);
|
||||
struct logk *logk_search(const char *name);
|
||||
struct master *master_alloc(void);
|
||||
static int master_compare(const void *ptr1, const void *ptr2);
|
||||
@ -1003,8 +999,7 @@ public:
|
||||
int set_kinetics_time(int n_user, LDBLE step);
|
||||
|
||||
// tidy.cpp -------------------------------
|
||||
int add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
struct name_coef *add_logk);
|
||||
int add_other_logk(LDBLE* source_k, std::vector<struct name_coef> &add_logk);
|
||||
int add_logks(struct logk *logk_ptr, int repeats);
|
||||
LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol);
|
||||
int replace_solids_gases(void);
|
||||
@ -1105,11 +1100,7 @@ public:
|
||||
public:
|
||||
void *free_check_null(void *ptr);
|
||||
protected:
|
||||
void free_hash_strings(HashTable * Table);
|
||||
int get_token(char **eqnaddr, char *string, LDBLE * z, int *l);
|
||||
int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr);
|
||||
void hdestroy_multi(HashTable * HashTable_ptr);
|
||||
ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action);
|
||||
int islegit(const char c);
|
||||
public:
|
||||
void malloc_error(void);
|
||||
@ -1121,6 +1112,7 @@ public:
|
||||
static bool replace(const char *str1, const char *str2, std::string & str);
|
||||
static int strcmp_nocase(const char *str1, const char *str2);
|
||||
static int strcmp_nocase_arg1(const char *str1, const char *str2);
|
||||
static void str_tolower(std::string &name);
|
||||
protected:
|
||||
void space(void **ptr, int i, int *max, int struct_size);
|
||||
void squeeze_white(char *s_l);
|
||||
@ -1135,9 +1127,6 @@ public:
|
||||
#endif
|
||||
const char *string_hsave(const char *str);
|
||||
void strings_map_clear();
|
||||
#ifdef HASH
|
||||
void strings_hash_clear();
|
||||
#endif
|
||||
protected:
|
||||
char *string_pad(const char *str, int i);
|
||||
int string_trim(char *str);
|
||||
@ -1146,8 +1135,6 @@ protected:
|
||||
static LDBLE under(LDBLE xval);
|
||||
int get_input_errors(void);
|
||||
int isamong(char c, const char *s_l);
|
||||
Address Hash_multi(HashTable * Table, const char *Key);
|
||||
void ExpandTable_multi(HashTable * Table);
|
||||
public:
|
||||
int main_method(int argc, char *argv[]);
|
||||
void set_phast(int);
|
||||
@ -1424,7 +1411,7 @@ protected:
|
||||
int count_ad_shifts;
|
||||
int print_ad_modulus;
|
||||
int punch_ad_modulus;
|
||||
int *advection_punch, *advection_print;
|
||||
std::vector<int> advection_print, advection_punch;
|
||||
LDBLE advection_kin_time;
|
||||
LDBLE advection_kin_time_defined;
|
||||
int advection_warnings;
|
||||
@ -1663,18 +1650,15 @@ protected:
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Hash definitions
|
||||
* Map definitions
|
||||
*/
|
||||
|
||||
std::map<std::string, std::string *> strings_map;
|
||||
#ifdef HASH
|
||||
std::hash_map<std::string, std::string *> strings_hash;
|
||||
#endif
|
||||
HashTable *elements_hash_table;
|
||||
HashTable *species_hash_table;
|
||||
HashTable *phases_hash_table;
|
||||
HashTable *logk_hash_table;
|
||||
HashTable *master_isotope_hash_table;
|
||||
std::map<std::string, struct element*> elements_map;
|
||||
std::map<std::string, struct species*> species_map;
|
||||
std::map<std::string, struct phase*> phases_map;
|
||||
std::map<std::string, struct logk*> logk_map;
|
||||
std::map<std::string, struct master_isotope*> master_isotope_map;
|
||||
|
||||
#if defined(PHREEQCI_GUI)
|
||||
#include "../../phreeqci_gui.h"
|
||||
@ -1685,11 +1669,11 @@ protected:
|
||||
std::vector<struct master_isotope*> master_isotope;
|
||||
int initial_solution_isotopes;
|
||||
std::vector<struct calculate_value*> calculate_value;
|
||||
HashTable *calculate_value_hash_table;
|
||||
std::map<std::string, struct calculate_value*> calculate_value_map;
|
||||
std::vector<struct isotope_ratio*> isotope_ratio;
|
||||
HashTable *isotope_ratio_hash_table;
|
||||
std::map<std::string, struct isotope_ratio*> isotope_ratio_map;
|
||||
std::vector<struct isotope_alpha*> isotope_alpha;
|
||||
HashTable *isotope_alpha_hash_table;
|
||||
std::map<std::string, struct isotope_alpha*> isotope_alpha_map;
|
||||
int phreeqc_mpi_myself;
|
||||
int first_read_input;
|
||||
char *user_database;
|
||||
|
||||
@ -608,6 +608,7 @@ calc_logk_n(const char *name)
|
||||
struct logk *logk_ptr;
|
||||
LDBLE l_logk[MAX_LOG_K_INDICES];
|
||||
struct name_coef add_logk;
|
||||
std::vector<struct name_coef> add_logk_v;
|
||||
|
||||
for (i = 0; i < MAX_LOG_K_INDICES; i++)
|
||||
{
|
||||
@ -619,7 +620,8 @@ calc_logk_n(const char *name)
|
||||
{
|
||||
add_logk.name = token;
|
||||
add_logk.coef = 1.0;
|
||||
add_other_logk(l_logk, 1, &add_logk);
|
||||
add_logk_v.push_back(add_logk);
|
||||
add_other_logk(l_logk, add_logk_v);
|
||||
lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
return (lk);
|
||||
}
|
||||
@ -660,7 +662,7 @@ calc_logk_p(const char *name)
|
||||
}
|
||||
//lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
select_log_k_expression(reaction_ptr->logk, l_logk);
|
||||
add_other_logk(l_logk, phase_ptr->count_add_logk, phase_ptr->add_logk);
|
||||
add_other_logk(l_logk, phase_ptr->add_logk);
|
||||
lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
}
|
||||
return (lk);
|
||||
@ -689,7 +691,7 @@ calc_logk_s(const char *name)
|
||||
}
|
||||
select_log_k_expression(s_ptr->logk, l_logk);
|
||||
mu_terms_in_logk = true;
|
||||
add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk);
|
||||
add_other_logk(l_logk, s_ptr->add_logk);
|
||||
lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
return (lk);
|
||||
}
|
||||
@ -769,7 +771,7 @@ calc_deltah_p(const char* name)
|
||||
}
|
||||
//lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
select_log_k_expression(reaction_ptr->logk, l_logk);
|
||||
add_other_logk(l_logk, phase_ptr->count_add_logk, phase_ptr->add_logk);
|
||||
add_other_logk(l_logk, phase_ptr->add_logk);
|
||||
lkm = k_calc(l_logk, tk_x - 1.0, patm_x * PASCAL_PER_ATM);
|
||||
lkp = k_calc(l_logk, tk_x + 1.0, patm_x * PASCAL_PER_ATM);
|
||||
dh = (lkp - lkm) / 2.0 * LOG_10 * R_KJ_DEG_MOL * pow(tk_x, 2.0);
|
||||
@ -798,7 +800,7 @@ calc_deltah_s(const char* name)
|
||||
}
|
||||
select_log_k_expression(s_ptr->logk, l_logk);
|
||||
mu_terms_in_logk = true;
|
||||
add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk);
|
||||
add_other_logk(l_logk, s_ptr->add_logk);
|
||||
lkm = k_calc(l_logk, tk_x-1.0, patm_x * PASCAL_PER_ATM);
|
||||
lkp = k_calc(l_logk, tk_x + 1.0, patm_x * PASCAL_PER_ATM);
|
||||
dh = (lkp - lkm) / 2.0 * LOG_10 * R_KJ_DEG_MOL * pow(tk_x,2.0);
|
||||
|
||||
@ -187,43 +187,6 @@ typedef enum {
|
||||
vmi1, vmi2, vmi3, vmi4, /* ionic strength terms: (i1 + i2/(TK - 228) + i3 * (TK - 228) ) * I^i4 */
|
||||
MAX_LOG_K_INDICES /* Keep this definition at the end of the enum */
|
||||
} LOG_K_INDICES;
|
||||
/* HSEARCH(3C) */
|
||||
typedef struct entry
|
||||
{
|
||||
const char *key;
|
||||
void *data;
|
||||
} ENTRY;
|
||||
typedef enum
|
||||
{ FIND, ENTER } ACTION;
|
||||
|
||||
/* TSEARCH(3C) */
|
||||
typedef enum
|
||||
{ preorder, postorder, endorder, leaf } VISIT;
|
||||
|
||||
typedef struct Element
|
||||
{
|
||||
/*
|
||||
** The user only sees the first two fields,
|
||||
** as we pretend to pass back only a pointer to ENTRY.
|
||||
** {S}he doesn`t know what else is in here.
|
||||
*/
|
||||
const char *Key;
|
||||
char *Data;
|
||||
struct Element *Next; /* secret from user */
|
||||
} Element, *Segment;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short p; /* Next bucket to be split */
|
||||
short maxp; /* upper bound on p during expansion */
|
||||
long KeyCount; /* current # keys */
|
||||
short SegmentCount; /* current # segments */
|
||||
short MinLoadFactor;
|
||||
short MaxLoadFactor;
|
||||
Segment *Directory[DirectorySize];
|
||||
} HashTable;
|
||||
|
||||
typedef unsigned long Address;
|
||||
|
||||
typedef struct PHRQMemHeader
|
||||
{
|
||||
@ -272,8 +235,6 @@ struct model
|
||||
bool numerical_fixed_volume;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct name_master
|
||||
{
|
||||
const char *name;
|
||||
@ -650,8 +611,7 @@ struct species
|
||||
LDBLE millero[7]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */
|
||||
/* VP: Density End */
|
||||
DELTA_H_UNIT original_units; /* enum with original delta H units */
|
||||
int count_add_logk;
|
||||
struct name_coef *add_logk;
|
||||
std::vector<struct name_coef> add_logk;
|
||||
LDBLE lg; /* log10 activity coefficient, gamma */
|
||||
LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */
|
||||
LDBLE lm; /* log10 molality */
|
||||
@ -682,9 +642,8 @@ struct logk
|
||||
LDBLE lk; /* log10 k at working temperature */
|
||||
LDBLE log_k[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analalytical expression */
|
||||
DELTA_H_UNIT original_units; /* enum with original delta H units */
|
||||
int count_add_logk;
|
||||
int done;
|
||||
struct name_coef *add_logk;
|
||||
std::vector<struct name_coef> add_logk;
|
||||
LDBLE log_k_original[MAX_LOG_K_INDICES]; /* log kt0, delh, 5 coefficients analalytical expression */
|
||||
DELTA_V_UNIT original_deltav_units;
|
||||
};
|
||||
@ -701,8 +660,7 @@ struct phase
|
||||
LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analalytical expression */
|
||||
DELTA_H_UNIT original_units; /* enum with original delta H units */
|
||||
DELTA_V_UNIT original_deltav_units;
|
||||
int count_add_logk;
|
||||
struct name_coef *add_logk;
|
||||
std::vector<struct name_coef> add_logk;
|
||||
LDBLE moles_x;
|
||||
LDBLE delta_max;
|
||||
LDBLE p_soln_x;
|
||||
|
||||
@ -1325,25 +1325,19 @@ master_isotope_store(const char *name, int replace_if_found)
|
||||
*/
|
||||
int n;
|
||||
struct master_isotope *master_isotope_ptr;
|
||||
ENTRY item, *found_item;
|
||||
char token[MAX_LENGTH];
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(master_isotope_hash_table, item, FIND);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
std::map<std::string, struct master_isotope*>::iterator mi_it =
|
||||
master_isotope_map.find(name);
|
||||
if (mi_it != master_isotope_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
master_isotope_ptr = (struct master_isotope *) (found_item->data);
|
||||
master_isotope_ptr = mi_it->second;
|
||||
return (master_isotope_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (mi_it != master_isotope_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
master_isotope_ptr = (struct master_isotope *) (found_item->data);
|
||||
master_isotope_ptr = mi_it->second;
|
||||
master_isotope_init(master_isotope_ptr);
|
||||
}
|
||||
else
|
||||
@ -1355,19 +1349,11 @@ master_isotope_store(const char *name, int replace_if_found)
|
||||
master_isotope_ptr = master_isotope[n];
|
||||
}
|
||||
/* set name and z in pointer in master_isotope structure */
|
||||
master_isotope_ptr->name = string_hsave(token);
|
||||
master_isotope_ptr->name = string_hsave(name);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = master_isotope_ptr->name;
|
||||
item.data = (void *) master_isotope_ptr;
|
||||
found_item = hsearch_multi(master_isotope_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in master_isotope_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
master_isotope_map[name] = master_isotope_ptr;
|
||||
return (master_isotope_ptr);
|
||||
}
|
||||
|
||||
@ -1381,11 +1367,7 @@ master_isotope_alloc(void)
|
||||
* return: pointer to a master_isotope structure
|
||||
*/
|
||||
{
|
||||
struct master_isotope *master_isotope_ptr;
|
||||
master_isotope_ptr =
|
||||
(struct master_isotope *) PHRQ_malloc(sizeof(struct master_isotope));
|
||||
if (master_isotope_ptr == NULL)
|
||||
malloc_error();
|
||||
struct master_isotope *master_isotope_ptr = new struct master_isotope;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -1427,7 +1409,7 @@ master_isotope_search(const char *name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for master_isotope.
|
||||
* Function locates the string "name" in the map for master_isotope.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, character string to be found in "master_isotope".
|
||||
@ -1436,21 +1418,15 @@ master_isotope_search(const char *name)
|
||||
* pointer to master_isotope structure "master_isotope" where "name" can be found.
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct master_isotope *master_isotope_ptr;
|
||||
ENTRY item, *found_item;
|
||||
char token[MAX_LENGTH];
|
||||
struct master_isotope* master_isotope_ptr = NULL;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(master_isotope_hash_table, item, FIND);
|
||||
|
||||
if (found_item != NULL)
|
||||
std::map<std::string, struct master_isotope*>::iterator mi_it =
|
||||
master_isotope_map.find(name);
|
||||
if (mi_it != master_isotope_map.end())
|
||||
{
|
||||
master_isotope_ptr = (struct master_isotope *) (found_item->data);
|
||||
master_isotope_ptr = mi_it->second;
|
||||
return (master_isotope_ptr);
|
||||
}
|
||||
return (NULL);
|
||||
@ -1462,15 +1438,15 @@ master_isotope_search(const char *name)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct calculate_value * Phreeqc::
|
||||
calculate_value_store(const char *name, int replace_if_found)
|
||||
calculate_value_store(const char *name_in, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for calculate_value.
|
||||
* Function locates the string "name" in the map for calculate_value.
|
||||
*
|
||||
* Pointer to a calculate_value structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old calculate_value structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -1485,52 +1461,39 @@ calculate_value_store(const char *name, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to calculate_value structure "calculate_value" where "name" can be found.
|
||||
*/
|
||||
int n;
|
||||
struct calculate_value *calculate_value_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
struct calculate_value *calculate_value_ptr=NULL;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(calculate_value_hash_table, item, FIND);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct calculate_value*>::iterator cv_it =
|
||||
calculate_value_map.find(name);
|
||||
if (cv_it != calculate_value_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
calculate_value_ptr = (struct calculate_value *) (found_item->data);
|
||||
calculate_value_ptr = cv_it->second;
|
||||
return (calculate_value_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (cv_it != calculate_value_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
calculate_value_ptr = (struct calculate_value *) (found_item->data);
|
||||
calculate_value_ptr = cv_it->second;
|
||||
calculate_value_free(calculate_value_ptr);
|
||||
calculate_value_init(calculate_value_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = (int)calculate_value.size();
|
||||
calculate_value.resize((size_t)n+1);
|
||||
size_t n = calculate_value.size();
|
||||
calculate_value.resize(n+1);
|
||||
/* Make new calculate_value structure */
|
||||
calculate_value[n] = calculate_value_alloc();
|
||||
calculate_value_ptr = calculate_value[n];
|
||||
}
|
||||
/* set name and z in pointer in calculate_value structure */
|
||||
calculate_value_ptr->name = string_hsave(name);
|
||||
/* set name in calculate_value structure */
|
||||
calculate_value_ptr->name = string_hsave(name_in);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = string_hsave(token);
|
||||
item.data = (void *) calculate_value_ptr;
|
||||
found_item = hsearch_multi(calculate_value_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in calculate_value_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
calculate_value_map[name] = calculate_value_ptr;
|
||||
return (calculate_value_ptr);
|
||||
}
|
||||
|
||||
@ -1544,11 +1507,8 @@ calculate_value_alloc(void)
|
||||
* return: pointer to a calculate_value structure
|
||||
*/
|
||||
{
|
||||
struct calculate_value *calculate_value_ptr;
|
||||
calculate_value_ptr = (struct calculate_value *)
|
||||
PHRQ_malloc(sizeof(struct calculate_value));
|
||||
if (calculate_value_ptr == NULL)
|
||||
malloc_error();
|
||||
struct calculate_value *calculate_value_ptr =
|
||||
new struct calculate_value;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -1585,11 +1545,11 @@ calculate_value_init(struct calculate_value *calculate_value_ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct calculate_value * Phreeqc::
|
||||
calculate_value_search(const char *name)
|
||||
calculate_value_search(const char *name_in)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for calculate_value.
|
||||
* Function locates the string "name" in the map for calculate_value.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, character string to be found in "calculate_value".
|
||||
@ -1598,22 +1558,13 @@ calculate_value_search(const char *name)
|
||||
* pointer to calculate_value structure "calculate_value" where "name" can be found.
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct calculate_value *calculate_value_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(calculate_value_hash_table, item, FIND);
|
||||
|
||||
if (found_item != NULL)
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct calculate_value*>::iterator cv_it =
|
||||
calculate_value_map.find(name);
|
||||
if (cv_it != calculate_value_map.end())
|
||||
{
|
||||
calculate_value_ptr = (struct calculate_value *) (found_item->data);
|
||||
return (calculate_value_ptr);
|
||||
return (cv_it->second);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@ -1648,11 +1599,11 @@ calculate_value_free(struct calculate_value *calculate_value_ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct isotope_ratio * Phreeqc::
|
||||
isotope_ratio_store(const char *name, int replace_if_found)
|
||||
isotope_ratio_store(const char *name_in, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for isotope_ratio.
|
||||
* Function locates the string "name" in the map for isotope_ratio.
|
||||
*
|
||||
* Pointer to a isotope_ratio structure is always returned.
|
||||
*
|
||||
@ -1671,51 +1622,39 @@ isotope_ratio_store(const char *name, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to isotope_ratio structure "isotope_ratio" where "name" can be found.
|
||||
*/
|
||||
int n;
|
||||
struct isotope_ratio *isotope_ratio_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct isotope_ratio*>::iterator it =
|
||||
isotope_ratio_map.find(name);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
if (it != isotope_ratio_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data);
|
||||
isotope_ratio_ptr = it->second;
|
||||
return (isotope_ratio_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (it != isotope_ratio_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data);
|
||||
isotope_ratio_ptr = it->second;
|
||||
isotope_ratio_init(isotope_ratio_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = (int)isotope_ratio.size();
|
||||
isotope_ratio.resize((size_t)n + 1);
|
||||
size_t n = isotope_ratio.size();
|
||||
isotope_ratio.resize(n + 1);
|
||||
/* Make new isotope_ratio structure */
|
||||
isotope_ratio[n] = isotope_ratio_alloc();
|
||||
isotope_ratio_ptr = isotope_ratio[n];
|
||||
}
|
||||
/* set name and z in pointer in isotope_ratio structure */
|
||||
isotope_ratio_ptr->name = string_hsave(name);
|
||||
isotope_ratio_ptr->name = string_hsave(name_in);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = string_hsave(token);
|
||||
item.data = (void *) isotope_ratio_ptr;
|
||||
found_item = hsearch_multi(isotope_ratio_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in isotope_ratio_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
isotope_ratio_map[name] = isotope_ratio_ptr;
|
||||
return (isotope_ratio_ptr);
|
||||
}
|
||||
|
||||
@ -1729,11 +1668,8 @@ isotope_ratio_alloc(void)
|
||||
* return: pointer to a isotope_ratio structure
|
||||
*/
|
||||
{
|
||||
struct isotope_ratio *isotope_ratio_ptr;
|
||||
isotope_ratio_ptr =
|
||||
(struct isotope_ratio *) PHRQ_malloc(sizeof(struct isotope_ratio));
|
||||
if (isotope_ratio_ptr == NULL)
|
||||
malloc_error();
|
||||
struct isotope_ratio* isotope_ratio_ptr =
|
||||
new struct isotope_ratio;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -1766,11 +1702,11 @@ isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct isotope_ratio * Phreeqc::
|
||||
isotope_ratio_search(const char *name)
|
||||
isotope_ratio_search(const char *name_in)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for isotope_ratio.
|
||||
* Function locates the string "name" in the map for isotope_ratio.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, character string to be found in "isotope_ratio".
|
||||
@ -1779,22 +1715,14 @@ isotope_ratio_search(const char *name)
|
||||
* pointer to isotope_ratio structure "isotope_ratio" where "name" can be found.
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct isotope_ratio *isotope_ratio_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct isotope_ratio*>::iterator it =
|
||||
isotope_ratio_map.find(name);
|
||||
|
||||
if (found_item != NULL)
|
||||
if (it != isotope_ratio_map.end())
|
||||
{
|
||||
isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data);
|
||||
return (isotope_ratio_ptr);
|
||||
return (it->second);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@ -1805,15 +1733,15 @@ isotope_ratio_search(const char *name)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct isotope_alpha * Phreeqc::
|
||||
isotope_alpha_store(const char *name, int replace_if_found)
|
||||
isotope_alpha_store(const char *name_in, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for isotope_alpha.
|
||||
* Function locates the string "name" in the map for isotope_alpha.
|
||||
*
|
||||
* Pointer to a isotope_alpha structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old isotope_alpha structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -1828,51 +1756,35 @@ isotope_alpha_store(const char *name, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to isotope_alpha structure "isotope_alpha" where "name" can be found.
|
||||
*/
|
||||
int n;
|
||||
struct isotope_alpha *isotope_alpha_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct isotope_alpha*>::iterator it =
|
||||
isotope_alpha_map.find(name);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
if (it != isotope_alpha_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data);
|
||||
return (isotope_alpha_ptr);
|
||||
return (it->second);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (it != isotope_alpha_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data);
|
||||
isotope_alpha_ptr = it->second;
|
||||
isotope_alpha_init(isotope_alpha_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = (int)isotope_alpha.size();
|
||||
isotope_alpha.resize((size_t)n + 1);
|
||||
size_t n = isotope_alpha.size();
|
||||
isotope_alpha.resize(n + 1);
|
||||
/* Make new isotope_alpha structure */
|
||||
isotope_alpha[n] = isotope_alpha_alloc();
|
||||
isotope_alpha_ptr = isotope_alpha[n];
|
||||
}
|
||||
/* set name and z in pointer in isotope_alpha structure */
|
||||
isotope_alpha_ptr->name = string_hsave(name);
|
||||
isotope_alpha_ptr->name = string_hsave(name_in);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = string_hsave(token);
|
||||
item.data = (void *) isotope_alpha_ptr;
|
||||
found_item = hsearch_multi(isotope_alpha_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in isotope_alpha_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
isotope_alpha_map[name] = isotope_alpha_ptr;
|
||||
return (isotope_alpha_ptr);
|
||||
}
|
||||
|
||||
@ -1886,11 +1798,8 @@ isotope_alpha_alloc(void)
|
||||
* return: pointer to a isotope_alpha structure
|
||||
*/
|
||||
{
|
||||
struct isotope_alpha *isotope_alpha_ptr;
|
||||
isotope_alpha_ptr =
|
||||
(struct isotope_alpha *) PHRQ_malloc(sizeof(struct isotope_alpha));
|
||||
if (isotope_alpha_ptr == NULL)
|
||||
malloc_error();
|
||||
struct isotope_alpha* isotope_alpha_ptr =
|
||||
new struct isotope_alpha;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -1922,11 +1831,11 @@ isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct isotope_alpha * Phreeqc::
|
||||
isotope_alpha_search(const char *name)
|
||||
isotope_alpha_search(const char *name_in)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for isotope_alpha.
|
||||
* Function locates the string "name" in the map for isotope_alpha.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, character string to be found in "isotope_alpha".
|
||||
@ -1935,22 +1844,14 @@ isotope_alpha_search(const char *name)
|
||||
* pointer to isotope_alpha structure "isotope_alpha" where "name" can be found.
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct isotope_alpha *isotope_alpha_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct isotope_alpha*>::iterator it =
|
||||
isotope_alpha_map.find(name);
|
||||
|
||||
if (found_item != NULL)
|
||||
if (it != isotope_alpha_map.end())
|
||||
{
|
||||
isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data);
|
||||
return (isotope_alpha_ptr);
|
||||
return (it->second);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@ -25,22 +25,8 @@ initialize(void)
|
||||
/*
|
||||
* Initialize global variables
|
||||
*/
|
||||
struct logk *logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
|
||||
moles_per_kilogram_string = string_duplicate("Mol/kgw");
|
||||
pe_string = string_duplicate("pe");
|
||||
/*
|
||||
* Initialize advection
|
||||
*/
|
||||
advection_punch = (int *) PHRQ_malloc(sizeof(int));
|
||||
if (advection_punch == NULL)
|
||||
malloc_error();
|
||||
advection_punch[0] = TRUE;
|
||||
advection_print = (int *) PHRQ_malloc(sizeof(int));
|
||||
if (advection_print == NULL)
|
||||
malloc_error();
|
||||
advection_print[0] = TRUE;
|
||||
/*
|
||||
* Allocate space
|
||||
*/
|
||||
@ -72,14 +58,6 @@ initialize(void)
|
||||
stag_data->exch_f = 0;
|
||||
stag_data->th_m = 0;
|
||||
stag_data->th_im = 0;
|
||||
/*
|
||||
* Create hash tables
|
||||
*/
|
||||
hcreate_multi((unsigned) MAX_S, &logk_hash_table);
|
||||
hcreate_multi((unsigned) MAX_ELTS, &master_isotope_hash_table);
|
||||
hcreate_multi((unsigned) MAX_ELTS, &elements_hash_table);
|
||||
hcreate_multi((unsigned) MAX_S, &species_hash_table);
|
||||
hcreate_multi((unsigned) MAX_PHASES, &phases_hash_table);
|
||||
|
||||
// user_print
|
||||
user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
|
||||
@ -136,25 +114,6 @@ initialize(void)
|
||||
g_spread_sheet.defaults.iso = NULL;
|
||||
g_spread_sheet.defaults.redox = NULL;
|
||||
#endif
|
||||
|
||||
/* calculate_value */
|
||||
hcreate_multi((unsigned) MAX_ELTS,
|
||||
&calculate_value_hash_table);
|
||||
|
||||
/* isotope_ratio */
|
||||
hcreate_multi((unsigned) MAX_ELTS, &isotope_ratio_hash_table);
|
||||
|
||||
/* isotope_alpha */
|
||||
hcreate_multi((unsigned) MAX_ELTS, &isotope_alpha_hash_table);
|
||||
|
||||
/*
|
||||
* define constant named log_k
|
||||
*/
|
||||
strcpy(token, "XconstantX");
|
||||
logk_ptr = logk_store(token, TRUE);
|
||||
strcpy(token, "1.0");
|
||||
read_log_k_only(token, &logk_ptr->log_k[0]);
|
||||
|
||||
// allocate space for copier
|
||||
copier_init(©_solution);
|
||||
copier_init(©_pp_assemblage);
|
||||
|
||||
@ -1017,11 +1017,6 @@ ineq(int in_kode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize space if necessary
|
||||
*/
|
||||
ineq_init(3 * count_unknowns, 3 * count_unknowns);
|
||||
/*
|
||||
* Normalize column
|
||||
*/
|
||||
@ -5312,7 +5307,7 @@ int Phreeqc::
|
||||
numerical_jacobian(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
LDBLE *base;
|
||||
std::vector<double> base;
|
||||
LDBLE d, d1, d2;
|
||||
int i, j;
|
||||
cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr();
|
||||
@ -5342,14 +5337,8 @@ numerical_jacobian(void)
|
||||
memcpy((void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
(void *) &(my_array[0]), (size_t)count_unknowns * sizeof(LDBLE));
|
||||
}
|
||||
|
||||
base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE));
|
||||
if (base == NULL)
|
||||
malloc_error();
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
base[i] = residual[i];
|
||||
}
|
||||
base.resize((size_t)count_unknowns);
|
||||
base = residual;
|
||||
d = 0.0001;
|
||||
d1 = d * LOG_10;
|
||||
d2 = 0;
|
||||
@ -5549,85 +5538,11 @@ numerical_jacobian(void)
|
||||
mb_gases();
|
||||
mb_ss();
|
||||
residuals();
|
||||
free_check_null(base);
|
||||
base.clear();
|
||||
calculating_deriv = FALSE;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
ineq_init(int l_max_row_count, int l_max_column_count)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
//if (normal == NULL)
|
||||
//{
|
||||
// normal =
|
||||
// (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE));
|
||||
// normal_max = count_unknowns;
|
||||
// if (normal == NULL)
|
||||
// malloc_error();
|
||||
//}
|
||||
////if (ineq_array == NULL)
|
||||
////{
|
||||
//// ineq_array =
|
||||
//// (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * l_max_column_count *
|
||||
//// sizeof(LDBLE));
|
||||
//// if (ineq_array == NULL)
|
||||
//// malloc_error();
|
||||
//// ineq_array_max = l_max_row_count * l_max_column_count;
|
||||
////}
|
||||
//if (back_eq == NULL)
|
||||
//{
|
||||
// back_eq = (int *) PHRQ_malloc((size_t) l_max_row_count * sizeof(int));
|
||||
// if (back_eq == NULL)
|
||||
// malloc_error();
|
||||
// back_eq_max = l_max_row_count;
|
||||
//}
|
||||
//if (zero == NULL)
|
||||
//{
|
||||
// zero = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE));
|
||||
// if (zero == NULL)
|
||||
// malloc_error();
|
||||
// zero_max = l_max_row_count;
|
||||
//}
|
||||
//if (res == NULL)
|
||||
//{
|
||||
// res = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE));
|
||||
// if (res == NULL)
|
||||
// malloc_error();
|
||||
// res_max = l_max_row_count;
|
||||
//}
|
||||
//if (delta1 == NULL)
|
||||
//{
|
||||
// delta1 =
|
||||
// (LDBLE *) PHRQ_malloc((size_t) l_max_column_count * sizeof(LDBLE));
|
||||
// if (delta1 == NULL)
|
||||
// malloc_error();
|
||||
// delta1_max = l_max_column_count;
|
||||
//}
|
||||
//if (cu == NULL)
|
||||
//{
|
||||
// cu = (LDBLE *) PHRQ_malloc((size_t) 3 * l_max_row_count *
|
||||
// sizeof(LDBLE));
|
||||
// if (cu == NULL)
|
||||
// malloc_error();
|
||||
// cu_max = 3 * l_max_row_count;
|
||||
//}
|
||||
//if (iu == NULL)
|
||||
//{
|
||||
// iu = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int));
|
||||
// if (iu == NULL)
|
||||
// malloc_error();
|
||||
// iu_max = 3 * l_max_row_count;
|
||||
//}
|
||||
//if (is == NULL)
|
||||
//{
|
||||
// is = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int));
|
||||
// if (is == NULL)
|
||||
// malloc_error();
|
||||
// is_max = 3 * l_max_row_count;
|
||||
//}
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
set_inert_moles(void)
|
||||
|
||||
@ -634,104 +634,68 @@ read_exchange_species(void)
|
||||
break;
|
||||
case 16: /* add_logk */
|
||||
case 17: /* add_log_k */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
/* read name */
|
||||
if (copy_token(token, &next_char, &i) == EMPTY)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token);
|
||||
s_ptr->add_logk[count_add_logk].name = string_hsave(token);
|
||||
/* read coef */
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
&s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].coef = 1;
|
||||
s_ptr->add_logk[count_add_logk].coef = 1;
|
||||
}
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 18: /* add_constant */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
&s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the constant to add for log_K definition.");
|
||||
"Expected the constant to add for log_K definition.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
/* set name */
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name =
|
||||
s_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave("XconstantX");
|
||||
/* read coef */
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 19: /* vm, molar volume */
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
@ -3728,79 +3692,54 @@ read_phases(void)
|
||||
break;
|
||||
case 9: /* add_logk */
|
||||
case 10: /* add_log_k */
|
||||
{
|
||||
if (phase_ptr == NULL)
|
||||
break;
|
||||
if (phase_ptr->count_add_logk == 0)
|
||||
{
|
||||
phase_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (phase_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk,
|
||||
(((size_t)phase_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (phase_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
size_t count_add_logk = phase_ptr->add_logk.size();
|
||||
phase_ptr->add_logk.resize(count_add_logk + 1);
|
||||
/* read name */
|
||||
if (copy_token(token, &next_char, &i) == EMPTY)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
phase_ptr->add_logk[phase_ptr->count_add_logk].name =
|
||||
phase_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave(token);
|
||||
/* read coef */
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&phase_ptr->add_logk[phase_ptr->count_add_logk].coef);
|
||||
&phase_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
phase_ptr->add_logk[phase_ptr->count_add_logk].coef = 1;
|
||||
phase_ptr->add_logk[count_add_logk].coef = 1;
|
||||
}
|
||||
phase_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 11: /* add_constant */
|
||||
{
|
||||
if (phase_ptr == NULL)
|
||||
break;
|
||||
if (phase_ptr->count_add_logk == 0)
|
||||
{
|
||||
phase_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (phase_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk,
|
||||
(((size_t)phase_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (phase_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
size_t count_add_logk = phase_ptr->add_logk.size();
|
||||
phase_ptr->add_logk.resize(count_add_logk + 1);
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&phase_ptr->add_logk[(size_t)phase_ptr->count_add_logk].coef);
|
||||
&phase_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the constant to add for log_K definition.");
|
||||
"Expected the constant to add for log_K definition.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
/* set name */
|
||||
phase_ptr->add_logk[phase_ptr->count_add_logk].name =
|
||||
phase_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave("XconstantX");
|
||||
/* read coef */
|
||||
phase_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 12: /* T_c */
|
||||
if (phase_ptr == NULL)
|
||||
break;
|
||||
@ -5613,92 +5552,68 @@ read_species(void)
|
||||
break;
|
||||
case 16: /* add_logk */
|
||||
case 17: /* add_log_k */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
/* read name */
|
||||
if (copy_token(token, &next_char, &i) == EMPTY)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token);
|
||||
s_ptr->add_logk[count_add_logk].name = string_hsave(token);
|
||||
/* read coef */
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
&s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].coef = 1;
|
||||
s_ptr->add_logk[count_add_logk].coef = 1;
|
||||
}
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 18: /* add_constant */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
&s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the constant to add for log_K definition.");
|
||||
"Expected the constant to add for log_K definition.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
/* set name */
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name =
|
||||
s_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave("XconstantX");
|
||||
/* read coef */
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 19: /* tracer diffusion coefficient */
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
@ -6309,98 +6224,66 @@ read_surface_species(void)
|
||||
break;
|
||||
case 13: /* add_logk */
|
||||
case 14: /* add_log_k */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
}
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
/* read name */
|
||||
if (copy_token(token, &next_char, &i) == EMPTY)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token);
|
||||
s_ptr->add_logk[count_add_logk].name = string_hsave(token);
|
||||
/* read coef */
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
&s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].coef = 1;
|
||||
s_ptr->add_logk[count_add_logk].coef = 1;
|
||||
}
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 15: /* add_constant */
|
||||
{
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (s_ptr->count_add_logk == 0)
|
||||
{
|
||||
s_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk,
|
||||
(((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (s_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&s_ptr->add_logk[s_ptr->count_add_logk].coef);
|
||||
size_t count_add_logk = s_ptr->add_logk.size();
|
||||
s_ptr->add_logk.resize(count_add_logk + 1);
|
||||
i = sscanf(next_char, SCANFORMAT, &s_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the constant to add for log_K definition.");
|
||||
"Expected the constant to add for log_K definition.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
/* set name */
|
||||
s_ptr->add_logk[s_ptr->count_add_logk].name =
|
||||
s_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave("XconstantX");
|
||||
/* read coef */
|
||||
s_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 16: /* cd_music */
|
||||
case 17: /* music */
|
||||
if (s_ptr == NULL)
|
||||
@ -7580,10 +7463,7 @@ read_advection(void)
|
||||
/*
|
||||
* Fill in data for punch
|
||||
*/
|
||||
advection_punch = (int *) PHRQ_realloc(advection_punch,
|
||||
((size_t)count_ad_cells + 1) * sizeof(int));
|
||||
if (advection_punch == NULL)
|
||||
malloc_error();
|
||||
advection_punch.resize((size_t)count_ad_cells + 1);
|
||||
if (count_punch != 0)
|
||||
{
|
||||
for (i = 0; i < count_ad_cells; i++)
|
||||
@ -7612,10 +7492,7 @@ read_advection(void)
|
||||
/*
|
||||
* Fill in data for print
|
||||
*/
|
||||
advection_print = (int *) PHRQ_realloc(advection_print,
|
||||
((size_t)count_ad_cells + 1) * sizeof(int));
|
||||
if (advection_print == NULL)
|
||||
malloc_error();
|
||||
advection_print.resize((size_t)count_ad_cells + 1);
|
||||
if (count_print != 0)
|
||||
{
|
||||
for (i = 0; i < count_ad_cells; i++)
|
||||
@ -9844,51 +9721,39 @@ read_named_logk(void)
|
||||
break;
|
||||
case 8: /* add_logk */
|
||||
case 9: /* add_log_k */
|
||||
{
|
||||
if (logk_ptr == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
"No reaction defined before option, %s.",
|
||||
opt_list[opt]);
|
||||
error_msg(error_string, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
if (logk_ptr->count_add_logk == 0)
|
||||
{
|
||||
logk_ptr->add_logk =
|
||||
(struct name_coef *)
|
||||
PHRQ_malloc(sizeof(struct name_coef));
|
||||
if (logk_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
logk_ptr->add_logk = (struct name_coef *) PHRQ_realloc(logk_ptr->add_logk,
|
||||
(((size_t)logk_ptr->count_add_logk + 1) * sizeof(struct name_coef)));
|
||||
if (logk_ptr->add_logk == NULL)
|
||||
malloc_error();
|
||||
}
|
||||
size_t count_add_logk = logk_ptr->add_logk.size();
|
||||
logk_ptr->add_logk.resize(count_add_logk + 1);
|
||||
/* read name */
|
||||
if (copy_token(token, &next_char, &i) == EMPTY)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
"Expected the name of a NAMED_EXPRESSION.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
break;
|
||||
}
|
||||
logk_ptr->add_logk[logk_ptr->count_add_logk].name =
|
||||
logk_ptr->add_logk[count_add_logk].name =
|
||||
string_hsave(token);
|
||||
/* read coef */
|
||||
i = sscanf(next_char, SCANFORMAT,
|
||||
&logk_ptr->add_logk[logk_ptr->count_add_logk].coef);
|
||||
&logk_ptr->add_logk[count_add_logk].coef);
|
||||
if (i <= 0)
|
||||
{
|
||||
logk_ptr->add_logk[logk_ptr->count_add_logk].coef = 1;
|
||||
logk_ptr->add_logk[count_add_logk].coef = 1;
|
||||
}
|
||||
logk_ptr->count_add_logk++;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 10: /* vm, molar volume */
|
||||
if (logk_ptr == NULL)
|
||||
{
|
||||
|
||||
@ -67,7 +67,7 @@ clean_up(void)
|
||||
for (j = 0; j < (int)s.size(); j++)
|
||||
{
|
||||
s_free(s[j]);
|
||||
s[j] = (struct species*)free_check_null(s[j]);
|
||||
delete s[j];
|
||||
}
|
||||
s.clear();
|
||||
|
||||
@ -83,7 +83,7 @@ clean_up(void)
|
||||
|
||||
for (j = 0; j < (int)elements.size(); j++)
|
||||
{
|
||||
elements[j] = (struct element*)free_check_null(elements[j]);
|
||||
delete elements[j];
|
||||
}
|
||||
elements.clear();
|
||||
/* solutions */
|
||||
@ -114,7 +114,7 @@ clean_up(void)
|
||||
for (j = 0; j < (int)phases.size(); j++)
|
||||
{
|
||||
phase_free(phases[j]);
|
||||
phases[j] = (struct phase*)free_check_null(phases[j]);
|
||||
delete phases[j];
|
||||
}
|
||||
phases.clear();
|
||||
/* inverse */
|
||||
@ -140,8 +140,8 @@ clean_up(void)
|
||||
/* logk hash table */
|
||||
for (j = 0; j < (int)logk.size(); j++)
|
||||
{
|
||||
free_check_null(logk[j]->add_logk);
|
||||
logk[j] = (struct logk*)free_check_null(logk[j]);
|
||||
logk[j]->add_logk.clear();
|
||||
delete logk[j];
|
||||
}
|
||||
logk.clear();
|
||||
/* save_values */
|
||||
@ -159,8 +159,8 @@ clean_up(void)
|
||||
stag_data = (struct stag_data*)free_check_null(stag_data);
|
||||
cell_data = (struct cell_data*)free_check_null(cell_data);
|
||||
/* advection */
|
||||
advection_punch = (int*)free_check_null(advection_punch);
|
||||
advection_print = (int*)free_check_null(advection_print);
|
||||
advection_punch.clear();
|
||||
advection_print.clear();
|
||||
/* selected_output */
|
||||
SelectedOutput_map.clear();
|
||||
/* user_print and user_punch */
|
||||
@ -192,38 +192,32 @@ clean_up(void)
|
||||
/* master_isotope */
|
||||
for (i = 0; i < (int)master_isotope.size(); i++)
|
||||
{
|
||||
master_isotope[i] = (struct master_isotope*)free_check_null(master_isotope[i]);
|
||||
delete master_isotope[i];
|
||||
}
|
||||
master_isotope.clear();
|
||||
hdestroy_multi(master_isotope_hash_table);
|
||||
master_isotope_hash_table = NULL;
|
||||
master_isotope_map.clear();
|
||||
/* calculate_value */
|
||||
for (i = 0; i < (int)calculate_value.size(); i++)
|
||||
{
|
||||
calculate_value_free(calculate_value[i]);
|
||||
calculate_value[i] = (struct calculate_value*)free_check_null(calculate_value[i]);
|
||||
delete calculate_value[i];
|
||||
}
|
||||
calculate_value.clear();
|
||||
hdestroy_multi(calculate_value_hash_table);
|
||||
calculate_value_hash_table = NULL;
|
||||
calculate_value_map.clear();
|
||||
/* isotope_ratio */
|
||||
for (i = 0; i < (int)isotope_ratio.size(); i++)
|
||||
{
|
||||
isotope_ratio[i] =
|
||||
(struct isotope_ratio*)free_check_null(isotope_ratio[i]);
|
||||
delete isotope_ratio[i];
|
||||
}
|
||||
isotope_ratio.clear();
|
||||
hdestroy_multi(isotope_ratio_hash_table);
|
||||
isotope_ratio_hash_table = NULL;
|
||||
isotope_ratio_map.clear();
|
||||
/* isotope_alpha */
|
||||
for (i = 0; i < (int)isotope_alpha.size(); i++)
|
||||
{
|
||||
isotope_alpha[i] =
|
||||
(struct isotope_alpha*)free_check_null(isotope_alpha[i]);
|
||||
delete isotope_alpha[i];
|
||||
}
|
||||
isotope_alpha.clear();
|
||||
hdestroy_multi(isotope_alpha_hash_table);
|
||||
isotope_alpha_hash_table = NULL;
|
||||
isotope_alpha_map.clear();
|
||||
/* tally table */
|
||||
free_tally_table();
|
||||
/* CVODE memory */
|
||||
@ -233,20 +227,12 @@ clean_up(void)
|
||||
/* sit */
|
||||
sit_clean_up();
|
||||
/* hash tables */
|
||||
hdestroy_multi(elements_hash_table);
|
||||
hdestroy_multi(species_hash_table);
|
||||
hdestroy_multi(logk_hash_table);
|
||||
hdestroy_multi(phases_hash_table);
|
||||
elements_hash_table = NULL;
|
||||
species_hash_table = NULL;
|
||||
logk_hash_table = NULL;
|
||||
phases_hash_table = NULL;
|
||||
elements_map.clear();
|
||||
species_map.clear();
|
||||
phases_map.clear();
|
||||
logk_map.clear();
|
||||
/* strings */
|
||||
#ifdef HASH
|
||||
strings_hash_clear();
|
||||
#else
|
||||
strings_map_clear();
|
||||
#endif
|
||||
/* delete basic interpreter */
|
||||
basic_free();
|
||||
/* change_surf */
|
||||
@ -324,69 +310,45 @@ element_compare(const void *ptr1, const void *ptr2)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct element * Phreeqc::
|
||||
element_store(const char *element)
|
||||
struct element* Phreeqc::
|
||||
element_store(const char * element)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "element" in the hash table for elements.
|
||||
*
|
||||
* If found, pointer to the appropriate element structure is returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made at the end of
|
||||
* the elements array (position count_elements) and count_elements is
|
||||
* incremented. A new entry is made in the hash table. Pointer to
|
||||
* the new structure is returned.
|
||||
*
|
||||
* Arguments:
|
||||
* element input, character string to be located or stored.
|
||||
*
|
||||
* Returns:
|
||||
* The address of an elt structure that contains the element data.
|
||||
*/
|
||||
struct element *elts_ptr;
|
||||
ENTRY item, *found_item;
|
||||
char token[MAX_LENGTH];
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
strcpy(token, element);
|
||||
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(elements_hash_table, item, FIND);
|
||||
if (found_item != NULL)
|
||||
/*
|
||||
* Function locates the string "element" in the map for elements.
|
||||
*
|
||||
* If found, pointer to the appropriate element structure is returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made at the end of
|
||||
* the elements array (position count_elements) and count_elements is
|
||||
* incremented. Pointer to the new structure is returned.
|
||||
*
|
||||
* Arguments:
|
||||
* element input, std::string to be located or stored.
|
||||
*
|
||||
* Returns:
|
||||
* The address of an elt structure that contains the element data.
|
||||
*/
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
std::map<std::string, struct element *>::const_iterator it;
|
||||
it = elements_map.find(element);
|
||||
if (it != elements_map.end())
|
||||
{
|
||||
elts_ptr = (struct element *) (found_item->data);
|
||||
return (elts_ptr);
|
||||
return (it->second);
|
||||
}
|
||||
/*
|
||||
* Save new elt structure and return pointer to it
|
||||
*/
|
||||
/* make sure there is space in elements */
|
||||
size_t count_elements = elements.size();
|
||||
elements.resize(count_elements + 1);
|
||||
elements[count_elements] = (struct element *) PHRQ_malloc((size_t) sizeof(struct element));
|
||||
if (elements[count_elements] == NULL)
|
||||
malloc_error();
|
||||
/* set name pointer in elements structure */
|
||||
elements[count_elements]->name = string_hsave(token);
|
||||
/* set return value */
|
||||
elements[count_elements]->master = NULL;
|
||||
elements[count_elements]->primary = NULL;
|
||||
elements[count_elements]->gfw = 0.0;
|
||||
/*
|
||||
* Update hash table
|
||||
*/
|
||||
item.key = elements[count_elements]->name;
|
||||
item.data = (void *) elements[count_elements];
|
||||
found_item = hsearch_multi(elements_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in element_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
return (elements[count_elements]);
|
||||
/*
|
||||
* Save new element structure and return pointer to it
|
||||
*/
|
||||
struct element *elt_ptr = new struct element;
|
||||
elt_ptr->name = string_hsave(element);
|
||||
elt_ptr->master = NULL;
|
||||
elt_ptr->primary = NULL;
|
||||
elt_ptr->gfw = 0.0;
|
||||
elements.push_back(elt_ptr);
|
||||
elements_map[element] = elt_ptr;
|
||||
return (elt_ptr);
|
||||
}
|
||||
|
||||
/* **********************************************************************
|
||||
@ -871,10 +833,7 @@ master_alloc(void)
|
||||
* return: pointer to a master structure
|
||||
*/
|
||||
{
|
||||
struct master *ptr;
|
||||
ptr = (struct master *) PHRQ_malloc(sizeof(struct master));
|
||||
if (ptr == NULL)
|
||||
malloc_error();
|
||||
struct master *ptr = new struct master;
|
||||
/*
|
||||
* set pointers in structure to NULL
|
||||
*/
|
||||
@ -939,7 +898,7 @@ master_free(struct master *master_ptr)
|
||||
return (ERROR);
|
||||
rxn_free(master_ptr->rxn_primary);
|
||||
rxn_free(master_ptr->rxn_secondary);
|
||||
master_ptr = (struct master *) free_check_null(master_ptr);
|
||||
delete master_ptr;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
@ -1158,9 +1117,7 @@ phase_alloc(void)
|
||||
/*
|
||||
* Allocate space
|
||||
*/
|
||||
phase_ptr = (struct phase *) PHRQ_malloc(sizeof(struct phase));
|
||||
if (phase_ptr == NULL)
|
||||
malloc_error();
|
||||
phase_ptr = new struct phase;
|
||||
/*
|
||||
* Initialize space
|
||||
*/
|
||||
@ -1229,8 +1186,7 @@ phase_free(struct phase *phase_ptr)
|
||||
rxn_free(phase_ptr->rxn);
|
||||
rxn_free(phase_ptr->rxn_s);
|
||||
rxn_free(phase_ptr->rxn_x);
|
||||
phase_ptr->add_logk =
|
||||
(struct name_coef *) free_check_null(phase_ptr->add_logk);
|
||||
phase_ptr->add_logk.clear();
|
||||
return (OK);
|
||||
}
|
||||
|
||||
@ -1295,8 +1251,7 @@ phase_init(struct phase *phase_ptr)
|
||||
for (i = 0; i < MAX_LOG_K_INDICES; i++)
|
||||
phase_ptr->logk[i] = 0.0;
|
||||
phase_ptr->original_units = kjoules;
|
||||
phase_ptr->count_add_logk = 0;
|
||||
phase_ptr->add_logk = NULL;
|
||||
phase_ptr->add_logk.clear();
|
||||
phase_ptr->moles_x = 0;
|
||||
phase_ptr->delta_max = 0;
|
||||
phase_ptr->p_soln_x = 0;
|
||||
@ -1337,18 +1292,17 @@ phase_init(struct phase *phase_ptr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct phase * Phreeqc::
|
||||
phase_store(const char *name)
|
||||
phase_store(const char *name_in)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for phases.
|
||||
* Function locates the string "name" in the map for phases.
|
||||
*
|
||||
* If found, pointer to the appropriate phase structure is returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made at the end of
|
||||
* the phases array (position count_phases) and count_phases is
|
||||
* incremented. A new entry is made in the hash table. Pointer to
|
||||
* the new structure is returned.
|
||||
* the phases array (position count_phases), it is added to the map,
|
||||
* and the new structure is returned.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, character string to be located or stored.
|
||||
@ -1358,49 +1312,34 @@ phase_store(const char *name)
|
||||
* If phase existed, it is reinitialized. The structure returned
|
||||
* contains only the name of the phase.
|
||||
*/
|
||||
struct phase *phase_ptr;
|
||||
ENTRY item, *found_item;
|
||||
char token[MAX_LENGTH];
|
||||
const char *ptr;
|
||||
struct phase *phase_ptr = NULL;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
|
||||
strcpy(token, name);
|
||||
str_tolower(token);
|
||||
ptr = string_hsave(token);
|
||||
|
||||
item.key = ptr;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(phases_hash_table, item, FIND);
|
||||
if (found_item != NULL)
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
std::map<std::string, struct phase*>::iterator p_it =
|
||||
phases_map.find(name);
|
||||
if (p_it != phases_map.end())
|
||||
{
|
||||
phase_ptr = (struct phase *) (found_item->data);
|
||||
phase_ptr = p_it->second;
|
||||
phase_free(phase_ptr);
|
||||
phase_init(phase_ptr);
|
||||
phase_ptr->name = string_hsave(name);
|
||||
phase_ptr->name = string_hsave(name_in);
|
||||
return (phase_ptr);
|
||||
}
|
||||
/*
|
||||
* Make new phase structure and return pointer to it
|
||||
*/
|
||||
size_t n = (int)phases.size();
|
||||
size_t n = phases.size();
|
||||
phases.resize(n + 1);
|
||||
phases[n] = phase_alloc();
|
||||
/* set name in phase structure */
|
||||
phases[n]->name = string_hsave(name);
|
||||
phases[n]->name = string_hsave(name_in);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = ptr;
|
||||
item.data = (void *) phases[n];
|
||||
found_item = hsearch_multi(phases_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in phase_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
phases_map[name] = phases[n];
|
||||
return (phases[n]);
|
||||
}
|
||||
/* **********************************************************************
|
||||
@ -1834,9 +1773,7 @@ s_alloc(void)
|
||||
*/
|
||||
{
|
||||
struct species *s_ptr;
|
||||
s_ptr = (struct species *) PHRQ_malloc(sizeof(struct species));
|
||||
if (s_ptr == NULL)
|
||||
malloc_error();
|
||||
s_ptr = new struct species;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -1886,7 +1823,7 @@ s_free(struct species *s_ptr)
|
||||
(struct elt_list *) free_check_null(s_ptr->next_secondary);
|
||||
s_ptr->next_sys_total =
|
||||
(struct elt_list *) free_check_null(s_ptr->next_sys_total);
|
||||
s_ptr->add_logk = (struct name_coef *) free_check_null(s_ptr->add_logk);
|
||||
s_ptr->add_logk.clear();
|
||||
rxn_free(s_ptr->rxn);
|
||||
rxn_free(s_ptr->rxn_s);
|
||||
rxn_free(s_ptr->rxn_x);
|
||||
@ -1943,8 +1880,7 @@ s_init(struct species *s_ptr)
|
||||
}
|
||||
/* VP: Density End */
|
||||
s_ptr->original_units = kjoules;
|
||||
s_ptr->count_add_logk = 0;
|
||||
s_ptr->add_logk = NULL;
|
||||
s_ptr->add_logk.clear();
|
||||
s_ptr->lg = 0.0;
|
||||
s_ptr->lg_pitzer = 0.0;
|
||||
s_ptr->lm = 0.0;
|
||||
@ -1975,52 +1911,43 @@ s_init(struct species *s_ptr)
|
||||
s_ptr->original_deltav_units = cm3_per_mol;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct species * Phreeqc::
|
||||
s_search(const char *name)
|
||||
struct species* Phreeqc::
|
||||
s_search(const char* name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for species.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, a character string to be located in species.
|
||||
* i is obsolete.
|
||||
*
|
||||
* Returns:
|
||||
* If found, pointer to the appropriate species structure is returned.
|
||||
* else, NULL pointer is returned.
|
||||
*/
|
||||
struct species *s_ptr;
|
||||
ENTRY item, *found_item;
|
||||
char safe_name[MAX_LENGTH];
|
||||
|
||||
strcpy(safe_name, name);
|
||||
item.key = safe_name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(species_hash_table, item, FIND);
|
||||
if (found_item != NULL)
|
||||
/*
|
||||
* Function locates the string "name" in the species_map.
|
||||
*
|
||||
* Arguments:
|
||||
* name input, a character string to be located in species.
|
||||
*
|
||||
* Returns:
|
||||
* If found, pointer to the appropriate species structure is returned.
|
||||
* else, NULL pointer is returned.
|
||||
*/
|
||||
struct species* s_ptr = NULL;
|
||||
std::map<std::string, struct species*>::iterator s_it =
|
||||
species_map.find(name);
|
||||
if (s_it != species_map.end())
|
||||
{
|
||||
s_ptr = (struct species *) (found_item->data);
|
||||
return (s_ptr);
|
||||
s_ptr = s_it->second;
|
||||
}
|
||||
return (NULL);
|
||||
return (s_ptr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct species * Phreeqc::
|
||||
s_store(const char *name, LDBLE l_z, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for species.
|
||||
* Function locates the string "name" in the map for species.
|
||||
*
|
||||
* Pointer to a species structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made at the end of
|
||||
* the elements array (position count_elements) and count_elements is
|
||||
* incremented. A new entry is made in the hash table. Pointer to
|
||||
* incremented. A new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old species structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -2036,31 +1963,25 @@ s_store(const char *name, LDBLE l_z, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to species structure "s" where "name" can be found.
|
||||
*/
|
||||
int n;
|
||||
struct species *s_ptr;
|
||||
ENTRY item, *found_item;
|
||||
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
item.key = name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(species_hash_table, item, FIND);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
struct species* s_ptr = NULL;
|
||||
s_ptr = s_search(name);
|
||||
if (s_ptr != NULL && replace_if_found == FALSE)
|
||||
{
|
||||
s_ptr = (struct species *) (found_item->data);
|
||||
return (s_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (s_ptr != NULL && replace_if_found == TRUE)
|
||||
{
|
||||
s_ptr = (struct species *) (found_item->data);
|
||||
s_free(s_ptr);
|
||||
s_init(s_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = (int)s.size();
|
||||
s.resize((size_t)n + 1);
|
||||
size_t n = s.size();
|
||||
s.resize(n + 1);
|
||||
/* Make new species structure */
|
||||
s[n] = s_alloc();
|
||||
s_ptr = s[n];
|
||||
@ -2069,17 +1990,9 @@ s_store(const char *name, LDBLE l_z, int replace_if_found)
|
||||
s_ptr->name = string_hsave(name);
|
||||
s_ptr->z = l_z;
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = s_ptr->name;
|
||||
item.data = (void *) s_ptr;
|
||||
found_item = hsearch_multi(species_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in species_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
species_map[name] = s_ptr;
|
||||
return (s_ptr);
|
||||
}
|
||||
/* **********************************************************************
|
||||
@ -3105,15 +3018,15 @@ system_duplicate(int i, int save_old)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct logk * Phreeqc::
|
||||
logk_store(char *name, int replace_if_found)
|
||||
logk_store(const char *name_in, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for logk.
|
||||
* Function locates the string "name" in the map for logk.
|
||||
*
|
||||
* Pointer to a logk structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old logk structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -3128,24 +3041,23 @@ logk_store(char *name, int replace_if_found)
|
||||
* Returns:
|
||||
* pointer to logk structure "logk" where "name" can be found.
|
||||
*/
|
||||
struct logk *logk_ptr;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
struct logk* logk_ptr = NULL;
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
item.key = name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
std::map<std::string, struct logk*>::iterator it =
|
||||
logk_map.find(name);
|
||||
|
||||
if (found_item != NULL && replace_if_found == FALSE)
|
||||
if (it != logk_map.end() && replace_if_found == FALSE)
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = it->second;
|
||||
return (logk_ptr);
|
||||
}
|
||||
else if (found_item != NULL && replace_if_found == TRUE)
|
||||
else if (it != logk_map.end() && replace_if_found == TRUE)
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = it->second;
|
||||
logk_init(logk_ptr);
|
||||
}
|
||||
else
|
||||
@ -3157,19 +3069,11 @@ logk_store(char *name, int replace_if_found)
|
||||
logk_ptr = logk[n];
|
||||
}
|
||||
/* set name and z in pointer in logk structure */
|
||||
logk_ptr->name = string_hsave(name);
|
||||
logk_ptr->name = string_hsave(name_in);
|
||||
/*
|
||||
* Update hash table
|
||||
* Update map
|
||||
*/
|
||||
item.key = logk_ptr->name;
|
||||
item.data = (void *) logk_ptr;
|
||||
found_item = hsearch_multi(logk_hash_table, item, ENTER);
|
||||
if (found_item == NULL)
|
||||
{
|
||||
error_string = sformatf( "Hash table error in logk_store.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
|
||||
logk_map[name] = logk_ptr;
|
||||
return (logk_ptr);
|
||||
}
|
||||
|
||||
@ -3184,9 +3088,7 @@ logk_alloc(void)
|
||||
*/
|
||||
{
|
||||
struct logk *logk_ptr;
|
||||
logk_ptr = (struct logk *) PHRQ_malloc(sizeof(struct logk));
|
||||
if (logk_ptr == NULL)
|
||||
malloc_error();
|
||||
logk_ptr = new struct logk;
|
||||
/*
|
||||
* set pointers in structure to NULL, variables to zero
|
||||
*/
|
||||
@ -3217,8 +3119,7 @@ logk_init(struct logk *logk_ptr)
|
||||
logk_ptr->log_k[i] = 0.0;
|
||||
logk_ptr->log_k_original[i] = 0.0;
|
||||
}
|
||||
logk_ptr->count_add_logk = 0;
|
||||
logk_ptr->add_logk = NULL;
|
||||
logk_ptr->add_logk.clear();
|
||||
return (OK);
|
||||
}
|
||||
|
||||
@ -3254,19 +3155,16 @@ logk_search(const char *name_in)
|
||||
* or NULL if not found.
|
||||
*/
|
||||
struct logk *logk_ptr;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Search list
|
||||
*/
|
||||
char * name = string_duplicate(name_in);
|
||||
std::string name = name_in;
|
||||
str_tolower(name);
|
||||
item.key = name;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
free_check_null(name);
|
||||
if (found_item != NULL)
|
||||
std::map<std::string, struct logk*>::iterator l_it =
|
||||
logk_map.find(name);
|
||||
if (l_it != logk_map.end())
|
||||
{
|
||||
logk_ptr = (struct logk *) (found_item->data);
|
||||
logk_ptr = l_it->second;
|
||||
return (logk_ptr);
|
||||
}
|
||||
return (NULL);
|
||||
|
||||
@ -476,8 +476,7 @@ check_species_input(void)
|
||||
else
|
||||
{
|
||||
select_log_k_expression(s[i]->logk, s[i]->rxn->logk);
|
||||
add_other_logk(s[i]->rxn->logk, s[i]->count_add_logk,
|
||||
s[i]->add_logk);
|
||||
add_other_logk(s[i]->rxn->logk, s[i]->add_logk);
|
||||
}
|
||||
}
|
||||
return (return_value);
|
||||
@ -488,18 +487,19 @@ int Phreeqc::
|
||||
select_log_k_expression(LDBLE * source_k, LDBLE * target_k)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int j, analytic;
|
||||
int j;
|
||||
bool analytic;
|
||||
|
||||
analytic = FALSE;
|
||||
analytic = false;
|
||||
for (j = T_A1; j <= T_A6; j++)
|
||||
{
|
||||
if (source_k[j] != 0.0)
|
||||
{
|
||||
analytic = TRUE;
|
||||
analytic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (analytic == TRUE)
|
||||
if (analytic)
|
||||
{
|
||||
target_k[logK_T0] = 0.0;
|
||||
target_k[delta_h] = 0.0;
|
||||
@ -550,27 +550,21 @@ tidy_logk(void)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
struct name_coef *add_logk)
|
||||
add_other_logk(LDBLE * source_k, std::vector<struct name_coef> &add_logk)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i, j, analytic;
|
||||
int j;
|
||||
bool analytic;
|
||||
struct logk *logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
LDBLE coef;
|
||||
ENTRY item, *found_item;
|
||||
|
||||
if (count_add_logk == 0)
|
||||
return (OK);
|
||||
for (i = 0; i < count_add_logk; i++)
|
||||
for (size_t i = 0; i < add_logk.size(); i++)
|
||||
{
|
||||
coef = add_logk[i].coef;
|
||||
strcpy(token, add_logk[i].name);
|
||||
std::string token = add_logk[i].name;
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
if (found_item == NULL)
|
||||
std::map<std::string, struct logk *>::iterator l_it = logk_map.find(token);
|
||||
if (l_it == logk_map.end())
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -579,17 +573,17 @@ add_other_logk(LDBLE * source_k, int count_add_logk,
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
logk_ptr = (struct logk *) found_item->data;
|
||||
analytic = FALSE;
|
||||
logk_ptr = l_it->second;
|
||||
analytic = false;
|
||||
for (j = T_A1; j <= T_A6; j++)
|
||||
{
|
||||
if (logk_ptr->log_k[j] != 0.0)
|
||||
{
|
||||
analytic = TRUE;
|
||||
analytic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (analytic == TRUE)
|
||||
if (analytic)
|
||||
{
|
||||
for (j = T_A1; j <= T_A6; j++)
|
||||
{
|
||||
@ -616,9 +610,7 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
{
|
||||
int i, j;
|
||||
struct logk *next_logk_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
LDBLE coef;
|
||||
ENTRY item, *found_item;
|
||||
/*
|
||||
* Adds in other named_expressions to get complete log K
|
||||
* Evaluates others recursively if necessary
|
||||
@ -631,15 +623,13 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
for (i = 0; i < logk_ptr->count_add_logk; i++)
|
||||
for (i = 0; i < (int)logk_ptr->add_logk.size(); i++)
|
||||
{
|
||||
coef = logk_ptr->add_logk[i].coef;
|
||||
strcpy(token, logk_ptr->add_logk[i].name);
|
||||
std::string token = logk_ptr->add_logk[i].name;
|
||||
str_tolower(token);
|
||||
item.key = token;
|
||||
item.data = NULL;
|
||||
found_item = hsearch_multi(logk_hash_table, item, FIND);
|
||||
if (found_item == NULL)
|
||||
std::map<std::string, struct logk*>::iterator l_it = logk_map.find(token);
|
||||
if (l_it == logk_map.end())
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -648,7 +638,7 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
next_logk_ptr = (struct logk *) found_item->data;
|
||||
next_logk_ptr = l_it->second;
|
||||
if (next_logk_ptr->done == FALSE)
|
||||
{
|
||||
/*output_msg(sformatf( "Done == FALSE\n", token)); */
|
||||
@ -1507,8 +1497,7 @@ tidy_phases(void)
|
||||
for (i = 0; i < (int)phases.size(); i++)
|
||||
{
|
||||
select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk);
|
||||
add_other_logk(phases[i]->rxn->logk, phases[i]->count_add_logk,
|
||||
phases[i]->add_logk);
|
||||
add_other_logk(phases[i]->rxn->logk, phases[i]->add_logk);
|
||||
phases[i]->rxn->token[0].name = phases[i]->name;
|
||||
phases[i]->rxn->token[0].s = NULL;
|
||||
}
|
||||
|
||||
@ -2806,11 +2806,11 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
}
|
||||
cell_data[i + 1].potV = cell_data[i].potV + dVc;
|
||||
}
|
||||
if (!dV_dcell || fix_current)
|
||||
{
|
||||
dVc = current_cells[i].R * (current_x - current_cells[i].dif);
|
||||
cell_data[i + 1].potV = cell_data[i].potV + dVc;
|
||||
}
|
||||
//if (!dV_dcell || fix_current)
|
||||
//{
|
||||
// dVc = current_cells[i].R * (current_x - current_cells[i].dif);
|
||||
// cell_data[i + 1].potV = cell_data[i].potV + dVc;
|
||||
//}
|
||||
|
||||
for (cp = 0; cp < comp; cp++)
|
||||
{
|
||||
|
||||
@ -1187,7 +1187,10 @@ strcmp_nocase(const char *str1, const char *str2)
|
||||
return (-1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void Phreeqc::str_tolower(std::string &name)
|
||||
{
|
||||
std::transform(name.begin(), name.end(), name.begin(), tolower);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
strcmp_nocase_arg1(const char *str1, const char *str2)
|
||||
@ -1233,54 +1236,7 @@ string_duplicate(const char *token)
|
||||
strcpy(str, token);
|
||||
return (str);
|
||||
}
|
||||
#ifdef HASH
|
||||
/* ---------------------------------------------------------------------- */
|
||||
const char * Phreeqc::
|
||||
string_hsave(const char *str)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Save character string str
|
||||
*
|
||||
* Arguments:
|
||||
* str input string to save.
|
||||
*
|
||||
* Returns:
|
||||
* starting address of saved string (str)
|
||||
*/
|
||||
std::hash_map<std::string, std::string *>::const_iterator it;
|
||||
it = strings_hash.find(str);
|
||||
if (it != strings_hash.end())
|
||||
{
|
||||
return (it->second->c_str());
|
||||
}
|
||||
|
||||
std::string *stdstr = new std::string(str);
|
||||
strings_map[*stdstr] = stdstr;
|
||||
return(stdstr->c_str());
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
strings_hash_clear()
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Save character string str
|
||||
*
|
||||
* Arguments:
|
||||
* str input string to save.
|
||||
*
|
||||
* Returns:
|
||||
* starting address of saved string (str)
|
||||
*/
|
||||
std::hash_map<std::string, std::string *>::iterator it;
|
||||
for (it = strings_hash.begin(); it != strings_hash.end(); it++)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
strings_hash.clear();
|
||||
}
|
||||
#else
|
||||
/* ---------------------------------------------------------------------- */
|
||||
const char * Phreeqc::
|
||||
string_hsave(const char *str)
|
||||
@ -1306,7 +1262,6 @@ string_hsave(const char *str)
|
||||
strings_map[*stdstr] = stdstr;
|
||||
return(stdstr->c_str());
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
strings_map_clear()
|
||||
@ -1527,300 +1482,7 @@ status(int count, const char *str, bool rk_string)
|
||||
*/
|
||||
|
||||
/* rewrote to remove MUL and DIV */
|
||||
# define MOD(x,y) ((x) & ((y)-1))
|
||||
|
||||
/*
|
||||
** Local data
|
||||
*/
|
||||
|
||||
#ifdef HASH_STATISTICS
|
||||
long HashAccesses, HashCollisions;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Code
|
||||
*/
|
||||
|
||||
int Phreeqc::
|
||||
hcreate_multi(unsigned Count, HashTable ** HashTable_ptr)
|
||||
{
|
||||
int i;
|
||||
HashTable *Table;
|
||||
/*
|
||||
** Adjust Count to be nearest higher power of 2,
|
||||
** minimum SegmentSize, then convert into segments.
|
||||
*/
|
||||
i = SegmentSize;
|
||||
while (i < (int) Count)
|
||||
i <<= 1;
|
||||
/* Count = DIV(i,SegmentSize); */
|
||||
Count = ((i) >> (SegmentSizeShift));
|
||||
|
||||
Table = (HashTable *) PHRQ_calloc(sizeof(HashTable), 1);
|
||||
*HashTable_ptr = Table;
|
||||
|
||||
if (Table == NULL)
|
||||
return (0);
|
||||
/*
|
||||
** resets are redundant - done by calloc(3)
|
||||
**
|
||||
Table->SegmentCount = Table->p = Table->KeyCount = 0;
|
||||
*/
|
||||
/*
|
||||
** Allocate initial 'i' segments of buckets
|
||||
*/
|
||||
for (i = 0; i < (int) Count; i++)
|
||||
{
|
||||
Table->Directory[i] =
|
||||
(Segment *) PHRQ_calloc(sizeof(Segment), SegmentSize);
|
||||
if (Table->Directory[i] == NULL)
|
||||
{
|
||||
hdestroy_multi(Table);
|
||||
return (0);
|
||||
}
|
||||
Table->SegmentCount++;
|
||||
}
|
||||
/* Table->maxp = MUL(Count,SegmentSize); */
|
||||
Table->maxp = (short) ((Count) << (SegmentSizeShift));
|
||||
Table->MinLoadFactor = 1;
|
||||
Table->MaxLoadFactor = DefaultMaxLoadFactor;
|
||||
#ifdef HASH_STATISTICS
|
||||
HashAccesses = HashCollisions = 0;
|
||||
#endif
|
||||
return (1);
|
||||
}
|
||||
|
||||
void Phreeqc::
|
||||
hdestroy_multi(HashTable * Table)
|
||||
{
|
||||
int i, j;
|
||||
Segment *seg;
|
||||
Element *p, *q;
|
||||
|
||||
if (Table != NULL)
|
||||
{
|
||||
for (i = 0; i < Table->SegmentCount; i++)
|
||||
{
|
||||
/* test probably unnecessary */
|
||||
if ((seg = Table->Directory[i]) != NULL)
|
||||
{
|
||||
for (j = 0; j < SegmentSize; j++)
|
||||
{
|
||||
p = seg[j];
|
||||
while (p != NULL)
|
||||
{
|
||||
q = p->Next;
|
||||
PHRQ_free((void *) p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
PHRQ_free(Table->Directory[i]);
|
||||
}
|
||||
}
|
||||
PHRQ_free(Table);
|
||||
/* Table = NULL; */
|
||||
}
|
||||
}
|
||||
|
||||
ENTRY * Phreeqc::
|
||||
hsearch_multi(HashTable * Table, ENTRY item, ACTION action)
|
||||
/* ACTION FIND/ENTER */
|
||||
{
|
||||
Address h;
|
||||
Segment *CurrentSegment;
|
||||
int SegmentIndex;
|
||||
int SegmentDir;
|
||||
Segment *p, q;
|
||||
|
||||
assert(Table != NULL); /* Kinder really than return(NULL); */
|
||||
#ifdef HASH_STATISTICS
|
||||
HashAccesses++;
|
||||
#endif
|
||||
h = Hash_multi(Table, item.key);
|
||||
/* SegmentDir = DIV(h,SegmentSize); */
|
||||
SegmentDir = ((h) >> (SegmentSizeShift));
|
||||
SegmentIndex = MOD(h, SegmentSize);
|
||||
/*
|
||||
** valid segment ensured by Hash()
|
||||
*/
|
||||
CurrentSegment = Table->Directory[SegmentDir];
|
||||
assert(CurrentSegment != NULL); /* bad failure if tripped */
|
||||
p = &CurrentSegment[SegmentIndex];
|
||||
q = *p;
|
||||
/*
|
||||
** Follow collision chain
|
||||
*/
|
||||
while (q != NULL && strcmp(q->Key, item.key))
|
||||
{
|
||||
p = &q->Next;
|
||||
q = *p;
|
||||
#ifdef HASH_STATISTICS
|
||||
HashCollisions++;
|
||||
#endif
|
||||
}
|
||||
if (q != NULL /* found */
|
||||
|| action == FIND /* not found, search only */
|
||||
)
|
||||
{
|
||||
return ((ENTRY *) q);
|
||||
}
|
||||
else if ((q = (Element *) PHRQ_calloc(sizeof(Element), 1)) == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
}
|
||||
*p = q; /* link into chain */
|
||||
/*
|
||||
** Initialize new element
|
||||
*/
|
||||
q->Key = item.key;
|
||||
q->Data = (char *) item.data;
|
||||
/*
|
||||
** cleared by calloc(3)
|
||||
q->Next = NULL;
|
||||
*/
|
||||
/*
|
||||
** Table over-full?
|
||||
*/
|
||||
/* if (++Table->KeyCount / MUL(Table->SegmentCount,SegmentSize) > Table->MaxLoadFactor) */
|
||||
if (++Table->KeyCount / ((Table->SegmentCount) << (SegmentSizeShift)) >
|
||||
Table->MaxLoadFactor)
|
||||
ExpandTable_multi(Table); /* doesn`t affect q */
|
||||
return ((ENTRY *) q);
|
||||
}
|
||||
|
||||
/*
|
||||
** Internal routines
|
||||
*/
|
||||
|
||||
Address Phreeqc::
|
||||
Hash_multi(HashTable * Table, const char *Key)
|
||||
{
|
||||
Address h, address;
|
||||
unsigned char *k = (unsigned char *) Key;
|
||||
|
||||
h = 0;
|
||||
/*
|
||||
** Convert string to integer
|
||||
*/
|
||||
while (*k)
|
||||
h = h * Prime1 ^ (*k++ - ' ');
|
||||
h %= Prime2;
|
||||
address = MOD(h, Table->maxp);
|
||||
if (address < (unsigned long) Table->p)
|
||||
address = MOD(h, (Table->maxp << 1)); /* h % (2*Table->maxp) */
|
||||
return (address);
|
||||
}
|
||||
|
||||
void Phreeqc::
|
||||
ExpandTable_multi(HashTable * Table)
|
||||
{
|
||||
Address NewAddress;
|
||||
int OldSegmentIndex, NewSegmentIndex;
|
||||
int OldSegmentDir, NewSegmentDir;
|
||||
Segment *OldSegment, *NewSegment;
|
||||
Element *Current, **Previous, **LastOfNew;
|
||||
|
||||
/* if (Table->maxp + Table->p < MUL(DirectorySize,SegmentSize)) */
|
||||
if (Table->maxp + Table->p < ((DirectorySize) << (SegmentSizeShift)))
|
||||
{
|
||||
/*
|
||||
** Locate the bucket to be split
|
||||
*/
|
||||
/* OldSegmentDir = DIV(Table->p,SegmentSize); */
|
||||
OldSegmentDir = ((Table->p) >> (SegmentSizeShift));
|
||||
OldSegment = Table->Directory[OldSegmentDir];
|
||||
OldSegmentIndex = MOD(Table->p, SegmentSize);
|
||||
/*
|
||||
** Expand address space; if necessary create a new segment
|
||||
*/
|
||||
NewAddress = Table->maxp + Table->p;
|
||||
/* NewSegmentDir = DIV(NewAddress,SegmentSize); */
|
||||
NewSegmentDir = ((NewAddress) >> (SegmentSizeShift));
|
||||
NewSegmentIndex = MOD(NewAddress, SegmentSize);
|
||||
if (NewSegmentIndex == 0)
|
||||
{
|
||||
Table->Directory[NewSegmentDir] =
|
||||
(Segment *) PHRQ_calloc(sizeof(Segment), SegmentSize);
|
||||
if (Table->Directory[NewSegmentDir] == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
}
|
||||
}
|
||||
NewSegment = Table->Directory[NewSegmentDir];
|
||||
/*
|
||||
** Adjust state variables
|
||||
*/
|
||||
Table->p++;
|
||||
if (Table->p == Table->maxp)
|
||||
{
|
||||
Table->maxp <<= 1; /* Table->maxp *= 2 */
|
||||
Table->p = 0;
|
||||
}
|
||||
Table->SegmentCount++;
|
||||
/*
|
||||
** Relocate records to the new bucket
|
||||
*/
|
||||
Previous = &OldSegment[OldSegmentIndex];
|
||||
Current = *Previous;
|
||||
LastOfNew = &NewSegment[NewSegmentIndex];
|
||||
*LastOfNew = NULL;
|
||||
while (Current != NULL)
|
||||
{
|
||||
if (Hash_multi(Table, Current->Key) == NewAddress)
|
||||
{
|
||||
/*
|
||||
** Attach it to the end of the new chain
|
||||
*/
|
||||
*LastOfNew = Current;
|
||||
/*
|
||||
** Remove it from old chain
|
||||
*/
|
||||
*Previous = Current->Next;
|
||||
LastOfNew = &Current->Next;
|
||||
Current = Current->Next;
|
||||
*LastOfNew = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
** leave it on the old chain
|
||||
*/
|
||||
Previous = &Current->Next;
|
||||
Current = Current->Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Phreeqc::
|
||||
free_hash_strings(HashTable * Table)
|
||||
{
|
||||
int i, j;
|
||||
Segment *seg;
|
||||
Element *p, *q;
|
||||
|
||||
if (Table != NULL)
|
||||
{
|
||||
for (i = 0; i < Table->SegmentCount; i++)
|
||||
{
|
||||
/* test probably unnecessary */
|
||||
if ((seg = Table->Directory[i]) != NULL)
|
||||
{
|
||||
for (j = 0; j < SegmentSize; j++)
|
||||
{
|
||||
p = seg[j];
|
||||
while (p != NULL)
|
||||
{
|
||||
q = p->Next;
|
||||
p->Data = (char *) free_check_null((void *) p->Data);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//# define MOD(x,y) ((x) & ((y)-1))
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user