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 @ 663

Last change on this file since 663 was 663, checked in by opalod, 17 years ago

RB: update CONV

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.9 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.6                                                                */
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[LONGNOM];
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   char *tmp;
89   int i;
90   listnom *parcours;
91   listvar *newvar;
92
93   if (argc < 2)
94   {
95       printf("usage : conv <file> [-rm] [-incdir <directory>] \n");
96       printf(" [-comdirin   <directory>] [-comdirout <directory>]\n");
97       printf(" [-convfile  <FILENAME >] -SubloopScalar -SubloopScalar1 \n");
98       exit(0);
99   }
100/******************************************************************************/
101/*  1-  Variables initialization                                              */
102/******************************************************************************/
103   List_Global_Var=(listvar *)NULL;
104   List_GlobalParameter_Var=(listvar *)NULL;
105   List_Allocate_Var=(listallocate *)NULL;
106   List_Common_Var=(listvar *)NULL;
107   List_SubroutineWhereAgrifUsed=(listnom *)NULL;
108   List_Subroutine_For_Alloc=(listnom *)NULL;
109   List_Include=(listusemodule *)NULL;
110   List_NameOfModuleUsed=(listusemodule *)NULL;
111   listofmoduletmp=(listusemodule *)NULL;
112   List_SubroutineDeclaration_Var=(listvar *)NULL;
113   List_UsedInSubroutine_Var=(listvar *)NULL;
114   List_NotGridDepend_Var=(listvar *)NULL;
115   Listofavailableindices=(listindice *)NULL;
116   List_CouplePointed_Var=(listvarpointtovar *)NULL;
117   List_ModuleUsed_Var = (listvar *)NULL;
118   List_ModuleUsedInModuleUsed_Var = (listvar *)NULL;
119   List_GlobParamModuleUsed_Var = (listparameter *)NULL;
120   List_GlobParamModuleUsedInModuleUsed_Var = (listparameter *)NULL;
121   List_SubroutineArgument_Var = (listvar *)NULL;
122   List_FunctionType_Var = (listvar *)NULL;
123   tmpuselocallist = (listusemodule *)NULL;
124   List_ContainsSubroutine = (listnom *)NULL;
125
126   strcpy(mainfile,argv[1]);
127   strcpy(nomdir,"AGRIF_INC");
128   strcpy(commondirin,".");
129   strcpy(commondirout,".");
130   strcpy(filetoparse," ");
131   strcpy(subofagrifinitgrids,"");
132   strcpy(meetagrifinitgrids,"");
133   strcpy(mpiinitvar,"");
134
135   checkexistcommon=1;
136   todebug=0;
137   onlyfixedgrids=0;
138   fixedgrids=0;
139   InAgrifParentDef = 0;
140   IndicenbmaillesX=0;
141   IndicenbmaillesY=0;
142   IndicenbmaillesZ=0;
143   created_dimensionlist = 1;
144   indicemaxtabvars = 0;   /* current indice in the table tabvars             */
145   SubloopScalar = 0;
146   todebug = 0;
147   todebugfree = 0;
148   retour77 = 1 ;
149   mark = 0 ;
150   shouldincludempif = 0 ;
151/******************************************************************************/
152/*  2-  Program arguments                                                     */
153/******************************************************************************/
154
155   if ((yyin=fopen(argv[1],"r"))==NULL)
156   {
157      printf("the file %s doesn't exist \n",argv[1]);
158      exit(0);
159   }
160
161   i=2;
162   while (i<argc)
163   {
164      if (!strcasecmp(argv[i],"-incdir"))
165      {
166         strcpy(nomdir,argv[i+1]);
167         i++;
168      }
169      else if (!strcasecmp(argv[i],"-comdirin")) /* input directory           */
170      {
171         strcpy(commondirin,argv[i+1]);
172         i++;
173      }
174      else if (!strcasecmp(argv[i],"-comdirout")) /* output directory         */
175      {
176         strcpy(commondirout,argv[i+1]);
177         i++;
178      }
179      else if (!strcasecmp(argv[i],"-convfile")) /* file to parse             */
180      {
181         strcpy(filetoparse,argv[i+1]);
182         i++;
183      }
184      else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse        */
185      {
186         SubloopScalar = 1 ;
187      }
188      else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse       */
189      {
190         SubloopScalar = 2 ;
191      }
192      else if (!strcasecmp(argv[i],"-todebug")) /* file to parse       */
193      {
194         todebug = 1 ;
195      }
196      else if (!strcasecmp(argv[i],"-mark")) /* file to parse       */
197      {
198         mark = 1 ;
199      }
200      else if (!strcasecmp(argv[i],"-todebugfree")) /* file to parse       */
201      {
202         todebugfree = 1 ;
203      }
204      else if (!strcasecmp(argv[i],"-rm"))
205      {
206         checkexistcommon=0;
207      }
208      else
209      {
210         printf("Unkwon option : %s\n",argv[i]);
211         exit(0);
212      }
213      i++;
214   }
215
216/******************************************************************************/
217/*  3-  Parsing of the  conv file <name>.in                                   */
218/******************************************************************************/
219
220   if ((yyin=fopen(argv[1],"r"))==NULL)
221   {
222       printf("the file %s doesn't exist \n",argv[1]);
223       exit(0);
224   }
225   strcpy(mainfile,argv[1]);
226
227   if ( strstr(filetoparse,".f90") ||
228        strstr(filetoparse,".F90") ) retour77 = 0;
229
230   yyparse();
231
232/******************************************************************************/
233/*  4-  Preparation of the file parsing                                       */
234/******************************************************************************/
235   if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ?   */
236   {
237      printf("the file %s doesn't exist \n",filetoparse);
238      exit(0);
239   }
240   /* mainfile : the name of the file to parse                                */
241   strcpy(mainfile,filetoparse);
242   /*                                                                         */
243   if ((dependglobaloutput=fopen(".dependglobal_agrif","r"))!=NULL)
244   {
245      fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars);
246      fclose(dependglobaloutput);
247   }
248   Readthedependavailablefile();
249   /* Read the .dependnbxnby file which contains indices of nbmaillsX,        */
250   /*    nbmailleY and nbmailleZ                                              */
251   Readthedependnbxnbyfile();
252   Read_Subroutine_For_Alloc();
253/******************************************************************************/
254/*  5-  Parsing of the input file (2 times)                                   */
255/******************************************************************************/
256   /* Record all variable in list                                             */
257   firstpass = 1;
258   processfortran(filetoparse);
259   /*                                                                         */
260   CompleteThelistvarindoloop();
261   /* Read list of module used                                                */
262   RecordUseModulesVariables();
263   /* Read list of module used in module used                                 */
264   RecordUseModulesUseModulesVariables();
265   /* Save variables are considered as globals ones                           */
266   Update_List_Global_Var_From_List_Save_Var();
267   /* Update all lists                                                        */
268   ListUpdate();
269   /* Indice tabvars identification                                           */
270   IndiceTabvarsIdentification();
271   /* Update all lists                                                        */
272   ListUpdate();
273   /* The allocation subroutine is necessary ????                             */
274   New_Allocate_Subroutine_Is_Necessary();
275   /* The allocation subroutine is necessary for common list                  */
276   New_Allocate_Subroutine_For_Common_Is_Necessary();
277   /* Sort List_SubroutineArgument_Var                                        */
278   Sort_List_SubroutineArgument_Var();
279   /* Clean all lists                                                         */
280   ListClean();
281   /* Update Indice of List_UsedInSubroutine_Var from module used             */
282   List_UsedInSubroutine_Var_Update_From_Module_Used();
283   /* Update List_SubroutineWhereAgrifUsed                                    */
284   UpdateList_SubroutineWhereAgrifUsed();
285   /* Update List_UsedInSubroutine_Var with v_readedlistdimension             */
286   UpdateList_UsedInSubroutine_With_dimension();;
287   /*                                                                         */
288   ModifyThelistvarindoloop();
289   /*                                                                         */
290   UpdateListDeclarationWithDimensionList();
291   /*                                                                         */
292   GiveTypeOfVariables();
293   Affiche();
294   /* Build new subroutines                                                   */
295   firstpass = 0;
296   processfortran(filetoparse);
297
298/******************************************************************************/
299/*  6-  Write informations in output files                                    */
300/******************************************************************************/
301
302   /* Write the .dependglobal_agrif file which contain the max indice         */
303   /*    of the tabvars table                                                 */
304   dependglobaloutput = fopen(".dependglobal_agrif","w");
305   fprintf(dependglobaloutput,"%d\n",indicemaxtabvars);
306   fclose(dependglobaloutput);
307   /* Write the list of available indice                                      */
308   Writethedependavailablefile();
309   /* Write the .dependnbxnby file which contains indices of nbmaillsX,       */
310   /*    nbmailleY and nbmailleZ                                              */
311   Writethedependnbxnbyfile();
312   /* Write the .depend<namefile> file which contain general informations     */
313   /*    about variable of this file                                          */
314   parcours = List_NameOfModule;
315   while( parcours )
316   {
317      Writethedependlistofmoduleused(parcours->o_nom);
318      WritedependParameterList(parcours->o_nom);
319      Writethedependfile(parcours->o_nom,List_Global_Var);
320      parcours=parcours->suiv;
321   }
322   parcours = List_NameOfCommon;
323   while( parcours )
324   {
325      Writethedependfile(parcours->o_nom,List_Common_Var);
326      parcours=parcours->suiv;
327   }
328   Write_Subroutine_For_Alloc();
329/******************************************************************************/
330/*  7-  Create files in AGRIF_INC directory                                   */
331/******************************************************************************/
332   creefichieramr(NameTamponfile);
333
334
335   if ( todebug == 1 ) printf("Out of CONV \n");
336   return 0;
337}
Note: See TracBrowser for help on using the repository browser.