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