fixed a new master, advection punch_temp and print_temp, some tidying

This commit is contained in:
David Parkhurst 2021-03-24 23:06:21 -06:00
parent 5f21dafa04
commit 48e6b939d2
5 changed files with 53 additions and 71 deletions

View File

@ -1688,11 +1688,10 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc)
max_master = MAX_MASTER;
*/
int count_master = (int)pSrc->master.size();
for (int i = 0; i < (int)master.size(); i++)
for (size_t i = 0; i < master.size(); i++)
{
master.resize((size_t)i + 1);
master[i] = (struct master *) PHRQ_malloc( sizeof(struct master));
if (master[i] == NULL) malloc_error();
master.resize(i + 1);
master[i] = new struct master;
memcpy(master[i], pSrc->master[i], sizeof(struct master));
// clean up pointers
master[i]->gfw_formula = NULL;

View File

@ -3157,7 +3157,6 @@ setup_exchange(void)
* Fill in data for exchanger in unknowns structures
*/
struct master *master_ptr;
//struct master **master_ptr_list;
std::vector<struct master*> master_ptr_list;
if (use.Get_exchange_ptr() == NULL)

View File

@ -7299,8 +7299,7 @@ read_advection(void)
char *description;
int n_user, n_user_end, i;
int count_punch, count_print;
int *punch_temp, *print_temp;
std::vector<int> punch_temp, print_temp;
int return_value, opt, opt_save;
char *next_char;
const char *opt_list[] = {
@ -7338,14 +7337,6 @@ read_advection(void)
count_ad_shifts = 0;
print_ad_modulus = 1;
punch_ad_modulus = 1;
count_punch = 0;
count_print = 0;
punch_temp = (int *) PHRQ_malloc(sizeof(int));
if (punch_temp == NULL)
malloc_error();
print_temp = (int *) PHRQ_malloc(sizeof(int));
if (print_temp == NULL)
malloc_error();
/*
* Read lines
*/
@ -7383,11 +7374,16 @@ read_advection(void)
break;
case 2: /* print */
case 5: /* print_cells */
print_temp =
read_list_ints_range(&next_char, &count_print, TRUE,
print_temp);
{
std::istringstream iss(next_char);
int idummy;
while (iss >> idummy)
{
print_temp.push_back(idummy);
}
opt_save = 2;
break;
}
break;
case 3: /* selected_output */
case 11: /* selected_output_frequency */
case 12: /* punch_frequency */
@ -7404,11 +7400,16 @@ read_advection(void)
case 4: /* punch */
case 14: /* punch_cells */
case 6: /* selected_cells */
punch_temp =
read_list_ints_range(&next_char, &count_punch, TRUE,
punch_temp);
{
std::istringstream iss(next_char);
int idummy;
while (iss >> idummy)
{
punch_temp.push_back(idummy);
}
opt_save = 4;
break;
}
case 7: /* time_step */
case 8: /* timest */
(void)sscanf(next_char, SCANFORMAT, &advection_kin_time);
@ -7464,11 +7465,11 @@ read_advection(void)
* Fill in data for punch
*/
advection_punch.resize((size_t)count_ad_cells + 1);
if (count_punch != 0)
if (punch_temp.size() != 0)
{
for (i = 0; i < count_ad_cells; i++)
advection_punch[i] = FALSE;
for (i = 0; i < count_punch; i++)
for (size_t i = 0; i < punch_temp.size(); i++)
{
if (punch_temp[i] > count_ad_cells || punch_temp[i] < 1)
{
@ -7488,16 +7489,16 @@ read_advection(void)
for (i = 0; i < count_ad_cells; i++)
advection_punch[i] = TRUE;
}
punch_temp = (int *) free_check_null(punch_temp);
punch_temp.clear();
/*
* Fill in data for print
*/
advection_print.resize((size_t)count_ad_cells + 1);
if (count_print != 0)
if (print_temp.size() != 0)
{
for (i = 0; i < count_ad_cells; i++)
advection_print[i] = FALSE;
for (i = 0; i < count_print; i++)
for (i = 0; i < print_temp.size(); i++)
{
if (print_temp[i] > count_ad_cells || print_temp[i] < 1)
{
@ -7517,7 +7518,7 @@ read_advection(void)
for (i = 0; i < count_ad_cells; i++)
advection_print[i] = TRUE;
}
print_temp = (int *) free_check_null(print_temp);
print_temp.clear();
return (return_value);
}
@ -8583,17 +8584,6 @@ read_user_punch(void)
{
r->commands.clear();
}
//rate_free(user_punch);
//user_punch->new_def = TRUE;
//user_punch->commands = (char *) PHRQ_malloc(sizeof(char));
//if (user_punch->commands == NULL)
// malloc_error();
//user_punch->commands[0] = '\0';
//user_punch->linebase = NULL;
//user_punch->varbase = NULL;
//user_punch->loopbase = NULL;
//user_punch->name =
// string_hsave("user defined Basic punch routine");
case OPT_1: /* read command */
r->commands.append(";\0");
r->commands.append(line);

View File

@ -417,9 +417,8 @@ elt_list_dup(struct elt_list *elt_list_ptr_old)
/*
* Malloc space and store element data
*/
elt_list_ptr_new =
(struct elt_list *) PHRQ_malloc(((size_t)count_totals + 1) *
sizeof(struct elt_list));
elt_list_ptr_new = (struct elt_list *) PHRQ_malloc(
((size_t)count_totals + 1) * sizeof(struct elt_list));
if (elt_list_ptr_new == NULL)
malloc_error();
memcpy(elt_list_ptr_new, elt_list_ptr_old,
@ -483,8 +482,8 @@ elt_list_save(void)
/*
* Malloc space and store element data
*/
elt_list_ptr = (struct elt_list*)PHRQ_malloc(((size_t)count_elts + 1) *
sizeof(struct elt_list));
elt_list_ptr = (struct elt_list*)PHRQ_malloc(
((size_t)count_elts + 1) * sizeof(struct elt_list));
if (elt_list_ptr == NULL)
{
malloc_error();
@ -508,7 +507,8 @@ NameDouble2elt_list(const cxxNameDouble &nd)
/*
* Takes NameDouble allocates space and fills new elt_list struct
*/
struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((nd.size() + 1) * sizeof(struct elt_list));
struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc(
(nd.size() + 1) * sizeof(struct elt_list));
if (elt_list_ptr == NULL)
{
malloc_error();
@ -564,19 +564,19 @@ inverse_alloc(void)
* allocate space for pointers in structure to NULL
*/
inverse_ptr->uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE));
inverse_ptr->uncertainties = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
if (inverse_ptr->uncertainties == NULL)
{
malloc_error();
return inverse_ptr;
}
inverse_ptr->ph_uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE));
inverse_ptr->ph_uncertainties = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
if (inverse_ptr->ph_uncertainties == NULL)
{
malloc_error();
return inverse_ptr;
}
inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int));
inverse_ptr->force_solns = (int *) PHRQ_malloc(sizeof(int));
if (inverse_ptr->force_solns == NULL)
{
malloc_error();
@ -587,7 +587,7 @@ inverse_alloc(void)
inverse_ptr->solns = NULL;
inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts));
inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc(sizeof(struct inv_elts));
if (inverse_ptr->elts == NULL)
{
malloc_error();
@ -596,7 +596,7 @@ inverse_alloc(void)
inverse_ptr->elts[0].name = NULL;
inverse_ptr->elts[0].uncertainties = NULL;
inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_malloc((size_t)
inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_malloc(
sizeof(struct inv_isotope));
if (inverse_ptr->isotopes == NULL)
{
@ -607,8 +607,7 @@ inverse_alloc(void)
inverse_ptr->isotopes[0].isotope_number = 0;
inverse_ptr->isotopes[0].elt_name = NULL;
inverse_ptr->i_u = (struct inv_isotope *) PHRQ_malloc((size_t)
sizeof(struct inv_isotope));
inverse_ptr->i_u = (struct inv_isotope *)PHRQ_malloc(sizeof(struct inv_isotope));
if (inverse_ptr->i_u == NULL)
{
malloc_error();
@ -618,7 +617,8 @@ inverse_alloc(void)
inverse_ptr->i_u[0].isotope_number = 0;
inverse_ptr->i_u[0].elt_name = NULL;
inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases));
inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc(
sizeof(struct inv_phases));
if (inverse_ptr->phases == NULL)
{
malloc_error();
@ -1434,8 +1434,7 @@ rate_copy(struct rate *rate_ptr)
*/
if (rate_ptr == NULL)
return (NULL);
struct rate * rate_new = (struct rate *) PHRQ_malloc(sizeof(struct rate));
if (rate_new == NULL) malloc_error();
struct rate* rate_new = new struct rate;
rate_new->commands = rate_ptr->commands;
rate_new->new_def = TRUE;
rate_new->linebase = NULL;
@ -1549,9 +1548,8 @@ rxn_alloc(int ntokens)
/*
* Malloc rxn_token structure
*/
rxn_ptr->token =
(struct rxn_token *) PHRQ_malloc((size_t) ntokens *
sizeof(struct rxn_token));
rxn_ptr->token = (struct rxn_token *) PHRQ_malloc(
(size_t) ntokens * sizeof(struct rxn_token));
for (i = 0; i < ntokens; i++)
{
rxn_ptr->token[i].s = NULL;
@ -3397,12 +3395,11 @@ copier_init(struct copier *copier_ptr)
copier_ptr->count = 0;
copier_ptr->max = 10;
copier_ptr->n_user =
(int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int)));
copier_ptr->start =
(int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int)));
copier_ptr->end =
(int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int)));
copier_ptr->n_user = (int *) PHRQ_malloc(
(size_t)copier_ptr->max * sizeof(int));
copier_ptr->start = (int *) PHRQ_malloc(
(size_t)copier_ptr->max * sizeof(int));
copier_ptr->end =(int *) PHRQ_malloc((size_t)copier_ptr->max * sizeof(int));
return (OK);
}
#include "StorageBin.h"

View File

@ -117,9 +117,8 @@ get_all_components(void)
* Buffer contains an entry for every primary master
* species that can be used in the transport problem.
*/
t_buffer =
(struct tally_buffer *) PHRQ_malloc((size_t) tally_count_component *
sizeof(struct tally_buffer));
t_buffer = (struct tally_buffer *) PHRQ_malloc(
(size_t)tally_count_component * sizeof(struct tally_buffer));
// store alkalinity
j = 0;
@ -1218,10 +1217,8 @@ extend_tally_table(void)
malloc_error();
for (i = 0; i < 3; i++)
{
tally_table[count_tally_table_columns].total[i] =
(struct tally_buffer *)
PHRQ_malloc((size_t) (count_tally_table_rows) *
sizeof(struct tally_buffer));
tally_table[count_tally_table_columns].total[i] = (struct tally_buffer *)
PHRQ_malloc((size_t)count_tally_table_rows * sizeof(struct tally_buffer));
if (tally_table[count_tally_table_columns].total[i] == NULL)
malloc_error();
for (j = 0; j < count_tally_table_rows; j++)