Diffstat (limited to 'noncore/apps/oxygen/kmolelements.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/oxygen/kmolelements.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/noncore/apps/oxygen/kmolelements.cpp b/noncore/apps/oxygen/kmolelements.cpp index ce8f9c1..e76461b 100644 --- a/noncore/apps/oxygen/kmolelements.cpp +++ b/noncore/apps/oxygen/kmolelements.cpp | |||
@@ -7,19 +7,19 @@ | |||
7 | // classes that store and manipulate chemical formulas represented as | 7 | // classes that store and manipulate chemical formulas represented as |
8 | // lists of elements | 8 | // lists of elements |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include "kmolelements.h" | 11 | #include "kmolelements.h" |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * A generic chemical entity. Can be an element or a group. | 14 | * A generic chemical entity. Can be an element or a group. |
15 | */ | 15 | */ |
16 | SubUnit::SubUnit () {} | 16 | SubUnit::SubUnit () {} |
17 | 17 | ||
18 | SubUnit::~SubUnit () {} | 18 | SubUnit::~SubUnit () {} |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Construct a subunit and return a pointer to it. The syntax of LINE is | 21 | * Construct a subunit and return a pointer to it. The syntax of LINE is |
22 | * the one used in the element definition file. | 22 | * the one used in the element definition file. |
23 | */ | 23 | */ |
24 | SubUnit* SubUnit::makeSubUnit(QString line) { | 24 | SubUnit* SubUnit::makeSubUnit(QString line) { |
25 | QString name, grpname, weight, coef; | 25 | QString name, grpname, weight, coef; |
@@ -27,9 +27,9 @@ SubUnit* SubUnit::makeSubUnit(QString line) { | |||
27 | str >> name; | 27 | str >> name; |
28 | if (name != "-group") { // not a group - must be represented as Element | 28 | if (name != "-group") { // not a group - must be represented as Element |
29 | str >> weight >> ws; | 29 | str >> weight >> ws; |
30 | return new Element(name, weight.toDouble()); | 30 | return new Element(name, weight.toDouble()); |
31 | } | 31 | } |
32 | else { | 32 | else { |
33 | str >> grpname; | 33 | str >> grpname; |
34 | ElementList* els = new ElementList(grpname); // group - make an ElementList | 34 | ElementList* els = new ElementList(grpname); // group - make an ElementList |
35 | while (!str.eof()) { | 35 | while (!str.eof()) { |
@@ -47,14 +47,14 @@ QString SubUnit::getName() const { | |||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Get the molecular weight of THIS, based on the data from ELSTABLE. | 49 | * Get the molecular weight of THIS, based on the data from ELSTABLE. |
50 | */ | 50 | */ |
51 | double SubUnit::getWeight(QDict<SubUnit>* elstable) const { | 51 | double SubUnit::getWeight(QDict<SubUnit>* ) const { |
52 | return -1; | 52 | return -1; |
53 | } | 53 | } |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * A group of elements. | 56 | * A group of elements. |
57 | */ | 57 | */ |
58 | ElementList::ElementList () { | 58 | ElementList::ElementList () { |
59 | elements = new QList<ElementCoef>; | 59 | elements = new QList<ElementCoef>; |
60 | } | 60 | } |
@@ -64,9 +64,9 @@ ElementList::~ElementList () { | |||
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * A group of elements. | 68 | * A group of elements. |
69 | */ | 69 | */ |
70 | ElementList::ElementList (QString name) { | 70 | ElementList::ElementList (QString name) { |
71 | this->name = name; | 71 | this->name = name; |
72 | elements = new QList<ElementCoef>; | 72 | elements = new QList<ElementCoef>; |
@@ -79,9 +79,9 @@ void ElementList::writeOut(QString& line) { | |||
79 | QString coef; | 79 | QString coef; |
80 | line = "-group " + name; | 80 | line = "-group " + name; |
81 | ElementCoef* current = elements->first(); | 81 | ElementCoef* current = elements->first(); |
82 | while (current != 0) { | 82 | while (current != 0) { |
83 | line += " " + current->name + " " + coef.setNum(current->coef, 'g', 10); | 83 | line += " " + current->name + " " + coef.setNum(current->coef, 'g', 10); |
84 | // precision set to 10 digits | 84 | // precision set to 10 digits |
85 | current = elements->next(); | 85 | current = elements->next(); |
86 | } | 86 | } |
87 | } | 87 | } |
@@ -102,9 +102,9 @@ double ElementList::getWeight(QDict<SubUnit>* elstable) const { | |||
102 | return weight; | 102 | return weight; |
103 | } | 103 | } |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * Return a string representing the elemental composition of THIS, as | 106 | * Return a string representing the elemental composition of THIS, as |
107 | * a tab-separated element - percentage pairs, separated by newlines. | 107 | * a tab-separated element - percentage pairs, separated by newlines. |
108 | */ | 108 | */ |
109 | QString ElementList::getEA(QDict<SubUnit>* elstable, double mw) const { | 109 | QString ElementList::getEA(QDict<SubUnit>* elstable, double mw) const { |
110 | if (mw == 0) mw = getWeight(elstable); | 110 | if (mw == 0) mw = getWeight(elstable); |
@@ -113,19 +113,19 @@ QString ElementList::getEA(QDict<SubUnit>* elstable, double mw) const { | |||
113 | ElementCoef* current = elements->first(); | 113 | ElementCoef* current = elements->first(); |
114 | while (current != 0) { | 114 | while (current != 0) { |
115 | SubUnit* e = elstable->find(current->name); | 115 | SubUnit* e = elstable->find(current->name); |
116 | if (e != 0) { | 116 | if (e != 0) { |
117 | double current_percent = 100 * (current->coef) * | 117 | double current_percent = 100 * (current->coef) * |
118 | (e->getWeight(elstable)) | 118 | (e->getWeight(elstable)) |
119 | / mw; | 119 | / mw; |
120 | ea += current->name + "\t" + | 120 | ea += current->name + "\t" + |
121 | temp.setNum(current_percent) + "\n"; | 121 | temp.setNum(current_percent) + "\n"; |
122 | } else return QString("ERROR!\n"); //ERROR | 122 | } else return QString("ERROR!\n"); //ERROR |
123 | current = elements->next(); | 123 | current = elements->next(); |
124 | } | 124 | } |
125 | return ea; | 125 | return ea; |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Return a string representing THIS as an empirical chemical formula. | 129 | * Return a string representing THIS as an empirical chemical formula. |
130 | */ | 130 | */ |
131 | QString ElementList::getEmpFormula() const { | 131 | QString ElementList::getEmpFormula() const { |
@@ -161,9 +161,9 @@ void ElementList::addTo(ElementList& els, double coef) { | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | /** | 164 | /** |
165 | * Add an element to THIS, with a coefficient COEF. If THIS already contains | 165 | * Add an element to THIS, with a coefficient COEF. If THIS already contains |
166 | * an element with the same name, adjust its coefficient only; if not, create | 166 | * an element with the same name, adjust its coefficient only; if not, create |
167 | * a new ElementCoef pair and add to THIS. | 167 | * a new ElementCoef pair and add to THIS. |
168 | */ | 168 | */ |
169 | void ElementList::addElement(const QString& name, double coef) { | 169 | void ElementList::addElement(const QString& name, double coef) { |
@@ -183,9 +183,9 @@ void ElementList::addElement(const QString& name, double coef) { | |||
183 | */ | 183 | */ |
184 | bool ElementList::contains(const QString& name) { | 184 | bool ElementList::contains(const QString& name) { |
185 | ElementCoef* current = elements->first(); | 185 | ElementCoef* current = elements->first(); |
186 | while (current != 0) { | 186 | while (current != 0) { |
187 | if (current->name == name) | 187 | if (current->name == name) |
188 | return true; | 188 | return true; |
189 | current = elements->next(); | 189 | current = elements->next(); |
190 | } | 190 | } |
191 | return false; | 191 | return false; |
@@ -201,9 +201,9 @@ QString ElementList::getName() const { | |||
201 | 201 | ||
202 | /** | 202 | /** |
203 | * A chemical element. | 203 | * A chemical element. |
204 | */ | 204 | */ |
205 | Element::Element(const QString& n, double w) | 205 | Element::Element(const QString& n, double w) |
206 | : weight(w), name(n) { } | 206 | : weight(w), name(n) { } |
207 | 207 | ||
208 | 208 | ||
209 | Element::~Element() { | 209 | Element::~Element() { |
@@ -217,9 +217,9 @@ void Element::writeOut(QString& line) { | |||
217 | line.setNum(weight); | 217 | line.setNum(weight); |
218 | line = name + " " + line; | 218 | line = name + " " + line; |
219 | } | 219 | } |
220 | 220 | ||
221 | double Element::getWeight(QDict<SubUnit>* elstable) const { | 221 | double Element::getWeight(QDict<SubUnit>* ) const { |
222 | return weight; | 222 | return weight; |
223 | } | 223 | } |
224 | 224 | ||
225 | void Element::addTo(ElementList& els, double coef) { | 225 | void Element::addTo(ElementList& els, double coef) { |
@@ -230,9 +230,9 @@ QString Element::getName() const { | |||
230 | return name; | 230 | return name; |
231 | } | 231 | } |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * An element - coefficient pair. Used to represent elements within an | 234 | * An element - coefficient pair. Used to represent elements within an |
235 | * element list. | 235 | * element list. |
236 | */ | 236 | */ |
237 | ElementCoef::ElementCoef(const QString& n, double c) : name(n), coef(c) {} | 237 | ElementCoef::ElementCoef(const QString& n, double c) : name(n), coef(c) {} |
238 | 238 | ||