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@imag.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.0 */ |
---|
34 | /******************************************************************************/ |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <string.h> |
---|
38 | #include "decl.h" |
---|
39 | |
---|
40 | /******************************************************************************/ |
---|
41 | /* initdimprob */ |
---|
42 | /******************************************************************************/ |
---|
43 | /* This subroutine is used to initialized grid dimension variable */ |
---|
44 | /******************************************************************************/ |
---|
45 | /* */ |
---|
46 | /* */ |
---|
47 | /* */ |
---|
48 | /******************************************************************************/ |
---|
49 | void initdimprob(int dimprobmod, char * nx, char * ny,char* nz) |
---|
50 | { |
---|
51 | dimprob = dimprobmod; |
---|
52 | |
---|
53 | strcpy(nbmaillesX,nx); |
---|
54 | strcpy(nbmaillesY,ny); |
---|
55 | strcpy(nbmaillesZ,nz); |
---|
56 | } |
---|
57 | |
---|
58 | /******************************************************************************/ |
---|
59 | /* Variableshouldberemove */ |
---|
60 | /******************************************************************************/ |
---|
61 | /* Firstpass 0 */ |
---|
62 | /******************************************************************************/ |
---|
63 | /* */ |
---|
64 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
65 | /* */ |
---|
66 | /******************************************************************************/ |
---|
67 | int Variableshouldberemove(char *nom) |
---|
68 | { |
---|
69 | |
---|
70 | int remove; |
---|
71 | |
---|
72 | remove = 0 ; |
---|
73 | |
---|
74 | if ( remove == 0 && !strcasecmp(nom,"RESHAPE") ) remove = 1 ; |
---|
75 | if ( remove == 0 && Agrif_in_Tok_NAME(nom) == 1 ) remove = 1 ; |
---|
76 | |
---|
77 | return remove; |
---|
78 | } |
---|
79 | |
---|
80 | /******************************************************************************/ |
---|
81 | /* variableisglobal */ |
---|
82 | /******************************************************************************/ |
---|
83 | /* This subroutine is to know if a variable is global */ |
---|
84 | /******************************************************************************/ |
---|
85 | int variableisglobal(listvar *curvar, listvar *listin) |
---|
86 | { |
---|
87 | int Globalite; |
---|
88 | listvar *newvar; |
---|
89 | |
---|
90 | |
---|
91 | Globalite = 0; |
---|
92 | newvar = listin; |
---|
93 | while ( newvar && Globalite == 0 ) |
---|
94 | { |
---|
95 | if ( !strcasecmp(newvar->var->nomvar,curvar->var->nomvar) ) |
---|
96 | { |
---|
97 | Globalite = 1; |
---|
98 | /* Now we should give the definition of the variable in the */ |
---|
99 | /* table listvarindoloop */ |
---|
100 | strcpy(curvar->var->typevar,newvar->var->typevar); |
---|
101 | strcpy(curvar->var->dimchar,newvar->var->dimchar); |
---|
102 | curvar->var->nbdim = newvar->var->nbdim; |
---|
103 | curvar->var->dimensiongiven = newvar->var->dimensiongiven; |
---|
104 | curvar->var->allocatable = newvar->var->allocatable; |
---|
105 | curvar->var->pointerdeclare = newvar->var->pointerdeclare; |
---|
106 | curvar->var->indicetabvars = newvar->var->indicetabvars; |
---|
107 | strcpy(curvar->var->precision,newvar->var->precision); |
---|
108 | strcpy(curvar->var->readedlistdimension, |
---|
109 | newvar->var->readedlistdimension); |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | newvar = newvar->suiv; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | return Globalite ; |
---|
118 | } |
---|
119 | |
---|
120 | /******************************************************************************/ |
---|
121 | /* variableisglobalinmodule */ |
---|
122 | /******************************************************************************/ |
---|
123 | /* This subroutine is to know if a variable is global */ |
---|
124 | /******************************************************************************/ |
---|
125 | void variableisglobalinmodule(listcouple *listin, char *module, FILE *fileout) |
---|
126 | { |
---|
127 | int Globalite; |
---|
128 | listcouple *newvar; |
---|
129 | listcouple *newvarprec; |
---|
130 | listvar *tempo; |
---|
131 | listvar *newvar2; |
---|
132 | int out; |
---|
133 | |
---|
134 | Globalite = 1; |
---|
135 | tempo = (listvar *)NULL; |
---|
136 | tempo = Readthedependfile(module,tempo); |
---|
137 | newvar = listin; |
---|
138 | while ( newvar ) |
---|
139 | { |
---|
140 | out = 0; |
---|
141 | newvar2 = tempo; |
---|
142 | while ( newvar2 && out == 0 ) |
---|
143 | { |
---|
144 | if ( !strcasecmp(newvar2->var->nomvar,newvar->namevar) ) out = 1; |
---|
145 | else newvar2 = newvar2 ->suiv; |
---|
146 | } |
---|
147 | if ( out == 1 ) |
---|
148 | { |
---|
149 | /* remove from the listin */ |
---|
150 | if ( newvar == listin ) |
---|
151 | { |
---|
152 | listin = listin->suiv; |
---|
153 | newvar = listin; |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | newvarprec->suiv = newvar->suiv; |
---|
158 | newvar = newvar->suiv; |
---|
159 | } |
---|
160 | } |
---|
161 | else |
---|
162 | { |
---|
163 | newvarprec = newvar; |
---|
164 | newvar = newvar->suiv; |
---|
165 | Globalite = 0; |
---|
166 | } |
---|
167 | } |
---|
168 | if ( Globalite == 0 || !newvar) |
---|
169 | { |
---|
170 | pos_end = setposcur(); |
---|
171 | RemoveWordSET_0(fileout,pos_curuse, |
---|
172 | pos_end-pos_curuse); |
---|
173 | newvar = listin; |
---|
174 | while ( newvar ) |
---|
175 | { |
---|
176 | fprintf(fileout," USE %s, ONLY : %s \n",module,newvar->namevar); |
---|
177 | newvar = newvar->suiv; |
---|
178 | } |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | /******************************************************************************/ |
---|
183 | /* variableisparameterglobal */ |
---|
184 | /******************************************************************************/ |
---|
185 | /* This subroutine is to know if a variable is global */ |
---|
186 | /******************************************************************************/ |
---|
187 | int variableisparameterglobal(listvar *curvar, listparameter *listin) |
---|
188 | { |
---|
189 | int Globalite; |
---|
190 | listparameter *newvar; |
---|
191 | |
---|
192 | Globalite = 0; |
---|
193 | newvar = listin; |
---|
194 | while ( newvar && Globalite == 0 ) |
---|
195 | { |
---|
196 | if ( !strcasecmp(newvar->name,curvar->var->nomvar) ) Globalite = 1; |
---|
197 | else newvar = newvar->suiv; |
---|
198 | } |
---|
199 | |
---|
200 | return Globalite ; |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | /******************************************************************************/ |
---|
205 | /* addsubroutine_alloc_0 */ |
---|
206 | /******************************************************************************/ |
---|
207 | /* Firstpass 0 */ |
---|
208 | /* We should add subroutine of allocation */ |
---|
209 | /* if moduleorcontains = 1 we are at the end module keyword */ |
---|
210 | /* if moduleorcontains = 0 we are at the contains keyword */ |
---|
211 | /******************************************************************************/ |
---|
212 | void addsubroutine_alloc_0(int moduleorcontains) |
---|
213 | { |
---|
214 | char ligne[LONGNOM]; |
---|
215 | int Allocisempty; |
---|
216 | listvar *newvar; |
---|
217 | |
---|
218 | |
---|
219 | if ( firstpass == 0) |
---|
220 | { |
---|
221 | /* It is necessary to know if this subroutine is not empty */ |
---|
222 | Allocisempty = 0; |
---|
223 | newvar = globliste; |
---|
224 | while ( newvar && Allocisempty == 0 ) |
---|
225 | { |
---|
226 | if ( !strcasecmp(newvar->var->modulename,curmodulename)) Allocisempty=1; |
---|
227 | else newvar = newvar->suiv; |
---|
228 | } |
---|
229 | if ( Allocisempty == 1 ) |
---|
230 | { |
---|
231 | while ( newvar && |
---|
232 | !strcasecmp(newvar->var->modulename,curmodulename) && |
---|
233 | Allocisempty == 1 ) |
---|
234 | { |
---|
235 | if ( (newvar->var->nbdim !=0 && |
---|
236 | newvar->var->allocatable != 1 ) || |
---|
237 | (newvar->var->nbdim == 0 && |
---|
238 | strcasecmp(newvar->var->initialvalue,"")) ) Allocisempty = 0; |
---|
239 | else newvar = newvar->suiv; |
---|
240 | } |
---|
241 | } |
---|
242 | if ( Allocisempty == 0 ) |
---|
243 | { |
---|
244 | if ( AllocInModule() == 1) |
---|
245 | { |
---|
246 | /* we should remove end module <name> */ |
---|
247 | if ( moduleorcontains == 1 ) |
---|
248 | { |
---|
249 | RemoveWordCUR_0(fortranout,(long)(-strlen(curmodulename)-12), |
---|
250 | strlen(curmodulename)+11); |
---|
251 | } |
---|
252 | /* we should remove contains */ |
---|
253 | if ( moduleorcontains == 0 ) |
---|
254 | { |
---|
255 | RemoveWordCUR_0(fortranout,(long)(-9),9); |
---|
256 | } |
---|
257 | strcpy (ligne, "\n PUBLIC Alloc_agrif_"); |
---|
258 | strcat (ligne, curmodulename); |
---|
259 | strcat (ligne, "\n"); |
---|
260 | fprintf(fortranout,ligne); |
---|
261 | } |
---|
262 | if (AllocInModule() == 1) |
---|
263 | { |
---|
264 | fprintf(fortranout,"\n contains\n"); |
---|
265 | strcpy (ligne, "\n#include \"alloc_agrif_"); |
---|
266 | strcat (ligne, curmodulename); |
---|
267 | strcat (ligne, ".h\"\n"); |
---|
268 | fprintf(fortranout,ligne); |
---|
269 | /* On reecrit la mot cle end module qui a ete efface du fichier */ |
---|
270 | /* d'origine */ |
---|
271 | if ( moduleorcontains == 1 ) fprintf(fortranout,"\n end module %s" |
---|
272 | ,curmodulename); |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | /******************************************************************************/ |
---|
280 | /* IsTabvarsUseInArgument_0 */ |
---|
281 | /******************************************************************************/ |
---|
282 | /* Firstpass 1 */ |
---|
283 | /******************************************************************************/ |
---|
284 | /* */ |
---|
285 | /******************************************************************************/ |
---|
286 | int IsTabvarsUseInArgument_0() |
---|
287 | { |
---|
288 | int out; |
---|
289 | int doloopout; |
---|
290 | listvar *parcours; |
---|
291 | |
---|
292 | out=1; |
---|
293 | |
---|
294 | if ( listvarindoloop ) |
---|
295 | { |
---|
296 | doloopout = 0; |
---|
297 | parcours = listvarindoloop; |
---|
298 | while ( parcours && doloopout == 0 ) |
---|
299 | { |
---|
300 | if ( !strcasecmp(parcours->var->modulename,subroutinename) ) |
---|
301 | doloopout = 1; |
---|
302 | else parcours = parcours->suiv; |
---|
303 | } |
---|
304 | if ( doloopout == 0 ) out = 0; |
---|
305 | else out = 1 ; |
---|
306 | } |
---|
307 | else out = 0; |
---|
308 | |
---|
309 | return out; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | /******************************************************************************/ |
---|
314 | /* ImplicitNoneInSubroutine */ |
---|
315 | /******************************************************************************/ |
---|
316 | /* Firstpass 0 */ |
---|
317 | /******************************************************************************/ |
---|
318 | /* */ |
---|
319 | /******************************************************************************/ |
---|
320 | int ImplicitNoneInSubroutine() |
---|
321 | { |
---|
322 | listname *parcours; |
---|
323 | int out; |
---|
324 | |
---|
325 | parcours= listimplicitnone; |
---|
326 | out = 0 ; |
---|
327 | while ( parcours && out == 0 ) |
---|
328 | { |
---|
329 | if ( !strcasecmp(parcours->name,subroutinename) ) out = 1; |
---|
330 | else parcours = parcours->suiv; |
---|
331 | |
---|
332 | } |
---|
333 | return out; |
---|
334 | } |
---|
335 | |
---|
336 | /******************************************************************************/ |
---|
337 | /* varispointer_0 */ |
---|
338 | /******************************************************************************/ |
---|
339 | /* Firstpass 0 */ |
---|
340 | /******************************************************************************/ |
---|
341 | /* */ |
---|
342 | /******************************************************************************/ |
---|
343 | int varispointer_0(char *ident) |
---|
344 | { |
---|
345 | listvar *newvar; |
---|
346 | int out; |
---|
347 | |
---|
348 | out =0; |
---|
349 | if (firstpass == 0 ) |
---|
350 | { |
---|
351 | newvar = globalvarofusefile; |
---|
352 | while ( newvar && out == 0 ) |
---|
353 | { |
---|
354 | if ( !strcasecmp(ident,newvar->var->nomvar) && |
---|
355 | newvar->var->pointerdeclare == 1 ) out = 1; |
---|
356 | else newvar = newvar->suiv; |
---|
357 | } |
---|
358 | } |
---|
359 | return out; |
---|
360 | } |
---|
361 | |
---|
362 | |
---|
363 | /******************************************************************************/ |
---|
364 | /* VariableIsNotFunction */ |
---|
365 | /******************************************************************************/ |
---|
366 | /* |
---|
367 | /******************************************************************************/ |
---|
368 | int VariableIsNotFunction(char *ident) |
---|
369 | { |
---|
370 | int out; |
---|
371 | listvar *newvar; |
---|
372 | |
---|
373 | out =0; |
---|
374 | |
---|
375 | if ( !strcasecmp(ident,"size") || |
---|
376 | !strcasecmp(ident,"if") || |
---|
377 | !strcasecmp(ident,"max") || |
---|
378 | !strcasecmp(ident,"min") |
---|
379 | ) |
---|
380 | { |
---|
381 | newvar = varofsubroutineliste; |
---|
382 | while ( newvar && out == 0 ) |
---|
383 | { |
---|
384 | if ( !strcasecmp(subroutinename, newvar->var->subroutinename) && |
---|
385 | !strcasecmp(ident, newvar->var->nomvar) ) out = 1; |
---|
386 | newvar = newvar -> suiv ; |
---|
387 | } |
---|
388 | if ( out == 1 ) out = 0; |
---|
389 | else out = 1; |
---|
390 | /* if it has not been found */ |
---|
391 | if ( out == 1 ) |
---|
392 | { |
---|
393 | out = 0; |
---|
394 | newvar = globliste; |
---|
395 | while ( newvar && out == 0 ) |
---|
396 | { |
---|
397 | if ( !strcasecmp(ident, newvar->var->nomvar) ) out = 1; |
---|
398 | newvar = newvar -> suiv ; |
---|
399 | } |
---|
400 | if ( out == 1 ) out = 0; |
---|
401 | else out = 1; |
---|
402 | } |
---|
403 | } |
---|
404 | /* */ |
---|
405 | return out; |
---|
406 | } |
---|