[1901] | 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 | /******************************************************************************/ |
---|
| 53 | void 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 | /******************************************************************************/ |
---|
| 94 | char *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 | /******************************************************************************/ |
---|
| 183 | int 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 | /******************************************************************************/ |
---|
| 208 | void 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 | { |
---|
[2715] | 286 | /* printf("--- in UtilCharacter we do not found the \n"); |
---|
[1901] | 287 | printf("--- variable %s, the module where this \n",nom); |
---|
| 288 | printf("--- variable has been defined has not been\n"); |
---|
[2715] | 289 | printf("--- found.\n");*/ |
---|
[1901] | 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /******************************************************************************/ |
---|
| 294 | /* DecomposeTheNameinlistnom */ |
---|
| 295 | /******************************************************************************/ |
---|
| 296 | /* Firstpass 0 */ |
---|
| 297 | /******************************************************************************/ |
---|
| 298 | /* */ |
---|
| 299 | /* */ |
---|
| 300 | /******************************************************************************/ |
---|
| 301 | listnom *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 | { |
---|
[2715] | 322 | |
---|
[1901] | 323 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 324 | { |
---|
| 325 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
| 326 | } |
---|
| 327 | strcpy(toprinttmp,""); |
---|
| 328 | } |
---|
| 329 | else |
---|
| 330 | { |
---|
| 331 | sprintf(chartmp,"%c",nom[i]); |
---|
| 332 | strcat(toprinttmp,chartmp); |
---|
[2715] | 333 | |
---|
[1901] | 334 | } |
---|
| 335 | /* */ |
---|
| 336 | i=i+1; |
---|
| 337 | } |
---|
| 338 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 339 | { |
---|
| 340 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
| 341 | } |
---|
| 342 | strcpy(toprinttmp,""); |
---|
| 343 | Save_Length(toprinttmp,44); |
---|
| 344 | |
---|
| 345 | return listout; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | /******************************************************************************/ |
---|
| 350 | /* DecomposeTheName */ |
---|
| 351 | /******************************************************************************/ |
---|
| 352 | /* Firstpass 0 */ |
---|
| 353 | /******************************************************************************/ |
---|
| 354 | /* */ |
---|
| 355 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
| 356 | /* */ |
---|
| 357 | /******************************************************************************/ |
---|
| 358 | void DecomposeTheName(char *nom) |
---|
| 359 | { |
---|
| 360 | char toprinttmp[LONG_4C]; |
---|
| 361 | int i; |
---|
| 362 | char chartmp[2]; |
---|
| 363 | |
---|
| 364 | i=0; |
---|
| 365 | strcpy(toprinttmp,""); |
---|
| 366 | /* */ |
---|
| 367 | while ( i < strlen(nom) ) |
---|
| 368 | { |
---|
| 369 | if ( nom[i] == '+' || |
---|
| 370 | nom[i] == '-' || |
---|
| 371 | nom[i] == '*' || |
---|
| 372 | nom[i] == '/' || |
---|
| 373 | nom[i] == ')' || |
---|
| 374 | nom[i] == '(' || |
---|
| 375 | nom[i] == ',' || |
---|
| 376 | nom[i] == ':' |
---|
| 377 | ) |
---|
| 378 | { |
---|
| 379 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 380 | { |
---|
| 381 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 382 | /* Is this variable present in globvarofusefile */ |
---|
| 383 | IsVarInUseFile(toprinttmp); |
---|
| 384 | } |
---|
| 385 | strcpy(toprinttmp,""); |
---|
| 386 | } |
---|
| 387 | else |
---|
| 388 | { |
---|
| 389 | sprintf(chartmp,"%c",nom[i]); |
---|
| 390 | strcat(toprinttmp,chartmp); |
---|
| 391 | } |
---|
| 392 | /* */ |
---|
| 393 | i=i+1; |
---|
| 394 | } |
---|
| 395 | Save_Length(toprinttmp,44); |
---|
| 396 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 397 | { |
---|
| 398 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 399 | /* Is this variable present in globvarofusefile */ |
---|
| 400 | IsVarInUseFile(toprinttmp); |
---|
| 401 | } |
---|
| 402 | strcpy(toprinttmp,""); |
---|
| 403 | |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | void convert2lower(char *name) |
---|
| 407 | { |
---|
| 408 | int l; |
---|
| 409 | int i; |
---|
| 410 | int caractere; |
---|
| 411 | |
---|
| 412 | l=strlen(name)-1; |
---|
| 413 | for (i=0;i<=l;i++) |
---|
| 414 | { |
---|
| 415 | caractere=name[i]; |
---|
| 416 | if ((caractere>=65 && caractere<=90)||(caractere>=192 && caractere<=221)) |
---|
| 417 | { |
---|
| 418 | name[i]+=32; |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | int convert2int(char *name) |
---|
| 424 | { |
---|
| 425 | int i; |
---|
| 426 | int caractere; |
---|
| 427 | int value; |
---|
| 428 | int value_tmp; |
---|
| 429 | int longueur; |
---|
| 430 | |
---|
| 431 | value = 0; |
---|
| 432 | |
---|
| 433 | longueur = strlen(name) - 1; |
---|
| 434 | for (i=0;i<=longueur;i++) |
---|
| 435 | { |
---|
| 436 | caractere=name[i]; |
---|
| 437 | value_tmp = caractere -'0'; |
---|
| 438 | if ( value_tmp > 9 ) return 0; |
---|
| 439 | if ( longueur+1-i == 6 ) value = value + value_tmp *100000; |
---|
| 440 | else if ( longueur+1-i == 5 ) value = value + value_tmp *10000; |
---|
| 441 | else if ( longueur+1-i == 4 ) value = value + value_tmp *1000; |
---|
| 442 | else if ( longueur+1-i == 3 ) value = value + value_tmp *100; |
---|
| 443 | else if ( longueur+1-i == 2 ) value = value + value_tmp *10; |
---|
| 444 | else if ( longueur+1-i == 1 ) value = value + value_tmp *1; |
---|
| 445 | } |
---|
| 446 | return value; |
---|
| 447 | } |
---|