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 @ 774

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

Update Agrif, see ticket:#39

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.1 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#include "decl.h"
39
40
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}
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/******************************************************************************/
115void CreateAndFillin_Curvar(char *type,variable *curvar)
116{
117   if (!strcasecmp(type,"character") && strcasecmp(CharacterSize,"") )
118   {
119      strcpy(curvar->v_dimchar,CharacterSize);
120      Save_Length(CharacterSize,5);
121   }
122
123  /* On donne la precision de la variable si elle a ete donnee                */
124  curvar->v_c_star = 0;
125  if ( c_star == 1 ) curvar->v_c_star = 1;
126  /*                                                                          */
127  strcpy(curvar->v_vallengspec,"");
128  if ( strcasecmp(vallengspec,"") )
129  {
130     strcpy(curvar->v_vallengspec,vallengspec);
131     Save_Length(vallengspec,8);
132  }
133
134  strcpy(curvar->v_precision,"");
135  if ( strcasecmp(NamePrecision,"") )
136  {
137     strcpy(curvar->v_precision,NamePrecision);
138     Save_Length(NamePrecision,12);
139  }
140  /* Si cette variable a ete declaree dans un module on met curvar->module=1  */
141  if ( inmoduledeclare == 1 || SaveDeclare == 1)
142  {
143      curvar->v_module = 1;
144   }
145   /* Puis on donne le nom du module dans curvar->v_modulename                */
146   strcpy(curvar->v_modulename,curmodulename);
147   Save_Length(curmodulename,6);
148   /* Si cette variable a ete initialisee                                     */
149   if (InitialValueGiven == 1 )
150   {
151      strcpy(curvar->v_initialvalue,InitValue);
152      Save_Length(InitValue,14);
153   }
154   /* Si cette variable est declaree en save                                  */
155   if (SaveDeclare == 1 ) curvar->v_save = 1;
156   /* Si cette variable est v_allocatable                                     */
157   if (Allocatabledeclare == 1 ) curvar->v_allocatable=1;
158   /* if INTENT spec has been given                                           */
159   if ( strcasecmp(IntentSpec,"") )
160   {
161      strcpy(curvar->v_IntentSpec,IntentSpec);
162      Save_Length(IntentSpec,13);
163   }
164}
165
166
167/******************************************************************************/
168/*                        duplicatelistvar                                    */
169/******************************************************************************/
170/*                                                                            */
171/******************************************************************************/
172void duplicatelistvar(listvar *orig)
173{
174   listvar *parcours;
175   listvar *tmplistvar;
176   listvar *tmplistvarprec;
177   listdim *tmplistdim;
178   variable *tmpvar;
179
180   tmplistvarprec = (listvar *)NULL;
181   parcours = orig;
182   while ( parcours )
183   {
184      tmplistvar = (listvar *)malloc(sizeof(listvar));
185      tmpvar = (variable *)malloc(sizeof(variable));
186      /*                                                                      */
187      Init_Variable(tmpvar);
188      /*                                                                      */
189      strcpy(tmpvar->v_typevar,parcours->var->v_typevar);
190      strcpy(tmpvar->v_nomvar,parcours->var->v_nomvar);
191      strcpy(tmpvar->v_oldname,parcours->var->v_oldname);
192      strcpy(tmpvar->v_dimchar,parcours->var->v_dimchar);
193      if ( parcours->var->v_dimension )
194      {
195         tmplistdim = (listdim *)malloc(sizeof(listdim));
196         tmplistdim = parcours->var->v_dimension;
197         tmpvar->v_dimension = tmplistdim;
198      }
199      tmpvar->v_nbdim=parcours->var->v_nbdim;
200      tmpvar->v_common=parcours->var->v_common;
201      tmpvar->v_positioninblock=parcours->var->v_positioninblock;
202      tmpvar->v_module=parcours->var->v_module;
203      tmpvar->v_save=parcours->var->v_save;
204      tmpvar->v_VariableIsParameter=parcours->var->v_VariableIsParameter;
205      tmpvar->v_indicetabvars=parcours->var->v_indicetabvars;
206      strcpy(tmpvar->v_modulename,parcours->var->v_modulename);
207      strcpy(tmpvar->v_commonname,parcours->var->v_commonname);
208      strcpy(tmpvar->v_vallengspec,parcours->var->v_vallengspec);
209      strcpy(tmpvar->v_nameinttypename,parcours->var->v_nameinttypename);
210      tmpvar->v_pointedvar=parcours->var->v_pointedvar;
211      strcpy(tmpvar->v_commoninfile,mainfile);
212      Save_Length(mainfile,10);
213      strcpy(tmpvar->v_subroutinename,parcours->var->v_subroutinename);
214      tmpvar->v_dimensiongiven=parcours->var->v_dimensiongiven;
215      tmpvar->v_c_star=parcours->var->v_c_star;
216      strcpy(tmpvar->v_precision,parcours->var->v_precision);
217      strcpy(tmpvar->v_initialvalue,parcours->var->v_initialvalue);
218      tmpvar->v_pointerdeclare=parcours->var->v_pointerdeclare;
219      tmpvar->v_optionaldeclare=parcours->var->v_optionaldeclare;
220      tmpvar->v_allocatable=parcours->var->v_allocatable;
221      strcpy(tmpvar->v_IntentSpec,parcours->var->v_IntentSpec);
222      tmpvar->v_dimsempty=parcours->var->v_dimsempty;
223      strcpy(tmpvar->v_readedlistdimension,
224                                          parcours->var->v_readedlistdimension);
225      /*                                                                      */
226      tmplistvar->var = tmpvar;
227      tmplistvar->suiv = NULL;
228      /*                                                                      */
229      if ( !listduplicated )
230      {
231         listduplicated = tmplistvar;
232         tmplistvarprec = listduplicated;
233      }
234      else
235      {
236         tmplistvarprec->suiv = tmplistvar;
237         tmplistvarprec = tmplistvar;
238      }
239      /*                                                                      */
240      parcours = parcours->suiv;
241   }
242}
243
244/******************************************************************************/
245/*                           insertdim                                        */
246/******************************************************************************/
247/* This subroutine is used to insert a record in a list of                    */
248/* struct : listdim                                                           */
249/******************************************************************************/
250/*        _______     _______     _______     _______     _______             */
251/*       +      +    +      +    +      +    +      +    +      +             */
252/*       + NEW  +--->+ lin  +--->+ lin  +--->+ lin  +--->+  lin +             */
253/*       +______+    +______+    +______+    +______+    +______+             */
254/*                                                                            */
255/******************************************************************************/
256listdim * insertdim(listdim *lin,typedim nom)
257{
258   listdim *newdim ;
259   listdim *parcours ;
260
261   newdim=(listdim *) malloc (sizeof (listdim));
262   newdim->dim=nom;
263   newdim->suiv=NULL;
264
265   if ( ! lin )
266   {
267      lin = newdim;
268   }
269   else
270   {
271      parcours = lin;
272      while ( parcours->suiv ) parcours=parcours->suiv;
273      parcours->suiv = newdim;
274   }
275
276   return lin;
277}
278
279/******************************************************************************/
280/*                            change_dim_char                                 */
281/******************************************************************************/
282/* This subroutine is used to change the dimension in the list lin            */
283/******************************************************************************/
284/*        _______     _______                 _______     _______             */
285/*       +  l   +    +  l   +                +  l   +    +   l  +             */
286/*       + old  +--->+ old  +--------------->+ lin  +--->+  lin +             */
287/*       +______+    +______+                +______+    +______+             */
288/*                                                                            */
289/******************************************************************************/
290void change_dim_char(listdim *lin,listvar * l)
291{
292   listvar *parcours_var;
293   variable *v;
294
295   parcours_var=l;
296   while(parcours_var)
297   {
298      v=parcours_var->var;
299      strcpy(v->v_dimchar,(lin->dim).last);
300      Save_Length((lin->dim).last,5);
301      parcours_var=parcours_var->suiv;
302   }
303}
304
305
306/******************************************************************************/
307/*                                num_dims                                    */
308/******************************************************************************/
309/* This subroutine is used to know the dimension of a table                   */
310/******************************************************************************/
311/*                                                                            */
312/*             Dimension(jpi,jpj,jpk) ----------> num_dims = 3                */
313/*                                                                            */
314/******************************************************************************/
315int num_dims(listdim *d)
316{
317   listdim *parcours;
318   int compteur = 0;
319
320   parcours = d;
321   while(parcours)
322   {
323     compteur++;
324     parcours=parcours->suiv;
325   }
326   return compteur;
327}
328
329
330/******************************************************************************/
331/*                          CREATEVAR                                         */
332/******************************************************************************/
333/* This subroutine is used to create and initialized a record of the          */
334/*      struct : variable                                                     */
335/******************************************************************************/
336variable * createvar(char *nom,listdim *d)
337{
338  variable *var;
339  listdim *dims;
340  char ligne[LONG_C];
341  char listdimension[LONG_C];
342
343   var=(variable *) malloc(sizeof(variable));
344   /*                                                                         */
345   Init_Variable(var);
346   /*                                                                         */
347   strcpy(var->v_nomvar,nom);
348   Save_Length(nom,4);
349   /*                                                                         */
350   strcpy(listdimension,"");
351   strcpy(var->v_modulename,curmodulename);
352   Save_Length(curmodulename,6);
353   strcpy(var->v_commoninfile,mainfile);
354   Save_Length(mainfile,10);
355   strcpy(var->v_subroutinename,subroutinename);
356   Save_Length(subroutinename,11);
357   /*                                                                         */
358   if ( strcasecmp(nameinttypename,"") )
359   {
360      strcpy(var->v_nameinttypename,nameinttypename);
361      Save_Length(nameinttypename,9);
362   }
363   if ( optionaldeclare     == 1 ) var->v_optionaldeclare = 1;
364   if ( pointerdeclare      == 1 ) var->v_pointerdeclare = 1;
365   if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ;
366   if ( PublicDeclare       == 1 ) var->v_PublicDeclare = 1 ;
367   if ( PrivateDeclare      == 1 ) var->v_PrivateDeclare = 1;
368   if ( ExternalDeclare     == 1 ) var->v_ExternalDeclare = 1;
369   /*                                                                         */
370   var->v_dimension=d;
371   /* Creation of the string for the dimension of this variable               */
372   dimsempty = 1;
373   if ( d )
374   {
375      var->v_dimensiongiven=1;
376      dims = d;
377      while (dims)
378      {
379         if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
380                                                                  dimsempty = 0;
381         sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
382         strcat(listdimension,ligne);
383         if ( dims->suiv )
384         {
385            strcat(listdimension,",");
386         }
387         dims = dims->suiv;
388      }
389      if ( dimsempty == 1 ) var->v_dimsempty=1;
390   }
391   strcpy(var->v_readedlistdimension,listdimension);
392   Save_Length(listdimension,15);
393   /*                                                                         */
394   var->v_nbdim=num_dims(d);
395   /*                                                                         */
396   return var;
397}
398
399/******************************************************************************/
400/*                            INSERTVAR                                       */
401/******************************************************************************/
402/* This subroutine is used to insert a record in a list of the                */
403/*      struct : listvar                                                      */
404/******************************************************************************/
405/*        _______     _______     _______     _______     _______             */
406/*       +      +    +      +    +      +    +      +    +      +             */
407/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ NEW  +             */
408/*       +______+    +______+    +______+    +______+    +______+             */
409/*                                                                            */
410/*                                                                            */
411/******************************************************************************/
412listvar * insertvar(listvar *lin,variable *v)
413{
414   listvar *newvar ;
415   listvar *tmpvar ;
416
417   newvar=(listvar *) malloc (sizeof (listvar));
418   newvar->var=v;
419   newvar->suiv = NULL;
420   if (!lin)
421   {
422      newvar->suiv=NULL;
423      lin = newvar;
424   }
425   else
426   {
427      tmpvar = lin ;
428      while (tmpvar->suiv)
429      {
430         tmpvar = tmpvar ->suiv ;
431      }
432      tmpvar -> suiv = newvar;
433   }
434   return lin;
435}
436
437/******************************************************************************/
438/*                             SETTYPE                                        */
439/******************************************************************************/
440/* This subroutine is used to give the same variable type at each             */
441/*      record of the list of the struct : listvar                            */
442/******************************************************************************/
443/*        _______     _______     _______     _______     _______             */
444/*       + REAL +    + REAL +    + REAL +    + REAL +    + REAL +             */
445/*       +  lin +--->+  lin +--->+ lin  +--->+ lin  +--->+ lin  +             */
446/*       +______+    +______+    +______+    +______+    +______+             */
447/*                                                                            */
448/*                                                                            */
449/******************************************************************************/
450listvar *settype(char *nom,listvar *lin)
451{
452   listvar *newvar;
453   variable *v;
454
455   newvar=lin;
456   while (newvar)
457   {
458      v=newvar->var;
459      strcpy(v->v_typevar,nom);
460      Save_Length(nom,3);
461      newvar=newvar->suiv;
462   }
463   newvar=lin;
464   return newvar ;
465}
Note: See TracBrowser for help on using the repository browser.