-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCKSSolution.cpp
342 lines (307 loc) · 7 KB
/
CKSSolution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// CKSSolution.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CKSSolution.h"
#include "KeywordPageListItems.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCKSSolution
IMPLEMENT_DYNAMIC(CCKSSolution, baseCKSSolution)
CCKSSolution::CCKSSolution(CWnd* pWndParent)
: baseCKSSolution(IDS_PROPSHT_CAPTION10, pWndParent)
{
// Add all of the property pages here. Note that
// the order that they appear in here will be
// the order they appear in on screen. By default,
// the first page of the set is the active one.
// One way to make a different property page the
// active one is to call SetActivePage().
AddPage(&m_Page1);
AddPage(&m_Page2);
AddPage(&m_Page3);
}
CCKSSolution::~CCKSSolution()
{
}
BEGIN_MESSAGE_MAP(CCKSSolution, baseCKSSolution)
//{{AFX_MSG_MAP(CCKSSolution)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCKSSolution message handlers
CString CCKSSolution::GetString()
{
/*
Line 0: SOLUTION 25 Test solution number 25
Line 1: temp 25.0
Line 2: pH 7.0 charge
Line 3: pe 4.5
Line 4: redox O(-2)/O(0)
Line 5: units ppm
Line 6: density 1.02
Line 7a: Ca 80.
Line 7b: S(6) 96. as SO4
Line 7c: S(-2) 1. as S
Line 7d: N(5) N(3) 14. as N
Line 7e: O(0) 8.0
Line 7f: C 61.0 as HCO3 CO2(g) -3.5
Line 7g: Fe 55. ug/kgs as Fe S(6)/S(-2) Pyrite
Line 8a: -isotope 13C -12. 1. # permil PDB
Line 8b: -isotope 34S 15. 1.5 # permil CDT
Line 9: -water 0.5 # kg
*/
CString strLines;
CString strFormat;
// Line 0
strLines = GetLineZero(CKeyword::K_SOLUTION);
// Line 1 temp
strFormat.Format(_T("%s%4c%-9s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("temp"),
DBL_DIG,
m_Page1.m_dTemp
);
strLines += strFormat;
// Line 2 pH
if (m_Page2.m_strChargeBalance.Compare(_T("(pH)")) == 0)
{
strFormat.Format(_T("%s%4c%-9s %.*g %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pH"),
DBL_DIG,
m_Page1.m_dPH,
_T("charge")
);
}
else if (!m_Page1.m_strPH_Equil.IsEmpty())
{
strFormat.Format(_T("%s%4c%-9s %.*g %s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pH"),
DBL_DIG,
m_Page1.m_dPH,
(LPCTSTR)m_Page1.m_strPH_Equil,
DBL_DIG,
m_Page1.m_dPH_SI
);
}
else
{
strFormat.Format(_T("%s%4c%-9s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pH"),
DBL_DIG,
m_Page1.m_dPH
);
}
strLines += strFormat;
// Line 3 pe
if (m_Page2.m_strChargeBalance.Compare(_T("(pe)")) == 0)
{
strFormat.Format(_T("%s%4c%-9s %.*g %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pe"),
DBL_DIG,
m_Page1.m_dPE,
_T("charge")
);
}
else if (!m_Page1.m_strPE_Equil.IsEmpty())
{
strFormat.Format(_T("%s%4c%-9s %.*g %s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pe"),
DBL_DIG,
m_Page1.m_dPE,
(LPCTSTR)m_Page1.m_strPE_Equil,
DBL_DIG,
m_Page1.m_dPE_SI
);
}
else
{
strFormat.Format(_T("%s%4c%-9s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("pe"),
DBL_DIG,
m_Page1.m_dPE
);
}
strLines += strFormat;
// Line 4 redox
if (!m_Page1.m_strRedox.IsEmpty())
{
strFormat.Format(_T("%s%4c%-9s %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("redox"),
(LPCTSTR)m_Page1.m_strRedox
);
strLines += strFormat;
}
// Line 5 units
m_Page2.m_strDefaultUnits.MakeLower();
strFormat.Format(_T("%s%4c%-9s %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("units"),
(LPCTSTR)m_Page2.m_strDefaultUnits
);
strLines += strFormat;
// Line 6 density
strFormat.Format(_T("%s%4c%-9s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("density"),
DBL_DIG,
m_Page1.m_dDensity
);
strLines += strFormat;
// Line 7
std::list<CConc>::const_iterator iter = m_Page2.m_listConc.begin();
CString strLine;
for (; iter != m_Page2.m_listConc.end(); ++iter)
{
// element list, concentration, [units],
// ([as formula] or [gfw gfw]), [redox couple],
// [(charge or phase name [saturation index])]
CConc conc(*iter);
// element list, concentration
ASSERT(!conc.m_strDesc.IsEmpty());
ASSERT(conc.m_dInputConc == conc.m_dInputConc);
strFormat.Format(_T("%s%4c%-9s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
(LPCTSTR)conc.m_strDesc,
DBL_DIG,
conc.m_dInputConc
);
strLine = strFormat;
// [units]
if (!conc.m_strUnits.IsEmpty() && conc.m_strUnits.Compare("(Default)") != 0)
{
strFormat.Format(_T(" %-10s"),
(LPCTSTR)conc.m_strUnits
);
strLine += strFormat;
}
// [as formula]
if (!conc.m_strAs.IsEmpty())
{
ASSERT(conc.m_dGFW != conc.m_dGFW);
strFormat.Format(_T(" as %-10s"),
(LPCTSTR)conc.m_strAs
);
strLine += strFormat;
}
// [gfw gfw]
if (conc.m_dGFW == conc.m_dGFW)
{
ASSERT(conc.m_strAs.IsEmpty());
strFormat.Format(_T(" gfw %.*g"),
DBL_DIG,
conc.m_dGFW
);
strLine += strFormat;
}
// [redox couple]
if (!conc.m_strRedox.IsEmpty())
{
strFormat.Format(_T(" %-10s"),
(LPCTSTR)conc.m_strRedox
);
strLine += strFormat;
}
// [(charge or phase name [saturation index])]
if (!conc.m_strPhase.IsEmpty())
{
strFormat.Format(_T(" %-10s"),
(LPCTSTR)conc.m_strPhase
);
strLine += strFormat;
if (conc.m_strPhase.CompareNoCase(_T("charge")) == 0)
{
ASSERT(conc.m_dPhaseSI != conc.m_dPhaseSI);
}
else
{
ASSERT(conc.m_dPhaseSI == conc.m_dPhaseSI);
strFormat.Format(_T(" %.*g"),
DBL_DIG,
conc.m_dPhaseSI
);
strLine += strFormat;
}
}
strLine.TrimRight();
strLines += strLine;
}
// Line 8 isotope
std::list<CIsotope>::const_iterator isoIter = m_Page3.m_listIsotopes.begin();
for (; isoIter != m_Page3.m_listIsotopes.end(); ++isoIter)
{
CIsotope isotope(*isoIter);
if (isotope.m_dRatioUncertainty == isotope.m_dRatioUncertainty)
{
strFormat.Format(_T("%s%4c%-9s %-7s %.*g %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("-isotope"),
(LPCTSTR)isotope.m_strName,
DBL_DIG,
isotope.m_dRatio,
DBL_DIG,
isotope.m_dRatioUncertainty
);
}
else
{
strFormat.Format(_T("%s%4c%-9s %-7s %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("-isotope"),
(LPCTSTR)isotope.m_strName,
DBL_DIG,
isotope.m_dRatio
);
}
strLines += strFormat;
}
// Line 9 water
strFormat.Format(_T("%s%4c%-9s %.*g # kg"),
(LPCTSTR)s_strNewLine,
_T(' '),
_T("-water"),
DBL_DIG,
m_Page1.m_dWaterMass
);
strLines += strFormat;
return strLines + s_strNewLine;
}
void CCKSSolution::Edit(CString& rStr)
{
try
{
PhreeqcI p(rStr);
p.GetData(this);
}
catch (...)
{
CString strResource;
strResource.LoadString(IDS_EXCEPTION_ACCESS_VIOLATION);
::MessageBox(NULL, strResource, _T("Unhandled Exception"), MB_OK|MB_ICONERROR);
}
}