1 | /******************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
4 | /* */ |
---|
5 | /* Copyright or or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
6 | /* Cyril Mazauric (Cyril_Mazauric@yahoo.fr) */ |
---|
7 | /* This software is governed by the CeCILL-C license under French law and */ |
---|
8 | /* abiding by the rules of distribution of free software. You can use, */ |
---|
9 | /* modify and/ or redistribute the software under the terms of the CeCILL-C */ |
---|
10 | /* license as circulated by CEA, CNRS and INRIA at the following URL */ |
---|
11 | /* "http://www.cecill.info". */ |
---|
12 | /* */ |
---|
13 | /* As a counterpart to the access to the source code and rights to copy, */ |
---|
14 | /* modify and redistribute granted by the license, users are provided only */ |
---|
15 | /* with a limited warranty and the software's author, the holder of the */ |
---|
16 | /* economic rights, and the successive licensors have only limited */ |
---|
17 | /* liability. */ |
---|
18 | /* */ |
---|
19 | /* In this respect, the user's attention is drawn to the risks associated */ |
---|
20 | /* with loading, using, modifying and/or developing or reproducing the */ |
---|
21 | /* software by the user in light of its specific status of free software, */ |
---|
22 | /* that may mean that it is complicated to manipulate, and that also */ |
---|
23 | /* therefore means that it is reserved for developers and experienced */ |
---|
24 | /* professionals having in-depth computer knowledge. Users are therefore */ |
---|
25 | /* encouraged to load and test the software's suitability as regards their */ |
---|
26 | /* requirements in conditions enabling the security of their systems and/or */ |
---|
27 | /* data to be ensured and, more generally, to use and operate it in the */ |
---|
28 | /* same conditions as regards security. */ |
---|
29 | /* */ |
---|
30 | /* The fact that you are presently reading this means that you have had */ |
---|
31 | /* knowledge of the CeCILL-C license and that you accept its terms. */ |
---|
32 | /******************************************************************************/ |
---|
33 | /* version 1.7 */ |
---|
34 | /******************************************************************************/ |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <string.h> |
---|
38 | #include "decl.h" |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | /******************************************************************************/ |
---|
44 | /* FindAndChangeNameToTabvars */ |
---|
45 | /******************************************************************************/ |
---|
46 | /* */ |
---|
47 | /******************************************************************************/ |
---|
48 | /* if whichone = 0 ----> Agrif_tabvars(i) % array2 */ |
---|
49 | /* */ |
---|
50 | /* if whichone = 1 ----> Agrif_tabvars(i) % parentvar % array2 */ |
---|
51 | /* */ |
---|
52 | /******************************************************************************/ |
---|
53 | void FindAndChangeNameToTabvars(const char name[LONG_M],char toprint[LONG_M], |
---|
54 | listvar * listtosee, int whichone) |
---|
55 | { |
---|
56 | listvar *newvar; |
---|
57 | int out; |
---|
58 | |
---|
59 | |
---|
60 | if ( strcasecmp(name,"") ) |
---|
61 | { |
---|
62 | newvar=listtosee; |
---|
63 | out=0; |
---|
64 | while( newvar && out == 0 ) |
---|
65 | { |
---|
66 | if ( !strcasecmp(newvar->var->v_nomvar,name) ) |
---|
67 | { |
---|
68 | |
---|
69 | if ( LookingForVariableInListName( |
---|
70 | List_SubroutineArgument_Var,name) == 0 ) |
---|
71 | { |
---|
72 | out = 1; |
---|
73 | strcat(toprint,vargridcurgridtabvars(newvar->var, whichone)); |
---|
74 | } |
---|
75 | else newvar=newvar->suiv; |
---|
76 | } |
---|
77 | else newvar=newvar->suiv; |
---|
78 | } |
---|
79 | if ( out == 0 ) strcat(toprint,name); |
---|
80 | } |
---|
81 | Save_Length(toprint,44); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /******************************************************************************/ |
---|
86 | /* ChangeTheInitalvaluebyTabvarsName */ |
---|
87 | /******************************************************************************/ |
---|
88 | /* */ |
---|
89 | /******************************************************************************/ |
---|
90 | /* */ |
---|
91 | /* */ |
---|
92 | /* */ |
---|
93 | /******************************************************************************/ |
---|
94 | const char *ChangeTheInitalvaluebyTabvarsName(const char *nom, listvar *listtoread) |
---|
95 | { |
---|
96 | char toprinttmp[LONG_M]; |
---|
97 | char chartmp[2]; |
---|
98 | size_t i = 0; |
---|
99 | |
---|
100 | strcpy(toprintglob, ""); |
---|
101 | strcpy(toprinttmp, ""); |
---|
102 | |
---|
103 | while ( i < strlen(nom) ) |
---|
104 | { |
---|
105 | if ( (nom[i] == '+') || (nom[i] == '-') || (nom[i] == '*') || (nom[i] == '/') || |
---|
106 | (nom[i] == '(') || (nom[i] == ')') || (nom[i] == ':') || (nom[i] == ',') ) |
---|
107 | { |
---|
108 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,0); |
---|
109 | strcpy(toprinttmp, ""); |
---|
110 | sprintf(chartmp, "%c", nom[i]); |
---|
111 | strcat(toprintglob, chartmp); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | sprintf(chartmp, "%c", nom[i]); |
---|
116 | strcat(toprinttmp, chartmp); |
---|
117 | } |
---|
118 | i += 1; |
---|
119 | } |
---|
120 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,0); |
---|
121 | strcpy(toprinttmp,""); |
---|
122 | |
---|
123 | Save_Length(toprinttmp,44); |
---|
124 | Save_Length(toprintglob,39); |
---|
125 | |
---|
126 | return toprintglob; |
---|
127 | } |
---|
128 | |
---|
129 | /******************************************************************************/ |
---|
130 | /* IsVariableReal */ |
---|
131 | /******************************************************************************/ |
---|
132 | /* */ |
---|
133 | /******************************************************************************/ |
---|
134 | /* */ |
---|
135 | /* */ |
---|
136 | /* */ |
---|
137 | /******************************************************************************/ |
---|
138 | int IsVariableReal(const char *nom) |
---|
139 | { |
---|
140 | return ( ( nom[0] >= 'a' && nom[0] <= 'h' ) || |
---|
141 | ( nom[0] >= 'A' && nom[0] <= 'H' ) || |
---|
142 | ( nom[0] >= 'o' && nom[0] <= 'z' ) || |
---|
143 | ( nom[0] >= 'O' && nom[0] <= 'Z' ) ); |
---|
144 | } |
---|
145 | /******************************************************************************/ |
---|
146 | /* IsVarInUseFile */ |
---|
147 | /******************************************************************************/ |
---|
148 | /* */ |
---|
149 | /******************************************************************************/ |
---|
150 | /* */ |
---|
151 | /* */ |
---|
152 | /* */ |
---|
153 | /******************************************************************************/ |
---|
154 | void IsVarInUseFile(const char *nom) |
---|
155 | { |
---|
156 | listvar *parcours; |
---|
157 | listparameter *parcoursparam; |
---|
158 | int out; |
---|
159 | |
---|
160 | out = 0; |
---|
161 | |
---|
162 | parcours = List_Global_Var; |
---|
163 | while( parcours && out == 0 ) |
---|
164 | { |
---|
165 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ; |
---|
166 | else parcours=parcours->suiv; |
---|
167 | } |
---|
168 | if ( out == 0 ) |
---|
169 | { |
---|
170 | parcours = List_Common_Var; |
---|
171 | while( parcours && out == 0 ) |
---|
172 | { |
---|
173 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ; |
---|
174 | else parcours=parcours->suiv; |
---|
175 | } |
---|
176 | } |
---|
177 | if ( out == 0 ) |
---|
178 | { |
---|
179 | parcours = List_GlobalParameter_Var; |
---|
180 | while( parcours && out == 0 ) |
---|
181 | { |
---|
182 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
183 | else parcours=parcours->suiv; |
---|
184 | } |
---|
185 | } |
---|
186 | if ( out == 0 ) |
---|
187 | { |
---|
188 | parcours = List_Parameter_Var; |
---|
189 | while( parcours && out == 0 ) |
---|
190 | { |
---|
191 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 1 ; |
---|
192 | else parcours=parcours->suiv; |
---|
193 | } |
---|
194 | } |
---|
195 | if ( out == 0 ) |
---|
196 | { |
---|
197 | parcoursparam = List_GlobParamModuleUsed_Var; |
---|
198 | while( parcoursparam && out == 0 ) |
---|
199 | { |
---|
200 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out = 2 ; |
---|
201 | else parcoursparam=parcoursparam->suiv; |
---|
202 | } |
---|
203 | } |
---|
204 | if ( out == 0 ) |
---|
205 | { |
---|
206 | parcours = List_ModuleUsed_Var; |
---|
207 | while( parcours && out == 0 ) |
---|
208 | { |
---|
209 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out = 2 ; |
---|
210 | else parcours=parcours->suiv; |
---|
211 | } |
---|
212 | } |
---|
213 | if ( out == 0 || out == 2 ) |
---|
214 | { |
---|
215 | parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var; |
---|
216 | while( parcoursparam && out != 1 ) |
---|
217 | { |
---|
218 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out = 1 ; |
---|
219 | else parcoursparam=parcoursparam->suiv; |
---|
220 | } |
---|
221 | if ( out == 1 ) |
---|
222 | { |
---|
223 | strcpy(charusemodule,parcoursparam->p_modulename); |
---|
224 | Addmoduletothelist(parcoursparam->p_modulename); |
---|
225 | } |
---|
226 | } |
---|
227 | if ( out == 0 && |
---|
228 | strcasecmp(nom,"MAX") && |
---|
229 | strcasecmp(nom,"mpi_status_size") |
---|
230 | ) |
---|
231 | { |
---|
232 | /* printf("--- in UtilCharacter we do not found the \n"); |
---|
233 | printf("--- variable %s, the module where this \n",nom); |
---|
234 | printf("--- variable has been defined has not been\n"); |
---|
235 | printf("--- found.\n");*/ |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | /******************************************************************************/ |
---|
240 | /* DecomposeTheNameinlistnom */ |
---|
241 | /******************************************************************************/ |
---|
242 | /* Firstpass 0 */ |
---|
243 | /******************************************************************************/ |
---|
244 | /* */ |
---|
245 | /* */ |
---|
246 | /******************************************************************************/ |
---|
247 | listnom *DecomposeTheNameinlistnom(const char *nom, listnom * listout) |
---|
248 | { |
---|
249 | char toprinttmp[LONG_M]; |
---|
250 | char chartmp[2]; |
---|
251 | size_t i = 0; |
---|
252 | |
---|
253 | strcpy(toprinttmp,""); |
---|
254 | |
---|
255 | while ( i < strlen(nom) ) |
---|
256 | { |
---|
257 | if ( nom[i] == '+' || |
---|
258 | nom[i] == '-' || |
---|
259 | nom[i] == '*' || |
---|
260 | nom[i] == '/' || |
---|
261 | nom[i] == ')' || |
---|
262 | nom[i] == '(' || |
---|
263 | nom[i] == ',' || |
---|
264 | nom[i] == ':' |
---|
265 | ) |
---|
266 | { |
---|
267 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
268 | { |
---|
269 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
270 | } |
---|
271 | strcpy(toprinttmp,""); |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | sprintf(chartmp,"%c",nom[i]); |
---|
276 | strcat(toprinttmp,chartmp); |
---|
277 | } |
---|
278 | i=i+1; |
---|
279 | } |
---|
280 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
281 | { |
---|
282 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
283 | } |
---|
284 | Save_Length(toprinttmp,44); |
---|
285 | strcpy(toprinttmp,""); |
---|
286 | |
---|
287 | return listout; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | /******************************************************************************/ |
---|
292 | /* DecomposeTheName */ |
---|
293 | /******************************************************************************/ |
---|
294 | /* Firstpass 0 */ |
---|
295 | /******************************************************************************/ |
---|
296 | /* */ |
---|
297 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
298 | /* */ |
---|
299 | /******************************************************************************/ |
---|
300 | void DecomposeTheName(const char *nom) |
---|
301 | { |
---|
302 | char toprinttmp[LONG_M]; |
---|
303 | char chartmp[2]; |
---|
304 | size_t i = 0; |
---|
305 | |
---|
306 | strcpy(toprinttmp,""); |
---|
307 | |
---|
308 | while ( i < strlen(nom) ) |
---|
309 | { |
---|
310 | if ( nom[i] == '+' || |
---|
311 | nom[i] == '-' || |
---|
312 | nom[i] == '*' || |
---|
313 | nom[i] == '/' || |
---|
314 | nom[i] == ')' || |
---|
315 | nom[i] == '(' || |
---|
316 | nom[i] == ',' || |
---|
317 | nom[i] == ':' |
---|
318 | ) |
---|
319 | { |
---|
320 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
321 | { |
---|
322 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
323 | /* Is this variable present in globvarofusefile */ |
---|
324 | IsVarInUseFile(toprinttmp); |
---|
325 | } |
---|
326 | strcpy(toprinttmp,""); |
---|
327 | } |
---|
328 | else |
---|
329 | { |
---|
330 | sprintf(chartmp,"%c",nom[i]); |
---|
331 | strcat(toprinttmp,chartmp); |
---|
332 | } |
---|
333 | i=i+1; |
---|
334 | } |
---|
335 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
336 | { |
---|
337 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
338 | /* Is this variable present in globvarofusefile */ |
---|
339 | IsVarInUseFile(toprinttmp); |
---|
340 | } |
---|
341 | Save_Length(toprinttmp,44); |
---|
342 | strcpy(toprinttmp,""); |
---|
343 | |
---|
344 | } |
---|
345 | |
---|
346 | void convert2lower(char *lowername, const char* inputname) |
---|
347 | { |
---|
348 | int i, l, caractere; |
---|
349 | |
---|
350 | strcpy(lowername, inputname); |
---|
351 | l = strlen(lowername)-1; |
---|
352 | |
---|
353 | for ( i=0 ; i<=l ; i++) |
---|
354 | { |
---|
355 | caractere = lowername[i]; |
---|
356 | if ( (caractere>=65 && caractere<=90) || (caractere>=192 && caractere<=221) ) |
---|
357 | { |
---|
358 | lowername[i] += 32; |
---|
359 | } |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | int convert2int(const char *name) |
---|
364 | { |
---|
365 | int i; |
---|
366 | int caractere; |
---|
367 | int value; |
---|
368 | int value_tmp; |
---|
369 | int longueur; |
---|
370 | |
---|
371 | value = 0; |
---|
372 | |
---|
373 | longueur = strlen(name) - 1; |
---|
374 | for (i=0;i<=longueur;i++) |
---|
375 | { |
---|
376 | caractere=name[i]; |
---|
377 | value_tmp = caractere -'0'; |
---|
378 | if ( value_tmp > 9 ) return 0; |
---|
379 | if ( longueur+1-i == 6 ) value = value + value_tmp *100000; |
---|
380 | else if ( longueur+1-i == 5 ) value = value + value_tmp *10000; |
---|
381 | else if ( longueur+1-i == 4 ) value = value + value_tmp *1000; |
---|
382 | else if ( longueur+1-i == 3 ) value = value + value_tmp *100; |
---|
383 | else if ( longueur+1-i == 2 ) value = value + value_tmp *10; |
---|
384 | else if ( longueur+1-i == 1 ) value = value + value_tmp *1; |
---|
385 | } |
---|
386 | return value; |
---|
387 | } |
---|