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 | // |
---|
13 | // Former revisions: |
---|
14 | // ----------------------- |
---|
15 | // Deleted $Id since document_changes does not work for C and C++ (15.03.2019, forkel) |
---|
16 | // |
---|
17 | // global_subtolower (June 2018, forkel) |
---|
18 | // |
---|
19 | // initial version (Nov. 2016, ketelsen) |
---|
20 | // |
---|
21 | |
---|
22 | |
---|
23 | #include "program_line.h" |
---|
24 | |
---|
25 | void program_line::set_line(string s) { |
---|
26 | |
---|
27 | line = s; |
---|
28 | |
---|
29 | tokens.fill_token(line); |
---|
30 | |
---|
31 | return; |
---|
32 | } |
---|
33 | void program_line::substitute(string old_s, string new_s) { |
---|
34 | |
---|
35 | int pos = line.find (old_s, 0); // look for string |
---|
36 | |
---|
37 | if (pos != string::npos) { // found |
---|
38 | line.replace(pos,old_s.size(),new_s); |
---|
39 | } |
---|
40 | |
---|
41 | return; |
---|
42 | } |
---|
43 | |
---|
44 | void program_line::global_substitute(string old_s, string new_s) { |
---|
45 | int pos; |
---|
46 | |
---|
47 | int start = line.size()-1; |
---|
48 | |
---|
49 | while (1) { |
---|
50 | pos = line.rfind (old_s, start); // look for string |
---|
51 | |
---|
52 | if (pos == string::npos) { |
---|
53 | break; |
---|
54 | } |
---|
55 | |
---|
56 | line.replace(pos,old_s.size(),new_s); |
---|
57 | |
---|
58 | start = pos-1; |
---|
59 | } |
---|
60 | |
---|
61 | return; |
---|
62 | } |
---|
63 | |
---|
64 | int program_line::get_token_number_from_string (string s) { |
---|
65 | |
---|
66 | for (int i=0; i<tokens.size(); i++) { |
---|
67 | if(tokens.get_token_by_index(i) == s) { |
---|
68 | return i; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return -1; |
---|
73 | } |
---|
74 | |
---|
75 | int program_line::get_token_number_from_string_upper (string s) { |
---|
76 | |
---|
77 | string s1 = my_to_upper(s); |
---|
78 | for (int i=0; i<tokens.size(); i++) { |
---|
79 | if(my_to_upper(tokens.get_token_by_index(i)) == s1) { |
---|
80 | return i; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | return -1; |
---|
85 | } |
---|
86 | |
---|
87 | void program_line::update_token (int i, string s) { |
---|
88 | |
---|
89 | string s_old=tokens.get_token_by_index(i); |
---|
90 | tokens.update (i,s); |
---|
91 | int pos=tokens.get_position(i); |
---|
92 | line.replace(pos,s_old.size(),s); |
---|
93 | |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | void program_line::change_variable_to_vector (string var) { |
---|
98 | string U_token; |
---|
99 | |
---|
100 | int ind = tokens.size()-2; |
---|
101 | for (int i=ind; i >= 0; i--) { |
---|
102 | U_token.clear(); |
---|
103 | U_token = my_to_upper(tokens.get_token_by_index(i)); |
---|
104 | if(U_token == my_to_upper(var) && tokens.get_token_by_index(i+1) == "(" ) { |
---|
105 | string new_s="(1:VL,"; |
---|
106 | tokens.update (i+1,new_s); |
---|
107 | int pos=tokens.get_position(i+1); |
---|
108 | line.replace(pos,1,new_s); |
---|
109 | tokens.reset (line); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | return; |
---|
114 | } |
---|
115 | |
---|
116 | void program_line::change_variable_to_vector_g (Vvar &var) { |
---|
117 | string U_token; |
---|
118 | string new_s; |
---|
119 | |
---|
120 | tokens.reset (line); |
---|
121 | |
---|
122 | int ind = tokens.size()-2; |
---|
123 | for (int i=ind; i >= 0; i--) { |
---|
124 | U_token.clear(); |
---|
125 | U_token = tokens.get_token_by_index(i); |
---|
126 | if(var.nr_dim() == 0) { |
---|
127 | if(my_to_upper(U_token) == my_to_upper(var.name) ) { |
---|
128 | new_s=U_token + "(k)"; |
---|
129 | tokens.update (i,new_s); |
---|
130 | int pos=tokens.get_position(i); |
---|
131 | line.replace(pos,U_token.size(),new_s); |
---|
132 | tokens.reset (line); |
---|
133 | } |
---|
134 | } else { |
---|
135 | if(my_to_upper(U_token) == my_to_upper(var.name) && tokens.get_token_by_index(i+1) == "(" ) { |
---|
136 | new_s="(k,"; |
---|
137 | tokens.update (i+1,new_s); |
---|
138 | int pos=tokens.get_position(i+1); |
---|
139 | line.replace(pos,1,new_s); |
---|
140 | tokens.reset (line); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | return; |
---|
146 | } |
---|
147 | void program_line::global_subtolower(string &line) { |
---|
148 | |
---|
149 | int start = line.size()-1; |
---|
150 | char c; |
---|
151 | |
---|
152 | int i = 0; |
---|
153 | while (line[i]) |
---|
154 | { |
---|
155 | c = line[i]; |
---|
156 | line[i] = tolower(c); |
---|
157 | i++; |
---|
158 | } |
---|
159 | return; |
---|
160 | } |
---|
161 | |
---|