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.
dependfile.c in vendors/AGRIF/release-4.0.1/LIB – NEMO

source: vendors/AGRIF/release-4.0.1/LIB/dependfile.c @ 13680

Last change on this file since 13680 was 5656, checked in by timgraham, 9 years ago

Merge of AGRIF branch (branches/2014/dev_r4765_CNRS_agrif) onto the trunk

  • Property svn:keywords set to Id
File size: 42.7 KB
Line 
1/******************************************************************************/
2/*                                                                            */
3/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
4/*                                                                            */
5/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
6/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
7/* This software is governed by the CeCILL-C license under French law and     */
8/* abiding by the rules of distribution of free software.  You can  use,      */
9/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
10/* license as circulated by CEA, CNRS and INRIA at the following URL          */
11/* "http://www.cecill.info".                                                  */
12/*                                                                            */
13/* As a counterpart to the access to the source code and  rights to copy,     */
14/* modify and redistribute granted by the license, users are provided only    */
15/* with a limited warranty  and the software's author,  the holder of the     */
16/* economic rights,  and the successive licensors  have only  limited         */
17/* liability.                                                                 */
18/*                                                                            */
19/* In this respect, the user's attention is drawn to the risks associated     */
20/* with loading,  using,  modifying and/or developing or reproducing the      */
21/* software by the user in light of its specific status of free software,     */
22/* that may mean  that it is complicated to manipulate,  and  that  also      */
23/* therefore means  that it is reserved for developers  and  experienced      */
24/* professionals having in-depth computer knowledge. Users are therefore      */
25/* encouraged to load and test the software's suitability as regards their    */
26/* requirements in conditions enabling the security of their systems and/or   */
27/* data to be ensured and,  more generally, to use and operate it in the      */
28/* same conditions as regards security.                                       */
29/*                                                                            */
30/* The fact that you are presently reading this means that you have had       */
31/* knowledge of the CeCILL-C license and that you accept its terms.           */
32/******************************************************************************/
33/* version 1.7                                                                */
34/******************************************************************************/
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include "decl.h"
39
40
41/******************************************************************************/
42/*            Creation and modification of .dependfile                        */
43/******************************************************************************/
44/*  .dependnbxnby            : this file contains tabvars indices of variables*/
45/*                                given in agrif.in as number of cells        */
46/*  .dependuse<module>       : this file contains all modules used in the     */
47/*                                current file                                */
48/*  .dependparameter<module> : this file contains all parmeters defined in    */
49/*                                the current file                            */
50/*  .depend<module name>     : this file contains all globals variables       */
51/*                                informations (name, dim, etc ...)           */
52/*  .dependavailable         : this file contains all tabvars indices which   */
53/*                                are not used.                               */
54/******************************************************************************/
55
56
57/******************************************************************************/
58/*                 Writethedependnbxnbyfile                                   */
59/******************************************************************************/
60/* This subroutine is used to create the .dependnbxnby                        */
61/******************************************************************************/
62/*                                                                            */
63/*                     .dependnbxnby                                          */
64/*                                                                            */
65/*                     nbmaillesX                                             */
66/*                     nbmaillesY                                             */
67/*                     nbmaillesZ                                             */
68/*                                                                            */
69/******************************************************************************/
70void Writethedependnbxnbyfile()
71{
72  FILE *dependfileoutput;
73  listvar *parcours;
74  int out;
75
76  // We look in 'List_Global_Var' for all the variables of the current file to parse
77  parcours = List_Global_Var;
78  out = 0;
79  while (parcours && out == 0 )
80  {
81     if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesX) ) out = 1;
82     else parcours = parcours->suiv;
83  }
84  if ( out == 0 )
85  {
86     parcours =List_Common_Var;
87     while (parcours && out == 0 )
88     {
89        if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesX) ) out = 1;
90        else parcours = parcours->suiv;
91     }
92  }
93  NbMailleXDefined = 0;
94  if ( out == 1 )
95  {
96     NbMailleXDefined = 1;
97     sprintf(dependfilename, "%s/.dependnbxnby", work_dir);
98     dependfileoutput = fopen(dependfilename, "w");
99
100     fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
101     IndicenbmaillesX = parcours->var->v_indicetabvars;
102
103     if ( dimprob > 1 )
104     {
105        parcours =List_Global_Var;
106        out = 0;
107        while (parcours && out == 0 )
108        {
109           if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesY) ) out = 1;
110           else parcours = parcours->suiv;
111        }
112        if ( out == 0 )
113        {
114           parcours =List_Common_Var;
115           while (parcours && out == 0 )
116           {
117              if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesY) ) out = 1;
118              else parcours = parcours->suiv;
119           }
120        }
121        if ( out == 1 )
122        {
123           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
124           IndicenbmaillesY = parcours->var->v_indicetabvars;
125        }
126     }
127
128     if ( dimprob > 2 )
129     {
130        parcours =List_Global_Var;
131        out = 0;
132        while (parcours && out == 0 )
133        {
134           if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesZ) ) out = 1;
135           else parcours = parcours->suiv;
136        }
137        if ( out == 0 )
138        {
139           parcours =List_Common_Var;
140           while (parcours && out == 0 )
141           {
142              if ( !strcasecmp(parcours->var->v_nomvar,nbmaillesZ) ) out = 1;
143              else parcours = parcours->suiv;
144           }
145        }
146        if ( out == 1 )
147        {
148           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
149           IndicenbmaillesZ = parcours->var->v_indicetabvars;
150        }
151     }
152
153     if ( out == 1 ) fclose(dependfileoutput);
154   }
155}
156
157/******************************************************************************/
158/*                 Readthedependnbxnbyfile                                    */
159/******************************************************************************/
160/* This subroutine is used to create the .dependnbxnby                        */
161/******************************************************************************/
162/*                                                                            */
163/*                     .dependnbxnby                                          */
164/*                                                                            */
165/*                     nbmaillesX                                             */
166/*                     nbmaillesY                                             */
167/*                     nbmaillesZ                                             */
168/*                                                                            */
169/******************************************************************************/
170void Readthedependnbxnbyfile()
171{
172    FILE *dependfileoutput;
173
174    sprintf(dependfilename, "%s/.dependnbxnby", work_dir);
175    if ((dependfileoutput = fopen(dependfilename, "r"))!=NULL)
176    {
177        fscanf(dependfileoutput,"%d\n",&IndicenbmaillesX);
178        if ( dimprob > 1 ) fscanf(dependfileoutput,"%d\n",&IndicenbmaillesY);
179        if ( dimprob > 2 ) fscanf(dependfileoutput,"%d\n",&IndicenbmaillesZ);
180        fclose(dependfileoutput);
181    }
182}
183
184/******************************************************************************/
185/*                     Writethedependlistofmoduleused                         */
186/******************************************************************************/
187/* This subroutine is used to create the .dependuse<module>                   */
188/******************************************************************************/
189/*                                                                            */
190/*               .dependuse<name>                                             */
191/*                                                                            */
192/*               mod1                                                         */
193/*               mod2                                                         */
194/*                                                                            */
195/******************************************************************************/
196void Writethedependlistofmoduleused(const char *NameTampon )
197{
198    FILE *dependfileoutput;
199    listusemodule *parcours;
200    char lowername[LONG_VNAME];
201
202    if ( ! List_NameOfModuleUsed ) return;
203
204    convert2lower(lowername, NameTampon);
205    sprintf(dependfilename, "%s/.depend_use%s", work_dir, lowername);
206    dependfileoutput = fopen(dependfilename, "w");
207
208    parcours = List_NameOfModuleUsed;
209    while (parcours)
210    {
211    if ( !strcasecmp(lowername,parcours->u_modulename) &&
212         !strcasecmp(parcours->u_cursubroutine,"") )
213    {
214        // We look in 'List_NameOfModuleUsed' for all the variables of the current file to parse
215        fprintf(dependfileoutput,"%s\n",parcours->u_usemodule);
216    }
217    parcours = parcours->suiv;
218    }
219    fclose(dependfileoutput);
220}
221
222/******************************************************************************/
223/*                    Readthedependlistofmoduleused                           */
224/******************************************************************************/
225/* This subroutine is used to create the .dependuse<module>                   */
226/******************************************************************************/
227/*                                                                            */
228/*               .dependuse<name>                                             */
229/*                                                                            */
230/*               mod1                                                         */
231/*               mod2                                                         */
232/*                                                                            */
233/******************************************************************************/
234void Readthedependlistofmoduleused(const char *NameTampon)
235{
236  FILE *dependfileoutput;
237  listusemodule *parcours;
238  char lowername[LONG_VNAME];
239
240  tmpuselocallist = (listusemodule *)NULL;
241
242  convert2lower(lowername, NameTampon);
243  sprintf(dependfilename, "%s/.depend_use%s", work_dir, lowername);
244
245  if ((dependfileoutput = fopen(dependfilename, "r"))!=NULL)
246  {
247    /* if the file exist we should verify that this file has changed          */
248      while (!feof(dependfileoutput))
249      {
250         parcours=(listusemodule *)calloc(1,sizeof(listusemodule));
251         fscanf(dependfileoutput,"%s\n",parcours->u_usemodule);
252
253         parcours->suiv = tmpuselocallist;
254         tmpuselocallist = parcours;
255
256         parcours = NULL;
257      }
258      fclose(dependfileoutput);
259  }
260}
261
262
263/******************************************************************************/
264/*                        WritedependParameterList                            */
265/******************************************************************************/
266/* This subroutine is used to create the .dependparameter<name>               */
267/******************************************************************************/
268/*                                                                            */
269/*               .dependparameter<name>                                       */
270/*                                                                            */
271/*               mod1                                                         */
272/*               mod2                                                         */
273/*                                                                            */
274/******************************************************************************/
275void WritedependParameterList(const char *NameTampon )
276{
277  FILE *dependfileoutput;
278  listvar *parcours;
279  char lowername[LONG_VNAME];
280
281  if ( List_GlobalParameter_Var )
282  {
283     convert2lower(lowername, NameTampon);
284     sprintf(dependfilename, "%s/.depend_paramater_%s", work_dir, lowername);
285
286     dependfileoutput = fopen(dependfilename, "w");
287     parcours = List_GlobalParameter_Var;
288     while (parcours)
289     {
290        if ( !strcasecmp(lowername, parcours->var->v_modulename) )
291        {
292           fprintf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
293           fprintf(dependfileoutput,"%s\n",parcours->var->v_modulename);
294        }
295        parcours = parcours->suiv;
296     }
297     fclose(dependfileoutput);
298  }
299}
300
301
302/******************************************************************************/
303/*                         ReaddependParameterList                            */
304/******************************************************************************/
305/* This subroutine is used to create the .dependparameter<name>               */
306/******************************************************************************/
307/*                                                                            */
308/*               .dependparameter<name>                                       */
309/*                                                                            */
310/*               mod1                                                         */
311/*               mod2                                                         */
312/*                                                                            */
313/******************************************************************************/
314listparameter *ReaddependParameterList(const char *NameTampon,listparameter *listout)
315{
316  FILE *dependfileoutput;
317  listparameter *parcours;
318  char lowername[LONG_VNAME];
319
320  convert2lower(lowername, NameTampon);
321  sprintf(dependfilename, "%s/.depend_paramater_%s", work_dir, lowername);
322
323  if ((dependfileoutput = fopen(dependfilename,"r"))!=NULL)
324  {
325    /* if the file exist we should verify that this file has changed          */
326      while (!feof(dependfileoutput))
327      {
328         parcours=(listparameter *)calloc(1,sizeof(listparameter));
329         fscanf(dependfileoutput,"%s\n",parcours->p_name);
330         fscanf(dependfileoutput,"%s\n",parcours->p_modulename);
331
332         parcours->suiv = listout;
333         listout = parcours;
334
335         parcours = NULL;
336      }
337      fclose(dependfileoutput);
338  }
339  return listout;
340}
341
342/******************************************************************************/
343/*                   Writethedependfile                                       */
344/******************************************************************************/
345/* This subroutine is used to create the .depend<name>                        */
346/******************************************************************************/
347/*                                                                            */
348/*                     .depend<name>                                          */
349/*                                                                            */
350/*                      REAL                                                  */
351/*                      Variable                                              */
352/*                      char dimension or T                                   */
353/*                      table dimension                                       */
354/*                      is type given                                         */
355/*                      precision or T                                        */
356/*                      initial value or T                                    */
357/*                      indice in the tabvars                                 */
358/*                      listdimension or T                                    */
359/*                      -------------------------                             */
360/*                                                                            */
361/******************************************************************************/
362void Writethedependfile(const char *NameTampon, listvar *input )
363{
364  FILE *dependfileoutput;
365  listvar *parcours;
366  listdim *dims;
367  char ligne[LONG_M];
368  char listdimension[LONG_M];
369  char curname[LONG_M];
370  char lowername[LONG_VNAME];
371  int out;
372
373  if ( input )
374  {
375    convert2lower(lowername, NameTampon);
376    sprintf(dependfilename, "%s/.depend_%s", work_dir, lowername);
377
378  dependfileoutput = fopen(dependfilename,"w");
379  // We look in 'input' for all the variables of the current file to parse
380  parcours =input;
381  out = 0;
382  strcpy(curname,"");
383  while (parcours && out == 0 )
384  {
385     if ( !strcasecmp(parcours->var->v_modulename, lowername) ||
386          !strcasecmp(parcours->var->v_commonname, lowername) )
387     {
388        /*                                                                    */
389        if (  strcasecmp(curname,"") &&
390             !strcasecmp(curname,parcours->var->v_nomvar) ) out = 1 ;
391        if ( !strcasecmp(curname,"") ) strcpy(curname,parcours->var->v_nomvar);
392        /*                                                                    */
393        if ( out == 0 )
394        {
395           /********** TYPEVAR ************************************************/
396           fprintf(dependfileoutput,"%s\n",parcours->var->v_typevar);
397           /********** CATVAR ************************************************/
398           fprintf(dependfileoutput,"%d\n",parcours->var->v_catvar);
399           /********** NOMVAR *************************************************/
400           fprintf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
401           /********** DIMCHAR ************************************************/
402           if ( strcasecmp(parcours->var->v_dimchar, "") )
403           {
404              fprintf(dependfileoutput,"%s\n",parcours->var->v_dimchar);
405           }
406           else
407           {
408              fprintf(dependfileoutput,"T\n");
409           }
410           /********** COMMONINFILE *******************************************/
411           if ( strcasecmp(parcours->var->v_commoninfile,"") )
412           {
413              fprintf(dependfileoutput,"%s\n",parcours->var->v_commoninfile);
414           }
415           else
416           {
417              fprintf(dependfileoutput,"T\n");
418           }
419           /********** COMMONNAME *********************************************/
420           if ( strcasecmp(parcours->var->v_commonname,"") )
421           {
422              fprintf(dependfileoutput,"%s\n",parcours->var->v_commonname);
423           }
424           else
425           {
426              fprintf(dependfileoutput,"T\n");
427           }
428           /********** MODULENAME *********************************************/
429           if ( strcasecmp(parcours->var->v_modulename,"") )
430           {
431              fprintf(dependfileoutput,"%s\n",parcours->var->v_modulename);
432           }
433           else
434           {
435              fprintf(dependfileoutput,"T\n");
436           }
437           /********** NBDIM **************************************************/
438/*           fprintf(dependfileoutput,"%d\n",parcours->var->v_nbdim);*/
439           /********** DIMENSIONGIVEN *****************************************/
440/*           fprintf(dependfileoutput,"%d\n",parcours->var->v_dimensiongiven);*/
441           /********** ALLOCATABLE ********************************************/
442           fprintf(dependfileoutput,"%d\n",parcours->var->v_allocatable);
443           /********** TARGET ********************************************/
444           fprintf(dependfileoutput,"%d\n",parcours->var->v_target);
445           /********** POINTERDECLARE *****************************************/
446           fprintf(dependfileoutput,"%d\n",parcours->var->v_pointerdeclare);
447           /********** PRECISION **********************************************/
448           if ( strcasecmp(parcours->var->v_precision,"") )
449           {
450              fprintf(dependfileoutput,"%s\n",parcours->var->v_precision);
451           }
452           else
453           {
454              fprintf(dependfileoutput,"T\n");
455           }
456           /********** INITIALVALUE *******************************************/
457/*           if ( strcasecmp(parcours->var->v_initialvalue,"") )
458           {
459              fprintf(dependfileoutput,"%s\n",parcours->var->v_initialvalue);
460           }
461           else
462           {
463              fprintf(dependfileoutput,"T\n");
464           }*/
465           /********** NAMEINTYPENAME *****************************************/
466           if ( strcasecmp(parcours->var->v_nameinttypename,"") )
467           {
468              fprintf(dependfileoutput,"%s\n",parcours->var->v_nameinttypename);
469           }
470           else
471           {
472              fprintf(dependfileoutput,"T\n");
473           }
474           /********** PRIVATE *****************************************/
475           fprintf(dependfileoutput,"%d\n",parcours->var->v_PrivateDeclare);
476
477           /********** INDICETABVARS ******************************************/
478           fprintf(dependfileoutput,"%d\n",parcours->var->v_indicetabvars);
479           /********** READEDLISTDIMENSION ************************************/
480           if ( parcours->var->v_dimensiongiven == 1 )
481           {
482              dims = parcours->var->v_dimension;
483              strcpy(listdimension,"");
484              while (dims)
485              {
486                 sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
487                 strcat(listdimension,ligne);
488                 if ( dims->suiv )
489                 {
490                    strcat(listdimension,",");
491                 }
492                 dims = dims->suiv;
493              }
494              Save_Length(listdimension,15);
495              fprintf(dependfileoutput,"%s\n",listdimension);
496           }
497           else
498           {
499              fprintf(dependfileoutput,"T\n");
500           }
501           /*******************************************************************/
502           fprintf(dependfileoutput,"------------------------\n");
503        }
504     }
505     parcours = parcours->suiv;
506  }
507  fclose(dependfileoutput);
508  }
509}
510
511/******************************************************************************/
512/*                         Readthedependfile                                  */
513/******************************************************************************/
514/* This subroutine is used to read the .dependfile<name> and to insert new    */
515/*    information in the listout list.                                        */
516/******************************************************************************/
517/*                                                                            */
518/*           .dependmodule -------->                      = list of var       */
519/*                                                                            */
520/*        not.dependmodule -------->                                          */
521/*                                                                            */
522/******************************************************************************/
523listvar *Readthedependfile(const char *NameTampon , listvar *listout)
524{
525  FILE *dependfileoutput;
526  listvar *parcours0;
527  listvar *parcours;
528  listvar *parcoursprec;
529  char nothing[LONG_M];
530  char lowername[LONG_VNAME];
531  size_t i;
532
533  parcoursprec = (listvar *)NULL;
534
535  convert2lower(lowername, NameTampon);
536  sprintf(dependfilename, "%s/.depend_%s", work_dir, lowername);
537
538  if ((dependfileoutput = fopen(dependfilename, "r"))==NULL)
539  {
540    /* if the file doesn't exist it means that it is the first time           */
541    /*    we tried to parse this file                                         */
542  }
543  else
544  {
545    /* if the file exist we should verify that this file has changed          */
546      while (!feof(dependfileoutput))
547      {
548         parcours=(listvar *)calloc(1,sizeof(listvar));
549         parcours->var=(variable *)calloc(1,sizeof(variable));
550         /*                                                                   */
551         Init_Variable(parcours->var);
552         /*                                                                   */
553           /********** TYPEVAR ************************************************/
554         fscanf(dependfileoutput,"%s\n",parcours->var->v_typevar);
555           /********** CATVAR ************************************************/
556         fscanf(dependfileoutput,"%d\n",&parcours->var->v_catvar);
557           /********** NOMVAR *************************************************/
558         fscanf(dependfileoutput,"%s\n",parcours->var->v_nomvar);
559           /********** DIMCHAR ************************************************/
560         fscanf(dependfileoutput,"%s\n",parcours->var->v_dimchar);
561         if ( !strcasecmp(parcours->var->v_dimchar,"T") )
562         {
563            strcpy(parcours->var->v_dimchar,"");
564         }
565           /********** COMMONINFILE *******************************************/
566         fscanf(dependfileoutput,"%s\n",parcours->var->v_commoninfile);
567         if ( !strcasecmp(parcours->var->v_commoninfile,"T") )
568         {
569            strcpy(parcours->var->v_commoninfile,"");
570         }
571           /********** COMMONNAME *********************************************/
572         fscanf(dependfileoutput,"%s\n",parcours->var->v_commonname);
573         if ( !strcasecmp(parcours->var->v_commonname,"T") )
574         {
575            strcpy(parcours->var->v_commonname,"");
576         }
577           /********** MODULENAME *********************************************/
578         fscanf(dependfileoutput,"%s\n",parcours->var->v_modulename);
579
580         if ( !strcasecmp(parcours->var->v_modulename,"T") )
581         {
582            strcpy(parcours->var->v_modulename,"");
583         }
584
585
586           /********** NBDIM **************************************************/
587/*         fscanf(dependfileoutput,"%d\n",&parcours->var->v_nbdim);*/
588           /********** DIMENSIONGIVEN *****************************************/
589/*         fscanf(dependfileoutput,"%d\n",&parcours->var->v_dimensiongiven);*/
590           /********** ALLOCATABLE ********************************************/
591         fscanf(dependfileoutput,"%d\n",&parcours->var->v_allocatable);
592         if ( parcours->var->v_allocatable == 1 )
593         {
594            Add_Allocate_Var_1(parcours->var->v_nomvar, parcours->var->v_commonname);
595         }
596           /********** TARGET ********************************************/
597         fscanf(dependfileoutput,"%d\n",&parcours->var->v_target);
598
599           /********** POINTERDECLARE *****************************************/
600         fscanf(dependfileoutput,"%d\n",&parcours->var->v_pointerdeclare);
601         if ( parcours->var->v_pointerdeclare == 1 )
602         {
603            Add_Pointer_Var_1(parcours->var->v_nomvar);
604         }
605           /********** PRECISION **********************************************/
606         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_precision);
607         if ( !strcasecmp(parcours->var->v_precision,"T") )
608         {
609            strcpy(parcours->var->v_precision,"");
610         }
611           /********** INITIALVALUE *******************************************/
612/*         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_initialvalue);
613         if ( !strcasecmp(parcours->var->v_initialvalue,"T") )
614         {
615            strcpy(parcours->var->v_initialvalue,"");
616         }*/
617           /********** NAMEINTYPENAME *****************************************/
618         fscanf(dependfileoutput,"%[^\n] \n",parcours->var->v_nameinttypename);
619         if ( !strcasecmp(parcours->var->v_nameinttypename,"T") )
620         {
621            strcpy(parcours->var->v_nameinttypename,"");
622         }
623           /********** PRIVATE *****************************************/
624         fscanf(dependfileoutput,"%d\n",&parcours->var->v_PrivateDeclare);
625
626           /********** INDICETABVARS ******************************************/
627         fscanf(dependfileoutput,"%d\n",&parcours->var->v_indicetabvars);
628           /********** READEDLISTDIMENSION ************************************/
629         fscanf(dependfileoutput,"%s\n",parcours->var->v_readedlistdimension);
630         if ( !strcasecmp(parcours->var->v_readedlistdimension,"T") )
631         {
632            strcpy(parcours->var->v_readedlistdimension,"");
633         }
634         else
635         {
636            parcours->var->v_dimensiongiven = 1;
637            parcours->var->v_nbdim = 1;
638            i = 1;
639            /*                                                                */
640            while ( i < strlen(parcours->var->v_readedlistdimension) )
641            {
642               if ( parcours->var->v_readedlistdimension[i] == ',' )
643               {
644                  parcours->var->v_nbdim = parcours->var->v_nbdim + 1 ;
645               }
646               /*                                                             */
647               i=i+1;
648            }
649         }
650           /*******************************************************************/
651         fscanf(dependfileoutput,"%s\n",nothing);
652         parcours->suiv = NULL;
653         if (parcours->var->v_PrivateDeclare == 0)
654         {
655         if ( !listout )
656         {
657            listout = parcours;
658            parcoursprec = parcours;
659         }
660         else
661         {
662            if ( parcoursprec )
663            {
664               parcoursprec->suiv = parcours;
665               parcoursprec = parcours;
666            }
667            else
668            {
669               parcours0 = listout;
670               while ( parcours0->suiv ) parcours0=parcours0->suiv;
671               parcours0->suiv = parcours;
672               parcoursprec = parcours0->suiv;
673            }
674         }
675         }
676         parcours = NULL;
677      }
678      fclose(dependfileoutput);
679  }
680  return listout;
681}
682
683void Write_Subroutine_For_Alloc()
684{
685   FILE *dependfileoutput;
686   listnom *parcours;
687
688   if ( List_Subroutine_For_Alloc )
689   {
690      sprintf(dependfilename, "%s/.dependAllocAgrif", work_dir);
691
692      if ((dependfileoutput=fopen(dependfilename, "w"))!=NULL)
693      {
694         parcours = List_Subroutine_For_Alloc;
695         while (parcours)
696         {
697            fprintf(dependfileoutput,"%s\n",parcours->o_nom);
698            parcours = parcours->suiv;
699         }
700         fclose(dependfileoutput);
701      }
702   }
703}
704
705void Read_Subroutine_For_Alloc()
706{
707    FILE *dependfileoutput;
708    listnom *parcours;
709    listnom *ref;
710
711    ref = (listnom*) NULL;
712    sprintf(dependfilename, "%s/.dependAllocAgrif", work_dir);
713
714    if ( (dependfileoutput=fopen(dependfilename, "r")) != NULL )
715    {
716        List_Subroutine_For_Alloc = (listnom*) NULL;
717        while ( !feof(dependfileoutput) )
718        {
719            parcours = (listnom*) calloc(1,sizeof(listnom));
720            strcpy(parcours->o_nom,"");
721
722            fscanf(dependfileoutput,"%s\n",parcours->o_nom);
723            parcours->suiv = NULL;
724
725            if ( !List_Subroutine_For_Alloc )
726            {
727                List_Subroutine_For_Alloc = parcours;
728            }
729            else
730            {
731                ref->suiv = parcours;
732            }
733            ref = parcours;
734        }
735        fclose(dependfileoutput);
736    }
737}
738
739/******************************************************************************/
740/*                        Writethedependavailablefile                         */
741/******************************************************************************/
742/* This subroutine is used to write the .dependfileavailable file             */
743/******************************************************************************/
744/*                                                                            */
745/*                                  .dependavailable                          */
746/*     tabvars(1) = var1                                                      */
747/*     tabvars(3) = var1                  2                                   */
748/*     tabvars(4) = var1         =====>   5                                   */
749/*     tabvars(6) = var1                                                      */
750/*     tabvars(7) = var1                                                      */
751/*                                                                            */
752/*                                                                            */
753/*                                                                            */
754/******************************************************************************/
755void Writethedependavailablefile()
756{
757    FILE *dependfileoutput;
758    listindice *parcours;
759    int i;
760
761    sprintf(dependfilename, "%s/.dependavailable", work_dir);
762
763    if ((dependfileoutput=fopen(dependfilename, "w"))!=NULL)
764    {
765        /* We are looking for all the indices of the Listofavailableindices      */
766        for (i=0;i<NB_CAT_VARIABLES;i++)
767        {
768            parcours = Listofavailableindices_glob[i];
769            while (parcours)
770            {
771                if ( parcours->i_indice != 0 )
772                {
773                    fprintf(dependfileoutput,"%d %d\n",i,parcours->i_indice);
774                }
775                parcours = parcours->suiv;
776            }
777        }
778        fclose(dependfileoutput);
779    }
780}
781
782/******************************************************************************/
783/*                        Readthedependavailablefile                          */
784/******************************************************************************/
785/* This subroutine is used to read the .dependfileavailable file              */
786/******************************************************************************/
787/*                                                                            */
788/*                                  .dependavailable                          */
789/*     tabvars(1) = var1                                                      */
790/*     tabvars(3) = var1                  2                                   */
791/*     tabvars(4) = var1         =====>   5  ==> Listofavailableindices       */
792/*     tabvars(6) = var1                                                      */
793/*     tabvars(7) = var1                                                      */
794/*                                                                            */
795/*                                                                            */
796/*                                                                            */
797/******************************************************************************/
798void Readthedependavailablefile()
799{
800  FILE *dependfileoutput;
801  listindice *parcours;
802  int current_cat;
803
804  sprintf(dependfilename, "%s/.dependavailable", work_dir);
805
806  if ((dependfileoutput=fopen(dependfilename, "r"))!=NULL)
807  {
808     /* We are looking for all the indices of the Listofavailableindices      */
809     Listofavailableindices_glob = (listindice **) calloc(NB_CAT_VARIABLES,sizeof(listindice *));
810     while (!feof(dependfileoutput))
811     {
812        parcours=(listindice *)calloc(1,sizeof(listindice));
813        fscanf(dependfileoutput,"%d %d\n",&current_cat,&parcours->i_indice);
814        if ( parcours->i_indice != 0 && parcours->i_indice < 10000000 )
815        {
816           parcours -> suiv = Listofavailableindices_glob[current_cat];
817           Listofavailableindices_glob[current_cat] = parcours;
818        }
819        else
820        {
821           free(parcours);
822        }
823     }
824     fclose(dependfileoutput);
825  }
826}
827
828
829/******************************************************************************/
830/*                       is_dependfile_created                                */
831/******************************************************************************/
832/* This subroutine is used to know if the .depend<NameTampon> exist           */
833/*    it means if the file has been ever parsed                               */
834/******************************************************************************/
835/*                                                                            */
836/******************************************************************************/
837int is_dependfile_created(const char *NameTampon)
838{
839  FILE *dependfileoutput;
840  char lowername[LONG_VNAME];
841
842  convert2lower(lowername, NameTampon);
843  sprintf(dependfilename, "%s/.depend_%s", work_dir, lowername);
844
845  dependfileoutput = fopen(dependfilename, "r");
846
847  if ( (dependfileoutput = fopen(dependfilename, "r")) != NULL )
848  {
849    fclose(dependfileoutput);
850    return 1;
851  }
852  else
853    return 0;
854}
855
856void Write_val_max()
857{
858    FILE *dependfileoutput;
859
860    sprintf(dependfilename, "%s/.dependvalmax", work_dir);
861
862    if ((dependfileoutput=fopen(dependfilename, "w"))!=NULL)
863    {
864        fprintf(dependfileoutput,"length_last\n");
865        fprintf(dependfileoutput,"%lu\n", length_last);
866        fprintf(dependfileoutput,"length_first\n");
867        fprintf(dependfileoutput,"%lu\n", length_first);
868        fprintf(dependfileoutput,"length_v_vallengspec\n");
869        fprintf(dependfileoutput,"%lu\n", length_v_vallengspec);
870        fprintf(dependfileoutput,"length_v_commoninfile\n");
871        fprintf(dependfileoutput,"%lu\n", length_v_commoninfile);
872        fprintf(dependfileoutput,"length_v_precision\n");
873        fprintf(dependfileoutput,"%lu\n", length_v_precision);
874        fprintf(dependfileoutput,"length_v_IntentSpec\n");
875        fprintf(dependfileoutput,"%lu\n", length_v_IntentSpec);
876        fprintf(dependfileoutput,"length_v_initialvalue\n");
877        fprintf(dependfileoutput,"%lu\n", length_v_initialvalue);
878        fprintf(dependfileoutput,"length_v_readedlistdimension\n");
879        fprintf(dependfileoutput,"%lu\n", length_v_readedlistdimension);
880        fprintf(dependfileoutput,"length_a_nomvar\n");
881        fprintf(dependfileoutput,"%lu\n", length_a_nomvar);
882        fprintf(dependfileoutput,"length_toprintglob\n");
883        fprintf(dependfileoutput,"%lu\n", length_toprintglob);
884        fprintf(dependfileoutput,"Size_char0d\n");
885        fprintf(dependfileoutput,"%d\n",value_char_size);
886        fprintf(dependfileoutput,"Size_char1d\n");
887        fprintf(dependfileoutput,"%d\n",value_char_size1);
888        fprintf(dependfileoutput,"Size_char2d\n");
889        fprintf(dependfileoutput,"%d\n",value_char_size2);
890        fprintf(dependfileoutput,"Size_char3d\n");
891        fprintf(dependfileoutput,"%d\n",value_char_size3);
892        fprintf(dependfileoutput,"length_tmpvargridname\n");
893        fprintf(dependfileoutput,"%lu\n", length_tmpvargridname);
894        fprintf(dependfileoutput,"length_ligne_Subloop\n");
895        fprintf(dependfileoutput,"%lu\n", length_ligne_Subloop);
896        fprintf(dependfileoutput,"length_toprint_toamr\n");
897        fprintf(dependfileoutput,"%lu\n", length_toprint_utilagrif);
898        fprintf(dependfileoutput,"length_toprinttmp_utilchar\n");
899        fprintf(dependfileoutput,"%lu\n", length_toprinttmp_utilchar);
900        fprintf(dependfileoutput,"length_ligne_writedecl\n");
901        fprintf(dependfileoutput,"%lu\n", length_ligne_writedecl);
902        fprintf(dependfileoutput,"length_newname_toamr\n");
903        fprintf(dependfileoutput,"%lu\n", length_newname_toamr);
904        fprintf(dependfileoutput,"length_newname_writedecl\n");
905        fprintf(dependfileoutput,"%lu\n", length_newname_writedecl);
906        fprintf(dependfileoutput,"length_ligne_toamr\n");
907        fprintf(dependfileoutput,"%lu\n", length_ligne_toamr);
908        fprintf(dependfileoutput,"length_tmpligne_writedecl\n");
909        fprintf(dependfileoutput,"%lu\n", length_tmpligne_writedecl);
910
911        fclose(dependfileoutput);
912    }
913}
914
915
916void Read_val_max()
917{
918    char nothing[LONG_M];
919    FILE *dependfileoutput;
920
921    sprintf(dependfilename, "%s/.dependvalmax", work_dir);
922
923    if ((dependfileoutput=fopen(".dependvalmax","r"))!=NULL)
924    {
925       fscanf(dependfileoutput,"%s\n",nothing);
926       fscanf(dependfileoutput,"%lu\n", &length_last);
927       fscanf(dependfileoutput,"%s\n",nothing);
928       fscanf(dependfileoutput,"%lu\n", &length_first);
929       fscanf(dependfileoutput,"%s\n",nothing);
930       fscanf(dependfileoutput,"%lu\n", &length_v_vallengspec);
931       fscanf(dependfileoutput,"%s\n",nothing);
932       fscanf(dependfileoutput,"%lu\n", &length_v_commoninfile);
933       fscanf(dependfileoutput,"%s\n",nothing);
934       fscanf(dependfileoutput,"%lu\n", &length_v_precision);
935       fscanf(dependfileoutput,"%s\n",nothing);
936       fscanf(dependfileoutput,"%lu\n", &length_v_IntentSpec);
937       fscanf(dependfileoutput,"%s\n",nothing);
938       fscanf(dependfileoutput,"%lu\n", &length_v_initialvalue);
939       fscanf(dependfileoutput,"%s\n",nothing);
940       fscanf(dependfileoutput,"%lu\n", &length_v_readedlistdimension);
941       fscanf(dependfileoutput,"%s\n",nothing);
942       fscanf(dependfileoutput,"%lu\n", &length_a_nomvar);
943       fscanf(dependfileoutput,"%s\n",nothing);
944       fscanf(dependfileoutput,"%lu\n", &length_toprintglob);
945       fscanf(dependfileoutput,"%s\n",nothing);
946       fscanf(dependfileoutput,"%d\n", &value_char_size);
947       fscanf(dependfileoutput,"%s\n", nothing);
948       fscanf(dependfileoutput,"%d\n", &value_char_size1);
949       fscanf(dependfileoutput,"%s\n", nothing);
950       fscanf(dependfileoutput,"%d\n", &value_char_size2);
951       fscanf(dependfileoutput,"%s\n", nothing);
952       fscanf(dependfileoutput,"%d\n", &value_char_size3);
953       fscanf(dependfileoutput,"%s\n",nothing);
954       fscanf(dependfileoutput,"%lu\n", &length_tmpvargridname);
955       fscanf(dependfileoutput,"%s\n",nothing);
956       fscanf(dependfileoutput,"%lu\n", &length_ligne_Subloop);
957       fscanf(dependfileoutput,"%s\n",nothing);
958       fscanf(dependfileoutput,"%lu\n", &length_toprint_utilagrif);
959       fscanf(dependfileoutput,"%s\n",nothing);
960       fscanf(dependfileoutput,"%lu\n", &length_toprinttmp_utilchar);
961       fscanf(dependfileoutput,"%s\n",nothing);
962       fscanf(dependfileoutput,"%lu\n", &length_ligne_writedecl);
963       fscanf(dependfileoutput,"%s\n",nothing);
964       fscanf(dependfileoutput,"%lu\n", &length_newname_toamr);
965       fscanf(dependfileoutput,"%s\n",nothing);
966       fscanf(dependfileoutput,"%lu\n", &length_newname_writedecl);
967       fscanf(dependfileoutput,"%s\n",nothing);
968       fscanf(dependfileoutput,"%lu\n", &length_ligne_toamr);
969       fscanf(dependfileoutput,"%s\n",nothing);
970       fscanf(dependfileoutput,"%lu\n", &length_tmpligne_writedecl);
971
972       fclose(dependfileoutput);
973    }
974}
Note: See TracBrowser for help on using the repository browser.