[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; |
---|
[1200] | 58 | |
---|
[663] | 59 | |
---|
[396] | 60 | if ( strcasecmp(name,"") ) |
---|
| 61 | { |
---|
| 62 | newvar=listtosee; |
---|
| 63 | out=0; |
---|
| 64 | while( newvar && out == 0 ) |
---|
| 65 | { |
---|
[663] | 66 | if ( !strcasecmp(newvar->var->v_nomvar,name) ) |
---|
[396] | 67 | { |
---|
[1200] | 68 | |
---|
[774] | 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; |
---|
[396] | 76 | } |
---|
| 77 | else newvar=newvar->suiv; |
---|
| 78 | } |
---|
| 79 | if ( out == 0 ) strcat(toprint,name); |
---|
| 80 | } |
---|
[774] | 81 | Save_Length(toprint,44); |
---|
[396] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /******************************************************************************/ |
---|
| 86 | /* ChangeTheInitalvaluebyTabvarsName */ |
---|
| 87 | /******************************************************************************/ |
---|
| 88 | /* */ |
---|
| 89 | /******************************************************************************/ |
---|
| 90 | /* */ |
---|
| 91 | /* */ |
---|
| 92 | /* */ |
---|
| 93 | /******************************************************************************/ |
---|
[663] | 94 | char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread, |
---|
| 95 | int whichone) |
---|
[396] | 96 | { |
---|
[774] | 97 | char toprinttmp[LONG_4C]; |
---|
[396] | 98 | int i; |
---|
| 99 | char chartmp[2]; |
---|
[663] | 100 | |
---|
[396] | 101 | i=0; |
---|
| 102 | strcpy(toprintglob,""); |
---|
| 103 | strcpy(toprinttmp,""); |
---|
[1200] | 104 | |
---|
[396] | 105 | /* */ |
---|
| 106 | while ( i < strlen(nom) ) |
---|
| 107 | { |
---|
[663] | 108 | if ( nom[i] == '+' ) |
---|
[396] | 109 | { |
---|
[774] | 110 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
[396] | 111 | strcpy(toprinttmp,""); |
---|
| 112 | strcat(toprintglob,"+"); |
---|
| 113 | } |
---|
[663] | 114 | else if ( nom[i] == '-' ) |
---|
[396] | 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 | { |
---|
[663] | 158 | sprintf(chartmp,"%c",nom[i]); |
---|
[396] | 159 | strcat(toprinttmp,chartmp); |
---|
| 160 | } |
---|
| 161 | /* */ |
---|
| 162 | i=i+1; |
---|
| 163 | } |
---|
| 164 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 165 | strcpy(toprinttmp,""); |
---|
[663] | 166 | |
---|
[774] | 167 | Save_Length(toprinttmp,44); |
---|
| 168 | Save_Length(toprintglob,39); |
---|
[1200] | 169 | |
---|
[396] | 170 | /* */ |
---|
| 171 | return toprintglob; |
---|
| 172 | } |
---|
| 173 | |
---|
[530] | 174 | /******************************************************************************/ |
---|
| 175 | /* IsVariableReal */ |
---|
| 176 | /******************************************************************************/ |
---|
| 177 | /* */ |
---|
| 178 | /******************************************************************************/ |
---|
| 179 | /* */ |
---|
| 180 | /* */ |
---|
| 181 | /* */ |
---|
| 182 | /******************************************************************************/ |
---|
| 183 | int IsVariableReal(char *nom) |
---|
| 184 | { |
---|
| 185 | int Real; |
---|
[663] | 186 | |
---|
[530] | 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 | /******************************************************************************/ |
---|
[396] | 208 | void IsVarInUseFile(char *nom) |
---|
| 209 | { |
---|
| 210 | listvar *parcours; |
---|
| 211 | listparameter *parcoursparam; |
---|
| 212 | int out; |
---|
| 213 | |
---|
| 214 | out = 0; |
---|
| 215 | |
---|
[663] | 216 | parcours = List_Global_Var; |
---|
[396] | 217 | while( parcours && out == 0 ) |
---|
| 218 | { |
---|
[663] | 219 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
[396] | 220 | else parcours=parcours->suiv; |
---|
| 221 | } |
---|
| 222 | if ( out == 0 ) |
---|
| 223 | { |
---|
[663] | 224 | parcours = List_Common_Var; |
---|
[396] | 225 | while( parcours && out == 0 ) |
---|
| 226 | { |
---|
[663] | 227 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
[396] | 228 | else parcours=parcours->suiv; |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | if ( out == 0 ) |
---|
| 232 | { |
---|
[663] | 233 | parcours = List_GlobalParameter_Var; |
---|
[396] | 234 | while( parcours && out == 0 ) |
---|
| 235 | { |
---|
[663] | 236 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =1 ; |
---|
[396] | 237 | else parcours=parcours->suiv; |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | if ( out == 0 ) |
---|
| 241 | { |
---|
[663] | 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; |
---|
[396] | 252 | while( parcoursparam && out == 0 ) |
---|
| 253 | { |
---|
[663] | 254 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out =2 ; |
---|
[396] | 255 | else parcoursparam=parcoursparam->suiv; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | if ( out == 0 ) |
---|
| 259 | { |
---|
[663] | 260 | parcours = List_ModuleUsed_Var; |
---|
[396] | 261 | while( parcours && out == 0 ) |
---|
| 262 | { |
---|
[663] | 263 | if ( !strcasecmp(nom,parcours->var->v_nomvar) ) out =2 ; |
---|
[396] | 264 | else parcours=parcours->suiv; |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | if ( out == 0 || out == 2 ) |
---|
| 268 | { |
---|
[663] | 269 | parcoursparam = List_GlobParamModuleUsedInModuleUsed_Var; |
---|
[396] | 270 | while( parcoursparam && out != 1 ) |
---|
| 271 | { |
---|
[663] | 272 | if ( !strcasecmp(nom,parcoursparam->p_name) ) out =1 ; |
---|
[396] | 273 | else parcoursparam=parcoursparam->suiv; |
---|
| 274 | } |
---|
[663] | 275 | if ( out == 1 ) |
---|
[396] | 276 | { |
---|
[663] | 277 | strcpy(charusemodule,parcoursparam->p_modulename); |
---|
| 278 | Addmoduletothelist(parcoursparam->p_modulename); |
---|
[396] | 279 | } |
---|
| 280 | } |
---|
[663] | 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 | } |
---|
[396] | 291 | } |
---|
| 292 | |
---|
| 293 | /******************************************************************************/ |
---|
| 294 | /* DecomposeTheNameinlistnom */ |
---|
| 295 | /******************************************************************************/ |
---|
| 296 | /* Firstpass 0 */ |
---|
| 297 | /******************************************************************************/ |
---|
| 298 | /* */ |
---|
| 299 | /* */ |
---|
| 300 | /******************************************************************************/ |
---|
| 301 | listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout) |
---|
| 302 | { |
---|
[774] | 303 | char toprinttmp[LONG_4C]; |
---|
[396] | 304 | int i; |
---|
| 305 | char chartmp[2]; |
---|
[663] | 306 | |
---|
[396] | 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] == ',' || |
---|
[663] | 319 | nom[i] == ':' |
---|
| 320 | ) |
---|
[396] | 321 | { |
---|
| 322 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
[663] | 323 | { |
---|
| 324 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
[396] | 325 | } |
---|
| 326 | strcpy(toprinttmp,""); |
---|
| 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
[663] | 330 | sprintf(chartmp,"%c",nom[i]); |
---|
[396] | 331 | strcat(toprinttmp,chartmp); |
---|
| 332 | } |
---|
| 333 | /* */ |
---|
| 334 | i=i+1; |
---|
| 335 | } |
---|
[663] | 336 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 337 | { |
---|
| 338 | listout = Addtolistnom(toprinttmp,listout,0); |
---|
[396] | 339 | } |
---|
| 340 | strcpy(toprinttmp,""); |
---|
[774] | 341 | Save_Length(toprinttmp,44); |
---|
[663] | 342 | |
---|
| 343 | return listout; |
---|
[396] | 344 | } |
---|
| 345 | |
---|
| 346 | |
---|
| 347 | /******************************************************************************/ |
---|
| 348 | /* DecomposeTheName */ |
---|
| 349 | /******************************************************************************/ |
---|
| 350 | /* Firstpass 0 */ |
---|
| 351 | /******************************************************************************/ |
---|
| 352 | /* */ |
---|
| 353 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
| 354 | /* */ |
---|
| 355 | /******************************************************************************/ |
---|
| 356 | void DecomposeTheName(char *nom) |
---|
| 357 | { |
---|
[774] | 358 | char toprinttmp[LONG_4C]; |
---|
[396] | 359 | int i; |
---|
| 360 | char chartmp[2]; |
---|
[663] | 361 | |
---|
[396] | 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] == ',' || |
---|
[663] | 374 | nom[i] == ':' |
---|
| 375 | ) |
---|
[396] | 376 | { |
---|
| 377 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
[663] | 378 | { |
---|
[396] | 379 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 380 | /* Is this variable present in globvarofusefile */ |
---|
| 381 | IsVarInUseFile(toprinttmp); |
---|
| 382 | } |
---|
| 383 | strcpy(toprinttmp,""); |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
[663] | 387 | sprintf(chartmp,"%c",nom[i]); |
---|
[396] | 388 | strcat(toprinttmp,chartmp); |
---|
| 389 | } |
---|
| 390 | /* */ |
---|
| 391 | i=i+1; |
---|
| 392 | } |
---|
[774] | 393 | Save_Length(toprinttmp,44); |
---|
[663] | 394 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 395 | { |
---|
[396] | 396 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 397 | /* Is this variable present in globvarofusefile */ |
---|
| 398 | IsVarInUseFile(toprinttmp); |
---|
| 399 | } |
---|
| 400 | strcpy(toprinttmp,""); |
---|
[663] | 401 | |
---|
[396] | 402 | } |
---|
[663] | 403 | |
---|
| 404 | void 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 | } |
---|
[774] | 420 | |
---|
| 421 | int 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 | } |
---|