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) % var % array2 */ |
---|
49 | /* */ |
---|
50 | /* if whichone = 1 ----> Agrif_tabvars(i) % parentvar % var % array2 */ |
---|
51 | /* */ |
---|
52 | /******************************************************************************/ |
---|
53 | void FindAndChangeNameToTabvars(char name[LONG_C],char toprint[LONG_4C], |
---|
54 | listvar * listtosee, int whichone) |
---|
55 | { |
---|
56 | listvar *newvar; |
---|
57 | int out; |
---|
58 | |
---|
59 | if ( strcasecmp(name,"") ) |
---|
60 | { |
---|
61 | newvar=listtosee; |
---|
62 | out=0; |
---|
63 | while( newvar && out == 0 ) |
---|
64 | { |
---|
65 | if ( !strcasecmp(newvar->var->v_nomvar,name) ) |
---|
66 | { |
---|
67 | if ( LookingForVariableInListName( |
---|
68 | List_SubroutineArgument_Var,name) == 0 ) |
---|
69 | { |
---|
70 | out = 1; |
---|
71 | strcat(toprint,vargridcurgridtabvars(newvar->var,whichone)); |
---|
72 | } |
---|
73 | else newvar=newvar->suiv; |
---|
74 | } |
---|
75 | else newvar=newvar->suiv; |
---|
76 | } |
---|
77 | if ( out == 0 ) strcat(toprint,name); |
---|
78 | } |
---|
79 | Save_Length(toprint,44); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | /******************************************************************************/ |
---|
84 | /* ChangeTheInitalvaluebyTabvarsName */ |
---|
85 | /******************************************************************************/ |
---|
86 | /* */ |
---|
87 | /******************************************************************************/ |
---|
88 | /* */ |
---|
89 | /* */ |
---|
90 | /* */ |
---|
91 | /******************************************************************************/ |
---|
92 | char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread, |
---|
93 | int whichone) |
---|
94 | { |
---|
95 | char toprinttmp[LONG_4C]; |
---|
96 | int i; |
---|
97 | char chartmp[2]; |
---|
98 | |
---|
99 | i=0; |
---|
100 | strcpy(toprintglob,""); |
---|
101 | strcpy(toprinttmp,""); |
---|
102 | /* */ |
---|
103 | while ( i < strlen(nom) ) |
---|
104 | { |
---|
105 | if ( nom[i] == '+' ) |
---|
106 | { |
---|
107 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
108 | strcpy(toprinttmp,""); |
---|
109 | strcat(toprintglob,"+"); |
---|
110 | } |
---|
111 | else if ( nom[i] == '-' ) |
---|
112 | { |
---|
113 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
114 | strcpy(toprinttmp,""); |
---|
115 | strcat(toprintglob,"-"); |
---|
116 | } |
---|
117 | else if ( nom[i] == '*' ) |
---|
118 | { |
---|
119 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
120 | strcpy(toprinttmp,""); |
---|
121 | strcat(toprintglob,"*"); |
---|
122 | } |
---|
123 | else if ( nom[i] == '/' ) |
---|
124 | { |
---|
125 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
126 | strcpy(toprinttmp,""); |
---|
127 | strcat(toprintglob,"/"); |
---|
128 | } |
---|
129 | else if ( nom[i] == '(' ) |
---|
130 | { |
---|
131 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
132 | strcpy(toprinttmp,""); |
---|
133 | strcat(toprintglob,"("); |
---|
134 | } |
---|
135 | else if ( nom[i] == ')' ) |
---|
136 | { |
---|
137 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
138 | strcpy(toprinttmp,""); |
---|
139 | strcat(toprintglob,")"); |
---|
140 | } |
---|
141 | else if ( nom[i] == ':' ) |
---|
142 | { |
---|
143 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
144 | strcpy(toprinttmp,""); |
---|
145 | strcat(toprintglob,":"); |
---|
146 | } |
---|
147 | else if ( nom[i] == ',' ) |
---|
148 | { |
---|
149 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
150 | strcpy(toprinttmp,""); |
---|
151 | strcat(toprintglob,","); |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | sprintf(chartmp,"%c",nom[i]); |
---|
156 | strcat(toprinttmp,chartmp); |
---|
157 | } |
---|
158 | /* */ |
---|
159 | i=i+1; |
---|
160 | } |
---|
161 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
162 | strcpy(toprinttmp,""); |
---|
163 | |
---|
164 | Save_Length(toprinttmp,44); |
---|
165 | Save_Length(toprintglob,39); |
---|
166 | /* */ |
---|
167 | return toprintglob; |
---|
168 | } |
---|
169 | |
---|
170 | /******************************************************************************/ |
---|
171 | /* IsVariableReal */ |
---|
172 | /******************************************************************************/ |
---|
173 | /* */ |
---|
174 | /******************************************************************************/ |
---|
175 | /* */ |
---|
176 | /* */ |
---|
177 | /* */ |
---|
178 | /******************************************************************************/ |
---|
179 | int IsVariableReal(char *nom) |
---|
180 | { |
---|
181 | int Real; |
---|
182 | |
---|
183 | Real = 0; |
---|
184 | if ( ( nom[0] >= 'a' && nom[0] <= 'h' ) || |
---|
185 | ( nom[0] >= 'A' && nom[0] <= 'H' ) || |
---|
186 | ( nom[0] >= 'o' && nom[0] <= 'z' ) || |
---|
187 | ( nom[0] >= 'O' && nom[0] <= 'Z' ) |
---|
188 | ) |
---|
189 | { |
---|
190 | Real = 1; |
---|
191 | } |
---|
192 | /* */ |
---|
193 | return Real; |
---|
194 | } |
---|
195 | /******************************************************************************/ |
---|
196 | /* IsVarInUseFile */ |
---|
197 | /******************************************************************************/ |
---|
198 | /* */ |
---|
199 | /******************************************************************************/ |
---|
200 | /* */ |
---|
201 | /* */ |
---|
202 | /* */ |
---|
203 | /******************************************************************************/ |
---|
204 | void IsVarInUseFile(char *nom) |
---|
205 | { |
---|
206 | listvar *parcours; |
---|
207 | listparameter *parcoursparam; |
---|
208 | int out; |
---|
209 | |
---|
210 | out = 0; |
---|
211 | |
---|
212 | parcours = List_Global_Var; |
---|
213 | while( parcours && out == 0 ) |
---|
214 | { |
---|
215 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
216 | else parcours=parcours->suiv; |
---|
217 | } |
---|
218 | if ( out == 0 ) |
---|
219 | { |
---|
220 | parcours = List_Common_Var; |
---|
221 | while( parcours && out == 0 ) |
---|
222 | { |
---|
223 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
224 | else parcours=parcours->suiv; |
---|
225 | } |
---|
226 | } |
---|
227 | if ( out == 0 ) |
---|
228 | { |
---|
229 | parcours = List_GlobalParameter_Var; |
---|
230 | while( parcours && out == 0 ) |
---|
231 | { |
---|
232 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
233 | else parcours=parcours->suiv; |
---|
234 | } |
---|
235 | } |
---|
236 | if ( out == 0 ) |
---|
237 | { |
---|
238 | parcours = List_Parameter_Var; |
---|
239 | while( parcours && out == 0 ) |
---|
240 | { |
---|
241 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
242 | else parcours=parcours->suiv; |
---|
243 | } |
---|
244 | } |
---|
245 | if ( out == 0 ) |
---|
246 | { |
---|
247 | parcoursparam = List_GlobParamModuleUsed_Var; |
---|
248 | while( parcoursparam && out == 0 ) |
---|
249 | { |
---|
250 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out =2 ; |
---|
251 | else parcoursparam=parcoursparam->suiv; |
---|
252 | } |
---|
253 | } |
---|
254 | if ( out == 0 ) |
---|
255 | { |
---|
256 | parcours = List_ModuleUsed_Var; |
---|
257 | while( parcours && out == 0 ) |
---|
258 | { |
---|
259 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =2 ; |
---|
260 | else parcours=parcours->suiv; |
---|
261 | } |
---|
262 | } |
---|
263 | if ( out == 0 || out == 2 ) |
---|
264 | { |
---|
265 | parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var; |
---|
266 | while( parcoursparam && out != 1 ) |
---|
267 | { |
---|
268 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out =1 ; |
---|
269 | else parcoursparam=parcoursparam->suiv; |
---|
270 | } |
---|
271 | if ( out == 1 ) |
---|
272 | { |
---|
273 | strcpy(charusemodule,parcoursparam->p_modulename); |
---|
274 | Addmoduletothelist(parcoursparam->p_modulename); |
---|
275 | } |
---|
276 | } |
---|
277 | if ( out == 0 && |
---|
278 | strcasecmp(nom,"MAX") && |
---|
279 | strcasecmp(nom,"mpi_status_size") |
---|
280 | ) |
---|
281 | { |
---|
282 | printf("--- in UtilCharacter we do not found the \n"); |
---|
283 | printf("--- variable %s, the module where this \n",nom); |
---|
284 | printf("--- variable has been defined has not been\n"); |
---|
285 | printf("--- found.\n"); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | /******************************************************************************/ |
---|
290 | /* DecomposeTheNameinlistnom */ |
---|
291 | /******************************************************************************/ |
---|
292 | /* Firstpass 0 */ |
---|
293 | /******************************************************************************/ |
---|
294 | /* */ |
---|
295 | /* */ |
---|
296 | /******************************************************************************/ |
---|
297 | listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout) |
---|
298 | { |
---|
299 | char toprinttmp[LONG_4C]; |
---|
300 | int i; |
---|
301 | char chartmp[2]; |
---|
302 | |
---|
303 | i=0; |
---|
304 | strcpy(toprinttmp,""); |
---|
305 | /* */ |
---|
306 | while ( i < strlen(nom) ) |
---|
307 | { |
---|
308 | if ( nom[i] == '+' || |
---|
309 | nom[i] == '-' || |
---|
310 | nom[i] == '*' || |
---|
311 | nom[i] == '/' || |
---|
312 | nom[i] == ')' || |
---|
313 | nom[i] == '(' || |
---|
314 | nom[i] == ',' || |
---|
315 | nom[i] == ':' |
---|
316 | ) |
---|
317 | { |
---|
318 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
319 | { |
---|
320 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
321 | } |
---|
322 | strcpy(toprinttmp,""); |
---|
323 | } |
---|
324 | else |
---|
325 | { |
---|
326 | sprintf(chartmp,"%c",nom[i]); |
---|
327 | strcat(toprinttmp,chartmp); |
---|
328 | } |
---|
329 | /* */ |
---|
330 | i=i+1; |
---|
331 | } |
---|
332 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
333 | { |
---|
334 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
335 | } |
---|
336 | strcpy(toprinttmp,""); |
---|
337 | Save_Length(toprinttmp,44); |
---|
338 | |
---|
339 | return listout; |
---|
340 | } |
---|
341 | |
---|
342 | |
---|
343 | /******************************************************************************/ |
---|
344 | /* DecomposeTheName */ |
---|
345 | /******************************************************************************/ |
---|
346 | /* Firstpass 0 */ |
---|
347 | /******************************************************************************/ |
---|
348 | /* */ |
---|
349 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
350 | /* */ |
---|
351 | /******************************************************************************/ |
---|
352 | void DecomposeTheName(char *nom) |
---|
353 | { |
---|
354 | char toprinttmp[LONG_4C]; |
---|
355 | int i; |
---|
356 | char chartmp[2]; |
---|
357 | |
---|
358 | i=0; |
---|
359 | strcpy(toprinttmp,""); |
---|
360 | /* */ |
---|
361 | while ( i < strlen(nom) ) |
---|
362 | { |
---|
363 | if ( nom[i] == '+' || |
---|
364 | nom[i] == '-' || |
---|
365 | nom[i] == '*' || |
---|
366 | nom[i] == '/' || |
---|
367 | nom[i] == ')' || |
---|
368 | nom[i] == '(' || |
---|
369 | nom[i] == ',' || |
---|
370 | nom[i] == ':' |
---|
371 | ) |
---|
372 | { |
---|
373 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
374 | { |
---|
375 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
376 | /* Is this variable present in globvarofusefile */ |
---|
377 | IsVarInUseFile(toprinttmp); |
---|
378 | } |
---|
379 | strcpy(toprinttmp,""); |
---|
380 | } |
---|
381 | else |
---|
382 | { |
---|
383 | sprintf(chartmp,"%c",nom[i]); |
---|
384 | strcat(toprinttmp,chartmp); |
---|
385 | } |
---|
386 | /* */ |
---|
387 | i=i+1; |
---|
388 | } |
---|
389 | Save_Length(toprinttmp,44); |
---|
390 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
391 | { |
---|
392 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
393 | /* Is this variable present in globvarofusefile */ |
---|
394 | IsVarInUseFile(toprinttmp); |
---|
395 | } |
---|
396 | strcpy(toprinttmp,""); |
---|
397 | |
---|
398 | } |
---|
399 | |
---|
400 | void convert2lower(char *name) |
---|
401 | { |
---|
402 | int l; |
---|
403 | int i; |
---|
404 | int caractere; |
---|
405 | |
---|
406 | l=strlen(name)-1; |
---|
407 | for (i=0;i<=l;i++) |
---|
408 | { |
---|
409 | caractere=name[i]; |
---|
410 | if ((caractere>=65 && caractere<=90)||(caractere>=192 && caractere<=221)) |
---|
411 | { |
---|
412 | name[i]+=32; |
---|
413 | } |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | int convert2int(char *name) |
---|
418 | { |
---|
419 | int i; |
---|
420 | int caractere; |
---|
421 | int value; |
---|
422 | int value_tmp; |
---|
423 | int longueur; |
---|
424 | |
---|
425 | value = 0; |
---|
426 | |
---|
427 | longueur = strlen(name) - 1; |
---|
428 | for (i=0;i<=longueur;i++) |
---|
429 | { |
---|
430 | caractere=name[i]; |
---|
431 | value_tmp = caractere -'0'; |
---|
432 | if ( value_tmp > 9 ) return 0; |
---|
433 | if ( longueur+1-i == 6 ) value = value + value_tmp *100000; |
---|
434 | else if ( longueur+1-i == 5 ) value = value + value_tmp *10000; |
---|
435 | else if ( longueur+1-i == 4 ) value = value + value_tmp *1000; |
---|
436 | else if ( longueur+1-i == 3 ) value = value + value_tmp *100; |
---|
437 | else if ( longueur+1-i == 2 ) value = value + value_tmp *10; |
---|
438 | else if ( longueur+1-i == 1 ) value = value + value_tmp *1; |
---|
439 | } |
---|
440 | return value; |
---|
441 | } |
---|