mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 08:38:23 +01:00
Squashed 'src/' changes from 6e248c34..81f180a0
81f180a0 Fixed bugs in inverse 6d575967 strcpy_safe and strcat_safe 6d98c4e1 trying different header files 72796f15 added <cstring> e8481607 warnings, strcat, strcpy 988bdee0 Try using goto(s) 9b10ce3f Try updated logical expression 812061be Turn off optimizing on k_temp git-subtree-dir: src git-subtree-split: 81f180a069285bcb4d180c860664b4b2a193854d
This commit is contained in:
parent
10bcb271d7
commit
1b2eb6ca0d
2
Var.c
2
Var.c
@ -74,7 +74,7 @@ char* VarAllocString(const char* pSrc)
|
|||||||
char* psz;
|
char* psz;
|
||||||
if (!pSrc) return NULL;
|
if (!pSrc) return NULL;
|
||||||
psz = (char*) malloc(strlen(pSrc) + 1);
|
psz = (char*) malloc(strlen(pSrc) + 1);
|
||||||
strcpy(psz, pSrc);
|
if(psz != NULL) strcpy(psz, pSrc);
|
||||||
return psz;
|
return psz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -406,7 +406,7 @@ cxxNameDouble::add(const char *token, LDBLE total)
|
|||||||
//
|
//
|
||||||
{
|
{
|
||||||
char key[MAX_LENGTH];
|
char key[MAX_LENGTH];
|
||||||
strcpy(key, token);
|
Utilities::strcpy_safe(key, MAX_LENGTH, token);
|
||||||
|
|
||||||
cxxNameDouble::iterator current = (*this).find(key);
|
cxxNameDouble::iterator current = (*this).find(key);
|
||||||
if (current != (*this).end())
|
if (current != (*this).end())
|
||||||
|
|||||||
@ -550,7 +550,8 @@ numtostr(char * Result, LDBLE n)
|
|||||||
l_s[i] = '\0';
|
l_s[i] = '\0';
|
||||||
* p2c: basic.p, line 248:
|
* p2c: basic.p, line 248:
|
||||||
* Note: Modification of string length may translate incorrectly [146] *
|
* Note: Modification of string length may translate incorrectly [146] *
|
||||||
return strcpy(Result, strltrim(l_s));
|
Utilities::strcpy_safe(Result, MAX_LENGTH, strltrim(l_s));
|
||||||
|
return Result;
|
||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1746,16 +1747,16 @@ void PBasic::
|
|||||||
snerr(const char * l_s)
|
snerr(const char * l_s)
|
||||||
{
|
{
|
||||||
char str[MAX_LENGTH] = {0};
|
char str[MAX_LENGTH] = {0};
|
||||||
strcpy(str, "Syntax_error ");
|
Utilities::strcpy_safe(str, MAX_LENGTH, "Syntax_error ");
|
||||||
if (phreeqci_gui)
|
if (phreeqci_gui)
|
||||||
{
|
{
|
||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_SYNTAX;
|
nIDErrPrompt = IDS_ERR_SYNTAX;
|
||||||
}
|
}
|
||||||
strcat(str, l_s);
|
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
|
||||||
strcat(str, " in line: ");
|
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat(str, inbuf);
|
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
|
||||||
errormsg(str);
|
errormsg(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1763,16 +1764,16 @@ void PBasic::
|
|||||||
tmerr(const char * l_s)
|
tmerr(const char * l_s)
|
||||||
{
|
{
|
||||||
char str[MAX_LENGTH] = {0};
|
char str[MAX_LENGTH] = {0};
|
||||||
strcpy(str, "Type mismatch error");
|
Utilities::strcpy_safe(str, MAX_LENGTH, "Type mismatch error");
|
||||||
if (phreeqci_gui)
|
if (phreeqci_gui)
|
||||||
{
|
{
|
||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_MISMATCH;
|
nIDErrPrompt = IDS_ERR_MISMATCH;
|
||||||
}
|
}
|
||||||
strcat(str, l_s);
|
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
|
||||||
strcat(str, " in line: ");
|
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat(str, inbuf);
|
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
|
||||||
errormsg(str);
|
errormsg(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1901,8 +1902,9 @@ require(int k, struct LOC_exec *LINK)
|
|||||||
if (item == command_tokens.end())
|
if (item == command_tokens.end())
|
||||||
snerr(": missing unknown command");
|
snerr(": missing unknown command");
|
||||||
else {
|
else {
|
||||||
strcpy(str, ": missing ");
|
Utilities::strcpy_safe(str, MAX_LENGTH, ": missing ");
|
||||||
snerr(strcat(str, item->first.c_str()));
|
Utilities::strcat_safe(str, MAX_LENGTH, item->first.c_str());
|
||||||
|
snerr(str);
|
||||||
}
|
}
|
||||||
#if !defined(R_SO)
|
#if !defined(R_SO)
|
||||||
exit(4);
|
exit(4);
|
||||||
@ -2544,7 +2546,7 @@ factor(struct LOC_exec * LINK)
|
|||||||
size_t l = elt_name.size();
|
size_t l = elt_name.size();
|
||||||
l = l < 256 ? 256 : l + 1;
|
l = l < 256 ? 256 : l + 1;
|
||||||
char* token = (char*)PhreeqcPtr->PHRQ_malloc(l * sizeof(char));
|
char* token = (char*)PhreeqcPtr->PHRQ_malloc(l * sizeof(char));
|
||||||
strcpy(token, elt_name.c_str());
|
Utilities::strcpy_safe(token, l, elt_name.c_str());
|
||||||
*elt_varrec->UU.U1.sval = token;
|
*elt_varrec->UU.U1.sval = token;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -6240,9 +6242,9 @@ exec(void)
|
|||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_ILLEGAL;
|
nIDErrPrompt = IDS_ERR_ILLEGAL;
|
||||||
}
|
}
|
||||||
strcat(STR1, "Illegal command in line: ");
|
Utilities::strcat_safe(STR1, MAX_LENGTH, "Illegal command in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat(STR1, inbuf);
|
Utilities::strcat_safe(STR1, MAX_LENGTH, inbuf);
|
||||||
errormsg(STR1);
|
errormsg(STR1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -6392,7 +6394,7 @@ cmdplot_xy(struct LOC_exec *LINK)
|
|||||||
n[i] = expr(LINK);
|
n[i] = expr(LINK);
|
||||||
if (n[i].stringval)
|
if (n[i].stringval)
|
||||||
{
|
{
|
||||||
strcpy(STR[i], n[i].UU.sval);
|
Utilities::strcpy_safe(STR[i], MAX_LENGTH, n[i].UU.sval);
|
||||||
PhreeqcPtr->PHRQ_free(n[i].UU.sval);
|
PhreeqcPtr->PHRQ_free(n[i].UU.sval);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "PBasic.h"
|
#include "PBasic.h"
|
||||||
#include "Temperature.h"
|
#include "Temperature.h"
|
||||||
#include "SSassemblage.h"
|
#include "SSassemblage.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -173,7 +174,7 @@ size_t Phreeqc::list_components(std::list<std::string> &list_c)
|
|||||||
{
|
{
|
||||||
if (it->first == "Charge") continue;
|
if (it->first == "Charge") continue;
|
||||||
char string[MAX_LENGTH];
|
char string[MAX_LENGTH];
|
||||||
strcpy(string, it->first.c_str());
|
Utilities::strcpy_safe(string, MAX_LENGTH, it->first.c_str());
|
||||||
class master *master_ptr = master_bsearch_primary(string);
|
class master *master_ptr = master_bsearch_primary(string);
|
||||||
if (master_ptr == NULL) continue;
|
if (master_ptr == NULL) continue;
|
||||||
if (master_ptr->type != AQ) continue;
|
if (master_ptr->type != AQ) continue;
|
||||||
|
|||||||
@ -1036,7 +1036,6 @@ public:
|
|||||||
int get_token(const char** eqnaddr, std::string& string, LDBLE* z, int* l);
|
int get_token(const char** eqnaddr, std::string& string, LDBLE* z, int* l);
|
||||||
int islegit(const char c);
|
int islegit(const char c);
|
||||||
void malloc_error(void);
|
void malloc_error(void);
|
||||||
int parse_couple(char* token);
|
|
||||||
int print_centered(const char* string);
|
int print_centered(const char* string);
|
||||||
static int replace(const char* str1, const char* str2, char* str);
|
static int replace(const char* str1, const char* str2, char* str);
|
||||||
static void replace(std::string &stds, const char* str1, const char* str2);
|
static void replace(std::string &stds, const char* str1, const char* str2);
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include "cxxMix.h"
|
#include "cxxMix.h"
|
||||||
#include "Reaction.h"
|
#include "Reaction.h"
|
||||||
#include "Temperature.h"
|
#include "Temperature.h"
|
||||||
|
#include "Utils.h"
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
@ -66,11 +66,11 @@ cxxSystem::totalize(Phreeqc * phreeqc_ptr)
|
|||||||
if (this->solution != NULL)
|
if (this->solution != NULL)
|
||||||
{
|
{
|
||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
strcpy(token, "O");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "O");
|
||||||
this->totals[token] = this->solution->Get_total_o();
|
this->totals[token] = this->solution->Get_total_o();
|
||||||
strcpy(token, "H");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "H");
|
||||||
this->totals[token] = this->solution->Get_total_h();
|
this->totals[token] = this->solution->Get_total_h();
|
||||||
strcpy(token, "Charge");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "Charge");
|
||||||
this->totals[token] = this->solution->Get_cb();
|
this->totals[token] = this->solution->Get_cb();
|
||||||
this->totals.add_extensive(this->solution->Get_totals(), 1.0);
|
this->totals.add_extensive(this->solution->Get_totals(), 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -705,7 +705,7 @@ calc_logk_n(const char* name)
|
|||||||
{
|
{
|
||||||
l_logk[i] = 0.0;
|
l_logk[i] = 0.0;
|
||||||
}
|
}
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
logk_ptr = logk_search(token);
|
logk_ptr = logk_search(token);
|
||||||
if (logk_ptr != NULL)
|
if (logk_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -730,7 +730,7 @@ calc_logk_p(const char* name)
|
|||||||
LDBLE lk = -999.9;
|
LDBLE lk = -999.9;
|
||||||
LDBLE l_logk[MAX_LOG_K_INDICES];
|
LDBLE l_logk[MAX_LOG_K_INDICES];
|
||||||
|
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
phase_ptr = phase_bsearch(token, &j, FALSE);
|
phase_ptr = phase_bsearch(token, &j, FALSE);
|
||||||
|
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
@ -769,7 +769,7 @@ calc_logk_s(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
LDBLE lk, l_logk[MAX_LOG_K_INDICES];
|
LDBLE lk, l_logk[MAX_LOG_K_INDICES];
|
||||||
|
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -797,7 +797,7 @@ dh_a0(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
double a = -999.99;
|
double a = -999.99;
|
||||||
|
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -819,7 +819,7 @@ dh_bdot(const char* name)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -839,7 +839,7 @@ calc_deltah_p(const char* name)
|
|||||||
LDBLE lkm, lkp;
|
LDBLE lkm, lkp;
|
||||||
LDBLE l_logk[MAX_LOG_K_INDICES];
|
LDBLE l_logk[MAX_LOG_K_INDICES];
|
||||||
double dh = -999.99;
|
double dh = -999.99;
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
phase_ptr = phase_bsearch(token, &j, FALSE);
|
phase_ptr = phase_bsearch(token, &j, FALSE);
|
||||||
|
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
@ -879,7 +879,7 @@ calc_deltah_s(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
LDBLE lkm, lkp, l_logk[MAX_LOG_K_INDICES];
|
LDBLE lkm, lkp, l_logk[MAX_LOG_K_INDICES];
|
||||||
double dh = -999.99;
|
double dh = -999.99;
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -929,7 +929,7 @@ calc_surface_charge(const char* surface_name)
|
|||||||
if (token_ptr->s->type != SURF)
|
if (token_ptr->s->type != SURF)
|
||||||
continue;
|
continue;
|
||||||
master_ptr = trxn.token[i].s->primary;
|
master_ptr = trxn.token[i].s->primary;
|
||||||
strcpy(token, master_ptr->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master_ptr->elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(token1, &cptr, &j);
|
copy_token(token1, &cptr, &j);
|
||||||
@ -1237,7 +1237,7 @@ calc_t_sc(const char* name)
|
|||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
|
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL && s_ptr->in)
|
if (s_ptr != NULL && s_ptr->in)
|
||||||
{
|
{
|
||||||
@ -1262,7 +1262,7 @@ calc_f_visc(const char* name)
|
|||||||
|
|
||||||
if (print_viscosity)
|
if (print_viscosity)
|
||||||
{
|
{
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL && s_ptr->in)
|
if (s_ptr != NULL && s_ptr->in)
|
||||||
return s_ptr->dw_t_visc;
|
return s_ptr->dw_t_visc;
|
||||||
@ -2111,7 +2111,7 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH];
|
char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH];
|
||||||
char str[2];
|
char str[2];
|
||||||
|
|
||||||
strcpy(token, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
squeeze_white(token);
|
squeeze_white(token);
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
if (strstr("token", "++") != NULL)
|
if (strstr("token", "++") != NULL)
|
||||||
@ -2168,7 +2168,7 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
/*
|
/*
|
||||||
* Replace elements with first of equivalent elements
|
* Replace elements with first of equivalent elements
|
||||||
*/
|
*/
|
||||||
strcpy(template1, mytemplate);
|
Utilities::strcpy_safe(template1, MAX_LENGTH, mytemplate);
|
||||||
squeeze_white(template1);
|
squeeze_white(template1);
|
||||||
cptr = template1;
|
cptr = template1;
|
||||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||||
@ -2229,22 +2229,22 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
token[0] = '\0';
|
token[0] = '\0';
|
||||||
for (i = 0; i < count_match_tokens; i++)
|
for (i = 0; i < count_match_tokens; i++)
|
||||||
{
|
{
|
||||||
strcat(token, match_vector[i].first.c_str());
|
Utilities::strcat_safe(token, MAX_LENGTH, match_vector[i].first.c_str());
|
||||||
if (match_vector[i].second != 1.0)
|
if (match_vector[i].second != 1.0)
|
||||||
{
|
{
|
||||||
snprintf(token1, sizeof(token1), "%g", (double)match_vector[i].second);
|
snprintf(token1, sizeof(token1), "%g", (double)match_vector[i].second);
|
||||||
strcat(token, token1);
|
Utilities::strcat_safe(token, MAX_LENGTH, token1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Write a template name using first of equivalent elements
|
* Write a template name using first of equivalent elements
|
||||||
*/
|
*/
|
||||||
strcpy(template1, mytemplate);
|
Utilities::strcpy_safe(template1, MAX_LENGTH, mytemplate);
|
||||||
squeeze_white(template1);
|
squeeze_white(template1);
|
||||||
cptr = template1;
|
cptr = template1;
|
||||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||||
{
|
{
|
||||||
strcpy(equal_list1, equal_list);
|
Utilities::strcpy_safe(equal_list1, MAX_LENGTH, equal_list);
|
||||||
replace("{", "", equal_list);
|
replace("{", "", equal_list);
|
||||||
replace("}", "", equal_list);
|
replace("}", "", equal_list);
|
||||||
while (replace(",", " ", equal_list) == TRUE);
|
while (replace(",", " ", equal_list) == TRUE);
|
||||||
@ -2410,10 +2410,6 @@ surf_total(const char* total_name, const char* surface_name)
|
|||||||
{
|
{
|
||||||
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
||||||
|
|
||||||
//strcpy(token, s_x[j]->next_elt[i].elt->name);
|
|
||||||
//replace("_", " ", token);
|
|
||||||
//cptr = token;
|
|
||||||
//copy_token(name, &cptr, &k);
|
|
||||||
token = s_x[j]->next_elt[i].elt->name;
|
token = s_x[j]->next_elt[i].elt->name;
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
std::string::iterator b = token.begin();
|
std::string::iterator b = token.begin();
|
||||||
@ -2512,7 +2508,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
{
|
{
|
||||||
if (x[j]->type != SURFACE)
|
if (x[j]->type != SURFACE)
|
||||||
continue;
|
continue;
|
||||||
strcpy(token, x[j]->master[0]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, x[j]->master[0]->elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(name, &cptr, &k);
|
copy_token(name, &cptr, &k);
|
||||||
@ -2528,7 +2524,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
}
|
}
|
||||||
if (j >= count_unknowns)
|
if (j >= count_unknowns)
|
||||||
return (0);
|
return (0);
|
||||||
strcpy(surface_name_local, name);
|
Utilities::strcpy_safe(surface_name_local, MAX_LENGTH, name);
|
||||||
/*
|
/*
|
||||||
* find total moles of each element in diffuse layer...
|
* find total moles of each element in diffuse layer...
|
||||||
*/
|
*/
|
||||||
@ -2542,7 +2538,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
{
|
{
|
||||||
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
||||||
|
|
||||||
strcpy(token, s_x[j]->next_elt[i].elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, s_x[j]->next_elt[i].elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(name, &cptr, &k);
|
copy_token(name, &cptr, &k);
|
||||||
@ -2792,7 +2788,7 @@ edl_species(const char* surf_name, LDBLE * count, char*** names, LDBLE * *moles,
|
|||||||
if (names == NULL)
|
if (names == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
*moles = (LDBLE*)PHRQ_malloc((sys.size() + 1) * sizeof(LDBLE));
|
*moles = (LDBLE*)PHRQ_malloc((sys.size() + 1) * sizeof(LDBLE));
|
||||||
if (moles == NULL)
|
if (*moles == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
|
|
||||||
(*names)[0] = NULL;
|
(*names)[0] = NULL;
|
||||||
@ -2886,13 +2882,13 @@ system_total(const char* total_name, LDBLE * count, char*** names,
|
|||||||
*/
|
*/
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
*names = (char**)PHRQ_malloc((count_sys + 1) * sizeof(char*));
|
*names = (char**)PHRQ_malloc((count_sys + 1) * sizeof(char*));
|
||||||
if (names == NULL)
|
if (*names == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
*types = (char**)PHRQ_malloc((count_sys + 1) * sizeof(char*));
|
*types = (char**)PHRQ_malloc((count_sys + 1) * sizeof(char*));
|
||||||
if (types == NULL)
|
if (*types == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
*moles = (LDBLE*)PHRQ_malloc((count_sys + 1) * sizeof(LDBLE));
|
*moles = (LDBLE*)PHRQ_malloc((count_sys + 1) * sizeof(LDBLE));
|
||||||
if (moles == NULL)
|
if (*moles == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
|
|
||||||
(*names)[0] = NULL;
|
(*names)[0] = NULL;
|
||||||
@ -3126,7 +3122,7 @@ system_total_elements(void)
|
|||||||
{
|
{
|
||||||
t = master_ptr->total;
|
t = master_ptr->total;
|
||||||
}
|
}
|
||||||
strcpy(name, master[i]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, master[i]->elt->name);
|
||||||
count_sys = sys.size();
|
count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
@ -3173,7 +3169,7 @@ system_total_si(void)
|
|||||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||||
}
|
}
|
||||||
si = -phases[i]->lk + iap;
|
si = -phases[i]->lk + iap;
|
||||||
strcpy(name, phases[i]->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, phases[i]->name);
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
@ -3491,7 +3487,7 @@ system_total_elt(const char* total_name)
|
|||||||
{
|
{
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
strcpy(name, x[k]->master[0]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
||||||
replace("_psi", "", name);
|
replace("_psi", "", name);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
sys[count_sys].moles = elt_list[j].coef;
|
sys[count_sys].moles = elt_list[j].coef;
|
||||||
@ -3736,7 +3732,7 @@ system_total_elt_secondary(const char* total_name)
|
|||||||
}
|
}
|
||||||
if (l >= count_elts)
|
if (l >= count_elts)
|
||||||
continue;
|
continue;
|
||||||
strcpy(name, x[k]->master[0]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
||||||
replace("_psi", "", name);
|
replace("_psi", "", name);
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
@ -4051,8 +4047,8 @@ iso_value(const char* total_name)
|
|||||||
int j;
|
int j;
|
||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
char my_total_name[MAX_LENGTH];
|
char my_total_name[MAX_LENGTH];
|
||||||
strcpy(token, "");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "");
|
||||||
strcpy(my_total_name, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace(" ", "_", my_total_name));
|
while (replace(" ", "_", my_total_name));
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
@ -4062,12 +4058,12 @@ iso_value(const char* total_name)
|
|||||||
continue;
|
continue;
|
||||||
return (isotope_ratio[j]->converted_ratio);
|
return (isotope_ratio[j]->converted_ratio);
|
||||||
}
|
}
|
||||||
strcpy(my_total_name, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace("[", "", my_total_name));
|
while (replace("[", "", my_total_name));
|
||||||
while (replace("]", "", my_total_name));
|
while (replace("]", "", my_total_name));
|
||||||
strcat(token, "R(");
|
Utilities::strcat_safe(token, MAX_LENGTH, "R(");
|
||||||
strcat(token, my_total_name);
|
Utilities::strcat_safe(token, MAX_LENGTH, my_total_name);
|
||||||
strcat(token, ")");
|
Utilities::strcat_safe(token, MAX_LENGTH, ")");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4086,10 +4082,10 @@ iso_unit(const char* total_name)
|
|||||||
char token[MAX_LENGTH], unit[MAX_LENGTH];
|
char token[MAX_LENGTH], unit[MAX_LENGTH];
|
||||||
class master_isotope* master_isotope_ptr;
|
class master_isotope* master_isotope_ptr;
|
||||||
char my_total_name[MAX_LENGTH];
|
char my_total_name[MAX_LENGTH];
|
||||||
strcpy(token, "");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "");
|
||||||
strcpy(my_total_name, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace(" ", "_", my_total_name));
|
while (replace(" ", "_", my_total_name));
|
||||||
strcpy(unit, "unknown");
|
Utilities::strcpy_safe(unit, MAX_LENGTH, "unknown");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4099,16 +4095,16 @@ iso_unit(const char* total_name)
|
|||||||
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
||||||
if (master_isotope_ptr != NULL)
|
if (master_isotope_ptr != NULL)
|
||||||
{
|
{
|
||||||
strcpy(unit, master_isotope_ptr->units);
|
Utilities::strcpy_safe(unit, MAX_LENGTH, master_isotope_ptr->units);
|
||||||
}
|
}
|
||||||
return string_duplicate(unit);
|
return string_duplicate(unit);
|
||||||
}
|
}
|
||||||
strcpy(my_total_name, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace("[", "", my_total_name));
|
while (replace("[", "", my_total_name));
|
||||||
while (replace("]", "", my_total_name));
|
while (replace("]", "", my_total_name));
|
||||||
strcat(token, "R(");
|
Utilities::strcat_safe(token, MAX_LENGTH, "R(");
|
||||||
strcat(token, my_total_name);
|
Utilities::strcat_safe(token, MAX_LENGTH, my_total_name);
|
||||||
strcat(token, ")");
|
Utilities::strcat_safe(token, MAX_LENGTH, ")");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4118,7 +4114,7 @@ iso_unit(const char* total_name)
|
|||||||
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
||||||
if (master_isotope_ptr != NULL)
|
if (master_isotope_ptr != NULL)
|
||||||
{
|
{
|
||||||
strcpy(unit, master_isotope_ptr->units);
|
Utilities::strcpy_safe(unit, MAX_LENGTH, master_isotope_ptr->units);
|
||||||
}
|
}
|
||||||
return string_duplicate(unit);
|
return string_duplicate(unit);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,6 +181,57 @@ Utilities::safe_exp(LDBLE t)
|
|||||||
}
|
}
|
||||||
return exp(t);
|
return exp(t);
|
||||||
}
|
}
|
||||||
|
size_t Utilities::
|
||||||
|
strcpy_safe(char* dest, size_t max, const char* src)
|
||||||
|
{
|
||||||
|
size_t lsrc = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dest == nullptr || src == nullptr)
|
||||||
|
{
|
||||||
|
std::cerr << "nullptr in Utilities::strcpy_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
lsrc = strlen(src);
|
||||||
|
if (lsrc + 1 > max)
|
||||||
|
{
|
||||||
|
std::cerr << "Buffer overrun in Utilities::strcpy_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
memcpy(dest, src, (lsrc + 1) * sizeof(char));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return lsrc;
|
||||||
|
}
|
||||||
|
size_t Utilities::
|
||||||
|
strcat_safe(char* dest, size_t max, const char* src)
|
||||||
|
{
|
||||||
|
size_t ldest = 0, lsrc = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dest == nullptr || src == nullptr)
|
||||||
|
{
|
||||||
|
std::cerr << "nullptr in Utilities::strcat_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
lsrc = strlen(src);
|
||||||
|
ldest = strlen(dest);
|
||||||
|
if (ldest + lsrc + 1 > max)
|
||||||
|
{
|
||||||
|
std::cerr << "Buffer overrun in Utilities::strcat_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
memcpy(&dest[ldest], src, (lsrc + 1) * sizeof(char));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ldest + lsrc;
|
||||||
|
}
|
||||||
//+NAN LDBLE: 7ff8000000000000
|
//+NAN LDBLE: 7ff8000000000000
|
||||||
//-NAN LDBLE: fff8000000000000
|
//-NAN LDBLE: fff8000000000000
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -20,7 +20,8 @@ namespace Utilities
|
|||||||
void str_toupper(std::string & str);
|
void str_toupper(std::string & str);
|
||||||
std::string pad_right(const std::string & str, size_t l);
|
std::string pad_right(const std::string & str, size_t l);
|
||||||
bool replace(const char *str1, const char *str2, std::string & str);
|
bool replace(const char *str1, const char *str2, std::string & str);
|
||||||
|
size_t strcat_safe(char* dest, size_t max, const char* src);
|
||||||
|
size_t strcpy_safe(char* dest, size_t max, const char* src);
|
||||||
void squeeze_white(std::string & s_l);
|
void squeeze_white(std::string & s_l);
|
||||||
double convert_time(double t, std::string in, std::string out);
|
double convert_time(double t, std::string in, std::string out);
|
||||||
LDBLE safe_exp(LDBLE t);
|
LDBLE safe_exp(LDBLE t);
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "phqalloc.h"
|
#include "phqalloc.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -124,7 +127,7 @@ get_line(void)
|
|||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
}
|
}
|
||||||
strcpy(line, phrq_io->Get_m_line().c_str());
|
Utilities::strcpy_safe(line, max_line, phrq_io->Get_m_line().c_str());
|
||||||
strcpy(line_save, phrq_io->Get_m_line_save().c_str());
|
Utilities::strcpy_safe(line_save, max_line, phrq_io->Get_m_line_save().c_str());
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ inverse_models(void)
|
|||||||
* for any marked "new".
|
* for any marked "new".
|
||||||
*/
|
*/
|
||||||
int n/*, print1*/;
|
int n/*, print1*/;
|
||||||
char string[MAX_LENGTH];
|
char string[MAX_LENGTH] = "";
|
||||||
if (count_inverse <= 0) return OK;
|
if (count_inverse <= 0) return OK;
|
||||||
// Revert to previous headings after inverse modeling
|
// Revert to previous headings after inverse modeling
|
||||||
std::vector<std::string> old_headings;
|
std::vector<std::string> old_headings;
|
||||||
@ -54,10 +54,10 @@ inverse_models(void)
|
|||||||
*/
|
*/
|
||||||
if (inverse[n].pat != NULL)
|
if (inverse[n].pat != NULL)
|
||||||
{
|
{
|
||||||
strcpy(string, inverse[n].pat);
|
Utilities::strcpy_safe(string, MAX_LENGTH, inverse[n].pat);
|
||||||
if (replace(".pat", ".pat", string) != TRUE)
|
if (replace(".pat", ".pat", string) != TRUE)
|
||||||
{
|
{
|
||||||
strcat(string, ".pat");
|
Utilities::strcat_safe(string, MAX_LENGTH, ".pat");
|
||||||
}
|
}
|
||||||
netpath_file = fopen(string, "w");
|
netpath_file = fopen(string, "w");
|
||||||
if (netpath_file == NULL)
|
if (netpath_file == NULL)
|
||||||
@ -4174,11 +4174,11 @@ print_total_multi(FILE * l_netpath_file, cxxSolution *solution_ptr,
|
|||||||
LDBLE sum;
|
LDBLE sum;
|
||||||
int i, found;
|
int i, found;
|
||||||
|
|
||||||
strcpy(elts[0], elt0);
|
Utilities::strcpy_safe(elts[0], MAX_LENGTH, elt0);
|
||||||
strcpy(elts[1], elt1);
|
Utilities::strcpy_safe(elts[1], MAX_LENGTH, elt1);
|
||||||
strcpy(elts[2], elt2);
|
Utilities::strcpy_safe(elts[2], MAX_LENGTH, elt2);
|
||||||
strcpy(elts[3], elt3);
|
Utilities::strcpy_safe(elts[3], MAX_LENGTH, elt3);
|
||||||
strcpy(elts[4], elt4);
|
Utilities::strcpy_safe(elts[4], MAX_LENGTH, elt4);
|
||||||
|
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "Phreeqc.h"
|
#include "Phreeqc.h"
|
||||||
#include "phqalloc.h"
|
#include "phqalloc.h"
|
||||||
#include "Solution.h"
|
#include "Solution.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -982,7 +983,7 @@ print_isotope_ratios(void)
|
|||||||
/*
|
/*
|
||||||
* Print isotope ratio
|
* Print isotope ratio
|
||||||
*/
|
*/
|
||||||
strcpy(token, isotope_ratio[j]->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, isotope_ratio[j]->name);
|
||||||
while (replace("_", " ", token) == TRUE);
|
while (replace("_", " ", token) == TRUE);
|
||||||
output_msg(sformatf( " %-20s\t%12.5e\t%15.5g %-10s\n",
|
output_msg(sformatf( " %-20s\t%12.5e\t%15.5g %-10s\n",
|
||||||
token, (double) isotope_ratio[j]->ratio,
|
token, (double) isotope_ratio[j]->ratio,
|
||||||
@ -1045,7 +1046,7 @@ print_isotope_alphas(void)
|
|||||||
/*
|
/*
|
||||||
* Print isotope ratio
|
* Print isotope ratio
|
||||||
*/
|
*/
|
||||||
strcpy(token, isotope_alpha[j]->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, isotope_alpha[j]->name);
|
||||||
while (replace("_", " ", token) == TRUE);
|
while (replace("_", " ", token) == TRUE);
|
||||||
if (isotope_alpha[j]->named_logk != NULL)
|
if (isotope_alpha[j]->named_logk != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -884,7 +884,6 @@ int Phreeqc::gammas_a_f(int i1)
|
|||||||
{
|
{
|
||||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||||
{
|
{
|
||||||
//strcpy(name, s_x[i]->rxn_x.token[j].s->name);
|
|
||||||
name = s_x[i]->rxn_x.token[j].s->name;
|
name = s_x[i]->rxn_x.token[j].s->name;
|
||||||
//m_ptr = s_x[i]->rxn_x.token[j].s->primary->elt->master; // appt debug
|
//m_ptr = s_x[i]->rxn_x.token[j].s->primary->elt->master; // appt debug
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -67,6 +67,7 @@
|
|||||||
#include "nvector_serial.h"
|
#include "nvector_serial.h"
|
||||||
#include "sundialstypes.h"
|
#include "sundialstypes.h"
|
||||||
#include "sundialsmath.h"
|
#include "sundialsmath.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
/* WARNING don`t include any headers below here */
|
/* WARNING don`t include any headers below here */
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ M_EnvInit_Serial(integertype vec_length)
|
|||||||
me->ops->nvprint = N_VPrint_Serial;
|
me->ops->nvprint = N_VPrint_Serial;
|
||||||
|
|
||||||
/* Attach ID tag */
|
/* Attach ID tag */
|
||||||
strcpy(me->tag, ID_TAG_S);
|
Utilities::strcpy_safe(me->tag, 8, ID_TAG_S);
|
||||||
|
|
||||||
return (me);
|
return (me);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "Phreeqc.h"
|
#include "Phreeqc.h"
|
||||||
#include "phqalloc.h"
|
#include "phqalloc.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -133,7 +134,7 @@ parse_eq(char* eqn, std::vector<class elt_list>& new_elt_list, int association)
|
|||||||
* Get elements in species or mineral formula
|
* Get elements in species or mineral formula
|
||||||
*/
|
*/
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
strcpy(token, trxn.token[0].name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, trxn.token[0].name);
|
||||||
replace("(s)", "", token);
|
replace("(s)", "", token);
|
||||||
replace("(S)", "", token);
|
replace("(S)", "", token);
|
||||||
replace("(g)", "", token);
|
replace("(g)", "", token);
|
||||||
|
|||||||
@ -5413,9 +5413,16 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */
|
|||||||
* Calculates log k's for all species and pure_phases
|
* Calculates log k's for all species and pure_phases
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (tc == current_tc && pa == current_pa && ((fabs(mu_x - current_mu) < 1e-3 * mu_x) || !mu_terms_in_logk))
|
// if (tc == current_tc && pa == current_pa && ((fabs(mu_x - current_mu) < 1e-3 * mu_x) || !mu_terms_in_logk))
|
||||||
|
// return OK;
|
||||||
|
if (tc != current_tc) goto proceed;
|
||||||
|
if (pa != current_pa) goto proceed;
|
||||||
|
if (fabs(mu_x - current_mu) > 1e-3 * mu_x) goto proceed;
|
||||||
|
if (mu_terms_in_logk) goto proceed;
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
proceed:
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
LDBLE tempk = tc + 273.15;
|
LDBLE tempk = tc + 273.15;
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -321,7 +321,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr)
|
|||||||
add_elt_list(s_x[j]->next_elt, moles_surface);
|
add_elt_list(s_x[j]->next_elt, moles_surface);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
strcpy(token, s_h2o->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, s_h2o->name);
|
||||||
ptr = &(token[0]);
|
ptr = &(token[0]);
|
||||||
get_elts_in_species (&ptr, mass_water_surface / gfw_water);
|
get_elts_in_species (&ptr, mass_water_surface / gfw_water);
|
||||||
*/
|
*/
|
||||||
@ -427,9 +427,9 @@ print_eh(void)
|
|||||||
/*
|
/*
|
||||||
* Print result
|
* Print result
|
||||||
*/
|
*/
|
||||||
strcpy(token, master[i]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master[i]->elt->name);
|
||||||
strcat(token, "/");
|
Utilities::strcat_safe(token, MAX_LENGTH, "/");
|
||||||
strcat(token, master[k]->elt->name);
|
Utilities::strcat_safe(token, MAX_LENGTH, master[k]->elt->name);
|
||||||
output_msg(sformatf("\t%-15s%12.4f%12.4f\n", token,
|
output_msg(sformatf("\t%-15s%12.4f%12.4f\n", token,
|
||||||
(double) pe, (double) eh));
|
(double) pe, (double) eh));
|
||||||
}
|
}
|
||||||
@ -2904,34 +2904,34 @@ punch_identifiers(void)
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(token, "init");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "init");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
strcpy(token, "i_soln");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_soln");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
strcpy(token, "i_exch");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_exch");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
strcpy(token, "i_surf");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_surf");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
strcpy(token, "i_gas");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_gas");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
strcpy(token, "react");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "react");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
strcpy(token, "inverse");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "inverse");
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
strcpy(token, "advect");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "advect");
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
strcpy(token, "transp");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "transp");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strcpy(token, "unknown");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "unknown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fpunchf(PHAST_NULL("state"), sformat, token);
|
fpunchf(PHAST_NULL("state"), sformat, token);
|
||||||
|
|||||||
@ -1097,7 +1097,7 @@ read_exchange_master_species(void)
|
|||||||
if (token[0] == '[') {
|
if (token[0] == '[') {
|
||||||
cptr1 = token;
|
cptr1 = token;
|
||||||
get_elt(&cptr, element, &l);
|
get_elt(&cptr, element, &l);
|
||||||
strcpy(token, element);
|
Utilities::strcpy_safe(token, MAX_LENGTH, element);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
@ -1752,7 +1752,7 @@ read_inv_phases(class inverse *inverse_ptr, const char* cptr)
|
|||||||
j = copy_token(token, &cptr, &l);
|
j = copy_token(token, &cptr, &l);
|
||||||
if (j == EMPTY)
|
if (j == EMPTY)
|
||||||
break;
|
break;
|
||||||
strcpy(token1, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
str_tolower(token1);
|
str_tolower(token1);
|
||||||
if (token1[0] == 'p')
|
if (token1[0] == 'p')
|
||||||
{
|
{
|
||||||
@ -3107,7 +3107,7 @@ read_master_species(void)
|
|||||||
if (token[0] == '[') {
|
if (token[0] == '[') {
|
||||||
cptr1 = token;
|
cptr1 = token;
|
||||||
get_elt(&cptr, element, &l);
|
get_elt(&cptr, element, &l);
|
||||||
strcpy(token, element);
|
Utilities::strcpy_safe(token, MAX_LENGTH, element);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
@ -3726,7 +3726,7 @@ read_phases(void)
|
|||||||
/*
|
/*
|
||||||
* Get pointer to each species in the reaction, store new species if necessary
|
* Get pointer to each species in the reaction, store new species if necessary
|
||||||
*/
|
*/
|
||||||
strcpy(token1, trxn.token[0].name);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, trxn.token[0].name);
|
||||||
replace("(g)", "", token1);
|
replace("(g)", "", token1);
|
||||||
replace("(s)", "", token1);
|
replace("(s)", "", token1);
|
||||||
replace("(G)", "", token1);
|
replace("(G)", "", token1);
|
||||||
@ -3739,7 +3739,7 @@ read_phases(void)
|
|||||||
(strstr(trxn.token[i].name, "(S)") == NULL) &&
|
(strstr(trxn.token[i].name, "(S)") == NULL) &&
|
||||||
(strstr(trxn.token[i].name, "(G)") == NULL))
|
(strstr(trxn.token[i].name, "(G)") == NULL))
|
||||||
{
|
{
|
||||||
strcpy(token1, trxn.token[i].name);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, trxn.token[i].name);
|
||||||
replace("(aq)", "", token1);
|
replace("(aq)", "", token1);
|
||||||
replace("(AQ)", "", token1);
|
replace("(AQ)", "", token1);
|
||||||
replace("H2O(l)", "H2O", token1);
|
replace("H2O(l)", "H2O", token1);
|
||||||
@ -5737,7 +5737,7 @@ read_use(void)
|
|||||||
/*
|
/*
|
||||||
* Read number
|
* Read number
|
||||||
*/
|
*/
|
||||||
strcpy(token1, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
i = copy_token(token, &cptr, &l);
|
i = copy_token(token, &cptr, &l);
|
||||||
@ -7013,16 +7013,16 @@ read_surface_master_species(void)
|
|||||||
master[count_master]->s = s_store(token1.c_str(), l_z, FALSE);
|
master[count_master]->s = s_store(token1.c_str(), l_z, FALSE);
|
||||||
}
|
}
|
||||||
master[count_master]->primary = TRUE;
|
master[count_master]->primary = TRUE;
|
||||||
strcpy(token, master[count_master]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master[count_master]->elt->name);
|
||||||
count_master++;
|
count_master++;
|
||||||
/*
|
/*
|
||||||
* Save values in master and species structure for surface psi
|
* Save values in master and species structure for surface psi
|
||||||
*/
|
*/
|
||||||
strcpy(token1, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
replace("_", " ", token1);
|
replace("_", " ", token1);
|
||||||
cptr1 = token1;
|
cptr1 = token1;
|
||||||
copy_token(token, &cptr1, &l);
|
copy_token(token, &cptr1, &l);
|
||||||
strcat(token, "_psi");
|
Utilities::strcat_safe(token, MAX_LENGTH, "_psi");
|
||||||
add_psi_master_species(token);
|
add_psi_master_species(token);
|
||||||
opt_save = OPTION_DEFAULT;
|
opt_save = OPTION_DEFAULT;
|
||||||
break;
|
break;
|
||||||
@ -7041,10 +7041,9 @@ add_psi_master_species(char *token)
|
|||||||
class species *s_ptr;
|
class species *s_ptr;
|
||||||
class master *master_ptr;
|
class master *master_ptr;
|
||||||
const char* cptr;
|
const char* cptr;
|
||||||
char token1[MAX_LENGTH];
|
char token1[MAX_LENGTH] = "";
|
||||||
int i, n, plane;
|
int i, n, plane;
|
||||||
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
strcpy(token1, token);
|
|
||||||
for (plane = SURF_PSI; plane <= SURF_PSI2; plane++)
|
for (plane = SURF_PSI; plane <= SURF_PSI2; plane++)
|
||||||
{
|
{
|
||||||
strcpy(token, token1);
|
strcpy(token, token1);
|
||||||
@ -9481,7 +9480,7 @@ read_copy(void)
|
|||||||
switch (next_keyword)
|
switch (next_keyword)
|
||||||
{
|
{
|
||||||
case Keywords::KEY_NONE: /* Have not read line with keyword */
|
case Keywords::KEY_NONE: /* Have not read line with keyword */
|
||||||
strcpy(nonkeyword, token);
|
Utilities::strcpy_safe(nonkeyword, MAX_LENGTH, token);
|
||||||
break;
|
break;
|
||||||
case Keywords::KEY_SOLUTION: /* Solution */
|
case Keywords::KEY_SOLUTION: /* Solution */
|
||||||
case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */
|
case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */
|
||||||
@ -9508,7 +9507,7 @@ read_copy(void)
|
|||||||
/*
|
/*
|
||||||
* Read source index
|
* Read source index
|
||||||
*/
|
*/
|
||||||
strcpy(token1, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
i = copy_token(token, &cptr, &l);
|
i = copy_token(token, &cptr, &l);
|
||||||
if (i == DIGIT)
|
if (i == DIGIT)
|
||||||
{
|
{
|
||||||
@ -9728,8 +9727,8 @@ cleanup_after_parser(CParser &parser)
|
|||||||
// check_key sets next_keyword
|
// check_key sets next_keyword
|
||||||
if (parser.get_m_line_type() == PHRQ_io::LT_EOF)
|
if (parser.get_m_line_type() == PHRQ_io::LT_EOF)
|
||||||
{
|
{
|
||||||
strcpy(line, "");
|
Utilities::strcpy_safe(line, max_line, "");
|
||||||
strcpy(line_save, "");
|
Utilities::strcpy_safe(line_save, max_line, "");
|
||||||
next_keyword = Keywords::KEY_END;
|
next_keyword = Keywords::KEY_END;
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
@ -9751,8 +9750,8 @@ cleanup_after_parser(CParser &parser)
|
|||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
}
|
}
|
||||||
strcpy(line, parser.line().c_str());
|
Utilities::strcpy_safe(line, max_line, parser.line().c_str());
|
||||||
strcpy(line_save, parser.line_save().c_str());
|
Utilities::strcpy_safe(line_save, max_line, parser.line_save().c_str());
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|||||||
@ -707,13 +707,13 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
|
|||||||
comp_ptr->Set_delta(0.0);
|
comp_ptr->Set_delta(0.0);
|
||||||
if (comp_ptr->Get_add_formula().size() > 0)
|
if (comp_ptr->Get_add_formula().size() > 0)
|
||||||
{
|
{
|
||||||
strcpy(token, comp_ptr->Get_add_formula().c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
||||||
cptr = &(token[0]);
|
cptr = &(token[0]);
|
||||||
get_elts_in_species(&cptr, 1.0);
|
get_elts_in_species(&cptr, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(token, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
}
|
}
|
||||||
if (comp_ptr->Get_moles() > 0.0)
|
if (comp_ptr->Get_moles() > 0.0)
|
||||||
|
|||||||
@ -914,13 +914,13 @@ build_tally_table(void)
|
|||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
if (comp_ptr->Get_add_formula().size() > 0)
|
if (comp_ptr->Get_add_formula().size() > 0)
|
||||||
{
|
{
|
||||||
strcpy(token, comp_ptr->Get_add_formula().c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
||||||
cptr = &(token[0]);
|
cptr = &(token[0]);
|
||||||
get_elts_in_species(&cptr, 1.0);
|
get_elts_in_species(&cptr, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(token, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
}
|
}
|
||||||
elt_list_combine();
|
elt_list_combine();
|
||||||
@ -971,7 +971,7 @@ build_tally_table(void)
|
|||||||
tally_table[n].type = Ss_phase;
|
tally_table[n].type = Ss_phase;
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy(token, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
elt_list_combine();
|
elt_list_combine();
|
||||||
tally_table[n].formula = elt_list_vsave();
|
tally_table[n].formula = elt_list_vsave();
|
||||||
@ -1019,7 +1019,7 @@ build_tally_table(void)
|
|||||||
phase_ptr = NULL;
|
phase_ptr = NULL;
|
||||||
if (kinetics_comp_ptr->Get_namecoef().size() == 1)
|
if (kinetics_comp_ptr->Get_namecoef().size() == 1)
|
||||||
{
|
{
|
||||||
strcpy(token, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str());
|
||||||
phase_ptr = phase_bsearch(token, &p, FALSE);
|
phase_ptr = phase_bsearch(token, &p, FALSE);
|
||||||
}
|
}
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
|
|||||||
@ -819,7 +819,7 @@ replace_solids_gases(void)
|
|||||||
/* try phase name without (g) or (s) */
|
/* try phase name without (g) or (s) */
|
||||||
if (phase_ptr == NULL)
|
if (phase_ptr == NULL)
|
||||||
{
|
{
|
||||||
strcpy(token, token_ptr->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, token_ptr->name);
|
||||||
replace("(g)", "", token);
|
replace("(g)", "", token);
|
||||||
replace("(s)", "", token);
|
replace("(s)", "", token);
|
||||||
replace("(G)", "", token);
|
replace("(G)", "", token);
|
||||||
@ -2013,8 +2013,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
//strcpy(token, "m_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "m_");
|
||||||
//strcat(token, punch.molalities[i].name);
|
//Utilities::strcat_safe(token, punch.molalities[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.molalities[i].s == NULL)
|
//if (punch.molalities[i].s == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2039,8 +2039,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
//strcpy(token, "la_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "la_");
|
||||||
//strcat(token, punch.activities[i].name);
|
//Utilities::strcat_safe(token, punch.activities[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.activities[i].s == NULL)
|
//if (punch.activities[i].s == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2066,8 +2066,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
//strcpy(token, "d_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "d_");
|
||||||
//strcat(token, punch.pure_phases[i].name);
|
//Utilities::strcat_safe(token, punch.pure_phases[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name));
|
//fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name));
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.pure_phases[i].phase == NULL)
|
//if (punch.pure_phases[i].phase == NULL)
|
||||||
@ -2093,8 +2093,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
//strcpy(token, "si_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "si_");
|
||||||
//strcat(token, punch.si[i].name);
|
//Utilities::strcat_safe(token, punch.si[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.si[i].phase == NULL)
|
//if (punch.si[i].phase == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2126,8 +2126,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
//strcpy(token, "g_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "g_");
|
||||||
//strcat(token, punch.gases[i].name);
|
//Utilities::strcat_safe(token, punch.gases[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.gases[i].phase == NULL)
|
//if (punch.gases[i].phase == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2149,11 +2149,11 @@ tidy_punch(void)
|
|||||||
name = "dk_";
|
name = "dk_";
|
||||||
name.append(pair_ref.first);
|
name.append(pair_ref.first);
|
||||||
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
||||||
//strcpy(token, "k_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "k_");
|
||||||
//strcat(token, punch.kinetics[i].name);
|
//Utilities::strcat_safe(token, punch.kinetics[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//strcpy(token, "dk_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "dk_");
|
||||||
//strcat(token, punch.kinetics[i].name);
|
//Utilities::strcat_safe(token, punch.kinetics[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2166,8 +2166,8 @@ tidy_punch(void)
|
|||||||
std::string name = "s_";
|
std::string name = "s_";
|
||||||
name.append(pair_ref.first);
|
name.append(pair_ref.first);
|
||||||
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
||||||
//strcpy(token, "s_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "s_");
|
||||||
//strcat(token, punch.s_s[i].name);
|
//Utilities::strcat_safe(token, punch.s_s[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2196,8 +2196,8 @@ tidy_punch(void)
|
|||||||
// punch.isotopes[i].name, punch.isotopes[i].name);
|
// punch.isotopes[i].name, punch.isotopes[i].name);
|
||||||
// warning_msg(error_string);
|
// warning_msg(error_string);
|
||||||
//}
|
//}
|
||||||
//strcpy(token, "I_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "I_");
|
||||||
//strcat(token, punch.isotopes[i].name);
|
//Utilities::strcat_safe(token, punch.isotopes[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2227,8 +2227,8 @@ tidy_punch(void)
|
|||||||
// punch.calculate_values[i].name);
|
// punch.calculate_values[i].name);
|
||||||
// warning_msg(error_string);
|
// warning_msg(error_string);
|
||||||
//}
|
//}
|
||||||
//strcpy(token, "V_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "V_");
|
||||||
//strcat(token, punch.calculate_values[i].name);
|
//Utilities::strcat_safe(token, punch.calculate_values[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1784,7 +1784,7 @@ set_initial_moles(int i)
|
|||||||
cxxExchComp comp;
|
cxxExchComp comp;
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy(token, "X");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "X");
|
||||||
cptr = token;
|
cptr = token;
|
||||||
get_elts_in_species(&cptr, 2e-10);
|
get_elts_in_species(&cptr, 2e-10);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
|
|||||||
@ -233,7 +233,7 @@ compute_gfw(const char *string, LDBLE * gfw)
|
|||||||
|
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy(token, string);
|
Utilities::strcpy_safe(token, MAX_LENGTH, string);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
if (get_elts_in_species(&cptr, 1.0) == ERROR)
|
if (get_elts_in_species(&cptr, 1.0) == ERROR)
|
||||||
{
|
{
|
||||||
@ -640,135 +640,6 @@ malloc_error(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
int Phreeqc::
|
|
||||||
parse_couple(char *token)
|
|
||||||
/* ---------------------------------------------------------------------- */
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Parse couple puts redox couples in standard form
|
|
||||||
* "+" is removed and couples are rewritten in sort
|
|
||||||
* order.
|
|
||||||
*/
|
|
||||||
int e1, e2, p1, p2;
|
|
||||||
const char* cptr;
|
|
||||||
std::string elt1, elt2;
|
|
||||||
char paren1[MAX_LENGTH], paren2[MAX_LENGTH];
|
|
||||||
|
|
||||||
if (strcmp_nocase_arg1(token, "pe") == 0)
|
|
||||||
{
|
|
||||||
str_tolower(token);
|
|
||||||
return (OK);
|
|
||||||
}
|
|
||||||
while (replace("(+", "(", token) == TRUE);
|
|
||||||
cptr = token;
|
|
||||||
get_elt(&cptr, elt1, &e1);
|
|
||||||
if (*cptr != '(')
|
|
||||||
{
|
|
||||||
error_string = sformatf( "Element name must be followed by "
|
|
||||||
"parentheses in redox couple, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
parse_error++;
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
paren_count = 1;
|
|
||||||
paren1[0] = '(';
|
|
||||||
p1 = 1;
|
|
||||||
while (*cptr != '\0')
|
|
||||||
{
|
|
||||||
cptr++;
|
|
||||||
if (*cptr == '/' || *cptr == '\0')
|
|
||||||
{
|
|
||||||
error_string = sformatf(
|
|
||||||
"End of line or " "/"
|
|
||||||
" encountered before end of parentheses, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
paren1[p1++] = *cptr;
|
|
||||||
if (*cptr == '(')
|
|
||||||
paren_count++;
|
|
||||||
if (*cptr == ')')
|
|
||||||
paren_count--;
|
|
||||||
if (paren_count == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
paren1[p1] = '\0';
|
|
||||||
cptr++;
|
|
||||||
if (*cptr != '/')
|
|
||||||
{
|
|
||||||
error_string = sformatf( " " "/" " must follow parentheses "
|
|
||||||
"ending first half of redox couple, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
parse_error++;
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
cptr++;
|
|
||||||
get_elt(&cptr, elt2, &e2);
|
|
||||||
if (strcmp(elt1.c_str(), elt2.c_str()) != 0)
|
|
||||||
{
|
|
||||||
error_string = sformatf( "Redox couple must be two redox states "
|
|
||||||
"of the same element, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
if (*cptr != '(')
|
|
||||||
{
|
|
||||||
error_string = sformatf( "Element name must be followed by "
|
|
||||||
"parentheses in redox couple, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
parse_error++;
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
paren2[0] = '(';
|
|
||||||
paren_count = 1;
|
|
||||||
p2 = 1;
|
|
||||||
while (*cptr != '\0')
|
|
||||||
{
|
|
||||||
cptr++;
|
|
||||||
if (*cptr == '/' || *cptr == '\0')
|
|
||||||
{
|
|
||||||
error_string = sformatf( "End of line or " "/" " encountered"
|
|
||||||
" before end of parentheses, %s.", token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
paren2[p2++] = *cptr;
|
|
||||||
if (*cptr == '(')
|
|
||||||
paren_count++;
|
|
||||||
if (*cptr == ')')
|
|
||||||
paren_count--;
|
|
||||||
if (paren_count == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
paren2[p2] = '\0';
|
|
||||||
if (strcmp(paren1, paren2) < 0)
|
|
||||||
{
|
|
||||||
strcpy(token, elt1.c_str());
|
|
||||||
strcat(token, paren1);
|
|
||||||
strcat(token, "/");
|
|
||||||
strcat(token, elt2.c_str());
|
|
||||||
strcat(token, paren2);
|
|
||||||
}
|
|
||||||
else if (strcmp(paren1, paren2) > 0)
|
|
||||||
{
|
|
||||||
strcpy(token, elt2.c_str());
|
|
||||||
strcat(token, paren2);
|
|
||||||
strcat(token, "/");
|
|
||||||
strcat(token, elt1.c_str());
|
|
||||||
strcat(token, paren1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error_string = sformatf( "Both parts of redox couple are the same, %s.",
|
|
||||||
token);
|
|
||||||
error_msg(error_string, CONTINUE);
|
|
||||||
return (ERROR);
|
|
||||||
}
|
|
||||||
return (OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
int Phreeqc::
|
int Phreeqc::
|
||||||
print_centered(const char *string)
|
print_centered(const char *string)
|
||||||
@ -783,7 +654,7 @@ print_centered(const char *string)
|
|||||||
for (i = 0; i < l1; i++)
|
for (i = 0; i < l1; i++)
|
||||||
token[i] = '-';
|
token[i] = '-';
|
||||||
token[i] = '\0';
|
token[i] = '\0';
|
||||||
strcat(token, string);
|
Utilities::strcat_safe(token, MAX_LENGTH, string);
|
||||||
for (i = 0; i < l2; i++)
|
for (i = 0; i < l2; i++)
|
||||||
token[i + l1 + l] = '-';
|
token[i + l1 + l] = '-';
|
||||||
token[79] = '\0';
|
token[79] = '\0';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user