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

source: trunk/AGRIF/LIB/toamr.c @ 530

Last change on this file since 530 was 530, checked in by opalod, 18 years ago

RB: update of the conv for IOM and NEC MPI library

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.4 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@imag.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.0                                                                */
34/******************************************************************************/
35#include <stdlib.h>
36#include <stdio.h>
37#include <string.h>
38#include "decl.h"
39char lvargridname[LONGNOM];
40char lvargridname2[LONGNOM];
41
42
43/******************************************************************************/
44/*                       variablenameroottabvars                              */
45/******************************************************************************/
46/* This subroutine is used to create the string                               */
47/******************************************************************************/
48/*                                                                            */
49/*  ----------->  Agrif_Mygrid % tabvars (i) % var                            */
50/*                                                                            */
51/******************************************************************************/
52char *variablenameroottabvars (variable * var)
53{
54  char *ligne;
55
56  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
57  sprintf (ligne, "Agrif_Mygrid %% tabvars(%d) %% var ", var->indicetabvars);
58  return ligne;
59}
60
61
62/******************************************************************************/
63/*                        variablenametabvars                                 */
64/******************************************************************************/
65/* This subroutine is used to create the string                               */
66/******************************************************************************/
67/*                                                                            */
68/*  if iorindice = 0 ---------->  Agrif_Gr % tabvars (i) % var                */
69/*                                                                            */
70/*  if iorindice = 1 ---------->  Agrif_Gr % tabvars (12) % var               */
71/*                                                                            */
72/******************************************************************************/
73char *variablenametabvars (variable * var, int iorindice)
74{
75  char *ligne;
76
77  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
78  if ( iorindice == 0 ) sprintf (ligne, " Agrif_Gr %% tabvars(%d)%% var",
79                                 var->indicetabvars);
80  else sprintf (ligne, " Agrif_Gr %% tabvars(i)%% var");
81  return ligne;
82}
83
84/******************************************************************************/
85/*                        variablecurgridtabvars                              */
86/******************************************************************************/
87/* This subroutine is used to create the string                               */
88/******************************************************************************/
89/*                                                                            */
90/*  ----------->  Agrif_Curgrid % tabvars (i) % var                           */
91/*                                                                            */
92/******************************************************************************/
93char *variablecurgridtabvars (variable * var,int ParentOrCurgrid)
94{
95  char *ligne;
96
97  ligne = (char *) malloc (LONGLIGNE * sizeof (char));
98  if ( ParentOrCurgrid == 0 ) sprintf (ligne, " Agrif_tabvars(%d) %% var",
99                              var->indicetabvars);
100  else if ( ParentOrCurgrid == 1 ) sprintf (ligne, 
101                              " Agrif_tabvars(%d) %% parent_var %% var",
102                               var->indicetabvars);
103  else if ( ParentOrCurgrid == 2 ) sprintf (ligne, 
104                              " Agrif_Mygrid %% tabvars(%d) %% var",
105                               var->indicetabvars);
106  else if ( ParentOrCurgrid == 3 ) sprintf (ligne, 
107                              " Agrif_Curgrid %% tabvars(%d) %% var",
108                               var->indicetabvars);
109  else sprintf (ligne, " AGRIF_Mygrid %% tabvars(%d) %% var",
110                               var->indicetabvars);
111  return ligne;
112}
113
114/******************************************************************************/
115/*                           vargridnametabvars                               */
116/******************************************************************************/
117/* This subroutine is used to create the string                               */
118/******************************************************************************/
119/*                                                                            */
120/*  if iorindice == 0 ----------->  Agrif_Gr % tabvars (i) % var % array1     */
121/*                                                                            */
122/*  if iorindice == 1 ----------->  Agrif_Gr % tabvars (12) % var % array1    */
123/*                                                                            */
124/******************************************************************************/
125char *vargridnametabvars (variable * var,int iorindice)
126{
127  char *tmp;
128  char tmp1[LONGNOM];
129 
130  tmp = variablenametabvars (var,iorindice);
131  strcpy(tmp1,tmp);
132  free(tmp);
133 
134  sprintf (lvargridname, "%s", tmp1);
135  if (!strcasecmp (var->typevar, "REAL"))
136    {
137      sprintf (lvargridname2, "%% array%d", var->nbdim);
138    }
139  else if (!strcasecmp (var->typevar, "REAL*8"))
140    {
141      sprintf (lvargridname2, "%% darray%d", var->nbdim);
142    }
143  else if (!strcasecmp (var->typevar, "INTEGER"))
144    {
145      sprintf (lvargridname2, "%% iarray%d", var->nbdim);
146    }
147  else if (!strcasecmp (var->typevar, "LOGICAL"))
148    {
149      sprintf (lvargridname2, "%% larray%d", var->nbdim);
150    }
151  else if (!strcasecmp (var->typevar, "CHARACTER"))
152    {
153      sprintf (lvargridname2, "%% carray%d", var->nbdim);
154    }
155
156  strcat (lvargridname, lvargridname2);
157
158  return lvargridname;
159}
160
161/******************************************************************************/
162/*                           vargridcurgridtabvars                            */
163/******************************************************************************/
164/* This subroutine is used to create the string                               */
165/******************************************************************************/
166/*                                                                            */
167/* if ParentOrCurgrid == 0 -->  Agrif_Curgrid % tabvars (i) % var % array1    */
168/*                                                                            */
169/* if ParentOrCurgrid == 1 -->  Agrif_tabvars (i) % parent_var %var % array1  */
170/*                                                                            */
171/* if ParentOrCurgrid == 2 -->  Agrif_Gr % tabvars (i) % var % array1         */
172/*                                                                            */
173/******************************************************************************/
174char *vargridcurgridtabvars (variable * var,int ParentOrCurgrid)
175{
176  char *tmp;
177  char tmp1[LONGNOM];
178 
179  tmp = variablecurgridtabvars (var,ParentOrCurgrid);
180  strcpy(tmp1,tmp);
181  free(tmp);
182 
183  sprintf (lvargridname, "%s", tmp1);
184  if (!strcasecmp (var->typevar, "REAL"))
185    {
186      sprintf (lvargridname2, "%% array%d", var->nbdim);
187    }
188  else if (!strcasecmp (var->typevar, "REAL*8"))
189    {
190      sprintf (lvargridname2, "%% darray%d", var->nbdim);
191    }
192  else if (!strcasecmp (var->typevar, "INTEGER"))
193    {
194      sprintf (lvargridname2, "%% iarray%d", var->nbdim);
195    }
196  else if (!strcasecmp (var->typevar, "LOGICAL"))
197    {
198      sprintf (lvargridname2, "%% larray%d", var->nbdim);
199    }
200  else if (!strcasecmp (var->typevar, "CHARACTER"))
201    {
202      sprintf (lvargridname2, "%% carray%d", var->nbdim);
203    }
204
205  strcat (lvargridname, lvargridname2);
206
207  return lvargridname;
208}
209
210/******************************************************************************/
211/*                               vargridparam                                 */
212/******************************************************************************/
213/* This subroutine is used to create the string which contains                */
214/* dimension list                                                             */
215/******************************************************************************/
216/*                                                                            */
217/*  DIMENSION(jpi,0:jpj) ----------->"1:jpi,0:jpj"                            */
218/*                                                                            */
219/******************************************************************************/
220char *vargridparam (variable * v, int whichone)
221{
222  typedim dim;
223  listdim *newdim;
224  char newname[LONGNOM];
225   
226  newdim = v->dimension;
227  if (!newdim) return "";
228
229  strcpy (tmpvargridname, "(");
230  while (newdim)
231  {
232     dim = newdim->dim;
233
234     strcpy(newname,"");
235     strcpy(newname, 
236            ChangeTheInitalvaluebyTabvarsName(dim.first,globliste,whichone));   
237     if ( !strcasecmp(newname,dim.first))
238     {
239        strcpy(newname,"");     
240        /* la liste des use de cette subroutine                               */
241        if ( !globalvarofusefile ) RecordUseModulesVariables();
242        strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,
243                       globalvarofusefile,whichone));
244     }
245     strcat (tmpvargridname, newname);
246     strcat (tmpvargridname, " : ");
247     strcpy(newname,"");
248     strcpy(newname,ChangeTheInitalvaluebyTabvarsName
249                        (dim.last,globliste,whichone));   
250     if ( !strcasecmp(newname,dim.last))
251     {
252        strcpy(newname,"");     
253        /* la liste des use de cette subroutine                               */
254        if ( !globalvarofusefile ) RecordUseModulesVariables();
255        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
256                       (dim.last, globalvarofusefile,whichone));
257     }
258     strcat (tmpvargridname, newname);
259     newdim = newdim->suiv;
260     if (newdim) strcat (tmpvargridname, ",");
261  }
262  strcat (tmpvargridname, ")");
263  strcat (tmpvargridname, "\0");
264  return tmpvargridname;
265}
266
267/******************************************************************************/
268/*                        write_probdimagrif_file                             */
269/******************************************************************************/
270/* This subroutine is used to create the file probdim_agrif.h                 */
271/******************************************************************************/
272/*                                                                            */
273/*               probdim_agrif.h                                              */
274/*                                                                            */
275/*               Agrif_probdim = <number>                                     */
276/*                                                                            */
277/******************************************************************************/
278void write_probdimagrif_file()
279{
280  FILE *probdim;
281  char ligne[LONGLIGNE*100];
282 
283  probdim = associate("probdim_agrif.h");
284  sprintf (ligne, "Agrif_Probdim = %d", dimprob);
285  tofich (probdim, ligne,1);
286  fclose (probdim);
287}
288
289/******************************************************************************/
290/*                             write_keysagrif_file                           */
291/******************************************************************************/
292/* This subroutine is used to create the file keys_agrif.h                    */
293/******************************************************************************/
294/*                                                                            */
295/*               keys_agrif.h                                                 */
296/*                                                                            */
297/*               AGRIF_USE_FIXED_GRIDS = 0                                    */
298/*               AGRIF_USE_ONLY_FIXED_GRIDS = 0                               */
299/*               AGRIF_USE_(ONLY)_FIXED_GRIDS = 1                             */
300/*                                                                            */
301/******************************************************************************/
302void write_keysagrif_file()
303{
304  FILE *keys;
305
306  keys = associate ("keys_agrif.h");
307  fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 0\n");
308  fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 0\n");
309  if (fixedgrids     == 1) fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 1\n");
310  if (onlyfixedgrids == 1) fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 1\n");
311
312  fclose(keys); 
313}
314
315/******************************************************************************/
316/*                      write_modtypeagrif_file                               */
317/******************************************************************************/
318/* This subroutine is used to create the file typedata                        */
319/******************************************************************************/
320/*                                                                            */
321/*               modtype_agrif.h                                              */
322/*                                                                            */
323/*               Agrif_NbVariables =                                          */
324/*                                                                            */
325/******************************************************************************/
326void write_modtypeagrif_file()
327{
328  char ligne[LONGLIGNE*100];
329  FILE *typedata;
330
331  typedata = associate ("modtype_agrif.h");
332  /* AGRIF_NbVariables : number of variables                                  */
333  sprintf (ligne, "AGRIF_NbVariables = %d",indicemaxtabvars);
334  tofich(typedata,ligne,1);
335  fclose (typedata);
336}
337
338/******************************************************************************/
339/*                   write_createvarnameagrif_file                            */
340/******************************************************************************/
341/* This subroutine is used to create the file  createvarname                  */
342/******************************************************************************/
343/*                                                                            */
344/*    Agrif_Gr % tabvars (i) % var % namevar = "variable"                     */
345/*                                                                            */
346/******************************************************************************/
347void write_createvarnameagrif_file(variable *v,FILE *createvarname,
348                                                       int *InitEmpty)
349{
350  char ligne[LONGLIGNE*100];
351  char *tmp;
352  char temp1[LONGLIGNE];
353 
354  tmp =  variablenametabvars(v,0);
355  strcpy (temp1, tmp);
356  free(tmp);
357
358  *InitEmpty = 0 ;
359  sprintf(ligne, "%s %% namevar = \"%s\"",temp1,v->nomvar);
360  tofich(createvarname,ligne,1);
361}
362
363/******************************************************************************/
364/*                        write_Setnumberofcells_file                         */
365/******************************************************************************/
366/* This subroutine is used to create the file  setnumberofcells               */
367/******************************************************************************/
368/*                                                                            */
369/*              Agrif_Gr % n(i) = nbmailles                                   */
370/*                                                                            */
371/******************************************************************************/
372void write_Setnumberofcells_file()
373{
374  char ligne[LONGLIGNE*100];
375  FILE *setnumberofcells;
376
377  setnumberofcells=associate("SetNumberofcells.h");
378 
379  if (onlyfixedgrids != 1 )
380  {
381  sprintf (ligne, 
382           "Agrif_Gr %% nb(1) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
383           IndicenbmaillesX);
384  }
385  else
386  {
387  sprintf (ligne, 
388           "Agrif_Gr %% nb(1) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
389           IndicenbmaillesX);
390  }
391  tofich (setnumberofcells, ligne,1);
392  if (dimprob > 1)
393  {
394     if (onlyfixedgrids != 1 )
395     {
396     sprintf (ligne, 
397           "Agrif_Gr %% nb(2) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
398           IndicenbmaillesY);
399     }
400     else
401     {
402     sprintf (ligne, 
403           "Agrif_Gr %% nb(2) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
404           IndicenbmaillesY);
405     }
406
407     tofich (setnumberofcells, ligne,1);
408  }
409  if (dimprob > 2)
410  {
411     if (onlyfixedgrids != 1 )
412     {
413     sprintf (ligne, 
414           "Agrif_Gr %% nb(3) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
415           IndicenbmaillesZ);
416     }
417     else
418     {
419     sprintf (ligne, 
420           "Agrif_Gr %% nb(3) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
421           IndicenbmaillesZ);
422     }
423     tofich (setnumberofcells, ligne,1);
424  }
425
426  fclose (setnumberofcells);
427}
428
429/******************************************************************************/
430/*                       write_Getnumberofcells_file                          */
431/******************************************************************************/
432/* This subroutine is used to create the file  getnumberofcells               */
433/******************************************************************************/
434/*                                                                            */
435/*              nbmailles = Agrif_Gr % n(i)                                   */
436/*                                                                            */
437/******************************************************************************/
438void write_Getnumberofcells_file()
439{
440  char ligne[LONGLIGNE*100];
441  FILE *getnumberofcells;
442
443  getnumberofcells=associate("GetNumberofcells.h");
444  sprintf (ligne, 
445           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(1)",
446           IndicenbmaillesX);
447  tofich (getnumberofcells, ligne,1);
448  if (dimprob > 1)
449    {
450      sprintf (ligne,
451           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(2)",
452           IndicenbmaillesY);
453      tofich (getnumberofcells, ligne,1);
454    }
455  if (dimprob > 2)
456    {
457      sprintf (ligne, 
458           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(3)",
459           IndicenbmaillesZ);
460      tofich (getnumberofcells, ligne,1);
461    }   
462  fclose (getnumberofcells);
463}
464
465/******************************************************************************/
466/*                      write_initialisationsagrif_file                       */
467/******************************************************************************/
468/* This subroutine is used to create the file initproc                        */
469/******************************************************************************/
470/*                                                                            */
471/*              ! variable                                                    */
472/*              Agrif_Gr % tabvars(i) % var % nbdim = 1                       */
473/*                                                                            */
474/******************************************************************************/
475void write_initialisationsagrif_file(variable *v,FILE *initproc,
476                                     int *VarnameEmpty)
477{
478  char ligne[LONGLIGNE*100];
479  char temp1[LONGLIGNE];
480  char *tmp;
481
482  tmp = variablenameroottabvars (v);
483  strcpy (temp1, tmp);
484  free(tmp);
485
486  if ( v->nbdim != 0 ) 
487  {
488     *VarnameEmpty = 0 ;
489     sprintf (ligne, "%s %% nbdim = %d", temp1, v->nbdim);
490     tofich (initproc, ligne,1);
491  }
492}
493
494/******************************************************************************/
495/*                        write_allocation                                    */
496/******************************************************************************/
497/* This subroutine is used to create the file allocationagrif                 */
498/******************************************************************************/
499/*                                                                            */
500/*                 allocations_calls_agrif.h                                  */
501/*                 Call Alloc_agrif_module (Agrif_Gr)                         */
502/*                                                                            */
503/*                 alloc_agrif_module.h                                       */
504/*                 Subroutine Alloc_agrif_module (Agrif_Gr)                   */
505/*                 allocate(Agrif_Gr%tabvars(i)%var%array1(jpi)               */
506/*                 variable =>Agrif_Gr%tabvars(i)%var%array1                  */
507/*                                                                            */
508/******************************************************************************/
509listnom *write_allocation(listvar *newvar,variable *v,
510                          listnom *listedesnoms,
511                          FILE *alloccalls,
512                          FILE *AllocUSE,
513                          FILE *modulealloc,
514                          int *IndiceMax)
515{
516  char ligne[LONGLIGNE*100];
517  char curname[LONGNOM];
518  char initialvalue[LONGNOM];
519  char name1[LONGNOM];
520  listvar *parcours;
521  listnom *parcoursnom;
522  int compteur;
523  int ValeurMax;
524  int donotwrite=0;
525  FILE *alloc_agrif;
526 
527  ValeurMax = 2;
528  if (v->common == 1) strcpy(curname,v->commonname);     
529  if (v->module == 1) strcpy(curname,v->modulename); 
530 
531  if ( strcasecmp(curname,Alloctreatedname) )
532  {
533     strcpy(Alloctreatedname,curname);     
534
535/******************************************************************************/
536/*                 alloc_agrif_module.h                                       */
537/*                 Subroutine Alloc_agrif_module (Agrif_Gr)                   */
538/******************************************************************************/
539     if ( v->common == 1 ) strcpy(name1,v->commonname);
540     else if ( v->module == 1 )  strcpy(name1,v->modulename);
541     else exit(1);
542
543     sprintf(ligne,"alloc_agrif_%s.h",name1);
544     allocationagrif = associate (ligne);
545
546     *IndiceMax = 0;
547     AllocEmpty = 1;
548
549     sprintf (ligne, "Subroutine Alloc_agrif_%s(Agrif_Gr)", curname);
550     tofich(allocationagrif,ligne,1);
551     if ( ModuleIsDefineInInputFile(curname) == 1 )
552     {
553        strcpy(ligne,"Use Agrif_Util");
554        tofich(allocationagrif,ligne,1);
555     }
556     else
557     {
558        if ( fortran77 == 1 )
559        {
560           strcpy(ligne,"Use Agrif_Types, ONLY : Agrif_tabvars");
561           tofich(allocationagrif,ligne,1);
562           strcpy(ligne,"Use Agrif_Types, ONLY : Agrif_grid");
563           tofich(allocationagrif,ligne,1);
564        }
565     }
566     strcpy (ligne, "Type(Agrif_grid), Pointer :: Agrif_Gr");
567     tofich(allocationagrif,ligne,1);
568     /* Add the declaration of I into the allocationagrif file                */
569     strcpy(ligne, "INTEGER :: i");
570     tofich (allocationagrif, ligne,1);
571
572     if ( fortran77 == 1 )
573     {
574        writedeclarationintoamr(parameterlist,allocationagrif,newvar,curname);
575     }
576     if ( ModuleIsDefineInInputFile(curname) == 1 )
577     {
578         /* add the call to initworkspace                                     */
579         tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
580         fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
581         tofich(allocationagrif,"else ",1);
582         fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
583         tofich(allocationagrif,"endif ",1);
584         tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
585     }
586  }
587  /* body of the file                                                         */
588  if ( !strcasecmp(v->commonname,Alloctreatedname) ||
589       !strcasecmp(v->modulename,Alloctreatedname) )
590  {
591     if (onlyfixedgrids != 1 && v->nbdim!=0) 
592     {
593        strcpy (ligne, "If (.not. associated(");
594        strcat (ligne, vargridnametabvars(v,0));
595        strcat (ligne, "))                       then");
596        tofich (allocationagrif, ligne,1);
597        AllocEmpty = 0;
598     }
599     if ( v->allocatable != 1 && ( v->dimsempty != 1) )
600     {
601        /*                ALLOCATION                                          */
602        if ( v->dimension != 0  )
603        {
604           if ( v->indicetabvars > *IndiceMax )
605           {
606              parcours = newvar;
607              compteur = -1;
608              while ( parcours &&
609                      !strcasecmp(newvar->var->readedlistdimension,
610                                  parcours->var->readedlistdimension) &&
611                      !strcasecmp(newvar->var->typevar,parcours->var->typevar) )
612              {
613                 compteur = compteur +1 ;
614                 parcours=parcours->suiv;
615              }
616              if ( compteur > ValeurMax )
617              {
618                 fprintf(allocationagrif,"      DO i = %d , %d\n", 
619                                          newvar->var->indicetabvars,
620                                          newvar->var->indicetabvars+compteur);
621                *IndiceMax = newvar->var->indicetabvars+compteur;
622                 strcpy (ligne, "allocate ");
623                 strcat (ligne, "(");
624                 strcat (ligne, vargridnametabvars(v,1));
625                 strcat (ligne, vargridparam(v,0));
626                 strcat (ligne, ")");
627                 tofich (allocationagrif, ligne,1);
628                 fprintf(allocationagrif,"      end do\n");           
629                 AllocEmpty = 0;
630              }
631              else
632              {
633                 strcpy (ligne, "allocate ");
634                 strcat (ligne, "(");
635                 strcat (ligne, vargridnametabvars(v,0));
636                 strcat (ligne, vargridparam(v,0));
637                 strcat (ligne, ")");
638                 tofich (allocationagrif, ligne,1); 
639                 AllocEmpty = 0;
640              }
641           }
642        } /* end of the allocation part                                       */
643        /*                INITIALISATION                                      */
644        if ( strcasecmp(v->initialvalue,"") ) 
645        {
646           strcpy (ligne, "");
647           strcat (ligne, vargridnametabvars(v,0));
648           /* We should modify the initialvalue in the case of variable has   */
649           /*    benn defined with others variables                           */
650           strcpy(initialvalue,
651                  ChangeTheInitalvaluebyTabvarsName
652                                      (v->initialvalue,globliste,0));
653           if ( !strcasecmp(initialvalue,v->initialvalue) )
654           {
655              strcpy(initialvalue,"");     
656              /* la liste des use de cette subroutine                         */
657              if ( !globalvarofusefile ) RecordUseModulesVariables();
658              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
659                                      (v->initialvalue,globalvarofusefile,0));
660           }
661           strcat (ligne," = "); 
662           strcat (ligne,initialvalue); 
663           /*                                                                 */
664           tofich (allocationagrif, ligne,1);
665           AllocEmpty = 0;
666        }
667     }
668     if (onlyfixedgrids != 1 && v->nbdim!=0) 
669     {
670        strcpy (ligne, "   End if");
671        tofich (allocationagrif, ligne,1);
672     }     
673  } 
674  /* closing of the file                                                      */
675  if ( newvar->suiv == NULL ||
676       ( v->common == 1 &&
677         strcasecmp(newvar->suiv->var->commonname,Alloctreatedname) ) ||
678       ( v->module == 1 &&
679         strcasecmp(newvar->suiv->var->modulename,Alloctreatedname) ) 
680     )
681  {
682     if ( ModuleIsDefineInInputFile(curname) == 1 )
683     {
684         /* add the call to initworkspace                                     */
685         tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
686         fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
687         tofich(allocationagrif,"else ",1);
688         fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
689         tofich(allocationagrif,"endif ",1);
690         tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
691     }
692     strcpy (ligne, "Return");
693     tofich(allocationagrif,ligne,1);
694     sprintf (ligne, "End Subroutine Alloc_agrif_%s",curname);
695     tofich(allocationagrif,ligne,1);
696     fclose(allocationagrif);
697     allocationagrif = (FILE *)NULL;
698
699/******************************************************************************/
700/*                 NewModule_module.h                                         */
701/*                 module <module> ETC ...                                    */
702/******************************************************************************/
703     if ( fortran77 == 1 )
704     {
705        donotwrite = 0 ;
706        if ( strcasecmp(v->commoninfile,mainfile)) donotwrite = 1 ;
707        else 
708        {
709           /* we should verify that this module has not been write in this fil*/
710           parcoursnom = listedesnoms;
711           sprintf(ligne,"USE %s",curname);
712           while ( parcoursnom && donotwrite == 0 )
713           {
714              if ( !strcasecmp(parcoursnom->nom,ligne) ) donotwrite = 1;
715              else parcoursnom = parcoursnom ->suiv;
716           }
717        }
718
719        if ( donotwrite == 0 ) 
720        {
721           if ( ModuleIsDefineInInputFile(curname) == 1 ) AllocEmpty = 0;
722           if ( AllocEmpty == 1 )
723           {
724            sprintf (ligne, "\n#include \"agrif_alloc_%s.h\"\n", curname);
725            fprintf(alloccalls,ligne);
726            sprintf (ligne, "agrif_alloc_%s.h", curname);
727            alloc_agrif = associate(ligne);
728            sprintf (ligne, "!", curname);
729            tofich (alloc_agrif, ligne,1);
730
731            fprintf(modulealloc,"! empty module alloc %s \n",curname );
732       fclose(alloc_agrif);
733           }
734           else
735           {
736/******************************************************************************/
737/*                 include_use_Alloc_agrif.h                               */
738/*                 USE mod                                                    */
739/******************************************************************************/
740            sprintf (ligne, "USE %s", curname);
741            tofich (AllocUSE, ligne,1);
742/******************************************************************************/
743/*                 allocations_calls_agrif.h                                  */
744/*                 Call Alloc_agrif_module (Agrif_Gr)                         */
745/******************************************************************************/
746            sprintf (ligne, "\n#include \"agrif_alloc_%s.h\"\n", curname);
747            fprintf(alloccalls,ligne);
748            sprintf (ligne, "agrif_alloc_%s.h", curname);
749            alloc_agrif = associate(ligne);
750            sprintf (ligne, "Call Alloc_agrif_%s(Agrif_Gr)", curname);
751            tofich (alloc_agrif, ligne,1);
752       fclose(alloc_agrif);
753/******************************************************************************/
754/******************************************************************************/
755            fprintf(modulealloc,"      module %s \n",curname);
756            fprintf(modulealloc,"      IMPLICIT NONE \n");
757            fprintf(modulealloc,"      PUBLIC Alloc_agrif_%s \n",curname);
758            fprintf(modulealloc,"      CONTAINS \n");
759            fprintf(modulealloc,"#include \"alloc_agrif_%s.h\" \n",curname);
760            fprintf(modulealloc,"      end module %s \n",curname);
761/******************************************************************************/
762/******************************************************************************/
763            sprintf(ligne,"USE %s",curname);
764            listedesnoms = Addtolistnom(ligne,listedesnoms);
765           }
766        }
767     }
768        else
769        {
770           if ( Did_filetoparse_treated == 0 && AllocEmpty == 0 )
771           {
772/******************************************************************************/
773/*                 include_use_Alloc_agrif.h                                  */
774/*                 USE mod                                                    */
775/******************************************************************************/
776              sprintf (ligne, "USE %s", curname);
777              tofich (AllocUSE, ligne,1);
778/******************************************************************************/
779/*                 allocations_calls_agrif.h                                  */
780/*                 Call Alloc_agrif_module (Agrif_Gr)                         */
781/******************************************************************************/
782              sprintf (ligne, "#include \"agrif_alloc_%s.h\" \n", curname);
783              fprintf (alloccalls, ligne);
784              sprintf (ligne, "agrif_alloc_%s.h", curname);
785              alloc_agrif = associate(ligne);
786              sprintf (ligne, "Call Alloc_agrif_%s(Agrif_Gr)", curname);
787              tofich (alloc_agrif, ligne,1);
788         fclose(alloc_agrif);
789           }
790        }
791  }
792  return listedesnoms;
793}
794
795/******************************************************************************/
796/*                           creefichieramr                                   */
797/******************************************************************************/
798/* This subroutine is the main one to create AGRIF_INC files                  */
799/******************************************************************************/
800/*                                                                            */
801/******************************************************************************/
802void creefichieramr (char *NameTampon)
803{
804  listvar *newvar;
805  variable *v;
806  int erreur;
807  char filefich[LONGNOM];
808  char ligne[LONGNOM];
809  int IndiceMax;
810  int InitEmpty;
811  int VarnameEmpty;
812  int donotwrite;
813  listnom *listedesnoms;
814 
815  FILE *initproc;
816  FILE *initglobal;
817  FILE *createvarname;
818  FILE *createvarnameglobal;
819  FILE *alloccalls;
820  FILE *AllocUSE;
821  FILE *modulealloc;
822 
823  strcpy (filefich, "cd ");
824  strcat (filefich, nomdir);
825  erreur = system (filefich);
826  if (erreur)
827    {
828      strcpy (filefich, "mkdir ");
829      strcat (filefich, nomdir);
830      system (filefich);
831      printf ("%s: Directory created\n", nomdir);
832    }
833
834/******************************************************************************/
835/******************** Creation of AGRIF_INC files *****************************/
836/******************************************************************************/
837  write_probdimagrif_file();
838  write_keysagrif_file();
839  write_modtypeagrif_file();     
840  write_Setnumberofcells_file();
841  write_Getnumberofcells_file();     
842  /*--------------------------------------------------------------------------*/
843  /*   Record the list of module used in the file include_use_Alloc_agrif     */
844  listedesnoms = (listnom *)NULL;
845
846  strcpy(Alloctreatedname,"");     
847/*----------------------------------------------------------------------------*/
848/*----------------------------------------------------------------------------*/
849/*----------------------------------------------------------------------------*/
850/*----------------------------------------------------------------------------*/
851/*----------------------------------------------------------------------------*/
852  if ( todebug == 1 )
853  {
854     strcpy(ligne,"initialisations_agrif_");
855     strcat(ligne,NameTampon);
856     strcat(ligne,".h");
857     initproc = associate (ligne);
858/*----------------------------------------------------------------------------*/
859     strcpy(ligne,"createvarname_agrif_");
860     strcat(ligne,NameTampon);
861     strcat(ligne,".h");
862     createvarname = associate (ligne);
863/*----------------------------------------------------------------------------*/
864     InitEmpty = 1 ;
865     VarnameEmpty = 1 ;
866
867     newvar = globliste;
868     while ( newvar && todebug == 1 )
869     {
870        donotwrite = 0;
871        v = newvar->var;
872
873        if ( fortran77 == 1 )
874        {
875           if ( v->indicetabvars <= oldindicemaxtabvars ) donotwrite = 1;
876        }
877
878        if ( ( v->common == 1 || v->module == 1 ) && donotwrite == 0 )
879        {
880          write_createvarnameagrif_file(v,createvarname,&VarnameEmpty);
881          write_initialisationsagrif_file(v,initproc,&InitEmpty);
882        }
883        newvar = newvar->suiv;
884     }
885  /*                                                                          */
886     fclose (createvarname); 
887     fclose (initproc);
888  /*--------------------------------------------------------------------------*/
889     if ( Did_filetoparse_treated == 0 ) 
890     {
891        if ( InitEmpty != 1  )
892        {
893           initglobal = associateaplus("initialisations_agrif.h");
894           strcpy(ligne,"#include \"initialisations_agrif_");
895           strcat(ligne,NameTampon);
896           strcat(ligne,".h\"\n");
897           fprintf(initglobal,ligne);
898           fclose(initglobal);     
899        }
900  /*--------------------------------------------------------------------------*/
901        if ( VarnameEmpty != 1 )
902        {
903           createvarnameglobal= associateaplus("createvarname_agrif.h");
904           strcpy(ligne,"#include \"createvarname_agrif_");
905           strcat(ligne,NameTampon);
906           strcat(ligne,".h\"\n");
907           fprintf(createvarnameglobal,ligne);
908           fclose(createvarnameglobal);     
909        }
910     }
911  }
912/*----------------------------------------------------------------------------*/
913/*----------------------------------------------------------------------------*/
914/*----------------------------------------------------------------------------*/
915/*----------------------------------------------------------------------------*/
916/*----------------------------------------------------------------------------*/
917  AllocUSE= associateaplus("include_use_Alloc_agrif.h");
918  alloccalls = associateaplus("allocations_calls_agrif.h");
919  sprintf(ligne,"NewModule_%s.h",NameTampon);
920  modulealloc=associate(ligne);
921  /*--------------------------------------------------------------------------*/
922  IndiceMax = 0;
923
924  newvar = globliste;
925  while (newvar)
926  {
927     v = newvar->var;
928     if ( (v->common == 1) || (v->module == 1) )
929     {
930        listedesnoms = write_allocation(newvar,v,
931                                       listedesnoms,
932                                       alloccalls,
933                                       AllocUSE,
934                                       modulealloc,
935                                       &IndiceMax);
936     }
937     newvar = newvar->suiv;
938  }
939 
940  fclose (AllocUSE);
941  fclose (alloccalls);
942  fclose (modulealloc);
943}
Note: See TracBrowser for help on using the repository browser.