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.
WorkWithlistofmodulebysubroutine.c in NEMO/releases/CMIP5_IPSL/AGRIF/LIB – NEMO

source: NEMO/releases/CMIP5_IPSL/AGRIF/LIB/WorkWithlistofmodulebysubroutine.c @ 11998

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

Adapt Agrif to the new SBC and correct several bugs for agrif (restart writing and reading), see ticket #133
Note : this fix does not work yet on NEC computerq (sxf90/360)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 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#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
39#include "decl.h"
40
41
42
43/******************************************************************************/
44/*                    RecordUseModulesVariables                               */
45/******************************************************************************/
46/*                                                                            */
47/******************************************************************************/
48void RecordUseModulesVariables()
49{
50  listusemodule *tmplistmodule;
51
52  /* we should record all variables defined in modules used in this file      */
53  if ( List_NameOfModuleUsed )
54  {
55     tmplistmodule = List_NameOfModuleUsed;
56     while ( tmplistmodule )
57     {
58        if ( tmplistmodule->u_firstuse == 1 )
59        {
60           /* check if the file .depend<u_usemodule> exist                    */
61           List_ModuleUsed_Var = Readthedependfile
62                               (tmplistmodule->u_usemodule,List_ModuleUsed_Var);
63
64           List_GlobParamModuleUsed_Var = ReaddependParameterList
65                      (tmplistmodule->u_usemodule,List_GlobParamModuleUsed_Var);
66
67        }
68
69        tmplistmodule = tmplistmodule->suiv;
70     }
71  }
72}
73
74/******************************************************************************/
75/*                RecordUseModulesUseModulesVariables                         */
76/******************************************************************************/
77/******************************************************************************/
78void  RecordUseModulesUseModulesVariables()
79{
80  listusemodule *tmplistmodule;
81  listusemodule *tmplistmodule1;
82
83  /* we should record all variables defined in modules used in this file      */
84  if ( List_NameOfModuleUsed )
85  {
86     /* and we should read the .depend of the module used by the module used  */
87     tmplistmodule = List_NameOfModuleUsed;
88     while ( tmplistmodule )
89     {
90        Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
91        while( tmpuselocallist )
92        {
93           Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
94           tmplistmodule1 = tmpuselocallist->suiv;
95           free(tmpuselocallist);
96           tmpuselocallist = tmplistmodule1;
97        }
98        tmplistmodule = tmplistmodule->suiv;
99     }
100
101     tmplistmodule = listofmoduletmp;
102     while ( tmplistmodule )
103     {
104        Readthedependlistofmoduleused(tmplistmodule->u_usemodule);
105        while( tmpuselocallist )
106        {
107           Addmoduletothelisttmp(tmpuselocallist->u_usemodule);
108           tmplistmodule1 = tmpuselocallist->suiv;
109           free(tmpuselocallist);
110           tmpuselocallist = tmplistmodule1;
111        }
112        tmplistmodule = tmplistmodule->suiv;
113     }
114
115
116
117     tmplistmodule = listofmoduletmp;
118     while ( tmplistmodule )
119     {
120        /* check if the file .depend<u_usemodule> exist                       */
121        List_ModuleUsedInModuleUsed_Var = Readthedependfile
122                   (tmplistmodule->u_usemodule,List_ModuleUsedInModuleUsed_Var);
123
124        List_GlobParamModuleUsedInModuleUsed_Var = ReaddependParameterList
125          (tmplistmodule->u_usemodule,List_GlobParamModuleUsedInModuleUsed_Var);
126        tmplistmodule = tmplistmodule->suiv;
127     }
128  }
129}
130
131/******************************************************************************/
132/*                      Add_NameOfModuleUsed_1                                */
133/******************************************************************************/
134/* This subroutine is used to add a record to a list of struct                */
135/* listusemodule                                                              */
136/******************************************************************************/
137/*                                                                            */
138/*       subroutine sub ... USE mod1 ===> insert in list                      */
139/*        _______     _______     _______     _______     _______             */
140/*       +      +    +      +    +      +    +      +    +      +             */
141/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
142/*       +______+    +______+    +______+    +______+    +______+             */
143/*                                                                            */
144/*       list =  List_NameOfModuleUsed                                        */
145/*                                                                            */
146/******************************************************************************/
147void Add_NameOfModuleUsed_1(char *name)
148{
149  listusemodule *newmodule;
150  listusemodule *parcours;
151  int out;
152
153  if ( firstpass == 1 )
154  {
155     newmodule =(listusemodule *)malloc(sizeof(listusemodule));
156     strcpy(newmodule->u_usemodule,name);
157     Save_Length(name,16);
158     strcpy(newmodule->u_charusemodule,charusemodule);
159     Save_Length(charusemodule,17);
160     strcpy(newmodule->u_modulename,curmodulename);
161     Save_Length(curmodulename,19);
162     strcpy(newmodule->u_cursubroutine,subroutinename);
163     Save_Length(subroutinename,18);
164     newmodule->u_firstuse = 1 ;
165     newmodule->suiv = NULL;
166
167     if ( !List_NameOfModuleUsed)
168     {
169         List_NameOfModuleUsed = newmodule ;
170     }
171     else
172     {
173    parcours = List_NameOfModuleUsed;
174    while ( parcours && newmodule->u_firstuse == 1 )
175    {
176       if ( !strcasecmp(name,parcours->u_usemodule) )
177       {
178          newmodule->u_firstuse = 0 ;
179       }
180       parcours=parcours->suiv;
181    }
182    /* we can not add the same module twice for the same subroutine           */
183    parcours = List_NameOfModuleUsed;
184    out = 0 ;
185    while ( parcours && out == 0 )
186    {
187       if ( !strcasecmp(name,parcours->u_usemodule) &&
188            !strcasecmp(subroutinename,parcours->u_cursubroutine)
189           )
190       {
191          out = 1 ;
192          free(newmodule);
193       }
194       else parcours=parcours->suiv;
195    }
196    if ( out == 0 )
197    {
198       newmodule->suiv = List_NameOfModuleUsed;
199       List_NameOfModuleUsed = newmodule;
200    }
201  }
202  }
203}
204
205
206/******************************************************************************/
207/*                        Addmoduletothelist                                  */
208/******************************************************************************/
209/* This subroutine is used to add a record to a list of struct                */
210/* listusemodule                                                              */
211/******************************************************************************/
212/*                                                                            */
213/*       subroutine sub ... USE mod1 ===> insert in list                      */
214/*        _______     _______     _______     _______     _______             */
215/*       +      +    +      +    +      +    +      +    +      +             */
216/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
217/*       +______+    +______+    +______+    +______+    +______+             */
218/*                                                                            */
219/*       list =  List_NameOfModuleUsed                                     */
220/*                                                                            */
221/******************************************************************************/
222void Addmoduletothelist(char *name)
223{
224  listusemodule *newmodule;
225  listusemodule *parcours;
226  int out;
227
228     newmodule =(listusemodule *)malloc(sizeof(listusemodule));
229     strcpy(newmodule->u_usemodule,name);
230     Save_Length(name,16);
231     strcpy(newmodule->u_charusemodule,charusemodule);
232     Save_Length(charusemodule,17);
233     strcpy(newmodule->u_cursubroutine,subroutinename);
234     Save_Length(subroutinename,18);
235     newmodule->u_firstuse = 1 ;
236     newmodule->suiv = NULL;
237
238     if ( !List_NameOfModuleUsed)
239     {
240         List_NameOfModuleUsed = newmodule ;
241     }
242     else
243     {
244    parcours = List_NameOfModuleUsed;
245    while ( parcours && newmodule->u_firstuse == 1 )
246    {
247       if ( !strcasecmp(name,parcours->u_usemodule) )
248       {
249          newmodule->u_firstuse = 0 ;
250       }
251       parcours=parcours->suiv;
252    }
253    /* we can not add the same module twice for the same subroutine           */
254    parcours = List_NameOfModuleUsed;
255    out = 0 ;
256    while ( parcours && out == 0 )
257    {
258       if ( !strcasecmp(name,parcours->u_usemodule) &&
259            !strcasecmp(subroutinename,parcours->u_cursubroutine)
260           )
261       {
262          out = 1 ;
263          free(newmodule);
264       }
265       else parcours=parcours->suiv;
266    }
267    if ( out == 0 )
268    {
269       newmodule->suiv = List_NameOfModuleUsed;
270       List_NameOfModuleUsed = newmodule;
271    }
272  }
273}
274
275
276/******************************************************************************/
277/*                        WriteUsemoduleDeclaration                           */
278/******************************************************************************/
279/* Firstpass 0                                                                */
280/******************************************************************************/
281/*                                                                            */
282/******************************************************************************/
283void WriteUsemoduleDeclaration()
284{
285  listusemodule *newmodule;
286
287  newmodule = List_NameOfModuleUsed;
288  fprintf(fortranout,"\n");
289
290  while ( newmodule )
291  {
292     if ( !strcasecmp(newmodule->u_cursubroutine,subroutinename) )
293     {
294             fprintf(fortranout,"      USE %s \n"
295                                                   ,newmodule->u_charusemodule);
296     }
297        newmodule = newmodule ->suiv;
298  }
299}
Note: See TracBrowser for help on using the repository browser.