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

source: trunk/AGRIF/LIB/Writedeclarations.c @ 663

Last change on this file since 663 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: 22.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.6                                                                */
34/******************************************************************************/
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38
39#include "decl.h"
40
41/******************************************************************************/
42/*                         WriteBeginDeclaration                              */
43/******************************************************************************/
44/* This subroutine is used to write the begin of a declaration                */
45/* taken in a variable record                                                 */
46/*                                                                            */
47/******************************************************************************/
48/*                                                                            */
49/*       integer variable ----------->   INTEGER                              */
50/*                                                                            */
51/******************************************************************************/
52void WriteBeginDeclaration(variable *v,char ligne[LONGLIGNE])
53{
54  char tmpligne[LONGLIGNE];
55
56  if ( !strcasecmp(v->v_typevar,"") )
57  {
58     printf("WARNING : The type of the variable %s \n",v->v_nomvar);
59     printf("          is unknown. CONV should define a type\n");
60  }
61  sprintf (ligne, "%s", v->v_typevar);
62  if ( v->v_c_star == 1 ) strcat(ligne,"*");
63  /* We should give the precision of the variable if it has been given        */
64  if ( strcasecmp(v->v_precision,"") )
65  {
66     sprintf(tmpligne,"(%s)",v->v_precision);
67     strcat(ligne,tmpligne);
68  }
69  if (strcasecmp(v->v_dimchar,""))
70  {
71     sprintf(tmpligne,"(%s)",v->v_dimchar);
72     strcat(ligne,tmpligne);
73  }
74  if ( strcasecmp(v->v_nameinttypename,"") )
75  {
76     sprintf(tmpligne,"*%s",v->v_nameinttypename);
77     strcat(ligne,tmpligne);
78  }
79  if (strcasecmp (v->v_IntentSpec, ""))
80  {
81     sprintf(tmpligne,",INTENT(%s) ",v->v_IntentSpec);
82     strcat(ligne,tmpligne);
83  }
84  if ( v->v_VariableIsParameter == 1 ) strcat(ligne, ", PARAMETER");
85  if ( v->v_PublicDeclare       == 1 ) strcat(ligne, ", PUBLIC");
86  if ( v->v_PrivateDeclare      == 1 ) strcat(ligne, ", PRIVATE");
87  if ( v->v_ExternalDeclare     == 1 ) strcat(ligne, ", EXTERNAL");
88  if ( v->v_allocatable         == 1 &&
89       v->v_save                == 0 ) strcat(ligne,", ALLOCATABLE");
90  if ( v->v_optionaldeclare     == 1 ) strcat(ligne,", OPTIONAL");
91  if ( v->v_pointerdeclare      == 1 ) strcat(ligne,", POINTER");
92}
93
94
95/******************************************************************************/
96/*                         WriteScalarDeclaration                             */
97/******************************************************************************/
98/* This subroutine is used to write a scalar declaration                      */
99/* taken in a variable record                                                 */
100/*                                                                            */
101/******************************************************************************/
102/*                                                                            */
103/*       integer variable ----------->   INTEGER :: VARIABLE                  */
104/*                                                                            */
105/******************************************************************************/
106void WriteScalarDeclaration(variable *v,char ligne[LONGLIGNE])
107{
108
109  strcat (ligne, " :: ");
110  strcat (ligne, v->v_nomvar);
111  if ( strcasecmp(v->v_vallengspec,"") ) strcat(ligne,v->v_vallengspec);
112  if ( v->v_VariableIsParameter == 1 )
113  {
114     strcat(ligne," = ");
115     strcat(ligne,v->v_initialvalue);
116  }
117}
118
119
120/******************************************************************************/
121/*                         WriteTableDeclaration                              */
122/******************************************************************************/
123/* This subroutine is used to write a Table declaration                       */
124/* taken in a variable record                                                 */
125/*                                                                            */
126/******************************************************************************/
127/*                                                                            */
128/*  integer variable(nb) ----------->                                         */
129/*                      INTEGER, DIMENSION(1:nb) :: variable                  */
130/*                                                                            */
131/******************************************************************************/
132void WriteTableDeclaration(variable * v,char ligne[LONGLIGNE],int tmpok)
133{
134  char newname[LONGNOM];
135
136  strcat (ligne, ", Dimension(");
137  if ( v->v_dimensiongiven == 1 && tmpok == 1 )
138                                         strcat(ligne,v->v_readedlistdimension);
139  if ( v->v_dimensiongiven == 1 && tmpok == 0 )
140  {
141     strcpy(newname,ChangeTheInitalvaluebyTabvarsName
142                                  (v->v_readedlistdimension,List_Global_Var,0));
143     if ( !strcasecmp(newname,v->v_readedlistdimension) )
144     {
145        strcpy(newname,"");
146        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
147                                 (v->v_readedlistdimension,List_Common_Var,0));
148        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
149     }
150     if ( !strcasecmp(newname,v->v_readedlistdimension) )
151     {
152        strcpy(newname,"");
153        /* la liste des use de cette subroutine                               */
154        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
155                              (v->v_readedlistdimension,List_ModuleUsed_Var,0));
156        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
157     }
158     strcat(ligne,newname);
159  }
160  strcat (ligne, ")");
161  strcat (ligne, " :: ");
162  strcat (ligne, v->v_nomvar);
163  if ( strcasecmp(vallengspec,"") ) strcat(ligne,v->v_vallengspec);
164/*  if ( !strcasecmp (v->v_typevar, "character") )
165                              strcat(ligne,vargridparam(v,0));*/
166  if ( v->v_VariableIsParameter == 1 )
167  {
168     strcat(ligne," = ");
169     strcat(ligne,v->v_initialvalue);
170  }
171}
172
173/******************************************************************************/
174/*                        writevardeclaration                                 */
175/******************************************************************************/
176/* This subroutine is used to write the initial declaration in the file       */
177/* fileout of a variable                                                      */
178/*                                                                            */
179/******************************************************************************/
180/*                                                                            */
181/*  integer variable(nb) ----------->                                         */
182/*                      INTEGER, DIMENSION(1:nb),Pointer :: variable          */
183/*                                                                            */
184/******************************************************************************/
185void writevardeclaration (listvar * var_record, FILE *fileout, int value)
186{
187  FILE *filecommon;
188  listvar *newvar;
189  variable *v;
190  char ligne[LONGNOM];
191
192  filecommon=fileout;
193  newvar = var_record;
194
195  if ( newvar->var->v_save == 0 || inmodulemeet == 0 )
196  {
197     v = newvar->var;
198     WriteBeginDeclaration(v,ligne);
199     if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
200     else WriteTableDeclaration(v,ligne,value);
201
202     if ( v->v_VariableIsParameter != 1 && strcasecmp(v->v_initialvalue,"") )
203     {
204        strcat(ligne," = ");
205        strcat(ligne,v->v_initialvalue);
206     }
207     tofich (filecommon, ligne,1);
208  }
209}
210
211
212void WriteLocalParamDeclaration()
213{
214   listvar *parcours;
215
216   parcours = List_Parameter_Var;
217   while ( parcours )
218   {
219      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
220      {
221         writevardeclaration(parcours,fortranout,0);
222      }
223      parcours = parcours -> suiv;
224   }
225}
226
227void WriteFunctionDeclaration()
228{
229   listvar *parcours;
230
231   parcours = List_FunctionType_Var;
232   while ( parcours )
233   {
234      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
235            strcasecmp(parcours->var->v_typevar,"")
236         )
237      {
238         writevardeclaration(parcours,fortranout,0);
239      }
240      parcours = parcours -> suiv;
241   }
242}
243
244void WriteSubroutineDeclaration(int value)
245{
246   listvar *parcours;
247
248   parcours = List_SubroutineDeclaration_Var;
249   while ( parcours )
250   {
251      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
252           parcours->var->v_save == 0                                  &&
253           parcours->var->v_allocatable == 0                           &&
254           parcours->var->v_pointerdeclare == 0                        &&
255           parcours->var->v_VariableIsParameter == 0                   &&
256           parcours->var->v_common == 0
257         )
258      {
259         writevardeclaration(parcours,fortranout,value);
260      }
261      else if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
262           parcours->var->v_save == 0                                  &&
263           parcours->var->v_VariableIsParameter == 0                   &&
264           parcours->var->v_common == 0
265              )
266      {
267         writevardeclaration(parcours,fortranout,value);
268      }
269      parcours = parcours -> suiv;
270   }
271}
272
273void WriteArgumentDeclaration_beforecall()
274{
275   variable *v;
276   int position;
277   listnom *neededparameter;
278   FILE *paramtoamr;
279   listvar *newvar;
280   char ligne[LONGLIGNE];
281   int out;
282   int writeit;
283   listnom *parcours;
284
285   fprintf(fortranout,"#include \"Param_BeforeCall_%s.h\" \n",subroutinename);
286   /*                                                                         */
287   sprintf(ligne,"Param_BeforeCall_%s.h",subroutinename);
288   paramtoamr = associate (ligne);
289   /*                                                                         */
290   neededparameter = (listnom * )NULL;
291   /*                                                                         */
292   position = 1;
293   newvar = List_SubroutineArgument_Var;
294   while ( newvar )
295   {
296      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
297                       newvar->var->v_positioninblock == position
298         )
299      {
300         position = position + 1;
301         writevardeclaration(newvar,fortranout,0);
302         neededparameter = writedeclarationintoamr(List_Parameter_Var,
303                   paramtoamr,newvar->var,newvar->var->v_subroutinename,
304                   neededparameter,subroutinename);
305
306         newvar = List_SubroutineArgument_Var;
307      }
308      else newvar = newvar -> suiv;
309   }
310   fclose(paramtoamr);
311}
312
313void WriteArgumentDeclaration_Sort()
314{
315   variable *v;
316   int position;
317/*   listnom *neededparameter;*/
318   FILE *paramtoamr;
319   listvar *newvar;
320   char ligne[LONGLIGNE];
321   int out;
322   int writeit;
323   listnom *parcours;
324
325   /*                                                                         */
326   position = 1;
327   newvar = List_SubroutineArgument_Var;
328   while ( newvar )
329   {
330      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
331                       newvar->var->v_positioninblock == position
332         )
333      {
334         position = position + 1;
335         writevardeclaration(newvar,fortranout,1);
336         /*                                                                   */
337         newvar = List_SubroutineArgument_Var;
338      }
339      else newvar = newvar -> suiv;
340   }
341   /*                                                                         */
342   newvar = List_SubroutineArgument_Var;
343   while ( newvar )
344   {
345      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
346                       newvar->var->v_positioninblock == 0           &&
347                       newvar->var->v_nbdim == 0
348         )
349      {
350         writevardeclaration(newvar,fortranout,1);
351      }
352      newvar = newvar -> suiv;
353   }
354   /*                                                                         */
355   newvar = List_SubroutineArgument_Var;
356   while ( newvar )
357   {
358      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
359                       newvar->var->v_positioninblock == 0           &&
360                       newvar->var->v_nbdim != 0
361         )
362      {
363         writevardeclaration(newvar,fortranout,1);
364      }
365      newvar = newvar -> suiv;
366   }
367}
368
369/******************************************************************************/
370/*                      writedeclarationintoamr                               */
371/******************************************************************************/
372/* This subroutine is used to write the declaration of parameters needed in   */
373/*    allocation subroutines creates in toamr.c                               */
374/******************************************************************************/
375/*                                                                            */
376/*                                                                            */
377/******************************************************************************/
378listnom *writedeclarationintoamr (listvar * deb_common, FILE *fileout,
379                              variable *var , char commonname[LONGNOM],
380                           listnom *neededparameter, char name_common[LONGNOM])
381{
382  listvar *newvar;
383  variable *v;
384  char ligne[LONGLIGNE];
385  int changeval;
386  char firstmodule[LONGNOM];
387  int out;
388  int writeit;
389  listnom *parcours;
390  listnom *parcoursprec;
391
392  parcoursprec = (listnom * )NULL;
393  /* we should list the needed parameter                                      */
394  if ( !strcasecmp(name_common,commonname) )
395     neededparameter = DecomposeTheNameinlistnom(var->v_readedlistdimension,
396                                                               neededparameter);
397  /*                                                                          */
398  parcours = neededparameter;
399  while (parcours)
400  {
401     newvar = deb_common;
402     out = 0 ;
403     while ( newvar && out == 0 )
404     {
405        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
406        {
407           out=1;
408        /* add the name to the list of needed parameter                       */
409           neededparameter = DecomposeTheNameinlistnom(
410                 newvar->var->v_initialvalue,
411                 neededparameter );
412        }
413        else newvar=newvar->suiv;
414     }
415     parcours=parcours->suiv;
416   }
417  /*                                                                          */
418  parcours = neededparameter;
419  while (parcours)
420  {
421     newvar = deb_common;
422     out = 0 ;
423     while ( newvar && out == 0 )
424     {
425        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
426        {
427           out=1;
428        /* add the name to the list of needed parameter                       */
429           neededparameter = DecomposeTheNameinlistnom(
430                 newvar->var->v_initialvalue,
431                 neededparameter );
432        }
433        else newvar=newvar->suiv;
434     }
435     parcours=parcours->suiv;
436   }
437  /*                                                                          */
438  strcpy(firstmodule,"");
439  tofich (fileout, "",1);
440  parcours = neededparameter;
441  while (parcours)
442  {
443     writeit = 0;
444     newvar = deb_common;
445     while ( newvar && writeit == 0 )
446     {
447        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) &&
448             parcours->o_val == 0 )
449        {
450           writeit=1;
451           parcours->o_val = 1;
452        }
453        else newvar = newvar->suiv;
454     }
455
456     if ( writeit == 1  )
457     {
458        changeval = 0;
459        v = newvar->var;
460        if ( v->v_allocatable == 1  )
461        {
462           changeval = 1;
463           v->v_allocatable = 0;
464        }
465        WriteBeginDeclaration(v,ligne);
466        if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
467        else WriteTableDeclaration(v,ligne,1);
468
469        tofich (fileout, ligne,1);
470        if ( changeval == 1 )
471        {
472           v->v_allocatable = 1;
473        }
474     }
475     else
476     {
477        if (  strncasecmp(parcours->o_nom,"mpi_",4) == 0 &&
478              shouldincludempif                     == 1 )
479        {
480           shouldincludempif = 0;
481           fprintf(fileout,"      include \'mpif.h\' \n");
482        }
483     }
484     parcours=parcours->suiv;
485  }
486  return neededparameter;
487}
488
489
490/******************************************************************************/
491/*                       writesub_loopdeclaration_scalar                      */
492/******************************************************************************/
493/* This subroutine is used to write the declaration part of subloop           */
494/*    subroutines                                                             */
495/******************************************************************************/
496/*                                                                            */
497/*  integer variable(nb) ----------->                                         */
498/*                                                                            */
499/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
500/*                                                                            */
501/******************************************************************************/
502void writesub_loopdeclaration_scalar (listvar * deb_common, FILE *fileout)
503{
504  listvar *newvar;
505  variable *v;
506  char ligne[LONGLIGNE];
507
508  tofich (fileout, "",1);
509  newvar = deb_common;
510  while (newvar)
511  {
512     if ( newvar->var->v_nbdim == 0 &&
513          !strcasecmp(newvar->var->v_subroutinename,subroutinename)  &&
514           newvar->var->v_allocatable == 0                           &&
515           newvar->var->v_pointerdeclare == 0
516         )
517     {
518        v = newvar->var;
519
520        WriteBeginDeclaration(v,ligne);
521        WriteScalarDeclaration(v,ligne);
522        tofich (fileout, ligne,1);
523     }
524     newvar = newvar->suiv;
525  }
526}
527
528/******************************************************************************/
529/*                       writesub_loopdeclaration_tab                         */
530/******************************************************************************/
531/* This subroutine is used to write the declaration part of subloop           */
532/*    subroutines                                                             */
533/******************************************************************************/
534/*                                                                            */
535/*  integer variable(nb) ----------->                                         */
536/*                                                                            */
537/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
538/*                                                                            */
539/******************************************************************************/
540void writesub_loopdeclaration_tab (listvar * deb_common, FILE *fileout)
541{
542  listvar *newvar;
543  variable *v;
544  char ligne[LONGLIGNE];
545  int changeval;
546
547  tofich (fileout, "",1);
548  newvar = deb_common;
549  while (newvar)
550  {
551     if ( newvar->var->v_nbdim != 0                                 &&
552          !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
553          newvar->var->v_allocatable == 0                           &&
554          newvar->var->v_pointerdeclare == 0
555        )
556     {
557        changeval = 0;
558        v = newvar->var;
559        if ( v->v_allocatable == 1 )
560        {
561           changeval = 1;
562           v->v_allocatable = 0;
563        }
564        WriteBeginDeclaration(v,ligne);
565        WriteTableDeclaration(v,ligne,1);
566        tofich (fileout, ligne,1);
567        if ( changeval == 1 ) v->v_allocatable = 1;
568     }
569     newvar = newvar->suiv;
570  }
571}
Note: See TracBrowser for help on using the repository browser.