Beginners > BASIC functions

PHREEQC output calculation of sum of cations and sum of anions separately?

(1/1)

peterwadeuk:
Greetings good people,

I need to know how much charge is generated in some simple mineral dissolution experiments.

I am currently manually summing cation concentration x cationic charge; same for anions. I find this laborious when I change the SELECTED_OUTPUT.

Is there a way to push to SELECTED_OUTPUT the calculated +ve and -ve charge in solution?

All the best,
Peter

dlparkhurst:
It takes some Basic programming, but here is an example that calculates the sum of cations and anions as eq/kgw. You can modify it for a USER_PUNCH definition for selected output.


--- Code: ---SOLUTION 1
Na 1
Cl 1
Zn 1
S(6) 1 charge
USER_PRINT
-start
 10 t = SYS("aq", count, name$, type$, moles, 1)
 20 PRINT "Species            Molality             Z     Eq/kgw"
 30 FOR i = 1 TO count
 40   s$ = SPECIES_FORMULA$(name$(i), count1, species$, coef)
 50   FOR j = 1 TO count1
 60     IF species$(j) <> "charge" THEN GOTO 110
 70     IF coef(j) = 0 THEN GOTO 120
 80     PRINT PAD$(name$(i), 15), moles(i), coef(j), moles(i)*coef(j)
 90     IF coef(j) > 0 THEN anions = anions+coef(j)*moles(i) ELSE cations = cations+coef(j)*moles(i)
100     GOTO 120
110   NEXT j
120 NEXT i
130 PRINT "Cations, eq: ", cations
140 PRINT "Anions, eq:  ", anions
150 END
-end

--- End code ---

peterwadeuk:
Oh, wow, thank you very much, David.

You have helped me enormously.

I wish a very satisfying day to you.
Peter

peterwadeuk:
Hello, I made this small modification to the script (changing > to <)

90     IF coef(j) < 0 THEN anions = anions+coef(j)*moles(i) ELSE cations = cations+coef(j)*moles(i)

Navigation

[0] Message Index

Go to full version