From 647485eab96ea795b0730275178227d8af4c8a8f Mon Sep 17 00:00:00 2001 From: rqthomas Date: Thu, 3 Oct 2019 11:51:50 -0400 Subject: [PATCH] added stop to carbon ph calculation if nnot converging --- src/aed2_carbon.F90 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/aed2_carbon.F90 b/src/aed2_carbon.F90 index f03e263..4fb9e2b 100644 --- a/src/aed2_carbon.F90 +++ b/src/aed2_carbon.F90 @@ -1112,13 +1112,19 @@ SUBROUTINE Cal_pHfromTATC(TAx, TCx, pHx, K1F, K2F, TBF, KBF, KWF, KP1F, KP2F, KP REAL :: H, Denom, CAlk, BAlk, OH, PhosTop, PhosBot, PAlk, SiAlk, & & FREEtoTOT, Hfree, HSO4, HF, Residual, Slope, deltapH, pHTol, ln10 + + INTEGER :: count + INTEGER :: max_count pHx = 8. !This is the first guess pHTol = 0.0001 !tolerance for iterations end ln10 = log(10.) deltapH = pHTol + 1 + + count = 0 + max_count = 100 - DO WHILE (abs(deltapH) > pHTol) + DO WHILE (abs(deltapH) > pHTol .AND. count < max_count) H = 10.**(-pHx) Denom = (H*H + K1F*H + K1F*K2F) CAlk = TCx*K1F*(H + 2.*K2F)/Denom @@ -1143,6 +1149,7 @@ SUBROUTINE Cal_pHfromTATC(TAx, TCx, pHx, K1F, K2F, TBF, KBF, KWF, KP1F, KP2F, KP pHx = pHx + deltapH !% Is on the same scale as K1 and K2 were calculated... + count = count + 1 END DO END SUBROUTINE Cal_pHfromTATC