1 | /******************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
4 | /* */ |
---|
5 | /* Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
6 | /* Cyril Mazauric (Cyril.Mazauric@imag.fr) */ |
---|
7 | /* */ |
---|
8 | /* This program is free software; you can redistribute it and/or modify */ |
---|
9 | /* it */ |
---|
10 | /* */ |
---|
11 | /* This program is distributed in the hope that it will be useful, */ |
---|
12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
---|
13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
---|
14 | /* GNU General Public License for more details. */ |
---|
15 | /* */ |
---|
16 | /******************************************************************************/ |
---|
17 | %{ |
---|
18 | #include <stdlib.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | #include "decl.h" |
---|
22 | %} |
---|
23 | |
---|
24 | %union { |
---|
25 | int ival; |
---|
26 | char na[LONGNOM]; |
---|
27 | listnom * ln; |
---|
28 | } |
---|
29 | |
---|
30 | %token TOK_SEP |
---|
31 | %token TOK_USE |
---|
32 | %token TOK_MINWIDTH /* minimum width for the adaptive refinement */ |
---|
33 | %token TOK_REGRIDDING |
---|
34 | %token TOK_COEFFRAFX /* space refinement factor in the x direction */ |
---|
35 | %token TOK_COEFFRAFY /* space refinement factor in the y direction */ |
---|
36 | %token TOK_COEFFRAFZ /* space refinement factor in the z direction */ |
---|
37 | %token TOK_COEFFRAFTX /* time refinement factor in the x direction */ |
---|
38 | %token TOK_COEFFRAFTY /* time refinement factor in the y direction */ |
---|
39 | %token TOK_COEFFRAFTZ /* time refinement factor in the z direction */ |
---|
40 | %token TOK_MODULEMAIN /* name of the module */ |
---|
41 | %token TOK_NOTGRIDDEP /* Variable which are not grid dependent */ |
---|
42 | %token <ival> TOK_NUM |
---|
43 | %token <na> TOK_FILENAME |
---|
44 | %token <na> TOK_USEITEM |
---|
45 | %token <na> TOK_NAME |
---|
46 | %token <na> TOK_PROBTYPE /* dimension of the problem */ |
---|
47 | %token <na> TOK_EFFICIENCY /* efficiency for the adaptive refinement */ |
---|
48 | %token <na> TOK_RAFMAX |
---|
49 | %token <na> TOK_RAFMAXX |
---|
50 | %token <na> TOK_RAFMAXY |
---|
51 | %token <na> TOK_RAFMAXZ |
---|
52 | %token ',' |
---|
53 | %token ';' |
---|
54 | %token ':' |
---|
55 | %token '(' |
---|
56 | %token ')' |
---|
57 | %token '[' |
---|
58 | %token ']' |
---|
59 | %% |
---|
60 | input : |
---|
61 | | input line |
---|
62 | ; |
---|
63 | line :'\n' |
---|
64 | | TOK_PROBTYPE TOK_NAME ';' {initdimprob(1,$2,"0","0");} |
---|
65 | | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';' {initdimprob(2,$2, $4,"0");} |
---|
66 | | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';' |
---|
67 | {initdimprob(3,$2, $4, $6);} |
---|
68 | | TOK_COEFFRAFX TOK_NUM ';' {coeffrafx =$2;} |
---|
69 | | TOK_REGRIDDING TOK_NUM ';' {regridding=$2;} |
---|
70 | | TOK_COEFFRAFY TOK_NUM ';' {coeffrafy =$2;} |
---|
71 | | TOK_COEFFRAFZ TOK_NUM ';' {coeffrafz =$2;} |
---|
72 | | TOK_COEFFRAFTX TOK_NUM ';' {coeffraftx=$2;} |
---|
73 | | TOK_COEFFRAFTY TOK_NUM ';' {coeffrafty=$2;} |
---|
74 | | TOK_COEFFRAFTZ TOK_NUM ';' {coeffraftz=$2;} |
---|
75 | | TOK_MODULEMAIN TOK_NAME ';' {Add_ModuleTo_listofmodules($2); |
---|
76 | Addmoduletothelist($2);} |
---|
77 | | TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';' {ajoutenotgriddep($3);} |
---|
78 | | TOK_EFFICIENCY TOK_NUM ';' {userefficiency=1;efficiency=$2;} |
---|
79 | | TOK_RAFMAX TOK_NUM ';' {rafmaxx=$2,rafmaxy=$2,rafmaxz=$2;} |
---|
80 | | TOK_RAFMAXX TOK_NUM ';' {rafmaxx =$2;} |
---|
81 | | TOK_RAFMAXY TOK_NUM ';' {rafmaxy =$2;} |
---|
82 | | TOK_RAFMAXZ TOK_NUM ';' {rafmaxz =$2;} |
---|
83 | | TOK_MINWIDTH TOK_NUM ';' {minwidth =$2;} |
---|
84 | | TOK_USE TOK_USEITEM ';' { |
---|
85 | if (!strcasecmp($2,"FIXED_GRIDS")) |
---|
86 | fixedgrids=1; |
---|
87 | if (!strcasecmp($2,"ONLY_FIXED_GRIDS")) |
---|
88 | onlyfixedgrids=1; |
---|
89 | if (!strcasecmp($2,"DEBUG")) todebug=1; |
---|
90 | } |
---|
91 | ; |
---|
92 | %% |
---|
93 | |
---|
94 | int main(int argc,char *argv[]) |
---|
95 | { |
---|
96 | extern FILE * yyin ; |
---|
97 | FILE *dependglobaloutput; |
---|
98 | char *tmp; |
---|
99 | int i; |
---|
100 | listnom *parcours; |
---|
101 | |
---|
102 | /******************************************************************************/ |
---|
103 | /* 1- Variables initialization */ |
---|
104 | /******************************************************************************/ |
---|
105 | globliste=(listvar *)NULL; |
---|
106 | listenamelist=(listnamelist *)NULL; |
---|
107 | globparam=(listvar *)NULL; |
---|
108 | globvarforcommon=(listvar *)NULL; |
---|
109 | AllocateList=(listallocate *)NULL; |
---|
110 | commonlist=(listvarcommon *)NULL; |
---|
111 | listofsubroutinewhereagrifisused=(listnom *)NULL; |
---|
112 | listofincludebysubroutine=(listusemodule *)NULL; |
---|
113 | listofmodulebysubroutine=(listusemodule *)NULL; |
---|
114 | listofmoduletmp=(listusemodule *)NULL; |
---|
115 | listmoduleinfile=(listmodule *)NULL; |
---|
116 | varofsubroutineliste=(listvar *)NULL; |
---|
117 | varsubroutine=(listvar *)NULL; |
---|
118 | listvarindoloop=(listvar *)NULL; |
---|
119 | listenotgriddepend=(listvar *)NULL; |
---|
120 | Listofavailableindices=(listindice *)NULL; |
---|
121 | Listofvarpointtovar=(listvarpointtovar *)NULL; |
---|
122 | globalvarofusefile = (listvar *)NULL; |
---|
123 | globalvarofusefile2 = (listvar *)NULL; |
---|
124 | |
---|
125 | strcpy(mainfile,argv[1]); |
---|
126 | strcpy(nomdir,"AGRIF_INC"); |
---|
127 | strcpy(commondirin,"."); |
---|
128 | strcpy(commondirout,"."); |
---|
129 | strcpy(filetoparse," "); |
---|
130 | strcpy(subofagrifinitgrids,""); |
---|
131 | strcpy(meetagrifinitgrids,""); |
---|
132 | strcpy(meetmpiinit,""); |
---|
133 | strcpy(mpiinitvar,""); |
---|
134 | |
---|
135 | listofvarofusemodulecreated=0; |
---|
136 | checkexistcommon=1; |
---|
137 | fortran77 = 0 ; |
---|
138 | Did_filetoparse_treated = 0 ; |
---|
139 | userefficiency=0; |
---|
140 | todebug=0; |
---|
141 | onlyfixedgrids=0; |
---|
142 | fixedgrids=0; |
---|
143 | InAgrifParentDef = 0; |
---|
144 | rafmaxx=0; |
---|
145 | rafmaxy=0; |
---|
146 | rafmaxz=0; |
---|
147 | IntegerIShouldBeAdd=0; |
---|
148 | IndicenbmaillesX=0; |
---|
149 | IndicenbmaillesY=0; |
---|
150 | IndicenbmaillesZ=0; |
---|
151 | minwidth=1; |
---|
152 | coeffrafx=0; |
---|
153 | coeffrafy=0; |
---|
154 | coeffrafz=0; |
---|
155 | indicemaxtabvars = 0; /* current indice in the table tabvars */ |
---|
156 | oldindicemaxtabvars = 0;/* current indice in the table tabvars */ |
---|
157 | SubloopScalar = 0; |
---|
158 | /******************************************************************************/ |
---|
159 | /* 2- Program arguments */ |
---|
160 | /******************************************************************************/ |
---|
161 | if (argc < 2) |
---|
162 | { |
---|
163 | printf("usage : conv <file> [-rm] [-incdir <directory>] \n"); |
---|
164 | printf(" [-comdirin <directory>] [-comdirout <directory>]\n"); |
---|
165 | printf(" [-convfile <FILENAME >] -SubloopScalar -SubloopScalar1 \n"); |
---|
166 | printf(" -f77\n"); |
---|
167 | exit(0); |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | if ((yyin=fopen(argv[1],"r"))==NULL) |
---|
172 | { |
---|
173 | printf("the file %s doesn't exist \n",argv[1]); |
---|
174 | exit(0); |
---|
175 | } |
---|
176 | |
---|
177 | i=2; |
---|
178 | while (i<argc) |
---|
179 | { |
---|
180 | if (!strcasecmp(argv[i],"-incdir")) |
---|
181 | { |
---|
182 | strcpy(nomdir,argv[i+1]); |
---|
183 | i++; |
---|
184 | } |
---|
185 | else if (!strcasecmp(argv[i],"-comdirin")) /* input directory */ |
---|
186 | { |
---|
187 | strcpy(commondirin,argv[i+1]); |
---|
188 | i++; |
---|
189 | } |
---|
190 | else if (!strcasecmp(argv[i],"-comdirout")) /* output directory */ |
---|
191 | { |
---|
192 | strcpy(commondirout,argv[i+1]); |
---|
193 | i++; |
---|
194 | } |
---|
195 | else if (!strcasecmp(argv[i],"-convfile")) /* file to parse */ |
---|
196 | { |
---|
197 | strcpy(filetoparse,argv[i+1]); |
---|
198 | i++; |
---|
199 | } |
---|
200 | else if (!strcasecmp(argv[i],"-f77")) /* fortran 77 file to parse */ |
---|
201 | { |
---|
202 | fortran77 = 1 ; |
---|
203 | } |
---|
204 | else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse */ |
---|
205 | { |
---|
206 | SubloopScalar = 1 ; |
---|
207 | } |
---|
208 | else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse */ |
---|
209 | { |
---|
210 | SubloopScalar = 2 ; |
---|
211 | } |
---|
212 | else if (!strcasecmp(argv[i],"-rm")) |
---|
213 | { |
---|
214 | checkexistcommon=0; |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | printf("Unkwon option : %s\n",argv[i]); |
---|
219 | exit(0); |
---|
220 | } |
---|
221 | i++; |
---|
222 | } |
---|
223 | |
---|
224 | /******************************************************************************/ |
---|
225 | /* 3- Parsing of the conv file <name>.in */ |
---|
226 | /******************************************************************************/ |
---|
227 | |
---|
228 | if ((yyin=fopen(argv[1],"r"))==NULL) |
---|
229 | { |
---|
230 | printf("the file %s doesn't exist \n",argv[1]); |
---|
231 | exit(0); |
---|
232 | } |
---|
233 | strcpy(mainfile,argv[1]); |
---|
234 | |
---|
235 | yyparse(); |
---|
236 | |
---|
237 | /******************************************************************************/ |
---|
238 | /* 4- Preparation of the file parsing */ |
---|
239 | /******************************************************************************/ |
---|
240 | if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ? */ |
---|
241 | { |
---|
242 | printf("the file %s doesn't exist \n",filetoparse); |
---|
243 | exit(0); |
---|
244 | } |
---|
245 | /* NameTamponfile : the name of the model file extract from the name */ |
---|
246 | /* of agrif_module_<NameTamponfile> */ |
---|
247 | tmp = strchr(filetoparse, '.'); |
---|
248 | NameTamponfile=(char *)malloc( |
---|
249 | (strlen(filetoparse)-strlen(tmp)+1)*sizeof(char)); |
---|
250 | strncpy(NameTamponfile,filetoparse,strlen(filetoparse)-strlen(tmp)+1); |
---|
251 | strcpy (&NameTamponfile[strlen(filetoparse)-strlen(tmp)], "\0"); |
---|
252 | /* mainfile : the name of the file to parse */ |
---|
253 | strcpy(mainfile,filetoparse); |
---|
254 | /* We should verify that this file has not been read before */ |
---|
255 | /* if it is the case we record the old globliste in the tmplocallist */ |
---|
256 | tmplocallist = NULL; |
---|
257 | tmpuselocallist = NULL; |
---|
258 | Did_filetoparse_treated = Did_filetoparse_readed(NameTamponfile); |
---|
259 | /* if Did_filetoparse_treated = 1 then the file to parse has been treated */ |
---|
260 | if ( Did_filetoparse_treated == 0 ) |
---|
261 | { |
---|
262 | /* if the filetoparse has not been treated, we should know the last */ |
---|
263 | /* tabvars indices which has been used */ |
---|
264 | if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) |
---|
265 | { |
---|
266 | fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars); |
---|
267 | fclose(dependglobaloutput); |
---|
268 | oldindicemaxtabvars = indicemaxtabvars; |
---|
269 | } |
---|
270 | } |
---|
271 | /* Write the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
272 | /* nbmailleY and nbmailleZ */ |
---|
273 | Readthedependnbxnbyfile(); |
---|
274 | |
---|
275 | /******************************************************************************/ |
---|
276 | /* 4- Parsing of the input file (2 times) */ |
---|
277 | /******************************************************************************/ |
---|
278 | |
---|
279 | firstpass = 1; |
---|
280 | processfortran(filetoparse); |
---|
281 | firstpass = 0; |
---|
282 | processfortran(filetoparse); |
---|
283 | |
---|
284 | /******************************************************************************/ |
---|
285 | /* 5- Write informations in output files */ |
---|
286 | /******************************************************************************/ |
---|
287 | |
---|
288 | if ( Did_filetoparse_treated == 0 ) /* if the file has never been treated */ |
---|
289 | { |
---|
290 | /* Write the .dependglobal file which contain the max indice */ |
---|
291 | /* of the tabvars table */ |
---|
292 | dependglobaloutput = fopen(".dependglobal","w"); |
---|
293 | fprintf(dependglobaloutput,"%d\n",indicemaxtabvars); |
---|
294 | fclose(dependglobaloutput); |
---|
295 | /* Write the .depend<namefile> file which contain general informations */ |
---|
296 | /* about variable of this file */ |
---|
297 | parcours = modulelist; |
---|
298 | while( parcours ) |
---|
299 | { |
---|
300 | Writethedependfile(parcours->nom,globliste); |
---|
301 | parcours=parcours->suiv; |
---|
302 | } |
---|
303 | } |
---|
304 | |
---|
305 | /******************************************************************************/ |
---|
306 | /* 7- Remove the non grid dependent variables */ |
---|
307 | /******************************************************************************/ |
---|
308 | |
---|
309 | /* we should remove from the globliste the non grid dependent variables */ |
---|
310 | RemoveNotgriddependFromGlobliste(); |
---|
311 | |
---|
312 | /******************************************************************************/ |
---|
313 | /* 8- Write informations in output files */ |
---|
314 | /******************************************************************************/ |
---|
315 | |
---|
316 | /* if this file has been treated in past called, */ |
---|
317 | /* we should compare the old parsing (record in the tmplocallist) */ |
---|
318 | /* and the new one contained in the globliste */ |
---|
319 | if ( Did_filetoparse_treated == 1 ) |
---|
320 | { |
---|
321 | parcours = modulelist; |
---|
322 | while( parcours ) |
---|
323 | { |
---|
324 | Recordtmplocallist(parcours->nom); |
---|
325 | parcours=parcours->suiv; |
---|
326 | } |
---|
327 | /* if the filetoparse has not been treated, we should know */ |
---|
328 | /* the last tabvars indices which has been used */ |
---|
329 | if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) |
---|
330 | { |
---|
331 | fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars); |
---|
332 | fclose(dependglobaloutput); |
---|
333 | oldindicemaxtabvars = indicemaxtabvars; |
---|
334 | } |
---|
335 | /* Read the list of available indice */ |
---|
336 | Readthedependavailablefile(); |
---|
337 | /* the old treatement has been recorded in the tmplocallist */ |
---|
338 | /* Now we should compare the old treatement with the new one */ |
---|
339 | /*mazauric for each module */ |
---|
340 | CompareNewparsingandoldone(); |
---|
341 | /* Write the .dependglobal file which contain general informations */ |
---|
342 | /* about globlist */ |
---|
343 | dependglobaloutput = fopen(".dependglobal","w"); |
---|
344 | fprintf(dependglobaloutput,"%d\n",indicemaxtabvars); |
---|
345 | fclose(dependglobaloutput); |
---|
346 | /* Write the list of available indice */ |
---|
347 | Writethedependavailablefile(); |
---|
348 | /* Write the .depend<namefile> file which contain general */ |
---|
349 | /* informations about variable of this file */ |
---|
350 | parcours = modulelist; |
---|
351 | while( parcours ) |
---|
352 | { |
---|
353 | Writethedependfile(parcours->nom,globliste); |
---|
354 | parcours=parcours->suiv; |
---|
355 | } |
---|
356 | /* Write the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
357 | /* nbmailleY and nbmailleZ */ |
---|
358 | Writethedependnbxnbyfile(); |
---|
359 | } |
---|
360 | /* Write the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
361 | /* nbmailleY and nbmailleZ */ |
---|
362 | Writethedependnbxnbyfile(); |
---|
363 | /* Write the list of module used in this file */ |
---|
364 | Writethedependlistofmoduleused(NameTamponfile); |
---|
365 | WritedependParameterList(NameTamponfile); |
---|
366 | /******************************************************************************/ |
---|
367 | /* 8- Create files in AGRIF_INC directory */ |
---|
368 | /******************************************************************************/ |
---|
369 | creefichieramr(NameTamponfile); |
---|
370 | return 0; |
---|
371 | } |
---|