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

source: trunk/AGRIF/LIB/DiversListe.c @ 1264

Last change on this file since 1264 was 774, checked in by rblod, 17 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: 24.1 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/******************************************************************************/
[774]33/* version 1.7                                                                */
[530]34/******************************************************************************/
[396]35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include "decl.h"
39
40/******************************************************************************/
[663]41/*                           Add_Common_var_1                                 */
[396]42/******************************************************************************/
43/*  This subroutines is used to add the variable defined in common in the     */
[663]44/*     List_Common_Var                                                        */
[396]45/******************************************************************************/
46/*                                                                            */
47/******************************************************************************/
[663]48void Add_Common_var_1()
[396]49{
[663]50   listvar *newvar;
51   listvar *newvar2;
52   variable *newvariable;
53   listdim *dims;
[774]54   char listdimension[LONG_C];
55   char ligne[LONG_C];
[663]56   int out;
57
58   if ( firstpass == 1 )
59   {
60
61   newvar = (listvar *)malloc(sizeof(listvar));
62   newvariable = (variable *)malloc(sizeof(variable));
63   /*                                                                         */
64   Init_Variable(newvariable);
65   /*                                                                         */
66   strcpy(newvariable->v_nomvar,commonvar);
[774]67   Save_Length(commonvar,4);
[663]68   strcpy(newvariable->v_commonname,commonblockname);
[774]69   Save_Length(commonblockname,7);
[663]70   strcpy(newvariable->v_modulename,curmodulename);
[774]71   Save_Length(curmodulename,6);
[663]72   strcpy(newvariable->v_subroutinename,subroutinename);
[774]73   Save_Length(subroutinename,11);
[663]74   newvariable->v_positioninblock= positioninblock;
75   newvariable->v_common=1;
76   strcpy(newvariable->v_commoninfile,mainfile);
[774]77   Save_Length(mainfile,10);
[663]78
79   newvar->var = newvariable;
80
81   if ( commondim )
82   {
83      newvariable->v_dimension=commondim;
84      newvariable->v_dimensiongiven=1;
85      newvariable->v_nbdim=num_dims(commondim);
86      /* Creation of the string for the dimension of this variable            */
87      dimsempty = 1;
88      strcpy(listdimension,"");
89
90      if ( commondim )
91      {
92         dims = commondim;
93         while (dims)
94         {
95            if ( strcasecmp(dims->dim.first,"") ||
96                 strcasecmp(dims->dim.last,""))  dimsempty = 0;
97            sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
98            strcat(listdimension,ligne);
99            if ( dims->suiv ) strcat(listdimension,",");
100            dims = dims->suiv;
101         }
102         if ( dimsempty == 1 ) newvariable->v_dimsempty=1;
103      }
104      strcpy(newvariable->v_readedlistdimension,listdimension);
[774]105      Save_Length(listdimension,15);
[663]106   }
107
108
[396]109   newvar->suiv = NULL;
110
[663]111   if ( !List_Common_Var )
[396]112   {
[663]113      List_Common_Var = newvar;
[396]114   }
115   else
116   {
[663]117      newvar2 = List_Common_Var;
118      out = 0 ;
119      while ( newvar2 && out == 0 )
120      {
121         if ( !strcasecmp(newvar2->var->v_nomvar,commonvar) &&
122              !strcasecmp(newvar2->var->v_commonname,commonblockname) &&
123              !strcasecmp(newvar2->var->v_subroutinename,subroutinename)
124                          ) out = 1 ;
125         else newvar2 = newvar2->suiv;
126      }
127      if ( out == 0 )
128      {
129         newvar->suiv = List_Common_Var;
130         List_Common_Var = newvar;
131      }
132      else
133      {
134         free(newvar);
135      }
[396]136   }
[663]137   }
[396]138}
139
140/******************************************************************************/
[530]141/*                           Addtolistnom                                     */
[396]142/******************************************************************************/
143/* This subroutine is used to add a variable to the list                      */
144/******************************************************************************/
145/*                                                                            */
146/******************************************************************************/
[663]147listnom *Addtolistnom(char *nom, listnom *listin,int value)
[396]148{
149   listnom *newnom;
150   listnom *parcours;
151   int out;
152
[530]153   newnom=(listnom *) malloc (sizeof (listnom));
[663]154   strcpy(newnom->o_nom,nom);
[774]155   Save_Length(nom,23);
[663]156   newnom->o_val = value;
[530]157   newnom->suiv = NULL;
158
159   if ( !listin ) listin = newnom;
[396]160   else
161   {
162      parcours = listin;
163      out = 0 ;
164      while ( parcours && out == 0 )
165      {
[663]166         if ( !strcasecmp(parcours->o_nom,nom) ) out = 1 ;
[396]167         else parcours=parcours->suiv;
168      }
[663]169      if ( out == 0 )
[396]170      {
171          newnom->suiv = listin;
172          listin = newnom;
173      }
[530]174      else
175      {
176         free(newnom);
177      }
[396]178   }
179   return listin;
180}
181
182/******************************************************************************/
[663]183/*                           Addtolistname                                    */
[396]184/******************************************************************************/
185/* This subroutine is used to add a        variable to the list               */
186/******************************************************************************/
187/*        _______     _______     _______     _______     _______             */
188/*       +      +    +      +    +      +    +      +    +      +             */
189/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
190/*       +______+    +______+    +______+    +______+    +______+             */
191/*                                                                            */
192/*                                                                            */
193/*                                                                            */
194/******************************************************************************/
[530]195listname *Addtolistname(char *nom,listname *input)
[396]196{
197   listname *newnom;
198   listname *parcours;
199   int out;
200
201   if ( !input )
202   {
203      newnom=(listname *) malloc (sizeof (listname));
[663]204      strcpy(newnom->n_name,nom);
[774]205      Save_Length(nom,20);
[396]206      newnom->suiv = NULL;
207      input = newnom;
208   }
209   else
210   {
211      parcours = input;
212      out = 0 ;
213      while ( parcours && out == 0 )
214      {
[663]215         if ( !strcasecmp(parcours->n_name,nom) ) out = 1;
216         else parcours=parcours->suiv;
[396]217      }
218      if ( out == 0 )
219      {
220         newnom=(listname *) malloc (sizeof (listname));
[663]221         strcpy(newnom->n_name,nom);
[774]222         Save_Length(nom,20);
[396]223         newnom->suiv = input;
224         input = newnom;
225      }
226   }
227   return input;
228}
229
230/******************************************************************************/
231/*                    ModuleIsDefineInInputFile                               */
232/******************************************************************************/
233/* This subroutine is used to know if the module is defined in the input file */
234/******************************************************************************/
235/*                                                                            */
236/*                                                                            */
237/******************************************************************************/
238int ModuleIsDefineInInputFile(char *name)
239{
240   listnom *newnom;
241   int out;
[663]242
[396]243   out = 0;
[663]244   if ( listofmodules )
[396]245   {
246      newnom = listofmodules;
247      while( newnom && out == 0 )
248      {
[663]249         if ( !strcasecmp(newnom->o_nom,name) ) out = 1 ;
[396]250         else newnom=newnom->suiv;
251      }
252   }
253   return out;
254}
255
256/******************************************************************************/
257/*                      Addmoduletothelisttmp                                 */
258/******************************************************************************/
259/* This subroutine is used to add a record to a list of struct                */
260/* listusemodule                                                              */
261/******************************************************************************/
262/*                                                                            */
263/*       subroutine sub ... USE mod1 ===> insert in list                      */
264/*        _______     _______     _______     _______     _______             */
265/*       +      +    +      +    +      +    +      +    +      +             */
266/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
267/*       +______+    +______+    +______+    +______+    +______+             */
268/*                                                                            */
269/*       list =  listofmoduletmp                                              */
270/*                                                                            */
271/******************************************************************************/
272void Addmoduletothelisttmp(char *name)
273{
274  listusemodule *newmodule;
275  listusemodule *parcours;
276  int out;
277
278  if ( !listofmoduletmp)
279  {
280    newmodule =(listusemodule *)malloc(sizeof(listusemodule));
[663]281    strcpy(newmodule->u_usemodule,name);
[774]282    Save_Length(name,16);
[663]283    strcpy(newmodule->u_cursubroutine,subroutinename);
[774]284    Save_Length(subroutinename,18);
[396]285    newmodule->suiv = NULL;
286    listofmoduletmp = newmodule ;
287  }
288  else
289  {
290    parcours = listofmoduletmp;
291    out = 0;
292    while( parcours && out == 0 )
293    {
[663]294       if ( !strcasecmp(parcours->u_usemodule,name) ) out = 1;
[396]295       else parcours = parcours->suiv;
296    }
297    if ( out == 0 )
298    {
299       newmodule =(listusemodule *)malloc(sizeof(listusemodule));
[663]300       strcpy(newmodule->u_usemodule,name);
[774]301       Save_Length(name,16);
[663]302       strcpy(newmodule->u_cursubroutine,subroutinename);
[774]303       Save_Length(subroutinename,18);
[396]304       newmodule->suiv = listofmoduletmp;
305       listofmoduletmp = newmodule;
306    }
307  }
308}
309
310/******************************************************************************/
[663]311/*                          Add_NameOfModule_1                                */
[396]312/******************************************************************************/
313/* This subroutine is used to add a        variable to the list               */
314/******************************************************************************/
315/*        _______     _______     _______     _______     _______             */
316/*       +      +    +      +    +      +    +      +    +      +             */
317/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
318/*       +______+    +______+    +______+    +______+    +______+             */
319/*                                                                            */
320/*                                                                            */
321/*                                                                            */
322/******************************************************************************/
[663]323void Add_NameOfModule_1(char *nom)
[396]324{
325   listnom *newnom;
326
[530]327   if ( firstpass == 1 )
328   {
329      newnom=(listnom *) malloc (sizeof (listnom));
[663]330      strcpy(newnom->o_nom,nom);
[774]331      Save_Length(nom,23);
[663]332      newnom->suiv = List_NameOfModule;
333      List_NameOfModule = newnom;
[530]334   }
[396]335}
336
337/******************************************************************************/
[663]338/*                          Add_NameOfCommon_1                                */
[396]339/******************************************************************************/
[663]340/* This subroutine is used to add a        variable to the list               */
341/******************************************************************************/
342/*        _______     _______     _______     _______     _______             */
343/*       +      +    +      +    +      +    +      +    +      +             */
344/*       + NEW  +--->+ glob +--->+ glob +--->+ glob +--->+ glob +             */
345/*       +______+    +______+    +______+    +______+    +______+             */
346/*                                                                            */
347/*                                                                            */
348/*                                                                            */
349/******************************************************************************/
350void Add_NameOfCommon_1(char *nom)
351{
352   listnom *newnom;
353   listnom *parcours;
354
355   if ( firstpass == 1 )
356   {
357      parcours = List_NameOfCommon;
358      while ( parcours && strcasecmp(parcours->o_nom,nom) )
359                                                      parcours = parcours->suiv;
360      if ( !parcours )
361      {
362         newnom=(listnom *) malloc (sizeof (listnom));
363         strcpy(newnom->o_nom,nom);
[774]364         Save_Length(nom,23);
[663]365         newnom->suiv = List_NameOfCommon;
366         List_NameOfCommon = newnom;
367      }
368   }
369}
370
371/******************************************************************************/
372/*                     Add_CouplePointed_Var_1                                */
373/******************************************************************************/
[396]374/* Firstpass 1                                                                */
[663]375/* We should complete the listvarpointtovar                                   */
[396]376/******************************************************************************/
377/*                                                                            */
378/******************************************************************************/
[663]379void Add_CouplePointed_Var_1(char *namemodule,listcouple *couple)
[396]380{
381   listvarpointtovar *pointtmp;
[663]382
383   if ( firstpass == 1 )
[396]384   {
[663]385      /* we should complete the List_CouplePointed_Var                        */
[396]386      pointtmp=(listvarpointtovar *)malloc(sizeof(listvarpointtovar));
[663]387      strcpy(pointtmp->t_usemodule,namemodule);
[774]388      Save_Length(namemodule,28);
[663]389      strcpy(pointtmp->t_cursubroutine,subroutinename);
[774]390      Save_Length(subroutinename,29);
[663]391      pointtmp->t_couple = couple;
392      if ( List_CouplePointed_Var )
[396]393      {
[663]394         pointtmp->suiv = List_CouplePointed_Var;
395         List_CouplePointed_Var = pointtmp;
[396]396      }
397      else
398      {
399         pointtmp->suiv = NULL;
[663]400         List_CouplePointed_Var = pointtmp;
[396]401      }
402   }
403}
404
405/******************************************************************************/
[663]406/*                           Add_Include_1                                    */
[396]407/******************************************************************************/
408/* This subroutine is used to add a record to a list of struct                */
[663]409/*  List_Include                                                              */
[396]410/******************************************************************************/
411/*                                                                            */
[663]412/*       subroutine sub ... include mod1 ===> insert in list                  */
[396]413/*        _______     _______     _______     _______     _______             */
414/*       +      +    +      +    +      +    +      +    +      +             */
415/*       + NEW  +--->+ list +--->+ list +--->+ list +--->+ list +             */
416/*       +______+    +______+    +______+    +______+    +______+             */
417/*                                                                            */
[663]418/*       list =  List_Include                                                 */
[396]419/*                                                                            */
420/******************************************************************************/
[663]421void Add_Include_1(char *name)
[396]422{
423  listusemodule *newinclude;
424
[530]425  if ( firstpass == 1 )
426  {
[396]427  newinclude =(listusemodule *)malloc(sizeof(listusemodule));
[663]428  strcpy(newinclude->u_usemodule,name);
[774]429  Save_Length(name,16);
[663]430  strcpy(newinclude->u_cursubroutine,subroutinename);
[774]431  Save_Length(subroutinename,18);
[396]432  newinclude->suiv = NULL;
433
[663]434  if ( !List_Include)
[396]435  {
[663]436     List_Include  = newinclude ;
[396]437  }
438  else
439  {
[663]440    newinclude->suiv = List_Include;
441    List_Include = newinclude;
[396]442  }
[530]443  }
[396]444}
445
[663]446/******************************************************************************/
447/*                     Add_ImplicitNoneSubroutine_1                           */
448/******************************************************************************/
449/* This subroutine is used to add a record to a list of struct                */
450/******************************************************************************/
451/*                                                                            */
452/*                                                                            */
453/******************************************************************************/
454void Add_ImplicitNoneSubroutine_1()
455{
[396]456
[663]457  if ( firstpass == 1 )
458  {
459     List_ImplicitNoneSubroutine = Addtolistname(subroutinename,
460                                                   List_ImplicitNoneSubroutine);
461  }
462}
463
464
[396]465/******************************************************************************/
466/*                        WriteIncludeDeclaration                             */
467/******************************************************************************/
468/* Firstpass 0                                                                */
469/******************************************************************************/
470/*                                                                            */
471/******************************************************************************/
472void WriteIncludeDeclaration()
473{
474  listusemodule *newinclude;
475
[663]476  newinclude = List_Include;
[396]477  fprintf(fortranout,"\n");
478  while ( newinclude )
479  {
[663]480     if ( !strcasecmp(newinclude->u_cursubroutine,subroutinename) )
[396]481     {
[663]482        fprintf(fortranout,"      INCLUDE %s \n",newinclude->u_usemodule);
[396]483     }
[663]484     newinclude = newinclude ->suiv;
[396]485  }
486}
[663]487
488/******************************************************************************/
489/*                          Add_Save_Var_1                                    */
490/******************************************************************************/
491/* This subroutine is used to add a record to List_Save_Var                   */
492/******************************************************************************/
493/*        _______     _______     _______     _______     _______             */
494/*       +      +    +      +    +      +    +      +    +      +             */
495/*       + NEW  +--->+ Save +--->+ Save +--->+ Save +--->+  Save+             */
496/*       +______+    +______+    +______+    +______+    +______+             */
497/*                                                                            */
498/******************************************************************************/
499void Add_Save_Var_1 (char *name,listdim *d)
500{
501  listvar *newvar;
502  listdim *dims;
[774]503  char ligne[LONG_C];
504  char listdimension[LONG_C];
[663]505
506  if ( firstpass == 1 )
507  {
508     newvar=(listvar *)malloc(sizeof(listvar));
509     newvar->var=(variable *)malloc(sizeof(variable));
510     /*                                                                       */
511     Init_Variable(newvar->var);
512     /*                                                                       */
513     newvar->var->v_save=1;
514     strcpy(newvar->var->v_nomvar,name);
[774]515     Save_Length(name,4);
[663]516     strcpy(newvar->var->v_modulename,curmodulename);
[774]517     Save_Length(curmodulename,6);
[663]518     strcpy(newvar->var->v_subroutinename,subroutinename);
[774]519     Save_Length(subroutinename,11);
[663]520     strcpy(newvar->var->v_commoninfile,mainfile);
[774]521     Save_Length(mainfile,10);
[663]522
523     newvar->var->v_dimension=d;
524     /* Creation of the string for the dimension of this variable             */
525     dimsempty = 1;
526     if ( d )
527     {
528        newvar->var->v_dimensiongiven=1;
529        dims = d;
530        while (dims)
531        {
532           if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
533                                                                  dimsempty = 0;
534           sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
535           strcat(listdimension,ligne);
536           if ( dims->suiv )
537           {
538              strcat(listdimension,",");
539           }
540           dims = dims->suiv;
541        }
542        if ( dimsempty == 1 ) newvar->var->v_dimsempty=1;
543     }
544     strcpy(newvar->var->v_readedlistdimension,listdimension);
[774]545     Save_Length(listdimension,15);
[663]546     /*                                                                       */
547     newvar->suiv = NULL;
548
549     if ( !List_Save_Var )
550     {
551        List_Save_Var  = newvar ;
552     }
553     else
554     {
555        newvar->suiv = List_Save_Var;
556        List_Save_Var = newvar;
557     }
558  }
559}
560
561void Add_Save_Var_dcl_1 (listvar *var)
562{
563  listvar *newvar;
564  listvar *parcours;
565
566  if ( firstpass == 1 )
567  {
568     parcours = var;
569     while ( parcours )
570     {
571        newvar=(listvar *)malloc(sizeof(listvar));
572        newvar->var=(variable *)malloc(sizeof(variable));
573        /*                                                                    */
574        Init_Variable(newvar->var);
575        /*                                                                    */
576        newvar->var->v_save=1;
577        strcpy(newvar->var->v_nomvar,parcours->var->v_nomvar);
578        strcpy(newvar->var->v_modulename,curmodulename);
[774]579        Save_Length(curmodulename,6);
[663]580        strcpy(newvar->var->v_subroutinename,subroutinename);
[774]581        Save_Length(subroutinename,11);
[663]582        strcpy(newvar->var->v_commoninfile,mainfile);
[774]583        Save_Length(mainfile,10);
[663]584        /*                                                                    */
585        strcpy(newvar->var->v_readedlistdimension,
586             parcours->var->v_readedlistdimension);
587        newvar->var->v_nbdim = parcours->var->v_nbdim;
588        newvar->var->v_dimension = parcours->var->v_dimension;
589        /*                                                                    */
590        newvar->var->v_dimensiongiven=parcours->var->v_dimensiongiven;
591        /*                                                                    */
592        newvar->suiv = NULL;
593
594        if ( !List_Save_Var ) List_Save_Var  = newvar ;
595        else
596        {
597           newvar->suiv = List_Save_Var;
598           List_Save_Var = newvar;
599        }
600        parcours = parcours->suiv;
601     }
602  }
603}
Note: See TracBrowser for help on using the repository browser.