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

source: trunk/AGRIF/LIB/UtilListe.c @ 738

Last change on this file since 738 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: 19.6 KB
RevLine 
[396]1/******************************************************************************/
2/*                                                                            */
3/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
4/*                                                                            */
[663]5/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
6/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
[530]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".                                                  */
[396]12/*                                                                            */
[530]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.                                                                 */
[396]18/*                                                                            */
[530]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.                                       */
[396]29/*                                                                            */
[530]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.           */
[396]32/******************************************************************************/
[663]33/* version 1.6                                                                */
[530]34/******************************************************************************/
[396]35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include "decl.h"
39
40
[663]41void Init_Variable(variable *var)
42{
43   strcpy(var->v_typevar            ,"");
44   strcpy(var->v_nomvar             ,"");
45   strcpy(var->v_oldname            ,"");
46   strcpy(var->v_dimchar            ,"");
47   strcpy(var->v_modulename         ,"");
48   strcpy(var->v_commonname         ,"");
49   strcpy(var->v_vallengspec        ,"");
50   strcpy(var->v_nameinttypename    ,"");
51   strcpy(var->v_commoninfile       ,"");
52   strcpy(var->v_subroutinename     ,"");
53   strcpy(var->v_precision          ,"");
54   strcpy(var->v_initialvalue       ,"");
55   strcpy(var->v_IntentSpec         ,"");
56   strcpy(var->v_readedlistdimension,"");
57   var->v_nbdim               = 0 ;
58   var->v_common              = 0 ;
59   var->v_positioninblock     = 0 ;
60   var->v_module              = 0 ;
61   var->v_save                = 0 ;
62   var->v_VariableIsParameter = 0 ;
63   var->v_PublicDeclare       = 0 ;
64   var->v_PrivateDeclare      = 0 ;
65   var->v_ExternalDeclare     = 0 ;
66   var->v_pointedvar          = 0 ;
67   var->v_notgrid             = 0 ;
68   var->v_dimensiongiven      = 0 ;
69   var->v_c_star              = 0 ;
70   var->v_indicetabvars       = 0 ;
71   var->v_pointerdeclare      = 0 ;
72   var->v_optionaldeclare     = 0 ;
73   var->v_allocatable         = 0 ;
74   var->v_dimsempty           = 0 ;
75   var->v_dimension = (listdim *)NULL;
76}
[396]77/******************************************************************************/
78/*                            AddListvartolistvar                             */
79/******************************************************************************/
80/* This subroutine is used to add a listvar l at the end of a listvar         */
81/* glob.                                                                      */
82/*                                                                            */
83/******************************************************************************/
84/*        _______     _______     _______     _______     _______             */
85/*       +      +    +      +    +      +    +      +    +      +             */
86/*       + glob +--->+ glob +--->+ glob +--->+ glob +--->+  l   +             */
87/*       +______+    +______+    +______+    +______+    +______+             */
88/*                                                                            */
89/******************************************************************************/
90listvar * AddListvarToListvar(listvar *l,listvar *glob,int ValueFirstpass)
91{
92   listvar *newvar;
93
94   if ( firstpass == ValueFirstpass )
95   {
96      if ( !glob) glob = l ;
97      else
98      {
99         newvar=glob;
100         while (newvar->suiv) newvar = newvar->suiv;
101         newvar->suiv = l;
102      }
103   }
104   return glob;
105}
106
107/******************************************************************************/
108/*                       CreateAndFillin_Curvar                               */
109/******************************************************************************/
110/* This subroutine is used to create the record corresponding to the          */
111/* list of declaration                                                        */
112/******************************************************************************/
113/*                                                                            */
114/******************************************************************************/
[663]115void CreateAndFillin_Curvar(char *type,variable *curvar)
[396]116{
[530]117   if (!strcasecmp(type,"character") && strcasecmp(CharacterSize,"") )
[663]118                            strcpy(curvar->v_dimchar,CharacterSize);
[396]119
120  /* On donne la precision de la variable si elle a ete donnee                */
[663]121  curvar->v_c_star = 0;
122  if ( c_star == 1 ) curvar->v_c_star = 1;
[396]123  /*                                                                          */
[663]124  strcpy(curvar->v_vallengspec,"");
125  if ( strcasecmp(vallengspec,"") ) strcpy(curvar->v_vallengspec,vallengspec);
[396]126
[663]127  strcpy(curvar->v_precision,"");
128  if ( strcasecmp(NamePrecision,"") ) strcpy(curvar->v_precision,NamePrecision);
[396]129  /* Si cette variable a ete declaree dans un module on met curvar->module=1  */
130  if ( inmoduledeclare == 1 || SaveDeclare == 1)
131  {
[663]132      curvar->v_module = 1;
[396]133   }
[663]134   /* Puis on donne le nom du module dans curvar->v_modulename                */
135   strcpy(curvar->v_modulename,curmodulename);
[396]136   /* Si cette variable a ete initialisee                                     */
[663]137   if (InitialValueGiven == 1 ) strcpy(curvar->v_initialvalue,InitValue);
[396]138   /* Si cette variable est declaree en save                                  */
[663]139   if (SaveDeclare == 1 ) curvar->v_save = 1;
140   /* Si cette variable est v_allocatable                                     */
141   if (Allocatabledeclare == 1 ) curvar->v_allocatable=1;
[396]142   /* if INTENT spec has been given                                           */
[663]143   if ( strcasecmp(IntentSpec,"") ) strcpy(curvar->v_IntentSpec,IntentSpec);
[396]144}
145
146
147/******************************************************************************/
148/*                        duplicatelistvar                                    */
149/******************************************************************************/
150/*                                                                            */
151/******************************************************************************/
[663]152void duplicatelistvar(listvar *orig)
[396]153{
154   listvar *parcours;
155   listvar *tmplistvar;
156   listvar *tmplistvarprec;
157   listdim *tmplistdim;
158   variable *tmpvar;
159
160   tmplistvarprec = (listvar *)NULL;
161   parcours = orig;
162   while ( parcours )
163   {
164      tmplistvar = (listvar *)malloc(sizeof(listvar));
165      tmpvar = (variable *)malloc(sizeof(variable));
166      /*                                                                      */
[663]167      Init_Variable(tmpvar);
168      /*                                                                      */
169      strcpy(tmpvar->v_typevar,parcours->var->v_typevar);
170      strcpy(tmpvar->v_nomvar,parcours->var->v_nomvar);
171      strcpy(tmpvar->v_oldname,parcours->var->v_oldname);
172      strcpy(tmpvar->v_dimchar,parcours->var->v_dimchar);
173      if ( parcours->var->v_dimension )
[396]174      {
175         tmplistdim = (listdim *)malloc(sizeof(listdim));
[663]176         tmplistdim = parcours->var->v_dimension;
177         tmpvar->v_dimension = tmplistdim;
[396]178      }
[663]179      tmpvar->v_nbdim=parcours->var->v_nbdim;
180      tmpvar->v_common=parcours->var->v_common;
181      tmpvar->v_positioninblock=parcours->var->v_positioninblock;
182      tmpvar->v_module=parcours->var->v_module;
183      tmpvar->v_save=parcours->var->v_save;
184      tmpvar->v_VariableIsParameter=parcours->var->v_VariableIsParameter;
185      tmpvar->v_indicetabvars=parcours->var->v_indicetabvars;
186      strcpy(tmpvar->v_modulename,parcours->var->v_modulename);
187      strcpy(tmpvar->v_commonname,parcours->var->v_commonname);
188      strcpy(tmpvar->v_vallengspec,parcours->var->v_vallengspec);
189      strcpy(tmpvar->v_nameinttypename,parcours->var->v_nameinttypename);
190      tmpvar->v_pointedvar=parcours->var->v_pointedvar;
191      strcpy(tmpvar->v_commoninfile,mainfile);
192      strcpy(tmpvar->v_subroutinename,parcours->var->v_subroutinename);
193      tmpvar->v_dimensiongiven=parcours->var->v_dimensiongiven;
194      tmpvar->v_c_star=parcours->var->v_c_star;
195      strcpy(tmpvar->v_precision,parcours->var->v_precision);
196      strcpy(tmpvar->v_initialvalue,parcours->var->v_initialvalue);
197      tmpvar->v_pointerdeclare=parcours->var->v_pointerdeclare;
198      tmpvar->v_optionaldeclare=parcours->var->v_optionaldeclare;
199      tmpvar->v_allocatable=parcours->var->v_allocatable;
200      strcpy(tmpvar->v_IntentSpec,parcours->var->v_IntentSpec);
201      tmpvar->v_dimsempty=parcours->var->v_dimsempty;
202      strcpy(tmpvar->v_readedlistdimension,
203                                          parcours->var->v_readedlistdimension);
[396]204      /*                                                                      */
205      tmplistvar->var = tmpvar;
206      tmplistvar->suiv = NULL;
207      /*                                                                      */
[530]208      if ( !listduplicated )
[396]209      {
[530]210         listduplicated = tmplistvar;
211         tmplistvarprec = listduplicated;
[396]212      }
213      else
214      {
215         tmplistvarprec->suiv = tmplistvar;
216         tmplistvarprec = tmplistvar;
217      }
218      /*                                                                      */
219      parcours = parcours->suiv;
220   }
221}
222
223/******************************************************************************/
224/*                           insertdim                                        */
225/******************************************************************************/
226/* This subroutine is used to insert a record in a list of                    */
227/* struct : listdim                                                           */
228/******************************************************************************/
229/*        _______     _______     _______     _______     _______             */
230/*       +      +    +      +    +      +    +      +    +      +             */
231/*       + NEW  +--->+ lin  +--->+ lin  +--->+ lin  +--->+  lin +             */
232/*       +______+    +______+    +______+    +______+    +______+             */
233/*                                                                            */
234/******************************************************************************/
235listdim * insertdim(listdim *lin,typedim nom)
236{
237   listdim *newdim ;
[530]238   listdim *parcours ;
[396]239
240   newdim=(listdim *) malloc (sizeof (listdim));
241   newdim->dim=nom;
[530]242   newdim->suiv=NULL;
[663]243
[530]244   if ( ! lin )
[396]245   {
[530]246      lin = newdim;
[396]247   }
[530]248   else
249   {
250      parcours = lin;
251      while ( parcours->suiv ) parcours=parcours->suiv;
252      parcours->suiv = newdim;
253   }
[663]254
[530]255   return lin;
[396]256}
257
258/******************************************************************************/
259/*                            change_dim_char                                 */
260/******************************************************************************/
261/* This subroutine is used to change the dimension in the list lin            */
262/******************************************************************************/
263/*        _______     _______                 _______     _______             */
264/*       +  l   +    +  l   +                +  l   +    +   l  +             */
265/*       + old  +--->+ old  +--------------->+ lin  +--->+  lin +             */
266/*       +______+    +______+                +______+    +______+             */
267/*                                                                            */
268/******************************************************************************/
269void change_dim_char(listdim *lin,listvar * l)
270{
271   listvar *parcours_var;
272   variable *v;
[663]273
[396]274   parcours_var=l;
275   while(parcours_var)
[663]276   {
[396]277      v=parcours_var->var;
[663]278      strcpy(v->v_dimchar,(lin->dim).last);
[396]279      parcours_var=parcours_var->suiv;
280   }
281}
282
283
284/******************************************************************************/
285/*                                num_dims                                    */
286/******************************************************************************/
287/* This subroutine is used to know the dimension of a table                   */
288/******************************************************************************/
289/*                                                                            */
290/*             Dimension(jpi,jpj,jpk) ----------> num_dims = 3                */
291/*                                                                            */
292/******************************************************************************/
293int num_dims(listdim *d)
294{
295   listdim *parcours;
296   int compteur = 0;
297
298   parcours = d;
299   while(parcours)
300   {
301     compteur++;
302     parcours=parcours->suiv;
303   }
[663]304   return compteur;
[396]305}
306
307
308/******************************************************************************/
309/*                          CREATEVAR                                         */
310/******************************************************************************/
311/* This subroutine is used to create and initialized a record of the          */
312/*      struct : variable                                                     */
313/******************************************************************************/
314variable * createvar(char *nom,listdim *d)
315{
316  variable *var;
317  listdim *dims;
318  char ligne[LONGNOM];
319  char listdimension[LONGNOM];
320
321   var=(variable *) malloc(sizeof(variable));
322   /*                                                                         */
[663]323   Init_Variable(var);
[396]324   /*                                                                         */
[663]325   strcpy(var->v_nomvar,nom);
326   /*                                                                         */
[396]327   strcpy(listdimension,"");
[663]328   strcpy(var->v_modulename,curmodulename);
329   strcpy(var->v_commoninfile,mainfile);
330   strcpy(var->v_subroutinename,subroutinename);
[396]331   /*                                                                         */
[663]332   if ( strcasecmp(nameinttypename,"") )
333                                 strcpy(var->v_nameinttypename,nameinttypename);
334   if ( optionaldeclare     == 1 ) var->v_optionaldeclare = 1;
335   if ( pointerdeclare      == 1 ) var->v_pointerdeclare = 1;
336   if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ;
337   if ( PublicDeclare       == 1 ) var->v_PublicDeclare = 1 ;
338   if ( PrivateDeclare      == 1 ) var->v_PrivateDeclare = 1;
339   if ( ExternalDeclare     == 1 ) var->v_ExternalDeclare = 1;
[396]340   /*                                                                         */
[663]341   var->v_dimension=d;
[396]342   /* Creation of the string for the dimension of this variable               */
343   dimsempty = 1;
344   if ( d )
345   {
[663]346      var->v_dimensiongiven=1;
[396]347      dims = d;
348      while (dims)
349      {
350         if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
351                                                                  dimsempty = 0;
352         sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
353         strcat(listdimension,ligne);
354         if ( dims->suiv )
355         {
[663]356            strcat(listdimension,",");
[396]357         }
358         dims = dims->suiv;
359      }
[663]360      if ( dimsempty == 1 ) var->v_dimsempty=1;
[396]361   }
[663]362   strcpy(var->v_readedlistdimension,listdimension);
[396]363   /*                                                                         */
[663]364   var->v_nbdim=num_dims(d);
[396]365   /*                                                                         */
366   return var;
367}
368
369/******************************************************************************/
370/*                            INSERTVAR                                       */
371/******************************************************************************/
372/* This subroutine is used to insert a record in a list of the                */
373/*      struct : listvar                                                      */
374/******************************************************************************/
375/*        _______     _______     _______     _______     _______             */
376/*       +      +    +      +    +      +    +      +    +      +             */
377/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ NEW  +             */
378/*       +______+    +______+    +______+    +______+    +______+             */
379/*                                                                            */
380/*                                                                            */
381/******************************************************************************/
382listvar * insertvar(listvar *lin,variable *v)
383{
384   listvar *newvar ;
385   listvar *tmpvar ;
386
387   newvar=(listvar *) malloc (sizeof (listvar));
388   newvar->var=v;
389   newvar->suiv = NULL;
390   if (!lin)
391   {
392      newvar->suiv=NULL;
393      lin = newvar;
394   }
395   else
396   {
397      tmpvar = lin ;
398      while (tmpvar->suiv)
399      {
400         tmpvar = tmpvar ->suiv ;
401      }
[663]402      tmpvar -> suiv = newvar;
[396]403   }
404   return lin;
405}
406
407/******************************************************************************/
408/*                             SETTYPE                                        */
409/******************************************************************************/
410/* This subroutine is used to give the same variable type at each             */
411/*      record of the list of the struct : listvar                            */
412/******************************************************************************/
413/*        _______     _______     _______     _______     _______             */
414/*       + REAL +    + REAL +    + REAL +    + REAL +    + REAL +             */
415/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ lin  +             */
416/*       +______+    +______+    +______+    +______+    +______+             */
417/*                                                                            */
418/*                                                                            */
419/******************************************************************************/
420listvar *settype(char *nom,listvar *lin)
421{
422   listvar *newvar;
423   variable *v;
424
425   newvar=lin;
426   while (newvar)
427   {
428      v=newvar->var;
[663]429      strcpy(v->v_typevar,nom);
[396]430      newvar=newvar->suiv;
431   }
432   newvar=lin;
433   return newvar ;
434}
Note: See TracBrowser for help on using the repository browser.