Commit 05dd25ed authored by Georges Khaznadar's avatar Georges Khaznadar

Import Upstream version 2.12

parents
This diff is collapsed.
-------------------------------------------
chemeq V2.12-1
-------------------------------------------
(c)2000-2013 G. Khaznadar
<georgesk@debian.org>
-------------------------------------------
chemeq est un filtre simple et autonome écrit en langage C,
flex et bison. Il accepte des entrées telles que :
2H2 + O2 ---> 2 H2O
et produit sur sa sortie standard du code LaTeX et des messages relatifs
à l'équilibre d'une équation de réaction chimique.
exemple:~/src$ echo "2H2 + O2 ---> 2 H2O" | chemeq -lc
2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O
OK
exemple:~/src$
ce qui signifie : 2 molécules de dihydrogène réagissent avec une molécule de
dioxygène pour donner deux molécules d'eau.
La première ligne, "2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O" est une
réécriture de l'équation en langage LaTeX.
La deuxième ligne "OK" signifie que l'équation de réaction est équilibrée.
Quand la chaîne d'entrée n'est pas reconnue, le filtre échoue et
renvoie un code 1.
exemple:~/src$ echo "2H^2 + O2 ---> 2 H2O" | chemeq -lc
ERROR parse error at 4
exemple:~/src$
NOTE : syntaxe des ions.
Bien que dans certains cas, une expression plus courte soit acceptée,
il est préférable de mettre une flèche haute (^) devant les symboles
de charge d'un ion.
Exemples : H3O^+, Fe(CN)6^4-, OH^-
NOTE : crochets
L'écriture de crochets est autorisée autour de la notation d'un corps simple,
comme pour [Fe(CN)6]4-, et seulement dans ce cas.
NOTE : constantes d'équilibre chimique.
Pour les équilibres chiliques, la constante pour l'équation de Gulder-Waage
ou le potentiel pour l'équation de Nernst peut être écrite à la fin de
l'équation, entre parenthèses. Voir quelques exemples dans src/test.1, et
typographiez-les grâce à LaTeX par la commande src/chemreport
Ce filtre peut être utilisé au sein de systèmes d'examens éducatifs,
pour analyser la réponse d'un étudiant à un problème de physique ou
de chimie.
Ce petit bout de code est sous GPL, voyez le fichier COPYING.
Les suggestions sont bienvenues.
--
Georges.
-----------------------------------------------------------
Les options de chemeq
-----------------------------------------------------------
On peut choisir le format de sortie de chemeq en spécifiant quelques options.
Les options valides sont les suivantes :
-h produit un message d'aide en anglais (*H*elp)
-m Produit une sortie *M*inimale. Ainsi chemeq est idempotent,
c'est à dire que les commandes 'chemeq | chemeq' et 'chemeq' sont
équivalentes.
-l Prouduit une chaîne *L*atex représentant l'équation chimique.
-c Produit un message donnant des indications sur la *C*onservation des
éléments et des charges. 'OK' signifie que les éléments et les charges
sont conservés.
-w Produit la chaîne LaTeX qui représente l'équation de Gulder-*W*aage
relative à l'équation chimique, ou l'équation de Nernst, si l'équation
de départ est une demi-réaction rédox.
-n Produit une chaîne *N*ormalisée représentant l'équation de départ.
Deux équations chimiques ayant la même chaîne normalisée sont
chimiquement équivalentes, même si l'ordre des molécules est différent,
et si les coefficients ne sont pas égaux mais proportionnels.
Par défaut, 'chemeq' est équivalent à 'chemeq -mlcwn'.
-----------------------------------------------------------
INSTALLATION
-----------------------------------------------------------
Pour compiler chemeq, lancez 'make' dans le répertoire principal chemeq.
Pour l'installer avec sa page de manuel, lancez 'make install' dans ce
même répertoire.
-----------------------------------------------------------
TEST et DEMONSTRATION
-----------------------------------------------------------
Si on modifie le code source, il est possible de tester sa conformité
aux versions précédentes en lançant 'make test' dans le répertoire principal.
Si 'make test' répond 'OK' à chaque item, et que latex et xdvi sont installés,
on peut lancer 'make demo' pour voir quelques exemples de traitement
typographique.
INSTALL=install
DESTDIR =
BIN = $(DESTDIR)/usr/bin
MAN1 = $(DESTDIR)/usr/share/man/man1
DOC = $(DESTDIR)/usr/share/doc/chemeq
TESTS = $(DOC)/tests
TESTSUITE = tests/chemreport tests/chemreport.pl \
tests/chemtest tests/chemtest.pl
TESTSTUFF = tests/test.stuff
all :
(cd src; ${MAKE})
demo : all
(cd tests; chemreport)
test : all
(cd tests; PATH=../src:$$PATH sh chemtest)
install : all
${INSTALL} -d $(BIN) $(MAN1) $(TESTS)
${INSTALL} src/chemeq $(BIN)
gzip -c -9 chemeq.1 > chemeq.1.gz
${INSTALL} -m644 chemeq.1.gz $(MAN1)
${INSTALL} -m755 $(TESTSUITE) $(TESTS)
${INSTALL} -m644 $(TESTSTUFF) $(TESTS)
uninstall :
rm $(BIN)/chemeq
rm $(MAN1)/chemeq.1.gz
rm -rf $(DOC)
clean :
rm -f *~ *.gz semantic.cache
(cd src; ${MAKE} clean)
chemeq.1: chemeq.man.xml
xsltproc --nonet --param man.charmap.use.subset "0" \
--param make.year.ranges "1" \
--param make.single.year.ranges "1" \
$<
\ No newline at end of file
-------------------------------------------
chemeq V2.12-1
-------------------------------------------
(c)2000-2013 G. Khaznadar
<georgesk@debian.org>
-------------------------------------------
chemeq is a basic standalone filter written in C language,
flex and bison. It inputs strings like:
2H2 + O2 ---> 2 H2O
and can outputs LaTeX code and messages about the equilibrium of a
chemical reaction.
example:~/src$ echo "2H2 + O2 ---> 2 H2O" | chemeq -lc
2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O
OK
example:~/src$
which means : 2 molecules of dihydrogen react with one molecule of
dioxygen, yelding two water molecules.
The first line, "2\,H_{2}\,+\,O_{2}\,\rightarrow\,2\,H_{2}O" is a translation
of the equation in LaTeX language.
The second line "OK" means that the equation is well equilibrated.
When the input is not successfully parsed, the filter fails with
the exit code 1.
example:~/src$ echo "2H^2 + O2 ---> 2 H2O" | chemeq -lc
ERROR parse error at 4
example:~/src$
NOTE : syntax of ions.
allthough in some cases, shorter expressions are sucessfully parsed,
it is safer to consider that an "up arrow" (^) must be put before the
charge symbols of an ion.
Examples : H3O^+, Fe(CN)6^4-, OH^-
NOTE : square brackets
Square brackets are allowed outside of a simple chemical notation, as in
[Fe(CN)6]4-, and only there.
NOTE : Chemical equilibrium constants.
For chemical equilibriums, the constant for the Gulder-Waage equation or
the potential for the Nernst equation can be written at the end of the
equation, surrounded by parentheses. See some examples in src/test.1, and
get them rendered by LaTeX with the command src/chemreport
This filter can be embedded in educational test systems, in order to
analyze a student's answer to a problem of physics or chemistry.
This software snippet is GPL, see the file COPYING.
Feedback is welcome.
--
Georges.
-----------------------------------------------------------
Chemeq options
-----------------------------------------------------------
You can choose chemeq's output by specifying some options.
Valid options are the following :
-h outputs a *H*elp message.
-m outputs a *M*inimal output. It allows chemeq to be idempotent,
i.e. the command 'chemeq | chemeq' is equivalent to 'chemeq'.
-l outputs a *L*aTeX string representing the chemical equation.
-c outputs a message giving informations about the *C*onservation of
elements and charges in the equation. 'OK' means that both elements
and electric charges are balanced.
-w outputs the LaTeX string representing the Gulder-*W*aage equation
related to the input chemical equation, or the Nernst equation,
if the input equation is a redox semi-equation.
-n outputs a *N*ormalized string accounting for the input equation.
Two chemical equations having the same normalized string are chemically
equivalent, even if the molecules are scrambled around and the
coefficient are not equal but proportionnal.
'chemeq' defaults to 'chemeq -mlcwn'.
-----------------------------------------------------------
INSTALLATION
-----------------------------------------------------------
To build chemeq, run 'make' in the main chemeq directory, to install it
with its man page, run 'make install' in the main directory.
-----------------------------------------------------------
TEST MODE and DEMO
-----------------------------------------------------------
If you modifiy the source code, it is possible to test its conformance
to previous versions by running 'make test' in the main directory.
If 'make test' replies 'OK' for all items, and if you have latex and
xdvi installed, you can run 'make demo' to see some examples of typesetting.
'\" t
.\" Title: CHEMEQ
.\" Author: Georges Khaznadar <georgesk@debian.org>
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\" Date: 06/19/2013
.\" Manual: User Manuals
.\" Source: chemeq 2.10
.\" Language: English
.\"
.TH "CHEMEQ" "1" "06/19/2013" "chemeq 2.10" "User Manuals"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
chemeq \- Chemical Equation Parser and Renderer
.SH "SYNOPSIS"
.HP \w'\fBchemeq\fR\ 'u
\fBchemeq\fR [\fB\-M\fR] [\fB\-m\fR] [\fB\-l\fR] [\fB\-c\fR] [\fB\-w\fR] [\fB\-C\fR] [\fB\-e\fR] [\fB\-s\fR] [\fB\-n\fR] [\fB\-W\fR]
.HP \w'\fBchemeq\fR\ 'u
\fBchemeq\fR [\fB\-h\fR] [\fB\-v\fR]
.SH "DESCRIPTION"
.PP
\fBchemeq\fR
is a chemical equation analyzer\&. It is a fast lexical and syntaxic analyser which helps to find out chemical informations embedded in source chemical equations\&. Data can be output in various sophisticated formats, depending on options\&. \*(Aqchemeq\*(Aq defaults to \*(Aqchemeq \-mlcwCn\*(Aq\&.
.SH "OPTIONS"
.PP
\fB\-M\fR
.RS 4
Outputs al list of space separated molecular weights\&.
.RE
.PP
\fB\-m\fR
.RS 4
Outputs a
\fBm\fRinimal output\&. It allows chemeq to be idempotent, i\&.e\&. the command \*(Aqchemeq | chemeq\*(Aq is equivalent to \*(Aqchemeq\*(Aq\&.
.RE
.PP
\fB\-l\fR
.RS 4
Outputs a
\fBL\fRaTeX string representing the chemical equation\&.
.RE
.PP
\fB\-c\fR
.RS 4
Outputs a message giving informations about the Conservation of elements and charges in the equation\&. \*(AqOK\*(Aq means that both elements and electric charges are balanced\&.
.RE
.PP
\fB\-w\fR
.RS 4
Outputs the LaTeX string representing the Gulder\-\fBW\fRaage equation related to the input chemical equation, or the Nernst equation, if the input equation is a redox semi\-equation\&.
.RE
.PP
\fB\-C\fR
.RS 4
Outputs a detailed
\fBC\fRount of the molecules and atoms contained in each member of the chemical equation\&. For example for the equation "H2_g + 1/2 O2_g \-\-> H2O" it outputs: "H2_g|H:1*2, 1/2 O2_g|O:1/2*2; H2O|H:1*2 O:1*1"
.RE
.PP
\fB\-e\fR
.RS 4
Outputs a detailed count of the
\fBE\fRlectrical charges\&.
.RE
.PP
\fB\-s\fR
.RS 4
Outputs a list of the chemical
\fBS\fRpecies\&.
.RE
.PP
\fB\-n\fR
.RS 4
Outputs a
\fBN\fRormalized string accounting for the input equation\&. Two chemical equations having the same normalized string are chemically equivalent, even if the molecules are scrambled around and the coefficient are not equal but proportionnal\&.
.RE
.PP
\fB\-W\fR
.RS 4
Changes the behavior of the renderer for some versions of
\fBW\fRims : works around a bug whith the macro \erightarrow\&.
.RE
.PP
\fB\-h\fR
.RS 4
Displays
\fBH\fRelp\&.
.RE
.PP
\fB\-v\fR
.RS 4
Displays the
\fBV\fRersion number
.RE
.SH "ENVIRONMENT"
.PP
\fBchemeq_input\fR, \fBw_chemeq_input\fR
.RS 4
if set, this variables\*(Aqs value overrides the standard input\&. If this variable is not set, the variable w_chemeq_input is taken in account (useful for the WIMS server)\&.
See above (useful for the WIMS server)\&.
.RE
.PP
\fBchemeq_option\fR
.RS 4
if set, this variable\*(Aqs value overrides the options\&.If this variable is not set, the variable w_chemeq_option is taken in account (useful for the WIMS server)\&.
.RE
.PP
\fBw_chemeq_option\fR
.RS 4
See above (useful for the WIMS server)\&.
.RE
.SH "EXAMPLES"
.PP
\fBecho "1/2 Cu^2+ + OH\- \-> 1/2Cu(OH)2s" | chemeq\fR
.RS 4
will display informations about the reaction of hydroxyde and Cu II ions\&.
.RE
.PP
\fBecho "MnO4^\- + 8H3O^+ + 5e\- \-\-> Mn^2+ + 12 H2O" | chemeq\fR
.RS 4
will display informations about the reaction of reduction of permanganate ions in an acid environment\&.
.RE
.PP
\fBecho "MnO4^\- + 8H3O^+ + 5e\- \-\-> Mn^2+ + 12 H2O" | chemeq \-w\fR
.RS 4
will display the LaTeX format for the Nernst law related to the reduction of permanganate ions in an acid environment\&.
.RE
.PP
\fBecho "MnO4^\- + 8H3O^+ + 5e\- \-\-> Mn^2+ + 8 H2O" | chemeq \-c\fR
.RS 4
will highlight the lack of conservation of elements H and O (water molecules are not well balanced)\&.
.RE
.SH "NOTES"
.PP
\fBsyntax of ions\fR
.RS 4
allthough in some cases, shorter expressions are sucessfully parsed, it is safer to consider that an "up arrow" (^) must be put before the charge symbols of an ion\&. Examples : H3O^+, Fe(CN)6^4\-, OH^\-
.RE
.PP
\fBComposing chemical equations\fR
.RS 4
Two operators are defined, # as an additive oprator and ~ (tilde) as a substractive operator: they allow to compose several chemical equations
.sp
\fB echo "MnO4^\- + 8H3O^+ + 5e\- \-\-> Mn^2+ + 8 H2O ~ 5Fe^3+ + 5e\- \-> 5Fe^2+" | chemeq\fR
.sp
will display the pure redox equation from the first equation, minus the second one\&. Electrons are simplified\&. So it will be equivalent to:
.sp
\fB echo "MnO4^\- + 8H3O^+ + 5Fe^2+\-\-> Mn^2+ + 8 H2O + 5Fe^3+" | chemeq \fR
which is their combination\&.
.RE
.PP
\fBMutiplying a chemical equation by one coefficient\fR
.RS 4
The operator * permits to multiply a whole equation by one coefficient which may be a fraction\&. Here is an example:
.sp
\fB echo "5 * Fe^3+ + e\- \-> Fe^2+" | chemeq \fR
.sp
will be equivalent to
.sp
\fB echo "5Fe^3+ + 5e\- \-> 5Fe^2+" | chemeq\fR
.RE
.PP
\fBCombining chemical equations, with coefficients\fR
.RS 4
The two previous techniques can be used at the same time, which enables you to make more comlicated combinations, like this one:
.sp
\fB echo "Fe^3+ + e^\- \-> Fe^2+ (0\&.77 V) # Fe^2+ + 6CN^\- \-> Fe(CN)6^4\- (Kfa=1e24) ~ Fe^3+ + 6CN^\- \-> Fe(CN)6^3\- (Kfb=1e31)" | chemeq \fR
.sp
which will work as expected, and yeld a good value for the stan\(hy dard potential of the redox couple of hexacyanoferrate II and III ions\&.
.RE
.SH "KNOWN BUGS"
.PP
When not specified, chemical entities coming from the standard input are believed to be in aqueous solutions\&. Water is considered by default as the main solvent\&. Only one liquid (aqueous) phase is currently taken in account\&. All solid chemical entities are considered as parts of separated phases\&. Suffixes _s, _g and _aq can be used to enforce the type of some chemical entities\&. There may be problemes when you write a standard potential with no decimal dot\&. For example, the entry
\fBMn^2+ + 2e^\- \-> Mn_s (\-1 V)\fR
would trigger an error\&. Then write
\fBMn^2+ + 2e^\- \-> Mn_s (\-1\&.0 V)\fR
or the more accurate value
\fBMn^2+ + 2e^\- \-> Mn_s (\-1\&.18 V)\fR
and there will be no error\&.
.SH "AUTHOR"
.PP
\fBGeorges Khaznadar\fR <\&georgesk@debian\&.org\&>
.RS 4
Wrote this manpage\&.
.RE
.SH "COPYRIGHT"
.br
Copyright \(co 2000-2013 Georges Khaznadar
.br
.PP
Redistribution and use of this manpage in source and binary forms, with or without modification, are permitted under the terms of the GNU General Public Licenses, version 2
.PP
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED\&. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE\&.
.sp
File added
This diff is collapsed.
chemlex.cc
chemparser.cc.output
chemparser.cc
chemeq
tmp.1
chemtest.tex
chemtest.log
chemtest.aux
chemtest.dvi
# -*- coding: utf-8 -*-
CXX = g++
CXXFLAGS= -g -O1
chemeq : chemeq.o chemparser.o mendeleiev.o
${CXX} $(CXXFLAGS) -o chemeq chemeq.o chemparser.o mendeleiev.o -lfl
chemeq.h: chemeq.h.in
echo "// Do not edit this file which has been automatically genreated." > $@
echo "// Instead, edit chemeq.h.in" >> $@
v=$$(basename $$(dirname $$(pwd))| sed 's/chemeq-//'); \
sed 's/VERSION.*/VERSION "'$$v'"/' $< >> $@
mendeleiev.o : mendeleiev.c chemeq.h
${CXX} $(CXXFLAGS) -c $<
chemeq.o : chemeq.cc chemeq.h
${CXX} $(CXXFLAGS) -c chemeq.cc
chemparser.o : chemparser.cc chemeq.h
${CXX} $(CXXFLAGS) -c chemparser.cc
chemparser.cc : chemlex.cc chemeq.y chemeq.h
bison --verbose -o chemparser.cc chemeq.y
chemlex.cc : chemeq.l
flex -ochemlex.cc chemeq.l
clean :
rm -f *~ *.o semantic.cache chemlex.cc chemparser.cc *.output chemeq chemeq.h
File added
This diff is collapsed.
// Do not edit this file which has been automatically genreated.
// Instead, edit chemeq.h.in
// -*- coding: utf-8 -*-
#ifndef CHEMEQ_H
#define CHEMEQ_H
#include <cstring>
#include <sstream>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#define VERSION "2.12"
/* Constante d'Avogadro, recommandée par CODATA, 2006 */
#define Avogadro 6.022141e+23
/* Charge élémentaire, voir wikipedia, 2007 */
#define Electron 1.602176e-19
/* Constante de Boltzmann, voir Wikipedia, 2007 */
#define Kb 1.3806e-23
/* D'où la constante de Faraday */
#define Faraday (Avogadro * Electron)
/* D'où la constante des Gaz parfaits 8.314 J.K^-1.mol^-1 */
#define R (Kb * Avogadro)
/* Température de référence pour les réactions chimiques, 25°C */
#define T0 (273.15+25)
/* MINVAL est une valeur impossible tant pour un potentiel standard */
/* que pour une constante d'équilibre */
#define MINVAL -999
typedef struct {
int Zed;
char symb[4];
} atome;
extern atome lesatomes[];
typedef std::pair<std::string,int> AtomeCompte;
class Compteur : public std::map<std::string,float>{
public:
std::ostream & operator << (std::ostream & o)const;
};
std::ostream & operator << (std::ostream & o, const Compteur & c);
class Chemeq;
class fraction{
public:
int i;
int d;
fraction(int numerateur, int denominateur=1):i(numerateur),d(denominateur){};
void inverse(){int n=i; i=d; d=n;};
void simplifie();
};
const fraction & minFraction(const fraction&, const fraction &);
std::ostream & operator << (std::ostream & o, fraction f);
fraction operator * (fraction f, int m);
fraction operator * (int m, fraction f);
fraction operator * (fraction f, fraction m);
fraction operator + (fraction f, fraction g);
fraction operator - (fraction f, fraction g);
bool operator > (fraction f, int i);
bool operator > (fraction f1, fraction f2);
bool operator != (fraction f, int i);
class AtomeListe{
AtomeListe * suiv, *group;
char symb[4];
int Zed, nb, no, sqbr;
public:
AtomeListe(const char* nom, int num, AtomeListe * s=0, AtomeListe * g=0){
strncpy(symb,nom,3); Zed=num; nb=1; sqbr=0;
/* sqbr == 1 quand il y a un square bracket */
suiv = s; group=g;
};
AtomeListe(const AtomeListe & a):
suiv(a.suiv), group(a.group), Zed(a.Zed), nb(a.nb), sqbr(a.sqbr){
strncpy(symb,a.symb,3);
};
const char * symbole() const{return symb;};
int Z()const{return Zed;};
int sq()const{return sqbr;};
void sq(int val){sqbr=val;};
void numerote(int n=0);
void setmolecularite(int n){nb=n;};
int getmolecularite()const{return nb;};
AtomeListe * groupe(){return group;};
void groupe(AtomeListe * al){group= al;};
const AtomeListe * suivant()const{return suiv;};
const AtomeListe * groupe()const{return group;};
void setsuivant(AtomeListe * s){suiv=s;};
void compte (Compteur &c, fraction mult=fraction(1,1))const;
double weight(fraction mult=fraction(1,1))const;
static AtomeListe * triage(AtomeListe * al);
void printcount(std::ostream & o, const fraction&, int multiple) const;
void printnorm(std::ostream & o) const;
bool isEqual(const AtomeListe & a2) const;
void debug(int decal = 0)const{
for (int i=0; i< decal; i++) std::cout << " ";
std::cout << "AtomeListe : ( & = " << this << " symb=\"" << symb << "\" Zed = " << Zed
<< " nb = " << nb << " no = " << no
<< " suiv = " << suiv << " group = " << group
<< ")\n";
if(group) group->debug(2+decal);
if(suiv) suiv->debug(decal);
};
};
typedef enum { aqueous, gas, sol } moltype;
extern const char* moltypeStr[]; /* les chaînes aq, g,s */
class Membre;
class Molec{
AtomeListe * al;
int ch;
fraction nb;
int no;
moltype t;
public:
Molec(AtomeListe * a, int c = 0, int n=1, int d=1):
al(a), ch(c), nb(n,d), t(aqueous){};
Molec(const Molec & m):
al(m.al), ch(m.ch), nb(m.nb.i,m.nb.d), t(m.t) {}
AtomeListe & liste()const{return *al;};
int charge()const{return ch;};
bool eqMol(const Molec * m) const {
return (al->isEqual(*(m->al))) && (ch== m->ch);
}
void nombre(int n, int d=1){nb=fraction(n,d);};
fraction nombre()const{return nb;};
void add(fraction f);
void sub(fraction f);
moltype typage()const{return t;};
void typage(moltype at){t=at;};
void numero(int n){no=n;};
int numero()const{return no;};
void triage(){al = AtomeListe::triage(al);};
void compte(Compteur & c)const{if (al) al->compte(c,nb);};
double weight(void)const{if (al) return al->weight(nb); else return 0.0;};
const std::string signature()const;
void printNombre(std::ostream & o)const;
bool printcount(std::ostream & o, bool first) const;
bool printelec(std::ostream & o, bool first) const;
bool printspecies(std::ostream & o, bool first) const;
void printnorm(std::ostream & o)const;
void printweigh(std::ostream & o)const;
void coeff( fraction f);
bool printNernst(std::ostream & o, const char * prefix ="");
bool printNernstWIMS(std::ostream & o, bool wantedlatex);
bool iswater()const;
bool iselectron()const;
fraction nbelectron()const;
void debug(int decal = 0)const{
for (int i=0; i < decal; i++) std::cout << " ";
std::cout << "Molec : ( " << this << " charge = " << ch
<< " nombre = " << nb << " no = " << no;
al->debug(decal+2);
std::cout << ")\n";
};
// two Molecs are equal if the AtomLists and the charges are equal.
friend Membre operator & (Membre & m1, Membre & m2);
friend Membre operator - (Membre & m1, Membre & m2);
};
std::ostream & operator << (std::ostream & o, const AtomeListe & l);
std::ostream & operator << (std::ostream & o, const Molec & m);
class Membre : public std::vector<Molec *>{
public:
int findMol(const Molec *);
void addMol(const Molec *);
void addMembre(const Membre *);
void eraseNull();
void compte(Compteur & c)const;
void numerote();
void triage();
void printnorm(std::ostream & o) const;
void printcount(std::ostream & o) const;
void printelec(std::ostream & o) const;
void printspecies(std::ostream & o) const;
void printweight(std::ostream & o) const;
void coeff( fraction f);
void printNernst(std::ostream & o);
void printNernstWIMS(std::ostream & o, bool wantedlatex);
int printableNernst();
bool redox()const;
fraction nbelectron()const;
void debug(int decal = 0)const{
for (int i=0; i < decal; i++) std::cout << " ";
std::cout << "Membre : ( " << this;
for (int j=0; j < size(); j++){
std::cout << j << " :\n";
operator[](j)->debug(decal+2);
}
std::cout << "\n";
}
};
// intersection between two Membres
Membre operator & (Membre & m1, Membre & m2);
// members of first set which are not in the second
Membre operator - (Membre & m1, Membre & m2);
std::ostream & operator << (std::ostream & o, const Membre & m);
class Chemeq{
Membre * gauche, * droit;
std::string cste;
long double val;
public:
Chemeq(Membre * g, Membre * d) : gauche (g), droit(d), val(MINVAL){};
const Membre * membredroit()const{return droit;};
const Membre * membregauche()const{return gauche;};
void addChemeq(const Chemeq *);
void subChemeq(const Chemeq *);
void simplifie(bool tri);
void numerote(){gauche->numerote(); droit->numerote();};
void triage(){gauche->triage(); droit->triage();};
/* ajuste le coefficient pour qu'il y ait 1 mol du premier réactif */
void coeff1();
/* mutiplie par la fraction num/den */
void multiply(int num, int den);
fraction nbelectron()const{return gauche->nbelectron()-droit->nbelectron();};
/* renvoie val ou nbelectron()*Faraday*val */
long double enthalpy() const;
void normalise(){numerote(); triage(); coeff1();};
void printnorm(std::ostream & o);
void printcount(std::ostream & o) const;
void printelec(std::ostream & o) const;
void printspecies(std::ostream & o) const;
void printweight(std::ostream & o) const;
void printNernst(std::ostream & o, std::ostream & w, bool wantedlatex=false);
std::string equilibre();
bool redox()const;
const std::st