AN ABSTRACT OF THE THESIS OF

Barry Kelly for the degree of Master of Science in Chemical

Engineering/Forest Products presentedon August 12, 1988.

Title: A Computer Program to Solve Aqueous Inorganic Equilibrium

Systems Using Pitzer's Method to Determine Activity

Coefficients.

Abstract approved: Redacted for Privacy W. J. FredericK/ Redacted for Privacy

r 6/ R. V. Mrazek

Chemical equilibrium is a major factor inmany natural and

industrial systems. The ability to predict ionic equilibrium is extremely valuable in industry in solvingproblems without the costs

involved in full scale experiments. An example of an application in the pulp and paper industry is the predictionof non-process element solubility in process streams.

A computer program, ISIS, was developed to estimate the solubil-

ity of inorganic salts in aqueous, inorganic solutions. The model

incorporates a two step minimization algorithmand

Pitzer's method for ionic prediction.

The program, ISIS, was tested on threecases. The test cases were: KC1 solubility in a NaC1 and water solution, NaC1 solubility

in a MgC12 and water solution, and CaSO4 solubility ina NaC1 and water solution. The equilibrium predictions in the test caseswere very good, with the mean of the absolute value of the relativeerror ranging from 4.3% for the first case, 17% for the secondcase, to

3.8% in the third case. ISIS accurately predicted the solid phase amount and chemical composition in each of the test cases.

A parametric study was conducted on the three testcases to examine the effects of the activity coefficient predictor, and of uncertainty in chemical potentials, and third virial coefficientsand mixing terms in the Pitzer activity coefficient prediction model.

The effects of the activity coefficient predictorwere determined by comparing predictions made with the Pitzer modelversus an extended

Debye-Huckel equation and an ideal solution assumption. The dif- ferences were great, with the other activity coefficientpredictors resulting in errors greater than five times theerror with the Pitzer activity coefficient model. The effect of the chemical potentials was large, especially in the trace species case, CaSO4 ina NaC1 and water solution. A relative change of less than a tenth ofa percent in the solid species chemical potential resulted inan increased error of ten times the original error. The effect of assuming the third virial coefficients and the mixingterms to be zero in the

Pitzer activity coefficient predictor can be large. Errors up to 90% in the mean activity coefficient were found.

It was concluded that the computer program ISIS couldpredict accurately the solubility of inorganic salts inaqueous, inorganic solutions. The accuracy of the prediction would be greatly affected by the accuracy of the chemical potentials and the availabilityof the third virial coefficient and mixing terms in the Pitzeractivity coefficient predictor. Future work is recommended in collecting accurate chemical potentials and Pitzer interaction terms to increase the database for ISIS and similar programs. The inclusion of ISIS into a steady state chemical process simulator is also recommended. A Computer Program to Solve Aqueous Inorganic Equilibrium Systems Using Pitzer's Method to Determine Activity Coefficients

by

Barry Kelly

A THESIS

Submitted to

Oregon State University

in partial fulfillment of the requirements for the degree of Master of Science

Completed August 12, 1988

Commencement June 1989 APPROVED:

Redacted for Privacy

13r/ofesdoVICh-e-mical Engineeringin charge of major

Redacted for Privacy

ProfeSZ;rof Forest Productsj4charge of major

Redacted for Privacy

HeadofOh,lical Engineering Department

Redacted for Privacy

Head of Forest/Products Department

Redacted for Privacy

e School1'

Date thesis is presented: August 12. 1988 ACKNOWLEDGMENT

The completion of this work represents the support and education

I received from many individuals. I would like to acknowledge just a few of the many. Specifically, I wish to thank Dr. William J.

Frederick and Dr. Robert V. Mrazek for their guidance and assistance

throughout the research and writing of project.

A special thanks goes to my family. The combination of support

from my mother and father, constant harassment frommy brothers and

sisters, and continual help from my fiance, JoAnne, createda driving

force towards the completion of the project of incrediblemagnitude.

I would also like to thank Dr. Biermann, Dr. Humphrey, Dr. Levien, and Dr. Nelson for having served on my committee, and Sadie Airth for her help with this manuscript. TABLE OF CONTENTS

Ent

INTRODUCTION 1

THEORY 5

A. Gibbs Free Energy Minimization 5 B. Activity Coefficient Calculation 9

RESULTS 21

A. Test Cases 22 B. Parametric Study 28

CONCLUSION 48

FUTURE WORK 50

BIBLIOGRAPHY 51

APPENDICES

Appendix A: Calculation of the Electrostatic Mixing Terms 54 Appendix B: Average ISIS Run Times 56 Appendix C: ISIS User Manual 57 Appendix D: ISIS Operations Manual 86 Appendix E: ISIS Source Code 124 Appendix F: ISIS Database Files 199 Appendix G: PITZER Source Code 211 LIST OF FIGURES

Figure Ent

1. Solubility of a slightly soluble salt, CaSO4, in NaC1 and water solutions (Silcock, 1979; Block and Waters, 1968; Marshel and Slusher, 1966) and calculated solubilities from several computer programs 3

2. Solubility of KC1 in NaC1 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program 23

3. Solubility of NaCl in MgC12 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program 24

4. Solubility of Nadi in MgC12 and water solutions at 25°C (Silcock, 1979) calculated solubility from ISIS computer program. , and absolute value of the relative deviations between the ISIS prediction and the experimental points versus MgC12 concentration 25

5. Solubility of CaSO4 in NaCl and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program 27

6. Solubility of KC1 in NaCl and water solutions 15 25°C (Silcock, 1979) and calculated solubility from ISIS computer program using Pitzer, extended Dedye-Huckel, and ideal solution activity coefficient prediction models 29

7. Solubility of Nadi in MgC12 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program using Pitzer, extended Dedye-Huckel, and ideal solution activity coefficient production models 30

8. Solubility of CaSO4 in NaC1 and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program using Pitzer, extended Debye-Huckel, and ideal solution activity coefficient prediction models 32

9. Solubility of KC1 in NaC1 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program using the Pitzer activity coefficient predictor and varying chemical potentials 34 Figure Page

10. Solubility of NaC1 in MgC12 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program using the Pitzer activity coefficient predictor and varying chemical potentials 36

11. Solubility of CaSO4 in NaC1 and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program using the Pitzer activity coefficient predictor and varying chemical potentials 39

12. Percent error in mean activity coefficient of NaC1 versus NaC1 ionic fraction for Case 1 45

13. Percent error in mean activity coefficient of KC1 versus KC1 ionic fraction for Case 1 45

14. Percent error in mean activity coefficient of NaC1 versus NaC1 ionic fraction for Case 2 46

15. Percent error in mean activity coefficient of MgC12 versus MgC12 ionic fraction for Case 2 46

16. Percent error in mean activity coefficient of NaC1 versus NaC1 ionic fraction for Case 3 47

17. Percent error in mean activity coefficient of CaSO4 versus CaSO4 ionic fraction for Case 3 47 LIST OF TABLES

Table Page

1. Empirical Constants in the Pitzer Activity Coefficient Equations 16

2. Comparison of Chemical Potentials Used inCase1 35

3. Comparison of Chemical Potentials Used inCase2 37

4. Comparison of Chemical Potentials Used inCase3 37 NOMENCLATURE aw activity of water

Actual actual solubility data from literature

A, B, ai, bi constants in the extended Debye-Huckel equation (17) ai activity of species i

Aki number of moles of element k in species i

AS Pitzer-Debye-Huckel limiting slope of , Equation (31) b empirical parameter in Equation (30)

B' MX derivative of BMXwith respect to ionic strength

BOmx second virial coefficient term, Equation (22)

MX second virial coefficient term, Equation (23)

COmx third virial coefficient constant for salt MX dw density of water at 25 °C

D dielectric constant of water at 25 °C e charge of electron

Ek total moles of element k in system f(I) Debye-Huckel term, Equation (19)

F sum of Debye-Huckel term and derivatives of the second virial coefficient terms with respect to ionic strength, Equation (30)

G Gibbs free energy

CEx excess Gibbs free energy

AGj Gibbs free energy change of reaction j

I ionic strength, Equation (18)

Ifmx ionic fraction of salt MX, Equation (56)

total number of all species

ISIS value calculated by program ISIS

Boltzmann constant kt total number of elements

K search parameter

m molality of salt

mi molality of species i

n number of data points compared ni number of moles of species i nw number of moles of water

No Avogadro number

P pressure

ideal gas constant

number of independent stoichiometric equations, Equation (12)

S entropy

T temperature

volume

mean activity coefficient using all parameters, Equation (55)

V' mean activity coefficient with selected parameters set to zero, Equation (55) xall mole fractions of all species x. 1 mole fraction of species i

xw mole fraction of water

z. 1 charge of species i a, empirical constants in Equations (32) to (37) (see al' a2 Table 1)

(0) (1) (2) fl MX' 0 MK' 0MX second virial coefficient constants for the salt MX ryi activity coefficient for species i yw activity coefficient of water cj extent of reaction, Equation (7)

0MN second virial coefficient term for mixed electrolytes

BAN the derivative of Omm with respect to the ionic strength

0MN second virial coefficient constant for the interaction of like charged ions M and N

A ij second virial coefficient of species i and j, Equation (19)

A: ij the derivative of Aij with respect to the ionic strength

PHW values calculated using chemical potentials from Harvie and Weare (1980) iAi chemical potential of species i

third virial coefficient of species i, j, and k, Equation (19)

PRobie values calculated using chemical potentials from Robie (1979)

Ki standard chemical potential of species i vij stoichiometric coefficient of reaction j for species i

osmotic coefficient

third virial coefficient constant for the interaction of the like charged ions M and N, and the oppositely charged ion X

Subscript

1 value from the last iteration of species 1 A Computer Program to Solve Aqueous Inorganic Equilibrium Systems Using Pitzer's Method to Determine Activity Coefficients

INTRODUCTION

Aqueous inorganic equilibrium systems exist in many places in nature and industry. In natural settings, the prediction of equilibrium is used in studying geological formations and determining how the formations came to be (Harvie and Weare, 1980; Eugster et al,

1980, 1982), and also the prediction can be used for predicting the condition of a geological site hundreds of years in the future, as in the case of a high level radioactive waste depository. In industrial settings equilibrium predictions have many applications including process modeling, predicting the final equilibrium state of a reaction, and predicting species distribution in environmental systems (Chen et al, 1979; Rafal and Sanders, 1984). For example, in the pulp and paper industry, the increase in trace (non-process) elements as the fractional recovery of pulping chemicals increase has been recognized as controlled by chemical equilibria (Bennett et al,

1982; Ulmgren, 1982). The importance of the prediction of these equilibria is in the ability to predict effects long before they happen or at minimal cost compared to a full scale plant test.

To solve the aqueous inorganic equilibrium problem three components are needed: thermochemical data, activity coefficients, and an equation solving routine. The thermochemical data can be in the form of equilibrium constants or chemical potentials for all the reactions or species involved in the system, and stoichiometric data for the species involved in the reactions. Activity coefficients for 2 the dissolved species are needed to correct for non-ideal behavior.

An equation solver is needed to solve the intricate matrices ofmass balance, charge balance, and either Gibbs freeenergy minimization or mass action equations (Kelly and Frederick, 1986; Frederick et al.,

1988).

The problem is to bring together these three components of the equilibrium calculation into a computer model to predict the equilibrium state. The computer program needs a database of thermochemical data for any species in the problem, andan accurate activity coefficient predictor capable of predicting activity coefficients in high ionic strength solutions. It also requires an equation solver that can keep track of trace elements insystems with other species that are orders of magnitude higher inconcentration.

The equation solver should be robust, capable of globalconvergence, and converge to a solution that is independent of the initial starting point for the calculations.

A number of computer models currently exist that do solve the equilibrium problem, such as WATEQF (Plummer et al, 1976), SENECA2

(Kerrisk, 1981; Ma and Shipman, 1972), and REDEQL-EPAK (Ingleet al,

1978). However, these models have their beginnings in geological work, and not in the chemical process industries. For example, the study of inorganic elements in the pulp and paper industry thatare not part of the active chemical cycle or their intermediates in the chemical recovery process, non-process elements, requiresa high degree of accuracy to achieve good results, especially in the prediction of trace element concentrations. In Figure 1 the solubility of the trace species CaSO4 is plottedas the concentration 0.12 --SENECA2 es' 0.10 00'

>, 1= 0 08 /

0.06 0cr CO / in EPExperimental 8 / DEJ 0.04I , "?..--.. WATEQF

0.02

1 I I I

0 I 2 3 4 5 6 NaCI molality

Figure 1. Solubility of a slightly soluble salt, CaSO4, in NaC1 and water solutions (Silcock, 1979; Block and Waters, 1968; Marshel and Slusher, 1966) and calculated solubilities from several computer programs. (Kerrisk, 1981) u.) 4

of NaCl in solution increases. The CaSO4 is two orders of magnitude

lower in concentration than the NaCl, and this makes the accurate prediction of the final equilibria difficult. The predictions by the equilibrium models listed is good, but notas accurate as needed for

trace element studies, especially at the higher NaCl concentrations.

However, these programs were not designed for trace element studies

in chemical process streams where the ionic strengths reach upwards

of seven molal, so a more accurate program is needed.

The objective is to develop a quantitative model for the behavior of trace elements in aqueous, inorganic solutions. The

scope of this work is to construct a computer model for predicting equilibrium in aqueous, inorganic solutions. The model will: 1)

treat major and minor components, 2) predict solubilities, 3) predict soluble and insoluble amounts and compositions, and 4) predict activity coefficients. Also included in this work is a

parametric study of the major variables in the computer model, the

activity coefficient predictor, the chemical potentials, and the ion

interaction terms in the activity coefficient predictor.

The computer program ISIS was written to complete thescope of

the work. The name for the program, ISIS, is an acronym for Ionic

Species Interaction Simulator. 5

THEORY

The computer program ISIS has to determine the final equilibrium state for an aqueous, inorganic solution, given the temperature, pressure, and a closed chemical system. This problem requires the solution of the equilibrium, mass balance, and electrical balance equations. However, the solution to those equations alone is not enough. The non-idealities of the problem must be considered and corrected for. These features have to be available in ISIS, as well as the ability to handle trace elements in high ionic strength solutions.

A. Gibbs Free Energy Minimization

The Gibbs free energy, mass balance, and electrical balance equations were solved using the SENECA2 program written by Ma and

Shipman (1972), and later modified by Feber (1980) and Kerrisk

(1981). The SENECA2 program was used because of its unique two step method of solving the equilibrium problem. It utilized a direct minimization of the Gibbs free energy and a more exact solutionto the problem using a Newton-Raphson method on the set of non-linear equilibrium equations (Ma and Shipman, 1972).

The first step in the SENECA2 approach was the minimization of the Gibbs free energy. This problem is solved using a direct minimization of the Gibbs function using a gradient method developed by Naphtali (1959). The minimization approach was chosen because of

the relatively global convergence of the method. This allows the user to have little knowledge of the final equilibrium state and

still achieve convergence. 6

The Gibbs free energy minimization developed by Naphtalistarts with the basic free energy equation (1).

dG = -SdT + VdP + X pidni (1)

When the temperature and pressure are fixed, Equation (1)becomes

dG = I pidni (2)

Applying the second law of thermodynamics to Equation (2)will generate the criterion for equilibrium in a closed chemicalsystem at constant temperature and pressure, Equation (3).

dG = Epidni 0 (3)

Equations (1) - (3) are standard to equilibrium calculations that utilize the free energy equations. The difference in the

Naphtali method is in how the mass balance constraintsare introduced into the problem. The mass balance is maintained by calculating the change in the number of moles ofan element, Equation (4).

dni E dei (4)

WherearetheStOidlionletriccoefficientsand.isvij ej theextent of the reaction j, which will be defined. Using Equations (3) and (4) together produces Equation (5).

dG = I a pivii)dEj (5) i

It is interesting to note that the freeenergy change of reaction j,

Equation (6), is now exposed in Equation (5).

AG4 = I p.m.. ij (6) 7

Naphtali (1960) chose the form of the extent of reaction variable, ej,to be

de.

1 1j (7) dK with K as a search parameter and dK as the step size in the search.

Substituting Equation (7) into Equation (5) gives Equation (8).

dG ,2 X (E Piij) (8) dK

From Equation (8),the slope of the G verses K curve will always be negative, and when all the individual free energy changes of the reactions are zero the slope will be zero (Ma and Shipman, 1972).

To close the iteration loop, Equation (7) is substituted into

Equation (4), yielding an expression for the change in the number of moles of species i from the stoichiometric coefficients, the previous chemical potentials, Al, and the search parameter, Equation (9).

dni - X vij E pivijca (9) j 1

The calculation cycle in the minimization section of SENECA2

(Van Zeggeren, 1970) is:

1) An initial mass balance is used to calculate thePits 2) The change in the number of moles of the species, dni, is

calculated using Equation (9).

3) The new mass balance is used to calculate the new chemical

potentials.

4) If the slope of the dG / dK is not within tolerances, go to

step 2; if it is within tolerances, end calculations.

The computation of equilibria which have trace elements in the 8 system using Naphtali's technique has a drawback in that the truncation errors introduced can cause the trace elements to become

insignificant. The method employed in SENECA2 to circumvent this problem was, in the early stages of the algorithm, to ignore species

that had dropped below a specified tolerance. When the species were

thus ignored they were assigned a mole fraction equal to the

tolerance level. As the calculations proceeded, the precision

increased and the tolerance level was reduced. If the species were

then significant, it was returned to the active section of the

algorithm. If during the minimization calculations a species mole

fraction increased above the tolerance level, then the species mole

fraction would no longer be held at the tolerance level and mole

fraction would be allowed to change as the minimization calculations

dictated (Ma and Shipman, 1972).

One of the major problems of Naphtali's method is the truncation

errors which introduce deviations from the beginning mass balance

(Van Zeggeren, 1970). The two step method utilized in this work

corrects this deviation.

The second step in the algorithm used in SENECA2 is the Newton-

Raphson solution to the set of non-linear equilibrium equations.

Convergence with the Newton-Raphson technique requires initial

estimates of the equilibrium concentrations that are close to the

solution. The initial estimates of the equilibrium condition used in

SENECA2 to start the Newton-Raphson algorithm were the final

estimates from the Gibbs free energy minimization using Naphtali's

method. These estimates were accurate enough to achieve convergence

with the Newton-Raphson method. 9

The set of non-linear equations to be solvedstart with the mass balance and charge balance equations, in the form ofEquations (10) and (11).

X A .n. E k k tequations (10) i-1

X z.n.= 0 1 equation (11) 3. i-1

The equilibrium relationships for the system, Equation (12),are needed as well.

X v..p- = 0 13 R equations (12) i =1

After the matrices were established, the subroutine NEWSON in

SENECA2 was used to solve the system. If the solution set started to diverge, NEWSON would return the calculations to the Gibbs free energy minimization section for a more accurate starting point for the Newton-Raphson subroutine. A more detailed description of the solution algorithms used in SENECA2may be obtained from the publications of Ma and Shipman (1972) and Kerrisk (1981).

B. Activity Coefficient Calculation

The problem of non-ideality of the chemicalsystems is where the major work of this project is involved. If the chemical system behaved ideally, the chemical potential would beas in Equation (13).

pi(T,P,xi) pt(T,P) + RT Inxi (13)

The chemical potential would depend onlyon the temperature, pres- sure, and the species' own composition, and not on the other species type and composition in the solution (Smith and Missen, 1982). 10

For a non-ideal solution, the chemical potential is given by

Equation (14).

Ai(T'Pixall) AV") + RT In ai(T,P,xall) (14) where the activity of species i, ai, is a function of thetempera- ture, pressure, and all the species in the chemical system. The ratio of activity of species i to the molality of species i is given by Equation (15), and is called the molal activity coefficient,7i.

As the molality of species i goes to zero, the activity coefficient extrapolated back to unit molality goes to one (Zemaitis et al,

1986).

a- t 7i 1 at mi - 1 asmi 0 (15) m.

Equation (14) for the chemical potential of species ican be written as Equation (16).

Ai(T'P'xall) - pi(T,P) + RT In 7imi(T,P,xall) (16)

The evaluation of the activity coefficient is the difficult part

of the problem. It is a function of the temperature, pressure, and

the other species in solution. When the system behaves ideally the

activity coefficient is constant and is equal to one. But once in

the realm of the nonideal system the determination of the activity

coefficient comes under the dominion of a series of empirical and

semi-empirical equations.

One of the simplest methods of determining the activity

coefficient is to use the Debye-Huckel limiting law,or an extension

of that basic equation. Equation (17) is an extension of the Debye-

Huckel equation (Harvie and Weare, 1981). This variation of the

equation is for single ion activity coefficients. 11

-(Azi 012) ln-yi + B[I (17) (1 + ain1/2)

A and B are constants, and ai and Bi' are specific functions of the ionic species i. The ionic strength, I,is the charge density throughout the solution and is defined by Equation (18).

I 1/2 E mizi2 (18)

This form of the extended Debye-Huckel equation has been foundto give good results on single valence and on mixtures of single and double valence ionic species up toa molality of 0.1 (Smith and

Nissen, 1982).

The calculation of equilibrium state in higher concentration solutions is the purpose of this work. The extended Debye-Huckel equation will not produce accurate activity coefficients in those regions, so ISIS requires a more involved activity coefficient prediction method. Pitzer and coworkers (1973) developed a semi- empirical method for the prediction of activity coefficients based upon a virial expansion of the excess Gibbs free energy. This approach can be used to calculate activity coefficients for high concentration solutions, and to calculate the activity ofwater, as the solvent, in the cases presented here. The Harvie and Weare form of the Pitzer equations (Harvie and Weare, 1980)were used in ISIS, and their paper provide an excellent review of the method.

The Pitzer method begins with a virial expansion of theexcess

Gibbs free energy of the system (19).

GEx 1 1 nwf(I) + XA. (I)n.n. + p.4kninink (19) .. 1J 2 RT ij Ida nwilk 12

Where nw is the kilograms of solvent, in ISIS the solvent iswater, and ni... ni are the moles of the solutes i...j. The term f(I) is a

function of the ionic strength and the solvent properties, itis basically a Debye-Huckel type term (Pitzer, 1973). The second virial coefficient, Aij(I), accounts for the effect of the shortrange forces between the species i and j, and isa function of the ionic strength. The third virial coefficient, pijk, is for the triple species interaction, and is assumed not to bea function of the ionic

strength (Pitzer, 1973).

Taking the partial derivatives of theexcess Gibbs free energy

equation (19) with respect to the amount of solvent, nw, and then with respect to the moles of each of the species,ni...nj, yields an

expression for the osmotic coefficient (20) and the activity

coefficients of the individual species (21).

aGEX

anw 0 1 (20) RT Xmi

paGEx In yi (21) RTani

When the derivatives were taken and the individual activity coeffici-

ents were combined into a mean activity coefficient for a system

consisting of the neutral species MX and NX,groups of second and

third virial coefficients became apparent. Pitzer defined certain combinations of these virial coefficients into convenient and observ-

able quantities, Equations (22) (27) (Pitzer, 1973). Third virial coefficients with all ions of the same sign, pmmm andAxxx were considered to be very small and were dropped (Pitzer, 1973). The 13

quantities that were needed only for mixedelectrolytes were given

greek letters,0 and O. The virial coefficientswere now grouped

into measurable quantities. However, the distinct ion interaction

meaning of the virial coefficientswas lost.

zx Omx(I)= Amx +IAkx + (Amm + IAkm)+ 2z14

zm (22)

(AXX /AsXX) 2zX

zx BMX(I) = 2Amx + IA (2Amm + IAkm)+ 2zM

zm (23) (2A XX+ IA' ) 2zx

1/2 zx zmI1/2 cOmx 3{ Pmmx --I MMXX (24) zm zX

C7mx- 3/2C°mx (25)

OmN = AmN -(zN/2zm)Amm (zm/2zN) ANN (26)

OMNX 6PMNX (3zN/zm)Ammx (3zm/zN )PNNX (27)

The function f and the defined quantityBid have an ionic strength

dependence that Pitzer evaluated inthe series of papers that he and his coworkers published (Pitzer, 1973,Pitzer and Mayorga, 1973,

1974, Pitzer and Kim, 1974, Pitzer, 1975)and were covered in detail

in those articles. An important item to note is that the ionic strength dependence of these functionswas evaluated empirically to achieve a best fit of the data toa form of an equation suggested by 14 the theory. For example, the electrostatic term, f, was evaluated using Debye-Huckel type expressions for the ionic strength depen- dence.

The final expressions, used in ISIS, for the activity coeffici- ents, Equations (28a) (28b), and the osmotic coefficient, Equation

(29), include the functions for the ionic strength dependentterms, f, and Bid, and the effects for the mixed electrolyte terms. The forms used in ISIS were the same as the forms used by Harvie and

Weare (1980).

In 7m zMF+ E ma(2BMa + X milzilCma) a

I mc("mc E maomca) (28a) a

E mamaiOaa,m lzmIE E mcmacca a

In lx = ziF + X mc(2Bcx + E milzilccx)

E ma("Xa E mc0Xac) (28b) a

+ X E mcmc4cc'X lzXIX/ mcmaCca c

2 A°I3/2 (95 1) Il 1/2 (X mi) 1 + bI

E m m (1395 c a ca+ E mdzdcca) + c a

mcmc,(80 , , cc E ma0cca) + (29) c

E mame(19#aa' mclhaec)1 a

The term F in the Equations 28a, 28b, and 29 depends onlyon the

ionic strength and temperature as shown in Equation (30) (Pitzer,

1973).

2 F -A° In (1 + b/i) 1 + bji

I XmcmaBCa x x mcmcarce, E X mama'rca' (30) c a c

1/2(e2/11AT)3/2 A° 1/3(2nNodw/1000) (31)

The value of AO at 25 °C is included in Table 1. Beyer and Staples

evaluated the value of AO for water from 0 to 350 °C from saturation

to 1 kbar, and is an excellent source for informationon this

parameter (Beyer and Staples, 1986). The term b in Equation (30) is

an empirical parameter equal to 1.2 at 25 °C. The designation a

and E

distinguishable pairs of dissimilar anions (or cations) in thesystem

(Harvie and Weare, 1980).

The parameters nil and BOii in Equations (28), (29), and (30) 16

Table 1. Empirical Constants in the Pitzer Activity Coefficient Equations.

Symbol Value Restrictions

AIS 0.392 Water, 25°C

b 1.2 25°C

a 2 1-1, 1-2 electrolytes

al 1.4 2-2 and higher order electrolytes

a2 12.0 2-2 and higher order electrolytes 17 are defined from the second virial coefficients as shown in Equations

(22) and (23) and describe the interactions of pairs of opposite charged ions. They are functions of the ionic strength. Forms of

the functions, found by Pitzer to have the best fit,are given by

Equations (32) - (34) for 1-1 and 1-2 electrolytes (Pitzer, 1973).

Pitzer recommends a value of a 2 in these equations. For 2-2 and higher valence electrolytes, Bid and )345ij are given by Equations

(35) (37) where al - 1.4 and a2 - 12.0 (Pitzer, 1973).

BOmx 0(12: fl(ge-ali (32)

A(0) p(1)-tafT) BMMX P MX P MX5. 4s/ (33)

p(A?cg'(a/Y)/I (34)

BOmx fi(g)(+ +13(1,4e-a2di (35)

15(led P(Mig(allY)4- fl(Mig(a2/i) (36)

Bkx fl(iig.(aiji)/1+ )5(Aigt(a2jY)/I (37)

g(x)and g'(x)in Equations (32) to (37) are defined by Equations

(38)and (39):

g(x) - 2 [ 1 - (1 + x)e-x / x2 (38)

g'(x) - -2 [ 1 - (1 + x + 0.5x2)e-x ] / x2 (39) 18

The term Cij in Equations (28) and (29) is the single electro- lyte third virial coefficient as can be seen in Equations (24) and

(25). It is independent of ionic strength. Pitzer and Mayorga

(1973) have tabulated values for Crbij. Equation (40) gives the rela- tionship between Cij and trbij.

Cm = Cmx / 2 ilzmzxl (40)

The mixed electrolyte terms in Equations (28), (29), and (30),

Oij, and Oij, account for the second virial coefficients between ions of like signs, as was seen in Equation (26), andare

given by Equations (41) - (43).

00ii Eoij(i) 1E0ii(I) SBij (41) E0ii(i) (42)

EO (43) eij ijI ()

ThetermsEOWI) and E 8'..(1)in Equations (41) - (43) depend only on the charges of the ions and on ionic strengths andare nonzero only for cation or anion pairs whose charges differ in

magnitude. They are defined by Equations (44) - (48) (Pitzer, 1975,

Harvie and Weare, 1980). The term sOij is a constant for the

interaction of species ij.

zmzN EeMN(I) (J0(xMN) 13.5J0(xMM) (L5J0(xNN)) (44) 41

zmzN Eo E MN (I) - MN 2(31(xMN) °.5J1(xMM) °5J1(xNN)) (45) 81 where

x - 6zzAO MN MN (46) 19

1 1 x .10(x) x 1 + [1- exp( - e-Y)]y2dy (47) 4 x 0

1 1 co

J1(x) x - I[1 - (1 + e-Y)* exp( e-Y)] y2dy (48) 4 x 0

The evaluation of Equations (47) and (48) is discussed in Appendix A.

The third virial coefficients for mixed electrolytes are combined in Oijk, and are assumed to be independent of ionic strength. The triple interaction between ions of the same sign is not included because they are considered too small to be of significance (Pitzer, 1973). The third virial coefficients included

in the definition of*ijk are given in Equation (27).

The mixed electrolyte terms, 0 and 0, used in ISIS, utilized the breakdown of the like charged second virial coefficients presented by

Pitzer (1975). The choice of the appropriate values of 50 and 0 is mandatory for accurate results using ISIS. The values of s0 and 0 must be from sources that included E9 and E9, in the calculations

(Pitzer, 1975).

The activity of the solvent, water, in ISIS was calculated using the osmotic coefficient form of the Pitzer equations, Equation (29),

and related equations. The expression for the activity of water was broken into the mole fraction and activity coefficient components,

Equation (49), and then using Equations (20) and (21) the activity of water was related back to the osmotic coefficient. The final form of the activity of water is given by Equation (50) (Zemaitis et al,

1986). 20

In as - In xw + In yw (49)

55.55 (0 1) X mi In aw - ln ( ) (50) 55.55 + ) mi 55.55 21

RESULTS

The combination of the equation solving routine,SENECA2, with the activity coefficient predictor developed by Pitzer,resulted in the computer program ISIS. The parameters used in ISIS for the chemical potentials and the Pitzer ion interactionparameters were taken from the literature and used in the database forISIS. To test the code in ISIS three test caseswere studied. The three cases included single valence species, multivalent species, andtrace element species. The results from the test cases were compared to data from the literature for thesame solutions. A parametric study of the effects of activity coefficient, chemical potential,and

Pitzer parameter on the three testcases was performed to demonstrate the effect of these variables on the outcome of theprediction.

The databases used in ISIS were compiled from literature sources. The chemical potential datawas from two sources,

"Thermodynamic Properties of Minerals and Related Substancesat

298.15 K and 1 Bar Pressure and at Higher Temperatures"by Robie et al (1979) and from the Harvie and Wearepaper "The prediction of mineral solubilities in natural waters: the Na-K-Mg-Ca-C1-SO4-120 system from zero to high concentration at 25 C" (1980). Uncertainty information on the chemical potentialswas available in Robie's book and was used in the parametric study of the effect ofchemical potential. The Pitzer ion interaction coefficientswere obtained from a number of sources: Harvie and Weare (1980), and the Pitzer papers (Pitzer, et al, 1973, 1974, 1975, 1977, 1979, 1980, 1983). 22

A. Test Cases

The first test case examined KC1 solubility ina NaC1 and water solution at 25°C. The ISIS prediction using chemical potentials from

Harvie and Weare and experimental data from Silcock (Silcock, 1979) are plotted in Figure 2. In Figure 2 the fit of the ISIS prediction

to the experimental data is quite good over the entire concentration range with a mean of the absolute value of the relative deviations for Case 1 of 4.3%. The mean of the absolute value of the relative deviations is defined as (51)

n 1 Actual -ISIS Actual Error (51) n where Actual is the experimental values from the literaturesources,

ISIS is the value predicted by the program ISIS at thesame concentrations as the Actual, and n is the number ofdata points.

The ISIS prediction worked well at ionic strengthsgreater than 7 molal. ISIS accurately predicted the solid phases and theinflection point of this system.

The second case, solubility of NaC1 in MgC12and water at 25°C, is plotted in Figure 3. The ISIS prediction using chemical potentials from Harvie and Weare is plotted with the experimental data from Silcock (1979) for the same system. ISIS accurately predicts the equilibrium curve at the lower MgC12 concentrations,but at higher concentrations it separates slightly from the experimental values. This deviation takes place in the higher ionic strength regions, as the MgC12 concentration climbs from about 2 molalto about 6 molal (ionic strength from 8 to 17 molal). Figure 4 has Experimental KCI (solid) Silcock, $979 ISIS >, 4- 3 71 0 E 5

NaCI (solid)

I I I I I 1 2 4 8 NaCI molality

Figure 2. Solubility of KC1 in NaC1 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program. tv CO o Experimental Silcock, 1979 ISIS

NaCI (solid)

4 6 8 10 12 MgC12 molality

Figure 3. Solubility of NaC1 in MgC12 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program. Experimental 16 Silcock, 1979 .0" ISIS .0" Total Ionic Strength 12 o% Relative Error .0"

0 0 E

60 ,P): w A 40 cu A AA A ._> A _ 2020 A A . . A I I 0 8-9 5 0 I 2 3 4 MgC12 molality

Figure 4. Solubility of NaC1 in MgC12 and water solutions at 25°C (Silcock, 1979) calculated solu- bility from ISIS computer program. Ionic strength, and absolute value of the relative deviations between the ISIS prediction and the experimental points versus MgC12 concentration. 26 the ionic strength and the absolute value of thepercent relative error plotted together with the solubility data and the ISIS predic- tion. The relative error is defined by Equation (52).

Relative Error Actual -ISIS (52) Actual where Actual and ISIS have the same meaningsas in Equation (51).

Below an ionic strength of 8 molal the prediction is muchbetter, with the error running less than five percent. The mean of the absolute values of the relative deviations for Case 2 is 17%. ISIS predicted the proper solid phase.

Figure 5 is a plot of Case 3, CaSO4 and NaCl inwater. This system contains a slightly soluble salt, CaSO4, anda higher order

+2 +2 pair of species, Ca and SO4 . A higher order pair is the combination of a cation and anion that both have valencecharges greater than or equal to two. The experimental data are from Hershel and Slusher (1966), Block and Waters (1968), and Silcock(1979) at 25

C. ISIS predicts the solubility of the CaSO4 witha mean of the absolute value of the relative deviation of 3.9%, using chemical potentials from Harvie and Weare. The solid phase was accurately predicted over the concentration range. The program ISIS demonstrates its ability to predict the equilibrium of sparingly soluble salts in solutions that are up to two orders ofmagnitude larger in concentrations and at ionic strengths greater than 6 molal.

These tests demonstrate ISIS's performance. From the test cases it can be seen that ISIS works well in predicting the equilibrium state. 0.06 0 CaSO4-2 H2O

0.05

0.04

0.03 Experimental Silcock, 1979 ISIS 0.02

I

1 2 3 4 5 6 NaCI molality

Figure 5. Solubility of CaSO4 in NaC1 and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program. 28

B. Parametric Study

A parametric study of the effect of the different parameterswas conducted. The method of activity coefficient prediction, chemical potentials, and the Pitzer ion interaction parameterswere varied to determine the effect of these variables.

The activity coefficient predictor can have a major impacton the accuracy of the calculated equilibrium state. Three activity coefficient predictors were used with the testcases. The chemical potentials of the pure species were held constant. The three different activity coefficient predictorswere the Pitzer activity coefficient predictor, an extended Debye-Huckel activity coefficient predictor, and the ideal solution model where the activity coefficient was set equal to one. Errors for these comparisons were the absolute value of the relative deviation, Equation (51).

Figure 6 is a plot of Case 1, NaC1 and KC1, using the three different activity coefficient predictors. As described earlier the

Pitzer prediction fit the data very well with anerror of 4.3%. The extended Debye-Huckel model did not fit the dataas well and had an error of 26%. The ideal solution assumption actually fit the data better than the extended Debye-Huckel model in the high KC1 region, but the overall error was higher, 36%. In Figure 7, the plot of Case

2, NaCl and MgC12, a similar pattern developed with the extended

Debye-Huckel model performing better than the ideal solution model, except at low concentrations. The errors for the Pitzer, extended

Debye-Huckel, and ideal solution activity coefficient predictorswere rIcio A at b. °C" 211-.4 2kt-etsovoc;0-6.? 501)-1\:/°"3-. ttolt 02,1.2'tCt.AG-1:C1/2.7, sol-ekts. 561,3.C1'"act-i-`1Y-/coetticl-e 5°ii,vai:c,Cdelcte6e6 $1";1°C°1)te.st:;;C:e765CS1-6°. = Experimental Silcock, 1979

0 Ideal Solution E Model

z .

Extended 1/4 ...... Pitzer Model ,. iDebye-FILickel . ., Model .... a-

0 2 4 6 8 10 12 MgC12molality

Figure 7. Solubility of NaC1 in MgC12 and water solutions at 25°C (Cilcock, 1979) and calculated solubility from ISIS computer program using Pitzer, extended Debye-Huckel, and ideal solution activity coefficient prediction models. U) 31

17%, 240%, and 710%, respectively. In Figure 8, the CaSO4 in Nan solution case, the pattern was repeated. The Pitzer activity coefficient predictor was the best fit, the extended Debye-Huckelwas the next best, and the ideal solution assumptionwas the worst of the three. The errors were 3.9%, 36%, and 84%, respectively.

The effect of the activity coefficient predictor is large.

Errors, as defined by Equation (51), up to 700% were found withan ideal solution assumption. The extended Debye-Huckel and ideal solution activity coefficient predictors provided excellent reference points for the performance of the Pitzer activity coefficient predictor. The Pitzer activity coefficients produced errors almost an order of magnitude lower than the other two.

The effect of chemical potentials on the final predictionwas studied for the three cases. The chemical potentials given in Robie

(1979) for 25°C and those given by Harvie and Weare (1980)were used to predict the equilibrium states. The ion interaction parameters for the Pitzer equations were held constant. The difference between

Harvie and Weare's chemical potentials and Robie'swas that Harvie and Weare's chemical potentials were adjusted to fit the specific solubility data for the chemical system that theywere studying. The chemical potentials from Robie were from published chemical potentials which were extracted from a number of independent experimental measurements, without the extra specific data fitting step. Robie's data was supplied with uncertainty estimates and these were used only on Robie's data. If a solid species chemical potential was missing from Robie the value from Harvie and Wearewas used and not varied. 0.06

Experimental 0.05 Pitzer Model

0.04 a a ONES.. - ..woo. 0.03 we- Extended Debye-Hiickel 0 Model 0 c) 0.02

Ideal Solution 0.01 Model ...

I 2 3 4 5 6 NaCImolality Figure 8. Solubility of CaSO4 in NaC1 and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program using Pitzer, extended Debye-Huckel, and ideal solution activity coefficient prediction models. 33

In the KC1-NaC1 system, Case 1, the results from the study can be seen in Figure 9. The chemical potentials from Robie and

Harvie and Weare produce curves very close to each other, especially at high NaCl concentrations. Table 2 lists the chemical potentials, normalized by RT to make the value dimensionless, used incase 1. In examining Table 2, the relative differences between the values of normalized chemical potentials given by Robie and those given by

Harvie and Weare for Na+, K+, Cl-, and NaCl are all in the order of

0.004% or less. The percent difference is defined by Equation (53)

AHW ARohie Difference = (53) PHW wherepHw is the chemical potential used by Harvie and Weare, and

Robie wasthe chemical potential reported by Robie. KC1(solid),on

the other hand, has a relative difference between the Robie valueand

the Harvie and Weare value of 0.02%, almostan order of magnitude

larger than the other species. This is also the solid species

present in the section of the equilibrium curve where the deviation between the plots using Harvie and Weare's and Robie's chemical

potentials is the greatest.

The plots of the equilibrium curves with the normalized chemical

potentials using Robie's data plus and minus the uncertaintyare also

on Figure 9. These curves are offset almost equally on either side

from the equilibrium curve for Robie's data without correction for

the uncertainty. The uncertainty in the chemical potentials was for

all species in the order of 0.04. This difference increased the 0 E U Experimental; Silcock, 1979 c Robie, 1979 Harvie and Weare, 1980 Robie plus uncertainity Robie minus uncertainity

I I i i 0 2 4 8 NaCImolality

Figure 9. Solubility of KC1 in NaC1 and water solutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer program using the Pitzer activity coefficient predictor and varying chemical potentials. 35 error, Equation (51), in the curves from 4.7% for Robie's data to

8.3% for Robie's data plus its uncertainty and 5.0% for Robie's data minus the uncertainty. The reason for the lower deviation on Robie's data minus the uncertainty is the sign of the error terms.

Table 2. Comparison of Chemical Potentials Used in Case 1

M /RT at 25°C (dimensionless)

SPECIES Harvie& %Relative Robie Robie Robie+ Robie- Weare difference uncertainty

Na+ -105.651 0.0033 -105.6475 0.0343 -105.6132 -105.6818 Cl- -52.955 0.0041 -52.95285 0.0444 -52.90845 -52.99725 H+ 0 NA 0 0 0 0 OH- -63.46436 0 -63.46436 0.0363 -63.42806 -63.50066 K+ -113.957 0.0032 -113.9533 0.0484 -114.0017 -113.9049 H2O -95.6635 0.0037 -95.66 0.0339 -95.6261 -95.6939 NaCl -154.99 0.0021 -154.9868 0.0444 -154.9424 -155.0312 KC1 -164.84 0.0206 -164.8061 0.0565 -164.7496 -164.8626

In Case 2, MgC12 and NaC1, the differences in the equilibrium curves between Harvie and Weare's chemical potentials and Robie's values are insignificant, as seen in Figure 10. The errors for the

two curves are 15.9% for Robie's data and 16.7% for Harvie and

Weare's data. Table 3 lists the chemical potentials for thecase,

and the relative difference between the two sets of chemical potentials. In Table 3, the relative differences are all 0.004% or

less. No significant shift in the equilibrium curves would be

expected with this small difference. Experimental Silcock, 1979

T 64-. 4 o E 3 All Predicted Equilibrium Curves L5a Z

1

2 4 6 8 ND 12 MgC12molality

Figure 10. Solubility of NaC1 in MgC12 and watersolutions at 25°C (Silcock, 1979) and calculated solubility from ISIS computer programusing the Pitzer activity coefficient predictor and varying chemical potentials. 37

Table 3. Comparison of Chemical Potentials Used in Case 2.

p/RT at 25°C (dimensionless)

SPECIES Harvie &%Relative Robie Robie Robie+ Robie- Weare difference uncertainty

Na+ -105.651 0.0033 -105.6475 0.0343 -105.6132 -105.6818 Cl- -52.955 0.0041 -52.95285 0.0444 -52.90845 -52.99725 H+ 0 NA 0 0 0 0 OH- -63.46436 0 -63.46436 0.0363 -63.42806 -63.50066 Mg+2 -183.4682 0.0038 -183.4612 0.6736 -182.7876 -184.1348 H2O -95.6635 0.0037 -95.66 0.0339 -95.6261 -95.6939 NaC1 -154.99 0.0021 -154.9868 0.0444 -154.9424 -155.0312 MgC12.6W -853.1 0 -853.1 0 -853.1 -853.1 MgC12 -238.7194 0 -238.7194 0.2195 -238.4999 -238.9389 W - waters of hydration

Table 4. Comparison of Chemical Potentials Used in Case 3.

p/RT at25°C (dimensionless)

SPECIES Harvie& %Relative Robie Robie Robie+ Robie- Weare difference uncertainty

Na+ -105.651 0.0033 -105.6475 0.0343 -105.6132 -105.6818 Cl- -52.955 0.0041 -52.95285 0.0444 -52.90845 -52.99725 H+ 0 NA 0 0 0 0 OH- -63.46436 0 -63.46436 0.0363 -63.42806 -63.50066 Ca+2 -223.3 0.0036 -223.2919 0.4841 -222.8078 -223.776 SO4 -2 -300.386 0.0035 -300.3754 0.0484 -300.327 -300.4238 H2O -95.6635 0.0037 -95.66 0.0339 -95.6261 -95.6939 NaC1 -154.99 0.0021 -154.9868 0.0444 -154.9424 -155.0312 CaSO4 -533.8 0.1204 -533.1574 1.6878 -531.4696 -534.8452 CaC12.6W -893.65 0 -893.65 0 -893.65 -893.65 CaSO4.2W -725.67 0.0966 -724.969221.8564 -723.11282 -726.82562 W- waters of hydration 38

The comparison between the equilibrium curves for Robie's chemi-

cal potentials including the uncertainty in the dataas reported is

also plotted in Figure 10. The uncertainties are given in Table 3.

The only uncertainty that is considerably different from therest is +2 the uncertainty for Mg , which is an order of magnitude greater than

the other values. The uncertainty for MgC12 (solid) is also larger,

but since it does not precipitate the mineral value is not used in

the equilibrium calculations and therefore it does not affect the

prediction. Even with this single large uncertainly the errors of

the curves differ by less than three percent. The errors for Case 2

with the uncertainties included were 15.9% for Robie's chemical

potentials, 14.4% for Robie plus the uncertainty, and 18.8% for Robie

minus the uncertainty.

In Case 3, NaC1 and CaSO4, the difference between the predicted

equilibrium curves using the chemical potentials used by Harvie and

Weave and those provided by Robie is significant. Figure 11 is a plot of the equilibrium curves using the different chemical potentials. The errors, Equation (51), for the different equilibrium

curves were 49% for Robie's chemical potentials and 3.9% for Harvie and Weare's chemical potentials. Table 4 lists the relative

difference between these sets of chemical potentials. It is on the order of 0.004% or less for all the species except for CaSO4 and

CaSO4.2H20 which are almost a tenth of a percent. The solid phase present for this case was CaSO4.2H20 (gypsum). This is similar to

the findings in Case 1, where the solid species has the largest difference between the sets of chemical potentials, and is the cause of the shifts between the two equilibrium curves. 0.16

0.14 Robie plus

0.12 6 0.10 Robie

111 WMMIP 0ct0.08 AMMO. 11=0 0 .0 Experimental Harvie c.) 0.06 aWeare \ ...... 00...... cm ...... 0.04

0.02 Robie minus

1 1 2 3 4 5 Nadi molality

Figure 11. Solubility of CaSO4 in NaC1 and water solutions at 25°C (Block and Waters, 1968; Marshel and Slusher, 1966; Silcock, 1979) and calculated solubility from ISIS computer program using the Pitzer activity coefficient predictor and varying chemical potentials. 40

The effects of the uncertainties reported by Robieare also significant in this case. The error in the predicted solubility of

CaSO4 for the reported chemical potentialwas 49%, for the reported plus the uncertainty the error was 270%, and for thereported minus the uncertainty it was 32%. From Table 4 the uncertainties of most of the species were on the order of 0.05or less. Two species that were present at equilibrium had larger uncertainties, Ca+2and

CaSO4.2H20. They were 0.4841 and 1.8564, respectively. The solid phase again appeared in the list of species that have the large uncertainty in chemical potential.

An estimate of the result of a change in the chemical potential can be made by examining the effects on a single salt. Assuming ideal solution behavior, and combining the Gibbs freeenergy change, mass action, and mass balance equations an estimate of the concentration of the single salt in solutioncan be made, Equation

(54).

2 ln m - 1E pt. RT i (54) where the concentration of the salt, m, isa function of the Gibbs free energy of the reaction. The valence charge on the anion and cation of the salt is restricted toone for Equation (54). Applying

Equation (54) using first Robie's chemical potentials and thenwith the chemical potentials with the uncertainty addedto them results in two concentrations that can be compared relative to each other.

In Case 1 the values for the relative change in the NaCl and KCl concentrations as the chemical potentials were switched from Robieto

Robie plus uncertainty were 2% and 3%, respectively. This relative 41 change compares well with the change in the errorsas defined by

Equation (51) of 48 as the uncertainty was added. When a similar approach was used on Case 2 the resultwas 2% for NaCl. This rela- tive change is larger than that foundover the entire equilibrium curve when the uncertainty is added, which is 2%. In Case 3 the relative change in the predicted concentrationas the uncertainty is added to the chemical potential (Equation 54) is 78%. The change in the equilibrium curve as the uncertaintiesare added was 220%.

Considering the assumptions used in this approach the estimate ofthe change in the equilibrium curve as the individual chemicalpotential change can estimated by studying the overall Gibbs freeenergy change for the reactions.

The effect of the Pitzer ion interaction coefficientson activity coefficients was studied last. The Pitzer activity coefficient model calculates activity coefficientsgiven temperature, pressure, and the molalities of the species in solution. Solubility data, available in the literature,was used as input data to the

Pitzer model for calculating the activity coefficients. Only activity coefficients were calculated in thissection at the parametric study. A computer program, PITZER (Appendix G),was written to calculate activity coefficients given the equilibrium conditions of a system, and was used for calculations in this section.

Mean activity coefficients were calculated first with all the ion interaction parameters available. This was used as the reference line. The next step was to set certain ion interactionparameters to zero and to then recalculate the mean activity coefficients, andto 42 compare the new mean activity coefficients to the mean activity coefficients calculated using all the ion interaction parameters.

The groups of parameters set to zero were first, 0, then 0 and 0, and finally 0 and Cmx. The reason for these choices was that they represent different interactions in the activity coefficient predictor. 0 is the term for the interaction of three different ions in solution, and is one part of the third term in the virial expan- sion. Cmxis the remainder of the third virial coefficient, it deals with two ions the same and the third a different ion. The third virial coefficient for all three ions the same was assumed by Pitzer

to be small and was not included (Pitzer, 1973). 19 is the interac- tion term for ions of like sign. It is composed of second virial coefficient terms. The combination of 0 and Cmxcovers all the third virial coefficient terms. By setting these terms to zero, the virial expansion is shortened to two terms, and the need for the third virial coefficient can be examined. The combination of 0 and 0 covers all the mixing terms for systems of more than one salt is in solution, the three different ion interaction terms, 0, and the ions of the same charge interaction term, 0. Solubility data for a single salt are more readily available in the literature thanare data for two salts with a common ion. The latter are needed to determine the ion interaction parameters 0 and O. Therefore, the combination of 0 and 0 is often unavailable.

For the work on the effect of the ion interaction parameter, the relative error is defined by Equation (55).

Relative Error (V- V ') (55) V 43

Where V is the mean activity coefficient with all the ioninteraction

parameters present, and V' is the mean activity coefficient with

selected parameters set to zero.

Figures 12 through 17 are the plots of theerror in the mean

activity coefficient, as compared to themean activity coefficient with all the ion interaction parameters available,versus the ionic

fraction. The ionic fraction is the contribution of that speciesto

the total ionic strength, as defined by Equation (56).

2 2 0.5 * [mmzm + mxzx] If, (56) I

Where mm is the molality of the cation of salt MX insolution and mx

is the molality of the anion in solution that balances thecharge with the cation. In all of the figures the error introduced by the

omission of 0, and of 0 and C goes tozero as the ionic fraction goes

to one. This is expected since they bothare terms for systems of

more than one salt, and, at an ionic fraction ofone, only the one

species exists. The error from these terms increasesas the ionic

fraction decreases. The largest error in the mean activity coeffi-

cient from the omission of these terms is inexcess of 80%. The

other combination of terms, 0 and C mx'are the third virial coeffi-

cient terms. The error introduced when they are assumed to bezero

does not always approach zero as the ionic fractiongoes to one. The

effect of these combinations of the third virial coefficientcannot

be considered insignificant. They introduce errors up to 80% in the

mean activity coefficient. 44

From the parametric study on the effects of the different variables on ISIS it was found that the Pitzer activity coefficient predictor is by far more accurate than either the extended Debye-

Huckel or the ideal solution assumption. The increase in the accuracy of the activity coefficient prediction can be lost with poor chemical potential data. In Case 3, a difference of 0.7 in the chemical potential divided by RT increased theerror from 3.9% to

49%. The assumption that certain ion interaction parametersare zero can also lead to significant errors, especially in the trace element case, Case 3, where the errors in the mean activity coefficientwere up to 85%. 45

kk=0,Cmx= 0

0 0cc cc cc 0 "c+1

stf=0,9=0

0.2 0.4 0.6 0.8 I 0 IONIC FRACTION Figure 12. Percent error in mean activity coefficientof Hadversus Nadi ionic fraction for Case 1.

IONIC FRACTION Figure 13. Percent error in mean activity coefficient of KC1versus KC1 ionic fraction for Case 1. 46

...... e .:Ca... 0 ' rr20 / 0 / CC / CC L1 4 i ti,o,Cpvix z 0 +1 - 40 =0, 8 =0 - - tir = 0

- 60 0 0.2 0.4 0.6 0.8 1.0 IONIC FRACTION Figure 14. Percent error in mean activity coefficientof NaC1 versus NaC1 ionic fraction for Case 2.

40

30

20

10

0

-10

-20 0 0.2 0.4 0.6 0.8 1.0 IONIC FRACTION Figure 15. Percent error in mean activity coefficient of MgC12 versus MgC12 ionic fraction for Case 2. 47

6

4 o, cmx= o %Ina,6 =0

-2

0 0.2 0.4 0.6 0.8 1.0

IONIC FRACTION Figure 16. Percent error in mean activity coefficient of NaC1versus NaC1 ionic fraction for Case 3.

80

75 60

0 lx40

41

20

0 0.2 0.4 0.6 0.8 1.0 IONIC FRACTION Figure 17. Percent error in mean activity coefficient of CaSO4 versus CaSO4 ionic fraction for Case 3. 48

CONCLUSION

The computer program ISIS can accurately predictthe equili-

brium state of aqueous, inorganic electrolytesystems. The model

incorporated Pitzer's activity coefficient predictor anda two step

Gibbs free energy minimization routine. Three test cases were

studied. The test cases included trace element species, highionic

strength systems, and higher valence species. The errors in the equilibrium prediction for the testcases ranged from 3.9% to 17%.

The program ISIS accurately predicted the saltsolubilities, soluble

and insoluble amounts, precipitate compositions,and single ion

activity coefficients.

A parametric study of the variableswas performed on the test

cases. The variables studied were the activity coefficient

predictor, the chemical potential, and the ioninteraction parameters.

The effect of the activity coefficient predictorwas signifi-

cant. The two other activity coefficient predictors usedwere the

extended Debye-Huckel and the ideal solution assumption,where acti- vity coefficients are assumed equal toone. The errors for the

extended Debye-Huckel prediction ranged from 26%to 240%. The ideal

solution assumption errors ranged from 36%to over 700%. The use of

an activity coefficient predictor capable of working in high ionic

strength regions is necessary to achieve accurate equilibriumpredic-

tions.

The errors introduced into equilibrium predictions withminor variations in the chemical potentials were surprisingly large. The 49 differences in the solid species' chemical potentialsappeared to be the largest in the three test cases studied. The effect of minor variations in the chemical potentials appearedto be the largest on the trace element species, where the relativeerrors increased from

3.9% to 49% with a relative change of onlya tenth of a percent in the chemical potential of a single species. Accurate chemical potentials are essential if accurate equilibrium predictionsare to be made.

The ion interaction terms were studied to determine the effect of assuming a value of zero for unavailable ioninteraction parameters. The ion interaction parameters were grouped togetherto study the effect of the two salt mixing parameters, 0and 9, the third virial coefficient terms, 0 and Cam, andthe three ion interaction term, 0. These groups of ion interaction parameters are the most likely to be difficult to find since they require the use of two salt solubilities or activities to calculate. The error

in the mean activity coefficients approachedzero as the ionic fraction approached one when the mixing terms and the threeion

interaction term, 0, were assumed to be zero. The third virial coefficient terms, 0 and Cam, displayed significant effects throughout the entire range. Errors up to 80% were introduced with this term held to zero. All the terms studied had significant effects on the mean activity coefficients. The third virial coefficient and the mixing terms need to be included to produce accurate equilibrium predictions. 50

FUTURE WORK

The current database of ISIS needs to be expanded. Ions of

specific interest to the pulp andpaper industry, and possible precipitates of these ions need to be included. The chemical potentials of these species need to bevery accurate if ISIS is to be used successfully in predictingtrace element solubility. The temperature dependence of these chemical potentials needsto be included for use with systems not at 25 °C. A method to determine the needed accuracy of the chemical potentialswould be of great value.

In this work a tenth of a percent relativeerror in a solid species' chemical potential causes an increase in theerror of over 40%. The ion interaction database also needs to beexpanded. The importance of the third virial coefficient and themixing terms was demonstrated in the study. Lack of these coefficients and ofa temperature dependence for them will severely limitthe use of the ion interaction models for activity coefficientprediction.

The inclusion of ISIS or similarprograms into a steady state simulator for use in the pulp andpaper industry is recommended.

This would allow studies ofnon-process element build-up and scaling problems, before process changes or feed stockchanges are made. It would reduce the costly experimentation oftenrequired before these changes are implemented. 51

BIBLIOGRAPHY

Bennett, A.J., J.D. Gillett, and H. Wunder, Appita, 35(5), 383 (1982).

Beyer, R.P. and B.R. Staples, Journal of Solution Chemistry,15(9), 749 (1986).

Block, J. and 0.B. Waters, Journal of Chemical andEngineering Data,

13(3) , 336 (1968).

Carnahan, B., H.A. Luter, and J.0. Wilkes, Applied Numerical Methods,

John Wiley and Sons, New York (1969) .

Chen, C-C., H.I. Britt, J.F.Boston,and L.B. Evans, AIChE Journal, 25(5), 820 (1979).

Eugster, H. P.,C.E.Harvie,and J.H.WeareGeochimica et Cosmochimia Ll 44,1335(1980).

Eugster, H. P.,C.E.Harvie,and J.H.Weare, Geochimica et Cosmochimia Acta, 46,1603(1982).

Feber, R. and J.F.Kerrisk,SENECA2internal documentation, Los Alamos Scientific Laboratory, (1980).

Frederick, W.J., B. Kelly, H.C. Kim, H.J. McIntyre,and J.P. Danko, "Modeling electrolyte behavior in pulp andpaper processes," Chemical Engineering Technology in Forest ProductsProcessing. Vol. 2, B. Crowell, Editor, AIChE Forest ProductsDivision, Tacoma, WA (1988).

Harvie, C.E. and J.H. Weare, Geochimica et CosmochimiaActa, 44, 981 (1980).

Ingle, S.E., M.D. Schuldt, and D.W. Schults, "AUser's Guide for REDEQL.EPAK, "Environmental Protection Agency reportEPA- 600/3- 78 -024 (February 1978).

Kelly, B. and W,J. Frederick, Jr., "An equilibriummodel for trace element solubility in aqueous inorganic solutions," Applications of Chemical Engineering Principles in the ForestProducts and Related Industries. Vol. 1,F. Kayihan and B. Krieger-Brockett, Editors, AIChE Forest Products Division, Tacoma, WA (1986).

Kerrisk, J.F., Los Alamos Scientific LaboratoryReport No. LA -8851- MS, UC66b (May 1981).

Ma, Y.H. and C.W. Shipman, AIChE Journal18(2), 299 (1972).

Hershel, W.L. and R. Slusher, Journal of Physical Chemistry,70(12), 4015 (1966). 52

Naphtali, L.M., Journal of Chemical Physics 31, 263 (1959).

Naphtali, L.M., "Computing Complex ChemicalEquilibria by Minimizing Free Energy " Kinetics. Equilibria andPerformance of High

Temperature Systems G.S. Bahn and E.E. Zukoski, ed., Butterworths, Washington (1960).

Pitzer,K.S.,Journal of Physical Chemistry,77(2), 268 (1973).

Pitzer,K.S.,Journal of Solution Chemistry4(3), 249 (1975).

Pitzer,K.S., Accounts of Chemical Research 10, 371 (1977) .

Pitzer,K.S.,"Theory: Ion Interaction Approach,"in Activity Coefficients in Electrolyte Solutions, R.M. Pytkowicz, ed. CRC Press, Inc., Boca Raton, FL (1979).

Pitzer, K.S., Journal of the American ChemicalSociety 102, 292 (1980).

Pitzer, K.S. and M. Conceicao P. de Lima Journal of Solution

Chemistry, 12(3) , 187 (1983).

Pitzer, K.S. and J.J. Kim, Journal of theAmerican Chemical Society, 96 (18), 5701 (1974).

Pitzer, K.S. and G. Mayorga, Journal of PhysicalChemistry 77 (19), 2300 (1973).

Plummer, L.N., B.F. Jones, and A.H. Truesdell,"WATEQF: A FORTRAN IV Version of WATEQ, A Computer Program for CalculatingChemical Equilibrium of Natural Waters, Users Guide," U.S. Geological Survey report USGS-WRI-76-13 (September 1976) .

Rafal, M. and S.J. Sanders, "Process SimulationInvolving Electro- lytes," Paper No. 29e, presented at the AIChE 1984Spring National Meeting, Anaheim, CA, May 20-23.

Robie, R.A., B.S. Hemingway, and J.R. Fisher,Thermodynamic Proper- ties of Minerals and Related Substancesat 298.15 K and 1 Bar (10DPascals) Pressure andat Higher Temperatures Geological Survey Bulletin 1452 (1978).

Silcock, H.L., ed., Solubilities of Inorganic and OrganicCompounds. Volume 3. Part 3. Ternary and Multicomponent Systems of Inorganic Substances Pergamon Press, New York, NY (1979) .

Silvester, L.F. and K.S. Pitzer, Journal of Physical Chemistry,81 (19), 1822 (1977).

Smith, W.A., and R. W. Missen, Chemical Reaction EquilibriumAnaly- sis: Theory and Algorithms John Wiley and Sons, New York (1982). 53

Ulmgren, P., Pulp and Paper Canada, Transactions TR 27-32 (June

1982) .

Van Zeggeren, F.and S.M. StoreyThe Computation of Chemical Equilibria Cambridge University Press, New York,NY(1970).

Zemaitis, J.F.,D.M. Clark, M. Rafal, and N.C. Scrivner, Handbook of AqueousElectrolyte ThermodynamicsAm. Ins. Chem. Engrs. (1986). APPENDICES 54

APPENDIX A

CALCULATION OF THE ELECTROSTATIC MIXING TERMS

The evaluation of the integrals for the effects of the higher- order electrostatic terms, Equations (47) and (48),was needed in

ISIS. The integrals and related functions were evaluatedas a function of the variable x and the results fit toa polynomial

series for use in ISIS.

The functions, Equation(47) and (48),

1 1 e-y)]y2dy JO(x) 1 + j [1- exp( (47) 4 x 0

1 1

J1(x) x cr1 - (1 + e Y)* exp( - e-Y)] y2dy (48) 4 x OL were developed by Pitzer to describe unsymmetrical mixing excluding the short range forces (Pitzer, 1975).

The method used to evaluate the functionswas an IMSL subroutine

DCADRE, which used a cautious adaptive Romberg extrapolation. The limits of integration were varied froma lower limit of 0.01 to 0.001 and upper limits of 30 to 50. The effects of the limits of integration on results were minimal.

The results from the Romberg integrationwere then used to form

the polynomial form of the equations used in ISIS. The polynomial was a nine point polynomial that was reduced using a Chebyshev economization (Carnahan, 1969) on the natural logarithm of the

Equations (47) and (48), this is similar to the approach usedby 55

Harvie and Weare (Harvie and Weare, 1980). The equations had a limiting value at high x and were set to that valueafter the polynomial version had converged to that limit. The final forms of the equations used in ISIS are given below forEquations (47) and

(48) respectively. For Equation (47):

if x < 2000, then

J0(x) = exp(-2.150403 + Y(1.378649 + Y(-0.0603501+ Y(-

0.7719421e-04 + Y(0.7749758e-03 + Y(0.2538732e-04+ Y(-0.1589227e-04

+ Y(-0.1884598e-06 + Y(0.2367578e-06 + Y(-0.132147)))))))))) if x > 2000, then

J (x) 0 0.25x 1. (54) For Equation (48): if x < 800, then

J1(x) exp(-0.1829293 + Y(0.1291033e+01 + Y(-0.6440535e-01+

Y(0.2021252e-02 + Y(0.1043347e-02 + Y(-0.3247351e-04+ Y(-0.2225391e-

04 + Y(0.9590904e-06 + Y(0.2592198e-06+ Y(-0.1874422e-07)))))))))) if x > 800, then

J(x) .25x 1 (55) where Y = In x.

The average relative difference between thepolynomials,

Equations (54) and (55), and those values presentedby Pitzer

(Pitzer, 1975) was 0.013% for Equation (54)and 0.042% for Equation

(55). 56

APPENDIX B

AVERAGE ISIS RUN TIMES

ISIS Run Times on Cyber 170 Model 720 Computer.

Case Number Average run time (CPU second)

1 2.13

2 8.80

3 12.84 57

APPENDIX C

OPERATIONS MANUAL FOR ISIS

Flow diagrams and database modification instructions for the computer program ISIS

by

Barry Kelly

Oregon State University

November, 1987 58

TABLE OF CONTENTS

Page

INTRODUCTION 61

GENERAL FLOW OF THE PROGRAM ISIS 62

DATABASE SUBROUTINES AND FILES 69

SUMMARY 84

BIBLIOGRAPHY 85 59

LIST OF FIGURES

Figure Page

C.1 SENECA2 flow sheet 63

C.2 Subroutine MINI as called in SENECA2 65

C.3 Subroutine GAMMA, activity coefficient predictor 66

C.4 Subroutine NEWSON as called in SENECA2 67 60

LIST OF TABLES

Table Page

C.1 Description of selected subroutines in ISIS 68

C.2 Values to be used for the variable IPHASE 71

C.3 Format for the first line of the database CHDATA 71

C.4 Format for the second line of the database CHDATA 71

C.5 Format for the third line of the database CHDATA 76

C.6 Format for the fourth line of the database CHDATA 76

C.7 Format for input to the database CONDATA 78

C.8 Format for input to the first section of the database PITDATA 82

C.9 Format for input to the second section of the database PITDATA 83 61

INTRODUCTION

The computer program ISIS is a predictor

for aqueous inorganic solutions. ISIS is the combination of the program SENECA2 with a more advanced activity coefficient predictor model developed by Pitzer and coworkers (Pitzer, 1979). SENECA2 is a modified version of the the program SENECA originally developed by Ma

and Shipman (Ma, 1972), and later modified by Feber and Kerrisk

(Feber, 1980; Kerrisk, 1981).

The purpose of this manual is to introduce the user to the

operational details of the program. The subjects covered are: the

general flow of the program, including a description of the various

subroutines, an overview of the three database files, and the

modification of the three database files to includenew species.

This manual is meant to supplement the User Manual for ISIS, and

should be used in conjunction with the User Manual.

A background in the FORTRAN computer language, thermodynamics,

and the use of the program ISIS is recommended. The information for

this manual was collected from technical journals,computer manuals,

communications with previous researchers, and myown experience with

the program. 62

GENERAL FLOW OF THE PROGRAM ISIS

ISIS is composed of five main subroutines, five data collection subroutines, and a large number of other minor subroutines and functions. The main subroutines SENECA2, MINI, TEST, GAMMA, and

NEWSON are the keys to understanding the program. They call the other subroutines and functions and manage the flow of theprogram.

The data collection subroutines are used to collect the information needed from the databases, and will be discussed in the sectionon the modification of the information contained within them. The other subroutines and functions are single task oriented, and will only be be discussed partially.

The main subroutine is SENECA2. SENECA2 drives all the other subroutines (see Figure C.1). In SENECA2, the program reads most of

the input file information, calls the data collection subroutines,

calls the other main subroutines, checks forconvergence, and prints

the results.

The next main subroutine is MINI. MINI is the Gibbs free energy minimization routine for the program. The program is designed around

a two step solution to the chemical equilibrium problem. The first

step is a global method to find the equilibrium point by a Gibb's

free energy minimization. This solution is then used as a starting

point for the solution to the non-linear system of equations bya

Newton-Raphson equation solver. This technique circumvents the

problems with using either approach alone. The inaccuracies of the

minimization are corrected by the Newton-Raphson non-linear equation

solver, and the convergence problems of the non-linear equation 63

/Read input Terminal and output input by file names user

/Read input file (Input information file

I Call (SENECA2) SENECA2

/Read more Input information file from input) file

Database Call file GETCHEM CHDATA

Call BRINUP STOP

Call Continued GAMSET

Continued

Figure C.1: SENECA2 flowsheet 64 solver are corrected by using the minimization routines answersas an initial guesses (Ma, 1972).

TEST is the next main subroutine called. TEST is used to select new sets of key species if a key species goes to zero in the prior pass through MINI. In MINI, unstable phases and species that fall below the tolerance of the program will be removed. If these species are a member of the key species then a new set of key species must be formed to continue the minimization routine, see Figure C.2.

MINI has two steps in its convergence. The initial step is to compute the minimum point without any activity coefficient calculations, the activity coefficients would be set to one until the minimization is converged. The next step is solve the minimization problem with the activity coefficient predictor engaged. These activity coefficient calculations are taken care of with the subroutine GAMMA. The Pitzer (Pitzer, 1979) method of predicting the activity coefficients is used in GAMMA. The most recently calculated equilibrium point is used as an initial starting point for the second step of the minimization problem (see Figures C.2 and C.3).

The last of the major subroutines is NEWSON. This is the

Newton-Raphson non-linear equation solver for the program. After

MINI has converged with the activity coefficient calculations

initialized, SENECA2 calls NEWSON to solve the system starting with

the final solution from MINI (see Figure C.4). NEWSON operates with

the activity coefficient predictor on all through its calculations.

There are a number of other minor subroutines that are described

in Table C.1. 65

Continued SENECA2 flowsheet

1

Select elements in most stable forms as key species

Start activity coefficient Call calculations MINI

Activity coefficient MINI calculation Converged on? YES

YES

Remove species that went to Call zero -prepare TEST for NEWSON

Continued

Figure C .2: Subroutine MINI as called in SENECA2. 66

(GAMMA)

Initialize storage area

Call

SWITCH

Call

ACTIVY

Water activity calculated in function WATRACT

Coll

SWITCH

(Re

Figure C.3: Subroutine GAMMA, activity coefficient predictor. 67

Figure C.4: Subroutine NEWSON as called in SENECA2. 68

TABLE C.1: DESCRIPTIONS OF SELECTED SUBROUTINES IN ISIS

SUBROUTINE DESCRIPTION

BRINVP Calculates the adjusted temperature for theaqueous solutioninthe problem and calls PSAT.

PSAT Calculates the vapor pressure of water at the temperaturecalculated in BRINVP.

ADVAP Adds water vapor to the list of species setting the appropriatespecies variables to the new values.

COMPSET : Adjusts the amounts of elements and species toaccount for the water that has vaporized from the solutionto the gas phase.

MATINV : Inverts the matrix A.

GAMSET : Recalls the information from the Pitzer ion interaction databases, CONDATA and PITDATA.

SWITCH : Separates anions, cations, and different phasespecies into there appropriate groups and the information forthe calculation of the activity coefficients. It is an interface between the SENECA2 and GAMMA.

ELNACT : Calculates the electron activity for the oxidation- reduction reactions. Please see the User Manual for further details.

ACTIVY : Calculates the activity coefficients of the ionic species.

WATRACT : Calculates the activity of water from the osmotic coefficient.

REFERENCE: Feber, R. and Kerrisk, J. SENECA2 internal documentation. Los Alamos Scientific Laboratory, New Mexico, 1980. 69

DATABASE SUBROUTINES AND FILES

The first data collection subroutine is GETCHEM. GETCHEM accesses the database file CHDATA to retrieve information about the species in the system, such as chemical potential,charge, and elemental composition. The database CHDATA contains all the information about the species except the Pitzer ioninteraction parameters.

The next data collection subroutine is CONDATA. CONDATA retrieves information from the database file CONDATA. The information in this file helps find the ioninteraction parameters.

It is a intermediate file that contains the locationof the ion interaction parameters but not their values.

PITDATA is the last data collection subroutine. PITDATA retrieves the Pitzer ion interaction parameters from thedatabase file PITDATA.

The addition of information to the database shouldbe done with extreme care. If the wrong information is entered, the chances of having a properly converged solutionare zero. First, the variables that are to be entered will be discussed; then theformat for the data in the database file will be shown.

CHDATA has all of the chemistry data for theprogram. The file has at least three lines of data for all species. Solid species have four lines of data.

The first variable is the species identification number,IDSP, which is the number used to identify the species in theinput file.

This variable is also used in the database file CONDATA. The next 70 set of variables are the species name, ANANE(J), BNAME(J), and

CNAME(J). The name is split into three variables of four characters for each variable. The three variables are used together to form the name of the species in the source code of ISIS. After the name variables is the phase identification number, IPHASE. The value of

IPHASE depends on what phase the species would be in, whether gaseous, liquid or solid. Table C.2 shows what number indicated which phase. Next was the species charge variable Z(J), this vari- able gave both the charge magnitude and sign. Next was the activity parameter AZERO(J), which was used in SENECA2 to calculated the activity coefficient. This variable is from the extended Debye-

Huckel model of the activity coefficient and is no longer needed for the program. After that is the water coefficient, H20, which is the number of water molecules involved during the formation reaction for this species, it can be either positive or negative. This must be calculated from the reaction stoichiometry, developed later in the file. ELEC(J) is the last variable on this line and is the number of electrons involved in the formation reaction of this species. This variable is similar to the water coefficient, and is calculated from reaction stoichiometry. The format for the first line is shown in

Table C.3. The first line in CHDATA for Ca+2would look like:

5 CA++(AQ) 2 2.0 6.0 0.0 71

TABLE C.2: Values to be used for the variable IPHASE. Kerrisk, J. F., Private communications, 1985.

PHASE VALUE OF IPHASE(J)

Gaseous 1

Aqueous 2

Solid 3

TABLE C.3: Format for the first line of input to the database CHDATA. Kerrisk, J. F., Private communications, 1985.

COLUMN NUMBERS DESCRIPTION

1 - 5 Species identification number, ISDP

6 8 No data

9 - 20 Species name, ANAME(J), BNAME(J), CNAME(J)

21 - 25 Phase identification, IPHASE(J)

26 30 Species charge, Z(J)

31 - 35 Activity parameter, AZERO(J) (not used)

36 40 Water coefficient, H20(J)

41 45 Number of electrons, ELEC(J)

TABLE C.4: Format for the second line of the database CHDATA. Kerrisk, J. F., Private communications, 1985.

COLUMN NUMBERS DESCRIPTION

1 - 5 Species identification number, IDSP

5 10 Number of non-zero coefficients in the A matrix for this species, ICT

11 15 Value of the first non-zero coefficient in the A matrix, XRD(1)

16 20 Position of first non-zero coefficient in A matrix, IXRD(1) 72

The values of XRD, and IXRD are repeated in this formatICT times.

The next line for the species contains the informationon its

formation reaction. The important fact to remember is that the

database CHDATA is a relational database. That is to say, that the

information entered into CHDATA dependson the existing information within the database. This is very important for the second line of

data on the species, the formation reaction information. For example consider the reaction aA + bB > C, the formation reaction matrix would be a moles of A, and b moles of B to makeone mole of C. The

species C is composed of the elements A and B. The second line of

information has to be able to describe this reaction. Elsewhere in the database CHDATA the elements A and B have beenentered, and must be referenced to add the species C. The elements A and B must also be referenced when a new element is added.

The first variable on the second line is the species

identification number. This is just for reference and is not read by

the program. After that IS the ICT, the number ofnon-zero

coefficients in the formation reaction matrix of this species In

the aA + bB > C reaction, ICT would be two, A andB are the non-zero coefficients that compose C. The next value entered is the

stoichiometric coefficient, XRD(1), for the first element that is used in the reaction to make the species C, in thiscase it is a.

Then the position, IXRD(1), for the first element, A, is entered.

This is repeated ICT times.

The position of an element is its element number. This is not necessarily its identification number; if they do coincide it is strictly by chance alone. The element number can only be found by 73 looking at the second line of the element's identification in CHDATA.

If the species is an element, ICT is one, the stoichiometric coefficient is one, and the position of the first element in its coefficient matrix element number. The first line in the identifica- tion must also be examined to make sure that the water coefficient and the number of electrons involved in the reaction are bothzero.

This examination will prevent problems with different oxidation states of the same species, being confused with elements. For +2 +3 example consider Fe and Fe :

19 FE++(AQ) 2 2.0 6.0 0.0 0.0 19 1 1.0 11 19 -3.181528E+01 0. 0. 20 FE+++(AQ) 2 3.0 9.0 0.0-1.0 20 1 1.0 11 20 -1.855590E+00 0. 0.

+2 . +3 Fe is an element, and Fe is actually composed of Fe+2 losing an electron. It should be noted that the in the example that the species identification number, 19, is not thesame as the element number, 11.

For example, in CHDATA Ca-/-2, Mg+2, and CO3-2are elements with the element numbers 5, 9, and 4 respectively. Together these elements can form the solid CaMg(CO3)2. The ICT number for the species CaMg(CO3)2 is three, and the second line in the database would look like: 15 3 2.0 4 1.0 5 1.0 9. This means the species number 15 formed from three elements, two of the element number 4 are needed (CO3-2), one of the element number 5 (Ca+2), and one of the element number 9 (Mg-I-2).

For the addition of new species to CHDATA, the second line isno major problem. The formation reaction must be written using the 74 existing elements in CHDATA. Then, with the reaction stoichiometry and the element numbers in hand, the second line of the new species is straight forward.

The addition of an element is a slightly more involved process.

The addition of an element must take into account previously entered elements, for placement in the element numbering system. Element numbers are assigned sequentially as they are added to the database.

To assign an element number the database must be searched for the highest element number, then the next larger number can be used for

the new element. The database elements must be watched closely,

especially with oxidation and reduction reactions. If a second

species is the same as another except for the oxidation state, only

one can be an element, the other must be formed by an oxidation-

+2 +3 reduction reaction, as was the case with Fe and Fe . If this is not done the program cannot run properly, mass balances would be

impossible, and minimization useless. Note that existing elements

are a user defined item. Carbon, for instance, could have been

defined as unoxidized Carbon, C, rather than CO3-2. The choice of

definition is in the hands of the user who is willing to add thenew

elements. Remember, the element numbers are not necessarily the

species numbers, you have to search line two of the species data to

determine if it is an element. The format for line two is shown in

Table C.4.

The third line of the species data is the polynomial for the

chemical potential data. The first item is the species

identification number, which is not read by the program and is used

only for reference. Next is the first of the polynomials that give 75

the chemical potential normalized by RT to be without units, The

2 3 4 5 polynomial was of the form A + BT + CT + DT + ET + FT . Where the values of A, B, C, D, E, and F are the coefficients enteredon line

three. The coefficients were placed in the matrix CLK(1-6,J) for

each species J. All the chemical potential data must be consistent!

The final section, line four, was only needed for solid species.

This line is for solid precipitates and their properties, and the

information required is mostly self-explanatory. This information is

not needed in running ISIS, and the explanation here is from Kerrisk

(Kerrisk, 1985) The first entry to the line was the species number.

The next input was the thermal conductivity of the solid, in Watts

per Centimeter * Kelvin. The next input is the density of the solid

when formed. The next columns contain the molecular weight of the

solid. The last value is the total fraction precipitate for the

solid, this is used in some precipitation models. The meaning for

this last variable is unknown, but it is not needed for solubility

calculations. The format for line four is shown in Table C.6.

The database file CONDATA is an interface between the

information handling in SENECA2 and the information needed for

activity coefficient calculations. CONDATA is a simple file. The

first line is a number bar to help with the addition ofnew

information. The next line inputs three values, the total number of

cations (NUMC1), the total number of anions (NUMA1), and the total

number ionic species combined (NTIRE). These values are used in the

database search in both CONDATA and PITDATA. In CONDATA, NTIRE is

used to search to the bottom of the file line by line, and helps

avoid certain crashes. In PITDATA, NUMC1 and NUMA1 are used to set 76

TABLE C.5: Format for the third line of input to the database CHDATA. Kerrisk, J. F., Private communications, 1985.

COLUMN NUMBERS DESCRIPTION

1 5 Species identification number, IDSP

6 - 20 First coefficient in reduced chemical potential as a function of temperature, CLK(1,J)

21 - 35 Second coefficient, CLK(2,J)

36 50 Third coefficient, CLK(3,J)

51 - 65 Fourth coefficient, CLK(4,J)

66 80 Fifth coefficient, CLK(5,J)

81 -95 Sixth coefficient, CLK(6,J)

TABLE C.6: Format for the fourth line of input to the database CHDATA. This line is only needed on solid species. Kerrisk, J. F., Private communications, 1985.

COLUMN NUMBERS DESCRIPTION

1 5 Species identification number, IDSP

6 15 Thermal conductivity of solid precipitate with units of W/CM K, THERCON(J)

15 - 25 Density of solid precipitate in GM/CC, DENPPT(J)

26 35 Formula weight of the solid precipitate in GM, FWPPT(J)

36- 45 Total fraction precipitate for this solid precipitate, used in some precipitation models, TFP(J) 77 the length of the searches in those datafields, and to help speed the search. The next lines are the interface information lines. Each species listed in CHDATA must be listed in CONDATA, and with the same species identification number. The line starts with the species name, this is only for reference and is not read by the program.

Next is the species identification number. After that is the type number, it identifies whether the species is a cation, anion, water,

or other species not of concern. The code used for this is cations

are 1, anions are 2, water is 4, and other species are 9. The last variable is the further breakdown of identification of the variable.

Each CONDATA line starts with the species numbers, then it is broken

down as to which species are cations, anions, and water. Next the

cations, anions, water, and other species are numbered within their

group. For example consider the group of species Ar(g), Na +, Cl, +2 Ca , and OH-. The species lines in CONDATA would look like:

AR(G) 1 9 1 NA+(AQ) 2 1 1 CL-(AQ) 3 2 1 CA+2(AQ) 4 1 2 OH-(AQ) 5 2 2

Ar(g) would be species number 1, it is not any of the other

categories so it is a 9, and it is the first member of that group,

that is the Ar(g) is the first species not of concern to the activity

coefficient calculation. Na+would be species number 2, it is a

cation, 1, and the first cation, 1. Cl- is species number 3, it is

+2 an anion, 2, and is the first anion. Ca isi species number 4, it is

a cation, 1, and is the second cation, 2. OH- is species number 5,

it is an anion, 2, and is the second anion, 2. Table C.7 has the

format for the file CONDATA. 78

TABLE C.7: Format for input to the database file CONDATA.

COLUMN NUMBERS DESCRIPTION

LINE 2

1 10 Number of cations in database, NUMC1

11 20 Number of anions in database, NUMA1

21 - 30 Total number of species in database, NTIRE

LINE 3 and on

1 - 10 Name of the species, not read

11 20 Species number, LIDSP

21 30 Species type, JCATAN

31 40 Cation, anion, identification number, IADD

PITDATA is the database with all the Pitzer ion interaction coefficients. It is divided into three sections, the first is the ion-ion interaction coefficients for cation-anion interactions, the second section is the triple ion interaction, and the cation-cation, and anion-anion interaction section, and finally the third section is some general constants for the Pitzer ion interaction model. The first line of each section is a number line to help place the values in the correct position.

When a value was not known for a particular ion interaction coefficient the value of 1001.0000000 was used. The program recognized this and change the value to zero for the calculations, and reported that the ion interaction coefficient was missing and assumed to be equal to zero (PITOUT). This convention was used throughout the database PITDATA.

The first section has the anion-cation interaction parameters. 79

The variables for the cation M and the anion X are, BOmx, Blmx, B2mx,

CPHImx, and whether the pair was a higher order pair, HOP. A higher order pair is a ion pair in which both ions have a valence state of two or higher. This section also supplied name data and charge data for the ion interaction calculations and for the output files PITCON, and PITOUT.

The section was organized with the cation listed first, ion

identification number, then name, and finally charge. The ion

identification number was the number that was searched out in the

CONDATA file. Then all the anions that were given in the database were listed. First the anion identification number, then the name,

charge, and then the variables value for BO through HOP. This was

repeated for every anion. The interaction parameters between Na+and

the anions would look like:

1 NA+ 1.0 1 CL-1 -1.0 0.0765000 0.2664000 0.0000000 0.00127000 2 CO3-2 -2.0 0.1897500 0.8460000 0.0000000 -0.04347400 3 014-1 -1.0 0.0864000 0.2530000 0.0000000 0.00440000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 SO4 -2 -2.0 0.0195800 1.1130000 0.0000000 0.00497000

When finished with all the anions, then the next cation was listed

and then all the anions with the ion interaction coefficients. Table

C.8 presents the spacing for the first section of PITDATA. This

format is repeated for every cation anion pair.

The triple interaction section of the database PITDATA has two

parts, the cation-cation-anion interaction parameters, and then the

anion-anion-cation interaction parameters. Included with this

section are the cation-cation and the anion-anion interaction terms. 80

This section of the database must be modified withgreat care. It is

set up for a sequential search, the program will not search backwards. The logic is that the first like-charge ion pairare ion

identification numbers 1 and 2, they will interact with the

oppositely charged ions in the order 1, 2, 3,... and so on. Next

the like-charged pair is 1 and 3, and then 1 and 4, untilthe last of

the interactions with the ion number 1. The next group will start with the like-charged ions 2 and 3. There is no need to repeat the

ions 1 and 2. The like-charged ions are numbered like the lower half of a matrix, and then every one of those interactionsis matched with

every oppositely charged ion. If this pattern isnotused the search will fail.

The triple interaction section starts off withanumber line for

convenience, to help maintain the proper spacing. The first line

that is read is the cation-cation line. On this line the two cations

are identified, first with their ion identification number then by

name, then the cation-cation interaction parameter, Theta. The next

series of lines are the cation-cation-anion interactionparameters.

The order of placement is very important, and thereare no easy

reference points. The cations of the group are listed in lineone

with both the ion identification number andname shown, for the

anion, only the value of the ion interactionparameter is given. The

program is set to count the values until it reaches the first value

needed and then it will be recorded, then thecount will proceed until the next needed value is found, andso on. The triple

interaction parameters are listed in groups of five, andare numbered

left to right. For example, consider the interaction coefficients 81

+ +2 -2 for the set Na Ca , and SO4 the ion identification numbers for ' the species are cations 1 and 2, and anion 5, respectively. The triple interaction section would look like:

1 NA+1 2 CA+2 0.0700000 -0.0140000 1001.0000000 1001.0000000 1001.0000000 -0.0230000 for the value of the cation-cation interaction constant being 0.07, and the cation-cation-anion constant being -0.023. If only a enough triple interaction constants are needed to fill part of a line, the rest of the line should be filled out with with 1001.0000000, this will stop any problems when the line is read.

The second half of the triple ion interaction parameter section is the anion-anion-cation section. The format of the variables is exactly the same as the cation-cation-anion section, except that where there were cations now anions are used and where therewere anions now they are replaced with cations. There must be no error in the order in which the ions are entered, or else the search will fail.

The final section of the database PITDATA contains five constants used in the Pitzer ion interaction model for the activity coefficients. The first line in the section was a number line, then each line after had a single constant and its name. The name for the constant was not read, and was only included as a convenience. The format was to read 13 blanks and then the next 13 spaces were read with a F13.7 format. The order of the variables cannot be changed.

The first variable was ALPHA. This is the value used in the calculation of the 1-1 and 1-2 electrolytes activity coefficients, and was determined by Pitzer (Pitzer, 1973) to be 2, for this use of the model. 82

The second and third variables were ALPHAl and ALPHA2. These were the constants used when the interaction was between a higher order pair of ions, 2-2 or higher electrolytes. The values determined by Pitzer (Pitzer, 1974) for this were ALPHAl was 1.4, and

ALPHA2 was 12.0.

The fourth variable was APHI. This was the limiting slope of the for the osmotic coefficient equation. The value used here was

0.392 (Harvie and Weare, 1980) which is valid for 25 C. APHI is a function of the temperature. An excellent source for more information is the paper by Beyer and Staples (Beyer and Staples,

1986).

The last variable was B. This is an empirical parameter with the value 1.2, that is used in the pebye-Huckel term of the Pitzer ion interaction model (Harvie and Weare, 1980).

TABLE C.8: Format for the first section of PITDATA, with the cation anion pair MX.

COLUMN NUMBERS DESCRIPTION

1 3 Ion identification number.

4 -11 Ion name.

12 - 17 Ion charge.

Above for both cation and anion information lines. The following is for only the anion lines.

17 - 29 BOMXion interaction coefficient.

30 - 42 B1MXion interaction coefficient.

43 - 55 B2 ion interaction coefficient.

56 - 68 CPHIMX ion interaction coefficient.

69 - 70 Higher order pair flag, 1 indicates higher order pair, 0 indicates a non-higher order pair. 83

TABLE C.9: Format for the second section of the databasePITDATA, triple ion interaction parameters and anion-anionand cation-cation parameters.

FIRST LINE OF LIKE-CHARGED PAIR

COLUMN NUMBERS DESCRIPTION

1 13 Ion identification number.

14 26 Ion name, not read.

27 39 Second like-charged ion identification number.

40 - 52 Second like-charged ion name, not read.

53 - 65 Like-charged ion interaction parameter, Theta.

SECOND LINE OF LIKE-CHARGED PAIR

COLUMN NUMBERS DESCRIPTION

1 13 Value of triple ion interaction parameter PSI, for the first oppositely charged species.

14 - 26 Value of triple ion interaction parameter PSI, forthe second oppositely charged species.

27 - 39 Value of triple ion interaction parameter PSI, for the third oppositely charged species.

40 -52 Value of triple ion interaction parameter PSI, forthe fourth oppositely charged species.

53 - 65 Value of triple ion interaction parameter PSI, for the fifth oppositely charged species.

This pattern is repeated on the next lines forion identification numbers six through ten, and then thenext line for eleven through twelve, and so on. 84

SUMMARY

The general flow of the program ISIS and a description of the databases involved with the program were discussed in this operations

manual. There are only five major subroutines that control the

program, SENECA2, MINI, TEST, GAMMA, and NEWSOM. The other

subroutines and functions are usually single task oriented, while

these actually manage the flow of the calculations. There are three

databases needed for the program, CHDATA, COMDATA, and PITDATA. Each

of these databases must be carefully updated, to insure proper

spacing, numerical order, internal consistency, and thermodynamic

consistency. If this is not done ISIS, will either crash in the run

or will give answers that are in error. There are no error messages

for incorrectly modified databases, so extremecare must be taken

when new species are entered, or values modified. ISIS has been

found to predict equilibrium conditions very well when given good

data to work with. Good luck. 85

BIBLIOGRAPHY

Beyer, R. P. and Staples, B. R., "Pitzer-Debye-Huckel LimitingSlopes for Water from 0 to 350 C and from Saturationto 1 kbar," Journal of Solution Chemistry 15, No. 9 (1986), pp. 749 763.

Feber, R. and Kerrisk, J. F. SENECA2 internal documentation (Los Alamos Scientific Laboratory, 1980).

Harvie, C. E. and Weare, J. H., "The Prediction of Mineral Solubilities in Natural Waters: The Na-K-Mg-Ca-C1-SO4-H20 System from Zero to High Concentration at 25 C," Geochimicaet Cosmochimica Acta44 (1980), pp. 981 - 997.

Kerrisk, J. F., Chemical Equilibrium Calculations forAqueous Geothermal Brines (Los Alamos Scientific Laboratory ReportNo. LA-8851-MS, UC66b, May, 1981).

Kerrisk, J. F., Private communications, 1985.

Ma, Y. H. and Shipman, C. W., "On the Computation ofComplex Equilibria," AIChE Journal, 18, No. 2 (1972),pp. 299 304.

Pitzer, K. S. and Mayorga, G., "Thermodynamics of ElectrolytesII: Activity and Osmotic Coefficients for Strong Electrolyteswith One or Both Ions Univalent," The Journal of PhysicalChemistry 77, No. 19 (1973) pp. 2300 2308.

Pitzer, K. S. and Mayorga, G., "Thermodynamics of ElectrolytesIII: Activity and Osmotic Coefficients for 2-2 Electrolytes,"Journal of Solution Chemistry, 3, No. 7 (1974)pp. 539 546.

Pitzer, K. S., "Theory: Ion interaction approach" Activity Coefficients in Electrolyte Solutions, Volume 1 R. M. Pytkowicz, Editor. (CRC Press, Inc., Boca Raton, FL, 1979), pp. 157 - 208. 86

APPENDIX D

USER MANUAL FOR ISIS

Directions and requirements for using the computer program ISIS

by

Barry Kelly

Oregon State University

November, 1987 87

TABLE OF CONTENTS

Page

INTRODUCTION 90

INPUT FILE 94

OUTPUT FILES 102

DATABASE FILES 113

RUNNING ISIS 117

SUMMARY 122

BIBLIOGRAPHY 123 88

LIST OF FIGURES

Figure Page

D.1. Example input file for ISIS 95

D.2. Example of the first section of the output file 103

D.3. Example of the last section of the output file 105

D.4. Example output with printer control equal to1 108

D.5. Example output with printer control equal to2 111

D.6. Example of the output file PITCON 112

D.7. Example of the output file PITOUT 113

D.8. Sample section of database file CHDATA 115

D.9. Sample section of database file CONDATA 115

D.10. Sample section of database file PITDATA 116

D.11. Sample of ISIS program start 118 89

LIST OF TABLES

Table Page

D.1. Files associated with ISIS 93

D.2, Values of IREDOX and ESET 101

D.3. Meaning of INDX3 in ISIS output 110

D.4. Error messages in ISIS 119 90

INTRODUCTION

The computer program ISIS is a chemical equilibrium predictor

for aqueous inorganic solutions. ISIS is the combination of the program SENECA2 with a more advanced activity coefficient predictor model developed by Pitzer and coworkers (Pitzer, 1979). SENECA2 is a

modified version of the the program SENECA originally developed by Ma

and Shipman (Ma, 1972), and later modified by Feber and Kerrisk

(Feber, 1980, Kerrisk, 1981).

The purpose of this manual is to introduce the chemist or

engineer to the technical aspects of using ISIS. The subjects

covered are: the files associated with ISIS, assembly of the run

files, the output files, and possible problems associated with

running the program.

A background in the FORTRAN computer language and thermodynamics

is recommended for the user of this program. Information from

technical journals, computer manuals, and class notes were used in

writing this manual. 91

The following definitions are used in this manual:

FILE(S): Computer input or output that is available to the program or written by the program.

ISIS: The computer program that calculates the solution to the chemical equilibrium problem.

FREE FORMATTED: This is when the information field required only a comma, or other punctuation mark recognized in FORTRAN to separate it from the next information field.

FORMATTED: This is when an information field has to reside in a certain space in the file being read. Commas are not needed for this type of information field, as the program only looks for it by location.

INFORMATION FIELD: A single piece of information to be read by the computer for use with the program, such as a name, date, or numerical value.

ELEMENTS: An element is the base chemical that was included to make the equilibrium system, e.g. Al, Cl,

SYSTEM: The system is all the chemical species that are in the solution, or could be in existence at the final equilibrium state. 92

An example of a use for ISIS is the prediction of the equilibrium between KCl and NaC1 in solution. After starting the program the user is prompted for the name of the input file. The input data required are the temperature, pressure, the chemical species that are suspected to be present (such as K +, Na+, Cl, 111-,

OH , KCL(s), NaCl(s), and H20), the actual make-up elements such as

Cl, H +, and OH- and their amounts (in molal units). This provides the system with the initial amounts of KC1, NaC1, and water

(H20) that the system begins with before the equilibrium state is reached. ISIS then needs to know the tolerances to which the program

is to be run. Again, the user will have to supply these. From this point, a thermodynamic database is employed to find the properties of

the species involved. The database has information on the chemical potential at the system temperature and pressure, the activity

coefficient data, and the reaction information about the species

(waters of hydration and so forth). This is where ISIS will begin

the equilibrium calculations.

The final output file name is specified by the user at the start

of the run. This output file includes the equilibrium amount of each

of the species in the system for both solids and species in

solution. Also included is, information about the ionic strength and

the pH of the solution.

ISIS also generates other output files that have information

about the Pitzer ion interaction parameters used in the calculation

of the activity coefficients, and the missing Pitzer ion interaction

parameters that were assumed to be zero.

The database files associated with ISIS are CONDATA, CHDATA, and 93

PITDATA. These files are discussed in the following sections. The files required by ISIS are summarized in Table 0.1.

TABLE D.1: Files associated with ISIS.

FILE NAME PURPOSE input file Contains all the user supplied information about (file name the chemical system, and information on the is user tolerances required. supplied) output file Contains the output of the program, (file name equilibrium values, ionic strength, is user and other data. supplied)

PITCON This output file includes the Pitzer ion interaction parameters used in the calculation of the activity coefficients.

PITOUT This output file includes the list of missing Pitzer ion interaction parameters that are assumed to be zero.

CHDATA The database file containing the thermodynamic information needed in the calculations.

CONDATA The database file containing the information to find the Pitzer ion interaction parameters of the system.

PITDATA The database file with the Pitzer ion interaction parameters. 94

The Input File

The input file contains information about the system of chemical species that are to be run by ISIS to predict the final equilibrium state. Proper creation of an input file is extremely important to a successful ISIS run. The input file is free formatted and has nine plus n lines where n is the number of elements.

A sample input file is shown in Figure D.1. The contents of the input file are described in the following paragraph.

The first line of the input file is the title line. The title line is defined by the user to describe the system for his own reference. The title line description is printed at the top of the output file.

The second line contains the number of different temperatures and pressures at which ISIS will run the system. ISIS will begin with the first temperature and pressure and calculate the final equilibrium values; then ISIS uses these final equilibrium values from the initial temperature and pressure as an initial starting point for the equilibrium calculations at a new set of temperature and pressure values.

The third line of the input file is the temperature input line.

The temperatures are in Kelvin and are in free format. If only a single value is used then no comma is necessary after the first value.

The fourth line is for the input of the system pressure. The pressures are in atmospheres and are entered in free format. 95

CASE T103: TEST K + VS NA + SOLUBILITY WITH CL- 1 298.15 1.0 0.0 5,8,3,4,2.00E-05,1.00E-10,1.00E-08,50,0 2,3,6,7,9,32,47,58 2.,2 7.,3 200.,6 200.,7 5.,32 7.,33.3 0,0

Title line. Number of different temperatures, and pressures. Temperature (K). Pressure (Atm). Quality. NELMT, NSPCS, NREACT, NPHAS, TOLL, TOL2, TOL3, KKMM, IPR Species numbers. Molal amount, specie number Molal amount, specie number Molal amount, specie number Molal amount, specie number Molal amount, specie number SLNMOL, SLTMW IREDOX, ESET

FIGURE D.1: Example input file for ISIS, and explanation of lines in the file. 96

The fifth line of the input file is the vapor quality of the system. The quality is used when calculations of equilibrium composition are done after a flashing operation. The quality values are free formatted, and separated by a comma.

Line number six is used for entering the numbers of the different elements, species, reactions, phases, the tolerance of the minimization, the tolerance of the Newton-Raphson subroutine, the tolerance of the material balance calculations, the maximum number of iterations on the Newton-Raphson subroutine, and the print control index. There are nine input variables assigned on this line.

The first variable in line six is the number of different elements which make up the building blocks of the system. The variable name in the program is NELMT. The elements are Nat, Cl-

, 14-, OH- in the examplecase, and NELMT is five.

The second variable is the number of different species. The number of different species in the system is the number of compounds that can possibly exist at the equilibrium state. These species are

K+, Na+, Cl-, H-1-, OH-, KC1(s), NaCl(s), and H2O in the example. The variable name for the number of species is NSPCS. In the example case NSPCS has a value of eight. A second feature of this variable

is to flag a special input to the program. If this variable is negative, ISIS will look at the end of the program for two extra lines. The first extra line is the number of species in the system.

The next line has the number of moles of the species, and the species number for each species in the system. The program is then able to use these values as a better starting point for the equilibrium calculations. This feature was not found to be very useful. 97

The third variable, the number of reactions, is the difference between the number of elements making up the system and the possible number of compounds formed at the equilibrium state. The variable name is NREACT, and is equal to the difference between NSPCS and

NELMT. For the example case of NaC1 and KC1 in water the value of

NREACT is three.

The number of different phases in the system is the next variable. Each solid specie is considered a different phase. The aqueous phase and the gas phase are considered as two additional phases. The program checks the total number of phases value and reports an error if the number of phases listed in the input file does not correlate with the number it has counted. The equilibrium calculation then proceeds with the number of phases theprogram has found to be the correct number of phases. The variable for the number of phases in the system is NPHAS. In the example case, NPHAS is four.

The next variable, the initial tolerance for the minimization routine, is set with the variable TOLL This tolerance is changed in the subroutine MINI as the calculation proceeds. The initial tolerance has an effect on the convergence of the minimization routine and some adjustments to the value are necessary to avoid converging to the incorrect solution that all species are infinitely soluble. The infinitely soluble solution is the most common spurious answer that went to completion and was considered by ISIS to be good solution to the equilibrium problem. Examination of the final output material balances is necessary in these cases If ISIS converges to a poor solution, the material balances has errors of 1.0 E+10. In a 98 properly converged solution the errors are in the order of 1.0 E-15.

A value of TOL1 in the order of 1.0 E-5 to 1.0 E-20 produces good results in running ISIS.

The next variable is the tolerance for the Newton-Raphson subroutine, NEWSON. An acceptable value of the NEWSON tolerance,

TOL2, is 1.0 E-10. The tolerance of the Newton-Raphson method subroutine is less critical to a successful run of ISIS than is the

tolerance of the minimization routine.

The next value is the material balance tolerance for

convergence. This value, TOL3, should be 1.0 E-10 or less.

The next variable is the maximum number of NEWSON iterations.

The routine will continue until the convergence criterion is metor until the maximum number of iterations allowed, RKMM, is reached. If

the maximum number of iterations is reached, the program will output

the final solution at that point. This solution is usually within

the accuracy of the equilibrium information in the database.

The print control index, IPR, is the last entry on line six.

The print control index is set equal to 0 for minimum output, 1 for

intermediate amount of output, and 2 for the maximum amount of

output. The 0 setting is suitable for most purposes. This variable

is discussed further in the output section.

Line seven is used for the species numbers. Each of the species

in the ISIS database is assigned a number for the program to locate

it with. The species numbers are available in either the CHDATA or

CONDATA databases. The species numbers are entered free format,

separated only by a comma, and do not need to be in sequential order.

Water, OH-, and H+ were species that must be included in the system; 99

OH- and H+ are needed as input elements also. When oxidation- reduction reactions are involved, the species that made up the reduced or oxidized species must be included as elements. The species that are considered the standard state for other species can be found in the database CHDATA. This is true for all reactions.

A two pass calculation is started if a negative value is used on line seven. A two pass calculation is when the equilibrium problem is divided into two parts. The first pass solves a simplified equilibrium problem using a subset of all the species listed on line seven. This subset consists of the major species that affect the equilibrium state. The second pass solves the equilibrium problem using all the species listed on line seven, using the equilibrium values from the first pass as initial guesses. These initial guesses make the problem, theoretically, easier to solve. The species that are listed after the first species' number which is negative

(inclusive of the first negative species number) are included in the second equilibrium calculation. For clarity, it is better to list all species numbers that are included in the second pass but not the first pass as negative numbers on line seven.

The next lines include the molal amounts and the species numbers of the elements that are the starting point of the calculations.

There are NELMT lines of the input element amounts. Line six defined how many lines would be read from the input file. If the number of elements reported on line six and the number of elements on these

lines differ, the run crashes. ISIS has no error messages for this problem. The line is free format, with the moles of that element per

1000 grams of solution added first, and then the species number. 100

After the NELMT lines of input are finished, the moles of salt in the solution, SLNMOL, and the average salt molecular weight,

SLTMW, are input. These values are used in the solution density calculations, and are entered free format, with SLNMOL entered first.

The next line is the input for the oxidation-reduction section of the program, and is used to calculate the electron activity. Two parameters are entered: the first is a flag to indicate what reaction controls the oxidation and reduction, IREDOX, the next value is the input to the controlling reaction, ESET. IREDOX has four values and each different value implies a different meaning to the value of ESET. See Table D.2.

Three methods of calculating the electron activity are used in the program: constant electron activity, electron activity based on oxygen partial pressure, and electron activity based on sulfate/sulfide ratio. When IREDOX is set to have a constant electron activity, the electron activity is calculated using the

Nerst equation (1).

ln[ae..] = EnF/RT (1)

When the oxygen partial pressure is the input, the electron activity is computed using reaction 2 as a basis, solving for the electron term, and using it in the other oxidation reduction reactions. When the sulfate/sulfide ratio is the input, reaction 3 was used in the same way as reaction 2, it is solved for electron activity and the electron activity is then used in the calculations.

4[0H-] <> 02 + 2[H20] + 4e- (2)

[S 2] + 8[0H-] <> [SO4-2] + 4[H20] + 8e- (3) 101

TABLE D.2: Values of IREDOX and ESET.

IREDOX ESET MEANING OF IREDOX

0 0.0 No oxidation reduction reactions.

1 Potential Electron activity constant. difference in Volts

2 Oxygen partial Oxidation-reduction reactions pressure in controlled by Oxygen partial Atmospheres pressure. Electron activity varies with pH.

3 Sulfate/Sulfide Oxidation and reduction ratio reactions controlled by sulfate/sulfide ratio. Electron activity varies with pH.

The example input file for the NaC1- KC1 equilibrium in water at 25 C is shown in Figure D.1. 102

THE OUTPUT FILES

ISIS generates three output files: a main output that is named by the user, PITCON, and PITOUT. The main output file has all the input data, the final equilibrium data, and variableamounts of intermediate information. PITCON has the values used in the calculation of the activity coefficient using Pitzer's method.

PITOUT lists the Pitzer ion interaction parameters thatare missing and are assumed to be zero.

The main output file is named by the user at the beginning of the ISIS run. The program prompts the user for both the input file name, and then, for the output file name.

The main output file had three sections: an input section, the run information, and the final equilibrium answer. The first and last sections can not be changed, but the amount ofrun information can be varied from zero to a large amount by using the print control variable on line six of the input file.

The first section of the output file isan echo of the input file information, and information collected from thedatabase CHDATA.

The first section from the examplecase is shown in Figure D.2. 103

CASE T103: TEST K + VS NA + SOLUBILITY WITH CL-

NELMT NSPCS NREACT NPHAS PRESS. TOL1 TOL2 TOL3 KKMMIPR 5 8 3 4 1.00 2.0E-05 1.0E-10 1.0E-08 50 0

THE FOLLOWING IS THE INPUT COMPOSITION IN MOLALITY

NA+(AQ) 2.000000E+00 CL-(AQ) 7.000000E+00 H+(AQ) 2.000000E+02 OH-(AQ) 2.000000E+02 K+(AQ) 5.000000E+00

SALT MOLALITY - 7.00000 SALT MOLECULAR WEIGHT - 33.30000

NO OXIDATION-REDUCTION REACTIONS INVOLVED

TEMPERATURE -298.1500

DENS. OF SOLN. = 1.2671 GM/CC

TOL1 = 2.000000E-05 POTO AMT AZERO IPHSE NA+(AQ) -105.651 2.000E+00 1. 4.0 2 CL-(AQ) -52.955 7.000E+00 -1. 3.0 2 H+(AQ) .000 2.000E+02 1. 9.0 2 OH-(AQ) -63.464 2.000E+02 -1. 3.5 2 K+(AQ) -113.957 5.000E+00 1. 3.0 2 H20(L) -95.664 .000E+00 0. .0 2 NACL(S) -154.990 .000E+00 0. .0 3 KCL(S) -164.840 .000E+00 0. .0 4

SYSTEM CHARGES BALANCE

FIGURE D.2: Example of the first section of the output file from ISIS. 104

The information from the database file CHDATA is shownat the end in Figure D.2. This information is the specie's name, the specie's chemical potential at the temperature of the system normal- ized by RT, the amount of the specie as a starting point in moles, the specie's charge, the specie's coefficient foran extended Debye-

Huckel activity coefficient predictor, and last, the phase the specie is in. The phase numbers are: 1 for gas phase, 2 for aqueous phase,

3 and up for each solid phase.

The final equilibrium section of the output is shown for the example case in Figure D.3. The final equilibrium section is self- explanatory. The AMOUNT column is in molal units. The MATERIAL

BALANCE ERRORS section does not refer to the specie that has the error, it only lists a relative number that ISIS uses to keep track of the species. 105

TEMPERATURE 298.1500 DEG K

PRESSURE 1.0000 ATM

SPECIES PHASE MOUNT ACTIVITY ACTIVITY PARTIAL NUMBER COEFFICIENT PRESSURE

NA+(AQ) 2 2.0000E+00 8.2430E-01 1.6486E+00

CL-(AQ) 2 5.6046E+00 6.9629E-01 3.9024E+00

H+(AQ) 2 6.3195E-08 2.9081E+00 1.8378E-07

OH-(AQ) 2 6.3195E-08 7.2952E-01 4.6102E-08

K+(AQ) 2 3.6046E+00 5.6451E-01 2.0348E+00

H20(L) 2 2.0000E+02 8.1642E-01

KCL(S) 3 1.3954E+00 1.0000E+00

IONIC STRENGTH 5.6046E+00 PH 6.735711 QUALITY .0000

MATERIAL BALANCE ERRORS

ELEMT 1 .00000E+00 2 .00000E+00 3 .00000E+00 4 .00000E+00 5 -2.84217E-14

INDX3 0

NORMAL EXIT

FIGURE D.3: Example of the last section of the output file from ISIS. 106

The intermediate section of the output records information during the program run. This information can be useful in finding the initial conditions that are needed to, achieveconvergence. The amount of output data can be varied from nothing toa large amount of run data. The amount of intermediate output information isset in the input file with IPR on line 6. If IPR is set to 0, then there will be no intermediate data. If IPR is set to 1, there is the additional information as shown in Figure D.4. From the documenta- tion in SENECA2 (Feber, 1980) and the paper by Ma and Shipman (Ma,

1972), DGDK is the derivative of the Gibb's function, G, withrespect to the search parameter, K. DK is the step size in the search parameter, K, and G is the value of the Gibb's function at the point.

INDX3 is a flag used in three subroutines to indicate the final status on exiting the subroutine. The meaning of the flags are listed in Table D.3. NCOUNT is the number of times that a special loop is called in the minimization routine MINI. The next line indicates whether a species has gone tozero in the minimization routine. The next line concerns the subroutine TEST, which selects the key species for the minimization routine. INDX3 is printed first

(See Table D.3), then NCT1 and NCT2 which are the number of times problems in TEST required a restart in TEST. The next output is a repetition of the above until convergence. Afterconvergence, MINI prints out a slightly different summary of results.

The summary includes the name of the species (NAME), theamount of the species (AMT), the mole fraction in that phase (X), the chemical potential of the species normalized by RT (POTO), and finally the chemical potential of that species in its particular 107 phase (POT) (Feber, 1980). The remaining sections deal with the material balance errors after the subroutine MINI, for each of the elemental species in the case.

The next series of output is from the subroutine NEWSON, the

Newton-Raphson equation solvingsequence. This section gives the iteration number and a measure of how well theconvergence is progressing by printing the charge balance for the system.

When the print control index IPR is set to 2, then the maximum output from the program will be given. Examples of the additional information are found in Figure D.5. The extra output is the additional information about the amounts, mole fractions, and chemical potentials. Also, the material balance errors are listedas they are when IPR is set to 1. The additional information is output after every MINI pass. This is usually more of a problem than a help. 108

START MINI - CALL NUMBER 1 TOL1 - 2.000000E-05 DGDK - -4.639461E+02 DK -1.647734E-04G - -2.026898E+04 NO. MINI ITERATIONS - 7 INDX3- 1 NCOUNT - 0 SPECIESH+(AQ) WENT TO ZERO TEST INDX3 - 4 NCT1 5 NCT2 = 0

TOL1 = 2.000000E-06 POTO AMT Z AZEROIPHSE NA+(AQ) -105.651 2.000E+00 1. 4.0 2 CL-(AQ) -52.955 4.389E+00 -1. 3.0 2 H+(AQ) .000 1.292E-03 1. 9.0 2 OH-(AQ) -63.464 1.292E-03 -1. 3.5 2 K+(AQ) -113.957 2.389E+00 1. 3.0 2 H20(L) -95.664 2.000E+02 O. .0 2 NACL(S) -154.990 .000E+00 O. .0 3 KCL(S) -164.840 2.611E+00 O. .0 4

The above information is output until MINI converged

START MINI - CALL NUMBER 6 TOL1 = 2.000000E-10 MINI CONVERGED NAME, AMT, X, POTO, AND POT LISTED BELOW NA+(AQ) 2.0000E+00 9.5795E-03 -1.0565E+02 -1.0496E+02 CL-(AQ) 4.3893E+00 2.1024E-02 -5.2955E+01 -5.1476E+01 H+(AQ) 8.6825E-08 4.1587E-10 .0000E+00 -1.6259E+01 OH-(AQ) 8.6825E-08 4.1587E-10 -6.3464E+01 -7.9724E+01 K+(AQ) 2.3893E+00 1.1444E-02 -1.1396E+02 -1.1309E+02 H20(L) 2.0000E+02 9.5795E-01 -9.5664E+01 -9.5664E+01 NACL(S) .0000E+00 1.0000E+00 -1.5499E+02 -1.5499E+02 KCL(S) 2.6107E+00 1.0000E+00 -1.6484E+02 -1.6484E+02 DG FOR EACH REACTION LISTED BELOW 3.195995E-01 .000000E+00 -2.781421E-01 DGDK -1.795069E-01 DK - 5.472397E-08 G - -2.026910E+04 NO. MINI ITERATIONS = 2 INDX3 = 0 NCOUNT 1

PRIOR CALCULATIONS WERE DONE WITH UNIT ACTIVITY COEFFICIENTS ACTIVITY COEFFICIENT CALCULATION HAS BEEN ACTIVATED

START MINI- CALL NUMBER 7 TOL1 = 2.000000E-11 MINI CONVERGED NAME, AMT, X, POTO, AND POT LISTED BELOW NA+(AQ) 2.0000E+00 9.4774E-03 -1.0565E+02 -1.0516E+02 CL-(AQ) 5.5138E+00 2.6128E-02 -5.2955E+01 -5.1613E+01 H+(AQ) 8.6825E-08 4.1144E-10 .0000E+00 -1.5215E+01 0H-(AQ) 8.6825E-08 4.1144E-10 -6.3464E+01 -8.0046E+01 K+(AQ) 3.5138E+00 1.6651E-02 -1.1396E+02 -1.1328E+02 H20(L) 2.0000E+02 9.4774E-01 -9.5664E+01 -9.5863E+01 NACL(S) .0000E+00 1.0000E+00 -1.5499E+02 -1.5499E+02 KCL(S) 1.4862E+00 1.0000E+00 -1.6484E+02 -1.6484E+02

FIGURE D.4: Example of run information in output file with printer control index set to 1. 109

FIGURE D.4 (Cont.)

DG FOR EACH REACTION LISTED BELOW -6.019657E-01 .000000E+00 4.785649E-02 DGDK - -3.646529E-01 DK - 1.176850E-07G - -2.031044E+04 NO. MINI ITERATIONS = 1 INDX3 = 0 NCOUNT - 1

MATERIAL BALANCE ERRORS AFTER MINI I = 1 ERROR - .000000E+00- FRAC ERROR = .000000E+00 I - 2 ERROR - 1.648015E-07 FRAC ERROR = 2.354308E-08 I - 3 ERROR - -8.353618E-08 FRAC ERROR - -4.176809E-10 I = 4 ERROR - -8.353618E-08 FRAC ERROR - -4.176809E-10 I = 5 ERROR - 1.676634E-07 FRAC ERROR = 3.353268E-08

START NEWSON ITER CHARGE BALANCE 1 2.861853E -09 2 6.015444E-04 3 2.461069E-05 4 7.998088E-07 5 3.191143E-08 6 1,220585E-09 7 4.702372E-11 8 1.804779E-12 9 2.842171E-14 10 -2.842171E-14 11 2.842171E-14 12 -5.684342E-14 13 2.842171E-14 14 1.421085E-14 END NEWSON INDX3 - 0 110

TABLE D.3: Meaning of INDX3 in ISIS output.

SUBROUTINE INDX3 MEANING

MINI 0 MINI has converged. 1 A key species has become too small. 2 A special minimization loop in MINI is used. 3 Minimization proceeding normally.

TEST 4 No suitable key species can be found.

NEWSON 0 NEWSON has converged. 1 A key species has become too small. 2 A nonkey species has become too small. 3 The maximum number of iterations was exceeded.

REFERENCE: Feber, R. and Kerrisk, J. SENECA2 internal documentation. Los Alamos Scientific Laboratory, New Mexico, 1980. 111

START MINI -CALL NUMBER 1 TOL1- 2.000000E-05 11NDX3 - 3 ITER = 1 JT 0

SPECIES AMOUNT X(J) POT(J) NA+(AQ) 2.0000E+00 6.7044E-03 -1.0496E+02 CL-(AQ) 3.2500E+00 1.0895E-02 -5.1776E+01 H+(AQ) 9.1810E+01 3,0777E-01 4,5197E+00 OH-(AQ) 9.1810E+01 3.0777E-01 -5.8945E+01 K+(AQ) 1.2500E+00 4.1903E-03 -1.1373E+02 H20(L) 1.0819E+02 3.6268E-01 -9.5664E+01 NACL(S) .0000E+00 1.0000E+00 -1.5499E+02 KCL(S) 3.7500E+00 1.0000E+00 -1.6484E+-02 -4.279577E+01 .000000E+00 -1.483348E+00 DGDK - -1.833679E+03 DK - 2.528065E+00G -1.648511E+04

MATERIAL BALANCE ERRORS I - 1 ERROR - .000000E+00 FRAC ERROR - .000000E+00 I - 2 ERROR - 1.421085E-14 FRAC ERROR - 2.030122E-15 I - 3 ERROR -4.547474E-13 FRAC ERROR -2.273737E-15 I 3- 4 ERROR -4.547474E-13 FRAC ERROR - 2.273737E-15 I - 5 ERROR = 1.421085E-14 FRAC ERROR = 2.842171E-15 1INDX3 = 3 ITER - 2 JT = 0.

FIGURE D.5 Example of run information in output file with printer control index set to 2.

The next output is the file PITCON. PITCON has the ion interaction parameters for the Pitzer equations,see Figure D.6. The last of the output files is PITOUT,see Figure D.7. This file has the listing of the missing Pitzer ioninteraction parameters. These values are assumed to be zero. 112

DATA USED IN ACTIVITY COEFFICIENT PREDICTION

CATION CHARGE ANIONCHARGE BO Bl B2 HOP

NA+ 1. CL-1 .0765. .2664 .0000 0 .001270

NA+ 1. OH-1 .0864 .2530 .0000 0 .004400

H+1 1. CL-1 .1775 .2945 .0000 0 .000800

H+1 1. OH-1 .0000 .0000 .0000 0 .000000

K+1 1. CL-1 .0484 .2122 .0000 0 -.000840

K+1 1. OH-1 .1298 .3200 .0000 0 .004100

CTHETA NA+ H+1 = .03600000 H+1 NA+ .03600000 CCAPSI VALUES FOR CATION PAIR ABOVE AND ANIONS: CL-1 - -.00400000 OH-1 .00000000

CTHETA NA+ K+1 - -.01200000 K+1 NA+ - -.01200000 CCAPSI VALUES FOR CATION PAIR ABOVE AND ANIONS: CL-1 - -.00180000 OH-1 = .00000000

CTHETA H+1 K+1 = .00500000 K+1 H+1 .00500000 CCAPSI VALUES FOR CATION PAIR ABOVE AND ANIONS: CL-1 = -.00700000 OH-1 = .00000000

ATHETA CL-1 OH-1 = -.05000000 OH-1 CL-1 = -.05000000 AACPSI VALUES FOR ANION PAIR ABOVE AND CATION: NA+ - -.00600000 H+1 .00000000 K+1 - -.00800000

FIGURE D.6: Example of the output file PITCON. 113

NO DATA WAS AVAILABLE FOR THE FOLLOWING ION INTERACTION CONSTANTS: MISSING VALUES ARE SET TO ZERO

BO H+1 OH-1 B1 H+1 OH-1 CFI H+1 OH-1 CCAPSINA+ H+1 OH-1. CCAPSIH+1 NA+ OH-1 CCAPSINA+ K+1 OH-1 CCAPSIK+1 NA+ OH-1 CCAPSIH+1 K+1 OH-1 CCAPSIK+1 H+1 OH-1 AACPSICL-1 OH-1 H+1 AACPSIOH-1 CL-1 H+1

FIGURE D.7: Example of the output file PITOUT.

THE DATABASE FILES

ISIS requires three database files, CHDATA, CONDATA, and

PITDATA. These files provide the thermodynamic information to ISIS for system specified in the input file. The following descriptions are general, and more complete descriptions are in the operations manual. The information fields in these database files are formatted; any changes that are made must keep the correct spacing or the program will crash when the file is used.

CHDATA is the data file with the chemistry data on the system species. The information included in this file is the species identification number, species name, phase, charge, activity parameter, water coefficient, the number of electrons, the reaction matrix, the chemical potential, and for solid species the thermal conductivity, density, formula weight, total fraction precipitate for the solid precipitate. Some of the information supplied in the database, specifically the solid precipitate information,can no 114

longer be used with ISIS because of modifications to thesource code.

An example section of CHDATA is in Figure D.8. CHDATA is the source

for the species numbers used in line seven of the input file, and for

the element species numbers in line eight.

The file CONDATA is an interface file between CHDATA and

PITDATA. CONDATA has information about what the species is, either

solid, gas, cation, anion, or water. CONDATA also has information

about which solid, cation, anion, etc. it is. This is necessary

because of the multidimensional search for the Pitzerparameters. An

example of a section of CONDATA is in Figure D.9.

The last database file is PITDATA. PITDATA contains the ion

interaction parameters needed for the Pitzer model of the activity

coefficient. The file is split into two parts, the double

interaction parameters first, and then the triple ion interaction

parameters. An example of PITDATA is in Figure D.10. At the end of

PITDATA are five constant values for the ion interaction calcula-

tions. They are valid only at 25 C. 115

1 AR(G) 1 0.00.0 0.0 1 1 1.0 8 1 O. O. O. O. 0 2 NA+(AQ) 2 1.0 4.0 0.0 2 1 1.0 1 2 -1.056510E+02 O. O. O. 0 3 CL-(AQ) 2-1.03.0 0.0 3 1 1.0 2 3 -5.295500E+01 O. O. O. 0 4 CO3--(AQ) 2-2.04.5 0.0 4 1 1.0 4 4 -2.129490E+02 O. O. O. 0 5 CA++(AQ) 2 2.0 6.0 0.0 5 1 1.0 5 5 -2.233000E+02 O. O. O. 0 6 H+(AQ) 2 1.0 9.0 0.0 6 1 1.0 6 6 O. 0. O. O. 0 7 OH-(AQ) 2-1.0 3.5 0.0 7 1 1.0 7 7 -6.346436E+01 O. O. 0. 0 8 HCO3-(AQ) 2-1.0 4.5 0.0 8 2 1.0 4 1.0 6 8 -2.367287E+02 0. 0. O. 0 9 H20(L) 2 0.0 0.0 0.0 9 2 1.0 6 1.0 7 9 -9.566350E+01 O. O. O. 0 10 SI02(AMOR) 3 0.00.0 2.0 10 1 1.0 3 10 -3.431060E+02 O. 0. O. 0 10 .005000 .2000060.08480 .005000 11 CASI03(S) 3 0.0 0.0 3.0 11 3 1.0 3 1.0 5 2.0 7 11 -6.252136E+02 O. O. O. 0 11 .060000 .25000116.16420 .005000

FIGURE D.8: A sample section of database file CHDATA.

123456789012345678901234567890123456789012345678901234567890123456789 14 5 62 AR(G) 1 9 1 NA+(AQ) 2 1 1 CL -(AQ) 3 2 1 CO3-2(AQ) 4 2 2 CA+2(AQ) 5 1 2 H+(AQ) 6 1 3 OH-(AQ) 7 2 3 HCO3-(AQ) 8 2 4 H20(L) 9 4 1 SI02(AMOR) 10 9 2 CASIO3(S) 11 9 3 FIGURE D.9: Asamplesection ofdatabasefile CONDATA. 116

1234567890123456789012345678901234567890123456789012345678901234567890 1 NA+ 1.0 1 CL-1 -1.0 0.0765000 0.2664000 0.0000000 0.00127000 2 CO3-2 -2.0 0.1897500 0.8460000 0.0000000 -0.04347400 3 OH-1 -1.0 0.0864000 0.2530000 0.0000000 0.00440000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 SO4-2 -2.0 0.0195800 1.1130000 0.0000000 0.00497000 2 CA+2 2.0 1 CL-1 -1.0 0.3159400 1.6140000 0.0000000 -0.00034300 2 CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3 OH-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 SO4-2 -2.0 0.2000000 2.6500000 -57.7000000 0.00000001 123456789012345678901234567890123456789012345678901234567890123456789 1 NA+1 2 CA+2 0.0700000 -0.0140000 1001.0000000 1001.0000000 1001.0000000 -0.0230000 1 NA+1 3 H+1 0.0360000 -0.0040000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 4 MG+2 0.0700000 -0.0120000 1001.0000000 1001.0000000 1001.0000000 -0.0150000 1 NA+1 5 ZN+2 0.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 6 FE+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 7 FE+3 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 9 CU+2 0.0000000 -0.0140000 1001.0000000 1001.0000000 1001.0000000 -0.0110000 1 NA+1 10 AG+1 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 1 NA+1 11 PB +2 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 1 NA+1 12 K+1 -0.0120000 -0.0018000 1001.00000001001.0000000 1001.0000000 -0.0100000 1 NA+1 13 MN+2 0.0000000 -0.0030000 1001.00000001001.0000000 1001.0000000 1001.0000000 1 NA+1 14 BA+2 -0.0030000 0.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 123456789012345678901234567890123456789012345678901234567890123456789 1 CL-1 2 CO3-2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 CL-1 3 OH-1 -0.0500000 -0.0060000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 -0.0080000 1001.0000000 1001.0000000 1001.0000000 1 CL-1 4 HCO3- 1001.0000000

FIGURE D.10: A sample section of the database file PITDATA. 117

FIGURE D.10 (Cont.)

1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1CL-1 5504-2 0.0200000 0.0014000 0.00000001001.0000000 -0.00400001001.0000000 1001.00000001001.00000001001.0000000 0.04300001001.0000000 1001.0000000 0.00000001001.00000001001.00000001001.0000000 12345678901234567890123456789012345678901234567890123456789012345678 ALPHA 2.0000000 ALPHAl 1.4000000 ALPHA2 12.0000000 APHI 0.3920000 1.2000000

RUNNING ISIS

ISIS was compiled from a FORTRAN source code and runon a Cyber

170 model 720 computer. The files necessary for ISIS are discussed earlier in this manual. ISIS requires that the database files

CHDATA, CONDATA, AND PITDATA be in the local fileaccess, and an input file such as in the example case, Figure D.1, is ready in the local file access also. The output files PITCON, and PITOUT must not be in the local file or else ISIS will crash, the output filename must not be an already used name or again the run will crash.

When ISIS is to be run, the compiled code must be in the local access file. When the compiled program is run, it prompts the user for the name of the input file, and then for thename of the output file, as is shown in Figure D.11. While the program is running the user is not required to give anymore input, except if the computer has a runtime limit that has to be acknowledged. Runtimes on the

Cyber 170 varied from four up to 30 CPU seconds. Output from the program is sent to the output file named when the program was 118 started. Some output is directed to the console. This output concerns the matrix operations in the program itself, and requires no feedback.

Error messages that were in SENECA2 were carriedover to ISIS.

Most of the error messages are self-explanatory, and deal witherrors made in assembling the input file. There are two types of error messages, the problem stop, and the error that could be corrected within the program. The error message for the problem stop would be printed and the program run stopped at that point. With the error that would continue to run, an error message would be printed and the run continued. If the later error type results ina converged answer from ISIS, the answer should be viewed with suspicion. The error should be corrected and the problemrun again. A list of error messages are in Table D.4. The error messages about unsuccessful

ISIS runs, answers that did not converge,mean that the initial conditions for the input file have to be modifiedto achieve a good run.

ISIS

? SPECIFY INPUT FILE NAME -

XXXXXXX

? SPECIFY OUTPUT FILE NAME

YYYYYYY

FIGURE D.11: Sample of ISIS program start. 119

TABLE D.4: Error messages in ISIS.

Subroutine SENECA2

1) CONFLICTING INPUT REQUESTS - - QUALITY GREATER THAN ZERO BUT NO COMPOSITION RESET REQUESTED COMPOSITION WILL BE RESET BASED ON INPUT QUALITY

2) NUMBER OF SOLID PHASES FOUND IS DIFFERENT FROM THE EXPECTED NUMBER NUMBER OF PHASES FOUND XXX NPHAS YYY PROBLEM WILL CONTINUE WITH NPHAS = YYY

3) IREDOX IS TOO LARGE PROBLEM STOP - CHECK INPUT DATA IREDOX = XXX ESET YYY

4) OXYGEN PARTIAL PRESSURE OR SULFATE/SULFIDE RATIO INPUT NEGATIVE VALUE PROBLEM STOP

5) STEAM. SATURATION PRESSURE GREATER THAN TOTAL PRESSURE-- CHECK INPUT DATA TEMP XXX PRESS YYY PSAT a ZZZ PROBLEM STOP IN SENECA2

6) SYSTEM CHARGES DO NOT BALANCE CHARGE SUM XXX CHECK INPUT DATA CALCULATION WILL CONTINUE

7) MOLES OF STEAM(XNS) TOO LARGE XNS XXX XNG = YYY PSAT = ZZZ PARTIAL GAS PRESSURE = AAA PROBLEM STOP

8) PHASE NUMBER MISMATCH NPHAS XXX NPA YYY CONTINUE CALCULATION USING NPHAS

9) ONLY KEY ELEMENTS ARE LEFT. NO ITERATION HAS BEEN PERFORMED IN THE NEWTON-RAPHESON ROUTINE THE MOLE FRACTIONS 'OT THESE KEY ELEMENTS WILL BE PRINTED ON THE NEXT PAGE.

10) SORRY, NO KEYS CAN BE LOCATED. THE MOLE FRACTIONS OF THE REMAINING SPECIES WILL BE PRINTED ON THE NEXT PAGE. 120

TABLE D.4 (Cont.)

11) THE NUMBER OF ITERATIONS IN NEWTON-RAPHESON ROUTINE (NEWSON) EXCEEDS THE ALLOWED MAXIMUM (KKMM) - XXX CALCULATION WILL CONTINUE

Subroutine MINI

1) MINI HAS EXCEEDED 50 ITERATIONS 50 CONSECUTIVE TIMES - PROGRAM STOP

Subroutine NEWSON

1) NUMBER OF SPECIES + NUMBER OF PHASES - XXX IS GREATER THAN ND - YYY REMOVE SOME SPECIES OR INCREASE PARAMETER ND- PROBLEM STOP

Subroutine ELNACT

1) IREDOX OUTSIDE RANGE OF ACCEPTABLE VALUES IREDOX = XXX PROBLEM STOP -- CHECK INPUT DATA

Subroutine GETCHEM

1) MISMATCH ON CHEMISTRY DATA FILE CHECK NUMBER OF CARDS PER SPECIES AND IPHASE NEAR SPECIES NUMBERED XXX YYY ZZZ CALCULATION TERMINATED STOP 76

2) NO MATCH WAS FOUND FOR ELEMENT XXX COMPARE LIST OF SPECIES AND INPUT COMPOSITIONS CALCULATION TERMINATED PROGRAM STOP 75

3) END OF FILE ENCOUNTERED ON CHEMISTRY DATA FILE THE FOLLOWING SPECIES NUMBERS WERE REQUESTED THOSE MARKED WITH** WERE NOT FOUND

4) REEXAMINE INPUT DATA CALCULATION TERMINATED PROBLEM STOP 77

REFERENCE: Feber, R. and Kerrisk, J. SENECA2 internal documentation. Los Alamos Scientific Laboratory, New Mexico, 1980. 121

ISIS has some troubles converging. Certain variables are important to having a successful run. The variables that have the greatest effect on the convergence are the H+, OH-, and the subroutine MINI tolerance TOLL

The combination of H+ and OH- are very important. The proper range for the starting amounts of those variables is impossible to predict. Kim (Kim, 1988) did work on an earlier version of ISIS using an IBM PC and found for thecases he studied that no true method existed for predicting the H+, OH- combinationthat would insure convergence. Kim also found that the region that would converge was very small. It was found that the best method for finding the convergence point was to experiment with therun file.

When one system has converged, a small change in the equilibrium point will still converge with thesame H+, and OH- values.

The variable TOL1 is another major factor in theconvergence of

ISIS. It is difficult to predict what value of TOL1 isnecessary to achieve convergence. It was found that setting the printer control index, IPR, to 1, and then watching the effect of the changein TOL1 would help in indicating the best value for TOLL Slight changes in the system were not found to cause major problems with TOL1values. 122

SUMMARY

ISIS requires one input file and three database files to berun.

Three output files are generated by the program, the mainoutput, and two files about the Pitzer ion interaction parameters. When ISIS is run, none of the output files can be present, or else the program will crash. The input file has to written correctly for the system of interest, or else problems with ISIS will arise. Most of the error messages that were in SENECA2, and were carried over to ISIS, but many input file mistakes would generatea simple crash before the program went too far. Convergence once the input file is corrected is a trial and error process. The main variables to experiment with are H+, OH-, and TOLL No pattern was found to recommend a course of attack on these variables. When proper convergence is achieved ISIS is found to be accurate. ISIS is also limited by the chemical potentials and activity coefficient information that it hasas starting material in the databases. 123

BIBLIOGRAPHY

Feber, R. and Kerrisk, J., SENECA2 internal documentation. Los Alamos Scientific Laboratory, 1980.

Kerrisk, J. F., Los Alamos Scientific Laboratory Report No. LA-8851-MS, UC66b, (May, 1981).

Kim, H. C. A Study of Chemical Equilibria for Strong Electrolytes in Aqueous Inorganic Solutions. Oregon State University, (June, 1988).

Ma Y. H. and Shipman, C. W., AIChE Journal 18(2), (1972).

Pitzer, K.S., "Theory: Ion Interaction Approach," in Activity Coef- ficients in Electrolyte Solutions, Vol. 1, R.M. Pytkowicz, Editor. CRC Press, Inc., Boca Raton, FL (1979). 124

APPENDIX E

ISIS SOURCE CODE

C ISIS (IONIC SPECIES INTERACTION SIMULATOR) C ISIS IS A MODIFIED VERSION OF SENECA2. C MODIFICATIONS OF PROGRAM TO INCLUDE A PITZER ACTIVITY C COEFFICIENT PREDICTION. C BY BARRY KELLY C C SENECA2 IS A MODIFIED VERSION OF SENECA BY C MA AND SHIPMAN, AICHE JOURNAL, VOL 18, NO 2,1972, C PP. 299-304. C MODIFICATIONS BY R. FEBER AND J. KERRISK OF LOS ALAMOS C SCIENTIFIC LABORATORY. C C LATEST VERSION JULY 04,1987 C PROGRAM ISIS CHARACTER*64 FNAME,FNAME2,TITLE DIMENSION T(50),TITLE(8),P(50),Q(50) WRITE(*,*)' SPECIFY INPUT FILE NAME -' READ(*,8001) FNAME 8001 FORMAT(A) OPEN(5,FILE=FNAME,STATUS='OLD') WRITE( *, *)' SPECIFY OUTPUT FILE NAME -' READ(*,8002) FNAME2 8002 FORMAT(A) OPEN(6,FILE=FNAME2,STATUS-'NEW) OPEN(15) OPEN(25,FTLE='CHDATA',STATUS='OLD') OPEN(30,FILE-IPITOUT',STATUS-'NEW') OPEN(31,FILE-.PITCONI,STATUS-1NEW) 10 CONTINUE READ(5,8000,END=25) TITLE 8000 FORMAT(8A10) WRITE(6,8010) TITLE 8010 FORMAT(2X,8A10) IREAD=-1 C C READ IN MULTIPLE TEMPERATURE, TEMPERATURES AND QUALITIES C READ(5,*) N1' NT - IABS(NT) READ(5,*) (T(I),I-1,NT) READ(5,*) (P(I),I=1,NT) READ(5,*) C C CALL SENECA FOR THE CASES STATED C 125

DO 20 I-1,NT CALL SENECA2(T(I),P(I),IREAD,Q(I)) 20 CONTINUE GO TO 10 25 CONTINUE WRITE(6,8020) 8020 FORMAT(2X,' EOF ON UNIT5 END OF INPUT DATA') END C C C C....SUBROUTINE SENECA2 C SUBROUTINE SENECA2(TEMP,PR,IREAD,QUAL) PARAMETER(ND-40) INTEGER ANAME,BNAME,CNAME,ANAMES,BNAMES,CNAMES INTEGER WTST COMMON ANAME(ND), BNAME(ND), CNAME(ND),IPHASE(ND), POTO(ND), 1AMT(ND), A(ND,ND), X(ND), E(ND),ST(ND,ND), P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MAKK,C(ND,ND), B(ND),IPR 3,AZERO(ND),Z(ND),IGAS,ELEC(ND) COMMON/ADDN/IGJWTST,A1120,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, 1 FRACT( ND), THERCON( ND), DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON/ITN/ITER,ASAVE(ND) COMMON/SALT/SLNMOL COMMON/JFKADD/CLK(6,ND) COMMON/JFKADX/TFP(ND) COMMON/REDOX/IREDOX,AELEC,ESET,TRDX,TCON COMMON/CHPOT/DGDK,DK,GPOT DIMENSION JSAVE(ND),PP(ND),ESAVE(ND),DSLN1(6),DSLN2(6) 1 ,AMTSV(ND),IDUM(ND),IDUM1(ND),IDUM2(ND),REDCOF(6,2) C COEFFICIENTS IN DENSITY EQUATIONS DATA DSLNI/-4.9017384E-01,1.8511008E-02,-8.8542829E-05, 1 2.1157153E-07,-2.5900226E-10,1.2701538E-13/ DATA DSLN2/-5.5171898E-02,1.3181904E-02,-6.0795153E-05, 1 1.3831342E-07,-1.6153135E-10,7.5158974E-14/ C COEFFICIENTS IN DELF/RT EQUATIONSFOR REDOX EQUATIONS DATA REDCOF/3.1782716E+2,-1.32944616E+0,1.82209378E-3, 1 -6.24750464E-7,-5.54373247E-10,0.0, 2 -6.55726336E+2,3.20421741E+0,-7.31189018E-3, 3 2.97881441E-6,1.08838328E-8,-1.14495731E-11/ C C C C VARIABLE DEFINITION C C A(J,I) IS A MATRIX OF COEFFICIENTSFOR THE FORMATION OF C SPECIES J-1,NSPCS FROM ELEMENTS I-1,NELMT. C AELEC IS THE ELECTRON ACTIVITY USED IN REDOX REACTIONS. AH20 IS THE ACTIVITY OF WATER. C AMT(J) IS THE AMOUNT OF SPECIES J. C AMTSV(J) IS USED TO SAVE AMT(J). C ANAME(J), BNAME(J), AND CNAME(J) CONTAINSTHE BCD NAME 126

C OF SPECIES J. C AZERO(J) IS A PARAMETER IN THE ACTIVITY COEFFICIENT C EQUATION FOR SPECIES J. C B(I) IS A UTILITY ARRAY. C C(I) IS A UTILITY ARRAY. C CLK(L,J) ARE COEFFICIENTS IN THE CHEMICAL POTENTIAL C POLYNOMIAL FOR SPECIES J L-1,6. C DENSLN IS THE DENSITY OF THE.SOLUTION PHASE IN G/CC. C DGDK IS THE DERIVITIVE OF G WITH RESPECT TO THE SEARCH C PARAMETER K. C DK IS THE STEP SIZE IN THE SEARCH PARAMETER K. C DSLNI(K) AND DSLN2(K) ARE COEFFICIENTS IN THE SOLUTION C DENSITY EQUATIONS. C E(I) IS THE AMOUNT OF ELEMENT I. C ELEC(J) IS THE NUMBER OF ELECTRONS INVOLVED IN THE REACTION C FOR SPECIES J. C ESAVE(I) IS USED TO SAVE VALUES OF E(I). C ESET IS THE VALUE INPUT THAT DETERMINES THE ELECTRON ACTIVITY. C FTOL1 IS A TOLERENCE REDUCTION FACTOR FOR TOLL. C G(J) IS THE CHEMICAL POTENTIAL OF SPECIES J. C GPOT THE GIBBS FREE ENERGY DIVIDED BY RT SAME AS G IN MINI. C H20(J)IS THE NUMBER OF WATER MOLECULES USED IN THE FORMATION OF SPECIES J. C I IS AN INTEGER USUALLY USED TO INDEX ELEMENTS. C ICHGCT IS USED TO INDICATE WHETHER THE CHARGE BALANCE HAS C BEEN DONE. C ICOTR IS AN INDEX USED IN REARRANGING SPECIES. C IDUM(J) IS AN ARRAY CONTAINING SPECIES NUMBERS FOR THE PROBLEM. C IDUM1(I) AN ARRAY CONTAINING ELEMENT NUMBERS FOR THE PROBLEM. C IG IS USED TO CONTROL THE ACTIVITY COEFFICIENT CALL C IG = 0 IS NO CALL IG = 1 IS CALL. C IGAS IS USED TO INDICATE WHETHER PHASE NUMBERS HAVE BEEN C ADJUSTED TO ACCOUNT FOR NO GAS PHASE. C INAMT IS USED TO CONTROL INPUT OF AN INITIAL ESTIMATE C OF COMPOSITION. C INCOM IS USED TO CONTROL RESTART OF CALCULATION WITH INITIAL C COMPOSITION ESTIMATE WHEN CONVERGENCE PROBLEMS OCCUR. C INDX3 IS USED TO INDICATE THE STATE OF MINI,TEST AND NEWSON C IN MINI INDX3 = 0 IF MINI HAS CONVERGED C 1 IF A KEY SPECIES AMOUNT HAS BECOME TOO SMALL C 2 IF SPECIAL ADJUSTMENT IN MINI IN STM 100+ C 3 IF MINIMIZATION PROCEEDING NORMALLY. C IN TEST INDX3 - 4 IF NO SUITABLE KEY SPECIES CAN BE FOUND. C IN NEWSON INDX3 = 0 IF NEWSON HAS CONVERGED C 1 IF A KEY SPECIES AMOUNT HAS BECOME TOO SMALL C 2 IF A NONKEY SPECIES AMOUNT HAS BECOME TOO SMALL 3 IF THE MAXIMUM NUMBER OF ITERATIONS EXCEEDED. C INTAP IS THE INPUT TAPE NUMBER -CHANGED FROM 5 TO 15 FOR C TWO PASS CALCULATION. C IPHASE(J) IS THE PHASE NUMBER OF SPECIES J. C IPR IS A PRINT CONTROL INDEX C 0 IS MINIMUM OUTPUT,1 IS INTERMEDIATE AND 2 IS MAXIMUM. C IPR1 ASSURES OUTPUT OF SPECIES LIST AT LEAST ONCE. 127

C IRDAMT CONTROLS INPUT OF SPECIES AMOUNTSON SECOND PASS. C IREAD CONTROLS DATA READING OR RESETTING C OF COMPOSITIONS AND AMOUNTS. C IREAD - -1 READ IN NEW CHEMISTRY DATA C TREAD - 0 DO NOT READ NEW CHEM DATA DO NOT RESET ELEMENT C OR SPECIES AMOUNTS C IREAD = 1 DO NOT READ NEW CHEM DATA- RESET ELEMENT AMOUNTS C TO ESAVE(I) RESET SPECIES AMOUNTS TO AMTSV(J) - C RESET INDX3 TO 10 C IREDOX IS AN OXIDATION-REDUCTIONCONTROL INDEX C IREDOX 0 IS NO REDOX REACTIONS C 1 CONTROLS AELEC BY SOLUTION EH C 2 CONTROLS AELEC BY OXYGEN PARTIALPRESSURE C 3 CONTROLS AELEC BY SULFATE/SULFIDERATIO. C ITER IS THE NUMBER OF ITERATIONS USEDIN MINI. C ITOL INDICATES WHETHER A VALUE OF TOLSIS AVAILABLE FROM A C PREVIOUS CALCULATION. C IZERO IS THE ELEMENT INDEX WITH ALL ZEROAMOUNTS ON RETURN FROM C TEST. C I2PAS IS A CONTROL VARIABLE FOR TWOPASS CALCULATIONS IT C INDICATES WHICH PASS IS IN PROGRESS. C JSAVE(J) IS USED IN REARRANGINGSPECIES. C JT - SPECIES NUMBER THAT HAS ZEROAMOUNT ON RETURN FROM MINI. C JTP SAVES A PAST VALUE OF JT. C JW IS THE INDEX OF THE SPECIES THATIS WATER SET IN MINI. C KICMA C KKMM IS THE MAXIMUM NUMBER OF ITERATIONSALLOWED IN NEWSON. C MACOTR IS A COUNT OF THE NUMBER OFSPECIES ELIMINATED BEFORE C CALLING NEWSON. C MAKK C NCOUNT IS THE NUMBER OF TIMES THESPECIAL MINIMIZATION SECTION IN MINI IS CALLED IN ANY ONE CALLTO MINI. NCTI AND NCT2 COUNT THE NUMBER OFTIMES TWO UNCONTROLLED LOOPS C IN TEST ARE CALLED. C ND IS THE PARAMETER VARIABLE USED TODIMENSION ARRAYS NEEDED C TO INCREASE THE SIZE OF THE PROBLEMTHAT CAN BE HANDLED, C INCREASE ND IN ALL SUBROUTINES. C NELMT IS THE NUMBER OF ELEMENTS (KEY SPECIES)FOR THE PROBLEM. C NLK(J) IS THE ORIGINAL SPECIES NUMBEROF SPECIES J. C NMINI IS THE NUMBER OF TIMES MINI IS CALLED. C NOVAP CONTROLS THE CALL TO COMPSETAND THE VAPORIZATION OF C SOLUTION WATER 0 - ALLOW COMPSET GALL C I - NO COMPOSITION RESETTING. C NPHAS IS THE NUMBER OF PHASES IN THE PROBLEM. C NPHA IS A SAVED VALUE OF NPHAS. C NREACT IS THE NUMBER OF REACTIONS CONSIDERED C NREACT IS NSPCS NELMT. C NREAC IS A SAVED VALUE OF NREACT. C NSPCS IS THE NUMBER OF SPECIES IN THE PROBLEM. C NSPC IS A SAVED VALUE OF NSPCS. C N4 IS A COUNT OF THE NUMBER OF TIMES TESTCOULD NOT FIND C A SUITABLE SET OF KEY SPECIES STOP IF .GT.9. C N5 IS A COUNT OF THE NUMBER OF SUCCESSIVETIMES THE 128

C MATERIAL BALANCE CRITERIA WAS NOT MET IN NEWSON C IF N5 .GT.5 RESART PROBLEM. C P IS THE GAS PHASE PRESSURE -IT MAY NOT INCLUDE THE C PRESSURE OF WATER VAPOR. C PHAS(K) IS THE AMOUNT OF PHASE K. C POTO(J) IS THE CHEMICAL POTENTIAL FOR SPECIES J C NORMALIZED BY R*T. C PP(K) IS A UTILITY ARRAY. C PR IS THE TOTAL PRESSURE IN ATM. C PWV IS THE VAPOR PRESSURE OF WATER AT THE TEMPERATURE C OF THE CALCULATION. C QUAL IS THE QUALITY OF THE SOLUTION MIXTURE (VAPOR FRACTION) WHEN CODE USED TO CALCULATE COMPOSITIONS C RESULTING FROM FLASHING. C REDCOF(K,L) ARE COEFFICIENTS IN THE TEMPERATURE POLYNOMIAL FOR REDOX CONTROL METHOD SET BY C IREDOX = L+1. C SLNMOL IS THE MOLES OF SALT IN THE SOLUTION USED FOR C CALCULATING SOLUTION DENSITY. C SLTMW IS THE AVERAGE MOLECULAR WEIGHT OF THE SALT IN THE C SOLUTION FOR SOLUTION DENSITY CALCULATION ONLY. C ST(J,K) ARE THE STOICHIOMETRIC COEFFICIENTS FOR SPECIES J C IN REACTION K. C TCON IS THE TEMPERATURE DEPENDENT CONSTANT IN THE REDOX C EQUATION -CALCULATED WITH REDCOF.

C TEMP IS THE TEMPERATURE OF THE CALCULATION - IN K. C TOL IS THE TOLERENCE USED IN THE SIMQWT CALL. C TOLL IS THE MINI TOLERENCE IT IS CHANGED IN MINI. C TOLS IS A SAVED VALUE OF TOLL. C TOL2 IS THE NEWSON TOLERENCE. C TOL3 IS THE MATERIAL BALANCE TOLERENCE. TRDX IS A SECOND VALUE OF THE TEMPERATURE IN K. C WTST IS THE BCD NAME FOR WATER. C WTSV IS USED IN DETERMINING THE WATER MATERIAL BALANCE. C X(J) IS THE MOLE FRACTION OF SPECIES J IN ITS PHASE. C XI IS THE IONIC STRENGTH OF THE SOLUTION C CALCULATED IN GAMMA. C XNG IS THE NUMBER OF MOLES OTHER THAN WATER IN THE GAS PHASE. C XNS IS THE NUMBER OF MOLES OF WATER IN THE GAS PHASE. C Z(J) IS THE CHARGE OF SPECIES J. C VARIABLES USED IN SCALE DEPOSITION CALCULATION. C C DENPPT(J) IS THE DENSITY OF SOLID PHASE J. C FWPPT(J) IS THE FORMULA WEIGHT OF SOLID PHASE J. TFP(J) 1S THE FRACTION PRECIPITATED IN ONE PRECIPITATION C MODEL. C THERGON(J) IS THE THERMAL CONDUCTIVITY OF SOLID PHASE J. C C DISCUSSION OF TOLERENCES USED IN SENECA2. C C TOLL IS MINI CONVERGENCE TOLERENCE C TOLL SHOULD BE BETWEEN 0.1*MINAMT AND 0.0001*MINAMT 129

C WHERE MINAMT IS THE SMALLEST AMOUNT OF AN ELEMENT INPUT C DIVIDED BY THE SUM OF ALL ELEMENT AMOUNTS INPUT TOL1 IS INPUT AS DATA C C TOL2 IS NEWSON CONVERGENCE CRITERION C TOL2 SHOULD BE AS SMALL AS PRACTICAL C 1.0E-10 IS A GOOD ESTIMATE C TOL2 IS INPUT AS DATA C C TOL3 IS MATERIAL BALANCE TOLERENCE - NEAR STM 18 C TOL3 SHOULD BE AS SMALL AS PRACTICAL C 1.0E-10 IS A GOOD ESTIMATE C C TOL1, TOL2, AND TOL3 SHOULD ALL BE GREATER THAN THE MACHINE ACCURACY -ON CDC THIS IS ABOUT 1E-14. C C FTOL1 IS TOL1 REDUCTION FACTOR IF TEST CANNOT FIND KEY C DATA TOL30FTOL1 / 1.0E-10,0.10 / C C INITIALIZE SOME VARIABLES INTAP - 5 I2PAS = 0 NOVAP = 0 JTP = 0 AELEC = 0.0 TRDX = TEMP C CHECK FOR NO SOLUTION VAPORIZATION IF(PR.LT.0.0) NOVAP = 1 PR - ABS(PR) C CHECK QUALITY AND VAPORIZATION CONTROLS FOR CONFLICT IF(QUAL.GT.1.OE -5 .AND. NOVAP.EQ.1) GO TO 1855 GO TO 1865 1855 WRITE(6,1857) 1857 FORMAT(//' CONFLICTING INPUT REQUESTS QUALITY GREATER 1,'THAN ZERO BUT NO COMPOSITION RESET REQUESTED'/ 2' COMPOSITION WILL BE RESET BASED ON INPUT QUALITY'/) NOVAP = 0 1865 IF(IREAD) 36,4,2 C C THIS SECTION READS IN DATA FOR PROBLEM C INITIALIZE SOME VARIABLES 36 WTST =4H H2O IRDAMT - 0 INAMT = 0 ITOL=O IGAS = 0 ICHGCT = 0 WTSV-0. READ(INTAP,*)NELMT,NSPCS,NREACT,NPHAS,TOL1,TOL2,TOL3,KKMM,IPR C CHECK WHETHER INPUT COMPOSITION WILL BE SUPPLIED. IF(NSPCS.LT.0) INAMT = 1 130

NSPCS = IABS(NSPCS) C RESET TOL1 FOR SECOND PASS OF TWO PASS CALC IF(I2PAS.EQ.2) TOL1 = TOLS 8 FORMAT(415,2E10.4,315) NSPC-NSPCS NREAC-NREACT TOLS-TOL1 NPHA-NPHAS WRITE(6,6) NELMT,NSPCS,NREACT,NPHAS,PR,TOL1,TOL2,10L3,KKMM,IPR 6 FORMAT(/' NELMT NSPCS NREACT NPHAS',9x,'PRESS. TOL1 TOL2 1 TOL3 KKMM IPR'/14,216,17, F16.2,1P3E9.1,16,15) C READ IN SPECIES NUMBERS, ELEMENT AMOUNTS AND ELEMENT NUMBERS. READ(INTAP,*)(IDUM(I),I-1,NSPCS) READ(INTAP,*)(ESAVE(I),IDUM1(I),I=1,NELMT) C CHECK FOR TWO PASS CALCULATION WRITE DATA ON TAPE15 C AND ADJUST NSPCS, NELMT, AND NREACT IF YES. IF(I2PAS.EQ.2) GO TO 1935 DO 1910 J=1,NSPCS IF(IDUM(J).GT.0) GO TO 1910 I2PAS = 1 REWIND 15 WRITE(15,*)NELMT,NSPCS,NREACT,NPHAS,TOL1,TOL2,TOL3,KKMM,IPR DO 1903 JX=1,NSPCS 1903 IDUM2(JX) = IABS(IDUM(JX)) WRITE(15,*)(IDUM2(JX),JX-1,NSPCS) DO 1905 IX-1,NELMT 1905 IDUM2(IX) = IABS(IDUM1(1X)) WRITE(15,*)(ESAVE(IX),IDUM2(IX),IX=1,NELMT) NSPCS = J-1 NSPC - NSPCS GO TO 1915 1910 CONTINUE GO TO 1935 1915 DO 1920 1-1,NELMT IF(IDUM1(I).GT.0) GO TO 1920 NELMT I-1 GO TO 1925 1920 CONTINUE 1925 NREACT = NSPCS-NELMT NREAC = NREACT WRITE(6,1930) 1930 FORMAT(//' THIS IS A TWO PASS CALCULATION'/ 1' THE FOLLOWING APPLIES TO THE FIRST PASS') WRITE(6,6) NELMT,NSPCS,NREACT,NPHAS,PR,TOL1,TOL2,TOL3,KKMM,IPR 1935 CONTINUE C PLACE SPECIES NUMBERS IN NUMERICAL ORDER DO 1990 J-1,NSPCS NEND = NSPCS-J DO 1985 JJ=1,NEND 1F(IDUM(JJ+1).CT.IDUM(JJ)) GO TO 1985 IDSV IDUM(JJ) IDUM(JJ) - IDUM(JJ+1) IDUM(JJ+1) = IDSV 131

1985 CONTINUE 1990 CONTINUE C CALL SUBROUTINE TO GET SPECIES DATA FROM FILE CHDATA. CALL CETCHEM(NSPCS,IDUM,NELMT,IDUM1) C ORDER ELEMENT NUMBERS DO 63 I-1,NELMT NEND = NELMT-I DO 62 II-1,NEND IF(IDUM1(II+1).GT.IDUM1(II)) GO TO 62 IDSV - IDUM1(II) IDUM1(II) = IDUM1(II+1) IDUM1(II+1) = IDSV DMSV = ESAVE(II) ESAVE(II) = ESAVE(II+1) ESAVE(II+1) = DMSV 62 CONTINUE 63 CONTINUE OUTPUT ELEMENTS AND AMOUNTS WRITE(6,110) 110 FORMAT(//10X,'THE FOLLOWING IS THE INPUT COMPOSITION IN 1MOLALITY'/) DO 21 I-1,NELMT IDUM1(I) WRITE(6,113)ANAME(I1),BNAME(I1),CNAME(I1),ESAVE(I) 113 FORMAT(11X,3A4,5X,1PE14.6) 21 CONTINUE SET PROPER PHASE NUMBERS FOR SOLID PHASES. IFC - 3 DO 60 I-1,NSPCS IF(IPHASE(I).LT.3) GO TO 60 IPHASE(I) = IFC IFC = IFC+1 60 CONTINUE IF(I2PAS.NE.1) GO TO 1940 C COUNT NUMBER OF PHASES - CHECK AGAINST INPUT VALUE NPHAS IFC-1 NPHA NPHAS GO TO 57 1940 CONTINUE IF(IFC-1.EQ.NPHAS) CO TO 57 IFC1 = IFC-1 WRITE(6,55)IFC1,NPHAS,IFC1 55 FORMAT(//' NUMBER OF SOLID PHASES FOUND IS DIFFERENT' 1,' FROM THE EXPECTED NUMBER'/ 2' NUMBER OF PHASES FOUND 1,13/ 3' NPHAS = ',I3/ 4' PROBLEM WILL CONTINUE WITH NPHAS = ',I3//) NPHAS = IFC1 NPHA = NPHAS 57 CONTINUE C SET NLK(J) VALUES DO 1795 J--1,NSPCS 1795 NLK(J) = J 132

C READ IN DATA FOR SOLUTION DENSITY CALCULATION READ(INTAP,*) SLNMOL,SLTMW IF(I2PAS.EQ.1) WRITE(15,*) SLNMOL,SLTMW WRITE(6,114) SLNMOL,SLTMW 114 FORMAT(//10X,'SALT MOLALITY = ',F8.5,7X,'SALT MOLECULAR WEIGHT = ',F10.5) GMSLT=SLNMOL*SLTMW C READ IN DATA FOR OXIDATION REDUCTION CALCULATION CHECK C FOR CONSISTANCY -TO STM 2055 READ(INTAP,*) IREDOX,ESET IF(I2PAS.EQ.1) WRITE(15,*) IREDOX,ESET IF(IREDOX.EQ.0) WRITE(6,2010) 2010 FORMAT(//' NO OXIDATION-REDUCTION REACTIONS INVOLVED'/) IF(IREDOX.EQ.1) WRITE(6,2015) ESET

2015 FORMAT(//' OXIDATION-REDUCTION REACTIONS CONTROLLED BY EH = ' 1 ,F8.4/' ELECTRON ACTIVITY CONSTANT' /) IF(IREDOX.EQ.2) WRITE(6,2020) ESET 2020 FORMAT(//' OXIDATION-REDUCTION REACTIONS CONTROLLED BY'

1, ' OXYGEN PARTIAL PRESSURE - ',1PE13.6, ' ATM'/

2 ' ELECTRON ACTIVITY VARIES WITH PH'/) IF(IREDOX.EQ.3) WRITE(6,2040) ESET 2040 FORMAT( / /'. OXIDATION-REDUCTION REACTIONS CONTROLLED BY'

1, ' SULFATE/SULFIDE RATIO - ',1PE13.6/

2 ' ELECTRON ACTIVITY VARIES WITH PH'/) IF(IREDOX.LE.3) GO TO 2051 WRITE(6,2050) IREDOX,ESET 2050 FORMAT(//' IREDOX TOO LARGE -PROBLEM STOP - CHECK INPUT DATA'/

1 ' IREDOX ',I6,7X,'ESET = ',1PE15.6) STOP 2051 IF(IREDOX.LE.1) GO TO 2055 IF(ESET.GT.0.0) GO TO 2055 WRITE(6,2053) ESET 2053 FORMAT(//' OXYGEN PARTIAL PRESSURE OR SULFATE/SULFIDE'

1, ' RATIO INPUT NEGATIVE'/

2 ' VALUE = ',1PE13.6/

3 ' PROBLEM STOP '//) STOP 2055 CONTINUE IF(TOLLGT.0.0) GO TO 2 C SET TOL1 IF INPUT VALUE NEGATIVE SUM = 0.0 DO 2080 I-1,NELMT SUM - SUM+ESAVE(I) 2080 CONTINUE TOLL = ESAVE(1)/SUM DO 2085 I-2,NELMT IF(TOLl.LT.(ESAVE(I)/SUM)) GO TO 2085 TOLL = ESAVE(I)/SUM 2085 CONTINUE TOLL a 0.01*TOL1 TOLS = TOL1 WRITE(6,2088) TOL1 2088 FORMAT(/' TOL1 SET TO ',1PE15.6) 133

C SET ELEMENT AMOUNTS FOR CALCULATION 2 DO 25 I-1,NELMT 25 E(I)-ESAVE(I) 16 FORMAT(E14.4) IF(ITOL.EQ.0) INDX3-10 C SKIP RESETTING SPECIES AMOUNTS FOR FIRST CALC IF(ITOL.EQ.0) GO TO 4 DO 710 J-1,NSPC I-NLK(J) 710 AMT(J)-AMTSV(I) C INITIALIZE SOME ADDITIONAL VARIABLES 4 N4-0 NMINI 0 N5 - 0 IPRI - 0 C CALC DELF/RT FOR ELECTRON ACTIVITY EQUATIONS IF(IREDOX.GE.2) TCON - SOLVE(REDCOF(1,IREDOX-1),TEMP,6) INCOM - 2 IF(IREAD NE.-1) WRITE(6,45) 45 FORMAT('1') WRITE(6,26) TEMP 26 FORMAT(/' TEMPERATURE - ',F9 4) C CALC VAPOR PRESSURE OF WATER - CHECK AGAINST TOTAL C PRESSURE - RESET PRESSURE OF SPECIES OTHER THAN WATER. XNS - 0.0 IF(QUAL.GT.1.OE -5) GO TO 1720 CALL BRINVP(TEMP,SLNMOL,PWV) IF(PWV.LT.PR) GO TO 1718 WRITE(6,1717) TEMP,PR,PWV 1717 FORMAT(//' STEAM SATURATION PRESSURE GREATER THAN TOTAL' 1,' PRESSURE -- CHECK INPUT DATA'/ 2' TEMP = ',1PE15.6/ 3' PRESS - ',1PE15.6/ 4' PSAT ',1PE15.6 //' PROBLEM STOP IN SENECA2') STOP 1718 P - PR-PWV IF(NOVAP.EQ.0) GO TO 1730 WRITE(6,1842) TEMP,PR,PWV,P 1842 FORMAT(//' SOLUTION COMPOSITION WILL NOT BE RESET'/ 1' TEMPERATURE = ',F10.4/ 2' INPUT TOTAL PRESSURE - ',F10.4/ 3' SATURATION PRESSURE OF WATER - ',F10.4/ 4' PRESSURE FOR GASSES OTHER THAN WATER RESET TO',1PE15.6/) GO TO 1730 C QUAL INPUT .GT. ZERO RESET. COMPOSITION BASED ON QUAL C THIS IS DONE ASSUMING QUAL OBTAINED FROM FLASHERCALCULATION. 1720 P PR 1725 IF(I2PAS.NE.1) CALL COMPSET(QUAL,NSPCS,NELMT,NSPC,XNS) 1730 IF(ITOL.EQ.0) GO TO 711 C FOR CALCULATIONS OTHER THAN THE FIRST RESET TOLS BASEDON C MINIMUM AMOUNT OF A SPECIES CALL MINV(AMT,1,NELMT,J,Y) TOLS-Y/10. 134

C RESET AMOUNTS OF SOLID SPECIES THAT WENT TO ZERO. Il-NELMT+1 DO 713 J-I1,NSPC IF(IPHASE(J).EQ.2) GO TO 713 IF(AMT(J).LE.TOLS) AMT(J)-1.1*TOLS 713 CONTINUE 711 ITOL-ITOL+1 IREAD-0 C CALC DENSITY OF SOLUTION D1=SOLVE(DSLN1,TEMP,6) D2-SOLVE(DSLN2,TEMP,6) DENSLN=D1+2.*(SLNMOL-0.5)*(D2-D1) WRITE(6,46) DENSLN 46 FORMAT(/' DENS. OF SOLN. ',F6.4,' GM/CC') C SET VARIABLES AND INITIALIZE SUBROUTINE GAMMA NSPCS=NSPC NREACT-NREAC TOLl-TOLS CALL GAMSET(NSPCS,TEMP,IDUM) C CALC CHEMICAL POTENTIAL OF SPECIES INCLUDE PRESSURE FOR GAS DO 20 J=1,NSPCS K= NLK(J) POTO(J)-SOLVE(CLK(1,K),TEMP,6) IF(IPHASE(J)-1)20,19,20 19 POTO(J)=POTO(J)+ALOG(P) 20 CONTINUE IF(INDX3-3)80,80,22 C PROGRAM SELECTS ELEMENTS IN THEIR MOST STABLE FORMS AS C KEY SPECIES, REARRANGES THE DATA SET AND ASSIGNS ALL C AMOUNTS TO ELEMENTS AS INITIAL COMPOSITION ESTIMATE C STM 22 TO STM 75 22 JJ-1 IG-0 707 CONTINUE DO 9 I-1,NSPCS 9 G(I)=1. DO 70 I=1,NELMT ICOTR =O DO 40 J=1,NSPCS IF(A(J,1))40,40,27 27 IT-I+1 IF(IT-NELMT)29,29.32 29 DO 31 K=IT,NELMT IF(A(J,K))40,31,40 31 CONTINUE 32 IT-I-1 IF(IT)38,38,35 35 DO 37 K-1,IT IF(A(J,K))40,37,40 37 CONTINUE 38 ICOTR-ICOTR+1 JSAVE(ICOTR)=J 40 CONTINUE 135

41 IF(ICOTR-1)42,42,44 42 J JSAVE(ICOTR) GO TO 50 44 J JSAVE(1) COMPPOTO(J)/A(J,I) DO 49 K...2,ICOTR WSAVE(K) IF(COMP-POTO(L)/A(L,I))49,49,47 47 COMPPOTO(L)/A(L,I) JL 49 CONTINUE 50 ANAMESANAME(J) ANAME(J)...ANAME(JJ) ANAME(JJ).ANAMES ANAMESBNAME(J) ENAME(J).BNAME(JJ) BNAME(JJ)ANAMES ANAMESCNAME(J) CNAME(J) CNAME(JJ) CNAME(JJ)ANAMES IPHAS...IFHASE(J) IPL95 E(J)IPHASE(jJ) IPHASE(JJ).-.ITHAS POTOS=POTO(J) POTO(J).-,POTO(JJ) POTO(JJ)POTOS ANAMEX Z(J) Z(J) Z(JJ) Z(JJ)ANAMEX ANAMEX.-AZERO(J) AZEROWaNAZERO(JJ) AZERO(SJ)esANAMER NLKS NLK(J) NLK(J)NLK(JJ) NLK(Jj)iNLKS ANTS AMT(J) AMT(J) AMT(JJ) AMT(JJ) AMTS ELECS FT.FC(J) ELEC(J) ELEC(JJ) ELEC(JJ) ELECS DO 68 I1 =1,NELMT ASA(J,I1) A(J,I1)-4(JJ,I1) 68 A(JJ,I1) AS JJ JJ +1 70 CONTINUE IF(N4.GT.0 .AND. INCOM.LT.2) GO TO 1980 DO 72 J- 1,NELMT 72 AMT(J)E(J)/A(J,J) KNELMT+1 DO 75 .J.=,K,NSPCS 75 AMT(J)-0. 136

C RESET INCOM AND JTP JTP = 0 INCOM - 0 1980 CONTINUE IF(IRDAMT.EQ.1) GO TO 80 IF(I2PAS.NE.2 .AND. INAMT.EQ.0) GO TO 80 C READ IN PREVIOUS COMPOSITION FOR TWO PASS CALCULATION READ(INTAP,*) NSPCHG READ(INTAP,*)(PP(J),IDUM1(J),J-1,NSPCHG) IRDAMT - 1 DO 1815 J-1,NSPCS JN NIK(J) ISP IDUM(JN) DO 1810 JX-1,NSPCHG IF(ISP.NE.IDUM1(JX)) GO TO 1810 AMT(J) - PP(JX) GO TO 1815 1810 CONTINUE 1815 CONTINUE IF(I2PAS.E0.2) GO TO 80 C NORMALIZE AMT(J) TO INPUT ELEMENT AMOUNTS E(I) DO 1830 I-1,NELMT SUME - 0.0 DO 1820 J-1,NSPCS 1820 SLIME s SUME+(AMT(J)*A(J,I)) IF(SUME.EQ.E(1)) GO TO 1830 IF(SUME.EQ.0.0) GO TO 1830 DO 1825 J-1,NSPCS 1825 AMT(J) - AMT(J)*E(I)/SUME 1830 CONTINUE C SUM AMOUNT OF EACH PHASE PRESENT 80 DO 85 I-1,NPHAS PHAS(I)-0. DO 88 J- 1.NSPCS IF(IPHASE(J)-I)86,84,86 84 PHAS(I)- PHAS(I) +AMT(J) 86 CONTINUE 85 CONTINUE IF(IPR.EQ.0 .AND. IPR1.GT.0) GO TO 87 C OUTPUT SPECIES LIST AND ASSOCIATED DATA WRITE(6,7) TOL1 7 FORMAT(/' TOL1 ',1PE13.6/16X,'POTO AMT 1 Z AZERO IPHASE') WRITE(6,10)(ANAME(J),BNAME(J),CNAME(J),POTO(j),AMT(J),Z(J), 2 AZERO(J),IPHASE(J),J-1,NSPCS) 10 FORMAT(3A4,0PF10.3,1PE11.3,0PF5.0,0PF6.1,I6) 87 IPR1 - 1 IF(ICHGCT.GT.0) GO TO 1748 C CHECK CHARGE BALANCE SUMZ - 0.0 DO 1740 J-1,NSPCS 1740 SUMZ - SUMZ+(AMT(J)*Z(J)) ICHGCT - 1 137

IF(ABS(SUMZ).LT.1.0E-07) GO TO 1745 WRITE (6,1742) SUMZ 1742 FORMAT(//' SYSTEM CHARGES DO NOT BALANCE'/ 1' CHARGE SUM - ',1PE15.6/ 2' CHECK INPUT DATA'/ 3' CALCULATION WILL CONTINUE'//) CO TO 1748 1745 WRITE(6,1746) 1746 FORMAT(//' SYSTEM CHARGES BALANCE'/) 1748 CONTINUE C CAIC MOLE FRACTIONS (X(J)) IN EACH PHASE DO 94 J- 1,NSPCS I-IFHASE(J) IF(PHAS(I))89,89,91 89 X(J)-1. GO TO 94 91 X(J)-AMT(J)/PHAS(I) IF(X(J)-1.E-10) 93,93,94 93 X(J)-1.E-10 94 CONTINUE COMPUTE STGICHIOMETRIC COEFFICIENTS FOR EACH SPECIES C STM 95 TO STM 118 95 M-NELMT+1 DC 112 J-H,NSPCS DO 98 I=1,NELMT 9$ B(I)=-ACJ,I) DO 102 I-1 NFIMT DO 101 K-I,NELMT 101 C(I,K)-ACK.I) 102 CONTivOt. GATT ARRAV(2,NEIMT,NELMT,ND,ND,C,C) C TOL USED TO DETERMINE WHEN A MATRIX IS SINGULAR IN THE C STOluMiOMETRIC COEN.ICIENT COMPUTATION. TOL=LE-10 CALL SIMOWT(C,B,NFIMT,KS,TOL) JR-J-NELMT MAKK-0 DO L11 I-1 NELMT ill ST(I,JR)-B(I) 112 CONTINUE DO 118 J-M,NSPCS DO Ili IR-1,NREACT IF(IE+NEIMT-J)116,115,116 115 ST(J,IR)-1. GO TO 117 116 ST(J,IR)-0. 117 CONTINUE 118 CONTINUE C C CALL MINI AND TEST C 119 NCOUNT - 0 NMINI NMINI+1 138

IF(IPR.GT.0) WRITE(6,121) NMINI,TOL1 121 FORMAT(/' START MINI CALL NUMBER ',I3, 1 7X,'TOL1 ',1PE13.6) C MINI IS THE DIRECT MINIMIZATION ROUTINE CALLED TO GET A C PRELIMINARY ESTIMATE OF THE COMPOSITION FOR NEWSON. CALL MINI(NSPCS,NELMT,TOL1,NCOUNT) IF(IPR.GT.0) WRITE(6,720) DGDK,DK,GPOT IF(IPR.GT.0) WRITE(6,700) ITER,INDX3,NCOUNT 720 FORMAT(' DGDK ',1PE13.6,7X,'DK - ',1PE13.6,7X, 1 'G - ',1PE13.6) 700 FORMAT(' NO. MINI ITERATIONS - ',I3,7X,'INDX3 - ',I2, 1 7X,'NCOUNT ',I6) IF(INDX3.EQ.1.AND.IPR.GT.0) WRITE(6,690)ANAME(JT) 1 ,BNAME(JT),CNAME(JT) 690 FORMAT(' SPECIES ',3A4,' WENT TO ZERO') IF(INDX3.EQ.0) JPT 0 C BRANCH BASED ON MINI INDX3 VALUE IF(INDX3-1)130,127,183 127 CONTINUE NCT1 - 0 NCT2 = 0 TEST SELECTS A NEW SET OF KEY SPECIES IF A KEY SPECIES C WENT TO ZERO AMOUNT IN MINI CALL TEST(NSPCS,NELMT,NCII,NCT2,IZERO) IF(IPR.GT.0) WRITE(6,702) INDX3,NCT1,NCT2 702 FORMAT(' TEST',7X 'INDX3 ',I2,8X, 1 'NCT1 C BRANCH BASED ON TEST INDX3 VALUE IF(INDX3-4)95,34,95 C THE FOLLOWING TO STM 130 -1 RESETS COMPOSITIONS C THAT- HAVE GONE-TO Lhit0 WHEN A SET OF KEY C SPECIES CANNOT BE FOUND. TRY TO KEEP MATERIAL BALANCE. C N4 IS USED TO COUNT NUMBER OF TTMFC SET OF KEY C SPECIES CANNOT BE FOUND MORE THAN 9 - QUIT. 34 N4-N4+1 IF(N4.GT.9) GO TO 169 TOLS-FTOLl*TQLS TOLl-TOLS IF(IZERO.EQ.0) GO TO 2205 C THIS SECTION RESETS COMP IF ALL SPECIES OF ONE ELEMENT C HAVE ZERO AMT. IZERO IS ELEMENT NUMBER C WITH ALL SPECIES WITH ZERO COMPOSITION. DO 2150 J-1,NSPCS IF(A(J,IZERO).EQ.0) GO TO 2150 J1 -J GO TO 2160 2150 CONTINUE STOP 2160 AMT(J1) 1.1*TOL1 EX - E(IZERO) (AMT(J1)*A(J1,IZER0)) IF(EX.GE.0.0) GO TO 2180 TOLL - E(IZERO) /(1.1 *A(J1,IZERO)) AMT(J1) 1.1*TOL1 139

GO TO 2300 2180 JJ1 = J1+1 SUM - 0.0 DO 2185 J-JJ1,NSPCS 2185 SUM - SUM+A(J,IZERO) IF(SUM.LE.0.0) SUM - 1.0 EX - EX/SUM DO 2190 J-JJ1,NSPCS IF(A(J,IZERO).EQ.0) GO TO 2190 AMT(J) - EX 2190 CONTINUE GO TO 2300 2205 CONTINUE C IN THIS SECTION SOME SPECIES OF ELEMENT IN TROUBLE HAVE C NONZERO COMP, BUT THEY ARE KEY SPECIES FOR OTHER ELEMENTS. C MUST ACCOUNT FOR ALL OF ELEMENT IN RESETTING COMP OF C SPECIES THAT WENT TO ZERO SUM - 0.0 DO 2210 I-1,NSPCS 2210 SUM - SUM + (A(I,JT)*AMT(I)) EX = E(JT)-SUM IF(EX.GT.0.0) GO TO 2240 AMT(JT) 1.1*TOL1 GO TO 2300 2240 AMT(JT) = EX/A(JT,JT) 2300 CONTINUE C CHECK IF ANY MORE KEY SPECS HAVE ZERO AMT C RECYCLE TO STM 2205 IF SO DO 2310 I-1,NELMT IF(AMT(I).GT.0.0) GO TO 2310 JT= I GO TO 2205 2310 CONTINUE JJ=1 IF(JT.NE.JTP) INCOM = 0 IF(JT.EQ.JTP) INCOM INCOM+1 JTP - JT C GO BACK TO STM 707 OR STM 80 FOR NEW START IF(INCOM.GE.2) GO TO 707 GO TO 80 C MINI CONVERGED IF ACTIVITY COEFF NOT YET CALCULATED (IG-0) C RESET IG AND GO BACK INTO MINI 130 IF(IG.GT.0) GO TO 132 IG - 1 TOL1 TOLS/10.0 IF(IPR.GT.0) WRITE(6,134) 134 FORMAT(/' PRIOR CALCULATIONS WERE DONE WITH UNIT ACTIVITY'

1, ' COEFFICIENTS'/

2 ' ACTIVITY COEFFICIENT CALCULATION HAS BEEN ACTIVATED') GO TO 119 132 IF(QUAL.GT.1.0E-5) GO TO 131 IF(XNS.GT.0.0) GO TO 131 IF(IGAS.GT.0) GO TO 131 140

IF(NOVAP.EQ.1) GO TO 131 C ESTIMATE MOLES OF WATER IN GAS PHASE BASED ON MOLES OF OTHER C SPECIES PRESENT, PRESSURE OF OTHER SPECIES AND VAPOR C PRESSURE OF WATER - ASSUMES WATER VAPOR SATURATES THE GAS C PHASE AND USED XNG - 0.0 DO 1750 J- 1,NSPCS IF(IPHASE(J).NE.1) GO TO 1750 XNG XNG+AMT(J) 1750 CONTINUE XNS PWV*XNG/P IF(XNS.LE.0.0) GO TO 131 IF(XNS.LE.10.0) CO TO 1760 WRITE(6,1755) XNS,XNG,PWV,P 1755 FORMAT(//' MOLES OF STEAM(XNS) TOO LARGE'/ 1' XNS ',1PE15.6/ 2' XNG - ',1PE15.6/ 3' PSAT ',1PE15.6/ 4' PARTIAL GAS PRESSURE 1,1PE15.6/1 PROBLEM STOP') STOP C CALL COMPSET TO RESET COMPOSITION BASED ON XNS MOLES OF WATER C REMOVED FROM SOLUTION AND TRANSFERRED TO GAS PHASE C GO BACK TO MINI FOR NEW COMPOSITION ESTIMATE 1760 IF(I2PAS.NE.1) CALL COMPSET(0.0,NSPCS,NELMT,NSPC,XNS) GO TO 119 C REMOVE SPECIES AND PHASES THAT WENT TO ZERO IN MINI C REARRANGE DATA SET IN PREPERATION FOR CALL TO NEWSON C STM 131 TO STM 158 131 MACOTR-O IrNELMT+1 DO 147 J-L,NSPCS IF(AMT(J))133,133,135 133 MAG0IReMACOTR+1 GO TO 147 135 K-J-MACOTR ANAMESANAME(K) BNAMES=BNAME(K) CNAMESCNAME(K) ANAME(K)=ANAME(J) BNAME(K)BNAME(J) CNAME(K)CNAME(J) ANAME(J)flANAMES BNAME(J)-BNAMES CNAME(J)-CNAMES AMTS-AMT(K) AMT(K)AMT(J) AMT(J)-AMTS XS -X(K) X(K) -X(J) X(J)XS POTOS-POTO(K) POTO(K)POTO(J) POTO(J) - POTOS 141

IPHAS-IPHASE(K) IPHASE(K)-IPHASE(J) IPHASE(J)-IPHAS S-Z(K) Z(K)-Z(J) Z(J)-S S-AZERO(K) AZERO(K)=AZERO(J) AZERO(J)-S S-G(K) G(K)=G(J) G(J) -S NLKS-NLK(K) NLK(K)-NLK(J) NLK(J)-NLKS ELECS ELEC(K) ELEC(K) - ELEC(J) ELEC(J) ELECS DO 136 I-1,NELMT AS-A(K,I) A(K,I)-A(J,I) 136 A(J,I) =AS IR-J-NELMT KR-IR-MACOTR IF(KR)147,147,137 137 DO 138 J1-1,NELMT 118 ST(J1,KR)-ST(J1,IR) 147 CONTINUE NSPCS-NSPCS-MACOTR NREACT-NREACT-MACOTR C CHECK FOR PRESENCE OF GAS PHASE REDUCE PHASE NUMBERS BY 1 C IF NO GAS PHASE PRESENT IF(IGAS.EQ.0) GO TO 1736 IF(MACOTR.LE.0) GO TO 1736 DO 1735 I-1,MACOTR 1735 IPHASE(I+NSPCS) - IPHASE(I+NSPCS)+1 1736 CONTINUE C IF NREACT .LE. ZERO ONLY KEY SPECIES ARE LEFT NO CALL TO C NEWSON REQUIRED IF(NREACT)166,166,151 151 K-1 152 MACOTR-0 DO 154 J-1,NSPCS IF(IPHASE(J)-K)154,153,154 153 MACOTR-MACOTR+1 154 CONTINUE IF(MACOTR)155,155,159 155 IF(K.EQ.1) IGAS - 1 DO 157 J-1,NSPCS IF(IPHASE(J)-K)157,157,156 156 IPHASE(J)-IPHASE(J)-1 157 CONTINUE NPHAS-NPHAS-1 142

GO TO 158 159 K-K+1 158 IF(K-NPHAS)152,152,163 C CHECK MATERIAL BALANCE AFTER MINI CONVERGED 163 IF(IPR.EQ.0) GO TO 2535 WRITE(6,2502) 2502 FORMAT(/' MATERIAL BALANCE ERRORS AFTER MINI') DO 2530 I-1,NELMT B(I) - E(I) DO 2520 J-1,NSPCS 2520 B(I) - B(I)-(AMT(J)*A(J,I)) FRAC - B(I)/E(I) WRITE(6,2522) I,B(I),FRAC 2522 FORMAT(' I - ',I3,4X,'ERROR ',1PE13.6,4X, 1 'FRAC ERROR - ',1PE13.6) 2530 CONTINUE C NEWSON SOLVES EXACT EQUATIONS USING ESTIMATE FROM MINI AS C INITIAL GUESS FOR COMPOSITION. 2535 CALL NEWSON(NSPCS,NELMT,TOL2,KKMM) IF(IPR.GT.0) WRITE(6,703) INDX3 703 FORMAT(' END NEWSON',7X,'INDX3 ',I2) C BRANCH BASED ON NEWSON INDX3 VALUE GO TO (706,127,119,1690,715),INDX3+1 C CALCULATED COMPOSITION CHANGE TOO LARGE -INITIAL ESTIMATE C OF COMPOSITION PROBABLY NOT GOOD ENOUGH C RESET TOL1 AND REINTRODUCE SPECIES WITH ZERO AMOUNTS - C GO BACK TO STM 707 FOR NEW START C STM 715 TO STM 2440+1 715 JJ - 1 N4 - N4+1 IF(N4.,GT.9) GO TO 169 INCOM - 2 TOL1 0.1*TOLS IF(IGAS.EQ.0) GO TO 2410 DO 2405 J-1,NSPCS 2405 IPHASE(J) IPHASE(J) + 1 NPHAS NPHAS + 1 IGAS - 0 2410 CONTINUE IF(NSPCS.EQ.NSPC) GO TO 2430 NSPC1 NSPCS+1 DO 2420 J-NSPC1,NSPC IF(AMT(J).LT.0.0) AMT(J) = 0.0 IF(IPHASE(J).LE.2) GO TO 2420 NPHAS NPHAS+1 IPHASE(J) = NPHAS 2420 CONTINUE 2430 CONTINUE NSPCS - NSPC NREACT - NREAC IF(NPHAS.EQ.NPHA) GO TO 2440 WRITE(6,2435) NPHAS,NPHA 2435 FORMAT(/' PHASE NUMBER MISMATCH'/ 143

1 ' NPHAS ',I3,6X,'NPHA - ',I3/

2 ' CONTINUE CALCULATION USING NPHAS'/) 2440 CONTINUE GO TO 707 C NEWSON CONVERGED - CHECK MATERIAL BALANCE AGAINST TOL3 706 IRPT-0 DO 17 I-1,NELMT B(I)-E(I) DO 18 J-1,NSPCS IF(NLK(J).EQ.I) 18 B(I)-B(I)-AMT(J)*A(J,I) IF(ABS(B(I)).LT.TOL3) GO TO 17 IRPT-IRPT+1 IF(IRPT.EQ.1 .AND. IPR.GT.0) WRITE(6,730) 730 FORMAT(' MATERIAL BALANCE ERRORS FROM NEWSON') AMT(I1)-AMT(I1)+B(I)*(1.-0.05*FLOAT(IRPT)) IF(AMT(I1).1..E.0.0) AMT(I1) - 1.1*TOLS IF(IPR.GT.0) WRITE(6,705) I,B(I) 705 FORMAT(' I - ',I3,7X,'B(I) - ',1PE13.6) 17 CONTINUE IF(IRPT.EQ.0) GO TO 1690

C MATERIAL BALANCE ERRORS - RESET TOL1 AND GO BACK TO MINI C IF 5 SUCCESSIVE CALLS TO NEWSON GIVE MATERIAL BALANCE C ERRORS GO TO STM 715 FOR NEW START. N5 - N5+1 IF(N5.LE.5) GO TO 718 N5 -0 GO TO 715 718 CONTINUE TOL1 0.5*TOLS TOLS - TOL1 IF(IPR.GT.0) WRITE(6,16-88) T011 1688 FORMAT(' TOI1 RESET TO ',1PE13.6) GO TO 119 1690 CONTINUE C IF MAX NUMBER OF ITERATIONS EXCEEDED IN NEWSON PRINT IF(INDX3.EQ.3) WRITE(6,180) KKMM C RESET PHASE NUMBERS IF NO GAS PHASE IF(IGAS.EQ.0) GO TO 1710 DO 1705 J-1,NSPCS 1705 IPHASE(J) - IPHASE(J)+1 NPHAS NPHAS+1 IGAS = 0 1710 CONTINUE IF(INDX3.GT.2) GO TO 171 C ZERO AMOUNTS IF NECESSARY RENUMBER PHASES IF SOME NOT C PRESENT IF(NSPCS.EQ.NSPC) GO TO 704 NSPC1-NSPCS+1 DO 701 J-NSPC1,NSPC IF(AMT(J).LT.0.) AMT(J)-0. IF(IPHASE(J).LE.2) GO TO 701 NPHAS-NPHAS+1 144

IPHASEM-NPHAS 701 CONTINUE 704 GO TO 708 C PRINT STATEMENT IF ONLY KEY SPECIES LEFT 166 WRITE(6,167) C SAVE COMPOSITION FOR FUTURE INITIAL ESTIMATE 708 DO 709 J-1,NSPC I-NLK(J) 709 AMTSV(I)-AMT(J) GO TO 171 C N4 .GT. 9- COULD NOT FIND SET OF KEY SPECIES 9 TIMES C PRINT MESSAGE AND SOME DATA 169 WRITE(6,170) 171 WRITE(6,172) TEMP,PR N1-0 C WATER MATERIAL BALANCE DO 712 J-1,NSPCS IF(IPHASE(J).NE.1) GO TO 712 N-NLK(J) IF(H20(N).LE.O.) GO TO 712 ADD-AMT(J)*H20(N)-WTSV AMT(JW) =AMT(JW) +ADD WTSV-ADD 712 CONTINUE C OUTPUT RESULTS DO 174 J-1,NSPCS IF(IPHASE(J).NE.1) GO TO 1 PP(J)-X(J)*P WRITE(6,162)ANAME(J),BNAME(J),CNAME(J),IPHASE(J),AMT(J),PP(J) 162 FORMAT(1H0,3A4,111,5X,1PE21.4,1PE63.4) GO TO 174 1 IF(IPPIASE(J).EQ.2) GO TO 160 WRITE(6,164)ANAME(J),BNAME(J),CNAME(J),IPHASE(J),AMT(J),X(J) 164 FORMAT(1H0,3A4,111,5X,1PE21.4,1PE42.4) GO TO 174 160 IF(J.NE.JW) GO TO 161 WRITE(6,164)ANAME(J),BNAME(J),CNAME(J),IPHASE(J),AMT(J),AH20 GO TO 174 161 ACT-AMT(J)*G(J) WRITE(6,175)ANAMEMBNAME(J),CNAME(J),IPHASE(J),AMT(J),G(J),ACT IF(ANAME(J).EQ.4H H+() N1 =J IF(ANAME(J).EQ.4H OH-) N2 =J 174 CONTINUE IF(N4.GT.9) STOP IF(XNS.LE.0.0) GO TO 1785 C IF WATER IN GAS PHASE OUTPUT DATA WRITE(6,1780) XNS,PWV 1780 FORMAT(/' WATER VAPOR',10X,'1',5X,1PE21.4,42X,1PE21.4) 1785 CONTINUE C COMPUTE SOLUTION PH AND OUTPUT IF(N1.EQ.0) GO TO 51 PH--ALOG10(AMT(N1)*G(N1)) GO TO 52 145

51 PH--ALOG10(EXP(POTO(JW))/(AMT(N2)*C(N2))) 52 WRITE(6,3) XI 3 FORMAT(/6X,'IONIC STRENGTH- ',1PE11.4) WRITE(6,53) PH 53 FORMAT(6X,'PH - ',F9.6) C COMPUTE SOLUTION EH AND OUTPUT IF IREDOX .GT. 0 IF(IREDOX.EQ.0) GO TO 2070 EH - -AELEC*TRDX/11605.4 WRITE(6,2060) EH 2060 FORMAT(6X,'EH - ',F9.6,' VOLTS') 2070 CONTINUE WRITE(6,2072) QUAL 2072 FORMAT(6X,'QUALITY- ',F7.4) C OUTPUT MATERIAL BALANCE ERRORS WRITE(6,14)(J,B(J),J=1,NELMT) 14 FORMAT(1H1,'MATERIAL BALANCE ERRORS'/' ELEMT'AI5,1PE15,5)) C OUTPUT INDX3 WRITE(6,28) INDX3 28 FORMAT(/5X,'INDX3 -',I2) IF(INDX3-3)183,179,179 183 WRITE(6,181) 179 IF(I2PAS.NE.1) GO TO 185 C FOR FIRST PASS OF TWO PASS CALCULATION WRITE COMPOSITION C ESTIMATE ON TAPE15 I2PAS = 2 INTAP 15 DO 1950 J-1,NSPCS JN - NLK(J) 1950 IDUM1(J) IDUM(JN) WRITE(15,*)NSPCS WRITE(15,*)(AMT(J),IDUM1(J),J=1,NSPCS) REWIND 15 WRITE(6,1955) 1955 FORMAT(1H1,'THIS IS THE SECOND PASS- SOME ELEMENTS' 1,' AND SPECIES HAVE BEEN ADDED'//) GO TO 36 185 CONTINUE RETURN C MISCELLANEOUS FORMAT STATEMENTS 167 FORMAT(///' ONLY KEY ELEMENTS ARE LEFT. NO ITERATION HAS

1BEEN PERFORMED IN THE NEWTON-RAPHESON ROUTINE '// 13X, ' 2 THE MOLE FRACTIONS OF THESE KEY ELEMENTS WILL

3 BE PRINTED ON THE NEXT PAGE 1) 170 FORMAT(/// SORRY, NO KEYS CAN BE LOCATED. THE MOLE FRACTIO 1NS OF THE REMAIN SPECIES WILL BE PRINTED ON THE NEXT PAGE.') 172 FORMAT(11.//' TEMPERATURE- ',F10.4,5X,'DEG K'//' PRESSURE-' 1,F10.4,5X,'ATM'//' SPECIES',14X,'PHASE',15X,'AMOUNT',14X, 2'ACTIVITY',13X,'ACTIVITY',14X,IPARTIAL71H ,21X,'NUMBER',33X, 3'COEFFICIENT',33X, 'PRESSURE') 175 FORMAT(1H0,3A4,I11,5X,1P4E21.4)

180 FORMAT (// ' THE NUMBER OF ITERATIONS IN NEWTON-RAPHESON'

1, ' ROUTINE (NEWSON) EXCEEDS THE ALLOWED MAXIMUM (KKMM)- ,I3/

2 ' CALCULATION WILL CONTINUE'//) 146

181 FORMAT(/' NORMAL EXIT') END C C C....SUBROUTINE TEST C C SUBROUTINE TEST (NSPCS,NELMT,NCT1,NCT2,IZERO) PARAMETER(ND-40) PARAMETER(ND1-ND+1) INTEGER ANAME,BNAME,CNAME,ANAMES,BNAMES,CNAMES INTEGER WTST COMMON ANAME(ND), BNAME(ND), CNAME(ND), IPHASE(ND), POTO(ND), LAMT(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND), P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MAKK, C(ND,ND), B(ND),IPR 3,AZERO(ND),Z(ND),IGAS,ELEC(ND) COMMON/ADDN/IG,WTST,AH20,G(ND),X1,NLK(ND),H20(ND),JW, & TOLS,FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSIN DIMENSION JP(ND,ND), KEY(ND), ML(ND1),LM(ND1) DIMENSION DET(2) REAL ML,LM C C SUBROUTINE TEST SELECTS A SET OF KEY SPECIES FROM THOSE OF C GREATEST AMOUNT AND REARRANGES THE SPECIES LIST WITH KEY C SPECIES FIRST IF A SET OF KEY SPECIES CANNOT BE FOUND C CONTROL IS RETURNED. C VARIABLE LIST C C JP(J,I) IS A MATRIX INDICATING THE STATUS OF EACH SPECIES J C AS A PORSTRYF CHOICE AS A KEY SPECIES FOR ELEMENT I C JP(J,I) 0 INDICATES AMT(J) -0 AND SPECIES IS NOT ELIGIBLE C 1 INDICATES THE SPECIES IS AN ELELIBLE KEY C 2 IF THE SPECIES ALREADY SELECTED AS A KEY FOR C SOME OTHER ELEMENT C 3 IF THE SPECIES MAKES A SINGULAR MATRIX WITH C PREVIOUSLY SELECTED KEYS C 4 IF THE SPECIES HAS BEEN TEMPORARILY ELIMINATED C TO SEE IF AN ALTERNATE EXISTS THAT WILL ALLOW C SELECTION OF A COMPLETE SET OF KEY SPECIES C KEY(I) IS USED TO STORE SPECIES NUMBERS DURING THE SELECTION C PROCESS C NCT1LIM IS LIMIT ON FIRST KEY SPECIES SEARCH PROCEDURE C NCT2LIM rs LIMIT ON SECOND KEY SPECIES SEARCH PROCEDURE C TEST RETURNS WITH INDX3 -4 IF NCT1.GT.NCTLLIM OR NCT2.GT.NCT2LIM C C SET NCTILIM AND NCT2LIM NCT1LIM - 500 NCT2LIM - 150 C DETERMINE JP MATRIX DO 11 I-1,NELMT DO 10 J-1,NSPCS IF(A(J,I)*AMT(J))7,7,9 147

7 JP(J,I)-0 GO TO 10 9 JP(J,I)-1 10 CONTINUE 11 CONTINUE C CHECK IF ALL SPECIES HAVE ZEROAMT FOR ANY ELEMENT C SET INDX3 4 IF TRUE IZERO - 0 DO 220 I .-1,NELMT ISUM 0 DO 210 J-1,NSPCS 210 ISUM - ISUM + JP(J,I) IF(ISUM.EQ.0) GO TO 224 220 CONTINUE GO TO 240 224 IZERO = I WRITE(6,226) IZERO 226 FORMAT(' ALL SPECIES FORELEMENT ',I3, 1' HAVE ZERO AMOUNTS TEST') GO TO 24 240 CONTINUE C FIND SPECIES WITH LARGESTAMOUNT FOR ELEMENT I AS C CHOICE OF KEY SPECIES 1=0 13 I-I+1 14 V=0. KEY(I)0 DO 21 J-.1,NSPCS IF(JY(J,I)-1)21,18,21 18 IF(A(J,I)*AMT(J)-V)21,21,19 19 V-A(J,I)*AMT(J) KEY(1)..7 21 CONTINUE IF(KEY(I))23,23,44 C IF I .LT. 2 NO KEY CAN BE FOUNDFOR FIRST ELEMENT- THIS C MEANS NO COMPLETE SET OF KEYSPECIES CAN BE FOUND RETURN C WITH INDX3 - 4 C IF I .GT. 2 THE THE JP COLUMNIS RETURNED TO ITS STATUS C BEFORE ATTEMPTING TO SELECT THEPARTICULAR KEY IN QUESTION, C THE KEY FOR THE PREVIOUSLYSELECTED ELEMENT IS IDENTIFIED C AS TEMPORARILY UNACCEPTABLE(JP -4) AND CONTROL IS RETURNED TO STM 14 FOR SELECTIONOF A NEW PREVIOUS KEY. 23 IF(I-1)24,24,26 24 INDX3 -4 GO TO 87 26 DO 34 J-1,NSPCS IF(JP(J,I)-3)34,28,34 28 140 DO 30 I1-1,L IF(JP(J,I1)-3)30,29,30 29 M.41+1 30 CONTINUE 148

IF(M)34,31,34 31 DO 33 I1-1,NELMT IF(JP(J,11)-3)33, 32,33 32 JP(J,I1)-1 33 CONTINUE 34 CONTINUE DO 36 J-1,NSPCS IF(JP(J,1)-4)36,35,36 35 JP(J,I)-1 36 CONTINUE I-I-1 K-KEY(I) JP(K,I)-4 L-I+1 DO 38 I1--L,NELMT IF(JP(K,11)-2)38,37,38 37 JP(K,I1)-1 38 CONTINUE NCT1 NCT1+1 IF(NCT1.LE.NCT1LIM) GO TO 14 WRITE(6,250) NCTILIM 250 FORMAT(//' NCT1 INTEST .GT. ' ,I4, ' - RETURN WITH INDX3 GO TO 24 = 4') 44 IF(I-1)59,59,45 C STM 45 TO 63 CHECK IF THEMATRIX OF A(J,I) OF THE KEYS C SELECTED IS SINGULAR. IF NOTTHE LATEST SELECTION IS ADDED C TO THE LIST OF KEYS AND JP IS SET. IF SINGULARJP IS SET C AND CONTROL IS RETURNED FOR SELECTION OF A NEWKEY. 45 DO 49 J-1,I K-KEY(J) DO 48 48 C(J,I1)=A(K,I1) 49 CONTINUE CALL ARRAY(2,I,I,ND,ND,C,C) CALL MATINV(C,I,I,ML,LM) D LM(1) IF(ABS(D)-.0001)53,53,59 53K=KEY(I) DO 57 I1- I,NELMT IF(JP(K, 11) -1)57, 56, 57 56 JP(K,I1) =3 57 CONTINUE NCT2 NCT2+1 IF(NCT2.LE.NCT2LIM) GO TO 14 WRITE(6,255) NCT2LIM 255 FORMAT(//' NCT2 IN TEST .GT. ',I4,' - RETURN WITH INDX3 GO TO 24 = 4') 59K-KEY(I) DO 63 I1-I,NELMT 1F(JP(K,I1)-1)63,62,63 62 JP(K,I1)-2 63 CONTINUE IF(I-NELMT)13,65,65 149

C REARRANGE SPECIES LIST 65 DO 66 Il,NELMT K= KEY(I) ANAMES=ANAME(I) BNAMES-BNAME(I) CNAMES-CNAME(I) AMTS-AMT(I) XS-X(I) POTOS-POTO(I) IPHASS- IPHASE(I) ANAME(I)-ANAME(K) BNAME(I)-BNAME(K) CNAME(I)=CNAME(K) AMT(I)-AMT(K) X(I) -X(K) POTO(I) - POTO(K) IPHASE(I)-IPHASE(K) ANAME(K)-ANAMES BNAME(K)BNAMES CNAME(K)-CNAMES AMT(K) =AMTS X(K)=XS POTO(K)=POTOS IPHASE(K)-IPHASS ANAMEX=Z(I) BNAMEXAZERO(I) CNAMEX -G(I) Z(I)-Z(K) AZER0(1)=AZERO(K) G(I)-G(K) Z(K)-ANAMEX AZERO(K)=BNAMEX G(K)...CNAMEX NLKS=NLK(I) NLK(I)=NLK(K) NLK(K)-NLKS ELECS = ELEC(I) ELEC(I) ELEC(K) ELEC(K) ELECS DO 651 I1-1,NELMT AS -A(I,I1) A(I,I1)- A(K,I1) 651 A(K,I1) -AS L=I+1 IF(L-NELMT)69,69,66 69 DO 70 I1-L,NELMT IF(KEY(I1)-I)70,71,70 71 KEY(I1)-K 70 CONTINUE 66 CONTINUE 87 RETURN END C 150

C C....SUBROUTINE MINI C C SUBROUTINE MINI(NSPCS, NELMT, TOL,NCOUNT) PARAMETER(ND -40) INTEGER ANAME,BNAME,CNAME,WTST COMMON ANAME(ND), BNAME(ND),-CNAME(ND), IPHASE(ND), POTO(ND), 1AMT(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND), P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MAKK, C(ND,ND), B(ND),IPR 3,AZERO(ND),Z(ND),IGAS,ELEC(ND) COMMON/ADDN/IG,WTST,AH20,GG(ND),XI,NLK(ND),H20(ND),J1, 1 TOLS,FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON/ITN/ITER,ASAVE(ND) COMMON/REDOX/IREDOX,AELEC,ESET,TRDX,TCON COMMON/CHPOT/DGDK,DK,G DIMENSION TX(ND),TAMT(ND),TPOT(ND),DG(ND),DN(ND),POT(ND) C C SUBROUTINE MINI ADJUSTS THE COMPOSITION TO MINIMIZE THE GIBBS C FREE ENERGY - THE RESULTING COMPOSITION IS USED AS AN INITIAL C ESTIMATE FOR THE NEWTON-RAPHSON CALCULATION. C C VARIABLE LIST C C DN(J) IS THE CHANGE IN AMT(J) OF SPECIES J FOR A UNIT CHANGE IN THE SEARCH PARAMETER. C FTOLM1 IS A FACTOR TO MULTIPLY TOL BY IF ITER .GT. 50. C FTQLM2 IS A FACTOR TO DIVIDE TOL BY AFTER A SUCCESSFUL ITER. C FTOLM3 IS A FACTOR TO MULTIPLY TOLM3 BY IF ITER .GT. 50. C G IS THE VALUE OF THE GIBBS FREE ENERGY DIVIDED BY RT - SAME AS C GPOT IN SENECA2. C GG(J) IS THE ACTIVITY COEFFICIENT OF SPECIES J SAME AS G(J) C IN SENECA2. C INDX1 IS A CONTROL VARIABLE -INDX1 - 0 MEANS NO PREVIOUS C SELECTION OF DK MADE INDX1 - 1 MEANS A TRIAL VALUE OF DK C IS STORED. C INDX2 IS A CONTROL VARIABLE IT INDICATES WHETHER A TRIAL VALUE C OF DK IS BEING USED OR WHETHER DK HAS BEEN CHOSEN TO MOVE AS FAR C AS POSSIBLE TOWARD THE MINIMUM IN G.

C INDX3 - SEE SENECA2 VARIABLE LIST. C ITER IS THE NUMBER OF COMPLETE ITERATIONS IN MINI. C NCOUNT IS THE NUMBER OF TIMES THE SPECIAL MINIMIZATION PROCEDURE C AT STM 100+ WAS PERFORMED ON THIS CALL TO MINI. C NGT50 IS THE NUMBER OF TIMES 50 ITERATIONS WAS REACHED ON THIS C CALL TO MINI IF NGT50 .GT. 50 PROGRAM STOP C POT(J) IS THE CHEMICAL POTENTIAL OF SPECIES J IN ITS PARTICULAR C PHASE. C TAMT(J) IS AN INTERMEDIATE ESTIMATE OF AMT(J) DURING THE CALC. C TOL IS THE INPUT TOLERENCE -SEE TOL1 IN SENECA2. C TOLM1 IS THE TOLERENCE ON DGDK - SEE STM 27+1 C TOLM2 IS THE TOLERENCE ON THE CHANGE IN AMT(J) - IF ALL SPECIES C HAVE CHANGE LESS THAN TOLM2 GO TO SPECIAL MINIMIZATION PROCEDURE C - USED IN STM 541. 151

C TOLM3 IS THE TOLERENCE ON (DGDK*DK/G) IF LESS THAN TOLM3 GO TO C SPECIAL MINIMIZATION PROCEDURE USED AFTER STM 53. C TOLM4 IS THE LOWER LIMIT ON TOL - WHEN TOL .LT. TOLM4 MINI HAS C CONVERGED SEE STM 28. C TPOT(J) IS AN INTERMEDIATE VALUE OF POT(J) DURING CALC. C TX(J) IS AN INTERMEDIATE VALUE OF X(J) DURING CALC. C

666 FORMATU5X,'SPECIES',5X,'AMOUNT',7X,'X(J). , 7X, 'POT(J)')

5 FORMAT(1H , 3A4, 1P3E13.4) 5656 FORMAT(' DGDK - ',1PE13.6,7X,'DK - ',1PE13.6,7X, 1 'G - ',1PE13.6) 6 FORMAT(1H1,'INDX3 - ',I2,7X,'ITER - ',I3,7X,'JT - ',I3) ISOL - 2-IGAS NGT50 - 0 C C TOLERENCES FOR MINI C TOLM1 - 5.0E-01 TOLM2 - 0.0001 TOLM3 = 2.0E-6 TOLM4 - 1.0E-20 FTOLM1 - 1.5 FTOLM2 - 10.0 FTOLM3 - 10.0 C C INITIALIZE SOME VARIABLES ITER-0 DO 1 J-1,NSPCS IF(ANAME(J).EQ.WTST) J1-J 1 CONTINUE 16 INDX1 -0 INDX2-0 JT-0 G-0. C CALL ACTIVITY COEFFICIENT ROUTINE AND ELECTRON ACTIVITY C ROUTINE. IF(IG.NE.0) CALL GAMMA(NSPCS,TEMP) IF(IREDOX.GT.0) CALL ELNACT(NSPCS) C CALCULATE CHEM POTENTIAL OF SPECIES J INCLUDING ACTIVITY C COEFFICIENTS AND ELECTRON ACTIVITY. DO 2 J-1,NSPCS I-IPHASE(J) POT(J)-POTO(J)+ALOG(X(J))+ALOG(GG(J))-(ELEC(J)*AELEC) IF(I.EQ.ISOL) POT(J)-POT(J)+ALOG(PHAS(I)) 2 CONTINUE POT(J1)- POTO(J1) +ALOG(AH2O) C CALC GIBBS FREE ENERGY AND DG FOR EACH REACTION. DO 17 J-1,NSPCS 17 G-G+POT(J)*AMT(J) 18 DO 20 IR-1,NREACT DG(IR)-0. DO 19 J-1,NSPCS 19 DG(IR)-DG(IR)+ST(J,IR)*POT(J) 152

20 CONTINUE IF(INDX3.EQ.3.AND.IG.NE.0) CALL GAMMA(NSPCS,TEMP) C CALC CHANGE IN AMT(J) FOR EACH SPECIES (DN(J)). DO 22 J-1,NSPCS DN(J) -O. DO 21 IR-1,NREACT 21 DN(J)-DN(J)-ST(J,IR)*DG(IR) 22 CONTINUE C CALC DGDK - THE CHANGE IN G WITH UNIT CHANGE IN THE SEARCH C PARAMETER - ALWAYS NEGATIVE. DGDK-0. DO 27 IR-1,NREACT DO 26 J-1,NSPCS IF(ST(J,IR))23,26,23 23 IF(AMT(J))24,24,26 24 IF(DN(J))25,25,26 25 DG(IR)-0. GO TO 27 26 CONTINUE DGDK-DGDK-DG(IR)*DG(IR) 27 CONTINUE C CHECK DGDK AGAINST TOLM1 FOR CONVERGENCE ON THIS ITERATION. IF(DGDK+TOLM1)31,28,28 C CHECK TOL AGAINST TOLM4 FOR FINAL CONVERGENCE - REDUCE TOL C IF .GT. TOLM4. 28 IF(TOL-TOLM4)30,30,29 29 TOLTOL/FTOLM2 C CONVERGENCE REACHED AT ONE TOLERENCE - ALL SPECIES ARE READMITTED C TO THE CALCULATION AT THE NEW TOLERENCE LEVEL. FOR THE NEXT C ITERATION CONTROL RETURNED TO STM 16 AT STM 299+1. DO 292 J-1,NSPCS IF(AMT(J))292,291,292 291 AMT(J) - TOL 292 CONTINUE DO 295 JPHA-1,NPHAS PHAS(JPHA)-0. DO 294 J-1,NSPCS IF(IPHASE(J)-JPHA)294,293,294 293 PHAS(JPHA)- PHAS(JPHA) +AMT(J) 294 CONTINUE 295 CONTINUE DO 299 J-1,NSPCS I-IPHASE(J) IF(PHAS(I)-TOL)296,296,297 296 X(J)-1. AMT(J)-0. GO TO 299 297 X(J)-AMT(J)/PHAS(I) IF(X(J)-TOL)298,299,299 298 AMT(J)-0. X(J)-TOL 299 CONTINUE GO TO 16 153

C FINAL CONVERGENCE REACHED- SET INDX3 -0 AND RETURN. 30 INDX3 -0 GO TO 200 C COMPUTE A NEW SET OF DN(J). 31 DO 33 J-1,NSPCS DN(J) -O. DO 32 IR-1,NREACT 32 DN(J)-DN(J)-ST(J,IR)*DG(IR) 33 CONTINUE C IF AN ESTIMATE OF DK HAS NOT PREVIOUSLY BEEN MADE, AN ESTIMATE IS MADE SUCH THAT THE LARGEST DECREASE IN AN AMT(J) C IS 50%- TO STM 372. IF(INDX1)38,34,38 34 ALPHA -DN(1)/AMT(1) DO 37 J=2,NSPCS IF(AMT(J))35,37,35 35 IF(ALPHA-DN(J)/AMT(J))37,37,36 36 ALPHA -DN(J)/AMT(J) 37 CONTINUE IF(ALPHA)372,371,372 371 DK=10.*DK GO TO 38 372 DK--.5/ALPHA C TRIAL VALUES OF NEW AMOUNTS ARE COMPUTED IF ANY NEW TRIAL C VALUE IS NEGATIVE, DK IS CUT IN HALF- THE AMOUNT OF EACH C PHASE PRESENT IS ALSO COMPUTED- TO STM 45. 38 DO 42 J-1,NSPCS IF(ABS(DN(J)-1.E-20))39,39,40 39 TAMT(J)-AMT(J) GO TO 42 40 TAMT(J)-AMT(J)+DN(J)*DK IF(TAMT(J))41,42,42 41 DK-DK/2. GO TO 38 42 CONTINUE DO 45 JPHA-1,NPHAS PHAS(JPHA) -O. DO 44 J-1,NSPCS IF(IPHASE(J)-JPHA)44,43,44 43 PHAS(JPHA)-PHAS(JPHA)+TAMT(J) 44 CONTINUE 45 CONTINUE C REJECT PHASES PRESENT IN AMOUNTS LESS THAN TOL OR SPECIES C PRESENT WITH MOLE FRACTIONS LESS THAN TOL USE GP TO SAVE NEW G. TG-0. GP -G IF(IREDOX.GT.0) CALL ELNACT(NSPCS) DO 52 J-1,NSPCS I -IPHASE(J) IF(PHAS(I)-TOL)46,46,47 46 TX(J) -1. X(J) -1. TAMT(J) -O. 154

GP-GP-POT(J)*AMT(J) GO TO 51 47 TX(J)-TAMT(J)/PHAS(I) IF(TX(J)-TOL)48,48,51 48 TAMT(J)-0. TX(J)-TOL GP-GP-POT(J)*AMT(J) 51 TPOT(J)-POTO(J)+ALOG(TX(J))

1 +ALOG(GG(J)) - (ELEC(J)*AELEC) IF(I.EQ.ISOL) TPOT(J)-TPOT(J)+ALOG(PHAS(I)) IF(ANAME(J).EQ.WTST) TPOT(J)-POTO(J)+ALOG(AH20) 52 TO-TG+TPOT(J)*TAMT(J) C TG IS VALUE OF GIBBS FREE ENERGY BASED ON ADJUSTED COMPOSITION C TEST FOR AN ACTUAL CHANGE IN COMPOSITION AND A DECREASE C IN GIBBS FUNCTION -IF GIBBS FUNCTION INCREASED REDUCE DK BY C HALF. 54 K-OP DO 56 J-1,NSPCS IF(AMT(J)+TAMT(J))56,55,541 541 IF(ABS(2.*(TAMT(J)-AMT(J))/(TAMT(J)+AMT(J)))-TOTM2)55,55,56 55 K-K+1 56 CONTINUE IF(K-NSPCS)570,100,100 570 IF(ITER.EQ.49 .AND. ABS(DGDK*DK/C).LT.TOLM.3) GO TO 100 57 IF(TG-GP)59,59,53 53 DK-DK/2. C CHECK THAT RELATIVE CHANGE IN G IS LARGER THAN TOLMI- IF NOT

C GO TO SPEGTAI MINIMIZATION SECTION - STM 100. IT(ABS(DGDK*DK/G)-TOLM3)100,100,38 C TRY TO CHOOSE DK TO REACH DGDK-0- IF G VS K CURVE IS ESSENTIALLY C LINEAR DK IS INCREASED MY 50 %- CONTROL RETURNS TO STM 38 AND TITRATION IS COMPLETED. 59 IF(INDX2)60,60.70 60 INDX2-4 DELTADK*DGDK D-TG-GP-DELTA IF(D-.0005)61,61,62 61 DK-1.5*DK GO TO 38 62 DK--DELTA*DK/2./D GO TO 38 C UPDATE AMT(J), POT(J) AND X(J) WITH TEMPORARY VALUES. 70 iNDX2-0 DO 72 J-1,NSPCS AMT(J)-TAMT(J) POT(J)-TPOT(J) 72 X(J)-TX(J) INDX1-1 G-TG INDX3-3 C IF ANY KEY SPECIES HAS ZERO AMOUNT RETURN WITH INDX3 - 1. 73 DO 81 J-1,NELMT IF(AMT(J))80,80,81 155

80 JT-J INDX3-1 GO TO 200 81 CONTINUE 82 ITER-ITER+1 C IF ITER .LT. 50 CONTINUE TO NEXT ITER. IF(ITER.LT.50) GO TO 705 NGT50 - NGT50+1 C IF 50 ITERATIONS REACHED 50 TIMES PRINT MESSAGE AND STOP. IF(NGT50.LT.50) GO TO 704 WRITE(6,702) 702 FORMAT(//' MINI HAS EXCEEDED 50 ITERATIONS 50 CONSECUTIVE'

1, ' TIMES PROGRAM STOP') STOP C ITER - 50- ADJUST TOL AND TOLM3 FOR NEXT 50 ITERATIONS - PRINT C SOME DATA. 704 CONTINUE IF(TOL.GE.TOLS) TOLS FTOLM1*TOLS TOL=FTOLK1*TOL IF(TOLM3.GT.1.0E-3) GO TO 740 TOLM3 FTOLM3*TOLM3 IF(IPR.GT.0) WRITE(6,739) TOLM3 739 FORMAT(' TOLM3 RESET IN MINI TOLM3 ',1PE13.6) 740 CONTINUE IF(IPR.GT.0) WRITE(6,5656) DGDK,DK,G IF(IPR.GT.0) WRITE(6,706) TOL,NCOUNT 706 FORMAT(' ITER GT 50 - NEW TOL IN MINI - 1,1EE13.5, 1 7X,'NCOUNT ',I6) ITER-0 705 IF(MOD(ITER,25),EQ.0) GO TO 203 200 LF(IPR.LT.2) GO TO 203 WRITE(6,6)INDX3,ITER,JT WRITE (6,666) DO 316 J-1,NSPCS 316 WRITE(6,5) ANAME(J), BNAME(J), CNAME(J).AMT(J), X(J), POT(J) WRITE(6,5657) (DG(IR),IR-1 NREACT) 5657 FORMAT(1P5E15.6) WRITE(6,5656) DGDK, DK, G C CALC AND PRINT MATERIAL BALANCE ERRORS WRITE(6,2502) 2502 FORMAT(/' MATERIAL BALANCE ERRORS') DO 2530 I-1,NELMT B(I) E(I) DO 2520 J- 1,NSPCS 2520 B(I) B(I)-(AMT(J)*A(J,I)) FRAC - B(I)/E(I) WRITE(6,2522) I,B(I),FRAC 2522 FORMAT(' I - ',I3,4X,'ERROR ',1PE13.6,4X, 1 'FRAC ERROR - ',1PE13.6) 2530 CONTINUE C GO ON TO NEXT ITERATION OR END DEPENDING ON INDX3. 203 IF(INDX3-2)90,16,18 C SECTION TO SHIFT TO NEW G VS K CURVE - THRU STM 140+1 156

100 BETAABS(DG(1)) C COUNT NUMBER OF TIMES THIS SECTION CALLED. NCOUNT NCOUNT+1 K-1 DO 102 IR- 2,NREACT IF(ABS(DG(IR))-BETA)102,102,101 101 KIR BETAABS(DG(K)) 102 CONTINUE IF(BETA)103,120,103 C DETERMINE IF THE REACTION TO BE ADJUSTED INVOLVES THE ELIMINATION C OF A PHASE ONLY - INDICATED BY PSI 0. C IF ONLY PHASE ELIMINATION IS INVOLVED, COMPOSITION IS ADJUSTED C IN STM 106 -1121, FINDING SPECIES SMALLEST IN AMOUNT. 103 PSI -0. DO 105 J-1,Nspcs JpHAIPHAsE(J) IF(X(J)-1.)104,105,105 104 PSI psi+sT(J,K)*ST(J,K)/PHAs(JpHA)/x(J) 105 CONTINUE IF(psi)113,106,113 106 BETADC(K)/BETA DO 108 J-1,NSPcS IF(BETA*sT(J,K))108,108,107 107 DPSIBETA*AMT(J)/ST(J,K) L=J+1 GO TO 109 108 CONTINUE 109 DO 112 JL,NSPCS IF(BETA*ST(J,K))112,112,110 110 IF CBETA*AmT(J)/ST(J,K)-DPSI)111,112,112 111 DPSIBETA*AMT(J)/ST(J,K) 112 CONTINUE DPSI BETA*DPSI DO 1121 J-1,NSPCS 1121 AMT(J) AMT(J) +ST(J,K) *DPSI GO TO 120 C THE FOLLOWING STATEMENTS ADJUST THE SELECTED REACTION FRACTIONALLY. C THE SUGGESTED SHIFTS IN COMPOSITION ARE CHECKED TO INSURE THAT C NONE WILL RESULT IN A NEGATIVE AMOUNT ADJUST THE EXTENT OF THE C REACTION SHIFT ACCORDINGLY. 113 Dpsi--DG(K)/PSI 114 DO 117 J-1,NSPCS IF(ST(J,K))115,117,115 115 DAMTAMT(J)+ST(J,K)*DPSI IF(DAMT)116,117,117 116 DPSI--AMT(J)/ST(J,K) 117 CONTINUE 118 DO 119 J- 1,NSPCS JPHA IPHASE(J) IF(sT(J,K))1181,119,1181 1181 AMT(J)X(J)*PHAS(JPHA)+ST(J,K)*DpsI 119 CONTINUE 157

C COMPUTE NEW MOLE FRACTIONS AND PHASE AMOUNTS- RETURN C CONTROL TO DIRECT MINIMIZATION ROUTINE. 120 DO 123 JPHA- 1,NPHAS PHAS(JPHA)-0. DO 122 J-1,NSPCS IF(IPHASE(J)-JPHA)122,121,122 121 PHAS(JPHA)-PHAS(JPHA)+AMT(J) 122 CONTINUE 123 CONTINUE DO 138 J-1,NSPCS I-IPHASE(J) 131 IF(PHAS(I)-TOL)132,132,133 132 X(J)-1. AMT(J)-O. CO TO 138 133 X(J)-AMT(J)/PHAS(I) IF(X(J)-TOL)134,134,138 134 AMT(J)-0. X(J)-TOL 138 CONTINUE 140 INDX3-2 GO TO 73 C PRINT SOME OUTPUT AND RETURN. 90 IF(INDX3 NE 0) GO TO 91 IF(IPR.EQ.0) GO TO 91 WRITE(6,735) 735 FORMAT(' MINI CONVERGED'/

1 ' NAME, AMT, X, POTO, AND POT LISTED BELOW') WRITE(6,730)(ANAME(J),BNAME(J),CNAME(J),AMT(J),X(J),POTO(J) 1,POT(J) ,1/41-1,NSPCS) 730 FORMAT(3A4,1P4EI3.4) WRITE(6,736) 736 FORMAT(' DG FOR EACH REACTION LISTEDBELOW') WRITE(6,731)(DG(J),J-1,NREACT) 731 FORMAT(1P5E15.6) 91 RETURN END C C.... SUBROUTINE GAMSET C C SUBROUTINE GAMSET(NSPCS,TEMP.IDUM) PARAMETER (ND-40, NION =15) C COMMON /ADDN/ IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, & FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, & AMOL(NION) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM COMMON /ADSWTCH/ ICANBR(ND) C REAL TEMP,G,AH20,XI,H20,CMOL,AMOL,CATACT(NION),ANACT(NION), & XACT(NION),ACTH20,ZIONST,ZC 158

INTEGER NSPCS,IDUM(ND),NLK,LIC,NUMC,LIA,NUMA,NUMC1,NUMA1, & NCM,NAM,ICANBR C C....THIS SUBROUTINE SETS THE DATABASE UP FOR THE C ACTIVITY COEFFICIENT CALCULATIONS. CONDATA WILL CONVERT THE C OVERALL SPECIES NUMBER, IDUM, TO INFORMATION AS TO TYPE OF C SPECIES AND LOCATION OF ION INTERACTION DATA. PITDATA WILL GO C TO THE MAIN DATABASE AND GET THE ION INTERACTION COEFFICIENTS C FOR THE CHARGED SPECIES, AND PLACE THEM IN THE COMMON BLOCKS FOR C THE CALCULATION OF THE ACTIVITY COEFFICIENTS. DATAWT SIMPLY SENDS C INFORMATION GATHERED TO TWO FILES, THE FIRST GIVING WHAT VALUES C WERE USED IN THE CALCULATION OF THE ACTIVITY COEFFICIENTS, THE C OTHER GIVING WHICH ION INTERACTION PARAMETERS WERE MISSING AND C ASSUMED TO BE ZERO. C CALL CONDATA (NSPCS,IDUM,NLK,ICANBR) CALL PITDATA (TEMP) CALL DATAWT C C....THE NUMBER OF CATIONS, AND ANIONS SPECIES IN SOLUTION C ARE PLACED IN THE SYSTEM COMMON BLOCKS C NUMC NCM NUMA - NAM AH2O - 1.0 RETURN END C C.... SUBROUTINE GAMMA C C....THIS SUBROUTINE CALCULATES THE ACTIVITY COEFFICIENT OF THE C AQUEOUS SPECIES IN THE PROBLEM. THE ACTIVITIES ARE CALCULATED C PITZER'S METHOD. C SUBROUTINE GAMMA(NSPCS,TEMP) PARAMETER (ND-40, NION -15) C COMMON /ADDN/ IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, & FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, & AMOL(NION) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM COMMON /ADSWTCH/ ICANBR(ND) C REAL TEMP,G,AH20,XI,H20,CMOL,AMOL,CATACT(NION),ANACT(NION), & ACTH20,ZIONST,ZC INTEGER NSPCS,IDUM(ND),NLK,LIC,NUMC,LIA,NUMA,NUMC1,NUMA1, & NCM,NAM,ICANBR

C C....INITIALIZE ACTIVITY COEFFICIENT TERMS DO 20 IPITG-1, NION CATACT(IPITG) 1. 159

ANACT(IPITG) = I. 20 CONTINUE DO 40 IPITG-1, ND G(IPITG) = 1. 40 CONTINUE ACTH2O = I. C C....THE FIRST CALL TO SWITCH PLACES THE VALUES OF THE AMOUNTS, AMT, C AND THE OTHER SYSTEM VARIABLES IN THE PROPER COMMON BLOCKS FOR C THE ACTIVITY COEFFICEINT CALCULATIONS. THE ACTIVITY COEFFICIENTS C ARE THEN CALCULATED, AND THEN SWITCH IS CALLED AGAIN TO PUT C THE PROPER COEFFICIENT WITH THE CORRECT G(IPITG) VALUE. C CALL SWITCH (NSPCS,ICANBR,CATACT,ANACT,ACTH20) CALL ACTIVY (ZIONST,ZC,CATACT,ANACT) XI = ZIONST ACTH2O = WATRACT (ZIONST,ZC) CALL SWITCH (NSPCS,ICANBR,CATACT,ANACT,ACTH20) RETURN END C C....SUBROUTINE SWITCH C C....THIS SUBROUTINE SEPARATES THE CATIONS, ANIONS, C AND DIFFERENT PHASE SPECIES AND PLACES THE INFORMATION ABOUT C IN THE PROPER VARIABLE NAMES FOR THE CALCULATIONS, ALSO IT C PLACES THE CORRECT ACTIVITY COEFFICIENT WITH THE PROPER G(I) C VALUE. C SUBROUTINE SWITCH (NSPCS,ICANBR,CATACT,ANACT,ACTH20) PARAMETER (ND-40, NION-15) C COMMON ANAME(ND),BNAME(ND),CNAME(ND),IPHASE(ND),POTO(ND), lAMT(ND),A(ND,ND),X(ND),E(ND),ST(ND,ND),P,NPHAS,NREACT, 2INDX3,PHAS(ND),JT,KKMA,MAKK,C(ND,ND),B(ND),IPR,AZERO(ND),Z(ND), 3IGAS,ELEC(ND) COMMON /ADDN/ IG, WTST, AH2O, G( ND),XI,NLK(ND),H2O(ND),JW,TOLS, & FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, & AMOL(NION) REAL CATACT(NION),ANACT(NION),ACTH20,AMT,AH20,G,X1, & H20,XMOL,CMOL,AMOL INTEGER NSPCS,ICANBR(ND),NLK,LIC,NUMC,LIA,NUMA C C....COUNTERS INTIIALIZED JVN = 0 J2 = 0 C C.. ICANBR IS SET UP IN CONDATA TO HAVE THE THOUSANDS PLACE INDICATE C WHETHER THE SPECIES IS AN CATION, ANION, NEUTRAL SPECIES, OR C DIFFERENT PHASE. THE REST OF THE NUMBER IS FOR WHICH ANION, OR C CATION IT IS WHETHER NUMBER 1 OR NUMBER 2, AND SO ON. C THE NUMBERING WAS SET UP LIKE THIS: 160

C 1XXX IS A CATION, RELATIVE NUMBER XXX C 2XXX IS A ANION, RELATIVE NUMBERXXX C 4000 IS WATER C 9 IS A SPECIES NOT IN SOLUTION,AND NOT OF CONCERN TO ACTIVITY C CALCULATIONS. C DO 20 ISWITCH-1, NSPCS ISPC - ICANBR(NLK(ISWITCH)) IF(ISPC.EQ.9) THEN G(ISWITCH) - 1. ENDIF IF(ISPC.GE.1000.AND.ISPC.LT.2000) THEN JVN JVN + 1 LIC(JVN) ISPC -1000 CMOL(LIC(JVN)) - AMT(ISWITCH) G(ISWITCH) CATACT(LIC(JVN)) ENDIF IF(ISPC.GE.2000.AND.ISPC.LT.3000) THEN J2 - J2 + 1 LIA(J2) = ISPC 2000 AMOL(LIA(J2)) AMT(ISWITCH) G(ISWITCH) ANACT(LIA(J2)) ENDIF IF(ISPC.EQ.4000) THEN G(ISWITCH) ACTH2O AH20 = ACTH2O ENDIF 20 CONTINUE RETURN END C C....FUNCTION SOLVE C C FUNCTION SOLVE(Q,X,N) C THIS FUNCTION COMPUTES A POLYNOMIALGIVEN THE COEFFICIENTS C AND THE INDEPENDENT VARIABLE. DIMENSION Q(7) SOLVE = O. DO 10 I-1,N 10 SOLVE-SOLVE+Q(I)*X**(I-1) RETURN END C C C....SUBROUTINE NEWSON C C SUBROUTINE NEWSON(NSPCS, NELMT, TOL, KKMM) PARAMETER(ND-40) INTEGER ANAME,BNAME,CNAME,WTST COMMON ANAME(ND), BNAME(ND), CNAME(ND),IPHASE(ND), POTO(ND), lAMI(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND),P, NPHAS, NREACT, 161

2INDX3, PHAS(ND), JT, KKMA, MAKK, C(ND,ND), B(ND),IPR 3,AZERO(ND),ZZ(ND),IGAS,ELEC(ND) COMMON/ADDN/IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, & FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON/REDOX/IREDOX,AELEC,ESET,TRDX,TCON C THIS SUBROUTINE SOLVES THE EQUILIBRIUM EQUATIONS USING THE C NEWTON-RAPHSON METHOD - OUTPUT COMPOSITION FROM MINI IS USED C AS THE INITIAL ESTIMATE. C C VARIABLE LIST C C ITER IS THE ITERATION COUNT IN NEWSON. C KKMM IS THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. C TOL IS THE CONVERGENCE TOLERENCE - USED BETWEEN STM 80 85. C TOLN1 IS THE SPECIES REJECTION TOLERENCE- REJECT SPECIES J IF C AMT(J) .LT. TOLN1. C INITIALIZE SOME VARIABLES TOLN1 = 1.0E-15 IG -1 ISOL = 2-IGAS IF(IPR.GT.0) WRITE(6,1) 1 FORMAT(/' START NEWSON'/' ITER CHARGE BALANCE') 3 FORMAT(' SET IS SINGULAR AT ITER = ',I4) ITER-0 C COMPUTE AMOUNTS OF PHASES DO 25 JTHA-1,NPHAS PHAS(JPHA) -O. DO 24 J-1,NSPCS IF(IPHASE{J)-SPHA)24,23,24 23 PHAS(JPHA)=PHAS(SPHA)+AMT(J) 24 CONTINUE 25 CONTINUE 107 ITER-IIEK+1 FF(ITER-KKMM)21,21,200 C COMPUTE CONSTANT VECTOR FOR MATERIAL BALANCE EQUATIONS 21 DO 50 I -1.NELMT B(I)-E(I) DO 51 J=1,NSPCS 51 B(I)=B(I)-AMT(J)*A(J,I) 50 CONTINUE COMPUTE CONSTANT VECTOR FOR PHASE EQUATIONS DO 52 JPHA-1,NPHAS K-NELMT+JPHA B(K) -1. DO 53 J-1,NSPCS IF(IPHASE(J)-JPHA)53,54,53 54 B(K)-B(K)-X(J) 53 CONTINUE 52 CONTINUE C COMPUTE CONSTANT VECTOR FOR EQUILIBRIUM EQUATIONS K-NELMT+NPHAS 162

CALL GAMMA(NSPCS,TEMP) IF(IREDOX.GT.0) CALL ELNACT(NSPCS) DO 55 IR=1,NREACT KK-K+IR B(KK) -O. DO 56 J-1,NSPCS I-IPHASE(J) IF(I.EQ.ISOL.AND.ANAME(J).NE.WTST) B(KK)-13(KK)-ST(J,IR)* 1 ALOG(PHAS(I)*G(J)) ADD-ALOG(X(J)) IF(ANAME(J).EQ.WIST) ADD-ALOG(AH20) 56 B(KK)-B(KK)-ST(J,IR)*(POTO(J)+ADD-(ELEC(J)*AELEC)) 55 CONTINUE C COMPUTE MATRIX FOR MATERIAL BALANCE EQUATIONS DO 60 I-1,NELMT DO 61 JPHA-1,NPHAS C(I,JPHA)=0. DO 62 J-1,NSPCS IF(IPHASE(J)-JPHA)62,63,62 63 C(I,JFHA)=C(I,JPHA)+A(J,I)*X(J) 62 CONTINUE 61 CONTINUE DO 64 J-1,NSPCS K = NPHAS+J 64 C(I,K)-A(J,I)*AMT(j) 60 CONTINUE C COMPUTE MATRIX FOR PHASE EQUATIONS K-NSPCS+NPHAS L-NELMT+1 DO 65 I-L,K DO 66 J-1,NPHAS 66 C(I,J) =0. 65 CONTINUE DO 67 I-1,NPHAS K-NELMT+I DO 68 J-1,NSPCS L-NPHAS+J IF(IPHASE(J)-I)69,70,69 69 C(K,L) -O. GO TO 68 70 C(K,L)=X(J) 68 CONTINUE 67 CONTINUE C COMPUTE MATRIX FOR EQUILIBRIUM EQUATIONS DO 71 IR-1,NREACT K-NELMT+NPHAS+IR DO 72 J=1,NSPCS L-NPHAS+J 72 C(K,L)-ST(J,IR) 71 CONTINUE BZ-0. DO 2 J-1,NSPCS 2 BZ =BZ +ZZ(J) *AMT(J) 163

IF(IPR.GT.0) WRITE(6,4) ITER,BZ 4 FORMAT(2X,I3,6X,1PE13.6) C SOLVE EQUATIONS B(K) ARE SOLUTION M-NSPCS+NPHAS IF(M.LE.ND) GO TO 78 WRITE(6,79) M,ND 79 FORMAT(//' NUMBER OF SPECIES + NUMBER OF PHASES - ',I3,

1 ' IS GREATER THAN ND - ',I3/ 2'REMOVE SOME SPECIES OR INCREASE PARAMETER ND-PROBLEM STOP') STOP 78 CONTINUE CALL ARRAY(2,M,M,ND,ND,C,C) CALL SIMOWT(C,B,M,KS,1.E-20) C IF KS .GT. ZERO - SYSTEM SINGULAR - RETURN WITH INDX3 - 4. IF(KS)80,80,81 81 WRITE(6,3)ITER INDX3-4 GO TO 210 80 K-0 C CHECK SOLUTION AGAINST TOL IF TOLERENCE NOT MET BY ALL C SPECIES AND PHASES SET K = 1. C NOTE THAT THE B(K) FOR THE SPECIES ARE ACTUALLY THE ALOGS OF C THE MOLE FRACTIONS- NOT THE SPECIES AMOUNTS. DO 82 I=1,NPHAS IF(B(I)/PHAS(I).GT.TOL)THEN K-1 ENDIF 82 CONTINUE DO 84 J-1,NSPCS L-NPHAS+J IF(B(L).GT.TOL)THEN K-1 ENDIF 84 CONTINUE IF(K.EQ.0)G0 TO 198 C UPDATE THE AMOUNTS OF PHASES AND THE AMOUNTS OF SPECIES C DO NOT ALLOW PHASE AMOUNT TO DECREASE BY MORE THAN HALF C DO NOT ALLOW SPECIES AMOUNTS TO DECREASE BY MORE THAN HALF C OR INCREASE BY MORE THAN A FACTOR OF 10.0. 87 DO 88 JPHA-1,NPHAS IF(BOPHAUPHAS(JPHA)+.5)89,90,90 89 PHAS(JPHA)=.5*PHAS(JPHA) GO TO 88 90 PHAS(JPHA) =PHAS(JPHA) +B(JPHA) 88 CONTINUE DO 91 J-1,NSPCS K- NPHAS +J C IF ANY B(K) TOO LARGE REDUCE TO 99.0 IF(B(K).LT.99.0) GO TO 192 B(K) - 99.0 192 CONTINUE Z- EXP(B(K)) IF(Z.LT.0.5) Z 0.5 164

IF(Z.GT.10.0) Z - 10.0 93 X(J) - X(J)*Z I-IPHASE(J) 91 AMT(J)-X(J)*PHAS(I) C IF ANY SPECIES AMOUNT IS LESS THAN TOLN1RETURN WITH INDX3 - 1 C IF IT IS A KEY SPECIES OR INDX3- 2 IF IT IS A NONKEY SPECIES. DO 94 J-1,NELMT IF(AMT(J)-TOLN1) 95,95,94 95 INDX3-1 IF(IPR.GT.0)WRITE(6,230) ANAME(J),BNAME(J),CNAME(J) GO TO 210 94 CONTINUE K-NELMT-1 DO 96 J-K,NSPCS IF(AMT(J)-TOLN1) 97,97,96 97 INDX3-2 IF(IPR.GT.0)WRITE(6,230) ANAME(J),BNAME(J),CNAME(J) 230 FORMAT(' SPECIES ',3A4,' WENT TO ZERO IN NEWSON') AMT(J)=0. GO TO 210 96 CONTINUE GO TO 107 198 INDX3-0 GO TO 210 200 INDX3=3 210 RETURN END C....SUBROUTINE SIMQWT C C SUBROUTINE SIMQWT(A,B,N,KS,TOL) PARAMETER(ND-40) DIMENSION A(1),B(1) KS-0 JJ--N DO 65 J-1,N JY-J+1 JJ-JJ+N+1 BIGA-0 IT-JJ-J DO 30 I-J,N IJ-IT+I IF(ASS(BICA)-ABS(A(IJ))) 20,30,30 20 BIGA-A(IJ) IMAX-I 30 CONTINUE IF(ABS(BIGA)-TOL) 35,35,40 35 KS-1 RETURN 40 I1-J+N*(J -2) IT-IMAX-J DO 50 K-J,N 165

Il-I1+N I2-I1+IT SAVE-A(I1) A(I1)-A(I2) A(I2) -SAVE 50 A(I1)-A(I1)/BIGA SAVE-B(IMAX) B(IMAX)-B(J) B(J)- SAVE /BIGA IF(J-N) 55,70,55 55 IQS-N*(J-1) DO 65 IX-JY,N IXJ-IQS+IX IT -J-IX DO 60 JX -JY,N IXJXN*(JX-1)+IX JJX-IXJX+IT 60 A(IXJX)-A(IXJX)-(A(IXJ)*A(JJX)) 65 B(IX)-B(IX)-(B(J)*A(IXJ)) 70 NY -N -1 ITsN*N DO 80 J -1,NY IA-IT-J IB-N-J IC -N DO 80 K=1,J B(1B)-B(IB)-A(lA)*B(IC) IA= IA-N 80 IC -IC -1 RETURN END C C.-SUBROUTINE ARRAY C C SUBROUTINE ARRAY(MODE,I,J,N,M,S,D) PARAMETER(ND-40) DIMENSION S(1),D(1)

IF(MODE-1)100,100,120 100 IJ-I*J+1 NM-N*J+1 DO 110 K-1,J NM-NM-NI DO 110 IJ-IJ-1 NM -NM -1 110 D(NM)-S(IJ) GO TO 140 120 IJ -O NM-0 DO 130 K-1,J DO 125 166

NM-NM+1 125 S(IJ)-D(NM) 130 NM-NM*NI 140 RETURN END C C....SUBROUTINE COMPSET C SUBROUTINE COMPSET(QV,NSPCS,NELMT,NSPC,XNS) PARAMETER(ND-40) INTEGER ANAME,BNAME,CNAME COMMON ANAME(ND), BNAME(ND),CNAME(ND), IPHASE(ND), POTO(ND), 1AMT(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND), P, NPHAS,NREACT, 2INDX3, PHAS(ND), JT, KKMA,MAKK, C(ND,ND), B(ND),IPR 3,AZERO(ND),Z(ND),ICAS,ELEC(ND) COMMON/SALT/SLNMOL C C THIS SUBROUTINE ADJUSTS THEAMOUNTS OF ELEMENTS (E(I)) AND SPECIES (AMT(J)) TO ACCOUNTFOR WATER THAT HAS VAPORIZEDFROM C THE SOLUTION INTO THE GASPHASE. IF QV IS .LT. 1.0E-5 AND XNS .GT. ZERO THE COMPOSITIONIS C ADJUSTED BASED ON XNS IF QV IS .GT. 1.0E-5 THECOMPOSITION IS ADJUSTED ON THE C BASIS OF QV C C VARIABLE LIST C C IPRT IS A PRINT CONTROL VARIABLE - IF ZERO NO PRINT. C TWAT AND SWAT ARE USED TOLOCATE WHICH SPECIES AND ELEMENT C IS WATER VAPOR. C QL IS THE MOLES OF LIQUIDWATER PER MOLE OF TOTAL WATER. QLSV IS THE VALUE OF QL FROMTHE LAST TIME COMPSET WAS CALLED C INITIALLY QLSV IS ONE. C QV IS THE MOLES OF WATERVAPOR PER MOLE OF TOTAL WATER. C QVSV IS THE VALUE OF QV FROMTHE LAST TIME COMPSET WAS CAI3.ED C INITIALLY QVSV IS ZERO. C XNS IS THE MOLES OF WATER INTHE GAS PHASE BASED ON SATURATION C OF THE GAS PHASE. C XNSS IS THE VALUE OF XNS FROMTHE LAST TIME COMPSET WAS CALLED C INITIALLY XNSS IS ZERO. C DATA QVSV,QLSV,XNSS/0.0,1.0,0.0/ IPRT - 1 C CHECK LIMITS ON QUALITY IF(QV.LE.0.75) GO TO 5 WRITE(6,3) QV 3 FORMAT(//' QUALITY- ',1PE15.6,8X, l'VALUE REDUCED TO 0.75 ANDCALCULATION CONTINUED'//) QV - 0.75 5 IF(QV.GE.0.0) GO TO 10 WRITE(6,7) QV 7 FORMAT(//' QUALITY- ',1PE15.6,8X, 167

1'VALUE INCREASED TO 0.0 AND CALCULATIONCONTINUED' //) QV - 0.0 10 QL - 1.0-QV 18 IF(W.GT.1.0E-5) CO TO 100 IF(XNS.LE.0.0) RETURN C ADJUST COMPOSITION BASED ON XNS- FAC IS THE FRACTIONAL CHANGE C IN E(I) AND AMT(I) FAC - (55.508-XNSS)/(55.508-XNS) DO 25 I-1,NELMT 25 E(I) - E(I)*FAC DO 30 J-1,NSPCS IF(IPHASE(J).NE.2) GO TO 30 AMT(J) AMT(J)*FAC 30 CONTINUE IF(IPRT.EQ.0) GO TO 60 WRITE(6,35) XNS,XNSS 35 FORMAT(/' COMPSET CALLEDWITH NEW MOLES OF WATER VAPOR- 11PE15.6/ 2' AND OLD MOLES OF WATER VAPOR= ',1PE15 6) WRITE(6,38) (E(I),I-1,NELMT) WRITE(6,40) (AMT(J),J-1,NSPCS) C SAVE VALUE OF XNS 60 XNSS XNS RETURN 100 IF(ABS(OV-OVSV).LT.1.0E-5)RETURN C ADJUST COMPOSITION BASED ON AN INPUTQUALITY (QV) IF(QVSV.GT.0.0) GO TO 107 QVSV - XNSS/(55.508-XNSS) C FIND OUT IF WATER VAPOR IS ALREADYPRESENT AS A SPECIES- IF IT C IS NOT CALL ADWVAP TO ADD WATERVAPOR TO THE LIST. 107 DO 120 J-1,NSPC IF(ANAME(J).NE. 4H WAT) GO TO 120 JWAT J DO 110 I-1,NELMT IF(A(JWAT,I).EQ.0.0) GO TO 110 TWAT - I GO TO 140 110 CONTINUE 120 CONTINUE CALL ADWVAP(NSPC,NELMT) JWAT NSPC IWAT NELMT C ADJUST E(I) AND AMT(J) 140 E(IWAT) XNSS + E(IWAT) + ((QV-OVSV)*55.508) AMT(JWAT) E(IWAT) DO 150 I-1,NELMT IF(I.EQ.IWAT) GO TO 150 E(I) E(I)*QLSV/QL 150 CONTINUE XNSS - 0.0 DO 160 J-1,NSPCS IF(IPHASE(J).NE.2) GO TO 160 AMT(J) AMT(J)*QLSV/QL 168

160 CONTINUE C ADJUST SALINITY SLNMOL - SLNMOL*QLSV/QL IF(IPRT.EQ.0) GO TO 195 WRITE(6,180)0V,OVSV 180 FORMAT(/' COMPSET CALLEDWITH NEW QUALITY- ',F7.4, 1' AND OLD QUALITY- ',F7.4) WRITE(6,38) (E(I),I-1,NELMT) 38 FORMAT(/' ELEMENT COMPOSITIONSRESET TO'/(1P5E15.5)) WRITE(6,40) (AMT(J),J-1,NSPCS) 40 FORMAT(/' SPECIES AMOUNTSRESET TO'/(1P5E15.5)) C SAVE VALUES OF QL AND QV 195 QLSV QL QVSV - QV RETURN END C C....SUBROUTINE ADVAP C SUBROUTINE ADWVAP(NSPC,NELMT) PARAMETER(ND-40) INTEGER ANAME,BNAME,CNAME,WTST COMMON ANAME(ND), BNAME(ND), CNAME(ND),IPHASE(ND), POTO(ND), lAMT(ND), A(ND,ND), X(ND), E(ND),ST(ND,ND), P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MAKK,C(ND,ND), B(ND),IPR 3,AZERO(ND),2(ND),IGAS,ELEC(ND) COMMON/ADDN/IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, 1 FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON/JFKADD/CLK(6,ND) C C THIS SUBROUTINE ADDS WATER VAPORTO THE LIST OF SPECIES C SETTING THE APPROPRIATE VALUES FORTHE SPECIES VARIABLES C NELMT = NELMT+1 NSPC - NSPC+1 IPHASE(NSPC) - 1 Z(NSPC) - 0.0 AZERO(NSPC) - 0.0 H20(NSPC) = 0.0 C(NSPC) = 1.0 DO 10 1-1,6 10 CLK(I,NSPC) = 0.0 NLK(NSPC) = NSPC DO 20 I-1,NELMT 20 A(NSPC,I) - 0.0 DO 25 J-1,NSPC 25 A(J,NELMT) - 0.0 A(NSPC,NELMT) - 1.0 E(NELMT) - 0.0 ANAME(NSPC) - 4H WAT BNAME(NSPC) 4HER V CNAME(NSPC) 4HAPOR RETURN 169

END C c....suBRoUTINE PsAT C SUBROUTINE PsAT(RT,RP) PARAMETER(ND-40) DIMENSION SK(9) DATA SK /- 7.691234564, -26. 08023696, - 168.1706546,64.23285504, 1-118.9646225,4.16711732,20.9750676,1.0E+9,6.0/ C C THIS SUBROUTINE CALCULATES THE VAPOR PRESSUREOF WATER C GIVEN THE TEMPERATURE - BOTH TEMP AND PRESS IN REDUCED UNITS C C RT Is REDUCED TEMPERATURE C PR IS REDUCED PRESSURE C THETA RT E 0.0 DO 10 N-1,5 10 E E+sK(N)*(1.0-THETA)**N E E/THETA/(1.0+SK(6)*(1.0-THETA)+sK(7)*(1.0-THETA)**2) E E-(1.0-THETA)/(SK(8)*(1.0-THETA)**2+SK(9)) BETA = EXP(E) RP = BETA RETURN END C C. SUBROUTINE GETCHEM C SUBROUTINE GETCHEM(NSPCS,IDUM,NELWr,IDUM1) PARAMETER(ND-40) INTEGER ANAME,BNAmE,CNAME COMMON ANAME(ND),BNAME(ND),CNAME(ND),IPHASE(ND),POTO(ND), 1AMT(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND),P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MARK, C(ND,ND),B(ND),IPR 3,AZERD(ND),2(ND),ICAS,ELEC(ND) INTEGER WTST COMMON/ADDN/IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, 1 FRACT(ND),THERCON(ND),DENPpT(ND),FWPPT(ND),GmsLT,DENSLN COMMON/JFKADD/CLK(6,ND) COMMON/JFKADX/TFP(ND) DIMENSION XRD( 15), IXRD (15),IDUM(1),IDUM1(1),IASW(ND) C C THIS SUBROUTINE READS CHEMISTRY DATA FROM TAPE25FOR THE C SPECIES NUMBERS LISTED BY IDUM(J) AND SETS THE VALUESOF C THE PROPER VARIABLES C C IASW(J) STORES THE A(J,I) COLUMN VALUES AS ON TAPE25- THESE C VALUES ARE REASSIGNED AFTER ALL DATA ARE READ IN SO THAT NO VACANT COLUMNS EXIST IN THE A(J,I) MATRIX. C C REWIND TAPE25 AND SKIP FIRST 4 LINES OF COMMENTS REWIND 25 170

READ(25,2002) 2002 FORMAT( / //) C INITIALIZE SOME VARIABLES Do 2010 1-1,40 Do 2005 J-1,40 2005 A(I,J) - 0.0 IASW(I) - 0 2010 CONTINUE IANXT - 0 NFND - 0 C READ A LINE CHECK IF SPECIES NUMBER MATCHES ANY IDUM(J) - C IF YES READ ADDITIONAL LINES AND SET DATA IN PROPERVARIABLES 1900 IDSPL IDSP READ(25,1905,END-1970) IDsp,(IxRD(JJ),JJ-1,4),(xRD(JJ),JJ-1,4) 1905 FoRMAT(15,3X,3A4,15,4F5.1) 1910 DO 1950 JJ- 1,NSPCS IF(IDSP.NE.IDUM(JJ)) GO TO 1950 C SET IDUM(JJ) NEGATIVE TO INDICATE A MATCH IDUM(JJ) IDUM(JJ) ANAME(JJ) IXRD(1) BNAME(JJ) IXRD(2) CNAME(JJ) = IXRD(3) IPHASE(JJ) = LXRD(4) Z(JJ) XRD(1) AZERO(JJ) = XRD(2) H20(JJ) = XRD(3) ELEC(JJ) = XRD(4) READ(25,1915) ICT,(XRD(JX),IXRD(JX),JX-1,ICT) 1915 FORMAT(5X,15,F5.1,15,F5.1,15,75.1,15,F5.1,15,F5.1,15,F5.1,15) C SET VALUES OF A(J,I) MATRIX- PACK SO NO VACANT COLUMNS DO 1920 JX -1,ICT IF(IANXT.EQ.0) GO TO 2030 DO 2020 Ty-1,1ANXT IF(IXRD(JX).EQ.IASW(JY)) GO TO 2040 2020 CONTINUE 2030 IANXT - IANXT+1 IASW(IANXT) IXRD(JX) A(JJ,IANXT) - XRD(JX) GO TO 1920 2040 A(JJ,JY) XRD(JX) 1920 CONTINUE READ(25,1935) (cLK(Jx,JJ),Jx-1,6) 1935 FORMAT(5X,6E15.6) C IF SOLID PHASE READ SOLID DATA IF(IPHASE(JJ).LE.2) GO TO 1960 READ(25,1945) THERCoN(JJ),DENRPT(JJ),FWPFT(JJ),TFP(JJ) 1945 FoRMAT(5x,F10.6,2F10.5,F10.6) GO TO 1960 1950 CONTINUE C IF NO MATCH BYPASS DATA FOR THIS SPECIES READ(25,1952) IDSPX READ(25,1952) IDSPX IF(IXRD(4).GT.2) READ(25,1952) IDSPX 171

1952 FORMAT(I5) IF(IDSPX.EQ.IDSP) GO TO 1900 WRITE(6,1955) IDSPL,IDSP,IDSPX 1955 FORMAT(///' MISMATCH ON CHEMISTRY DATA FILE'/ 1' CHECK NUMBER OF CARDS PER SPECIES AND IPHASE NEAR SPECIES 2'NUMBERED ',3I8// 3' CALCULATION TERMINATED',15X,'STOP 76') STOP 76 C CHECK IF ALL DATA HAVE BEEN READ IN 1960 NFND - NFND +1 IF(NFND.LT.NSPCS) GO TO 1900 C ALL DATA IN - CHECK FOR MATCH BETWEEN SPECIES NUMBERS AND C ELEMENT NUMBERS - REASSIGN ELEMENT NUMBERS DO 2070 II-1,NELMT DO 2050 JJ-1,NSPCS IF(IDUM1(II).NE.IABS(IDUM(JJ))) GO TO 2050 IDUM1(II) - JJ GO TO 2070 2050 CONTINUE WRITE(6,2060) IDUM1(II) 2060 FORMAT(///' NO MATCH WAS FOUND FOR ELEMENT ',I6/ 1' COMPARE LIST OF SPECIES AND INPUT COMPOSITIONS'/ 2' CALCULATION TERMINATED',15X,'PROGRAM STOP 75') STOP 75 2070 CONTINUE C RESET IDUM(J) POSATIVE DO 1965 JJ-1,NSPCS 1965 IDUM(JJ) = IABS(IDUM(JJ)) GO TO 1995 C END OF FILE PATH - PRINT DATA AND STOP 1970 WRITE(6,1972)

1972 FORMAT(///' END OF FILE ENCOUNTERED ON CHEMISTRY ' 2,'DATA FILE'/ 3' THE FOLLOWING SPECIES NUMBERS WERE REQUESTED'/ 4' THOSE MARKED WITH ** WERE NOT FOUND'/) DO 1979 JJ-1,NSPCS IF(IDUM(JJ).LT.0) GO TO 1978 WRITE(6,1974) IDUM(JJ) 1974 FORMAT(I8,3H **) GO TO 1979 1978 IDUM(JJ) -IDUM(JJ) WRITE(6,1976) IDUM(JJ) 1976 FORMAT(I8) 1979 CONTINUE WRITE(6,1980) 1980 FORMAT(///' REEXAMINE INPUT DATA'/ 1' CALCULATION TERMINATED',15X,'PROBLEM STOP 77') STOP 77 1995 CONTINUE RETURN END C C....SUBROUTINE BRINVP 172

C SUBROUTINE BRINVP(TX,SAL,PVP) PARAMETER(ND -40) C C SUBROUTINE CALCULATES ADJUSTED TEMPERATUREFOR BRINE C OF SAL MOLES OF SALT PER KG H2O AND CALLSPSAT FOR C CALCULATION OF VAPOR PRESSURE C C TX IS TEMPERATURE IN K C SAL IS SOLUTION SALINITY IN MOLES OF SALTPER KG WATER C PVP IS WATER VAPOR PRESSURE IN ATM C TC - 647.3 PC - 218.31 A-1.+5.93582E-06*SAL-5.19386E-05*SAL**2.+1.23156E-05*SAL**3. B-1.1542E-06*SAL+1.41254E-07*SAL**2.-1.92476E-08*SAL**3. 1-1.70717E-09*SAL**4.+1.0539E-10*SAL**5. SLOPE-1/(A+B*TX) TZERO-EXP(SLOPE*ALOG(TX)) TR-TZERO/TC CALL PSAT(TR,PR) PVP PC*PR RETURN END C C....SUBROUTINE ELNACT C SUBROUTINE ELNACT(NSPCS) PARAMETER(ND-40) C C SUBROUTINE CALCULATES ELECTRON ACTIVITY FOROXIDATION-REDUCTION C REACTIONS BY VARIOUS TECHNIQUES C IREDOX SETS TYPE OF CALCULATION C AELEC IS LN(ELECTRON ACTIVITY) C COMMON ANAME(ND), BNAME(ND), CNAME(ND),IPHASE(ND), POTO(ND), lAMT(ND), A(ND,ND), X(ND), E(ND), ST(ND,ND),P, NPHAS, NREACT, 2INDX3, PHAS(ND), JT, KKMA, MAKK, C(ND,ND),B(ND),IPR 3,AZERO(ND),Z(ND),IGAS,ELEC(ND) COMMON/ADDN/IG,WTST,AH20,G(ND),XI,NLK(ND),H20(ND),JW,TOLS, 1 FRACT(ND),THERCON(ND),DENPPT(ND),FWPPT(ND),GMSLT,DENSLN COMMON/REDOX/IREDOX,AELEC,ESET,TRDX,TCON C CHECK LIMITS OF IREDOX IF(IREDOX.LE.0) RETURN IF(IREDOX.LE.3) GO TO 10 WRITE(6,5) IREDOX 5 FORMAT(//' IREDOX OUTSIDE RANGE OF ACCEPTABLEVALUES'/ 1 ' IREDOX - ',I6/

2 ' PROBLEM STOP -- CHECK INPUT DATA' //) STOP C BRANCH DEPENDING ON VALUE OF IREDOX 10 GO TO(100,200,200),IREDOX C EH VALUE INPUT AS ESET- ELECTRON ACTIVITY CONSTANT 173

C LN(ELEC ACT) - -ESET*F/(R*TRDX) 100 AELEC - -ESET*11605.4/TRDX RETURN C ELECTRON ACTIVITY DEPENDS ON H2O ACTIVITY ANDOH- ACTIVITY C FIND AND CALCULATE THE REQUIRED DATA C TCON IS DELF/RT FOR THE REACTION CONTROLLINGELECTRON ACTIVITY 200 N1 - 0 N2 -0 FAC = 0.0 NFAC 0 DO 210 J-1,NSPCS IF(ANAME(J).EQ.4H H+() Ni J IF(ANAME(J).EQ.4H OH-) N2- J 210 CONTINUE IF(N2.EQ.0) GO TO 220 IF(AMT(N2).LE.0.0) GO TO 220 FAG - ALOG(AMT(N2)*G(N2)) NFAC NFAC+1 220 IF(N1.EQ.0) GO TO 222 IF(AMT(N1).LE.0.0) GO TO 222 FAC = FAC + POTO(JW)- ALOG(AMT(N1)*G(N1)) NFAC = NFAC+1 222 IF(NFAC.EQ.0) GO TO 225 FAC = FAC/FLOAT(NFAC) GO TO 230 225 FAC = -16.12 230 IF(IREDOX.GT.2) GO TO 300 C OXYGEN PARTIAL PRESSURE INPUT AS ESET C 40H- - 02(G) + 21120 + 4E- AELEC 0.25*(-TCON ALOG(ESET) - (2.0*ALOC(AH20)) 1 + (4.0*FAC)) RETURN C SULFATE/SULFIDE RATIO INPUT AS ESET C S-2 + 80H- - 804-2 + 4H20 + 8E- 300 AELEC 0.125*(-TCON - ALOC(ESET) (4.0*ALOG(AH20)) 1 + (8.0*FAC)) RETURN END C C.. SUBROUTINE MATINV C SUBROUTINE MATINV(A,IA,IN,R,DET) C C THIS SUBROUTINE INVERTS MATRIX A C DIMENSIONA(IA,IN),DET(1),R(1) C THE FOLLOWING CARD IS USED IF DOTPRO IS DONEIN DOUBLE C PRECISION - SEE FUNCTION DOTPRO. C DOUBLE PRECISION DOTPRO,S CHARACTER*50 B,C EQUIVALENCE(S,SS)

B ' MATINV, N.LE.0 OR N.GT.IA, N - C - 'MATINV SINGULAR SYSTEM, NO UNIQUE SOLUTION 174

A(I,J)- -DOTPRO(NE,A(NR,J),1,A(I,NR),IA) -A(I,J) 114 NE-NE+1 DET(1)-DET(1)*A(NR,NR) 110 CONTINUE S-1./A(N,N) A(N,N)-S D0116 I-2,N 116 A(N,I-1)-A(N,I-1)*S NE-1 NC-N-1 NP-N MC-N-2 DO 120 NR-2,N S-1./A(NC,NC) IF(MC.LE.0)GOT0126 D0124 IR-1,MC 124 A(NC,IR)-S*(A(NC,IR)-DOTPRO(NE,A(NC,NP),IA,A(NP,IR),1)) 126 A(NC,NC)-S*( 1. -DOTFRO(NE,A(NC,NP),IA,A(NF,NC),1)) DO 128 IR-NP,N DET(IR) --S*DOTPRO(NE,A(NC,NP),IA,A(NP,IR),1) 128 CONTINUE D0129 IR-NP,N 129 A(NC,IR)-DET(IR) MC-MC-1 NC-NC-1 NP-NP-1 120 NE-NE+1 D0140 IR-2,N J-N-IR+1 K-R(J) IF(K-EQ-J)G0T0140 D0144 I-1,N S-A(I,J) A(I,J)-A(I,K) 144 A(I,K)-S DET(1)--DET(1) 140 CONTINUE 99 RETURN 96 CALL LABRT(1,B,N) 97 DET(1)=0. GOT099 98 CALL LABRT(1.C,NR) GOT097 END C C. .SUBROUTINE LABRT C SUBROUTINE LABRT(ISW,LHOL,INX) C C THIS SUBROUTINE PRINTS A MESSAGE AND ABORTS EXECUTION WITH A STOP C IN CASE OF AN ERROR C CHARACTER*50 LHOL 175

LOGICALPS,TS IF((ISW.EQ.0).0R.(ISW.GT.5))RETURN GOTO(1,2,3,4,5),ISW DATA NP/10/,PS/.TRUE./,TS/.FALSE./ 1 IF(PS.AND.(NP.GT.0)) WRITE(*,27)LHOL,INX 27 FORMAT(/10X,A50,3X,I6) NP-NP-1 IF(TS) STOP RETURN 2 PS- .FALSE RETURN 3 PS- .TRUE. NP-INX RETURN 4 TS -.TRUE. RETURN 5 TS- .FALSE. RETURN END C C....FUNCTION DOTPRO

FUNCTION DOTPRO(N,X,IX,Y,IY) DOUBLE FUNCTION DOTPRO(N,X,IX,Y,IY) C C THIS ROUTINE CALCULATES THE INNER PRODUCT OF TWO REAL VECTORS,I.E. C C DOTPRO - SUMMATIONX(1+(I-1)*IX) * Y(1+(I-1)*IY) C I - 1,2 C

C THUS IX IS THE MEMORY SPACING BETWEEN ELEMENTS OF THEFIRST VECTOR, AND IY IS THE MEMORY SPACINGBETWEEN ELEMENTS OF THE SECOND C VECTOR. C THE ELEMENTS OF X AND Y ARESINGLE PRECISION, AND THE SUM C IS ACCUMULATED IN SINGLEPRECISION. IF DOUBLE PRECISION C IS DESIRED REPLACE THE FUNCTIONNAME BY THAT ON THE CARD AFTER C IT, AND REMOVE THE COMMENTFROM THE CARD DOUBLE SUM. ALSO C REMOVE THE COMMENT FROM THEDOUBLE CARD IN SUBROUTINE C MATINV. C DOUBLE SUM C IF N .LE. 0 RESULT IS ZERO DIMENSION X(I),Y(1) IF(N.LE.0) COT020 SUM-0, NX = IX NY - IY J-1 K-1 D010I -1,N SUM -SUM+X(J)*Y(K) J-J+NX 10 K-K+NY 176

DOTPRO SUM RETURN 20 DOTPRO =O. RETURN END C C....SUBROUTINE MINV C SUBROUTINE MINV(X,IX,N,I,Y) DIMENSION X(200) 1 12-1 2 YX(1) 1=1 IF(I2.EQ.0)Y=ABS(Y) NN(N-1)*IX+1 DO 6 II=1,NN,IX Z=X(II) IF(12.EQ.0)Z=ABS(2) 4 IF(Z-Y)5,6,6 5 Y=Z

6 CONTINUE IIIX*(I-1) +1 YX(II) RETURN END C C CONDATA C C SUBROUTINE CONDATA( -NSPCS,IDUM,NLK,ICANBR) PARAMETER (ND = 40) C C....THIS SUBROUTINE CONVERTS THEINPUT OF SENECA2 INTO A FORM USED C IN THE PITZER EQUATIONS. IT COMPARES THE SPECIES IN THE SYSTEM C WITH A LIST WHICH WILL TELL IFTHE SPECIES IS A CATION, ANION OR C OTHER SPECIES. IT KEEPS TRACK OF THE NUMBERS OF EACHOF THESE, C AND ALSO GIVES THE ADDRKsSES INPITDATA FOR THE INFORMATION C NEEDED IN THE PITZER EQUAITONS. C C C COMMON /ADDRESS/ KANUM(ND), KCATNUM(ND) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM C C INTEGER NSPCS,IDUM(ND),NLK(ND),KANUM,KCATNUM,NUMC1,NUMA1, NCM,NAM,LIDSP,JCATAN,IADD,LCON,JCON,ICANBR(ND) C OPEN(26,FILE'CONDATA',FORM'FORMATTED',ACCESS'SEQUENTIAL', &STATUS 'OLD') REWIND(26) C 177

C....READ IN THE NUMBER OF DATA AVIALABLE FORCATIONS, AND ANIONS C SPECIES. ALSO, READ IN THE SUM OF THESE VALUES, N. C READ(26,8001) NUMC1,NUMA1,NTIRE 8001 FORMAT(/,3I10) C C....INITIALIZE VARIABLE COUNTERS AND ARRAYSOF DATA C NCM 0 NAM - 0 DO 20 LCON-1,ND ICANBR(LCON) 0 KCATNUM(LCON) 0 KANUM(LCON) 0 20 CONTINUE C C..READ IN DATA LINE, CHECK IF IT IS IN SYSTEMAND IF IT IS WHETHER C IT IS A CATION, ANION, OR SOLID SPECIES, OR NONEOF THESE. C PLACE IN ADDRESS RELATIVE TO NLK AND SAVE DATA ADDRESSFOR FINDING C PITZER COEFFICIENTS. C DO 60 LCON-1,NTIRE READ(26,8002) LIDSP,JCATAN,IADD 8002 FORMAT(10X,3I10) C C..THE VALUES ARE READ IN FROM THE FILE, ANDTHEN DETERMINED C TO BE EITHER CATION, ANION, OR SOLID SPECIES. THEY ARE C ASSIGNED A 1000, 2000, OR 9 NUMBER PLUS THE NUMBEROF C SPECIES THEY WERE. THIS IS DONE SO WHEN THE ORDER OF THE C COMPONENTS IS CHANGED THE IONIC SPECIES CAN STILLBE RECOGNIZED C RELATIVE TO THE PARAMETER NLK. THE WATER VALUE IS ALSO FOUND C AND GIVEN A ICANBR OF 4000. C DO 40 JCON-1,NSPCS IF(IDUM(JCON).EQ.LIDSP)THEN IF(JCATAN.EQ.9)THEN ICANBR(NLK(JCON)) - 9 ELSE IF(JCATAN.EQ.1)THEN NCM - NCM + 1 ICANBR(NLK(JCON)) - 1000 + NCM KCATNUM(NCM) - IADD ENDIF IF(JCATAN.EQ.2)THEN NAM - NAM + 1 ICANBR(NLK(JCON)) - 2000 + NAM KANUM(NAM) IADD ENDIF IF(JCATAN.EQ.4)THEN ICANBR(NLK(JCON)) - 4000 ENDIF ENDIF ENDIF 178

40 CONTINUE 60 CONTINUE CLOSE(26) C C WRITE(*,8003) C 8003 FORMAT(//5X,'END OFCONDATA FILE',//) C RETURN END C C SUBROUTINE PITDATA C SUBROUTINE PITDATA(TEMP) PARAMETER (ND - 40,NION- 15) COMMON /BETA/B0(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /CPHI/ CFI(NION,NION) COMMON /DHTERM/ APHI,BEE COMMON /THETA/ATHETA(NION,NION),CTHETA(NION,NION) COMMON /ALFA/ ALPHAO,ALPHA1,ALPHA2 COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) COMMON /NAME/ ANNAME(NION),CATNAME(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /ADDRESS/ KANUM(ND),KCATNUM(ND) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM C C....DECLARATION OF VARIABLE TYPES REAL BO,B1,B2,CFI,ATHETA,CTHETA,AACPSI,CCAPSI,ACHARG,CCHARG, ALPHAO,ALPHA1,ALPHA2,ANTHET,BA,BB,BC,CATHET,CH,CP, TEMP,VAL(5),ZAP,BEE INTEGER HOP,KANUM,KCATNUM,NUMC1,NUMA1,NCM,NAM,LPIT,LI1, IDOWNC(NION),IHOP,LINA(NION),LINC(NION), IDOWNA(NION),IOLDA(NION),IOLDC(NION),IOLDS,ITA,ITOT,JPIT, JUNO,J2,JA,JB,JC,JD,JSKIP,KAY,MN1,MN2,NEXT,NEXTA, NSKIPA,NSKIPC,NUmA3,NUMC3,IANUM,ISKFLG CHARACTER*9 ANNAME,CATNAME CHARACTER*9 ANAM C C....INTIALIZE THE STORAGE ARRAYSTO ZERO DO 10 JPIT-1,NION ANNAME(JPIT)- 'BLANK' CATNAME(JPIT)= 'BLANK' ACHARC(JPIT)-0.0 CCHARG(JPIT)-0.0 10 CONTINUE DO 40 JPIT-1,NION DO 20 LPIT-1,NION BO(JPIT,LPIT)-0.0 B1(JPIT,LPIT)-0.0 B2(JPIT,LPIT)-0,0 CFI(JPIT,LPIT)-0.0 HOP(JPIT,LPIT)-0 CTHETA(JPIT,LPIT)-0.0 179

ATHETA(JPIT,LPIT)=0.0 20 CONTINUE 40 CONTINUE DO 100 KAY-1,NION DO 80 JPIT-1,NION DO 60 LPIT-1,NION AACPSI(KAY,JPIT,LPIT)-0.0 CCAPSI(KAY,JPIT,LPIT)-0.0 60 CONTINUE 80 CONTINUE 100 CONTINUE C C..CALL SORTING ROUTINE. THIS SORTING ROUTINE WILL PUT THE VALUES C IN ASCENDING ORDER WHILE KEEPING TRACK OF THERE ORIGINAL POSITION C IN THE CALL. THIS IS DONE FOR A SPEED-UP IN THE SEARCH TIME AS C THE SYSTEMS AND DATABASES ENLARGED. C CALL SORT(KANUM,NAM,NUMA1,IOLDA,NSKIPA,IDOWNA,LINA) CALL SORT(KCATNUM,NCM,NUMC1,IOLDC,NSKIPC,IDOWNC,LINC) C OPEN(27,FILE-'PITDATA.,STATUS=1OLD') REWIND(27) C C..THIS SECTION READS A LINE FROM THE DATABASE AND COMPARES IT WITH C THE CURRENT CATION, IF THEY MATCH, THEN A STEP THROUGH THE ANIONS C TO FILL THE CATION-ANION INTERACTION TERMS. IF THEY DO NOT MATCH C BLANK SPACES ARE READ TILL THE NEXT CATION LINE IS READ. C READ(27,8005) 8005 FORMAT(8X) NEXT - 1 DO 140 LPIT -1, NUMC1 READ(27,8010) NUMAGE,ANAM,ZAP 8010 FORMAT(I3,A9,F5.1) IF(NUMAGE.EQ.KCATNUM(NEXT))THEN CATNAME(IOLDC(NEXT)) = ANAM CCHARG(IOLDC(NEXT)) - ZAP NEXTA = 1 DO 120 JPIT =1, NUMA1 READ(27,8020) IANUM,ANAM,CH,BA,BB,BC,CPHI1,IHOP 8020 FORMAT(I3,A9,F5.1,4F13.7,12) IF(IANUM.EQ.KANUM(NEXTA))THEN ANNAME(IOLDA(NEXTA)) = ANAM ACHARG(IOLDA(NEXTA)) = CH BO(IOLDC(NEXT),IOLDA(NEXTA)) = BA B1(IOLDC(NEXT),IOLDA(NEXTA)) - BB B2(IOLDC(NEXT),IOLDA(NEXTA)) - BC CFI(IOLDC(NEXT),IOLDA(NEXTA)) = CPHI1 HOP(IOLDC(NEXT),IOLDA(NEXTA)) - IHOP NEXTA - NEXTA + 1 ENDIF 120 CONTINUE NEXT = NEXT + 1 180

ELSE DO 130 LI1-1, NUMA1 READ(27,8030) 8030 FORMAT(5X) 130 CONTINUE ENDIF 140 CONTINUE C C....FIND CCAPSI VALUES IN DATABASE C C....SET SEARCH LENGTH PARAMETER C READ(27,8005) NUMC3 (NUMC1*(NUMC1 -1))/2 DO 280 LPIT -1, NUMC3 ISKFLG = 0 READ(27,8040) MN1,MN2,CATHET 8040 FORMAT(113,13X,I13,13X,F13.7) C C....GOES THROUGH ALL CATIONS IN THE SYSTEM DO 240 JUNO-1, NCM C C....CHECK FIRST TERM IN CCAPSI IF(MN1.EQ.KCATNUM(JUNO))THEN DO 220 J2-1, NCM C C....CHECK SECOND TERM IF(MN2.EQ.KCATNUM(J2))THEN C C....PLACING VALUE IN BOTH SIDES OF THE SYMMETRIC MATRIX ISKFLG - 1 CTHETA(IOLDC(JUNO),IOLDC(J2)) - CATHET CTHETA(IOLDC(J2),IOLDC(JUNO)) CATHET IOLDS - 0 DO 180 JA-1, NAM C C..CHECK TO SEE IF THIS VALUE IS ON THE SAME LINE AS PREVIOUS VALUE C IF NOT, CALCULATE HOW MANY LINES TO SKIP AND READ IN NECESSARY C LINE. IF(IOLDS.NE.IDOWNA(JA))THEN

ITA = IDOWNA(JA) - IOLDS IOLDS = IDOWNA(JA) DO 160 JB=1, ITA READ(27,8050)(VAL(JC),JC-1,5) 160 CONTINUE 8050 FORMAT(5F13.7) ENDIF C C....PLACE VALUE IN BOTH SIDES OF THE MATRIX CCAPSI(IOLDC(JUNO),IOLDC(J2),IOLDA(JA)) VAL(LINA(JA)) CCAPSI(IOLDC(J2),IOLDC(JUNO),IOLDA(JA)) VAL(LINA(JA)) 180 CONTINUE C 181

C....CALCULATE THE REMAINING NUMBER OF LINES TO SKIP BEFORETHE NEXT C CATION - CATION LINE, AND THENSKIP THEM IF(NSKIPA.NE.IOLDS)THEN ITOT - NSKIPA- IOLDS DO 200 JD-1, ITOT READ(27,8030) 200 CONTINUE ENDIF ENDIF 220 CONTINUE ENDIF 240 CONTINUE IF(ISKFLG.EQ.0)THEN DO 260 JSKIP-1, NSKIPA READ(27,8030) 260 CONTINUE ENDIF 280 CONTINUE C C..FIND AACPSI VALUES INDATABASE MATIRIX C FOR EXPLAINATION SEE SECTIONON CCAPSI SEARCH C READ(27,8005) NUMA3 = (NUMA1*(NUMA1 1))/2 DO 420 LPIT-1, NUMA3 ISKFLG 0 READ(27,8040) MN1,MN2,ANTHET DO 380 JUNO-1, NAM IF(MN1.EQ.KANUM(JUNO))THEN DO 360 J2-1, NAM IF(MN2.EQ.KANUM(J2))THEN ISKFLG - 1 ATHETAUOLDA(JUNO),IOLDA(J2)) ANTHET ATHETA(IOLDA(J2),IOLDA(JUNO)) s ANTHET IOLDS = 0 DO 320 JA-1,NCM IF(IOLDS.NE.IDOWNC(JA))THEN ITA IDOWNC(JA) IOLDS IOLDS = IDOWNC(JA) DO 300 JB-1, ITA READ(27,8050)(VAL(JC),JC-1,5) 300 CONTINUE ENDIF AACPSI(IOLDA(JUNO),IOLDA(J2),IOLDC(JA)) VAL(LINC(JA)) AACPSI(IOLDA(J2),IOLDA(JUNO),IOLDC(JA)) VAL(LINC(JA)) 320 CONTINUE IF(NSKIPC.NE.IOLDS)THEN ITOT - NSKIPC -IOLDS DO 340 JD-1, ITOT READ(27,8030) 340 CONTINUE ENDIF ENDIF 182

360 CONTINUE ENDIF 380 CONTINUE IF(ISKFLG.EQ.0)THEN DO 400 JSKIP-1,NSKIPC READ(27,8030) 400 CONTINUE ENDIF 420 CONTINUE C C....READ IN ALPHA'S, APHI, AND B C READ(27,8005) READ(27,8060) ALPHAO READ(27,8060) ALPHA1 READ(27,8060) ALPHA 2 READ(27,8060) APHI READ(27,8060) BEE 8060 FORMAT(13X,F13.7) CLOSE(27) C C WRITE(6,8070) C 8070 FORMAT(//5X,'END OF COLLECTINGPITZER DATA. C & NOW BEGINNING TO ', 'CHECK VALUES FOR MISSING DATA',//) C RETURN END C SUBROUTINE SORT(IVEC,NUMSKL,NUMT,IOLD,NSKIP,IDOWN,IN) C C..THIS SUBROUTINE MAKES SURE THAT THEVALUES ARE IN ASCENDING ORDER, C AND WILL KEEP TRACE OF THE ORIGINALADDRESSES IN THE MATRIX IOLD. C ALSO, THIS SUBROUTINE WILL CALCULATETHE NUMBER OF LINES THAT C CAN BE SKIPPED IN IN THE TRIPLEINTERACTION PARAMETER SECTION IF C NEEDED, OR WHERE IN THE DATA BLOCK RESIDESTHE VALUE NEEDED. C C VARIABLE TYPE DESCRIPTION C C LSOR INTEGER-I COUNTER C IPLUS I START VALUE ON ORDERING VALUES JSOR I COUNTER C NUMSKL I STOP VALUE C IVEC(X) I THE ORIGINAL VECTOR TO BE SORTED AND C VALUE LOCATED C IHAND I DUMMY VARIABLE IOLD(X) I THE ORIGINAL ADDRESS OF THE VALUE C IVEC(X) BEFORE SORTING C XLIN R CALL LINE IN DATA BLOCK C IHOLD I PART OF CALC IN DATA BLOCK C PLUS R VALUE TO DETERMINE IF END OF LINE C IDOWN(X) I NUMBER OF LINES TO SKIP IN DATA BLOCK C IN(X) I WHICH VALUE IN THE DATA BLOCK OF FIVE C NSKIP I TOTAL LINES TO BE SKIPPED IF NOT A 183

ION OF INTEREST IN DATA BLOCK C NUMT I TOTAL NUMBER OF IONS OF THAT TYPEIN C DATABASE, SO NSKIP CAN BE CALCULATED C C C REAL XLIN,PLUS INTEGER LSOR,IPLUS,JSOR,NUMSKL,IVEC(NUMSKL),IHAND,IOLD(NUMSKL), & IN(NUMSKL),NSKIP,NUMT,IDOWN(NUMSKL),IHOLD C C....INITIALIZE VECTORS THAT ARE FIRST USED INTHIS SUBROUTINE C DO 10 LSOR-1, NUMSKL IOLD(LSOR) LSOR IDOWN(LSOR) - 0 IN(LSOR) 0 10 CONTINUE C....SORT VALUES OF IVEC KEEPING TRACK OFORIGINAL ADDRESS IN IOLD C DO 30 LSOR-1,NUMSKL-1 IPLUS LSOR + 1 DO 20 JSOR-IPLUS, NUMSKL IF(IVEC(JSOR).LT.IVEC(LSOR))THEN IHAND - IVEC(JSOR) IVEC(JSOR) IVEC(LSOR) IVEC(LSOR) IHAND IHAND - IOLD(LSOR) IOLD(LSOR) a IOLD(JSOR) IOLD(JSOR) IHAND ENDIF 20 CONTINUE 30 CONTINUE C C....CALCULATE LOCATION OF VALUE IN IVEC C DO 40 LSOR-1, NUMSKL XLIN REAL(IVEC(LSOR))/5. IHOLD - INT(XLIN) PLUS - XLIN - REAL(IHOLD) IF(PLUS.EQ.0.00000)THEN IDOWN(LSOR) IHOLD IN(LSOR) - 5 ELSE IDOWN(LSOR) IHOLD + I IN(LSOR) INT(5.1*PLUS) ENDIF 40 CONTINUE C C....CALCULATE NUMBER OF LINES TO BE SKIPPED IF IONNOT OF INTEREST C XLIN REAL(NUMT)/5. IHOLD - INT(XLIN) PLUS - XLIN REAL(IHOLD) 184

IF(PLUS.EQ.0.00000)THEN NSKIP IHOLD ELSE NSKIP IHOLD + 1 ENDIF RETURN END C C C SUBROUTINE DATAWT PARAMETER (NION 15) COMMON /BETA/BO(NION,NION),B1(NION,NION),B2(NION,NION), HOP(NION,NION) COMMON /CPHI/ CFI(NION,NION) COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /PSI/AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) COMMON /NAME/ ANNAME(NION),CATNAME(NION) COMMON /CHARGE/ ACHARG(NION),CCHARC(NION) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM REAL BO,B1,B2,CFLATHETA,CTHETA,AACPSI,CCAPSI,ACHARC,CCHARG INTEGER HOP,NUMC1,NUMA1,NCM,NAM,LUT,JWT,KAY CHARACTER*9 ANNAME,CATNAME C C FILE 30 HAS WHICH CONSTANTSARE MISSING AND SET TO ZERO C FILE 31 HAS THE VALUES FORTHE CONSTANTS USED IN THEPROGRAM C WRITE(30,8010) 8010 FORMAT(//5X,'NO DATAWAS AVAILABLE FOR THE FOLLOWINGLON ', &'INTERACTION CONSTANTS:',/5X,'MISSINGVALUES ARE SET TO ZERO', & //) WRITE(31,8020) 8020 FORMAT(//5X,'DATA USED IN ACTIVITY COEFFICIENTPREDICTION', &//2X,'CATION',3X,'CHARGE",2X,'ANION',5X/CHAREE',4X,'BO',

C C....A CHECK TO SEE IF THE VALUE 1001WAS READ FROM THE INPUT FILE. C IF IT WAS THE CONSTANT ISUNKNOWN, AND SET TO ZERO AND RECORDED C ON THE FILE PITOUT. IF THE VALUE IS NOT 1001, THENIT WRITTEN C TO THE FILE PITCON, DO 40 LWT-1,NCM DO 20 JWT-1,NAM IF(BO(LWT,JWT).EQ.1001.) & BO(LWT,JWT)-FIX1(1130 ',CATNAME(LWT),ANNAME(JWT)) IF(B1(LWT,JWT).EQ.1001.) & B1(LWT,JWT)-FIX1('Bl ',CATNAME(LWT),ANNAME(JWT)) IF(B2(LMT,JWT).EQ.1001.) & B2(LWT,JWT)-FIX1('B2 ',CATNAME(LWT),ANNAME(JWT)) IF(CFI(LWT,JWT).EQ.1001.) & CFI(LWT,JWT)-FIX1('CFI ',CATNAME(LWT),ANNAME(JWT)) WRITE(31,8030)CATNAME(LWT),CCHARG(LWT),ANNAME(JWT),ACHARG(JWT), &BO(LWT,JWT),B1(LWT,JWT),B2(LWT,JWT),HOP(LWT,JWT),CFI(LWT,JWT) 8030 FORMAT(/2X,A9,1X,F5.0,1X,A9,1X,F5.0,3(2X,F8.4),2X,I2,2X,F8.6) 185

20 CONTINUE 40 CONTINUE WRITE(31,8040) 8040 FORMAT(//2X,76('-'),//) C C....HERE THE CATION-CATION INTERACTION PARAMETERS ARE CHECKED FOR C FOR MISSING VALUES, ALONG WITH THE CCAPSI VALUES. THE CHECK C VALUE OF 1001 WAS USED HERE ALSO FOR MISSING DATA. C DO 100 LWT-1,NCM NSTART = LWT + 1 DO 80 JWT-NSTART,NCM IF(CTHETA(LWT,JWT).EQ.1001.)THEN CTHETA(LWT,JWT) FIX1('CTHETA',CATNAME(LWT),CATNAME(JWT)) CTHETA(JWT,LWT) = FIX1('CTHETA',CATNAME(JWT),CATNAME(LWT)) ENDIF WRITE(31,8050) 8050 FORMAT(/5X,'CTHETA') WRITE(31,8060) CATNAME(LWT),CATNAME(JWT),CTHETA(LWT,JWT) WRITE(31,8060) CATNAME(JWT),CATNAME(LWT),CTHETA(JWT,LWT) 8060 FORMAT(5X,A9,2X,A9,' ',F13.8) WRITE(31,8070) 8070 FORMAT(5X,'CCAPSI VALUES FOR CATION PAIR ABOVE AND ANIONS:') DO 60 KAY-1, NAM IF(CCAPSI(LWT,JWT,KAY).EQ.1001.) THEN CCAPSI(LWT,JWT,KAY) = FIX1ACCCAPSP,CATNAME(LWT), CATNAME(JWT),ANNAME(KAY)) CCAPSI(JWT,LWT,KAY) - FIX1ACCCAPSII,CATNAME(JWT), CATNAME(LWT),ANNAME(KAY)) ENDIF WRITE(31,8080) ANNAME(KAY), CCAPSI(LWT,JWT,KAY) 8080 FORMAT(5X,A9,' ',F13.8) 60 CONTINUE 80 CONTINUE 100 CONTINUE C C....THIS SECTION TESTS ATHETA, AND AACPSI VALUES FOR MISSING DATA C IN THE SAME WAY AS FOR CTHETA AND CCAPSI. C DO 160 LWT-1,NAM NSTART = LWT + 1 DO 140 JWT-NSTART,NAM IF(ATHETA(LWT,JWT).EQ.1001.)THEN ATHETA(LWT,JWT) = FIX1CATHETA',ANNAME(LWT),ANNAME(JWT)) ATHETA(JWT,LWT) - FIXWATHETA',ANNAME(JWT),ANNAME(LWT)) ENDIF WRITE(31,8090) 8090 FORMAT(/5X,'ATHETA') WRITE(31,8060) ANNAME(LWT),ANNAME(JWT),ATHETA(LWT,JWT) WRITE(31,8060) ANNAME(JWT),ANNAME(LWT),ATHETA(JWT,LWT) WRITE(31,8100) 8100 FORMAT(5X,'AACPSI VALUES FOR ANION PAIR ABOVE AND CATION:') DO 120 KAY-1, NCM 186

IF(AACPSI(LWI,JWT,KAY).EQ.1001.) THEN AACPSI(LWT,JWT,KAY)- FIX1A('AACPSI', ANNAME(LWT),ANNAME(JWT),CATNAME(KAY)) AACPSI(JWT,LWT,KAY) FIX1A('AACPSI', ANNAME(JWT),ANNAME(LWT),CATNAME(KAY)) ENDIF WRITE(31,8080) CATNAME(KAY),AACPSI(LWT,JWT,KAY) 120 CONTINUE 140 CONTINUE 160 CONTINUE RETURN END C C FUNCTION FIX1 C FUNCTION FIX1(ID,ID1,1D2) CHARACTER*9 ID1,ID2 CHARACTER*6 ID WRITE(30,8010) ID,ID1,ID2 8010 FORMAT(5X,A6,2(A9)) FIX1 = 0.0 RETURN END C C F U N C T I O N F I X 1 A C FUNCTION FIX1A(ID,ID1,ID2,ID3) CHARACTER*9 ID1,ID2,ID3 CHARACUR*6 ID WRITE(30,8010) ID,ID1,ID2,ID3 8010 FORMAT(5X,A6,3(A9)) FIX1A - 0.0 RETURN END C C. -SUBROUTINE ACTIVY C SUBROUTINE ACTIVY(ZIONST,ZC,CATACT,ANACT) PARAMETER (NION - 15) REAL ZIONST,ZC,FT,F,CT,GAMCAT,CAMAN,CATACT(NION),ANACT(NION) INTEGER ICNTC,ICNTA,NCAT,NAN C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) REAL CMOL,AMOL,ACHARG,CCHARG INTEGER LIC,NUMC,LIA,NUMA C C....COMMON CALCULATIONS C CALL IONZ(ZIONST,ZC) CALL CTERM(CT) FT-F(ZIONST) 187

C C....CATION ACTIVITIES CALCULATED C DO 20 ICNTC-1,NUMC NCAT-LIC(ICNTC) GAMCAT-CCHARG(NCAT)*CCHARG(NCAT)*FT + VC(NCAT,O,ZIONST,ZC) + ABS(CCHARG(NCAT))*CT CATACT(NCAT)-EXP(GAMCAT) 20 CONTINUE C C....ANION ACTIVITIES CALCULATED C DO 40 ICNTA-1,NUMA NAN -LIA(ICNTA) CAMAN-ACHARG(NAN)*ACHARG(NAN)*FT + VC(NAN,1,ZIONST,2C) + ABS(ACHARG(NAN))*CT ANACT(NAN)- EXP(GAMAN) 40 CONTINUE RETURN END C C C....FUNCTION VC C C FUNCTION VC(ION,IONCA,ZIONST,2C) PARAMETER (NION - 15) C REAL ZIONST,ZC,SK1,SK2,SK3,SK4,VC INTEGER ION,IONCA,K1,K2,K3,KA1,KA2,KC1,KC2 C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) REAL CMOL,AMOL,AACPSI,CCAPSI INTEGER LIC,LIA,NUMC,NUMA C C CHECK F FROM ANION OR CATION CALCULATIONS. IONCA - 0 FOR CATION IF(IONCA.EQ.0)THEN SK1-0.0 DO 20 K1-1,NUMA SK1-SKI + AMOL(LIA(K1))*(2.0*BMX(ION,LIA(K1),ZIONST) + ZC*CMX(ION,LIA(K1))) 20 CONTINUE SK2-0.0 DO 60 K2-1,NUMC SK3-0.0 DO 40 K3-1,NUMA SK3-SK3 + AMOL(LIA(K3))*CCAPSI(ION,LIC(K2),LIA(K3)) 40 CONTINUE SK2-SK2 + CMOL(LIC(K2))*(2.0*PHI(ION,LIC(K2),ZIONST,O)+SK3) 60 CONTINUE SK4-0.0 188

DO 100 KA1-1,NUMA KSTP-KA1-1 DO 80 KA2-1,KSTP SK4-SK4 + AMOL(LIA(KA1))*AMOL(LIA(KA2))* AACPSI(LIA(KA1),LIA(KA2),ION) 80 CONTINUE 100 CONTINUE ELSE SK1-0.0 DO 120 K1-1,NUMC SK1-SK1 + CMOL(LIC(K1))*(2.0*BMX(LIC(K1),ION,ZIONST) + ZC*CMX(LIC(K1),ION)) 120 CONTINUE SK2-0.0 DO 160 K2-1,NUMA SK3-0.0 DO 140 K3-1,NUMC SK3-SK3 + CMOL(LIC(K3))*AACPSI(ION,LIA(K2),LIC(K3)) 140 CONTINUE SK2-SK2+AMOL(LIA(K2))*(2.0*PHI(ION,LIA(K2),ZIONST,1) + SK3) 160 CONTINUE SK4-0.0 DO 200 KC1=2,NUMC KSTP-KC1-1 DO 180 KC2=1,KSTP SK4-SK4 + CMOL(LIC(KC1))*CMOL(LIC(KC2))* CCAPSI(LIC(KC1),LIC(KC2),ION) 180 CONTINUE 200 CONTINUE EMIT VC=SK1 + SK2 + SK4 RETURN END

C C....SUBROUTINE CTERM C SUBROUTINE CTERM(CT) PARAMETER (NION = 15) C REAL CT INTEGER LCC,LCA C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION).LIA(NION),NUMA, &AMOL(NION) REAL CMOL,AMOL INTEGER LIC,NUMC,LIA,NUMA C CT-0.0 DO 40 LCC-1,NUMC DO 20 LCA-1,NUMA CT- CT + CMOL(LIC(LCC))*AMOL(LIA(LCA))*CMX(LIC(LCC), LIA(LCA)) 189

20 CONTINUE 40 CONTINUE RETURN END C C C C....FUNCTION F C FUNCTION F(ZIONST) PARAMETER (NION - 15) REAL ZIONST,SVC1,SVC2,BPRIME,PHIPRM,SVC3,F INTEGER JCAT,JAN,JC1,JC2,JA1,JA2, JSTP2,JSTP3 C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) REAL CMOL,AMOL,ACHARG,CCHARG INTEGER LIC,NUMC,LIA,NUMA C C....CATION-ANION PAIR SUMMATION OVER BPRIME C SVC1 -0.0 DO 40 JCAT=1,NUMC DO 20 JAN -1,NUMA SVC1-SVC1 + AMOI(LIA(JAN))*CMOL(LIC(JCAT))*BPRIME(LIC(JCAT), LIA(JAN),ZIONST) 20 CONTINUE 40 CONTINUE C C....CATION-CATION SUMMATION OVER PHIPRIME C SVC2-0.0 DO 80 JC1-2,NUMC JSTP2- JC1 -1 DO 60 JC2-1,JSTP2 SVC2-SVC2 + CMOL(LIC(JC1))*CMOL(LIC(JC2))* PHIPRM(LIC(JC1),LIC(JC2),ZIONST,O) 60 CONTINUE 80 CONTINUE C C....ANION-ANION SUMMATION OVER PHIPRIME C SVC3-0.0 DO 120 JA1-2,NUMA JSTP3- JAI 1 DO 100 JA2-1,JSTP3 SVC3-SVC3 + AMOL(LIA(JA1))*AMOL(LIA(JA2))* PHIPRM(LIA(JA1),LIA(JA2),ZIONST,1) 100 CONTINUE 120 CONTINUE F-DH(ZIONST) + SVC1 + SVC2 + SVC3 190

RETURN END

C C....CALCULATTION OF IONIC STRENGTH ANDTHE PARAMETER ZC C SUBROUTINE IONZ(ZIONST,ZC) PARAMETER (NION - 15) C REAL ZIONST,ZC,ZSUM,XIONSUM C COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, 64AMOL(NION) REAL CMOL,AMOL,ACHARG,CCHARG INTEGER LIC,LIA,NUMC,NUMA C ZIONST-0.0 ZC-0.0 C C...SUMMING OVER ANIONS DO 20 IION-1,NUMA XIONSUM-AMOL(LIA(IION))*ACHARG(LIA(IION))*ACHARG(LIA(IION)) ZIONST-ZIONST+XIONSUM C C....ZC SUMMATION ZSUM-AMOL(LIA(IION))*ABS(ACHARG(LIA(IION))) ZC-ZC+ZSUM 20 CONTINUE C C....SUMMING OVER CATIONS DO 40 JION-1,NUMC XIONSUM-CMOL(LIC(JION))*CCHARG(LIC(JION))*CCHARC(LIC(JION)) ZIONST=ZIONST+XIONSUM ZSUM-CMOL(LIC(JION))*ABS(CCHARG(LIC(JION))) ZC -ZC +ZSUM 40 CONTINUE ZIONST-0.5*ZIONST RETURN END C C....FUNCTION GEE C FUNCTION GEE(XRAY) C REAL GEE,XRAY GEE-2.*(1.-(1.+XRAY)*EXP(-1.*XRAY))/(XRAY*XRAY) RETURN END C C....FUNCTION GPRIME C FUNCTION GPRIME(XRAY) 191

REAL GPRIME,XRAY GPRIME--2.*(1.-(1.+XRAY+0.5*XRAY*XRAY)*EXP(-1.*XRAY))/(XRAY &*XRAY) RETURN END C C....FUNCTION DH C CALCULATION OF THE DEBYE-HUCKEL TERM WHICH IS ONLY A FUNCTION OF C IONIC STRENGTH AND TEMPERATURE C FUNCTION DH(ZIONST) C REAL DH,ZIONST,DH1 C COMMON /DHTERM/ APHI,BEE REAL APHI,BEE C DH1-(SQRT(ZIONST)/(1.+BEE*SQRT(ZIONST)))+(2 /BEE)* &ALOG(1.+BEE*SORT(ZIONST)) DH--1.*APHI*DH1 RETURN END C C....FUNCTION CMX C FUNCTION CMX(ICATJAN) PARAMETER (NION - 15) C REAL CMX,XRAY INTEGER ICAT,IAN C COMMON /CHARGE/ ACHARG(NION),CCHARC(NION) COMMON /CPHI/ CFI(NION,NION) REAL ACHARG,CCHARG,CFI C XRAY- ABS(ACHARG(IAN)*CCHARG(ICAT)) CMX- CFI(ICAT,IAN)/(2.*SQRT(XRAY)) RETURN END C C....FUNCTION BMX C FUNCTION BMX(ICAT,IAN,ZIONST) PARAMETER (NION = 15) C REAL BMX,ZIONST,WHY,Y1,Y2,GEE INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHA1,ALPHA2 REAL BO,B1,B2,ALPHAO,ALPHA1,ALPHA2 192

INTEGER HOP C C....CHECK IF HIGHER ORDER PAIR C HOP- 0 NOT HIGHER ORDER PAIR C HOP- 1 HIGHER ORDER PAIR C IF(HOP(ICAT,IAN).EQ.0)THEN WHY-ALPHAO*SQRT(ZIONST) BMX -B0(ICAT,IAN) + Bl(ICAT,IAN)*GEE(WHY) RETURN ELSE Y1= ALPHAl*SQRT(ZIONST) Y2- ALPHA2*SQRT(ZIONST) BMX- BO(ICAT,IAN) + Bl(ICAT,IAN)*GEE(Y1) + BO(ICAT,IAN)* GEE(Y2) RETURN ENDIF END C C C C C.. FUNCTION BPRIME C FUNCTION BPRIME(ICAT,IAN,ZIONST) PARAMETER (NION - 15) C REAL BPRIME,ZIONST,XRAY,X1,X2,GPRIME INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHAL,ALPHA2 REAL BO,B1,B2,ALPHAO,ALPHA1,ALPHA2 INTEGER HOP C C....CHECK FOR HIGHER ORDER PAIRS C HOP - 0 NOT HIGHER ORDER PAIR C HOP - 1 HIGHER ORDER PAIR C IF(HOP(ICAT,IAN).EQ.0)THEN XRAY-ALPHAO * SQRT(ZIONST) BPRIME-B1(ICAT,IAN)*GPRIME(XRAY)/ZIONST RETURN ELSE Xl-ALPEA1 * SQRT(ZIONST) X2-ALPHA2 * SQRT(ZIONST) BPRIME-B1(ICAT,IAN)*GPRIME(X1)/ZIONST + B2(ICAT,IAN)*GPRIME(X2)/ZIONST RETURN ENDIF END C 193

C....FUNCTION PHI C C FUNCTION PHI(LI1,LI2,ZIONST,IONCA) PARAMETER (NION- 15) C REAL PHI,ZIONST,SUMO INTEGER LII,LI2,IONCA C COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /CHARGE/ACHARG(NION),CCHARC(NION) COMMON /DHTERM/ APHI,BEE REAL ATHETA,CTHETA,ACHARG,CCHARG,APHI,BEE C C....ROUTE TO CATION (IONCA-0)OR TO ANION (IONCA-1) C CALCULATIONS IF(IONCA.EQ.0) THEN XMN-6.*CCHARG(LI1)*CCHARC(LI2)*APHI*SQRT(ZIONST) XMM-6.*CCHARG(LI1)*CCHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*CCHARG(LI2)*CCHARC(LI2)*APHI*SORT(ZIONST) ZMN-CCHARC(LI1)*CCHARG(LI2) THET-CTHETA(LI1,L12) C C.. NOTE: PHI1 C IF THE TWO IONS OF INTEREST ARE OF THE SAMEMAGNITUDE C OF CHARGE, ETHETA AND ETHETAPRIME ARE ZERO. THIS CHECKS C FOR THIS CASE. SAME FOR ANIONS. C IF(CCHARG(LI1).EQ.CCHARG(LI2))THEN ETHETA-0.0 ELSE ETHETA-ZMN*(SUMO(XMN)-0.5*SUMO(XMM)-0.5*SUMO(XNN)) /(4.*ZIONST) ENDIF ELSE XMN-6.*ACHARC(LI1)*ACHARG(LI2)*APHI*SQRT(ZIONST) XMM-6.*ACHARG(LI1)*ACHARG(LI1)*APHI*SQRT(ZIONST) XNN-6.*ACHARG(LI2)*ACHARG(LI2)*APHI*SORT(ZIONST) ZMN-ACHARG(LI1)*ACHARG(LI2) THET-ATHETA(LI1,LI2) C C....SEE NOTE: PHI1 C IF(ACHARG(LI1).EQ.ACHARG(LI2))THEN ETHETA-0.0 ELSE ETHETA-ZMN*(SUMO(XMN)-0.5*SUMO(XMM)-0.5*SUMO(XNN)) /(4.*ZIONST) ENDIF ENDIF PHI-THET + ETHETA RETURN END 194

C C C C....FUNCTION SUMO C C..THE VALUES FOR THE J AND JPRIMEWERE EVALUATED OUTSIDEOF THE C PROGRAM AND THE VALUSE FIT TO APOLYNOMIAL OF THE FORM LNXVS C LNF(XRAY). THE INTERRGRALS WERE EVALUATEDUSING A ROMBERG C INTEGRATION ROUTINE FOUND IN THE IMSLLIBRARY. THE VALUES OF C THE INTEGRAL COMPARED WITH THOSEPRESENTED IN PITZERS THIRD PAPER C FUNCTION SUMO(XRAY) REAL XLN,XRAY,SUMLN,SUMO IF(XRAY.LT.2000.)THEN XLN- ALOG(XRAY) SUMLN = (-2.150403 + XLN*(1.378649+ XLN*(-0.0603501 + XLN*( & -0.7719421E-04 + XLN*(0.7749758E-03+ XLN*(0.2538732E-04 + & XLN*(-0.1589227E-04 + XLN*(-0.1884598E-06+ XLN*(0.2367578E-06 & + XLN*(-0.132147E-07)))))))))) SUMO - EXP(SUMLN) ELSE

SUMO - (.25 * XRAY) - 1.00 ENDIF RETURN END C C C C....FUNCTION PHIPRM C C FUNCTION PHIPRM(LI1,LI2,ZIONST,IONCA) PARAMETER (NION = 15) C REAL PHI,ZIONST,SUM1 INTEGER LI1,LI2,IONCA C COMMON /THETA/ATHETA(NION,NION),CTHETA(NION,NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /DHTERM/ APHI,BEE REAL ATHETA,CTHETA,ACHARG,CCHARG,APHI,BEE C C....ROUTE TO CATION (IONCA -0)OR TO ANION (IONCA-1) CALCULATIONS C IF(IONCA.EQ.0) THEN C C....SEE NOTE: PHI1 C IF(CCHARG(LI1).EQ.CCHARG(LI2))THEN PHIPRM =0.0 RETURN ENDIF XMN-6.*CCHARG(LI1)*CCHARG(LI2)*APHI*SORT(ZIONST) 195

XMM-6.*CCHARG(LI1)*CCHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*CCHARG(LI2)*CCHARG(LI2)*APHI*SQRT(ZIONST) ZMN-CCHARG(LI1)*CCHARG(LI2) THET-CTHETA(LI1,LI2) ELSE C C....SEE NOTE: PHI]. C IF(ACHARG(LI1).EQ.ACHARG(LI2))THEN PHIPRM-0.0 RETURN ENDIF XMN-6.*ACHARG(LI1)*ACHARC(LI2)*APHI*SQRT(ZIONST) XMM-6.*ACHARG(LI1)*ACHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*ACHARG(LI2)*ACHARG(LI2)*APHI*SORT(ZIONST) ZMN-ACHARG(LI1)*ACHARG(LI2) THET-ATHETA(LI1,LI2) ENDIF ETHETP-ZMN*(SUM1(XMN)-0.5*SUM1(XMM)-0.5*SUM1(XNN)) /(8.0*ZIONST*ZIONST) FRIPRM-ETHETP-(PHI(LI1,L12,ZIONST,IONCA)-THET)/ZIONST RETURN END C C C

C FUNCTION SUM1(XRAY) REAL XLN,XRAY,SUMLN,SUM1 IF(XRAY.LT.800.)THEN XLN ALOG(XRAY) SUMLN (-0.1829293E+01+XIN*(0.1291033E+01+XLN*(-0.64/10535E-01 & + XLN*(0.2021252E-02 + XLN*(0.1043347E-02 + XLN *( & -0.3247351E-04 + XLN*(-0.2225391E-04 + XIN*(0.9590904E-6 + & XLN*(0.2592198E-06 + XLN*(-0.1874422E-07)))))))))) SUM1 EXP(SUMLN) ELSE SUM1 - .25 * XRAY ENDIF RETURN END C C C FUNCTION WATRACT C C THIS FUNCTION CALCULATES THE ACTIVITY OF WATER IN AN C IONIC SOLUTION AT 25 DEGREES C. SEE HARVIE AND WEARE, GEOCHEMICA

C ET COSMOCHIMICA, VOL 44, PP 981 - 997, 1980. C FUNCTION WATRACT(ZIONST,ZC) PARAMETER (NION - 15) C 196

REAL WATRACT,DEBYHUK,SUMBC,SUMC,SUMA,ZIONST,ZC & ,WATRSUM,WATRERC,WATRLOG INTEGER IBC1,IBC2,ICLIC2,ICSTOP,IC3,IA1,IA2,IASTOP,IA3,IWTR

COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /DHTERM/ APHI, BEE COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) C REAL CMOL,AMOL,APHI,BEE,AACPSI,CCAPSI INTEGER NUMC,NUMA,LIC,LIA C CALCULATION OF THE DEBYE-HUCKEL TERM OF THEACTIVITY COEFFICIENT C DEBYHUK -2.0 * APHI* (ZIONST**1.5)/(1.+ BEE * SQRT(ZIONST)) C INITITALIZE SUMMATION VARIABLES TO ZERO

SUMBC-0.0 SUMC-0.0 SUMA-0,0 C SUMBC: SUM OVER ALL THE DIFFERENT PAIRS OFANOINS AND CATIONS, C WITH FIRST VIRIAL COEFFICIENT ANDMIXING COEFFIENT. C DO 40 IBCI-1, NUMC DO 20 IBC2-1, NUMA SUMBC SUMBC + CMOULIC(IBC1))*AMOL(LIA(IBC2))* (BRHI(LIC(IBC1),LIA(IBC2),ZIONST) + ZC *CMX(LIC(IBC1), LIA(IBC2))) 20 CONTINUE 40 CONTINUE SUMBC 2.0 * SUMBC C C SUNG: SUM OVER ALL DIFFERENT PAIRS OFCATIONS, AND WITH A THIRD C VIRAIL COEFFICIENT OVER ALL THEANIONS.

DO 100 IC1-1, NUMC

ICSTOP = IC1 - 1 DO 80 IC2-1, ICSTOP DO 60 IC3-1,NUMA SUMC SUMC + AMOL(LIA(IC3))*CCAPSI(LIC(IC1),LIC(IC2),LIA(IC3)) 60 CONTINUE SUMC SUMC + EHI(LIC(Ic1),LIC(Ic2),ZioNsT,O)+ ZIONST* PHIPRm(Lic(ic1),LIC(IC2),ziONsT,0) SUMC = SUMC * CMOL(LIC(IC1)) * CMOL(LIC(IC2)) 80 CONTINUE 100 CONTINUE C SUMA: SUM OVER ALL DIFFERNENT PAIRS OF ANIONS,WITH A THIRD VIRIAL COEFFICIENT OVER ALL THE CATIONS. C DO 160 IA1-1, NUMA 197

IASTOP - IA1 -1 DO 140 IA2-1, IASTOP DO 120 IA3-1, NUMC SUMA - SUMA + CMOL(LIC(IA3))*AACPSI(LIA(IA1),LIA(IA2),LIC(IA3)) 120 CONTINUE SUMA - SUMA + PHI(LIA(IA1),LIA(IA2),ZIONST,1) + ZIONST* PHIPRM(LIA(IA1),LIA(IA2),ZIONST,1) SUMA SUMA * AMOL(LIA(IA1)) * AMOL(LIA(IA2)) 140 CONTINUE 160 CONTINUE C C....THIS CALCULATES THE MOLE FRACTION OF WATER IN THE SYSTEM C USED IN CALCULATING THE ACTIVITY OF THE WATER. C WATRSUM = 0.0 DO 180 IWTR=1, NUMC WATRSUM = WATRSUM + CMOL(IWTR) 180 CONTINUE DO 200 IWTR=1, NUMA WATRSUM = WATRSUM + AMOL(IWTR) 200 CONTINUE WATRFRC = (55.555 / (55.555 + WATRSUM)) WATRLOG-LOG(WATRFRC)-((DEBYHUK+SUMBC +(2 *SUMC) + (2 *SUMA)) & /55.555) C C CALCULATION OF THE ACTIVITY COEFFICIENT OF WATER C WATRACT = EXP(WATRLOG) RETURN END C C C FUNCTION BPHI C C THIS FUNCTION CALCULATES THE SECOND VIRIAL COEFFICIENT FOR THE C ACTIVITY COEFFICIENT OF WATER. C FUNCTION BPHI(ICAT,IAN,ZIONST) PARAMETER (NION - 15)

REAL ZIONST,SQION,BPHI INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),131(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHA1,ALPHA2 REAL BO,B1,B2,ALPHAO,ALPHA1,ALPHA2 INTEGER HOP C C CALCULATE THE SQUREROOT OF THE IONIC STRENGTH SQION SQRT(ZIONST) C 198

C CHECK IF HIGHER ORDER PAIR C HOP - 0 NOT HIGHER ORDER PAIR C HOP - 1 HIGHER ORDER PAIR C IF(HOP(ICATJAN),EQ.0) THEN BPHI - BO(ICAT,IAN) + B1(ICAT,IAN)*EXP(-1.*ALPHAO*SOION) RETURN ELSE BPHI-B0(ICATJAN) + Bl(ICATJAN)*EXP(-1.*ALPHAl*SOION) + B2(ICATJAN)*EXP(-1.*ALPHA2*SOION) RETURN ENDIF END 199

APPENDIX F

ISIS DATABASE FILES

CHDATA

CHEMISTRY DATA FILE FOR LASL GEOCHEMISTRY SCALING PROGRAM. SHOULD BE ON FILE NAMED CHDATA. REPORTED VALUES (CHDATA1) LAST UPDATE: 05/23/87: DATA FROM ROBIE, HARVIE AND WEARE, 2345678901234567890123456789012345678901234567890123456789012345678 1 AR(G) 1 0.0 0.0 0.0 1 1 1.0 8 1 O. O. O. O. 2 NA+(AQ) 2 1.0 4.0 0.0 2 1 1.0 1 2 1.056475E+02 O. O. O. 3 CL-(AQ) 2-1.0 3.0 0.0 3 1 1.0 2 3 5.295285E+01 O. O. 0. 4 CO3--(AQ) 2-2.0 4.5 0.0 4 1 1.0 4 4 2.129490E+02 O. O. 0. 5 CA++(AQ) 2 2.0 6.0 0.0 5 1 1.0 5 5 2.232919E+02 O. O. 0. 6 H+(AQ) 2 1.0 9.0 0.0 6 1 1.0 6 6 O. O. O. O. 7 OH-(AQ) 2-1.0 3.5 0.0 7 1 1.0 7 7 6.346436E+01 O. O. O. 8 HCO3-(AQ) 2-1.0 4.5 0.0 8 2 1.0 4 1,0 6 8 2.367287E+02 O. O. O. 9 H20(L) 2 0.0 0.0 0.0 9 2 1.0 6 1.0 7 9 9.566003E+01 O. O. O. 10 SI02(AMOR) 3 0.0 0.0 2.0 10 1 1.0 3 10 -3.431060E+02 O. O. 0. 10 .005000 .20000 60.08480 .005000 11 CASIO3(S) 3 0.0 0.0 3.0 11 3 1.0 3 1.0 5 2.0 7 11 -6.252136E+02 O. O. 11 .060000 .25000116.16420 .005000 12 CAC03(S) 3 0.0 0.0 0.0 12 2 1.0 4 1.0 5 12 -4.553623E+02 O. O. 12 .050000 .25000100.08935 .005000 13 CA2SI04(S) 3 0.00.0 4.0 13 3 1.0 3 2.0 5 4.0 7 200

13 -8.873683E+02 0. 0. 0. 13 .070000 .25000172.24360 .005000 14 MG++(AQ) 2 2.0 8.0 0.0 14 1 1.0 9 14 -1.834613E+02 0. 0. 0. 15 CAMG(CO3)2 3 0.0 0.00.0 15 3 2.0 4 1.0 5 1.0 9 15 -8.719944E+02 0. 0. 0. 15 .070000 .25000184.41070 .005000 16 MGC03(S) 3 0.0 0.00.0 16 2 1.0 4 1.0 9 16 -4.152808E+02 0. 0. 0. 16 .070000 .25000 84.32135 .005000 17 ZN++(AQ) 2 2.0 6.0 0.0 17 1 1.0 10 17 -5.940304E+01 0. 0. 0. 18 CO2(G) 1 0.0 0.0 1.0 18 2 1.0 4 2.0 6 18 -1.590865E+02 0. 0. 0. 19 FE++(AQ) 2 2.0 6.0 0.0 0.0 19 1 1.0 11 19 -3.181528E+01 0. 0. 0. 20 FE+++(AQ) 2 3.0 9.0 0.0 -1.0 20 1 1.0 11 20 -1.855590E+00 0. 0. 0. 21 CU+(AQ) 2 1.0 4.0 0.0 0.0 21 1 1.0 12 21 2.016944E+01 0. 0. 0. 22 CU++(AQ) 2 2.0 6.0 0.0 -1.0 22 1 1.0 12 22 2.643004E+01 0. 0. 0. 23 AG+(AQ) 2 1.0 2.5 0.0 0.0 23 1 1.0 13 23 3.109200E+01 0. 0. 0. 24 AG(S) 3 0.0 0.0 0.0 1.0 24 1 1.0 13 24 0. 0. 0. 0. 24 4.100000 10.50000107.90000 .005000 25 CU(S) 3 0.0 0.0 0.0 1.0 25 1 1.0 12 25 0. 0. 0. 0. 25 3.930000 8.96000 63.50000 .005000 26 PB++(AQ) 2 2.0 4.5 0.0 0.0 26 1 1.0 14 26 -9.842690E+00 0. 0. 0. 27 FE203(S) 3 0.0 0.0 3.0 -2.0 27 2 6.0 7 2.0 11 27 -2.995900E+02 0. 0. 0 27 .070000 .25000159.70000 .005000 28 FE304(S) 3 0.0 0.0 4.0 -2.0 28 2 8.0 7 3.0 11 28 -4.084578E+02 0. 0. 0. 28 .070000 .25000231.50000 .005000 201

29 ZNC03(S) 3 0.0 0.0 0.0 0.0 29 2 1.0 4 1.0 10 29 -2.950709E+02 0. 0. 0. 29 .070000 .25000125.38000 .005000 30 PBC03(S) 3 0.0 0.0 0.0 0.0 30 2 1.0 4 1.0 14 30 -2.522540E+02 0. 0. 0. 30 .070000 .25000267.20000 .005000 31 FEC03(S) 3 0.0 0.0 0.0 0.0 31 2 1.0 4 1.0 11 31 -2.689385E+02 0. 0. 0. 31 .070000 .25000115.86000 .005000 32 K+(AQ) 2 1.0 3.0 0.0 0.0 32 1 1.0 15 32 -1.139533E+02 0. 0. 0. 33 MN++(AQ) 2 2.0 6.0 0.0 0.0 33 1 1.0 16 33 -9.197266E+01 0. 0. 0. 34 SO4--(AQ) 2-2.0 4.3 0.0 0.0 34 1 1.0 17 34 -3.003754E+02 0. 0. 0. 35 BA++(AQ) 2 2.0 5.0 0.0 0.0 35 1 1.0 18 35 -2.261963E+02 0. 0. 0. 36 BASO4(S) 3 0.0 0.0 0.0 0.0 36 2 1.0 17 1.0 18 36 -5.494906E+02 0. 0. 0. 36 .070000 .25000233.40200 .005000 37 CASO4(S) 3 0.0 0.0 0.0 0.0 37 2 1.0 5 1.0 17 37 -5.331574E+02 0. 0. 0. 37 .070000 .25000136.14200 .005000 38 CACL2.6H20 3 0.0 0.0 0.0 0.0 38 4 1.0 5 2.0 2 6.0 6 6.0 7 38 -8.936500E+02 0. 0. 0. 38 .070000 1.68 219.09 .005000 39 K2SO4(S) 3 0.0 0.0 0.0 0.0 39 2 2.0 15 1.0 17 39 -5.323900E+02 0. 0. 0. 39 .070000 2.662 174.25 .005000 40 MGCL2.6H20 3 0.0 0.0 0.0 0.0 40 4 1.0 9 2.0 2 6.0 6 6.0 7 40 -8.531000E+02 0. 0. 0. 40 .070000 1.56 203.33 .005000 41 NA2MGS0424W 3 0.0 0.0 0.0 0.0 41 5 2.0 1 1.0 9 2.0 17 4.0 6 4.0 7 41 -1.383600E+03 0. 0. 0. 41 .070000 2.23 334.48 .005000 42 KMGCL3.6H20 3 0.0 0.0 0.0 0.0 42 5 3.0 2 1.0 9 6.0 6 6.0 7 1.0 15 42 -1.020300E+03 0. 0. 0. 42 .070000 1.61 277.86 .005000 43 MGS04.7H20 3 0.0 0.0 0.0 0.0 202

43 4 1.0 9 1.0 17 7.0 7 7.0 6 43 -1.157830E+03 0. 0. 0. 43 .070000 1.68 246.49 .005000 44 NA2K6(SO4)4 3 0.00.0 0.0 0.0 44 3 4.0 17 6.0 15 2.0 1 44 -2.114100E+03 0. 0. 0. 44 .070000 2.7 664.84 .005000 45 NA2CA(SO4)2 3 0.0 0.0 0.00.0 45 3 2.0 17 1.0 5 2.0 1 45 -1.047600E+03 0. 0. 0. 45 .070000 2.64 278.17 .005000 46 CASO4.2H20 3 0.0 0.0 0.00.0 46 4 2.0 7 1.0 17 1.0 5 2.0 6 46 -7.249692E+02 0. 0. 0. 46 .070000 2.32 172.17 .005000 47 NACL(S) 3 0.0 0.0 0.0 0.0 47 2 1.0 1 1.0 2 47 -1.549868E+02 0. 0. 0. 47 .070000 2.165 58.44 .005000 48 MGS04.6H20 3 0.0 0.0 0.0 0.0 48 46.0 7 1.0 17 6.0 6 1.0 9 48 -1.061600E+03 0. 0. 0. 48 .070000 1.68 228.46 .005000 49 MGS04.H20 3 0.0 0.0 0.0 0.0 49 4 1.0 7 1.0 17 1.0 9 1.0 6 49 -5.798000E+02 0. 0. 0. 49 .070000 2.445 138.39 .005000 50 KMGCLS04.3W 3 0.0 0.0 0.0 0.0 50 6 3.0 7 1.0 17 3.0 6 1.0 2 1.0 9 1.015 50 -9.382000E+02 0. 0. 0. 50 .070000 2.131 248.98 .005000 51 NA4CAS0432W 3 0.0 0.0 0.0 0.0 51 5 2.0 7 3.0 17 2.0 6 4.0 1 1.0 5 51 -1.751600E+03 0. 0. 0. 51 .070000 2.6 474.23 .005000 52 MGSO4.4H20 3 0.0 0.0 0.0 0.0 52 4 4.0 7 1.0 17 4.0 6 1.0 9 52 -8.685500E+02 0. 0. 0. 52 .070000 2. 192.44 .005000 53 K2MGS042.4W 3 0.0 0.0 0.0 0.0 53 5 4.0 7 2.0 17 4.0 6 1.0 9 2.0 15 53 -1.403970E+03 0. 0. 0. 53 .070000 1.49 366.70 .005000 54 NA2SO4.10W 3 0.0 0.0 0.0 0.0 54 4 10.0 7 1.0 17 10.0 6 2.0 1 54 -1.471150E+03 0. 0. 0. 54 .070000 1.464 322.19 .005000 55 MGSO4.5H20 3 0.0 0.0 0.0 0.0 55 4 5.0 7 1.0 17 5.0 6 1.0 9 55 9.651300E+02 0. 0. 0. 55 .070000 2. 210.45 .005000 56 K2MGCA2S044 3 0.0 0.0 0.0 0.0 56 6 2.0 7 4.0 17 2.0 6 1.0 5 1.0 9 2.015 203

56 -2.282800E+03 O. 0. O. 56 .070000 2.775 602.95 .005000 57 K2MGS042.6W 3 0.0 0.0 0.0 0.0 57 5 6.0 7 2.0 17 6.0 6 1.0 9 2.0 15 57 -1.596100E+03 O. O. O. 57 .070000 2.15 402.73 .005000 58 KCL(S) 3 0.0 0.0 0.0 0.0 58 2 1.0 2 1.0 15 58 -1.648061E+02 O. O. O. 58 .070000 1.984 74.56 .005000 59 K2CAS042.6W 3 0.0 0.0 0.0 0.0 59 5 6.0 7 2.0 17 6.0 6 1.0 5 2.0 15 59 -1.164800E+03 O. O. O. 59 .070000 2.6 418.47 .005000 60 MG2CACL612W 3 0.0 0.0 0.0 0.0 60 5 6.0 2 1.0 5 12.0 6 12.0 7 2.0 9 60 -2.015900E+03 O. O. O. 60 .070000 2. 517.59 .005000 61 NA2(s04) 3 0.0 0.0 0.0 0.0 61 2 2.0 1 1.0 17 61 -5.122978E+02 O. O. O. 61 .070000 2.68 142.04 .005000 62 MGCL2(S) 3 0.0 0.00.0 0.0 62 2 2.0 2 1.0 9 62 -2.387194E+02 O. O. O. 62 .070000 2.32 95.22 .005000

CONDATA

12345678901234567890123456789012345678901234567890123456789 14 5 62 AR(G) 1 9 1 NA+(AQ) 2 1 1 CL -(AQ) 3 2 1 CO3 -2(AQ) 4 2 2 CA +2(AQ) 5 1 2 H+(AQ) 6 1 3 OH-(AQ) 7 2 3 HCO3-(AQ) 8 2 4 H20(L) 9 4 1 SI02(AMOR) 10 9 2 CASIO3(S) 11 9 3 cAc03(s) 12 9 4 CA2SIO4(S) 13 9 5 MC-1-2(AQ) 14 1 4 CAMC(CO3)2 15 9 6 MGC03(S) 16 9 7 ZN +2(AQ) 17 1 5 CO2(G) 18 9 8 FE+2(AQ) 19 1 6 FE+3(AQ) 20 1 7 CU +(AQ) 21 1 8 204

CU+2(AQ) 22 1 9 AG+(AQ) 23 1 10 AG(S) 24 9 9 CU(S) 25 9 10 PB+2(AQ) 26 1 11 FE203(S) 27 9 11 FE304(S) 28 9 12 ZNC03(S) 29 9 13 PBC03(S) 30 9 14 FEC03(S) 31 9 15 K+(AQ) 32 1 12 MN+2(AQ) 33 1 13 804-2(AQ) 34 2 5 BA+2(AQ) 35 1 14 BASO4(S) 36 9 16 CASO4(S) 37 9 17 CACL2.6H20 38 9 18 K2504(S) 39 9 19 MGCL2.6H20 40 9 20 NA2MGS0424 41 9 21 KMGCL3.6W 42 9 22 MGSO4.7H20 43 9 23 NA2K6SO4)4 44 9 24 NA2CASO4)2 45 9 25 CASO4.2H20 46 9 26 NACL(S) 47 9 27 MGSO4.6H20 48 9 28 MGSO4.H20 49 9 29 KMGCLSO43W 50 9 30 NA4CASO42W 51 9 31 MGS04.4H20 52 9 32 K2MGS0424W 53 9 33 NA2SO4.10W 54 9 34 MGSO4.5H20 55 9 35 K2MGCA2SO4 56 9 36 K2MGS0426W 57 9 37 KCL(S) 58 9 38 K2CAS0426W 59 9 39 MG2CACL612 60 9 40 NA2SO4(S) 61 9 41 MGCL2(S) 62 9 42

PITDATA

1234567890123456789012345678901234567890123456789012345678901234567890 1 NA+ 1.0 1 CL-1 -1.0 0.0765000 0.2664000 0.0000000 0.00127000 2 CO3-2 -2.0 0.1897500 0.8460000 0.0000000 -0.04347400 3 OH-1 -1.0 0.0864000 0.2530000 0.0000000 0.00440000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 SO4-2 -2.0 0.0195800 1.1130000 0.0000000 0.00497000 2 CA+2 2.0 205

1CL-1 -1.0 0.3159400 1.6140000 0.0000000 -0.00034300 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3OH-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5304-2 -2.0 0.2000000 2.6500000 -57.7000000 0.00000001 3H+1 1.0 1CL-1 -1.0 0.1775000 0.2945000 0.0000000 0.00080000 2CO3-2 -2.01001.00000001001.0000000 0.00000001001.00000000 3011-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 804-2 -2.01001.00000001001.0000000 0.00000001001.00000000 4 MG+2 2.0 1CL-1 -1.0 0.3523500 1.6815000 0.0000000 0.00519000 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3011-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5SO4 -2 -2.0 0.2210000 3.3430000 -37.2500000 0.02500001 5ZN+2 2.0 1CL-1 -1.0 0.2601750 1.6425000 0.0000000 -0.08798200 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3OH-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5304-2 -2.0 0.1949000 2.8830000 -32.8100000 0.02900001 6FE+2 2.0 1CL-1 -1.0 0.3359250 1.5322500 0.0000000 -0.00860700 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3011-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5804-2 -2.01001.00000001001.00000001001.00000001001.00000001 7FE+3 3.0 1CL-1 -1.01001.00000001001.0000000 0.00000001001.00000000 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3011-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5804-2 -2.01001.00000001001.00000001001.00000001001.00000001 8CU+1 1.0 1CL-1 -1.01001.00000001001.0000000 0.00000001001.00000000 2CO3-2 -2.01001.00000001001.0000000 0.00000001001.00000000 3OH-1 -1.01001.00000001001.0000000 0.00000001001.00000000 411c03- -1.01001.00000001001.0000000 0.00000001001.00000000 5804-2 -2.01001.00000001001.0000000 0.00000001001.00000000 9CU+2 2.0 1CL-1 -1.0 0.2966000 1.3910000 0.0000000 -0.03602000 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 3011-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5 804-2 -2.0 0.2340000 2.5270000 -48.3300000 0.00440001 10 AG+1 1.0 1CL-1 -1.01001.00000001001.0000000 0.00000001001.00000000 2CO3-2 -2.01001.00000001001.0000000 0.00000001001.00000000 3OH-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5804-2 -2.01001.00000001001.0000000 0.00000001001.00000000 206

11PB+2 2.0 1CL-1 -1.01001.00000001001.0000000 0.00000001001.00000000 2 CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 301-i-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5804-2 -2.01001.00000001001.00000001001.00000001001.00000001 12K+1 1.0 1CL-1 -1.0 0.0483500 0.2122000 0.0000000 -0.00084000 2CO3-2 -2.0 0.2669000 0.0000000 0.0000000 -0.01870000 3011-1 -1.0 0.1298000 0.3200000 0.0000000 0.00410000 4H003- -1.0 0.0689000 0.0000000 0.0000000 0.00840000 5304-2 -2.0 0.0499500 0.7792500 0.00000001001.00000000 13MN+2 2.0 1CL-1 -1.0 0,3272300 1,5503000 0.0000000 -0,01855200 2CO3-2 -2.01001.00000001001.00000001001.00000001001.00000001 301-1-1 -1.01001.00000001001.0000000 0.00000001001.00000000 4 HCO3- -1.01001.00000001001.0000000 0.00000001001.00000000 5304-2 -2.0 0.2010000 0.29800001001.0000000 0.01820001 14BA+2 2.0 1CL-1 -1.0 0.2628000 1.4962500 0.0000000 -0.01753900 2003-2 -2.01001.00000001001.00000001001.00000001001.00000001 3OH-1 -1.0 0.1717500 1.2000000 0.00000001001.00000000 4H003- -1.01001.00000001001.0000000 0.00000001001.00000000 5304-2 -2.01001.00000001001.00000001001.00000001001.00000001 123456789012345678901234567890123456789012345678901234567890123456789 1 NA+1 2 CA+2 0.0700000 0.0140000 1001.0000000 1001.0000000 1001.0000000 -0.0230000 1 NA+1 3 H+1 0.0360000 0.0040000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 4 MG+2 0.0700000 -0.0120000 1001.0000000 1001.0000000 1001.0000000 -0.0150000 1 NA+1 5 ZN+2 0.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 6 FE+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 7 FE+3 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 1 NA+1 9 CU+2 0.0000000 -0.0140000 1001.0000000 1001.0000000 1001.0000000 -0.0110000 1 NA+1 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 11 P8+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 12 K+1 -0.0120000 -0.0018000 1001.0000000 1001.0000000 1001.0000000 -0.0100000 1 NA+1 13 MN+2 0.0000000 -0.0030000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1 NA+1 14 BA+2 -0.0030000 0.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 2 CA+2 3 11+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 207

2 CA+2 4 MG+2 0.0070000 -0.0120000 1001.00000001001.0000000 1001.0000000 0.0500000 2 CA+2 5 ZN+2 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 2 CA+2 6 FE+2 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 2 CA+2 7 FE+3 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 2 CA+2 8 CU+1 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 2 CA+2 9 CU+2 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 1001.0000000 2 CA+2 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 2 CA+2 11 PB+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 2 CA+2 12 K+1 0.0320000 -0.0250000 1001.0000000 1001.0000000 1001.0000000 0.0000000 2 CA+2 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 2 CA+2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 4 MG+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 5 ZN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 6 FE+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 7 FE+3 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 9 CU+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 11 PB+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 12 K+1 0.0050000 -0.0070000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 13 MN+2 0.0000000 0.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 3 H+1 14 BA+2 -0.0360000 0.0240000 1001.0000000 1001.0000000 1001.00000001001.0000000 4 MG+2 5 ZN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 4 MG+2 6 FE+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 4 MG+2 7 FE+3 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 4 MG+2 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.00000001001.0000000 1001.0000000 4 MG+2 9CU+2 1001.0000000 208

1001.0000000 1001,0000000 1001.0000000 1001.0000000 1001.0000000 4 MG+2 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 4 MG+2 11 P3+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 4 MG+2 12 1(+1 0.0000000 -0.0220000 1001.0000000 1001.0000000 1001.0000000 -0.0480000 4 MG+2 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 4 MG+2 14 3A+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 6 FE+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 7 FE+3 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 9 CU+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 S ZN+2 11 P3+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 2N+2 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 5 ZN+2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 7 FE+3 1001.0000000 1001.0000000 1.001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 9 CU+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 11 P3+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 6 FE+2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE+3 8 CU+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE+3 9 CU+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE+3 10 AG+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE+3 11 P3+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 209

7 FE+3 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE+3 13 MN +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 7 FE +3 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 cu+1 9 CU +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 cu+1 10 AG +1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 CU +1 11 T3+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 CU +1 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 cu+1 13 MN +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 8 cu+1 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 9 cu+2 10 AG +1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 9 CU +2 11 PB +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 9 CU +2 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 9 cu+2 13 MN +2 1001,0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 9 CU +2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 10 AG +1 11 PB +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 10 Ac+1 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 10 AG+1 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 10 AG+1 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 11 13)3+2 12 K+1 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 11 PB+2 13 MN+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 11 PB+2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 12 K+1 13 MN +2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 12 K+1 14 BA+2 -0.0720000 0.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 13 MN +2 14 BA+2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 123456789012345678901234567890123456789012345678901234567890123456789 1 CL-1 2 CO3-2 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001.0000000 1001,0000000 1001.0000000 1001.0000000 210

1CL-1 3OH-1 -0.0500000 -0.00600001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.0000000 -0.00800001001.00000001001.00000001001.0000000 1CL-1 4 HCO3- 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1CL-1 5SO4-2 0.0200000 0.0014000 0.00000001001.0000000 -0.00400001001.0000000 1001.00000001001.00000001001.0000000 0.04300001001.0000000 1001.0000000 0.00000001001.00000001001.00000001001.0000000 2CO3-2 3OH-1 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 2CO3-2 4HCO3- 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 2CO3-2 5804-2 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 3OH-1 4 HCO3- 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 3OH-1 5SO4 -2 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 4HCO3-1 5SO4-2 1001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 1001.00000001001.00000001001.00000001001.00000001001.0000000 123456789012345678901234567890123456789012345678901234567890123456789 ALPHA 2.0000000 ALPHA1 1.4000000 ALPHA2 12.0000000 APHI 0.3920000 1.2000000 211

APPENDIX G

PITZER SOURCE CODE

C....PITZER IS FOR THE PREDICTION OF THE ACTIVITYCOEFFICIENTS C USING PITZERS METHOD. THE FORM USED WAS TAKEN FROM HARVIE AND C WEARE. THE PROGRAM WAS WRITTEN BY BARRY KELLY AT OREGONSTATE C UNIVERSITY IN PARTIAL REQUIREMENTS OF HIS MASTERSTHESIS. C 07/19/87 C C PROGRAM PITZER PARAMETER (ND-40) COMMON /ADDN/ AH20,G(ND),XI,NLK(ND),AMT(ND) COMMON /OUT/ ISPC(ND) REAL AH20,G,XI,AMT INTEGER NLK,IDUM(ND),ISPC CHARACTER*10 PNAME(ND),FNAME,FNAME2 C C....OPEN FILES FOR OUTPUT AND INPUT WRITE(*,*) 'SPECIFY INPUT FILE NAME' READ(*,8001) FNAME2 OPEN(6,FILE=FNAME2,STATUS='OLD') OPEN(30,FILE-'PITOUT',STATUS-'NEW) OPEN(31,FILE-'FITCON',STATUS='NEW) WRITE(*,*) 'SPECIFY OUTPUT FILE NAME' READ(*,8001) FNAME 8001 FORMAT(A) OPEN(32,FILE=FNAME,STATUS-'NEW') C C....INITIALIZE VARIABLES DO 10 1=1,40 IDUM(I) =1000 NLK(I)=1000 AMT(I)=1000. G(I) =1000. ISPC(I)=1000 10 CONTINUE C C....READ IN DATA ON SYSTEM OF INTEREST READ(6,*) NSPCS DO 20 I-1,NSPCS READ(6,*) PNAME(I),IDUM(I),AMT(I) 20 CONTINUE READ(6,*) TEMP C C....SET NLK NUMBERS C DO 30 I-1,NSPCS NLK(I) = I 30 CONTINUE 212

CALL GAMSET(NSPCS,TEMP,IDUM) CALL GAMMA(NSPCS,TEMP) C C... WRITE THE RESULTS TO OUTPUT FILE WRITE(32,9001) 9001 FORMAT(/6X,'SPECIES',6X,'ID1,6X,'MOLALITY',6X,'ACTIVITY', 1 7X,'ACTIVITY',/17X,'NUMBER',17X,'COEFFICIENT',//) DO 40 J-1,NSPCS IF(ISPC(J).EQ.9)THEN WRITE(32,9002) PNAME(J),IDUM(J) 9002 FORMAT(5X,A10,3X,I3,5X,'SPECIES NOT IN SOLUTION') ENDIF IF(ISPC(J).EQ.4000)THEN WRITE(32,9003) PNAME(J),IDUM(J),G(J) 9003 FORMAT(5X,A10,3X,I3,35X,E11.5) ENDIF IF(ISPC(J).GE.1000.AND.ISPC(J).LT.3000)THEN WRITE(32,9004) PNAME(J),IDUM(J),AMT(J),G(J) 9004 FORMAT(5X,A10,3X,I3,4X,E11.5,4X,E11.5) ENDIF 40 CONTINUE WRITE(32,*) 'IONIC STRENGTH = ',XI CLOSE(30) CLOSE(31) CLOSE(32) STOP END C C.... SUBROUTINE GAMSET C C SUBROUTINE GAMSET(NSPCS,TEMP,IDUM) PARAMETER (ND=40, NION =15) C COMMON /ADDN/ AH20,C(40),XI,NLK(40),AMT(40) COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, AMOL(NION) COMMON /NUM/ NUMC1,NUMAT,NCM,NAM COMMON /ADSWTCH/ ICANBR(ND) C REAL TEMP,G,AH20,XI,CMOL,AMOL,ACTH20 INTEGER NSPCS,IDUM(ND),NLK,LIC,NUMC,LIA,NUMA,NUMC1,NUMA1, & NCM,NAM,ICANBR C C..THIS SUBROUTINE SETS THE DATABASE UP FOR THE C ACTIVITY COEFFICIENT CALCULATIONS. CONDATA WILL CONVERT THE C OVERALL SPECIES NUMBER, IDUM, TO INFORMATION AS TO TYPE OF C SPECIES AND LOCATION OF ION INTERACTION DATA. PITDATA WILL GO C TO THE MAIN DATABASE AND GET THE ION INTERACTION COEFFICIENTS C FOR THE CHARGED SPECIES, AND PLACE THEM IN THE COMMON BLOCKS FOR C THE CALCULATION OF THE ACTIVITY COEFFICIENTS. DATAWT SIMPLY SENDS C INFORMATION GATHERED TO TWO FILES, THE FIRST GIVING WHAT VALUES 213

C WERE USED IN THE CALCULATION OF THE ACTIVITY COEFFICIENTS,THE C OTHER GIVING WHICH ION INTERACTIONPARAMETERS WERE MISSING AND C ASSUMED TO BE ZERO. C CALL CONDATA (NSPCS,IDUM,NLK,ICANBR) CALL PITDATA (TEMP) CALL DATAWT C C....THE NUMBER OF CATIONS,AND ANIONS SPECIES IN SOLUTION C ARE PLACED IN THE SYSTEM COMMONBLOCKS C NUMC NCM NUMA = NAM AH20 - 1.0 RETURN END C SUBROUTINE GAMMA C C....THIS SUBROUTINE CALCULATESTHE ACTIVITY COEFFICIENT OFTHE C AQUEOUS SPECIES IN THE PROBLEM. THE ACTIVITIES ARE CALCULATED C PITZER'S METHOD. C SUBROUTINE GAMMA(NSPCS,TEMP) PARAMETER (ND-40, NION=15) C COMMON /ADDN/ AH20,G(40),XI,NLK(40),AMT(40) C COMMON /SYSTEM/LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, & AMOL(NION) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM COMMON /ADSWTCH/ ICANBR(ND) C REAL TEMP,G,AH20,XI,CMOL,AMOL,CATACT(NION),ANACT(NION), & ACTH2O,ZIONST,ZC INTEGER NSPCS,IDUM(ND),NLK,LIC,NUMC,LIA,NUMA,NUMC1,NUMA1, & NCM,NAM,ICANBR

C INITIALIZE ACTIVITY COEFFICIENTTERMS DO 20 IPITG-1, NION CATACT(IPITG) - 1. ANACT(IPITG) = I. 20 CONTINUE DO 40 IPITG-1, ND G(IPITG) = I. 40 CONTINUE ACTH2O - 1. C C..THE FIRST CALL TO SWITCH PLACES THE VALUES OF THE AMOUNTS,AMT, C AND THE OTHER SYSTEM VARIABLES IN THE PROPER COMMON BLOCKSFOR C THE ACTIVITY COEFFICEINTCALCULATIONS. THE ACTIVITY COEFFICIENTS C ARE THEN CALCULATED, AND THENSWITCH IS CALLED AGAIN TO PUT 214

C THE PROPER COEFFICIENT WITH THE CORRECT G(IPITG) VALUE. C CALL SWITCH ( NSPCS, ICANBR,CATACT,ANACT,ACTH2O) CALL ACTIVY (ZIONST,ZC,CATACT,ANACT) XI = ZIONST ACTH2O = WATRACT (ZIONST,ZC) CALL SWITCH (NSPCS,ICANBR,CATACT,ANACT,ACTH20) RETURN END C UBROUTINE SWITCH C C....THIS SUBROUTINE SEPARATES THE CATIONS, ANIONS, C AND DIFFERENT PHASE SPECIES AND PLACES THE INFORMATION ABOUT C IN THE PROPER VARIABLE NAMES FOR THE CALCULATIONS, ALSO IT C PLACES THE CORRECT ACTIVITY COEFFICIENT WITH THE PROPER G(I) C VALUE. C SUBROUTINE SWITCH (NSPCS,ICANBR,CATACT,ANACT,ACTH20) PARAMETER (ND=40, NION-15) C COMMON /OUT/ ISPC(ND) COMMON /ADDN/ AH20,e(40),XI,NLK(40),AMT(40) COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, & AMOL(NION) REAL CATACT(NION),ANACT(NION),ACTH20,AMT,AH20,G,XI, & H20,XMOL,CMOL,AMOL INTEGER NSPCS,ICANBR(ND),NLK,LIC,NUMC,LIA,NUMA,ISPC C C....COUNTERS INTIIALIZED JVN = 0 J2 = 0 C C..ICANBR IS SET UP IN CONDATA TO HAVE THE THOUSANDS PLACE INDICATE C WHETHER THE SPECIES IS AN CATION, ANION, NEUTRAL SPECIES, OR C DIFFERENT PHASE. THE REST OF THE NUMBER IS FOR WHICH ANION, OR C CATION IT IS WHETHER NUMBER 1 OR NUMBER 2, AND SO ON. C THE NUMBERING WAS SET UP LIKE THIS: C 1XXXIS A CATION, RELATIVE NUMBER XXX C 2XXX IS A ANION, RELATIVE NUMBER XXX C 4000 IS WATER C 9 IS A SPECIES NOT IN SOLUTION, AND NOT OF CONCERN TO ACTIVITY C CALCULATIONS. C DO 20 ISWITCH=1, NSPCS ISPC(ISWITCH) = ICANBR(NLK(ISWITCH)) IF(ISPC(ISWITCH).EQ.9) THEN G(ISWITCH) = 1. ENDIF IF(ISPC(ISWITCH).GE 1000.AND.ISPC(ISWITCH).LT.2000) THEN JVN = JVN + 1

LIC(JVN) = ISPC(ISWITCH) - 1000 CMOL(LIC(JVN)) = AMT(ISWITCH) 215

G(ISWITCH) = CATACT(LIC(JVN)) ENDIF IF(ISPC(ISWITCH).GE.2000.AND.ISPC(ISWITCH).LT.3000) THEN J2 J2 + 1 LIA(J2) = ISPC(ISWITCH)- 2000 AMOL(LIA(J2)) - AMT(ISWITCH) G(ISWITCH) = ANACT(LIA(J2)) ENDIF IF(ISPC(ISWITCH).EQ.4000) THEN G(ISWITCH) - ACTH2O AH20 - ACTH2O ENDIF 20 CONTINUE RETURN END C C C SUBROUTINE CONDATA(NSPCS,IDUM,NLK,ICANBR) PARAMETER (ND = 40) C C. THIS SUBROUTINE CONVERTS THE INPUT OF SENECA2 INTO A FORM USED C IN THE PITZER EQUATIONS. IT COMPARES THE SPECIES IN THE SYSTEM C WITH A LIST WHICH WILL TELL IF THE SPECIES IS A CATION, ANION OR C OTHER SPECIES. IT KEEPS TRACK OF THE NUMBERS OF EACH OF THESE, C AND ALSO GIVES THE ADDRESSES IN PIT DATA FOR THE INFORMATION C NEEDED IN THE PITZER EQUAITONS. C C C COMMON /ADDRESS/ KANUM(ND), KCATNUM(ND) COMMON /NUM/ NUMC1,NUMAI,NCM,NAM C C INTEGER NSPCS,IDUM(ND),NLK(ND),KANUM,KCATNUM,NUMC1,NUMA1, & NCM,NAM,LIDSP,JCATAN,IADD,LCON,JCON,ICANBR(ND) C OPEN(26,FILE=1CONDATA',FORM='FORMATTED',ACCESS-.SEQUENTIAL', &STATUS = 'OLD') REWIND(26) C C....READ IN THE NUMBER OF DATA AVIALABLE FOR CATIONS, AND ANIONS C SPECIES. ALSO, READ IN THE SUM OF THESE VALUES, N. C READ(26,8001) NUMC1,NUMA1,NTIRE 8001 FORMAT(/,3I10) C C....INITIALIZE VARIABLE COUNTERS AND ARRAYS OF DATA C NCM = 0 NAM - 0 DO 20 LCON-1,ND ICANBR(LCON) = 0 216

KCATNUM(LCON) = 0 KANUM(LCON) 0 20 CONTINUE C C..READ IN DATA LINE, CHECK IF IT IS IN SYSTEMAND IF IT IS WHETHER C IT IS A CATION, ANION, OR SOLID SPECIES, OR NONEOF THESE. C PLACE IN ADDRESS RELATIVE TO NLK AND SAVE DATA ADDRESSFOR C FINDING PITZER COEFFICIENTS. C DO 60 LCON=1,NTIRE READ(26,8002) LIDSP,JCATAN,IADD 8002 FORMAT(1OX,3110) C C....THE VALUES ARE READ IN FROM THE FILE, AND THENDETERMINED C TO BE EITHER CATION, ANION, OR SOLID SPECIES. THEY ARE C ASSIGNED A 1000, 2000, OR 9 NUMBER PLUS THE NUMBEROF C SPECIES THEY WERE. THIS IS DONE SO WHEN THE ORDER OF THE C COMPONENTS IS CHANGED THE IONIC SPECIES CAN STILL BERECOGNIZED C RELATIVE TO THE PARAMETER NLK. THE WATER VALUE IS ALSO FOUND C AND GIVEN A ICANBR OF 4000. C DO 40 JCON=1,NSPCS IF(IDUM(JCON).EQ.LIDSP)THEN IF(JCATAN.EQ.9)THEN ICANBR(NLK(JCON)) = 9 ELSE IF(JCATAN.EQ.1)THEN NCM NCM + 1 ICANBR(NLK(JCON)) = 1000 + NCM KCATNUM(NCM) = IADD ENDIF IF(JCATAN.EQ.2)THEN NAM - NAM + 1 ICANBR(NLK(JCON)) - 2000 NAM KANUM(NAM) = IADD ENDIF IF(JCATAN.EQ.4)THEN ICANBR(NLK(JCON)) = 4000 ENDIF ENDIF ENDIF 40 CONTINUE GO CONTINUE CLOSE(26) C C WRITE(*,8003) C 8003 FORMAT(//5X,'END OF CONDATA FILE',//) C RETURN END C C SUBROUTINE PITDATA 217

SUBROUTINE PITDATA(TEMP) PARAMETER (ND - 40,NION - 15) COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /CPHI/ CFI(NION,NION) COMMON /DHTERM/ APHI,BEE COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /ALFA/ ALPHAO,ALPHA1,ALPHA2 COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) COMMON /NAME/ ANNAME(NION),CATNAME(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /ADDRESS/ KANUM(ND),KCATNUM(ND) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM C C....DECLARATION OF VARIABLE TYPES REAL BO,B1,132,CFI,ATHETA,CTHETA,AACPSI,CCAPSI,ACHARG,CCHARG, ALPHAO,ALPHA1,ALPHA2,ANTHET,BA,BB,BC,CATHET,CH,CP, TEMP,VAL(5),ZAP,BEE INTEGER HOP,KANUM,KCATNUM,NUMG1,NUMA1,NCM,NAM,LPIT,LI1, IDOWNC(NION),IHOP,LINA(NION),LINC(NION), IDOWNA(NION),IOLDA(NION),IOLDC(NION),IOLDS,ITA,ITOT,JPIT, JUNO,J2,JA,JB,JC,JD,JSKIP,KAY,MN1,MN2,NEXT,NEXTA, NSKIPA,NSKIPC,NUMA3,NUMC3,IANUM,ISKFLG CHARACTER*9 ANNAME,CATNAME CHARACTER*9 ANAM C C....INTIALIZE THE STORAGE ARRAYS TOZERO DO 10 JPIT-1,NION ANNAME(JPIT)= 'BLANK' CATNAME(JPIT)= 'BLANK' ACHARG(JPIT)=0.0 CCHARG(JPIT)=0.0 10 CONTINUE DO 40 JPIT-1,NION DO 20 LPIT=1,NION BO(JPIT,LPIT)-0.0 B1(JPIT,LPIT)-0.0 B2(JPIT,LPIT)=0.0 CFI(JPIT,LPIT)-0.0 HOP(JPIT,LPIT)-0 CTHETA(JPIT,LPIT)=0.0 ATHETA(JPIT,LPIT)-0.0 20 CONTINUE 40 CONTINUE DO 100 KAY=1,NION DO 80 JPIT-1,NION DO 60 LPIT=1,NION AACPSI(KAY,JPIT,LPIT)=0.0 CCAPSI(KAY,JPIT,LPIT)=0.0 60 CONTINUE 80 CONTINUE 100 CONTINUE C 218

C..CALL SORTING ROUTINE. THIS SORTING ROUTINE WILL PUT THE VALUES C IN ASCENDING ORDER WHILE KEEPING TRACK OF THERE ORIGINAL POSITION C IN THE CALL. THIS IS DONE FOR A SPEED-UP IN THE SEARCH TIME AS C THE SYSTEMS AND DATABASES ENLARGED. C CALL SORT(KANUM,NAM,NUMA1,IOLDA,NSKIPA,IDOWNA,LINA) CALL SORT(KCATNUM,MCM,NUMC1,IOLDC,NSKIPC,IDOWNC,LINC) C OPEN(27,FILE-'PITDATA',STATUS-10LD') REWIND(27) C C..THIS SECTION READS A LINE FROM THE DATABASE AND COMPARES IT WITH C THE CURRENT CATION, IF THEY MATCH, THEN A STEP THROUGH THE ANIONS C TO FILL THE CATION-ANION INTERACTION TERMS. IF THEY DO NOT MATCH C BLANK SPACES ARE READ TILL THE NEXT CATION LINE IS READ. C READ(27,8005) 8005 FORMAT(8X) NEXT - 1 DO 140 LPIT-1, NUMC1 READ(27,8010) NUMAGE,ANAM,ZAP 8010 FORMAT(I3,A9,F5.1) IF(NUMAGE.EQ.KCATNUM(NEXT))THEN CATNAME(IOLDC(NEXT)) = ANAM CCHARG(IOLDC(NEXT)) - ZAP NEXTA = 1 DO 120 JPIT-1, NUMA1 READ(27,8020) IANUM ,ANAM,CH,BA,BB,BC,CPHII,IHOP 8020 FORMAT(I3,A9,F5.1,4F13.7,12) IF(IANUM.EQ.KANUM(NEXTA))THEN ANNAME(IOLDA(NEXTA)) = ANAM ACHARG(IOLDA(NEXTA)) - CH B0(IOLDC(NEXT),IOLDA(NEXTA)) = BA B1(IOLDC(NEXT),IOLDA(NEXTA)) - BB B2(IOLDC(NEXT),IOLDA(NEXTA)) = BC CFI(IOLDC(NEXT),IOLDA(NEXTA)) = CPHI1 HOP(IOLDC(NEXT),IOLDA(NEXTA)) - IHOP NEXTA NEXTA + 1 ENDIF 120 CONTINUE NEXT - NEXT + 1 ELSE DO 130 LI1-1, NUMA1 READ(27,8030) 8030 FORMAT(5X) 130 CONTINUE ENDIF 140 CONTINUE C C....FIND CCAPSI VALUES IN DATABASE C C....SET SEARCH LENGTH PARAMETER 219

READ(27,8005) NUMC3 = (NUMC1*(NUMC1 1))/2 DO 280 LPIT-1, NUMC3 ISKFLG 0 READ(27,8040) MNI,MN2,CATHET 8040 FORMAT(I13,13X,I13,13X,F13.7) C C....GOES THROUGH ALL CATIONS INTHE SYSTEM DO 240 JUNO=1, NCM C C....CHECK FIRST TERM IN CCAPSI IF(MN1.EQ.KCATNUM(JUNO))THEN DO 220 J2-1, NCM C C.,..CHECK SECOND TERM IF(MN2.EQ.KCATNUM(J2))THEN C C....PLACING VALUE IN BOTH SIDES OFTHE SYMMETRIC MATRIX ISKFLG = 1 CTHETAGOLDC(JUNO),IOLDC(J2)) CATHET CTHETA(IOLDC(J2),IOLDC(JUNO)) CATHET IOLDS = 0 DO 180 JA-1, NAM C C. CHECK TO SEE IF THIS VALUE IS ON THE SAME LINE AS PREVIOUSVALUE C IF NOT, CALCULATE HOW MANY LINESTO SKIP AND READ IN NECESSARY C LINE. IF(IOLDS.NE.IDOWNA(JA))THEN ITA = IDOWNA(JA) IOLDS IOLDS = IDOWNA(JA) DO 160 JB-1, ITA READ(27,8050)(VAL(JC),JC-1,5) 160 CONTINUE 8050 FORMAT(5F13.7) ENDIF C C....PLACE VALUE IN BOTH SIDES OFTHE MATRIX CCAPSI(IOLDC(JUNO),IOLDC(J2),IOLDA(JA))= VAL(LINA(JA)) CCAPSI(IOLDC(J2),IOLDC(JUNO),IOLDA(JA))= VAL(LINA(JA)) 180 CONTINUE C C....CALCULATE THE REMAINING NUMBEROF LINES TO SKIP BEFORE THE NEXT C CATION - CATION LINE, AND THENSKIP THEM IF(NSKIPA.NE.IOLDS)THEN ITOT = NSKIPA IOLDS DO 200 JD-1, ITOT READ(27,8030) 200 CONTINUE ENDIF ENDIF 220 CONTINUE ENDIF 240 CONTINUE 220

IF(ISKFLG.EQ.0)THEN DO 260 JSKIP-1, NSKIPA READ(27,8030) 260 CONTINUE ENDIF 280 CONTINUE C C....FIND AACPSI VALUES INDATABASE MATIRIX C FOR EXPLAINATION SEE SECTIONON CCAPSI SEARCH C READ(27,8005) NUMA3 (NUMA1*(NUMA1 -1))/2 DO 420 LPIT=1, NUMA3 ISKFLG 0 READ(27,8040) MN1,MN2,ANTHET DO 380 JUNO-1, NAM IF(MN1.EQ.KANUM(JUNO))THEN DO 360 J2-1, NAM IF(MN2.EQ.KANUM(J2))THEN ISKFLG 1 ATHETA(IOLDA(JUNO),IOLDA(J2)) ANTHET ATHETA(IOLDA(J2),IOLDA(JUNO)) ANTHET IOLDS = 0 DO 320 JA-1,NCM IF(IOLDS.NE.IDOWNC(JA))THEN ITA = IDOWNC(JA)- IOLDS IOLDS = IDOWNC(JA) DO 300 JB-1, ITA READ(27,8050)(VAL(JC),JC-1,5) 300 CONTINUE ENDIF AACPSI(IOLDA(JUNO),IOLDA(J2),IOLDC(JA)) VAL(LINC(JA)) AACPSI(IOLDA(J2),IOLDA(JUNO),IOLDC(JA))e VAL(LINC(JA)) 320 CONTINUE IF(NSKIPC.NE.IOLDS)THEN ITOT - NSKIPC- IOLDS DO 340 JD=1, ITOT READ(27,8030) 340 CONTINUE ENDIF ENDIF 360 CONTINUE ENDIF 380 CONTINUE IF(ISKFLG.EQ.0)THEN DO 400 JSKIP=1,NSKIPC READ(27,8030) 400 CONTINUE ENDIF 420 CONTINUE C C....READ IN ALPHA'S, APHI, AND B C 221

READ(27,8005) READ(27,8060) ALPHAO READ(27,8060) ALPHAl READ(27,8060) ALPHA 2 READ(27,8060) APHI READ(27,8060) BEE 8060 FORMAT(13X,F13.7) CLOSE(27) C C WRITE(6,8070) C 8070 FORMAT(//5X,'END OF COLLECTINGPITZER DATA. NOW BEGINNING TO', C & 'CHECK VALUES FOR MISSING DATA',//) C RETURN END C SUBROUTINE SORT(IVEC,NUMSKL,NUMT,IOLD,NSKIP,IDOWN,IN) C C..THIS SUBROUTINE MAKES SURE THAT THEVALUES ARE IN ASCENDING ORDER, C AND WILL KEEP TRACE OF THE ORIGINALADDRESSES IN THE MATRIX IOLD. C ALSO, THIS SUBROUTINE WILL CALCULATETHE NUMBER OF LINES THAT C CAN BE SKIPPED IN IN THE TRIPLEINTERACTION PARAMETER SECTION IF C NEEDED, OR WHERE IN THE DATA BLOCKRESIDES THE VALUE NEEDED. C C VARIABLE TYPE DESCRIPTION C C .LSOR INTEGER-I COUNTER C IPLUS I START VALUE ON ORDERING VALUES C JSOR I COUNTER C NUMSKL STOP VALUE C IVEC(X) I THE ORIGINAL VECTOR TO BE SORTED AND C VALUE LOCATED C IHAND I DUMMY VARIABLE C IOLD(X) I THE ORIGINAL ADDRESS OF THE VALUE C IVEC(X) BEFORE SORTING C XLIN R CALL LINE IN DATA BLOCK C IHOLD I PART OF CALC IN DATA BLOCK C PLUS R VALUE TO DETERMINE IF END OF LINE C IDOWN(X) I NUMBER OF LINES TO SKIP IN DATA BLOCK C IN(X) I WHICH VALUE IN THE DATA BLOCK OF FIVE C NSKIP I TOTAL LINES TO BE SKIPPED IF NOT A C ION OF INTEREST IN DATA BLOCK C NUMT I TOTAL NUMBER OF IONS OF THAT TYPE IN C DATABASE, SO NSKIP CAN BE CALCULATED C C C REAL XLIN,PLUS INTEGER LSOR,IPLUS,JSOR,NUMSKL,IVEC(NUMSKL),IHAND,IOLD(NUMSKL), & IN(NUMSKL),NSKIP,NUMT,IDOWN(NUMSKL),IHOLD C C....INITIALIZE VECTORS THAT ARE FIRST USED IN THIS SUBROUTINE C 222

DO 10 LSOR-1, NUMSKL IOLD(LSOR) = LSOR IDOWN(LSOR) 0 IN(LSOR) = 0 10 CONTINUE C....SORT VALUES OF IVEC KEEPING TRACK OF ORIGINAL ADDRESSIN IOLD C DO 30 LSOR-1,NUMSKL-1 IPLUS LSOR + 1 DO 20 JSOR-IPLUS, NUMSKL IF(IVEC(JSOR).LT.IVEC(LSOR))THEN IHAND = IVEC(JSOR) IVEC(JSOR) = IVEC(LSOR) IVEC(LSOR) IHAND IHAND = IOLD(LSOR) IOLD(LSOR) = IOLD(JSOR) IOLD(JSOR) F IHAND ENDIF 20 CONTINUE 30 CONTINUE C C....CALCULATE LOCATION OF VALUE IN IVEC C DO 40 LSOR-1, NUMSKL XLIN = REAL(IVEC(LSOR))/5. IHOLD INT(XLIN) PLUS = XLIN REAL(IHOLD) IF(PLUS.EQ.0.00000)THEN IDOWN(LSOR) = IHOLD IN(LSOR) - 5 ELSE IDOWN(LSOR) = IHOLD + 1 IN(LSOR) = INT(5.1*PLUS) ENDIF 40 CONTINUE C C....CALCULATE NUMBER OF LINES TO BE SKIPPED IF ION NOT OFINTEREST C XLIN = REAL(NUMT)/5. IHOLD INT(XLIN) PLUS = XLIN REAL(IHOLD) IF(PLUS.EQ.0.00000)THEN NSKIP IHOLD ELSE NSKIP = IHOLD + 1 ENDIF RETURN END C C C SUBROUTINE DATAWT PARAMETER (NION = 15) 223

COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), HOP(NION,NION) COMMON /CPHI/ CFI(NION,NION) COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) COMMON /NAME/ ANNAME(NION),CATNAME(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /NUM/ NUMC1,NUMA1,NCM,NAM REAL BO,B1,132,CFI,ATHETA,CTHETA,AACPSI,CCAPSI,ACHARG,CCHARG INTEGER HOP,NUMC1,NUMA1,NCM,NAM,LWT,JWT,KAY CHARACTER*9 ANNAME,CATNAME C C FILE 30 HAS WHICH CONSTANTS ARE MISSING AND SET TO ZERO C FILE 31 HAS THE VALUES FOR THE CONSTANTS USED IN THE PROGRAM C WRITE(30,8010)

8010 FORMAT(//5X,'NO DATA WAS AVAILABLE FOR THE FOLLOWING ION ', &'INTERACTION CONSTANTS:',/5X,'MISSING VALUES ARE SET TO ZERO', & //) WRITE(31,8020) 8020 FORMAT(//5X,'DATA USED IN ACTIVITY COEFFICIENT PREDICTION', &//2X,'CATION',3X,'CHARGE',2X,'ANION',5X,'CHARGE',4X,'BO',

C C....A CHECK TO SEE IF THE VALUE 1001 WAS READ FROM THE INPUTFILE. C IF IT WAS THE CONSTANT IS UNKNOWN, AND SET TO ZERO AND RECORDED C ON THE FILE PITOUT. IF THE VALUE IS NOT 1001, THEN IT WRITTEN C TO THE FILE PITCON. DO 40 LWT-1,NCM DO 20 JWT-1,NAM IF(BO(LWT,JWT).EQ.1001.) & BO(LWT,JWT)=FIX1('BO ',CATNAME(LWT),ANNAME(JWT)) IF(B1(LWT,JWT).EQ.1001.) & B1(LWT,JWT)=FIX1('Bl ',CATNAME(LWT),ANNAME(JWT)) IF(B2(LWT,JWT).EQ.1001.) & B2(LWT,JWT)=FIX1('B2 ',CATNAME(LWT),ANNAME(JWT)) IF(CFI(LWT,JWT).EQ.1001.) & CFI(LWT,JWT)=FIX1CCFI ',CATNAME(LWT),ANNAME(JWT)) WRITE(31,8030)CATNAME(LWT),CCHARG(LWT),ANNAME(JWT),ACHARG(JWT), & BO(LWT,JWT),B1(LWT,JWT),B2(LWT,JWT),HOP(LWT,JWT),CFI(LMT,JWT) 8030 FORMAT(/2X,A9,1X,F5.0,1X,A9,1X,F5.0,3(2X,F8.4),2X,I2,2X,F8.6) 20 CONTINUE 40 CONTINUE WRITE(31,8040) 8040 FORMAT(//2X,76('-'),//) C G. HERE THE CATION-CATION INTERACTION PARAMETERS ARE CHECKED FOR C FOR MISSING VALUES, ALONG WITH THE CCAPSI VALUES. THE CHECK C VALUE OF 1001 WAS USED HERE ALSO FOR MISSING DATA. C DO 100 LWT-1,NCM NSTART = LWT + 1 DO 80 JWT-NSTART,NCM 224

IF(CTHETA(LWT,JWT).EQ.1001.)THEN CTHETA(LWT,JWT) = FIX1('CTHETA',CATNAME(LWT),CATNAME(JWT)) CTHETA(JWT,LWT) = FIX1CCTHETA',CATNAME(JWT),CATNAME(LWT)) ENDIF WRITE(31,8050) 8050 FORMAT(/5X,'CTHETA') WRITE(31,8060) CATNAME(LWT),CATNAME(JWT),CTHETA(LWT,JWT) WRITE(31,8060) CATNAME( JWT),CATNAME(LWT),CTHETA(JWT,LWT) 8060 FORMAT(5X,A9,2X,A9,' ',F13.8) WRITE(31,8070) 8070 FORMAT(5X,'CCAPSI VALUES FOR CATION PAIR ABOVE AND ANIONS:') DO 60 KAY-1, NAM IF(CCAPSI(LWT,JWT,KAY).EQ.1001.) THEN CCAPSI(LWT,JWT,KAY)= FIX1AUCCAPSI',CATNAME(LUT), CATNAME(JWT),ANNAME(KAY)) CCAPSI(JWT,LWT,KAY)= FIX1A('CCAPSI',CATNAME(JWT), CATNAME(LWT),ANNAME(KAY)) ENDIF WRITE(31,8080) ANNAME(KAY), CCAPSI(LWT,JWT,KAY) 8080 FORMAT(5X,A9,' ',F13.8) 60 CONTINUE 80 CONTINUE 100 CONTINUE C C....THIS SECTION TESTS ATHETA, AND AACPSI VALUES FOR MISSINGDATA C IN THE SAME WAY AS FOR CTHETA AND CCAPSI. C DO 160 LWT=1,NAM NSTART LWT + 1 DO 140 JWT-NSTART,NAM IF(ATHETA(LWT,JWT).EQ.1001.)THEN ATHETA(LWT,JWT) = FIX1('ATHETA',ANNAME(LWT),ANNAME(JWT)) ATHETA(JWT,LWT) = FIX1CATHETAI,ANNAME(JWT),ANNAME(LWT)) ENDIF WRITE(31,8090) 8090 FORMAT(/5X,'ATHETA') WRITE(31,8060) ANNAME(LWT),ANNAME(JWT),ATHETA(LWT,JWT) WRITE(31,8060) ANNAME(JWT),ANNAME(LWT),ATHETA(JWT,LWT) WRITE(31,8100) 8100 FORMAT(5X,'AACPSI VALUES FOR ANION PAIR ABOVE AND CATION:') DO 120 KAY-1, NCM IF(AACPSI(LWT,JWT,KAY).EQ.1001.) THEN AACPSI(LWT,JWT,KAY)- FIX1A('AACPSI', ANNAME(LWT),ANNAME(JWT),CATNAME(KAY)) AACPSI(JWT,LWT,KAY) FIX1A('AACPSI', ANNAME(JWT),ANNAME(LWT),CATNAME(KAY)) ENDIF WRITE(31,8080) CATNAME(KAY), AACPSI(LWT,JWT,KAY) 120 CONTINUE 140 CONTINUE 160 CONTINUE RETURN END 225

C C FUNCTION FIX 1 C FUNCTION FIX1(ID,ID1,ID2) CHARACTER*9 ID1,ID2 CHARACTER*6 ID WRITE(30,8010) ID,ID1,ID2 8010 FORMAT(5X,A6,2(A9)) FIX1 - 0.0 RETURN END C C FUNCTION FIX1 A C FUNCTION FIX1A(ID,ID1,ID2,ID3) CHARACTER*9 ID1,1D2,1D3 CHARACTER*6 ID WRITE(30,8010) ID,ID1,ID2,ID3 8010 FORMAT(5X,A6,3(A9)) FIX1A - 0.0 RETURN END C C....SUBROUTINE ACTIVY C SUBROUTINE ACTIVY(ZIONST,ZC,CATACT,ANACT) PARAMETER (NION = 15) REAL ZIONST,ZC,FT,F,CT,GAMCAT,GAMAN,CATACT(NION),ANACT(NION) INTEGER ICNTC,ICNTA,NCAT,NAN C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) REAL CMOL,AMOL,ACHARG,CCHARG INTEGER LIC,NUMC,LIA,NUMA C C....COMMON CALCULATIONS C CALL IONZ(ZIONST,ZC) CALL CTERM(CT) FT= F(ZIONST) C C....CATION ACTIVITIES CALCULATED C DO 20 ICNTC-1,NUMC NCAT= LIC(ICNTC) GAMCAT-CCHARG(NCAT)*CCHARG(NCAT)*FT + VC(NCAT,O,ZIONST,ZC) + ABS(CCHARG(NCAT))*CT CATACT(NCAT)=EXP(GAMCAT) 20 CONTINUE C C....ANION ACTIVITIES CALCULATED C 226

DO 40 ICNTA=1,NUMA NAN=LIA(ICNTA) CAMAN-ACHARC(NAN)*ACHARG(NAN)*FT + VC(NAN,1,ZIONST,ZC)+ ABS(ACHARG(NAN))*CT ANACT(NAN)= EXP(GAMAN) 40 CONTINUE RETURN END C C C....FUNCTION VC C C FUNCTION VC(ION,IONCA,ZIONST,ZC) PARAMETER (NION = 15) C REAL ZIONST,2C,SK1,SK2,SK3,SK4,VC INTEGER ION,IONCA,K1,K2,K3,KALKA2,KC1,KC2 C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /PSI/ AACPSI(NION,NION,NION),CCAPSI(NION,NION,NION) REAL CMOL,AMOL,AACPSI,CCAPSI INTEGER LIC,LIA,NUMC,NUMA C C..CHECK F FROM ANION OR CATION CALCULATIONS. IONCA - 0 FOR CATION IF(IONCA.EQ.0)THEN SK10.0 DO 20 K1=1,NUMA SK1-SK1 + AMOL(LIA(K1))*(2.0*BMX(ION,LIA(K1),ZIONST)+ ZC*CMX(ION,LIA(K1))) 20 CONTINUE SK2-0.0 DO 60 K2=1,NUMC SK3=0.0 DO 40 K3-1,NUMA SK3-SK3 + AMOL(LIA(K3))*CCAPSI(ION,LIC(K2),LIA(K3)) 40 CONTINUE SK2-SK2 + CMOL(LIC(K2))*(2.0*PHI(ION,LIC(K2),ZIONST,O)+SK3) 60 CONTINUE SK4-0.0 DO 100 KAI-1,NUMA KSTP =KA1 -1 DO 80 KA2-1,KSTP SK4-SK4 + AMOL(LIA(KA1))*AMOL(LIA(KA2))* AACPSI(LIA(KA1),LIA(KA2),ION) 80 CONTINUE 100 CONTINUE ELSE SK1-0.0 DO 120 K1=1,NUMC + CMOL(LIC(K1))*(2.0*BMX(LIC(K1),ION,ZIONST)+ ZC*CMX(LIC(K1),ION)) 227

120 CONTINUE SK2-0.0 DO 160 K2=1,NUMA SK3-0.0 DO 140 K3=1,NUMC SK3 =SK3 + CMOL(LIC(K3))*AACPSI(ION,LIA(K2),LIC(K3)) 140 CONTINUE SK2-SK2 + AMOL(LIA(K2))*(2.0*PHI(ION,LIA(K2),ZIONsT,1)+ SK3) 160 CONTINUE SK4-0.0 DO 200 KC1-2,NUMC KSTP -KC1 -1 DO 180 KC2-1,KSTP SK4-SK4 + CMOL(LIC(KC1))*CMOL(LIC(KC2))* CCAPSI(LIC(KC1),LIC(KC2),ION) 180 CONTINUE 200 CONTINUE ENDIF VC-SK1 + SK2 + SK4 RETURN END

C C....SUBROUTINE CTERM C SUBROUTINE CTERM(CT) PARAMETER (NION = 15) C REAL CT INTEGER LCC,LCA C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) REAL CMOL,AMOL INTEGER LIC,NUMC,LIA,NUMA C CT=0.0 DO 40 LCC=1,NUMC DO 20 LCA=1,NUMA CT= CT + CMOL( LIC( LCC)) *AMOL(LIA(LCA)) *CMX(LIC(LCC), LIA(LCA)) 20 CONTINUE 40 CONTINUE RETURN END C C C C....FUNCTION F C FUNCTION F(ZIONST) PARAMETER (NION = 15) REAL ZIONST,SVC1,SVC2,BPRIME,PHIPRM,SVC3,F 228

INTEGER JCAT,JAN,JC1,JC2,JA1,JA2, JSTP2,JSTP3

COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) REAL CMOL,AMOL,ACHARG,CCHARC INTEGER LIC,NUMC,LIA,NUMA C C....CATION-ANION PAIR SUMMATION OVER BPRIME C SVC1-0.0 DO 40 JCAT-1,NUMC DO 20 JAN-1,NUMA SVC1-SVC1 + AMOL(LIA(JAN))*CMOL(LIC(JCAT))*BPRIME(LIC(JCAT), LIA(JAN),ZIONST) 20 CONTINUE 40 CONTINUE C C. .CATION-CATION SUMMATION OVER PHIPRIME C SVC2-0.0 DO 80 JC1-2,NUMC JSTP2= JC1 1 DO 60 JC2-1,JSTP2 SVC2-SVC2 + CMOL(LIC(JC1))*CMOL(LIC(JC2))* PHIPRM(LIC(JC1),LIC(JC2),ZIONST,O) 60 CONTINUE 80 CONTINUE C C,_,ANION-ANION SUMMATION OVER PHIPRIME C SVC3-0.0 DO 120 JA1-2,NUMA JSTP3- JA1 -1 DO 100 JA2-1,JSTP3 SVC3-SVC3 + AMOL(LIA(JA1))*AMOL(LIA(JA2))* PHIPRM(LIA(JA1),LIA(JA2),ZIONST,1) 100 CONTINUE 120 CONTINUE F =DH(ZIONST) + SVC1 + SVC2 + SVC3 RETURN END

C C....CALCULATTION OF IONIC STRENGTH AND THE PARAMETER ZC C SUBROUTINE IONZ(ZIONST,ZC) PARAMETER (NION = 15) C REAL ZIONST,ZC,ZSUM,XIONSUM C COMMON /CHARGE/ ACHARC(NION),CCHARG(NION) 229

COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) REAL CMOL,AMOL,ACHARG,CCHARG INTEGER LIC,LIA,NUMC,NUMA C ZIONST-0.0 ZC-0.0 C G....SUMMING OVER ANIONS DO 20 IION-1,NUMA XIONSUM-AMOL(LIA(IION))*ACHARG(LIA(IION))*ACHARG(LIA(IION)) ZIONST-ZIONST+XIONSUM C C....ZC SUMMATION ZSUM-AMOL(LIA(IION))*ABS(ACHARG(LIA(IION))) ZC=ZC+ZSUM 20 CONTINUE C C....SUMMING OVER CATIONS DO 40 JION-1,NUMC XIONSUM=CMOL(LIC(JION))*CCHARG(LIC(JION))*CCHARG(LIC(JION)) ZIONST-ZIONST+XIONSUM ZSUM-010L(LIG(JION))*ABS(CCHARG(LIC(JION))) ZC=ZC+ZSUM 40 CONTINUE ZIONST=0.5*ZIONST RETURN END C C....FUNCTION GEE C FUNCTION GEE(XRAY) C REAL GEE,XRAY GEE=2.*(1.-(1.+XRAY)*EXP(-1.*XRAY))/(XRAY*XRAY) RETURN END C C....FUNCTION GPRIME C FUNCTION GPRIME(XRAY) C REAL GPRIME,XRAY GPRIME--2.*(1.-(1.+XRAY+0.5*XRAY*XRAY)*EXP(-1.*XRAY))/(XRAY &*XRAY) RETURN END C C.. FUNCTION DH C CALCULATION OF THE DEBYE-HUCKEL TERM WHICH IS ONLYA FUNCTION OF C IONIC STRENGTH AND TEMPERATURE

FUNCTION DH(Z1ONST) 230

REAL DH,ZIONST,DH1

COMMON /DHTERM/ APHI,BEE REAL APHI,BEE C DH1-(SORT(ZIONST)/(1.+BEE*SORT(ZIONST)))+(2./BEE)* &ALOG(1.+BEE*SQRT(ZIONST)) DH =- 1. *APHI *DH1 RETURN END C C....FUNCTION CMX C FUNCTION CMX(ICAT,IAN) PARAMETER (NION - 15) C REAL CMX,XRAY INTEGER ICAT,IAN C COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /CPHI/ CFI(NION,NION) REAL ACHARG,CCHARG,CFI C XRAY= ABS(ACHARG(IAN)*CCHARC(ICAT)) CMX- CFI(ICAT,IAN)/(2.*SQRT(XRAY)) RETURN END C C....FUNCTION BMX C FUNCTION BMX(ICAT,IAN,ZIONST) PARAMETER (NION - 15) C REAL BMX,ZIONST,WHY,Y1,Y2,GEE INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHALALPRA2 REAL BO,B1,B2,ALPHAO,ALPHA1,ALPHA2 INTEGER HOP C C....CHECK IF HIGHER ORDER PAIR C HOP= 0 NOT HIGHER ORDER PAIR C HOP- 1 HIGHER ORDER PAIR C IF(HOP(ICAT,IAN).EQ.0)THEN WHY-ALPHAO*SQRT(ZIONST) BMX-130(ICATJAN) + Bl(ICATJAN)*GEE(WHY) RETURN ELSE Yl- ALPHAl*SORT(ZIONST) 231

Y2- ALPHA2*SQRT(ZIONST) BMX- BO(ICAT,IAN) + B1(ICATJAN)*GEE(Y1)+ B2(ICAT,IAN)* GEE(Y2) RETURN ENDIF END C C C C C....FUNCTION BPRIME C FUNCTION BPRIME(ICAT,IAN,ZIONST) PARAMETER (NION 15) C REAL BPRIME, ZIONST,XRAY,X1,X2,GPRIME INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHA1,ALPHA2 REAL BO,B1,B2,ALPHAO,ALPHALALPRA2 INTEGER HOP C C....CHECK FOR HIGHER ORDER PAIRS C HOP = 0 NOT HIGHER ORDER PAIR C HOP = 1 HIGHER ORDER PAIR C IF(HOP(ICAT,IAN).EQ.0)THEN XRAY=ALPHAO * SQRT(ZIONST) BPRIME=B1(ICAT,IAN)*GPRIME(XRAY)/ZIONST RETURN ELSE X1-ALPRA1 * SQRT(ZIONST) X2=ALPHA2 * SQRT(ZIONST) BPRIME=B1(ICAT,IAN)*GPRIME(X1)/ZIONST + B2(ICAT,IAN)*GPRIME(X2)/ZIONST RETURN ENDIF END C C.. ..FUNCTION PHI C C FUNCTION PHI(LI1,LI2,ZIONST,IONCA) PARAMETER (NION = 15) C REAL PHI,ZIONST,SUMO INTEGER LI1,LI2,IONCA C COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /DHTERM/ APR1,BEE 232

REAL ATHETA,CTHETA,ACHARG,CCHARG,APHI,BEE C C....ROUTE TO CATION (IONCA-0) OR TO ANION (IONCA-1) CALCULATIONS C IF(IONCA.EQ.0) THEN XMN-6.*CCHARG(LI1)*CCHARG(LI2)*APHI*SORT(ZIONST) XMM=6.*CCHARG(LI1)*CCHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*CCHARG(LI2)*CCHARG(LI2)*APHI*SORT(ZIONST) ZMN=CCHARG(LI1)*CCHARG(LI2) THET-CTHETA(LI1,LI2) C C....NOTE: PHIL C IF THE TWO IONS OF INTEREST ARE OF THE SAME MAGNITUDE C OF CHARGE, ETHETA AND ETHETAPRIME ARE ZERO. THIS CHECKS C FOR THIS CASE. SAME FOR ANIONS. C IF(CCHARG(LI1).EQ.CCHARG(LI2))THEN ETHETA=0.0 ELSE ETHETA=ZMN*(SUMO(XMN)-0.5*SUMO(XMM)-0.5*SUMO(XNN)) /(4.*ZIONST) ENDIF ELSE XMN-6.*ACHARG(LI1)*ACHARG(LI2)*APHI*SQRT(ZIONST) XMM-6.*ACHARG(LI1)*ACHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*ACHARG(LI2)*ACHARG(LI2)*APHI*SORT(ZIONST) ZMN-ACHARG(LI1)*ACHARG(LI2) THET-ATHETA(LII,LI2) C C....SEE NOTE: PHI1 C IF(ACHARG(LI1).EQ.ACHARG(LI2))THEN ETHETA-0.0 ELSE ETHETA-ZMN*(SUMO(XMN)-0.5*SUMO(XMM)-0.5*SUMO(XNN)) /(4.*ZIONST) ENDIF ENDIF PHI-THET + ETHETA RETURN END C C C C....FUNCTION SUMO C C..,.THE VALUES FOR THE J AND JPRIME WERE EVALUATED OUTSIDE OF THE C PROGRAM AND THE VALUSE FIT TO A POLYNOMIAL OF THE FORM LNX VS C LNF(XRAY). THE INTERRGRALS WERE EVALUATED USING A ROMBERG C INTEGRATION ROUTINE FOUND IN THE IMSL LIBRARY. THE VALUES OF C THE INTEGRAL COMPARED WITH THOSE PRESENTED IN PITZERS THIRDPAPER C FUNCTION SUMO(XRAY) 233

REAL XLN,XRAY,SUMLN,SUMO IF(XRAY.LT.2000.)THEN XLN= ALOG(XRAY) SUMLN - (-2.150403 + XLN*(1.378649 + XLN*(-0.0603501+ XLN*( &-0.7719421E-04 + XLN*(0.7749758E-03 + XLN*(0.2538732E-04+ &XLN*(-0.1589227E-04 + XLN*(-0.1884598E-06+ XLN*(0.2367578E-06 &+ XLN*(-0.132147E-07)))))))))) SUMO - EXP(SUMLN) ELSE SUMO - (.25 * XRAY) 1.00 ENDIF RETURN END C C C C....FUNCTION PHIPRM C C FUNCTION PHIPRM(LI1,LI2,ZIONST,IONCA) PARAMETER (NION - 15) C REAL PHI,ZIONST,SUM1 INTEGER LI1,LI2,IONCA C COMMON /THETA/ ATHETA(NION,NION),CTHETA(NION,NION) COMMON /CHARGE/ ACHARG(NION),CCHARG(NION) COMMON /DHTERM/ APHI,BEE REAL ATHETA,CTHETA,ACHARG,CCHARG,APHI,BEE C C....RODTE TO CATION (IONCA=0) OR TO ANION(IONCA =1) CALCULATIONS C IF(IONCA.EQ.0) THEN C C....SEE NOTE: PHI1 C IF(CCHARG(LI1).EQ.CCHARG(LI2))THEN PHIPRM-0.0 RETURN ENDIF XMN-8.*CCHARG(LI1)*CCHARG(LI2)*APHI*SQRT(ZIONST) XMM=6.*CCHARC(LI1)*CCHARC(LI1)*APHI*SQRT(ZIONST) XNN-6.*GCHARG(LI2)*CCHARG(LI2)*APHI*SQRT(ZIONST) ZMN-CCHARG(LI1)*CCHARG(LI2) THET-CTHETA(LI1,LI2) ELSE C C....SEE NOTE: PHI1 C IF(ACHARG(LI1).EQ.ACHARG(LI2))THEN PHIPRM-0.0 RETURN ENDIF 234

XMN-6.*ACHARG(LI1)*ACHARG(LI2)*APHI*SQRT(ZIONST) XMM-6.*ACHARG(LI1)*ACHARG(LI1)*APHI*SORT(ZIONST) XNN-6.*ACHARG(L12)*ACHARG(LI2)*APHI*SORT(ZIONST) ZMN-ACHARG(LI1)*ACHARG(LI2) THET=ATHETA(LI1,LI2) ENDIF ETHETP=ZMN*(SUM1(XMN)-0.5*SUM1(XMM)-0.5*SUM1(XNN)) /(8.0*ZIONST*2IONST) PHIPRM=ETHETP-(PHI(LI1,LI2,ZIONST,IONCA)-THET)/ZIONST RETURN END C C C C C FUNCTION SUM1(XRAY) REAL XLN,XRAY,SUMLN,SUM1 IF(XRAY.LT.800.)THEN XLN = ALOC(XRAY) SUMLN = (-0.1829293E+01+XLN*(0.1291033E+01+XLN*(-0.6440535E-01 & + XLN*(0.2021252E-02 + XLN*(0.1043347E-02+ XLN*( & -0.3247351E-04 + XLN*(-0.2225391E-04 + XLN*(0.9590904E-6+ & XLN*(0.2592198E-06 + XLN*(-0.1874422E-07)))))))))) SUM1 EXP(SUMLN) ELSE SUM1 - .25 * XRAY ENDIF RETURN END C C C FUNCTION WATRACT C C THIS FUNCTION CALCULATES THE ACTIVITYOF WATER IN AN C IONIC SOLUTION AT 25 DEGREES C. SEE HARVIE AND WEARE, GEOCHEMICA C ET COSMOCHIMICA, VOL 44, PP 981 - 997, 1980. C FUNCTION WATRACT(ZIONST,N) PARAMETER (NION = 15) C REAL WATRACT,DEBYHUK,SUMBC,SUMC,SUMA,ZIONST,2C & ,WATRSUM,WATRFRC,WATRLOG INTEGER IBC1,IBC2,IC1,IC2,ICSTOP,IC3,IA1,IA2,IASTOP,IA3,IWTR C COMMON /SYSTEM/ LIC(NION),NUMC,CMOL(NION),LIA(NION),NUMA, &AMOL(NION) COMMON /DHTERM/ APHI, BEE COMMON /PSI/ AACPSI(NION,NION,NION), CCAPSI(NION,NION,NION) C REAL CMOL,AMOL,APHI,BEE,AACPSI,CCAPSI INTEGER NUMC,NUMA,LIC,LIA C CALCULATION OF THE DEBYE-HUCKEL TERM OF THE ACTIVITYCOEFFICIENT 235

C DEBYHUK = -2.0 * APHI* (ZIONST**1.5)/(1.+ BEE * SQRT(ZIONST)) C C INITITALIZE SUMMATION VARIABLES TO ZERO C SUMBC=0.0 SUMC-0.0 SUMA-0.0 C C SUMBC: SUM OVER ALL THE DIFFERENT PAIRS OF ANOINS ANDCATIONS, C WITH FIRST VIRIAL COEFFICIENT AND MIXING COEFFIENT. C DO 40 IBC1-1, NUMC DO 20 IBC2-1, NUMA SUMBC = SUMBC + CMOL(LIC(IBC1))*AMOL(LIA(IBC2))* (BPHI(LIC(IBC1),LIA(IBC2),ZIONST) + ZC*CMX(LIC(IBC1), LIA(IBC2))) 20 CONTINUE 40 CONTINUE SUMBC = 2.0 * SUMBC C C SUMC: SUM OVER ALL DIFFERENT PAIRS OF CATIONS,AND WITH A THIRD C VIRAIL COEFFICIENT OVER ALL THE ANIONS. C DO 100 IC1=1, NUMC

ICSTOP = IC1 - 1 DO 80 IC2-1, ICSTOP DO 60 IC3-1,NUMA SUMC SUMC + AMOL(LIA(IC3))*CCAPSI(LIC(IC1),LIC(IC2),LIA(IC3)) 60 CONTINUE SUMC = SUMC + PHI(LIC(IC1),LIC(IC2),ZIONST,O)+ ZIONST* PHIPRM(LIC(IC1),LIC(IC2),ZIONST,O) SUMC = SUMC * CMOL(LIC(IC1)) *CMOL(LIC(IC2)) 80 CONTINUE 100 CONTINUE C C SUMA: SUM OVER ALL DIFFERN-ENT PAIRS OF ANIONS,WITH A THIRD C VIRIAL COEFFICIENT OVER ALL THE CATIONS. C DO 160 IA1-1, NUMA IASTOP IA1 1 DO 140 IA2-1, IASTOP DO 120 IA3-1, NUMC SUMA SUMA + CMOL(LIC(IA3))*AACPSI(LIA(IA1),LIA(IA2),LIC(IA3)) 120 CONTINUE SUMA = SUMA + PHI(LIA(IA1),LIA(IA2),ZIONST,1)+ ZIONST* PHIPRM(LIA(IA1),LIA(IA2),ZIONST,1) SUMA = SUMA * AMOL(LIA(IA1)) * AMOL(LIA(IA2)) 140 CONTINUE 160 CONTINUE C 236

C....THIS CALCULATES THE MOLE FRACTION OF WATER INTHE SYSTEM C USED IN CALCULATING THE ACTIVITY OF THE WATER. C WATRSUM = 0.0 DO 180 IWTR=1, NUMC WATRSUM = WATRSUM + CMOL(IWTR) 180 CONTINUE DO 200 IWTR-1, NUMA WATRSUM = WATRSUM + AMOL(IWTR) 200 CONTINUE WATRFRC - (55.555 / (55.555 + WATRSUM)) WATRLOG-LOG(WATURC)-((DEBYHUK + SUMBC +(2.*SUMC)+ (2.*SUMA)) & /55.555) C C CALCULATION OF THE ACTIVITY COEFFICIENT OF WATER C WATRACT = EXP(WATRLOG) RETURN END C C C FUNCTION BPHI C C THIS FUNCTION CALCULATES THE SECOND VIRIAL COEFFICIENTFOR THE C ACTIVITY COEFFICIENT OF WATER.

FUNCTION BPHI(ICAT,IAN,ZIONST) PARAMETER (NION = 15) C REAL ZIONST,SQION,BPHI INTEGER ICAT,IAN C COMMON /BETA/ BO(NION,NION),B1(NION,NION),B2(NION,NION), &HOP(NION,NION) COMMON /ALFA/ ALPHAO,ALPHALALPHA2 REAL BO,B1,B2,ALPHAO,ALPHALALPHA2 INTEGER HOP C C CALCULATE THE SQUREROOT OF THE IONIC STRENGTH SQION = SQRT(ZIONST) C C CHECK IF HIGHER ORDER PAIR C HOP - 0 NOT HIGHER ORDER PAIR C HOP - 1 HIGHER ORDER PAIR C IF(HOP(ICAT IAN).EQ.0) THEN BPHI = BO(ICAT,IAN) + B1(ICATJAN)*EXP(-1.*ALPHAO*SQION) RETURN ELSE BPHI - BO(ICAT,IAN) + B1(ICATJAN)*EXP(-1.*ALPHAl*SOION)+ B2(ICATJAN)*EXP(-1.*ALPHA2*SOION) RETURN ENDIF END