New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
convert.y in trunk/AGRIF/LIB – NEMO

source: trunk/AGRIF/LIB/convert.y @ 774

Last change on this file since 774 was 774, checked in by rblod, 16 years ago

Update Agrif, see ticket:#39

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
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%{
36#include <stdlib.h>
37#include <stdio.h>
38#include <string.h>
39#include "decl.h"
40%}
41
42%union {
43       int ival;
44       char na[LONG_C];
45       listnom * ln;
46       }
47
48%token TOK_SEP
49%token TOK_USE
50%token TOK_MODULEMAIN      /* name of the module                              */
51%token TOK_NOTGRIDDEP      /* Variable which are not grid dependent           */
52%token <na> TOK_USEITEM
53%token <na> TOK_NAME
54%token <na> TOK_PROBTYPE   /* dimension of the problem                        */
55%token ','
56%token ';'
57%token ':'
58%token '('
59%token ')'
60%token '['
61%token ']'
62%%
63input :
64      | input line
65;
66line :'\n'
67      | TOK_PROBTYPE TOK_NAME ';'                   {initdimprob(1,$2,"0","0");}
68      | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';'      {initdimprob(2,$2, $4,"0");}
69      | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';'
70                                                    {initdimprob(3,$2, $4, $6);}
71      | TOK_MODULEMAIN TOK_NAME ';'
72                             {listofmodules = Addtolistnom($2,listofmodules,0);
73                                                        Addmoduletothelist($2);}
74      | TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';'       {Add_NotGridDepend_Var_1($3);}
75      | TOK_USE TOK_USEITEM ';'  {
76                                    if (!strcasecmp($2,"FIXED_GRIDS"))
77                                                                 fixedgrids=1;
78                                    if (!strcasecmp($2,"ONLY_FIXED_GRIDS"))
79                                                             onlyfixedgrids=1;
80                                 }
81      ;
82%%
83
84int main(int argc,char *argv[])
85{
86   extern FILE * yyin ;
87   FILE *dependglobaloutput;
88   int i;
89   listnom *parcours;
90   listvar *newvar;
91
92   if (argc < 2)
93   {
94       printf("usage : conv <file> [-rm] [-incdir <directory>] \n");
95       printf(" [-comdirin   <directory>] [-comdirout <directory>]\n");
96       printf(" [-convfile  <FILENAME >] -SubloopScalar -SubloopScalar1 \n");
97       exit(0);
98   }
99/******************************************************************************/
100/*  1-  Variables initialization                                              */
101/******************************************************************************/
102   List_Global_Var=(listvar *)NULL;
103   List_GlobalParameter_Var=(listvar *)NULL;
104   List_Allocate_Var=(listallocate *)NULL;
105   List_Common_Var=(listvar *)NULL;
106   List_SubroutineWhereAgrifUsed=(listnom *)NULL;
107   List_Subroutine_For_Alloc=(listnom *)NULL;
108   List_Include=(listusemodule *)NULL;
109   List_NameOfModuleUsed=(listusemodule *)NULL;
110   listofmoduletmp=(listusemodule *)NULL;
111   List_SubroutineDeclaration_Var=(listvar *)NULL;
112   List_UsedInSubroutine_Var=(listvar *)NULL;
113   List_NotGridDepend_Var=(listvar *)NULL;
114   Listofavailableindices=(listindice *)NULL;
115   List_CouplePointed_Var=(listvarpointtovar *)NULL;
116   List_ModuleUsed_Var = (listvar *)NULL;
117   List_ModuleUsedInModuleUsed_Var = (listvar *)NULL;
118   List_GlobParamModuleUsed_Var = (listparameter *)NULL;
119   List_GlobParamModuleUsedInModuleUsed_Var = (listparameter *)NULL;
120   List_SubroutineArgument_Var = (listvar *)NULL;
121   List_FunctionType_Var = (listvar *)NULL;
122   tmpuselocallist = (listusemodule *)NULL;
123   List_ContainsSubroutine = (listnom *)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(mpiinitvar,"");
133
134   length_last = 0 ;
135   length_first = 0 ;
136   length_v_typevar = 0 ;
137   length_v_nomvar = 0 ;
138   length_v_dimchar = 0 ;
139   length_v_modulename = 0 ;
140   length_v_commonname = 0 ;
141   length_v_vallengspec = 0 ;
142   length_v_nameinttypename = 0 ;
143   length_v_commoninfile = 0 ;
144   length_v_subroutinename = 0 ;
145   length_v_precision = 0 ;
146   length_v_IntentSpec = 0 ;
147   length_v_initialvalue = 0 ;
148   length_v_readedlistdimension = 0 ;
149   length_u_usemodule = 0 ;
150   length_u_charusemodule = 0 ;
151   length_u_cursubroutine = 0 ;
152   length_u_modulename = 0 ;
153   length_n_name = 0 ;
154   length_c_namevar = 0 ;
155   length_c_namepointedvar = 0 ;
156   length_o_nom = 0 ;
157   length_o_module = 0 ;
158   length_a_nomvar = 0 ;
159   length_a_subroutine = 0 ;
160   length_a_module = 0 ;
161   length_t_usemodule = 0 ;
162   length_t_cursubroutine = 0 ;
163   length_curfilename = 0 ;
164   length_nomfileoutput = 0 ;
165   length_motparse = 0 ;
166   length_mainfile = 0 ;
167   length_nomdir = 0 ;
168   length_commondirout = 0 ;
169   length_commondirin = 0 ;
170   length_filetoparse = 0 ;
171   length_curbuf = 0 ;
172   length_toprintglob = 0 ;
173   length_tmpvargridname = 0 ;
174   length_ligne_Subloop = 0 ;
175   length_lvargridname_toamr = 0 ;
176   length_toprint_utilagrif = 0 ;
177   length_toprinttmp_utilchar = 0 ;
178   length_ligne_writedecl = 0 ;
179   length_newname_toamr = 0 ;
180   length_newname_writedecl = 0 ;
181   length_ligne_toamr = 0 ;
182   length_tmpligne_writedecl = 0 ;
183   value_char_size = 0 ;
184   value_char_size1 = 0 ;
185   value_char_size2 = 0 ;
186   value_char_size3 = 0 ;
187
188   checkexistcommon=1;
189   todebug=0;
190   onlyfixedgrids=0;
191   fixedgrids=0;
192   InAgrifParentDef = 0;
193   IndicenbmaillesX=0;
194   IndicenbmaillesY=0;
195   IndicenbmaillesZ=0;
196   created_dimensionlist = 1;
197   indicemaxtabvars = 0;   /* current indice in the table tabvars             */
198   SubloopScalar = 0;
199   todebug = 0;
200   todebugfree = 0;
201   retour77 = 1 ;
202   mark = 0 ;
203   shouldincludempif = 0 ;
204   Read_val_max();
205/******************************************************************************/
206/*  2-  Program arguments                                                     */
207/******************************************************************************/
208
209   if ((yyin=fopen(argv[1],"r"))==NULL)
210   {
211      printf("the file %s doesn't exist \n",argv[1]);
212      exit(0);
213   }
214
215   i=2;
216   while (i<argc)
217   {
218      if (!strcasecmp(argv[i],"-incdir"))
219      {
220         strcpy(nomdir,argv[i+1]);
221         i++;
222      }
223      else if (!strcasecmp(argv[i],"-comdirin")) /* input directory           */
224      {
225         strcpy(commondirin,argv[i+1]);
226         i++;
227      }
228      else if (!strcasecmp(argv[i],"-comdirout")) /* output directory         */
229      {
230         strcpy(commondirout,argv[i+1]);
231         i++;
232      }
233      else if (!strcasecmp(argv[i],"-convfile")) /* file to parse             */
234      {
235         strcpy(filetoparse,argv[i+1]);
236         i++;
237      }
238      else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse        */
239      {
240         SubloopScalar = 1 ;
241      }
242      else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse       */
243      {
244         SubloopScalar = 2 ;
245      }
246      else if (!strcasecmp(argv[i],"-todebug")) /* file to parse       */
247      {
248         todebug = 1 ;
249      }
250      else if (!strcasecmp(argv[i],"-mark")) /* file to parse       */
251      {
252         mark = 1 ;
253      }
254      else if (!strcasecmp(argv[i],"-todebugfree")) /* file to parse       */
255      {
256         todebugfree = 1 ;
257      }
258      else if (!strcasecmp(argv[i],"-rm"))
259      {
260         checkexistcommon=0;
261      }
262      else
263      {
264         printf("Unkwon option : %s\n",argv[i]);
265         exit(0);
266      }
267      i++;
268   }
269
270   Save_Length(nomdir,34);
271   Save_Length(commondirout,35);
272   Save_Length(commondirin,36);
273   Save_Length(filetoparse,37);
274
275/******************************************************************************/
276/*  3-  Parsing of the  conv file <name>.in                                   */
277/******************************************************************************/
278
279   if ((yyin=fopen(argv[1],"r"))==NULL)
280   {
281       printf("the file %s doesn't exist \n",argv[1]);
282       exit(0);
283   }
284   strcpy(mainfile,argv[1]);
285   Save_Length(mainfile,33);
286
287   if ( strstr(filetoparse,".f90") ||
288        strstr(filetoparse,".F90") ) retour77 = 0;
289
290   yyparse();
291
292/******************************************************************************/
293/*  4-  Preparation of the file parsing                                       */
294/******************************************************************************/
295   if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ?   */
296   {
297      printf("the file %s doesn't exist \n",filetoparse);
298      exit(0);
299   }
300   /* mainfile : the name of the file to parse                                */
301   strcpy(mainfile,filetoparse);
302   /*                                                                         */
303   if ((dependglobaloutput=fopen(".dependglobal_agrif","r"))!=NULL)
304   {
305      fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars);
306      fclose(dependglobaloutput);
307   }
308   Readthedependavailablefile();
309   /* Read the .dependnbxnby file which contains indices of nbmaillsX,        */
310   /*    nbmailleY and nbmailleZ                                              */
311   Readthedependnbxnbyfile();
312   Read_Subroutine_For_Alloc();
313/******************************************************************************/
314/*  5-  Parsing of the input file (2 times)                                   */
315/******************************************************************************/
316   /* Record all variable in list                                             */
317   firstpass = 1;
318   processfortran(filetoparse);
319   /*                                                                         */
320   CompleteThelistvarindoloop();
321   /* Read list of module used                                                */
322   RecordUseModulesVariables();
323   /* Read list of module used in module used                                 */
324   RecordUseModulesUseModulesVariables();
325   /* Save variables are considered as globals ones                           */
326   Update_List_Global_Var_From_List_Save_Var();
327   /* Update all lists                                                        */
328   ListUpdate();
329   /*                                                                         */
330   Clean_List_Global_Var();
331   /* Indice tabvars identification                                           */
332   IndiceTabvarsIdentification();
333   /* Update all lists                                                        */
334   ListUpdate();
335   /* The allocation subroutine is necessary ????                             */
336   New_Allocate_Subroutine_Is_Necessary();
337   /* The allocation subroutine is necessary for common list                  */
338   New_Allocate_Subroutine_For_Common_Is_Necessary();
339   /* Sort List_SubroutineArgument_Var                                        */
340   Sort_List_SubroutineArgument_Var();
341   /* Clean all lists                                                         */
342   ListClean();
343   /* Update Indice of List_UsedInSubroutine_Var from module used             */
344   List_UsedInSubroutine_Var_Update_From_Module_Used();
345   /* Update List_SubroutineWhereAgrifUsed                                    */
346   UpdateList_SubroutineWhereAgrifUsed();
347   /* Update List_UsedInSubroutine_Var with v_readedlistdimension             */
348   UpdateList_UsedInSubroutine_With_dimension();;
349   /*                                                                         */
350   ModifyThelistvarindoloop();
351   /*                                                                         */
352   UpdateListDeclarationWithDimensionList();
353   /*                                                                         */
354   GiveTypeOfVariables();
355   Affiche();
356   /* Build new subroutines                                                   */
357   firstpass = 0;
358   processfortran(filetoparse);
359
360   newvar = (listvar *)NULL;
361/*newvar = List_Global_Var; */
362   while ( newvar )
363   {
364      printf("++++ %s %d %s %s %s\n",
365      newvar->var->v_nomvar,
366      newvar->var->v_nbdim,
367      newvar->var->v_subroutinename,
368      newvar->var->v_modulename,
369      newvar->var->v_typevar
370             );
371      newvar = newvar->suiv;
372   }
373/******************************************************************************/
374/*  6-  Write informations in output files                                    */
375/******************************************************************************/
376
377   /* Write the .dependglobal_agrif file which contain the max indice         */
378   /*    of the tabvars table                                                 */
379   dependglobaloutput = fopen(".dependglobal_agrif","w");
380   fprintf(dependglobaloutput,"%d\n",indicemaxtabvars);
381   fclose(dependglobaloutput);
382   /* Write the list of available indice                                      */
383   Writethedependavailablefile();
384   /* Write the .dependnbxnby file which contains indices of nbmaillsX,       */
385   /*    nbmailleY and nbmailleZ                                              */
386   Writethedependnbxnbyfile();
387   /* Write the .depend<namefile> file which contain general informations     */
388   /*    about variable of this file                                          */
389   parcours = List_NameOfModule;
390   while( parcours )
391   {
392      Writethedependlistofmoduleused(parcours->o_nom);
393      WritedependParameterList(parcours->o_nom);
394      Writethedependfile(parcours->o_nom,List_Global_Var);
395      parcours=parcours->suiv;
396   }
397   parcours = List_NameOfCommon;
398   while( parcours )
399   {
400      Writethedependfile(parcours->o_nom,List_Common_Var);
401      parcours=parcours->suiv;
402   }
403   Write_Subroutine_For_Alloc();
404/******************************************************************************/
405/*  7-  Create files in AGRIF_INC directory                                   */
406/******************************************************************************/
407   creefichieramr(NameTamponfile);
408
409   Write_val_max();
410
411   if ( todebug == 1 ) printf("Out of CONV \n");
412   return 0;
413}
Note: See TracBrowser for help on using the repository browser.