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

source: trunk/AGRIF/LIB/WorkWithvarofsubroutineliste.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: 9.3 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/*                    OPTI_1_ajoutvarofsubroutine                             */
24/******************************************************************************/
25/* Firstpass 1                                                                */
26/* We should complete the listvarofsubroutine                                 */
27/******************************************************************************/
28/*                                                                            */
29/*                                                                            */
30/******************************************************************************/
31void OPTI_1_ajoutvarofsubroutine(listvar *listtoadd)
32{
33   listvar *tmplist;
34   
35   tmplist = (listvar *)NULL;
36   if ( firstpass == 1 && VariableIsParameter == 0 && SaveDeclare == 0)
37   {
38      tmplist = duplicatelistvar(listtoadd);
39      varofsubroutineliste = AddListvarToListvar
40                                               (tmplist,varofsubroutineliste,1);
41   }
42}
43
44/******************************************************************************/
45/*                 CleanThelistvarofsubroutineliste                           */
46/******************************************************************************/
47/* This subroutine is to remove from the varofsubroutineliste                 */
48/* all variables which are not located in the subroutine argument             */
49/******************************************************************************/
50void CleanThelistvarofsubroutineliste()
51{
52  listvar *newvar;
53  listvar *newvarprec;
54  listvar *tmpglobvar;
55  int out;
56
57  newvarprec = (listvar *)NULL;
58  newvar = varofsubroutineliste;
59  while ( newvar )
60  {
61
62     out = 0;
63     tmpglobvar = listargsubroutine;
64     while ( tmpglobvar && out == 0 )
65     {
66        if ( !strcasecmp(newvar->var->nomvar,tmpglobvar->var->nomvar) &&
67             !strcasecmp(newvar->var->modulename,subroutinename) )
68        {
69           out = 1;
70   }
71   else
72   {
73           tmpglobvar = tmpglobvar->suiv; 
74   } 
75     }
76     /*  if the variable has not be found we should remove it                 */
77     if ( out == 0 && !strcasecmp(newvar->var->modulename,subroutinename) )
78     {
79        /* remove the variable in the  varofsubroutineliste                   */
80   if ( newvar == varofsubroutineliste )
81   {
82      varofsubroutineliste = varofsubroutineliste->suiv;
83      newvar = varofsubroutineliste;
84   }
85   else
86   {
87      newvarprec->suiv = newvar->suiv;
88      newvar = newvarprec->suiv;
89   }
90     }
91     else
92     {
93         newvarprec= newvar;
94    newvar = newvar->suiv;
95     }
96  }
97}
98
99
100/******************************************************************************/
101/*             UpdatevarofsubroutinelisteWithcommonlist                       */
102/******************************************************************************/
103/*  This subroutines is used to add the variable defined in common in the     */
104/*    varofsubroutineliste                                                    */
105/******************************************************************************/
106/*                                                                            */
107/******************************************************************************/
108void UpdatevarofsubroutinelisteWithcommonlist()
109{
110   listvarcommon *parcours;
111   listvar *parcours2;
112   listvar *parcoursvar;
113   listvar *parcoursvarprec;
114   int out;
115   
116   parcoursvar = varofsubroutineliste;
117   parcoursvarprec = (listvar *)NULL;
118   while ( parcoursvar )
119   {
120      /* We should look in the commonlist if this variable is present         */
121      parcours=commonlist;
122      out=0;
123      while( parcours && out == 0 )
124      {
125         if ( !strcasecmp(parcoursvar->var->nomvar,parcours->nomvar) &&
126              !strcasecmp(parcoursvar->var->subroutinename,
127                                           parcours->subroutinename)
128            )
129         {
130            out = 1 ;
131         }
132         else
133         {
134            parcours = parcours->suiv;
135         }
136      }
137      if ( out == 1 )
138      {
139         /* we found it                                                       */
140         /* we should remove the variable from the varofsubroutineliste       */
141         if ( parcoursvar == varofsubroutineliste )
142         {
143            varofsubroutineliste = varofsubroutineliste->suiv;
144            parcoursvar = varofsubroutineliste ;
145         }
146         else
147         {
148            parcoursvarprec->suiv = parcoursvar->suiv;
149            parcoursvar = parcoursvarprec->suiv;
150         }
151      }
152      else
153      {
154         parcoursvarprec = parcoursvar;
155         parcoursvar = parcoursvar->suiv;
156      }
157   }
158   
159   /* now we should remove all parameters                                     */
160   parcoursvar = varofsubroutineliste;
161   while ( parcoursvar )
162   {
163      /* We should look in the commonlist if this variable is present         */
164      parcours2=parameterlist;
165      out=0;
166      while( parcours2 && out == 0 )
167      {
168         if ( !strcasecmp(parcoursvar->var->nomvar,parcours2->var->nomvar) &&
169              !strcasecmp(parcoursvar->var->subroutinename,
170                                           parcours2->var->subroutinename) 
171            )
172         {
173            out = 1 ;
174            /*                                                                */
175         }
176         else
177         {
178            parcours2 = parcours2->suiv;
179         }
180      }
181      if ( out == 1 )
182      {
183         /* we did find it                                                    */
184         /* we should remove the variable from the varofsubroutineliste       */
185         if ( parcoursvar == varofsubroutineliste )
186         {
187            varofsubroutineliste = varofsubroutineliste->suiv;
188            parcoursvar = varofsubroutineliste;
189         }
190         else
191         {
192            parcoursvarprec->suiv = parcoursvar->suiv;
193            parcoursvar = parcoursvarprec->suiv;
194         }
195      }
196      else
197      {
198         parcoursvarprec = parcoursvar;
199         parcoursvar = parcoursvar->suiv;
200      }
201   }
202}
203
204
205/******************************************************************************/
206/*                COM_1_UpdatevarsubroutineWithvarofsubroutinelist            */
207/******************************************************************************/
208/*  This subroutines is used to add the variable defined in common in the     */
209/******************************************************************************/
210/*                                                                            */
211/******************************************************************************/
212void COM_1_UpdatevarsubroutineWithvarofsubroutinelist()
213{
214   listvar *parcours;
215   listvar *parcours2;
216   listvar *parcoursprec;
217   int out;
218   
219   parcours = varsubroutine;
220   while ( parcours )
221   {
222      /* We should look in the varofsubroutineliste if this variable is       */
223      /*    present                                                           */
224      parcours2=varofsubroutineliste;
225      out=0;
226      while( parcours2 && out == 0 )
227      {
228         if ( !strcasecmp(parcours->var->nomvar,parcours2->var->nomvar) &&
229              !strcasecmp(parcours->var->subroutinename,
230                                            parcours2->var->modulename) 
231            )
232         {
233            out = 1 ;
234         }
235         else
236         {
237            parcours2 = parcours2->suiv;
238         }
239      }
240      if ( out == 1 )
241      {
242         /* we did not find it                                                */
243         /* we should remove the variable from the varsubroutine              */
244         if ( parcours ==  varsubroutine)
245         {
246            varsubroutine = varsubroutine->suiv;
247            parcours = varsubroutine;
248         }
249         else
250         {
251            parcoursprec->suiv = parcours->suiv;
252            parcours = parcoursprec->suiv;
253         }
254      }
255      else
256      {
257         parcoursprec = parcours;
258         parcours = parcours->suiv;
259      }
260   }
261}
Note: See TracBrowser for help on using the repository browser.