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 branches/2010_and_older/dev_001_GM/AGRIF/LIB – NEMO

source: branches/2010_and_older/dev_001_GM/AGRIF/LIB/toamr.c @ 9021

Last change on this file since 9021 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: 45.3 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 <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->v_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->v_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->v_indicetabvars);
100  else if ( ParentOrCurgrid == 1 ) sprintf (ligne,
101                              " Agrif_tabvars(%d) %% parent_var %% var",
102                               var->v_indicetabvars);
103  else if ( ParentOrCurgrid == 2 ) sprintf (ligne,
104                              " Agrif_Mygrid %% tabvars(%d) %% var",
105                               var->v_indicetabvars);
106  else if ( ParentOrCurgrid == 3 ) sprintf (ligne,
107                              " Agrif_Curgrid %% tabvars(%d) %% var",
108                               var->v_indicetabvars);
109  else sprintf (ligne, " AGRIF_Mygrid %% tabvars(%d) %% var",
110                               var->v_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  if ( todebugfree == 1 ) free(tmp);
133
134  sprintf (lvargridname, "%s", tmp1);
135  if (!strcasecmp (var->v_typevar, "REAL"))
136    {
137      if ( !strcasecmp(var->v_nameinttypename,"8") )
138                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
139      else if ( !strcasecmp(var->v_nameinttypename,"4") )
140                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
141      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
142    }
143  else if (!strcasecmp (var->v_typevar, "INTEGER"))
144    {
145      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
146    }
147  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
148    {
149      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
150    }
151  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
152    {
153      sprintf (lvargridname2, "%% carray%d", var->v_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  if ( todebugfree == 1 ) free(tmp);
182
183  sprintf (lvargridname, "%s", tmp1);
184  if (!strcasecmp (var->v_typevar, "REAL"))
185    {
186      if ( !strcasecmp(var->v_nameinttypename,"8") )
187                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
188      else if ( !strcasecmp(var->v_nameinttypename,"4") )
189                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
190      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
191    }
192  else if (!strcasecmp (var->v_typevar, "INTEGER"))
193    {
194      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
195    }
196  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
197    {
198      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
199    }
200  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
201    {
202      sprintf (lvargridname2, "%% carray%d", var->v_nbdim);
203    }
204
205  strcat (lvargridname, lvargridname2);
206
207  return lvargridname;
208}
209
210/******************************************************************************/
211/*                  vargridcurgridtabvarswithoutAgrif_Gr                      */
212/******************************************************************************/
213/* This subroutine is used to create the string                               */
214/******************************************************************************/
215/*                                                                            */
216/******************************************************************************/
217char *vargridcurgridtabvarswithoutAgrif_Gr (variable * var)
218{
219
220  sprintf (lvargridname, "(%d) %% var", var->v_indicetabvars);
221
222  if (!strcasecmp (var->v_typevar, "REAL"))
223    {
224      if ( !strcasecmp(var->v_nameinttypename,"8") )
225                           sprintf (lvargridname2, "%% darray%d", var->v_nbdim);
226      else if ( !strcasecmp(var->v_nameinttypename,"4") )
227                           sprintf (lvargridname2, "%% sarray%d", var->v_nbdim);
228      else sprintf (lvargridname2, "%% array%d", var->v_nbdim);
229    }
230  else if (!strcasecmp (var->v_typevar, "INTEGER"))
231    {
232      sprintf (lvargridname2, "%% iarray%d", var->v_nbdim);
233    }
234  else if (!strcasecmp (var->v_typevar, "LOGICAL"))
235    {
236      sprintf (lvargridname2, "%% larray%d", var->v_nbdim);
237    }
238  else if (!strcasecmp (var->v_typevar, "CHARACTER"))
239    {
240      sprintf (lvargridname2, "%% carray%d", var->v_nbdim);
241    }
242
243  strcat (lvargridname, lvargridname2);
244
245  return lvargridname;
246}
247
248/******************************************************************************/
249/*                               vargridparam                                 */
250/******************************************************************************/
251/* This subroutine is used to create the string which contains                */
252/* dimension list                                                             */
253/******************************************************************************/
254/*                                                                            */
255/*  DIMENSION(jpi,0:jpj) ----------->"1:jpi,0:jpj"                            */
256/*                                                                            */
257/******************************************************************************/
258char *vargridparam (variable * v, int whichone)
259{
260  typedim dim;
261  listdim *newdim;
262  char newname[LONGNOM];
263
264  newdim = v->v_dimension;
265  if (!newdim) return "";
266
267  strcpy (tmpvargridname, "(");
268  while (newdim)
269  {
270     dim = newdim->dim;
271
272     strcpy(newname,"");
273     strcpy(newname,
274            ChangeTheInitalvaluebyTabvarsName(dim.first,List_Global_Var,
275                                                                     whichone));
276     if ( !strcasecmp(newname,dim.first))
277     {
278        strcpy(newname,"");
279        strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,
280                       List_Common_Var,whichone));
281     }
282     if ( !strcasecmp(newname,dim.first))
283     {
284        strcpy(newname,"");
285        /* la liste des use de cette subroutine                               */
286        strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,
287                       List_ModuleUsed_Var,whichone));
288     }
289     strcat (tmpvargridname, newname);
290     strcat (tmpvargridname, " : ");
291     strcpy(newname,"");
292     strcpy(newname,ChangeTheInitalvaluebyTabvarsName
293                        (dim.last,List_Global_Var,whichone));
294     if ( !strcasecmp(newname,dim.last))
295     {
296        strcpy(newname,"");
297        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
298                       (dim.last, List_Common_Var,whichone));
299     }
300     if ( !strcasecmp(newname,dim.last))
301     {
302        strcpy(newname,"");
303        /* la liste des use de cette subroutine                               */
304        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
305                       (dim.last, List_ModuleUsed_Var,whichone));
306     }
307     strcat (tmpvargridname, newname);
308     newdim = newdim->suiv;
309     if (newdim) strcat (tmpvargridname, ",");
310  }
311  strcat (tmpvargridname, ")");
312  strcat (tmpvargridname, "\0");
313  return tmpvargridname;
314}
315
316/******************************************************************************/
317/*                        write_probdimagrif_file                             */
318/******************************************************************************/
319/* This subroutine is used to create the file probdim_agrif.h                 */
320/******************************************************************************/
321/*                                                                            */
322/*               probdim_agrif.h                                              */
323/*                                                                            */
324/*               Agrif_probdim = <number>                                     */
325/*                                                                            */
326/******************************************************************************/
327void write_probdimagrif_file()
328{
329  FILE *probdim;
330  char ligne[LONGLIGNE*100];
331
332  probdim = associate("probdim_agrif.h");
333  sprintf (ligne, "Agrif_Probdim = %d", dimprob);
334  tofich (probdim, ligne,1);
335  fclose (probdim);
336}
337
338/******************************************************************************/
339/*                             write_keysagrif_file                           */
340/******************************************************************************/
341/* This subroutine is used to create the file keys_agrif.h                    */
342/******************************************************************************/
343/*                                                                            */
344/*               keys_agrif.h                                                 */
345/*                                                                            */
346/*               AGRIF_USE_FIXED_GRIDS = 0                                    */
347/*               AGRIF_USE_ONLY_FIXED_GRIDS = 0                               */
348/*               AGRIF_USE_(ONLY)_FIXED_GRIDS = 1                             */
349/*                                                                            */
350/******************************************************************************/
351void write_keysagrif_file()
352{
353  FILE *keys;
354
355  keys = associate ("keys_agrif.h");
356  fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 0\n");
357  fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 0\n");
358  if (fixedgrids     == 1) fprintf(keys,"      AGRIF_USE_FIXED_GRIDS = 1\n");
359  if (onlyfixedgrids == 1)
360                         fprintf(keys,"      AGRIF_USE_ONLY_FIXED_GRIDS = 1\n");
361
362  fclose(keys);
363}
364
365/******************************************************************************/
366/*                      write_modtypeagrif_file                               */
367/******************************************************************************/
368/* This subroutine is used to create the file typedata                        */
369/******************************************************************************/
370/*                                                                            */
371/*               modtype_agrif.h                                              */
372/*                                                                            */
373/*               Agrif_NbVariables =                                          */
374/*                                                                            */
375/******************************************************************************/
376void write_modtypeagrif_file()
377{
378  char ligne[LONGLIGNE*100];
379  FILE *typedata;
380
381  typedata = associate ("modtype_agrif.h");
382  /* AGRIF_NbVariables : number of variables                                  */
383  sprintf (ligne, "AGRIF_NbVariables = %d",indicemaxtabvars);
384  tofich(typedata,ligne,1);
385  fclose (typedata);
386}
387
388/******************************************************************************/
389/*                   write_createvarnameagrif_file                            */
390/******************************************************************************/
391/* This subroutine is used to create the file  createvarname                  */
392/******************************************************************************/
393/*                                                                            */
394/*    Agrif_Gr % tabvars (i) % var % namevar = "variable"                     */
395/*                                                                            */
396/******************************************************************************/
397void write_createvarnameagrif_file(variable *v,FILE *createvarname,
398                                                       int *InitEmpty)
399{
400  char ligne[LONGLIGNE*100];
401  char *tmp;
402  char temp1[LONGLIGNE];
403
404  tmp =  variablenametabvars(v,0);
405  strcpy (temp1, tmp);
406  if ( todebugfree == 1 ) free(tmp);
407
408  *InitEmpty = 0 ;
409  sprintf(ligne, "%s %% namevar = \"%s\"",temp1,v->v_nomvar);
410  tofich(createvarname,ligne,1);
411}
412
413/******************************************************************************/
414/*                        write_Setnumberofcells_file                         */
415/******************************************************************************/
416/* This subroutine is used to create the file  setnumberofcells               */
417/******************************************************************************/
418/*                                                                            */
419/*              Agrif_Gr % n(i) = nbmailles                                   */
420/*                                                                            */
421/******************************************************************************/
422void write_Setnumberofcells_file()
423{
424  char ligne[LONGLIGNE*100];
425  FILE *setnumberofcells;
426
427  if ( IndicenbmaillesX != 0 )
428  {
429  setnumberofcells=associate("SetNumberofcells.h");
430
431  if (onlyfixedgrids != 1 )
432  {
433  sprintf (ligne,
434           "Agrif_Gr %% nb(1) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
435           IndicenbmaillesX);
436  }
437  else
438  {
439  sprintf (ligne,
440           "Agrif_Gr %% nb(1) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
441           IndicenbmaillesX);
442  }
443  tofich (setnumberofcells, ligne,1);
444  if (dimprob > 1)
445  {
446     if (onlyfixedgrids != 1 )
447     {
448     sprintf (ligne,
449           "Agrif_Gr %% nb(2) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
450           IndicenbmaillesY);
451     }
452     else
453     {
454     sprintf (ligne,
455           "Agrif_Gr %% nb(2) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
456           IndicenbmaillesY);
457     }
458
459     tofich (setnumberofcells, ligne,1);
460  }
461  if (dimprob > 2)
462  {
463     if (onlyfixedgrids != 1 )
464     {
465     sprintf (ligne,
466           "Agrif_Gr %% nb(3) = Agrif_Gr %% tabvars(%d) %% var %% iarray0",
467           IndicenbmaillesZ);
468     }
469     else
470     {
471     sprintf (ligne,
472           "Agrif_Gr %% nb(3) = Agrif_Curgrid %% tabvars(%d) %% var %% iarray0",
473           IndicenbmaillesZ);
474     }
475     tofich (setnumberofcells, ligne,1);
476  }
477
478  fclose (setnumberofcells);
479  }
480}
481
482/******************************************************************************/
483/*                       write_Getnumberofcells_file                          */
484/******************************************************************************/
485/* This subroutine is used to create the file  getnumberofcells               */
486/******************************************************************************/
487/*                                                                            */
488/*              nbmailles = Agrif_Gr % n(i)                                   */
489/*                                                                            */
490/******************************************************************************/
491void write_Getnumberofcells_file()
492{
493  char ligne[LONGLIGNE*100];
494  FILE *getnumberofcells;
495
496  if ( IndicenbmaillesX != 0 )
497  {
498  getnumberofcells=associate("GetNumberofcells.h");
499  sprintf (ligne,
500           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(1)",
501           IndicenbmaillesX);
502  tofich (getnumberofcells, ligne,1);
503  if (dimprob > 1)
504    {
505      sprintf (ligne,
506           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(2)",
507           IndicenbmaillesY);
508      tofich (getnumberofcells, ligne,1);
509    }
510  if (dimprob > 2)
511    {
512      sprintf (ligne,
513           "Agrif_Curgrid %% tabvars(%d) %% var %% iarray0 = Agrif_Gr %% nb(3)",
514           IndicenbmaillesZ);
515      tofich (getnumberofcells, ligne,1);
516    }
517  fclose (getnumberofcells);
518  }
519}
520
521
522/******************************************************************************/
523/*                      write_initialisationsagrif_file                       */
524/******************************************************************************/
525/* This subroutine is used to create the file initproc                        */
526/******************************************************************************/
527/*                                                                            */
528/*              ! variable                                                    */
529/*              Agrif_Gr % tabvars(i) % var % nbdim = 1                       */
530/*                                                                            */
531/******************************************************************************/
532void write_initialisationsagrif_file(variable *v,FILE *initproc,
533                                     int *VarnameEmpty)
534{
535  char ligne[LONGLIGNE*100];
536  char temp1[LONGLIGNE];
537  char *tmp;
538
539  tmp = variablenameroottabvars (v);
540  strcpy (temp1, tmp);
541  if ( todebugfree == 1 ) free(tmp);
542
543  if ( v->v_nbdim != 0 )
544  {
545     *VarnameEmpty = 0 ;
546     sprintf (ligne, "%s %% nbdim = %d", temp1, v->v_nbdim);
547     tofich (initproc, ligne,1);
548  }
549}
550
551
552void Write_Alloc_Agrif_Files()
553{
554   listnom *parcours;
555   FILE *alloccalls;
556   FILE *AllocUSE;
557
558   AllocUSE= associate("include_use_Alloc_agrif.h");
559   alloccalls = associate("allocations_calls_agrif.h");
560
561   parcours = List_Subroutine_For_Alloc;
562   while ( parcours )
563   {
564      fprintf(AllocUSE,"      USE %s\n", parcours -> o_nom );
565      fprintf (alloccalls,"      Call Alloc_agrif_%s(Agrif_Gr)\n",
566                                                            parcours -> o_nom );
567      parcours = parcours -> suiv;
568   }
569
570   fclose (AllocUSE);
571   fclose (alloccalls);
572}
573
574int IndiceInlist(int indic, listindice *listin)
575{
576   listindice *parcoursindic;
577   int out;
578
579   out = 0 ;
580
581   parcoursindic = listin;
582   while ( parcoursindic && out == 0 )
583   {
584      if ( parcoursindic->i_indice == indic ) out = 1;
585      else parcoursindic = parcoursindic -> suiv;
586   }
587
588   return out;
589}
590void write_allocation_Common_0()
591{
592   listnom *parcours_nom;
593   listnom *neededparameter;
594   listvar *parcours;
595   listvar *parcoursprec;
596   listvar *parcours1;
597   FILE *allocationagrif;
598   FILE *paramtoamr;
599   char ligne[LONGNOM];
600   variable *v;
601   int IndiceMax;
602   int IndiceMin;
603   int compteur;
604   int out;
605   int indiceprec;
606   int ValeurMax;
607   char initialvalue[LONGNOM];
608   listindice *list_indic;
609   listindice *parcoursindic;
610   int i;
611
612   parcours_nom = List_NameOfCommon;
613   ValeurMax = 2;
614   while ( parcours_nom  )
615   {
616      /*                                                                      */
617      if ( parcours_nom->o_val == 1 )
618      {
619         /* Open the file to create the Alloc_agrif subroutine                */
620         sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
621         allocationagrif = associate (ligne);
622         /*                                                                   */
623         fprintf(allocationagrif,"#include \"Param_toamr_%s.h\" \n",
624                                                           parcours_nom->o_nom);
625         /*                                                                   */
626         sprintf(ligne,"Param_toamr_%s.h",parcours_nom->o_nom);
627         paramtoamr = associate (ligne);
628         neededparameter = (listnom * )NULL;
629         /*                                                                   */
630         list_indic = (listindice *)NULL;
631         /*                                                                   */
632         shouldincludempif = 1 ;
633         parcours = List_Common_Var;
634         while ( parcours )
635         {
636            if ( !strcasecmp(parcours->var->v_commonname,parcours_nom->o_nom) &&
637                  IndiceInlist(parcours->var->v_indicetabvars,list_indic) == 0
638               )
639            {
640               /***************************************************************/
641               /***************************************************************/
642               /***************************************************************/
643               v = parcours->var;
644               IndiceMax = 0;
645               IndiceMin = indicemaxtabvars;
646  /* body of the file                                                         */
647  if ( !strcasecmp(v->v_commoninfile,mainfile) )
648  {
649     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
650     {
651        strcpy (ligne, "If (.not. associated(");
652        strcat (ligne, vargridnametabvars(v,0));
653        strcat (ligne, "))                       then");
654        tofich (allocationagrif, ligne,1);
655     }
656     if ( v->v_allocatable != 1 && ( v->v_dimsempty != 1) )
657     {
658        /*                ALLOCATION                                          */
659        if ( v->v_dimension != 0  )
660        {
661           if ( v->v_indicetabvars < IndiceMin ||
662                v->v_indicetabvars > IndiceMax )
663           {
664              parcours1 = parcours;
665              compteur = -1;
666              out = 0;
667              indiceprec = parcours->var->v_indicetabvars -1 ;
668              while ( parcours1 && out == 0 &&
669                      !strcasecmp(  parcours->var->v_readedlistdimension,
670                                  parcours1->var->v_readedlistdimension) &&
671                      !strcasecmp(  parcours->var->v_typevar,
672                                  parcours1->var->v_typevar) &&
673                            ( parcours1->var->v_indicetabvars == indiceprec+1 )
674                     )
675              {
676
677               if ( !strcasecmp(parcours1->var->v_modulename,
678                                parcours_nom->o_nom) ||
679                    !strcasecmp(parcours1->var->v_commonname,
680                                parcours_nom->o_nom) )
681                 {
682                      compteur = compteur +1 ;
683                      indiceprec = parcours1->var->v_indicetabvars;
684                      parcoursprec = parcours1;
685                      parcours1 = parcours1->suiv;
686                 }
687                 else out = 1;
688              }
689
690              if ( compteur > ValeurMax )
691              {
692                 fprintf(allocationagrif,"      DO i = %d , %d\n",
693                                         parcours->var->v_indicetabvars,
694                                       parcours->var->v_indicetabvars+compteur);
695                 IndiceMin = parcours->var->v_indicetabvars;
696                 IndiceMax = parcours->var->v_indicetabvars+compteur;
697                 strcpy (ligne, "allocate ");
698                 strcat (ligne, "(");
699                 strcat (ligne, vargridnametabvars(v,1));
700                 strcat (ligne, vargridparam(v,0));
701                 strcat (ligne, ")");
702                 tofich (allocationagrif, ligne,1);
703                 fprintf(allocationagrif,"      end do\n");
704                 i=parcours->var->v_indicetabvars;
705                 do
706                 {
707                    parcoursindic =  (listindice *)malloc(sizeof(listindice));
708                    parcoursindic -> i_indice = i;
709                    parcoursindic -> suiv = list_indic;
710                    list_indic = parcoursindic;
711                    i = i + 1;
712                 } while ( i <= parcours->var->v_indicetabvars+compteur );
713                 parcours = parcoursprec;
714                 /*                                                           */
715              }
716              else
717              {
718                 strcpy (ligne, "allocate ");
719                 strcat (ligne, "(");
720                 strcat (ligne, vargridnametabvars(v,0));
721                 strcat (ligne, vargridparam(v,0));
722                 strcat (ligne, ")");
723                 tofich (allocationagrif, ligne,1);
724                 /*                                                           */
725                 parcoursindic =  (listindice *)malloc(sizeof(listindice));
726                 parcoursindic -> i_indice = parcours->var->v_indicetabvars;
727                 parcoursindic -> suiv = list_indic;
728                 list_indic = parcoursindic;
729              }
730                neededparameter = writedeclarationintoamr(List_Parameter_Var,
731                              paramtoamr,v,parcours_nom->o_nom,neededparameter,
732                                                               v->v_commonname);
733              /*                                                              */
734           }
735        } /* end of the allocation part                                       */
736        /*                INITIALISATION                                      */
737        if ( strcasecmp(v->v_initialvalue,"") )
738        {
739           strcpy (ligne, "");
740           strcat (ligne, vargridnametabvars(v,0));
741           /* We should modify the initialvalue in the case of variable has   */
742           /*    been defined with others variables                           */
743           strcpy(initialvalue,
744                  ChangeTheInitalvaluebyTabvarsName
745                                      (v->v_initialvalue,List_Global_Var,0));
746           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
747           {
748              strcpy(initialvalue,"");
749              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
750                                      (v->v_initialvalue,List_Common_Var,0));
751           }
752           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
753           {
754              strcpy(initialvalue,"");
755              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
756                                     (v->v_initialvalue,List_ModuleUsed_Var,0));
757           }
758           strcat (ligne," = ");
759           strcat (ligne,initialvalue);
760           /*                                                                 */
761           tofich (allocationagrif, ligne,1);
762        }
763     }
764     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
765     {
766        strcpy (ligne, "   End if");
767        tofich (allocationagrif, ligne,1);
768     }
769  }
770               /***************************************************************/
771               /***************************************************************/
772               /***************************************************************/
773            }
774            parcours = parcours -> suiv;
775         }
776         /* Close the file Alloc_agrif                                        */
777         fclose(allocationagrif);
778         fclose(paramtoamr);
779      }
780      /*                                                                      */
781      parcours_nom = parcours_nom -> suiv;
782   }
783
784}
785
786
787
788void write_allocation_Global_0()
789{
790   listnom *parcours_nom;
791   listvar *parcours;
792   listvar *parcoursprec;
793   listvar *parcours1;
794   FILE *allocationagrif;
795   char ligne[LONGNOM];
796   variable *v;
797   int IndiceMax;
798   int IndiceMin;
799   int compteur;
800   int out;
801   int indiceprec;
802   int ValeurMax;
803   char initialvalue[LONGNOM];
804
805   parcours_nom = List_NameOfModule;
806   ValeurMax = 2;
807   while ( parcours_nom  )
808   {
809      /*                                                                      */
810      if ( parcours_nom->o_val == 1 )
811      {
812         IndiceMax = 0;
813         IndiceMin = indicemaxtabvars;
814         /* Open the file to create the Alloc_agrif subroutine                */
815         sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
816         allocationagrif = associate (ligne);
817         /*                                                                   */
818         if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
819         {
820             /* add the call to initworkspace                                 */
821            tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
822            fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
823            tofich(allocationagrif,"else ",1);
824            fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
825            tofich(allocationagrif,"endif ",1);
826            tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
827         }
828
829         parcours = List_Global_Var;
830         while ( parcours )
831         {
832            if ( !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom) &&
833                 parcours->var->v_VariableIsParameter == 0                  &&
834                 parcours->var->v_notgrid == 0                              &&
835                 !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom)  )
836            {
837               /***************************************************************/
838               /***************************************************************/
839               /***************************************************************/
840               v = parcours->var;
841               IndiceMax = 0;
842               IndiceMin = indicemaxtabvars;
843  /* body of the file                                                         */
844  if ( !strcasecmp(v->v_commoninfile,mainfile) )
845  {
846     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
847     {
848        strcpy (ligne, "If (.not. associated(");
849        strcat (ligne, vargridnametabvars(v,0));
850        strcat (ligne, "))                       then");
851        tofich (allocationagrif, ligne,1);
852     }
853     if ( v->v_allocatable != 1 && ( v->v_dimsempty != 1) )
854     {
855        /*                ALLOCATION                                          */
856        if ( v->v_dimension != 0  )
857        {
858           if ( v->v_indicetabvars < IndiceMin ||
859                v->v_indicetabvars > IndiceMax )
860           {
861              parcours1 = parcours;
862              compteur = -1;
863              out = 0;
864              indiceprec = parcours->var->v_indicetabvars -1 ;
865              while ( parcours1 && out == 0 &&
866                      !strcasecmp(  parcours->var->v_readedlistdimension,
867                                  parcours1->var->v_readedlistdimension) &&
868                      !strcasecmp(  parcours->var->v_typevar,
869                                  parcours1->var->v_typevar) &&
870                             ( parcours1->var->v_indicetabvars == indiceprec+1 )
871                     )
872              {
873
874               if ( !strcasecmp(parcours1->var->v_modulename,
875                                parcours_nom->o_nom) ||
876                    !strcasecmp(parcours1->var->v_commonname,
877                                parcours_nom->o_nom) )
878                 {
879                      compteur = compteur +1 ;
880                      indiceprec = parcours1->var->v_indicetabvars;
881                      parcoursprec = parcours1;
882                      parcours1 = parcours1->suiv;
883                 }
884                 else out = 1;
885              }
886              if ( compteur > ValeurMax )
887              {
888                 fprintf(allocationagrif,"      DO i = %d , %d\n",
889                                          parcours->var->v_indicetabvars,
890                                       parcours->var->v_indicetabvars+compteur);
891                 IndiceMin = parcours->var->v_indicetabvars;
892                 IndiceMax = parcours->var->v_indicetabvars+compteur;
893                 strcpy (ligne, "allocate ");
894                 strcat (ligne, "(");
895                 strcat (ligne, vargridnametabvars(v,1));
896                 strcat (ligne, vargridparam(v,0));
897                 strcat (ligne, ")");
898                 tofich (allocationagrif, ligne,1);
899                 fprintf(allocationagrif,"      end do\n");
900                 parcours = parcoursprec;
901              }
902              else
903              {
904                 strcpy (ligne, "allocate ");
905                 strcat (ligne, "(");
906                 strcat (ligne, vargridnametabvars(v,0));
907                 strcat (ligne, vargridparam(v,0));
908                 strcat (ligne, ")");
909                 tofich (allocationagrif, ligne,1);
910              }
911           }
912        } /* end of the allocation part                                       */
913        /*                INITIALISATION                                      */
914        if ( strcasecmp(v->v_initialvalue,"") )
915        {
916           strcpy (ligne, "");
917           strcat (ligne, vargridnametabvars(v,0));
918           /* We should modify the initialvalue in the case of variable has   */
919           /*    been defined with others variables                           */
920           strcpy(initialvalue,
921                  ChangeTheInitalvaluebyTabvarsName
922                                      (v->v_initialvalue,List_Global_Var,0));
923           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
924           {
925              strcpy(initialvalue,"");
926              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
927                                      (v->v_initialvalue,List_Common_Var,0));
928           }
929           if ( !strcasecmp(initialvalue,v->v_initialvalue) )
930           {
931              strcpy(initialvalue,"");
932              strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName
933                                     (v->v_initialvalue,List_ModuleUsed_Var,0));
934           }
935           strcat (ligne," = ");
936           strcat (ligne,initialvalue);
937           /*                                                                 */
938           tofich (allocationagrif, ligne,1);
939        }
940     }
941     if (onlyfixedgrids != 1 && v->v_nbdim!=0)
942     {
943        strcpy (ligne, "   End if");
944        tofich (allocationagrif, ligne,1);
945     }
946  }
947               /***************************************************************/
948               /***************************************************************/
949               /***************************************************************/
950            }
951            parcours = parcours -> suiv;
952         }
953         /*                                                                   */
954         if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
955         {
956            /* add the call to initworkspace                                  */
957            tofich(allocationagrif,"if ( .NOT. Agrif_Root() ) then ",1);
958            fprintf(allocationagrif,"#include \"GetNumberofcells.h\" \n");
959            tofich(allocationagrif,"else ",1);
960            fprintf(allocationagrif,"#include \"SetNumberofcells.h\" \n");
961            tofich(allocationagrif,"endif ",1);
962            tofich(allocationagrif,"Call Agrif_InitWorkspace ",1);
963         }
964         /* Close the file Alloc_agrif                                        */
965         fclose(allocationagrif);
966      } /* end parcours_nom == 1                                              */
967      /*                                                                      */
968      parcours_nom = parcours_nom -> suiv;
969   }
970}
971
972/******************************************************************************/
973/*                           creefichieramr                                   */
974/******************************************************************************/
975/* This subroutine is the main one to create AGRIF_INC files                  */
976/******************************************************************************/
977/*                                                                            */
978/******************************************************************************/
979void creefichieramr (char *NameTampon)
980{
981  listvar *newvar;
982  variable *v;
983  int erreur;
984  char filefich[LONGNOM];
985  char ligne[LONGNOM];
986  char ligne1[LONGNOM];
987  int IndiceMax;
988  int IndiceMin;
989  int InitEmpty;
990  int VarnameEmpty;
991  int donotwrite;
992
993  FILE *initproc;
994  FILE *initglobal;
995  FILE *createvarname;
996  FILE *createvarnameglobal;
997  FILE *modulealloc;
998  FILE *dependfileoutput;
999
1000  if ( todebug == 1 ) printf("Enter in creefichieramr\n");
1001  strcpy (filefich, "cd ");
1002  strcat (filefich, nomdir);
1003  erreur = system (filefich);
1004  if (erreur)
1005  {
1006     strcpy (filefich, "mkdir ");
1007     strcat (filefich, nomdir);
1008     system (filefich);
1009     printf ("%s: Directory created\n", nomdir);
1010  }
1011
1012/******************************************************************************/
1013/******************** Creation of AGRIF_INC files *****************************/
1014/******************************************************************************/
1015
1016/*----------------------------------------------------------------------------*/
1017  if ( todebug == 1 )
1018  {
1019     strcpy(ligne,"initialisations_agrif_");
1020     strcat(ligne,NameTampon);
1021     strcat(ligne,".h");
1022     initproc = associate (ligne);
1023/*----------------------------------------------------------------------------*/
1024     strcpy(ligne,"createvarname_agrif_");
1025     strcat(ligne,NameTampon);
1026     strcat(ligne,".h");
1027     createvarname = associate (ligne);
1028/*----------------------------------------------------------------------------*/
1029     InitEmpty = 1 ;
1030     VarnameEmpty = 1 ;
1031
1032     newvar = List_Global_Var;
1033     while ( newvar && todebug == 1 )
1034     {
1035        donotwrite = 0;
1036        v = newvar->var;
1037
1038        if ( ( v->v_common == 1 || v->v_module == 1 ) && donotwrite == 0 )
1039        {
1040          write_createvarnameagrif_file(v,createvarname,&VarnameEmpty);
1041          write_initialisationsagrif_file(v,initproc,&InitEmpty);
1042        }
1043        newvar = newvar->suiv;
1044     }
1045  /*                                                                          */
1046     fclose (createvarname);
1047     fclose (initproc);
1048  /*--------------------------------------------------------------------------*/
1049     if ( Did_filetoparse_readed(curmodulename) == 0 )
1050     {
1051        if ( InitEmpty != 1  )
1052        {
1053           initglobal = associateaplus("initialisations_agrif.h");
1054           strcpy(ligne,"#include \"initialisations_agrif_");
1055           strcat(ligne,NameTampon);
1056           strcat(ligne,".h\"\n");
1057           fprintf(initglobal,ligne);
1058           fclose(initglobal);
1059        }
1060  /*--------------------------------------------------------------------------*/
1061        if ( VarnameEmpty != 1 )
1062        {
1063           createvarnameglobal= associateaplus("createvarname_agrif.h");
1064           strcpy(ligne,"#include \"createvarname_agrif_");
1065           strcat(ligne,NameTampon);
1066           strcat(ligne,".h\"\n");
1067           fprintf(createvarnameglobal,ligne);
1068           fclose(createvarnameglobal);
1069        }
1070     }
1071  }
1072/*----------------------------------------------------------------------------*/
1073/*----------------------------------------------------------------------------*/
1074/*----------------------------------------------------------------------------*/
1075/*----------------------------------------------------------------------------*/
1076/*----------------------------------------------------------------------------*/
1077  IndiceMax = 0;
1078  IndiceMin = 0;
1079
1080  write_allocation_Common_0();
1081  write_allocation_Global_0();
1082
1083  Write_Alloc_Agrif_Files();
1084  write_probdimagrif_file();
1085  write_keysagrif_file();
1086  write_modtypeagrif_file();
1087  write_Setnumberofcells_file();
1088  write_Getnumberofcells_file();
1089  if ( todebug == 1 ) printf("Out of creefichieramr\n");
1090}
Note: See TracBrowser for help on using the repository browser.