PhreeqcUsers Discussion Forum

Please email phreeqcusers at gmail.com with your name and affiliation to request an account.
Welcome Guest
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • BASIC functions »
  • PHREEQC output calculation of sum of cations and sum of anions separately?
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: PHREEQC output calculation of sum of cations and sum of anions separately?  (Read 12895 times)

peterwadeuk

  • Top Contributor
  • Posts: 54
PHREEQC output calculation of sum of cations and sum of anions separately?
« on: 22/01/25 12:44 »
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
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4335
Re: PHREEQC output calculation of sum of cations and sum of anions separately?
« Reply #1 on: 22/01/25 16:34 »
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: [Select]
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
Logged

peterwadeuk

  • Top Contributor
  • Posts: 54
Re: PHREEQC output calculation of sum of cations and sum of anions separately?
« Reply #2 on: 24/01/25 08:52 »
Oh, wow, thank you very much, David.

You have helped me enormously.

I wish a very satisfying day to you.
Peter
Logged

peterwadeuk

  • Top Contributor
  • Posts: 54
Re: PHREEQC output calculation of sum of cations and sum of anions separately?
« Reply #3 on: 24/01/25 12:33 »
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)
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • BASIC functions »
  • PHREEQC output calculation of sum of cations and sum of anions separately?
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2