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.
WorkWithglobliste.c in trunk/AGRIF/LIB – NEMO

source: trunk/AGRIF/LIB/WorkWithglobliste.c @ 396

Last change on this file since 396 was 396, checked in by opalod, 18 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
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#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "decl.h"
21
22/******************************************************************************/
23/*                     CompareNewparsingandoldone                             */
24/******************************************************************************/
25/* this subroutine is used to compare the old treatement with                 */
26/* the new one                                                                */
27/******************************************************************************/
28/*        _______     _______     _______     _______     _______             */
29/*       +      +    +      +    +      +    +      +    +      +             */
30/*       + glob +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
31/*       +______+    +______+    +______+    +______+    +______+             */
32/*                                                                            */
33/*           =         not=         =                                         */
34/*        _______     _______     _______                                     */
35/*       +      +    +      +    +      +                                     */
36/*       + tmp  +--->+ tmp  +--->+ tmp  +                                     */
37/*       +______+    +______+    +______+                                     */
38/*                                                                            */
39/******************************************************************************/
40void CompareNewparsingandoldone()
41{
42   listvar *NewTreated;
43   listvar *OldTreated;
44   listvar *OldTreatedPrec;
45   int Out;
46   listindice *newindice;
47
48   OldTreatedPrec = (listvar *)NULL;
49   NewTreated = globliste;
50   while ( NewTreated )
51   {
52         /* we are going to compare the two treatement                        */
53         /* each time that we meet in the oldlist the same record we          */
54         /* remove it from the tmplocallist                                   */
55         OldTreated = tmplocallist;
56         Out = 0;
57         while ( OldTreated && Out == 0 )
58         { 
59            if ( !strcasecmp(NewTreated->var->nomvar, OldTreated->var->nomvar))
60            {
61               /* We should keep the same indice for tabvars table than       */
62               /* the old one                                                 */
63               NewTreated->var->indicetabvars = OldTreated->var->indicetabvars;
64               /* we remove it from the tmplocallist                          */
65               if ( OldTreated == tmplocallist ) 
66               {
67                  tmplocallist = tmplocallist -> suiv;
68               }
69               else
70               {
71                  OldTreatedPrec->suiv = OldTreated -> suiv;
72               } 
73               /* We go out of the loop because we find two variables         */
74               /* with the same name in the same file                         */
75               Out = 1;
76            }
77            else
78            {
79               OldTreatedPrec = OldTreated;
80               OldTreated = OldTreated -> suiv;
81            }
82      }
83     
84      if ( !OldTreated  && Out == 0) 
85      {
86         /* if this tmplocallist has been readed without finding the          */
87         /* variable of the globliste                                         */
88         /* it means that this variable has been added                        */
89         /* in this case we choose a new tabvars indice                       */
90    /* for this variable                                                 */
91         if ( Listofavailableindices )
92         {
93            NewTreated->var->indicetabvars = Listofavailableindices -> indice;
94            Listofavailableindices = Listofavailableindices ->suiv;
95         }
96         else
97         {
98            indicemaxtabvars = indicemaxtabvars + 1;
99            NewTreated->var->indicetabvars = indicemaxtabvars;
100         }
101      }
102      /*  On passe a l'enregistrement suivant */
103      NewTreated = NewTreated -> suiv;
104   }
105   if ( tmplocallist )
106   {
107      /* if the tmplocallist is not empty it means that some variables        */
108      /* has been removed in the new version of the filetoparse               */
109      /* in this case we should record the indice of the tabvars              */
110      /* to know that this field is empty                                     */
111      while (tmplocallist)
112      {   
113         if ( tmplocallist -> var -> indicetabvars != 0 )
114         {
115            newindice=(listindice *) malloc (sizeof (listindice));
116            newindice -> indice = tmplocallist -> var -> indicetabvars;
117            newindice -> suiv = Listofavailableindices;
118            Listofavailableindices = newindice;
119         }
120         tmplocallist = tmplocallist -> suiv;
121      }
122   }
123}
124
125
126/******************************************************************************/
127/*                          decl_1_ajoutevar                                  */
128/******************************************************************************/
129/* Firstpass 1                                                                */
130/* We should add this declaration to the globliste                            */
131/******************************************************************************/
132void decl_1_ajoutevar(listvar *listtoadd)
133{
134   if ( firstpass == 1 && VariableIsParameter == 0 )
135   if ( aftercontainsdeclare == 0 || fortran77 == 1 )
136   {
137      globliste = AddListvarToListvar(listtoadd,globliste,1);
138   }
139}
140
141/******************************************************************************/
142/*                          decl_1_ajoutevarsave                              */
143/******************************************************************************/
144/* Firstpass 1                                                                */
145/* We should add this declaration to the globliste. case SAVE                 */
146/******************************************************************************/
147void decl_1_ajoutevarsave(listvar *listtoadd)
148{
149   if ( VariableIsParameter == 0 && SaveDeclare == 1 && firstpass == 1 )
150   {
151      globliste = AddListvarToListvar(listtoadd,globliste,1);
152   }     
153}
154
155/******************************************************************************/
156/*                       UpdateIndiceTabvarsofGlobliste                      */
157/******************************************************************************/
158/*                                                                            */
159/******************************************************************************/
160/*                                                                            */
161/******************************************************************************/
162void UpdateIndiceTabvarsofGlobliste()
163{
164
165   int indicetmp;
166   listvar *NewTreated;
167   listvar *OldTreated;
168   listvar *OldTreatedPrec;
169   int Out;
170   FILE *dependglobaloutput;
171   
172   
173   if ( Did_filetoparse_treated == 1 )
174   {
175
176   Recordtmplocallist(NameTamponfile);
177
178   if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) 
179   {
180      fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars);
181      fclose(dependglobaloutput);
182      oldindicemaxtabvars = indicemaxtabvars;
183   }
184   /* Read the list of available indice                                       */
185   Readthedependavailablefile();
186   /*                                                                         */
187   indicetmp = indicemaxtabvars;
188   OldTreatedPrec = (listvar *)NULL;
189   NewTreated = globliste;
190   while ( NewTreated )
191   {
192         /* we are going to compare the two treatement                        */
193         /* each time that we meet in the oldlist the same record we          */
194         /* remove it from the tmplocallist                                   */
195         OldTreated = tmplocallist;
196         Out = 0;
197         while ( OldTreated && Out == 0 )
198         { 
199            if ( !strcasecmp(NewTreated->var->nomvar, OldTreated->var->nomvar))
200            {
201               /* We should keep the same indice for tabvars table than       */
202               /* the old one                                                 */
203               NewTreated->var->indicetabvars = OldTreated->var->indicetabvars;
204               /* we remove it from the tmplocallist                          */
205               if ( OldTreated == tmplocallist ) 
206               {
207                  tmplocallist = tmplocallist -> suiv;
208               }
209               else
210               {
211                  OldTreatedPrec->suiv = OldTreated -> suiv;
212               } 
213               /* We go out of the loop because we find two variables         */
214               /* with the same name in the same file                         */
215               Out = 1;
216            }
217            else
218            {
219               OldTreatedPrec = OldTreated;
220               OldTreated = OldTreated -> suiv;
221            }
222      }
223     
224      if ( !OldTreated  && Out == 0) 
225      {
226         /* if this tmplocallist has been readed without finding the          */
227         /* variable of the globliste                                         */
228         /* it means that this variable has been added                        */
229         /* in this case we choose a new tabvars indice                       */
230    /* for this variable                                                 */
231         if ( Listofavailableindices )
232         {
233            NewTreated->var->indicetabvars = Listofavailableindices -> indice;
234            Listofavailableindices = Listofavailableindices ->suiv;
235         }
236         else
237         {
238            indicetmp = indicetmp + 1;
239            NewTreated->var->indicetabvars = indicetmp;
240         }
241      }
242      /*  On passe a l'enregistrement suivant */
243      NewTreated = NewTreated -> suiv;
244   }
245   tmplocallist = NULL;
246   
247   } /* end of Did_filetoparse_treated == 1                                   */
248}
249
250/******************************************************************************/
251/*                  UpdateIndiceTabvarsofGloblisteFromCommon                  */
252/******************************************************************************/
253/*                                                                            */
254/******************************************************************************/
255/*                                                                            */
256/******************************************************************************/
257void UpdateIndiceTabvarsofGloblisteFromCommon()
258{
259
260   listnom *parcours;
261   listvar *parcours2;
262   listvar *listtmp;
263   listvar *parcoursglob;
264   listvar *parcoursglob2;
265   int find;
266   int NumberofNewVar;
267   int NumberofVar;
268   
269   listtmp = ( listvar *)NULL ;
270   NumberofNewVar=0;
271   NumberofVar=0;
272   parcours = modulelist;
273   while( parcours )
274   {
275      listtmp = Recordglobalvarofusefile( parcours->nom  , listtmp);
276      parcours=parcours->suiv;
277   }
278   /*                                                                         */
279   parcoursglob = globliste;
280   /* if this common has been ever read, we should update the tabvars         */
281   /*    indices                                                              */
282   while ( parcoursglob )
283   {
284      NumberofVar = NumberofVar +1 ;
285      parcours2 = listtmp;
286      find = 0 ;
287      while ( parcours2 && find == 0 )
288      {
289         if ( !strcasecmp(parcoursglob->var->nomvar,parcours2->var->nomvar) &&
290              !strcasecmp(parcoursglob->var->commonname,
291                                                parcours2->var->commonname)
292            )
293         {
294            parcoursglob->var->indicetabvars = parcours2->var->indicetabvars;
295            strcpy(parcoursglob->var->commoninfile,
296                                               parcours2->var->commoninfile);
297               find = 1;
298         }
299         parcours2 = parcours2->suiv;
300      }
301      /* if we did not find it, it means that it is a new variable            */
302      /*    we should see if this variable has not been defined twice later   */
303      if ( find == 0 && (parcoursglob->var->indicetabvars > 
304           (oldindicemaxtabvars + NumberofNewVar)) )
305      {
306         NumberofNewVar = NumberofNewVar +1 ;
307         parcoursglob->var->indicetabvars = oldindicemaxtabvars
308                                                               + NumberofNewVar;
309         parcoursglob2 = parcoursglob;
310         while ( parcoursglob2 )
311         {
312            if ( !strcasecmp(parcoursglob->var->nomvar,
313                                                parcoursglob2->var->nomvar) &&
314                 !strcasecmp(parcoursglob->var->commonname,
315                                            parcoursglob2->var->commonname)
316               )
317            {
318               parcoursglob2->var->indicetabvars = oldindicemaxtabvars
319                                                               + NumberofNewVar;
320            }
321            parcoursglob2 = parcoursglob2->suiv;
322         }
323      }
324      /*                                                                      */
325      parcoursglob  = parcoursglob  ->suiv;
326   }
327   indicemaxtabvars = oldindicemaxtabvars + NumberofNewVar;
328}
329
330
331/******************************************************************************/
332/*                   COM_1_UpdateGloblisteWithcommonlist                      */
333/******************************************************************************/
334/*  This subroutines is used to add the variable defined in common in the     */
335/*     commonlist                                                             */
336/******************************************************************************/
337/*                                                                            */
338/******************************************************************************/
339void COM_1_UpdateGloblisteWithcommonlist()
340{
341   listvarcommon *parcours;
342   listvar *parcoursindic;
343   listvar *parcoursvar;
344   listvar *parcoursvarprec;
345   int out;
346   
347   parcoursvar = globliste;
348   while ( parcoursvar )
349   {
350      /* We should look in the commonlist if this variable is present         */
351      parcours=commonlist;
352      out=0;
353      while( parcours && out == 0 )
354      {
355         if ( !strcasecmp(parcoursvar->var->nomvar,parcours->nomvar) &&
356              !strcasecmp(parcoursvar->var->subroutinename,
357                                           parcours->subroutinename) 
358            )
359         {
360            out = 1 ;
361            /* we should update the globliste                                 */
362            strcpy(parcoursvar->var->commonname,parcours->commonname);
363            parcoursvar->var->positioninblock = parcours->positioninblock;
364            parcoursvar->var->common = 1;
365         }
366         else
367         {
368            parcours = parcours->suiv;
369         }
370      }
371      if ( out == 0 )
372      {
373         /* We should update the tabvarsindic of the following variable       */
374         /*    present in the globliste                                       */
375         parcoursindic = parcoursvar;
376         indicemaxtabvars=indicemaxtabvars-1;
377         while(parcoursindic)
378         {
379            parcoursindic->var->indicetabvars =
380                                            parcoursindic->var->indicetabvars-1;
381            parcoursindic = parcoursindic->suiv;
382         }
383         /* we did not find it                                                */
384         /* we should remove the variable from the globliste                  */
385         if ( parcoursvar == globliste )
386         {
387            globliste = globliste->suiv;
388            parcoursvar = globliste;
389         }
390         else
391         {
392            parcoursvarprec->suiv = parcoursvar->suiv;
393            parcoursvar = parcoursvarprec->suiv;
394         }
395      }
396      else
397      {
398         parcoursvarprec = parcoursvar;
399         parcoursvar = parcoursvar->suiv;
400      }
401   }
402}
Note: See TracBrowser for help on using the repository browser.