Subversion Repositories wimsdev

Rev

Rev 4351 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
!if $wims_read_parm!=slib_header
13594 bpr 2
  !goto proc
20 reyssat 3
!endif
4158 bpr 4
 
4351 bpr 5
slib_author=Georges, Khaznadar
20 reyssat 6
slib_license=GPL
4158 bpr 7
 
20 reyssat 8
slib_example= H2_g + O2_g -> H2O, state, html \
9
H2_g + O2_g -> H2O \
10
H2_g + 1/2O2_g -> H2O, nostate, html \
11
H2_g + 1/2O2_g -> H2O, nostate \
12
BH3_s + 3H2O -> B(OH)3 + 3H2_g, state, html\
13
MnO4^- + 8H^+ + 5e^- -> Mn^2+ + 4H2O, nostate, html \
14
MnO4^- + 8H^+ + 5e^- -> Mn^2+ + 4H2O
3265 bpr 15
slib_require=chemeq
20 reyssat 16
!exit
17
 
18
:proc
19
 
20
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21
!! first check the version of chemeq
22
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23
chemeq_option=v
24
slib_out=!exec chemeq
25
!reset chemeq_option
26
slib_out=!line 1 of $slib_out
27
slib_out=!replace .*version. by $empty in $slib_out
28
!if $slib_out < 1.119999
29
  slib_out=Warning! the version of chemeq is $slib_out (<< 1.12), \
30
install a newer version of this program (at least the version 1.12).
31
  !goto end
32
!endif
33
 
34
!reset slib_parm, slib_eq, slib_format, slib_rep, slib_left, slib_right, \
35
slib_w, slib_l, slib_r, slib_mol_l, slib_elcount, slib_el, slib_eln, slib_i, \
36
slib_j, slib_atomlist, slib_a, slib_debug, slib_atom, slib_stoe, slib_arity, \
37
slib_stoechiometry, slib_phrase, slib_latex, slib_state, slib_charge, \
38
slib_chleft, slib_chright, slib_c, slib_ion
39
 
40
slib_stoechiometry= Stoech.,
41
slib_latex= Equation,
42
 
43
slib_parm=!item 1 to 3 of $wims_read_parm
44
!distribute item $slib_parm into slib_eq, slib_state, slib_format
45
 
46
!default slib_state state
47
!default slib_format matrix
48
 
49
chemeq_option=C
50
slib_rep=!exec chemeq $slib_eq
51
chemeq_option=e
52
slib_charge=!exec chemeq $slib_eq
53
!reset chemeq_option
54
 
55
slib_left=$(slib_rep[1;])
56
slib_right=$(slib_rep[2;])
57
slib_chleft=$(slib_charge[1;])
58
slib_chright=$(slib_charge[2;])
59
slib_ion=
60
 
61
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62
!! collect the elements
63
!! result in the sorted list slib_el
64
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65
slib_el=!replace ^[^|]*| by $empty in $slib_rep
66
slib_el=!replace :[^ ]* by $empty in $slib_el
67
slib_el=!replace [ ][^ ]*| by , in $slib_el
68
slib_el=!replace [0-9/]* by $empty in $slib_el
69
slib_el=!replace [ ()] by , in $slib_el
70
slib_el=!sort list $slib_el
71
slib_el=!listuniq $slib_el
72
!! remove electrons
73
slib_i=
74
!for slib_j in $slib_el
75
  !if $slib_j != e
76
    slib_i=$slib_i$empty$slib_j,
77
  !endif
78
!next slib_j
79
slib_el=$(slib_i[1..-2])
80
!! count the number of elements
81
slib_eln=!itemcnt $slib_el
82
 
83
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
84
!! define variables bound to each element
85
!! like slib_arity_Na, slib_arity_H, slib_total_Fe, etc.
86
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87
!for slib_i in $slib_el
88
  !reset slib_arity_$(slib_i)
89
  !reset slib_total_$(slib_i)
90
  slib_arity_$(slib_i)=$(slib_i)_arity,
91
  slib_total_$(slib_i)=$(slib_i)_total,
92
!next slib_i
93
 
94
!reset slib_arity_ch
95
!reset slib_total_ch
96
slib_arity_ch=Charge_arity,
97
slib_total_ch=Charge_total,
98
 
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
100
!! Deal with the left side of the equation
101
!! slib_l will be the count of molecules on the left side
102
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
103
slib_l=0
104
slibmol_l=
105
!for slib_w in $slib_left
106
  slib_molcomp=!replace internal | by , in $slib_w
107
  slib_mol_l= $slib_mol_l $(slib_molcomp[1]),
108
  slib_i=!replace ^[ 0-9/]* by $empty in $(slib_molcomp[1])
109
  !if $slib_state = nostate
110
    slib_i=!replace _.* by $empty in $slib_i
111
  !endif
112
  slib_j=!replace [eA-Z].* by $empty in $(slib_molcomp[1])
113
  chemeq_option=l
114
  slib_i=!exec chemeq $slib_i
115
  !reset chemeq_option
116
  slib_latex=$slib_latex $slib_j $slib_i,
117
  slib_atomlist=!words2list $(slib_molcomp[2])
118
  !for slib_i in $slib_el
119
    slib_arity_local_$(slib_i)=0
120
  !next slib_i
121
  !for slib_a in $slib_atomlist
122
    slib_a=!replace [*:] by , in $slib_a
123
    !distribute item $slib_a into slib_atom, slib_stoe, slib_arity
124
    slib_arity_local_$(slib_atom)=$slib_arity
125
  !next slib_a
126
  slib_stoechiometry=$slib_stoechiometry $slib_stoe,
127
  !for slib_i in $slib_el
128
    slib_arity_$(slib_i)= $(slib_arity_$(slib_i)) $(slib_arity_local_$(slib_i)),
129
    slib_total_$(slib_i)= $(slib_total_$(slib_i)) $[$slib_stoe * $(slib_arity_local_$(slib_i))],
130
  !next slib_i
131
  slib_l=!eval $slib_l + 1
132
!next slib_w
133
 
134
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
135
!! now once more for the charges
136
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
137
slib_c=2
138
!for slib_w in $slib_chleft
139
  slib_i=!replace internal | by , in $slib_w
140
  slib_i=!replace internal * by , in $slib_i
141
  slib_arity_ch=$slib_arity_ch $(slib_i[3]),
142
  !if $(slib_i[3]) != 0
143
    slib_ion=yes
144
  !endif
145
  slib_debug=$slib_debug --- $slib_i
146
  slib_total_ch=$slib_total_ch $[$(slib_stoechiometry[$slib_c]) * ($(slib_i[3]))],
147
  slib_c=!eval $slib_c + 1
148
!next slib_w
149
 
150
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
151
!! add one colum to separate left and right side
152
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
153
slib_latex=$slib_latex \rightarrow,
154
slib_stoechiometry=$slib_stoechiometry %,
155
slib_arity_ch=$slib_arity_ch %,
156
slib_total_ch=$slib_total_ch %,
157
slib_c=!eval $slib_c + 1
158
!for slib_i in $slib_el
159
  slib_arity_$(slib_i)= $(slib_arity_$(slib_i)) %,
160
  slib_total_$(slib_i)=$(slib_total_$(slib_i)) %,
161
!next slib_i
162
 
163
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
164
!! Deal with the right side of the equation
165
!! slib_r will be the count of molecules on the right side
166
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
167
slib_r=0
168
slibmol_r=
169
!for slib_w in $slib_right
170
  slib_molcomp=!replace internal | by , in $slib_w
171
  slib_mol_l= $slib_mol_l $(slib_molcomp[1]),
172
  slib_i=!replace ^[ 0-9/]* by $empty in $(slib_molcomp[1])
173
  !if $slib_state = nostate
174
    slib_i=!replace _.* by $empty in $slib_i
175
  !endif
176
  slib_j=!replace [A-Z].* by $empty in $(slib_molcomp[1])
177
  chemeq_option=l
178
  slib_i=!exec chemeq $slib_i
179
  !reset chemeq_option
180
  slib_latex=$slib_latex $slib_j $slib_i,
181
  slib_atomlist=!words2list $(slib_molcomp[2])
182
  !for slib_i in $slib_el
183
    slib_arity_local_$(slib_i)=0
184
  !next slib_i
185
  !for slib_a in $slib_atomlist
186
    slib_a=!replace [*:] by , in $slib_a
187
    !distribute item $slib_a into slib_atom, slib_stoe, slib_arity
188
    slib_arity_local_$(slib_atom)=$slib_arity
189
  !next slib_a
190
  slib_stoechiometry=$slib_stoechiometry $slib_stoe,
191
  !for slib_i in $slib_el
192
    slib_arity_$(slib_i)= $(slib_arity_$(slib_i)) $(slib_arity_local_$(slib_i)),
193
    slib_total_$(slib_i)= $(slib_total_$(slib_i)) $[$slib_stoe * $(slib_arity_local_$(slib_i))],
194
  !next slib_i
195
  slib_r=!eval $slib_r + 1
196
!next slib_w
197
 
198
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
199
!! now once more for the charges
200
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
201
!for slib_w in $slib_chright
202
  slib_i=!replace internal | by , in $slib_w
203
  slib_i=!replace internal * by , in $slib_i
204
  slib_arity_ch=$slib_arity_ch $(slib_i[3]),
205
  !if $(slib_i[3]) != 0
206
    slib_ion=yes
207
  !endif
208
  slib_debug=$slib_debug --- $slib_i
209
  slib_total_ch=$slib_total_ch $[$(slib_stoechiometry[$slib_c]) * ($(slib_i[3]))],
210
  slib_c=!eval $slib_c + 1
211
!next slib_w
212
 
213
!if $slib_format = html
214
slib_phrase=<table border=1>
215
  slib_latex=$(slib_latex[1 to -2])
216
  slib_latex=!replace , by </td><td> in $slib_latex
217
  slib_phrase=$slib_phrase <tr> <td>$slib_latex</td> </tr>
218
  slib_stoechiometry=$(slib_stoechiometry[1 to -2])
219
  slib_stoechiometry=!replace , by </td><td> in $slib_stoechiometry
220
  slib_phrase=$slib_phrase <tr> <td>$slib_stoechiometry</td> </tr>
221
  !for slib_i in $slib_el
222
    slib_arity_$(slib_i)=$(slib_arity_$(slib_i)[1 to -2])
223
    slib_arity_$(slib_i)=!replace , by </td><td> in $(slib_arity_$(slib_i))
224
    slib_phrase=$slib_phrase <tr> <td>$(slib_arity_$(slib_i))</td> </tr>
225
    slib_total_$(slib_i)=$(slib_total_$(slib_i)[1 to -2])
226
    slib_total_$(slib_i)=!replace , by </td><td> in $(slib_total_$(slib_i))
227
    slib_phrase=$slib_phrase <tr> <td>$(slib_total_$(slib_i))</td> </tr>
228
  !next slib_i
229
  !if $slib_ion = yes
230
    slib_total_ch=$(slib_total_ch[1 to -2])
231
    slib_total_ch=!replace , by </td><td> in $slib_total_ch
232
    slib_phrase=$slib_phrase <tr> <td>$slib_total_ch</td> </tr>
233
  !endif
234
  slib_phrase=$slib_phrase </table>
235
!else
236
  slib_phrase=$slib_phrase $slib_latex;
237
  slib_phrase=$slib_phrase $slib_stoechiometry;
238
  !for slib_i in $slib_el
239
    slib_phrase=$slib_phrase $(slib_arity_$(slib_i));
240
    slib_phrase=$slib_phrase $(slib_total_$(slib_i));
241
  !next slib_i
242
  !if $slib_ion = yes
243
    slib_phrase=$slib_phrase $slib_total_ch;
244
  !endif
245
  !! cuts the excess separators in the matrix
246
  slib_phrase=$(slib_phrase[1..-1;1..-2])
247
!endif
248
 
249
slib_out=$slib_phrase
250
 
13594 bpr 251
:end