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

source: trunk/AGRIF/LIB/UtilNotGridDep.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: 8.8 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/*                        ajoutenotgriddep                                    */
24/******************************************************************************/
25/* This subroutine is used to add a record into listenotgriddepend            */
26/*    This variable is add only if it is not present in the list              */
27/*    This variable is add at the end of the list                             */
28/******************************************************************************/
29/*        _______     _______     _______     _______     _______             */
30/*       + not  +    + not  +    +  not +    +  not +    +      +             */
31/*       + grid +--->+ grid +--->+ grid +--->+ grid +--->+ NEW  +             */
32/*       +______+    +______+    +______+    +______+    +______+             */
33/*                                                                            */
34/******************************************************************************/
35void ajoutenotgriddep (char *name)
36{
37   /*                                                                         */
38   variabletempo =(variable *)NULL;
39   listvartempo=(listvar *)NULL;
40   /* create the record                                                       */
41   variabletempo=createvar(name,NULL);
42   /* look in the listenotgriddepend if this variable exist                   */
43   listvartempo = listenotgriddepend;
44   while (listvartempo)
45   {
46     if (!strcasecmp(listvartempo->var->nomvar,name))
47     {
48        /* if this variable exist -> exit of the program                      */
49        printf(" The variable %s\n",name);
50        printf(" has been declared twice \n");
51        printf(" as a non grid dependent variable \n");
52        exit(1);
53     }
54      listvartempo= listvartempo->suiv;
55   }
56   /* if variable does not exist, we add it                                   */
57   listvartempo = insertvar(listenotgriddepend,variabletempo);
58   listenotgriddepend = listvartempo;
59}
60
61/******************************************************************************/
62/*                           RemoveNotgriddependFromGlobliste                 */
63/******************************************************************************/
64/* This subroutine is used to remove from the globliste all variables         */
65/* which are not grid dependent                                               */
66/******************************************************************************/
67/*        _______     _______     _______     _______     _______             */
68/*       +      +    +      +    +      +    +      +    +      +             */
69/*       + glob +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
70/*       +______+    +______+    +______+    +______+    +______+             */
71/*                                          not grid                          */
72/*                                            remove                          */
73/*                                                                            */
74/******************************************************************************/
75void RemoveNotgriddependFromGlobliste()
76{
77   listvar  *newvarglobliste;
78   listvar  *newvargloblistePrec;
79   listvar  *newvarnotgriddepend;
80   listvar  *newvarnotgriddependPrec;
81   int      Out;
82   int      Out1;
83   
84   if ( listenotgriddepend )
85   {
86      newvargloblistePrec = (listvar *)NULL;
87      newvarnotgriddependPrec = (listvar *)NULL;
88      /* Read of the globliste                                                */
89      newvarglobliste = globliste;
90      Out1 = 1 ;
91      while ( newvarglobliste && Out1 == 1 )
92      {
93         newvarnotgriddepend = listenotgriddepend;
94    Out = 1 ;
95         /* Read of the notgriddepend                                         */
96    while ( newvarnotgriddepend && Out == 1 )
97    {
98            /* If the variable is in the notgriddepend list                   */
99       if ( ! strcasecmp(newvarglobliste->var->nomvar,
100                                             newvarnotgriddepend->var->nomvar) )
101       {
102               /* We should go out of the loop so Out = 0                     */
103               Out = 0 ;
104          /* We remove the variable from the globliste                   */
105          /* If we are at the beginning of the globliste                 */
106               if ( newvarglobliste == globliste )
107               {
108                  globliste = globliste->suiv;         
109               }
110               else
111               {
112                  newvargloblistePrec->suiv = newvarglobliste->suiv;
113                  newvarglobliste = newvargloblistePrec;
114               }
115               /* We remove the variable from the notgriddepend list          */
116              if ( newvarnotgriddepend == listenotgriddepend )
117              {
118                 listenotgriddepend = listenotgriddepend->suiv;           
119              }
120              else
121              {
122                 newvarnotgriddependPrec->suiv = newvarnotgriddepend->suiv;
123                 newvarnotgriddepend = newvarnotgriddependPrec;
124               }
125       }
126            /* If the variable is not in the notgriddepend list               */
127       else
128       {
129          newvarnotgriddependPrec = newvarnotgriddepend;
130          newvarnotgriddepend = newvarnotgriddepend->suiv;
131       }
132    }
133    /* If the notgriddepend list is empty we go out of this subroutine   */
134    if ( !listenotgriddepend )
135    {
136       Out1 = 0;
137    }
138    newvargloblistePrec = newvarglobliste;
139    newvarglobliste = newvarglobliste->suiv;
140      }
141   }
142}
143
144/******************************************************************************/
145/*                      VarIsNonGridDepend                                    */
146/******************************************************************************/
147/* This subroutine is used to know if a variable has been declared as non     */
148/* grid dependent                                                             */
149/******************************************************************************/
150/*                                                                            */
151/*  notgriddepend variable;    ----------->  VarIsNonGridDepend = 1           */
152/*                                                                            */
153/*                                                                            */
154/******************************************************************************/
155int VarIsNonGridDepend(char *name)
156{
157   listvar *newvar;
158   int out;
159
160   newvar = listenotgriddepend;
161   out=0;
162   while (newvar && out == 0 )
163   {
164      if ( !strcasecmp(newvar->var->nomvar,name) ) out = 1;
165      else newvar = newvar->suiv;
166   }
167   return out;
168}
169
170
171/******************************************************************************/
172/*                       DECL_0_NonGridDepDeclaration                         */
173/******************************************************************************/
174/* Firstpass 0                                                                */
175/* We should modify this declaration in the file fortranout                   */
176/******************************************************************************/
177void DECL_0_NonGridDepDeclaration(listvar *listtomodify)
178{
179   if ( (aftercontainsdeclare == 0 && VariableIsParameter == 0) )
180   {
181      if (firstpass == 0)
182      {
183         pos_end = setposcur();
184         RemoveWordSET(fortranout,pos_cur,
185                               pos_end-pos_cur);
186         /* Modifications of declarations */
187         NonGridDepDeclaration(listtomodify);
188      }
189   }
190}
Note: See TracBrowser for help on using the repository browser.