summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/kmolcalc.cpp
Unidiff
Diffstat (limited to 'noncore/apps/oxygen/kmolcalc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolcalc.cpp25
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,3 +1,3 @@
1/* 1/*
2 * kmolcalc.cpp 2 * kmolcalc.cpp
3 * 3 *
@@ -9,5 +9,5 @@
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
@@ -16,4 +16,5 @@
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
@@ -37,5 +38,5 @@ void KMolCalc::readElstable() {
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);
@@ -43,7 +44,7 @@ void KMolCalc::readElstable() {
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.
@@ -65,5 +66,5 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) {
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;
@@ -86,20 +87,20 @@ QString KMolCalc::readGroup(const QString& s, ElementList* els) {
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;
@@ -177,5 +178,5 @@ void KMolCalc::undefineGroup (const QString& name) {
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