[396] | 1 | /******************************************************************************/ |
---|
| 2 | /* */ |
---|
| 3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
| 4 | /* */ |
---|
| 5 | /* Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
| 6 | /* Cyril Mazauric (Cyril.Mazauric@imag.fr) */ |
---|
| 7 | /* */ |
---|
| 8 | /* This program is free software; you can redistribute it and/or modify */ |
---|
| 9 | /* it */ |
---|
| 10 | /* */ |
---|
| 11 | /* This program is distributed in the hope that it will be useful, */ |
---|
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
---|
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
---|
| 14 | /* GNU General Public License for more details. */ |
---|
| 15 | /* */ |
---|
| 16 | /******************************************************************************/ |
---|
| 17 | #include <stdio.h> |
---|
| 18 | #include <stdlib.h> |
---|
| 19 | #include <string.h> |
---|
| 20 | #include "decl.h" |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | /******************************************************************************/ |
---|
| 26 | /* FindAndChangeNameToTabvars */ |
---|
| 27 | /******************************************************************************/ |
---|
| 28 | /* */ |
---|
| 29 | /******************************************************************************/ |
---|
| 30 | /* if whichone = 0 ----> Agrif_tabvars(i) % var % array2 */ |
---|
| 31 | /* */ |
---|
| 32 | /* if whichone = 1 ----> Agrif_tabvars(i) % parentvar % var % array2 */ |
---|
| 33 | /* */ |
---|
| 34 | /******************************************************************************/ |
---|
| 35 | void FindAndChangeNameToTabvars(char name[LONGNOM],char toprint[LONGNOM], |
---|
| 36 | listvar * listtosee, int whichone) |
---|
| 37 | { |
---|
| 38 | listvar *newvar; |
---|
| 39 | int out; |
---|
| 40 | |
---|
| 41 | if ( strcasecmp(name,"") ) |
---|
| 42 | { |
---|
| 43 | newvar=listtosee; |
---|
| 44 | out=0; |
---|
| 45 | while( newvar && out == 0 ) |
---|
| 46 | { |
---|
| 47 | if ( !strcasecmp(newvar->var->nomvar,name) ) |
---|
| 48 | { |
---|
| 49 | out = 1; |
---|
| 50 | strcat(toprint,vargridcurgridtabvars(newvar->var,whichone)); |
---|
| 51 | } |
---|
| 52 | else newvar=newvar->suiv; |
---|
| 53 | } |
---|
| 54 | if ( out == 0 ) strcat(toprint,name); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /******************************************************************************/ |
---|
| 60 | /* ChangeTheInitalvaluebyTabvarsName */ |
---|
| 61 | /******************************************************************************/ |
---|
| 62 | /* */ |
---|
| 63 | /******************************************************************************/ |
---|
| 64 | /* */ |
---|
| 65 | /* */ |
---|
| 66 | /* */ |
---|
| 67 | /******************************************************************************/ |
---|
| 68 | char *ChangeTheInitalvaluebyTabvarsName(char *nom,listvar *listtoread, int whichone) |
---|
| 69 | { |
---|
| 70 | char toprinttmp[LONGNOM]; |
---|
| 71 | int i; |
---|
| 72 | char chartmp[2]; |
---|
| 73 | |
---|
| 74 | i=0; |
---|
| 75 | strcpy(toprintglob,""); |
---|
| 76 | strcpy(toprinttmp,""); |
---|
| 77 | /* */ |
---|
| 78 | while ( i < strlen(nom) ) |
---|
| 79 | { |
---|
| 80 | if ( nom[i] == '+' ) |
---|
| 81 | { |
---|
| 82 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 83 | strcpy(toprinttmp,""); |
---|
| 84 | strcat(toprintglob,"+"); |
---|
| 85 | } |
---|
| 86 | else if ( nom[i] == '-' ) |
---|
| 87 | { |
---|
| 88 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 89 | strcpy(toprinttmp,""); |
---|
| 90 | strcat(toprintglob,"-"); |
---|
| 91 | } |
---|
| 92 | else if ( nom[i] == '*' ) |
---|
| 93 | { |
---|
| 94 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 95 | strcpy(toprinttmp,""); |
---|
| 96 | strcat(toprintglob,"*"); |
---|
| 97 | } |
---|
| 98 | else if ( nom[i] == '/' ) |
---|
| 99 | { |
---|
| 100 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 101 | strcpy(toprinttmp,""); |
---|
| 102 | strcat(toprintglob,"/"); |
---|
| 103 | } |
---|
| 104 | else if ( nom[i] == '(' ) |
---|
| 105 | { |
---|
| 106 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 107 | strcpy(toprinttmp,""); |
---|
| 108 | strcat(toprintglob,"("); |
---|
| 109 | } |
---|
| 110 | else if ( nom[i] == ')' ) |
---|
| 111 | { |
---|
| 112 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 113 | strcpy(toprinttmp,""); |
---|
| 114 | strcat(toprintglob,")"); |
---|
| 115 | } |
---|
| 116 | else if ( nom[i] == ':' ) |
---|
| 117 | { |
---|
| 118 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 119 | strcpy(toprinttmp,""); |
---|
| 120 | strcat(toprintglob,":"); |
---|
| 121 | } |
---|
| 122 | else if ( nom[i] == ',' ) |
---|
| 123 | { |
---|
| 124 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 125 | strcpy(toprinttmp,""); |
---|
| 126 | strcat(toprintglob,","); |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | sprintf(chartmp,"%c",nom[i]); |
---|
| 131 | strcat(toprinttmp,chartmp); |
---|
| 132 | } |
---|
| 133 | /* */ |
---|
| 134 | i=i+1; |
---|
| 135 | } |
---|
| 136 | FindAndChangeNameToTabvars(toprinttmp,toprintglob,listtoread,whichone); |
---|
| 137 | strcpy(toprinttmp,""); |
---|
| 138 | |
---|
| 139 | /* */ |
---|
| 140 | return toprintglob; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | void IsVarInUseFile(char *nom) |
---|
| 145 | { |
---|
| 146 | listvar *parcours; |
---|
| 147 | listparameter *parcoursparam; |
---|
| 148 | int out; |
---|
| 149 | |
---|
| 150 | out = 0; |
---|
| 151 | |
---|
| 152 | parcours = globliste; |
---|
| 153 | while( parcours && out == 0 ) |
---|
| 154 | { |
---|
| 155 | if ( !strcasecmp(nom,parcours->var->nomvar) ) out =1 ; |
---|
| 156 | else parcours=parcours->suiv; |
---|
| 157 | } |
---|
| 158 | if ( out == 0 ) |
---|
| 159 | { |
---|
| 160 | parcours = globparam; |
---|
| 161 | while( parcours && out == 0 ) |
---|
| 162 | { |
---|
| 163 | if ( !strcasecmp(nom,parcours->var->nomvar) ) out =1 ; |
---|
| 164 | else parcours=parcours->suiv; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | if ( out == 0 ) |
---|
| 168 | { |
---|
| 169 | parcours = parameterlist; |
---|
| 170 | while( parcours && out == 0 ) |
---|
| 171 | { |
---|
| 172 | if ( !strcasecmp(nom,parcours->var->nomvar) ) out =1 ; |
---|
| 173 | else parcours=parcours->suiv; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | if ( out == 0 ) |
---|
| 177 | { |
---|
| 178 | parcoursparam = tmpparameterlocallist; |
---|
| 179 | while( parcoursparam && out == 0 ) |
---|
| 180 | { |
---|
| 181 | if ( !strcasecmp(nom,parcoursparam->name) ) out =2 ; |
---|
| 182 | else parcoursparam=parcoursparam->suiv; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | if ( out == 0 ) |
---|
| 186 | { |
---|
| 187 | parcours = globalvarofusefile; |
---|
| 188 | while( parcours && out == 0 ) |
---|
| 189 | { |
---|
| 190 | if ( !strcasecmp(nom,parcours->var->nomvar) ) out =2 ; |
---|
| 191 | else parcours=parcours->suiv; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | if ( out == 0 || out == 2 ) |
---|
| 195 | { |
---|
| 196 | parcoursparam = tmpparameterlocallist2; |
---|
| 197 | while( parcoursparam && out != 1 ) |
---|
| 198 | { |
---|
| 199 | if ( !strcasecmp(nom,parcoursparam->name) ) out =1 ; |
---|
| 200 | else parcoursparam=parcoursparam->suiv; |
---|
| 201 | } |
---|
| 202 | if ( out == 1 ) |
---|
| 203 | { |
---|
| 204 | strcpy(charusemodule,parcoursparam->modulename); |
---|
| 205 | Addmoduletothelist(parcoursparam->modulename); |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | if ( out == 0 ) printf("--- in UtilCharacter we do not found the \n"); |
---|
| 209 | if ( out == 0 ) printf("--- variable %s, the module where this \n",nom); |
---|
| 210 | if ( out == 0 ) printf("--- variable has been defined has not been\n"); |
---|
| 211 | if ( out == 0 ) printf("--- found.\n"); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | /******************************************************************************/ |
---|
| 215 | /* DecomposeTheNameinlistnom */ |
---|
| 216 | /******************************************************************************/ |
---|
| 217 | /* Firstpass 0 */ |
---|
| 218 | /******************************************************************************/ |
---|
| 219 | /* */ |
---|
| 220 | /* */ |
---|
| 221 | /******************************************************************************/ |
---|
| 222 | listnom *DecomposeTheNameinlistnom(char *nom, listnom * listout) |
---|
| 223 | { |
---|
| 224 | char toprinttmp[LONGNOM]; |
---|
| 225 | int i; |
---|
| 226 | char chartmp[2]; |
---|
| 227 | |
---|
| 228 | i=0; |
---|
| 229 | strcpy(toprinttmp,""); |
---|
| 230 | /* */ |
---|
| 231 | while ( i < strlen(nom) ) |
---|
| 232 | { |
---|
| 233 | if ( nom[i] == '+' || |
---|
| 234 | nom[i] == '-' || |
---|
| 235 | nom[i] == '*' || |
---|
| 236 | nom[i] == '/' || |
---|
| 237 | nom[i] == ')' || |
---|
| 238 | nom[i] == '(' || |
---|
| 239 | nom[i] == ',' || |
---|
| 240 | nom[i] == ':' |
---|
| 241 | ) |
---|
| 242 | { |
---|
| 243 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 244 | { |
---|
| 245 | listout = Addtolistnom(toprinttmp,listout); |
---|
| 246 | |
---|
| 247 | } |
---|
| 248 | strcpy(toprinttmp,""); |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | sprintf(chartmp,"%c",nom[i]); |
---|
| 253 | strcat(toprinttmp,chartmp); |
---|
| 254 | } |
---|
| 255 | /* */ |
---|
| 256 | i=i+1; |
---|
| 257 | } |
---|
| 258 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 259 | { |
---|
| 260 | listout = Addtolistnom(toprinttmp,listout); |
---|
| 261 | } |
---|
| 262 | strcpy(toprinttmp,""); |
---|
| 263 | |
---|
| 264 | return listout; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | /******************************************************************************/ |
---|
| 269 | /* DecomposeTheName */ |
---|
| 270 | /******************************************************************************/ |
---|
| 271 | /* Firstpass 0 */ |
---|
| 272 | /******************************************************************************/ |
---|
| 273 | /* */ |
---|
| 274 | /* Agrif_<toto>(variable) ====> Agrif_<toto>(variable) */ |
---|
| 275 | /* */ |
---|
| 276 | /******************************************************************************/ |
---|
| 277 | void DecomposeTheName(char *nom) |
---|
| 278 | { |
---|
| 279 | char toprinttmp[LONGNOM]; |
---|
| 280 | int i; |
---|
| 281 | char chartmp[2]; |
---|
| 282 | |
---|
| 283 | i=0; |
---|
| 284 | strcpy(toprinttmp,""); |
---|
| 285 | /* */ |
---|
| 286 | while ( i < strlen(nom) ) |
---|
| 287 | { |
---|
| 288 | if ( nom[i] == '+' || |
---|
| 289 | nom[i] == '-' || |
---|
| 290 | nom[i] == '*' || |
---|
| 291 | nom[i] == '/' || |
---|
| 292 | nom[i] == ')' || |
---|
| 293 | nom[i] == '(' || |
---|
| 294 | nom[i] == ',' || |
---|
| 295 | nom[i] == ':' |
---|
| 296 | ) |
---|
| 297 | { |
---|
| 298 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 299 | { |
---|
| 300 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 301 | /* Is this variable present in globvarofusefile */ |
---|
| 302 | IsVarInUseFile(toprinttmp); |
---|
| 303 | } |
---|
| 304 | strcpy(toprinttmp,""); |
---|
| 305 | } |
---|
| 306 | else |
---|
| 307 | { |
---|
| 308 | sprintf(chartmp,"%c",nom[i]); |
---|
| 309 | strcat(toprinttmp,chartmp); |
---|
| 310 | } |
---|
| 311 | /* */ |
---|
| 312 | i=i+1; |
---|
| 313 | } |
---|
| 314 | if (strcasecmp(toprinttmp,"") && ( toprinttmp[0] >= 'A' ) ) |
---|
| 315 | { |
---|
| 316 | ajoutevarindoloop_definedimension (toprinttmp); |
---|
| 317 | /* Is this variable present in globvarofusefile */ |
---|
| 318 | IsVarInUseFile(toprinttmp); |
---|
| 319 | } |
---|
| 320 | strcpy(toprinttmp,""); |
---|
| 321 | |
---|
| 322 | } |
---|