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.6 */ |
---|
34 | /******************************************************************************/ |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include <string.h> |
---|
38 | #include "decl.h" |
---|
39 | |
---|
40 | |
---|
41 | void Init_Variable(variable *var) |
---|
42 | { |
---|
43 | strcpy(var->v_typevar ,""); |
---|
44 | strcpy(var->v_nomvar ,""); |
---|
45 | strcpy(var->v_oldname ,""); |
---|
46 | strcpy(var->v_dimchar ,""); |
---|
47 | strcpy(var->v_modulename ,""); |
---|
48 | strcpy(var->v_commonname ,""); |
---|
49 | strcpy(var->v_vallengspec ,""); |
---|
50 | strcpy(var->v_nameinttypename ,""); |
---|
51 | strcpy(var->v_commoninfile ,""); |
---|
52 | strcpy(var->v_subroutinename ,""); |
---|
53 | strcpy(var->v_precision ,""); |
---|
54 | strcpy(var->v_initialvalue ,""); |
---|
55 | strcpy(var->v_IntentSpec ,""); |
---|
56 | strcpy(var->v_readedlistdimension,""); |
---|
57 | var->v_nbdim = 0 ; |
---|
58 | var->v_common = 0 ; |
---|
59 | var->v_positioninblock = 0 ; |
---|
60 | var->v_module = 0 ; |
---|
61 | var->v_save = 0 ; |
---|
62 | var->v_VariableIsParameter = 0 ; |
---|
63 | var->v_PublicDeclare = 0 ; |
---|
64 | var->v_PrivateDeclare = 0 ; |
---|
65 | var->v_ExternalDeclare = 0 ; |
---|
66 | var->v_pointedvar = 0 ; |
---|
67 | var->v_notgrid = 0 ; |
---|
68 | var->v_dimensiongiven = 0 ; |
---|
69 | var->v_c_star = 0 ; |
---|
70 | var->v_indicetabvars = 0 ; |
---|
71 | var->v_pointerdeclare = 0 ; |
---|
72 | var->v_optionaldeclare = 0 ; |
---|
73 | var->v_allocatable = 0 ; |
---|
74 | var->v_dimsempty = 0 ; |
---|
75 | var->v_dimension = (listdim *)NULL; |
---|
76 | } |
---|
77 | /******************************************************************************/ |
---|
78 | /* AddListvartolistvar */ |
---|
79 | /******************************************************************************/ |
---|
80 | /* This subroutine is used to add a listvar l at the end of a listvar */ |
---|
81 | /* glob. */ |
---|
82 | /* */ |
---|
83 | /******************************************************************************/ |
---|
84 | /* _______ _______ _______ _______ _______ */ |
---|
85 | /* + + + + + + + + + + */ |
---|
86 | /* + glob +--->+ glob +--->+ glob +--->+ glob +--->+ l + */ |
---|
87 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
88 | /* */ |
---|
89 | /******************************************************************************/ |
---|
90 | listvar * AddListvarToListvar(listvar *l,listvar *glob,int ValueFirstpass) |
---|
91 | { |
---|
92 | listvar *newvar; |
---|
93 | |
---|
94 | if ( firstpass == ValueFirstpass ) |
---|
95 | { |
---|
96 | if ( !glob) glob = l ; |
---|
97 | else |
---|
98 | { |
---|
99 | newvar=glob; |
---|
100 | while (newvar->suiv) newvar = newvar->suiv; |
---|
101 | newvar->suiv = l; |
---|
102 | } |
---|
103 | } |
---|
104 | return glob; |
---|
105 | } |
---|
106 | |
---|
107 | /******************************************************************************/ |
---|
108 | /* CreateAndFillin_Curvar */ |
---|
109 | /******************************************************************************/ |
---|
110 | /* This subroutine is used to create the record corresponding to the */ |
---|
111 | /* list of declaration */ |
---|
112 | /******************************************************************************/ |
---|
113 | /* */ |
---|
114 | /******************************************************************************/ |
---|
115 | void CreateAndFillin_Curvar(char *type,variable *curvar) |
---|
116 | { |
---|
117 | if (!strcasecmp(type,"character") && strcasecmp(CharacterSize,"") ) |
---|
118 | strcpy(curvar->v_dimchar,CharacterSize); |
---|
119 | |
---|
120 | /* On donne la precision de la variable si elle a ete donnee */ |
---|
121 | curvar->v_c_star = 0; |
---|
122 | if ( c_star == 1 ) curvar->v_c_star = 1; |
---|
123 | /* */ |
---|
124 | strcpy(curvar->v_vallengspec,""); |
---|
125 | if ( strcasecmp(vallengspec,"") ) strcpy(curvar->v_vallengspec,vallengspec); |
---|
126 | |
---|
127 | strcpy(curvar->v_precision,""); |
---|
128 | if ( strcasecmp(NamePrecision,"") ) strcpy(curvar->v_precision,NamePrecision); |
---|
129 | /* Si cette variable a ete declaree dans un module on met curvar->module=1 */ |
---|
130 | if ( inmoduledeclare == 1 || SaveDeclare == 1) |
---|
131 | { |
---|
132 | curvar->v_module = 1; |
---|
133 | } |
---|
134 | /* Puis on donne le nom du module dans curvar->v_modulename */ |
---|
135 | strcpy(curvar->v_modulename,curmodulename); |
---|
136 | /* Si cette variable a ete initialisee */ |
---|
137 | if (InitialValueGiven == 1 ) strcpy(curvar->v_initialvalue,InitValue); |
---|
138 | /* Si cette variable est declaree en save */ |
---|
139 | if (SaveDeclare == 1 ) curvar->v_save = 1; |
---|
140 | /* Si cette variable est v_allocatable */ |
---|
141 | if (Allocatabledeclare == 1 ) curvar->v_allocatable=1; |
---|
142 | /* if INTENT spec has been given */ |
---|
143 | if ( strcasecmp(IntentSpec,"") ) strcpy(curvar->v_IntentSpec,IntentSpec); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /******************************************************************************/ |
---|
148 | /* duplicatelistvar */ |
---|
149 | /******************************************************************************/ |
---|
150 | /* */ |
---|
151 | /******************************************************************************/ |
---|
152 | void duplicatelistvar(listvar *orig) |
---|
153 | { |
---|
154 | listvar *parcours; |
---|
155 | listvar *tmplistvar; |
---|
156 | listvar *tmplistvarprec; |
---|
157 | listdim *tmplistdim; |
---|
158 | variable *tmpvar; |
---|
159 | |
---|
160 | tmplistvarprec = (listvar *)NULL; |
---|
161 | parcours = orig; |
---|
162 | while ( parcours ) |
---|
163 | { |
---|
164 | tmplistvar = (listvar *)malloc(sizeof(listvar)); |
---|
165 | tmpvar = (variable *)malloc(sizeof(variable)); |
---|
166 | /* */ |
---|
167 | Init_Variable(tmpvar); |
---|
168 | /* */ |
---|
169 | strcpy(tmpvar->v_typevar,parcours->var->v_typevar); |
---|
170 | strcpy(tmpvar->v_nomvar,parcours->var->v_nomvar); |
---|
171 | strcpy(tmpvar->v_oldname,parcours->var->v_oldname); |
---|
172 | strcpy(tmpvar->v_dimchar,parcours->var->v_dimchar); |
---|
173 | if ( parcours->var->v_dimension ) |
---|
174 | { |
---|
175 | tmplistdim = (listdim *)malloc(sizeof(listdim)); |
---|
176 | tmplistdim = parcours->var->v_dimension; |
---|
177 | tmpvar->v_dimension = tmplistdim; |
---|
178 | } |
---|
179 | tmpvar->v_nbdim=parcours->var->v_nbdim; |
---|
180 | tmpvar->v_common=parcours->var->v_common; |
---|
181 | tmpvar->v_positioninblock=parcours->var->v_positioninblock; |
---|
182 | tmpvar->v_module=parcours->var->v_module; |
---|
183 | tmpvar->v_save=parcours->var->v_save; |
---|
184 | tmpvar->v_VariableIsParameter=parcours->var->v_VariableIsParameter; |
---|
185 | tmpvar->v_indicetabvars=parcours->var->v_indicetabvars; |
---|
186 | strcpy(tmpvar->v_modulename,parcours->var->v_modulename); |
---|
187 | strcpy(tmpvar->v_commonname,parcours->var->v_commonname); |
---|
188 | strcpy(tmpvar->v_vallengspec,parcours->var->v_vallengspec); |
---|
189 | strcpy(tmpvar->v_nameinttypename,parcours->var->v_nameinttypename); |
---|
190 | tmpvar->v_pointedvar=parcours->var->v_pointedvar; |
---|
191 | strcpy(tmpvar->v_commoninfile,mainfile); |
---|
192 | strcpy(tmpvar->v_subroutinename,parcours->var->v_subroutinename); |
---|
193 | tmpvar->v_dimensiongiven=parcours->var->v_dimensiongiven; |
---|
194 | tmpvar->v_c_star=parcours->var->v_c_star; |
---|
195 | strcpy(tmpvar->v_precision,parcours->var->v_precision); |
---|
196 | strcpy(tmpvar->v_initialvalue,parcours->var->v_initialvalue); |
---|
197 | tmpvar->v_pointerdeclare=parcours->var->v_pointerdeclare; |
---|
198 | tmpvar->v_optionaldeclare=parcours->var->v_optionaldeclare; |
---|
199 | tmpvar->v_allocatable=parcours->var->v_allocatable; |
---|
200 | strcpy(tmpvar->v_IntentSpec,parcours->var->v_IntentSpec); |
---|
201 | tmpvar->v_dimsempty=parcours->var->v_dimsempty; |
---|
202 | strcpy(tmpvar->v_readedlistdimension, |
---|
203 | parcours->var->v_readedlistdimension); |
---|
204 | /* */ |
---|
205 | tmplistvar->var = tmpvar; |
---|
206 | tmplistvar->suiv = NULL; |
---|
207 | /* */ |
---|
208 | if ( !listduplicated ) |
---|
209 | { |
---|
210 | listduplicated = tmplistvar; |
---|
211 | tmplistvarprec = listduplicated; |
---|
212 | } |
---|
213 | else |
---|
214 | { |
---|
215 | tmplistvarprec->suiv = tmplistvar; |
---|
216 | tmplistvarprec = tmplistvar; |
---|
217 | } |
---|
218 | /* */ |
---|
219 | parcours = parcours->suiv; |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | /******************************************************************************/ |
---|
224 | /* insertdim */ |
---|
225 | /******************************************************************************/ |
---|
226 | /* This subroutine is used to insert a record in a list of */ |
---|
227 | /* struct : listdim */ |
---|
228 | /******************************************************************************/ |
---|
229 | /* _______ _______ _______ _______ _______ */ |
---|
230 | /* + + + + + + + + + + */ |
---|
231 | /* + NEW +--->+ lin +--->+ lin +--->+ lin +--->+ lin + */ |
---|
232 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
233 | /* */ |
---|
234 | /******************************************************************************/ |
---|
235 | listdim * insertdim(listdim *lin,typedim nom) |
---|
236 | { |
---|
237 | listdim *newdim ; |
---|
238 | listdim *parcours ; |
---|
239 | |
---|
240 | newdim=(listdim *) malloc (sizeof (listdim)); |
---|
241 | newdim->dim=nom; |
---|
242 | newdim->suiv=NULL; |
---|
243 | |
---|
244 | if ( ! lin ) |
---|
245 | { |
---|
246 | lin = newdim; |
---|
247 | } |
---|
248 | else |
---|
249 | { |
---|
250 | parcours = lin; |
---|
251 | while ( parcours->suiv ) parcours=parcours->suiv; |
---|
252 | parcours->suiv = newdim; |
---|
253 | } |
---|
254 | |
---|
255 | return lin; |
---|
256 | } |
---|
257 | |
---|
258 | /******************************************************************************/ |
---|
259 | /* change_dim_char */ |
---|
260 | /******************************************************************************/ |
---|
261 | /* This subroutine is used to change the dimension in the list lin */ |
---|
262 | /******************************************************************************/ |
---|
263 | /* _______ _______ _______ _______ */ |
---|
264 | /* + l + + l + + l + + l + */ |
---|
265 | /* + old +--->+ old +--------------->+ lin +--->+ lin + */ |
---|
266 | /* +______+ +______+ +______+ +______+ */ |
---|
267 | /* */ |
---|
268 | /******************************************************************************/ |
---|
269 | void change_dim_char(listdim *lin,listvar * l) |
---|
270 | { |
---|
271 | listvar *parcours_var; |
---|
272 | variable *v; |
---|
273 | |
---|
274 | parcours_var=l; |
---|
275 | while(parcours_var) |
---|
276 | { |
---|
277 | v=parcours_var->var; |
---|
278 | strcpy(v->v_dimchar,(lin->dim).last); |
---|
279 | parcours_var=parcours_var->suiv; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | /******************************************************************************/ |
---|
285 | /* num_dims */ |
---|
286 | /******************************************************************************/ |
---|
287 | /* This subroutine is used to know the dimension of a table */ |
---|
288 | /******************************************************************************/ |
---|
289 | /* */ |
---|
290 | /* Dimension(jpi,jpj,jpk) ----------> num_dims = 3 */ |
---|
291 | /* */ |
---|
292 | /******************************************************************************/ |
---|
293 | int num_dims(listdim *d) |
---|
294 | { |
---|
295 | listdim *parcours; |
---|
296 | int compteur = 0; |
---|
297 | |
---|
298 | parcours = d; |
---|
299 | while(parcours) |
---|
300 | { |
---|
301 | compteur++; |
---|
302 | parcours=parcours->suiv; |
---|
303 | } |
---|
304 | return compteur; |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | /******************************************************************************/ |
---|
309 | /* CREATEVAR */ |
---|
310 | /******************************************************************************/ |
---|
311 | /* This subroutine is used to create and initialized a record of the */ |
---|
312 | /* struct : variable */ |
---|
313 | /******************************************************************************/ |
---|
314 | variable * createvar(char *nom,listdim *d) |
---|
315 | { |
---|
316 | variable *var; |
---|
317 | listdim *dims; |
---|
318 | char ligne[LONGNOM]; |
---|
319 | char listdimension[LONGNOM]; |
---|
320 | |
---|
321 | var=(variable *) malloc(sizeof(variable)); |
---|
322 | /* */ |
---|
323 | Init_Variable(var); |
---|
324 | /* */ |
---|
325 | strcpy(var->v_nomvar,nom); |
---|
326 | /* */ |
---|
327 | strcpy(listdimension,""); |
---|
328 | strcpy(var->v_modulename,curmodulename); |
---|
329 | strcpy(var->v_commoninfile,mainfile); |
---|
330 | strcpy(var->v_subroutinename,subroutinename); |
---|
331 | /* */ |
---|
332 | if ( strcasecmp(nameinttypename,"") ) |
---|
333 | strcpy(var->v_nameinttypename,nameinttypename); |
---|
334 | if ( optionaldeclare == 1 ) var->v_optionaldeclare = 1; |
---|
335 | if ( pointerdeclare == 1 ) var->v_pointerdeclare = 1; |
---|
336 | if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ; |
---|
337 | if ( PublicDeclare == 1 ) var->v_PublicDeclare = 1 ; |
---|
338 | if ( PrivateDeclare == 1 ) var->v_PrivateDeclare = 1; |
---|
339 | if ( ExternalDeclare == 1 ) var->v_ExternalDeclare = 1; |
---|
340 | /* */ |
---|
341 | var->v_dimension=d; |
---|
342 | /* Creation of the string for the dimension of this variable */ |
---|
343 | dimsempty = 1; |
---|
344 | if ( d ) |
---|
345 | { |
---|
346 | var->v_dimensiongiven=1; |
---|
347 | dims = d; |
---|
348 | while (dims) |
---|
349 | { |
---|
350 | if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,"")) |
---|
351 | dimsempty = 0; |
---|
352 | sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last); |
---|
353 | strcat(listdimension,ligne); |
---|
354 | if ( dims->suiv ) |
---|
355 | { |
---|
356 | strcat(listdimension,","); |
---|
357 | } |
---|
358 | dims = dims->suiv; |
---|
359 | } |
---|
360 | if ( dimsempty == 1 ) var->v_dimsempty=1; |
---|
361 | } |
---|
362 | strcpy(var->v_readedlistdimension,listdimension); |
---|
363 | /* */ |
---|
364 | var->v_nbdim=num_dims(d); |
---|
365 | /* */ |
---|
366 | return var; |
---|
367 | } |
---|
368 | |
---|
369 | /******************************************************************************/ |
---|
370 | /* INSERTVAR */ |
---|
371 | /******************************************************************************/ |
---|
372 | /* This subroutine is used to insert a record in a list of the */ |
---|
373 | /* struct : listvar */ |
---|
374 | /******************************************************************************/ |
---|
375 | /* _______ _______ _______ _______ _______ */ |
---|
376 | /* + + + + + + + + + + */ |
---|
377 | /* + lin +--->+ lin +--->+ lin +--->+ lin +--->+ NEW + */ |
---|
378 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
379 | /* */ |
---|
380 | /* */ |
---|
381 | /******************************************************************************/ |
---|
382 | listvar * insertvar(listvar *lin,variable *v) |
---|
383 | { |
---|
384 | listvar *newvar ; |
---|
385 | listvar *tmpvar ; |
---|
386 | |
---|
387 | newvar=(listvar *) malloc (sizeof (listvar)); |
---|
388 | newvar->var=v; |
---|
389 | newvar->suiv = NULL; |
---|
390 | if (!lin) |
---|
391 | { |
---|
392 | newvar->suiv=NULL; |
---|
393 | lin = newvar; |
---|
394 | } |
---|
395 | else |
---|
396 | { |
---|
397 | tmpvar = lin ; |
---|
398 | while (tmpvar->suiv) |
---|
399 | { |
---|
400 | tmpvar = tmpvar ->suiv ; |
---|
401 | } |
---|
402 | tmpvar -> suiv = newvar; |
---|
403 | } |
---|
404 | return lin; |
---|
405 | } |
---|
406 | |
---|
407 | /******************************************************************************/ |
---|
408 | /* SETTYPE */ |
---|
409 | /******************************************************************************/ |
---|
410 | /* This subroutine is used to give the same variable type at each */ |
---|
411 | /* record of the list of the struct : listvar */ |
---|
412 | /******************************************************************************/ |
---|
413 | /* _______ _______ _______ _______ _______ */ |
---|
414 | /* + REAL + + REAL + + REAL + + REAL + + REAL + */ |
---|
415 | /* + lin +--->+ lin +--->+ lin +--->+ lin +--->+ lin + */ |
---|
416 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
417 | /* */ |
---|
418 | /* */ |
---|
419 | /******************************************************************************/ |
---|
420 | listvar *settype(char *nom,listvar *lin) |
---|
421 | { |
---|
422 | listvar *newvar; |
---|
423 | variable *v; |
---|
424 | |
---|
425 | newvar=lin; |
---|
426 | while (newvar) |
---|
427 | { |
---|
428 | v=newvar->var; |
---|
429 | strcpy(v->v_typevar,nom); |
---|
430 | newvar=newvar->suiv; |
---|
431 | } |
---|
432 | newvar=lin; |
---|
433 | return newvar ; |
---|
434 | } |
---|