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

source: trunk/AGRIF/LIB/UtilCharacter.c @ 1200

Last change on this file since 1200 was 1200, checked in by rblod, 16 years ago

Adapt Agrif to the new SBC and correct several bugs for agrif (restart writing and reading), see ticket #133
Note : this fix does not work yet on NEC computerq (sxf90/360)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 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
43/******************************************************************************/
44/*                         FindAndChangeNameToTabvars                         */
45/******************************************************************************/
46/*                                                                            */
47/******************************************************************************/
48/* if  whichone = 0 ----> Agrif_tabvars(i) % var % array2                     */
49/*                                                                            */
50/* if  whichone = 1 ----> Agrif_tabvars(i) % parentvar % var % array2         */
51/*                                                                            */
52/******************************************************************************/
53void FindAndChangeNameToTabvars(char name[LONG_C],char toprint[LONG_4C],
54                                              listvar * listtosee, int whichone)
55{
56   listvar *newvar;
57   int out;
58   
59
60   if ( strcasecmp(name,"") )
61   {
62      newvar=listtosee;
63      out=0;
64      while( newvar && out == 0 )
65      {
66         if ( !strcasecmp(newvar->var->v_nomvar,name) )
67         {
68
69            if ( LookingForVariableInListName(
70                             List_SubroutineArgument_Var,name) == 0 )
71            {
72               out = 1;
73               strcat(toprint,vargridcurgridtabvars(newvar->var,whichone));
74            }
75            else newvar=newvar->suiv;
76         }
77         else newvar=newvar->suiv;
78      }
79      if ( out == 0 ) strcat(toprint,name);
80   }
81   Save_Length(toprint,44);
82}
83
84
85/******************************************************************************/
86/*                     ChangeTheInitalvaluebyTabvarsName                      */
87/******************************************************************************/
88/*                                                                            */
89/******************************************************************************/
90/*                                                                            */
91/*                                                                            */
92/*                                                                            */
93/******************************************************************************/
94char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread,
95                                                                   int whichone)
96{
97   char toprinttmp[LONG_4C];
98   int i;
99   char chartmp[2];
100
101   i=0;
102   strcpy(toprintglob,"");
103   strcpy(toprinttmp,"");
104
105   /*                                                                         */
106   while ( i < strlen(nom) )
107   {
108      if ( nom[i] == '+' )
109      {
110        FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
111         strcpy(toprinttmp,"");
112         strcat(toprintglob,"+");
113      }
114      else if ( nom[i] == '-' )
115      {
116         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
117         strcpy(toprinttmp,"");
118         strcat(toprintglob,"-");
119      }
120      else if ( nom[i] == '*' )
121      {
122         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
123         strcpy(toprinttmp,"");
124         strcat(toprintglob,"*");
125      }
126      else if ( nom[i] == '/' )
127      {
128         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
129         strcpy(toprinttmp,"");
130         strcat(toprintglob,"/");
131      }
132      else if ( nom[i] == '(' )
133      {
134         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
135         strcpy(toprinttmp,"");
136         strcat(toprintglob,"(");
137      }
138      else if ( nom[i] == ')' )
139      {
140         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
141         strcpy(toprinttmp,"");
142         strcat(toprintglob,")");
143      }
144      else if ( nom[i] == ':' )
145      {
146         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
147         strcpy(toprinttmp,"");
148         strcat(toprintglob,":");
149      }
150      else if ( nom[i] == ',' )
151      {
152         FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
153         strcpy(toprinttmp,"");
154         strcat(toprintglob,",");
155      }
156      else
157      {
158         sprintf(chartmp,"%c",nom[i]);
159         strcat(toprinttmp,chartmp);
160      }
161      /*                                                                      */
162      i=i+1;
163   }
164   FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone);
165   strcpy(toprinttmp,"");
166
167   Save_Length(toprinttmp,44);
168   Save_Length(toprintglob,39);
169
170   /*                                                                         */
171   return toprintglob;
172}
173
174/******************************************************************************/
175/*                            IsVariableReal                                  */
176/******************************************************************************/
177/*                                                                            */
178/******************************************************************************/
179/*                                                                            */
180/*                                                                            */
181/*                                                                            */
182/******************************************************************************/
183int IsVariableReal(char *nom)
184{
185   int Real;
186
187   Real = 0;
188   if ( ( nom[0] >= 'a' && nom[0] <= 'h' ) ||
189        ( nom[0] >= 'A' && nom[0] <= 'H' ) ||
190        ( nom[0] >= 'o' && nom[0] <= 'z' ) ||
191        ( nom[0] >= 'O' && nom[0] <= 'Z' )
192       )
193       {
194          Real = 1;
195       }
196   /*                                                                         */
197   return Real;
198}
199/******************************************************************************/
200/*                         IsVarInUseFile                                     */
201/******************************************************************************/
202/*                                                                            */
203/******************************************************************************/
204/*                                                                            */
205/*                                                                            */
206/*                                                                            */
207/******************************************************************************/
208void IsVarInUseFile(char *nom)
209{
210   listvar *parcours;
211   listparameter *parcoursparam;
212   int out;
213
214   out = 0;
215
216   parcours = List_Global_Var;
217   while( parcours && out == 0 )
218   {
219      if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
220     else parcours=parcours->suiv;
221   }
222   if ( out == 0 )
223   {
224      parcours = List_Common_Var;
225      while( parcours && out == 0 )
226      {
227         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
228        else parcours=parcours->suiv;
229      }
230   }
231   if ( out == 0 )
232   {
233      parcours = List_GlobalParameter_Var;
234      while( parcours && out == 0 )
235      {
236         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
237        else parcours=parcours->suiv;
238      }
239   }
240   if ( out == 0 )
241   {
242      parcours = List_Parameter_Var;
243      while( parcours && out == 0 )
244      {
245         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ;
246        else parcours=parcours->suiv;
247      }
248   }
249   if ( out == 0 )
250   {
251      parcoursparam = List_GlobParamModuleUsed_Var;
252      while( parcoursparam && out == 0 )
253      {
254         if ( !strcasecmp(nom,parcoursparam->p_name) ) out =2 ;
255         else parcoursparam=parcoursparam->suiv;
256      }
257   }
258   if ( out == 0 )
259   {
260      parcours = List_ModuleUsed_Var;
261      while( parcours && out == 0 )
262      {
263         if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =2 ;
264        else parcours=parcours->suiv;
265      }
266   }
267   if ( out == 0 || out == 2 )
268   {
269      parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var;
270      while( parcoursparam && out != 1 )
271      {
272         if ( !strcasecmp(nom,parcoursparam->p_name) ) out =1 ;
273         else parcoursparam=parcoursparam->suiv;
274      }
275      if ( out == 1 )
276      {
277         strcpy(charusemodule,parcoursparam->p_modulename);
278         Addmoduletothelist(parcoursparam->p_modulename);
279      }
280   }
281   if ( out == 0 &&
282        strcasecmp(nom,"MAX")             &&
283        strcasecmp(nom,"mpi_status_size")
284      )
285   {
286      printf("--- in UtilCharacter we do not found the \n");
287      printf("---  variable %s, the module where this \n",nom);
288      printf("---  variable has been defined has not been\n");
289      printf("---  found.\n");
290   }
291}
292
293/******************************************************************************/
294/*                      DecomposeTheNameinlistnom                             */
295/******************************************************************************/
296/* Firstpass 0                                                                */
297/******************************************************************************/
298/*                                                                            */
299/*                                                                            */
300/******************************************************************************/
301listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout)
302{
303   char toprinttmp[LONG_4C];
304   int i;
305   char chartmp[2];
306
307   i=0;
308   strcpy(toprinttmp,"");
309   /*                                                                         */
310   while ( i < strlen(nom) )
311   {
312      if ( nom[i] == '+' ||
313           nom[i] == '-' ||
314           nom[i] == '*' ||
315           nom[i] == '/' ||
316           nom[i] == ')' ||
317           nom[i] == '(' ||
318           nom[i] == ',' ||
319           nom[i] == ':'
320         )
321      {
322         if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
323         {
324             listout = Addtolistnom(toprinttmp,listout,0);
325         }
326         strcpy(toprinttmp,"");
327      }
328      else
329      {
330         sprintf(chartmp,"%c",nom[i]);
331         strcat(toprinttmp,chartmp);
332      }
333      /*                                                                      */
334      i=i+1;
335   }
336   if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
337   {
338      listout = Addtolistnom(toprinttmp,listout,0);
339   }
340   strcpy(toprinttmp,"");
341   Save_Length(toprinttmp,44);
342
343   return listout;
344}
345
346
347/******************************************************************************/
348/*                      DecomposeTheName                                      */
349/******************************************************************************/
350/* Firstpass 0                                                                */
351/******************************************************************************/
352/*                                                                            */
353/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
354/*                                                                            */
355/******************************************************************************/
356void DecomposeTheName(char *nom)
357{
358   char toprinttmp[LONG_4C];
359   int i;
360   char chartmp[2];
361
362   i=0;
363   strcpy(toprinttmp,"");
364   /*                                                                         */
365   while ( i < strlen(nom) )
366   {
367      if ( nom[i] == '+' ||
368           nom[i] == '-' ||
369           nom[i] == '*' ||
370           nom[i] == '/' ||
371           nom[i] == ')' ||
372           nom[i] == '(' ||
373           nom[i] == ',' ||
374           nom[i] == ':'
375         )
376      {
377         if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
378         {
379            ajoutevarindoloop_definedimension (toprinttmp);
380            /* Is this variable present in globvarofusefile                   */
381            IsVarInUseFile(toprinttmp);
382         }
383         strcpy(toprinttmp,"");
384      }
385      else
386      {
387         sprintf(chartmp,"%c",nom[i]);
388         strcat(toprinttmp,chartmp);
389      }
390      /*                                                                      */
391      i=i+1;
392   }
393   Save_Length(toprinttmp,44);
394   if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) )
395   {
396      ajoutevarindoloop_definedimension (toprinttmp);
397      /* Is this variable present in globvarofusefile                         */
398      IsVarInUseFile(toprinttmp);
399   }
400   strcpy(toprinttmp,"");
401
402}
403
404void convert2lower(char *name)
405{
406   int l;
407   int i;
408   int caractere;
409
410   l=strlen(name)-1;
411   for (i=0;i<=l;i++)
412   {
413      caractere=name[i];
414      if ((caractere>=65 && caractere<=90)||(caractere>=192 && caractere<=221))
415      {
416         name[i]+=32;
417      }
418   }
419}
420
421int convert2int(char *name)
422{
423   int i;
424   int caractere;
425   int value;
426   int value_tmp;
427   int longueur;
428
429   value = 0;
430
431   longueur = strlen(name) - 1;
432   for (i=0;i<=longueur;i++)
433   {
434      caractere=name[i];
435      value_tmp = caractere -'0';
436      if ( value_tmp > 9 ) return 0;
437           if ( longueur+1-i == 6 ) value = value + value_tmp *100000;
438      else if ( longueur+1-i == 5 ) value = value + value_tmp *10000;
439      else if ( longueur+1-i == 4 ) value = value + value_tmp *1000;
440      else if ( longueur+1-i == 3 ) value = value + value_tmp *100;
441      else if ( longueur+1-i == 2 ) value = value + value_tmp *10;
442      else if ( longueur+1-i == 1 ) value = value + value_tmp *1;
443   }
444   return value;
445}
Note: See TracBrowser for help on using the repository browser.