1 | |
---|
2 | // ############################################################################ |
---|
3 | // |
---|
4 | // create_mz_kpp_module |
---|
5 | // |
---|
6 | // create vectorcode from .90 sources created by KPP to be used in MESSy |
---|
7 | // |
---|
8 | // COPYRIGHT Klaus Ketelsen and MPI-CH April 2007 |
---|
9 | // |
---|
10 | // ############################################################################ |
---|
11 | |
---|
12 | #include <fstream> |
---|
13 | #include "fortran_file.h" |
---|
14 | |
---|
15 | #include "utils.h" |
---|
16 | |
---|
17 | |
---|
18 | void fortran_file::edit_inc_vec (vector<string> &gvl) { |
---|
19 | vector<program_line>::iterator ip; |
---|
20 | vector<string>::iterator ig; |
---|
21 | |
---|
22 | cout << "Handling include: " <<name <<endl; |
---|
23 | |
---|
24 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
25 | if(ip->get_token(0) == "REAL") { |
---|
26 | int pos = ip->get_token_number_from_string("::"); |
---|
27 | if(pos > 1) { |
---|
28 | pos ++; |
---|
29 | for (ig=gvl.begin(); ig != gvl.end(); ig++) { |
---|
30 | string var_name = *ig; |
---|
31 | if(ip->get_token(pos) == var_name) { |
---|
32 | ip->update_token(pos+1,"(VL_DIM,"); |
---|
33 | } |
---|
34 | } |
---|
35 | } |
---|
36 | } |
---|
37 | if(ip->get_token(0) == "EQUIVALENCE" && ip->get_token(2) == "C" ) { |
---|
38 | ip->update_token(3,"(1,"); |
---|
39 | ip->update_token(9,"(1,"); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | return; |
---|
44 | } |
---|
45 | |
---|
46 | void fortran_file::global_variables2vector (vector<string> &gvl) { |
---|
47 | vector<program_line>::iterator ip; |
---|
48 | vector<string>::iterator ig; |
---|
49 | |
---|
50 | cout << "Handling subroutine: " <<name <<endl; |
---|
51 | |
---|
52 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
53 | for (ig=gvl.begin(); ig != gvl.end(); ig++) { |
---|
54 | string var_name = *ig; |
---|
55 | ip->change_variable_to_vector (var_name); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | void fortran_file::edit_Update_RCONST (vector <Vvar> &var_list) { |
---|
63 | vector<program_line>::iterator ip; |
---|
64 | vector<Vvar>::iterator iv; |
---|
65 | string lo_line; |
---|
66 | |
---|
67 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
68 | ip->global_substitute ("*"," *"); |
---|
69 | ip->global_substitute ("* *","**"); |
---|
70 | ip->global_substitute (","," , "); |
---|
71 | ip->global_substitute ("/"," / "); |
---|
72 | ip->global_substitute ("1:VL","j"); |
---|
73 | } |
---|
74 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
75 | for (iv=var_list.begin(); iv != var_list.end(); iv++) { |
---|
76 | ip->change_variable_to_vector_g (*iv); |
---|
77 | } |
---|
78 | } |
---|
79 | ip = pline.begin()+1 ; |
---|
80 | lo_line = ip->get_line() ; |
---|
81 | lo_line.erase(); |
---|
82 | lo_line = " INTEGER :: j,k"; |
---|
83 | ip->set_line(lo_line); |
---|
84 | |
---|
85 | if(kpp_switches.is_vector() ) { |
---|
86 | ip = pline.begin()+2 ; |
---|
87 | lo_line = ip->get_line() ; |
---|
88 | lo_line.erase(); |
---|
89 | lo_line = " do k=is,ie"; |
---|
90 | ip->set_line(lo_line); |
---|
91 | |
---|
92 | ip = pline.begin()+3 ; |
---|
93 | lo_line = ip->get_line() ; |
---|
94 | lo_line.erase(); |
---|
95 | lo_line = " j = k-is+1"; |
---|
96 | ip->set_line(lo_line); |
---|
97 | |
---|
98 | ip = pline.end()-2 ; |
---|
99 | lo_line = ip->get_line() ; |
---|
100 | lo_line.erase(); |
---|
101 | lo_line = " end do"; |
---|
102 | ip->set_line(lo_line); |
---|
103 | } else { |
---|
104 | ip = pline.begin()+3 ; |
---|
105 | lo_line = ip->get_line() ; |
---|
106 | lo_line.erase(); |
---|
107 | lo_line = " k = is"; |
---|
108 | ip->set_line(lo_line); |
---|
109 | } |
---|
110 | |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | void fortran_file::edit_KppDecomp () { |
---|
116 | |
---|
117 | vector<program_line>::iterator ip; |
---|
118 | string lo_line; |
---|
119 | |
---|
120 | bool declaration = true; |
---|
121 | |
---|
122 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
123 | |
---|
124 | if(ip->get_token(0) == "IER") { |
---|
125 | declaration = false; |
---|
126 | } |
---|
127 | if ( declaration ) { |
---|
128 | if(ip->get_token(0) == "REAL") { |
---|
129 | lo_line = ip->get_line() ; |
---|
130 | lo_line.erase(); |
---|
131 | if(kpp_switches.de_indexing () == 2) { |
---|
132 | lo_line = " REAL(kind=dp) :: JVS(:,:), a(VL)"; |
---|
133 | } else { |
---|
134 | lo_line = " REAL(kind=dp) :: JVS(:,:), W(VL,NVAR), a(VL)"; |
---|
135 | } |
---|
136 | ip->set_line(lo_line); |
---|
137 | } |
---|
138 | |
---|
139 | } else { |
---|
140 | ip->change_variable_to_vector ("W"); |
---|
141 | ip->change_variable_to_vector ("JVS"); |
---|
142 | |
---|
143 | if(ip->get_token(0) == "IF" || ip->get_token(1) == "IF") { |
---|
144 | lo_line = ip->get_line() ; |
---|
145 | lo_line.insert(0,"! Not in vector Mode "); |
---|
146 | ip->set_line(lo_line); |
---|
147 | } |
---|
148 | if(ip->get_token(0) == "IER" && ip->get_token(2) == "k") { |
---|
149 | lo_line = ip->get_line() ; |
---|
150 | lo_line.insert(0,"! Not in vector Mode "); |
---|
151 | ip->set_line(lo_line); |
---|
152 | } |
---|
153 | if(ip->get_token(0) == "RETURN") { |
---|
154 | lo_line = ip->get_line() ; |
---|
155 | lo_line.insert(0,"! Not in vector Mode "); |
---|
156 | ip->set_line(lo_line); |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | return; |
---|
162 | } |
---|
163 | |
---|
164 | void fortran_file::edit_KppSolve () { |
---|
165 | |
---|
166 | vector<program_line>::iterator ip; |
---|
167 | |
---|
168 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
169 | if(ip->get_token(0) == "REAL") { |
---|
170 | ip->substitute("NVAR",":,:"); |
---|
171 | ip->substitute("LU_NONZERO",":,:"); |
---|
172 | } else { |
---|
173 | ip->change_variable_to_vector ("JVS"); |
---|
174 | ip->change_variable_to_vector ("X"); |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | return; |
---|
179 | } |
---|
180 | |
---|
181 | void fortran_file::edit_Jac_SP () { |
---|
182 | |
---|
183 | vector<program_line>::iterator ip; |
---|
184 | string lo_line; |
---|
185 | |
---|
186 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
187 | if(ip->get_token(0) == "REAL") { |
---|
188 | ip->substitute("NVAR",":,:"); |
---|
189 | ip->substitute("NFIX",":,:"); |
---|
190 | ip->substitute("NREACT",":,:"); |
---|
191 | ip->substitute("LU_NONZERO",":,:"); |
---|
192 | if(ip->get_token(5) == "B") { |
---|
193 | lo_line = ip->get_line() ; |
---|
194 | lo_line.erase(); |
---|
195 | lo_line = " REAL(kind=dp) :: B(VL," +ip->get_token(7) +")"; |
---|
196 | ip->set_line(lo_line); |
---|
197 | } |
---|
198 | } else { |
---|
199 | ip->change_variable_to_vector ("V"); |
---|
200 | ip->change_variable_to_vector ("F"); |
---|
201 | ip->change_variable_to_vector ("B"); |
---|
202 | ip->change_variable_to_vector ("RCT"); |
---|
203 | ip->change_variable_to_vector ("JVS"); |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | return; |
---|
208 | } |
---|
209 | |
---|
210 | void fortran_file::edit_Fun () { |
---|
211 | |
---|
212 | vector<program_line>::iterator ip; |
---|
213 | |
---|
214 | bool declaration = true; |
---|
215 | |
---|
216 | for (ip=pline.begin(); ip != pline.end(); ip++) { |
---|
217 | |
---|
218 | if(ip->get_token(1) == "Computation" || ip->get_token(1) == "Told" ) { |
---|
219 | declaration = false; |
---|
220 | } |
---|
221 | if ( declaration ) { |
---|
222 | if(ip->get_token(0) == "REAL") { |
---|
223 | ip->substitute("NVAR",":,:"); |
---|
224 | ip->substitute("NFIX",":,:"); |
---|
225 | ip->substitute("NREACT",":,:"); |
---|
226 | } |
---|
227 | } else { |
---|
228 | ip->change_variable_to_vector ("V"); |
---|
229 | ip->change_variable_to_vector ("F"); |
---|
230 | ip->change_variable_to_vector ("RCT"); |
---|
231 | ip->change_variable_to_vector ("Vdot"); |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | return; |
---|
236 | } |
---|
237 | |
---|