author | cniehaus <cniehaus> | 2002-09-21 13:43:51 (UTC) |
---|---|---|
committer | cniehaus <cniehaus> | 2002-09-21 13:43:51 (UTC) |
commit | 65cf44292ac6abfb1a60be5f582cab26333cfb0a (patch) (unidiff) | |
tree | 8fec45b6ca9302055dd497fc7857015cf571665d /noncore/apps/oxygen/kmolcalc.cpp | |
parent | 99d546ce72f40e28b04f09201d92d58294401591 (diff) | |
download | opie-65cf44292ac6abfb1a60be5f582cab26333cfb0a.zip opie-65cf44292ac6abfb1a60be5f582cab26333cfb0a.tar.gz opie-65cf44292ac6abfb1a60be5f582cab26333cfb0a.tar.bz2 |
* moving oxygendata and kmolweights
* fixing the datafile-problems (thanks to Max)
Diffstat (limited to 'noncore/apps/oxygen/kmolcalc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/oxygen/kmolcalc.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp index 0ba52da..33666b1 100644 --- a/noncore/apps/oxygen/kmolcalc.cpp +++ b/noncore/apps/oxygen/kmolcalc.cpp | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * kmolcalc.cpp | 2 | * kmolcalc.cpp |
3 | * | 3 | * |
4 | * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> | 4 | * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com> |
@@ -8,13 +8,14 @@ | |||
8 | /** | 8 | /** |
9 | * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic | 9 | * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic |
10 | * weights and group definitions ELSTABLE, and the currently processed formula, stored | 10 | * weights and group definitions ELSTABLE, and the currently processed formula, stored |
11 | * as a list of elements and their coefficients, ELEMENTS. | 11 | * as a list of elements and their coefficients, ELEMENTS. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "kmolcalc.h" | 14 | #include "kmolcalc.h" |
15 | #include <qdict.h> | 15 | #include <qdict.h> |
16 | #include <qdir.h> | 16 | #include <qdir.h> |
17 | #include <qfile.h> | 17 | #include <qfile.h> |
18 | #include <qpe/qpeapplication.h> | ||
18 | #include <iostream.h> | 19 | #include <iostream.h> |
19 | 20 | ||
20 | 21 | ||
@@ -36,15 +37,15 @@ void KMolCalc::readElstable() { | |||
36 | if (elstable) delete elstable; | 37 | if (elstable) delete elstable; |
37 | elstable = new QDict<SubUnit> (197, TRUE); | 38 | elstable = new QDict<SubUnit> (197, TRUE); |
38 | elstable->setAutoDelete(TRUE); | 39 | elstable->setAutoDelete(TRUE); |
39 | mwfile = "/home/opie/opie/noncore/apps/oxygen/kmolweights"; | 40 | mwfile = QPEApplication::qpeDir() +"share/oxygen/kmolweights"; |
40 | QFile f(mwfile); | 41 | QFile f(mwfile); |
41 | if (f.exists()) readMwfile(f); | 42 | if (f.exists()) readMwfile(f); |
42 | } | 43 | } |
43 | 44 | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * Parse a string S and construct the ElementList this->ELEMENTS, representing the | 47 | * Parse a string S and construct the ElementList this->ELEMENTS, representing the |
47 | * composition of S. Returns 0 if successful, or an error code (currently -1) if | 48 | * composition of S. Returns 0 if successful, or an error code (currently -1) if |
48 | * parsing failed. | 49 | * parsing failed. |
49 | * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. | 50 | * The elements is S must be valid element or group symbols, as stored in this->ELSTABLE. |
50 | * See help files for correct formula syntax. | 51 | * See help files for correct formula syntax. |
@@ -64,7 +65,7 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) { | |||
64 | QString errors ("OK"); | 65 | QString errors ("OK"); |
65 | bool ok = TRUE; | 66 | bool ok = TRUE; |
66 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 67 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
67 | double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); | 68 | double prefix = (i == 0 ? 1 : s.left(i).toDouble(&ok)); |
68 | if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR | 69 | if (! ok || i == sl || prefix == 0) return QString ("Bad formula."); // ERROR |
69 | ElementList* elstemp = new ElementList; | 70 | ElementList* elstemp = new ElementList; |
70 | while (i < sl) { | 71 | while (i < sl) { |
@@ -85,22 +86,22 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) { | |||
85 | errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); | 86 | errors = KMolCalc::readGroup(s.mid(j+1, i-j-1), inner); |
86 | j = ++i; | 87 | j = ++i; |
87 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 88 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
88 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); | 89 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); |
89 | if (! ok || suffix == 0) { | 90 | if (! ok || suffix == 0) { |
90 | delete inner; | 91 | delete inner; |
91 | delete elstemp; | 92 | delete elstemp; |
92 | return QString ("Bad formula."); // ERROR | 93 | return QString ("Bad formula."); // ERROR |
93 | } | 94 | } |
94 | inner->addTo(*elstemp, suffix); | 95 | inner->addTo(*elstemp, suffix); |
95 | delete inner; | 96 | delete inner; |
96 | inner = NULL; | 97 | inner = NULL; |
97 | } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { | 98 | } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) { |
98 | while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || | 99 | while (++i < sl && ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '*' || |
99 | s[i] == '\'')); | 100 | s[i] == '\'')); |
100 | QString elname = s.mid(j, i-j); | 101 | QString elname = s.mid(j, i-j); |
101 | j = i; | 102 | j = i; |
102 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; | 103 | while (i < sl && ((s[i] <= '9' && s[i] >= '0') || s[i] == '.')) i++; |
103 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); | 104 | double suffix = (i == j ? 1 : s.mid(j, i-j).toDouble(&ok)); |
104 | if (! ok || suffix == 0) { | 105 | if (! ok || suffix == 0) { |
105 | delete elstemp; | 106 | delete elstemp; |
106 | return QString ("Bad formula."); // ERROR | 107 | return QString ("Bad formula."); // ERROR |
@@ -176,7 +177,7 @@ void KMolCalc::undefineGroup (const QString& name) { | |||
176 | } | 177 | } |
177 | 178 | ||
178 | /** | 179 | /** |
179 | * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes | 180 | * Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes |
180 | * NAME has valid syntax. | 181 | * NAME has valid syntax. |
181 | 182 | ||
182 | */ | 183 | */ |