[396] | 1 | /******************************************************************************/ |
---|
| 2 | /* */ |
---|
| 3 | /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */ |
---|
| 4 | /* */ |
---|
[530] | 5 | /* Copyright or © or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */ |
---|
[396] | 6 | /* Cyril Mazauric (Cyril.Mazauric@imag.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 | /******************************************************************************/ |
---|
[530] | 33 | /* version 1.0 */ |
---|
| 34 | /******************************************************************************/ |
---|
[396] | 35 | %{ |
---|
| 36 | #include <stdlib.h> |
---|
| 37 | #include <stdio.h> |
---|
| 38 | #include <string.h> |
---|
| 39 | #include "decl.h" |
---|
| 40 | %} |
---|
| 41 | |
---|
| 42 | %union { |
---|
| 43 | int ival; |
---|
| 44 | char na[LONGNOM]; |
---|
| 45 | listnom * ln; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | %token TOK_SEP |
---|
| 49 | %token TOK_USE |
---|
| 50 | %token TOK_MODULEMAIN /* name of the module */ |
---|
| 51 | %token TOK_NOTGRIDDEP /* Variable which are not grid dependent */ |
---|
| 52 | %token <na> TOK_USEITEM |
---|
| 53 | %token <na> TOK_NAME |
---|
| 54 | %token <na> TOK_PROBTYPE /* dimension of the problem */ |
---|
| 55 | %token ',' |
---|
| 56 | %token ';' |
---|
| 57 | %token ':' |
---|
| 58 | %token '(' |
---|
| 59 | %token ')' |
---|
| 60 | %token '[' |
---|
| 61 | %token ']' |
---|
| 62 | %% |
---|
| 63 | input : |
---|
| 64 | | input line |
---|
| 65 | ; |
---|
| 66 | line :'\n' |
---|
| 67 | | TOK_PROBTYPE TOK_NAME ';' {initdimprob(1,$2,"0","0");} |
---|
| 68 | | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';' {initdimprob(2,$2, $4,"0");} |
---|
| 69 | | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';' |
---|
| 70 | {initdimprob(3,$2, $4, $6);} |
---|
[530] | 71 | | TOK_MODULEMAIN TOK_NAME ';' |
---|
| 72 | {listofmodules = Addtolistnom($2,listofmodules); |
---|
| 73 | Addmoduletothelist($2);} |
---|
[396] | 74 | | TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';' {ajoutenotgriddep($3);} |
---|
| 75 | | TOK_USE TOK_USEITEM ';' { |
---|
| 76 | if (!strcasecmp($2,"FIXED_GRIDS")) |
---|
| 77 | fixedgrids=1; |
---|
| 78 | if (!strcasecmp($2,"ONLY_FIXED_GRIDS")) |
---|
| 79 | onlyfixedgrids=1; |
---|
| 80 | if (!strcasecmp($2,"DEBUG")) todebug=1; |
---|
| 81 | } |
---|
| 82 | ; |
---|
| 83 | %% |
---|
| 84 | |
---|
| 85 | int main(int argc,char *argv[]) |
---|
| 86 | { |
---|
| 87 | extern FILE * yyin ; |
---|
| 88 | FILE *dependglobaloutput; |
---|
| 89 | char *tmp; |
---|
| 90 | int i; |
---|
| 91 | listnom *parcours; |
---|
| 92 | |
---|
[530] | 93 | if (argc < 2) |
---|
| 94 | { |
---|
| 95 | printf("usage : conv <file> [-rm] [-incdir <directory>] \n"); |
---|
| 96 | printf(" [-comdirin <directory>] [-comdirout <directory>]\n"); |
---|
| 97 | printf(" [-convfile <FILENAME >] -SubloopScalar -SubloopScalar1 \n"); |
---|
| 98 | printf(" -f77\n"); |
---|
| 99 | exit(0); |
---|
| 100 | } |
---|
[396] | 101 | /******************************************************************************/ |
---|
| 102 | /* 1- Variables initialization */ |
---|
| 103 | /******************************************************************************/ |
---|
| 104 | globliste=(listvar *)NULL; |
---|
| 105 | listenamelist=(listnamelist *)NULL; |
---|
| 106 | globparam=(listvar *)NULL; |
---|
| 107 | AllocateList=(listallocate *)NULL; |
---|
| 108 | commonlist=(listvarcommon *)NULL; |
---|
| 109 | listofsubroutinewhereagrifisused=(listnom *)NULL; |
---|
| 110 | listofincludebysubroutine=(listusemodule *)NULL; |
---|
| 111 | listofmodulebysubroutine=(listusemodule *)NULL; |
---|
| 112 | listofmoduletmp=(listusemodule *)NULL; |
---|
| 113 | listmoduleinfile=(listmodule *)NULL; |
---|
| 114 | varofsubroutineliste=(listvar *)NULL; |
---|
| 115 | varsubroutine=(listvar *)NULL; |
---|
| 116 | listvarindoloop=(listvar *)NULL; |
---|
| 117 | listenotgriddepend=(listvar *)NULL; |
---|
| 118 | Listofavailableindices=(listindice *)NULL; |
---|
| 119 | Listofvarpointtovar=(listvarpointtovar *)NULL; |
---|
| 120 | globalvarofusefile = (listvar *)NULL; |
---|
| 121 | globalvarofusefile2 = (listvar *)NULL; |
---|
[530] | 122 | tmpparameterlocallist = (listparameter *)NULL; |
---|
| 123 | tmpparameterlocallist2 = (listparameter *)NULL; |
---|
[396] | 124 | |
---|
| 125 | strcpy(mainfile,argv[1]); |
---|
| 126 | strcpy(nomdir,"AGRIF_INC"); |
---|
| 127 | strcpy(commondirin,"."); |
---|
| 128 | strcpy(commondirout,"."); |
---|
| 129 | strcpy(filetoparse," "); |
---|
| 130 | strcpy(subofagrifinitgrids,""); |
---|
| 131 | strcpy(meetagrifinitgrids,""); |
---|
| 132 | strcpy(meetmpiinit,""); |
---|
| 133 | strcpy(mpiinitvar,""); |
---|
| 134 | |
---|
| 135 | listofvarofusemodulecreated=0; |
---|
| 136 | checkexistcommon=1; |
---|
| 137 | fortran77 = 0 ; |
---|
| 138 | Did_filetoparse_treated = 0 ; |
---|
| 139 | todebug=0; |
---|
| 140 | onlyfixedgrids=0; |
---|
| 141 | fixedgrids=0; |
---|
| 142 | InAgrifParentDef = 0; |
---|
| 143 | IndicenbmaillesX=0; |
---|
| 144 | IndicenbmaillesY=0; |
---|
| 145 | IndicenbmaillesZ=0; |
---|
[530] | 146 | created_dimensionlist = 1; |
---|
[396] | 147 | indicemaxtabvars = 0; /* current indice in the table tabvars */ |
---|
| 148 | oldindicemaxtabvars = 0;/* current indice in the table tabvars */ |
---|
| 149 | SubloopScalar = 0; |
---|
| 150 | /******************************************************************************/ |
---|
| 151 | /* 2- Program arguments */ |
---|
| 152 | /******************************************************************************/ |
---|
| 153 | |
---|
| 154 | if ((yyin=fopen(argv[1],"r"))==NULL) |
---|
| 155 | { |
---|
| 156 | printf("the file %s doesn't exist \n",argv[1]); |
---|
| 157 | exit(0); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | i=2; |
---|
| 161 | while (i<argc) |
---|
| 162 | { |
---|
| 163 | if (!strcasecmp(argv[i],"-incdir")) |
---|
| 164 | { |
---|
| 165 | strcpy(nomdir,argv[i+1]); |
---|
| 166 | i++; |
---|
| 167 | } |
---|
| 168 | else if (!strcasecmp(argv[i],"-comdirin")) /* input directory */ |
---|
| 169 | { |
---|
| 170 | strcpy(commondirin,argv[i+1]); |
---|
| 171 | i++; |
---|
| 172 | } |
---|
| 173 | else if (!strcasecmp(argv[i],"-comdirout")) /* output directory */ |
---|
| 174 | { |
---|
| 175 | strcpy(commondirout,argv[i+1]); |
---|
| 176 | i++; |
---|
| 177 | } |
---|
| 178 | else if (!strcasecmp(argv[i],"-convfile")) /* file to parse */ |
---|
| 179 | { |
---|
| 180 | strcpy(filetoparse,argv[i+1]); |
---|
| 181 | i++; |
---|
| 182 | } |
---|
| 183 | else if (!strcasecmp(argv[i],"-f77")) /* fortran 77 file to parse */ |
---|
| 184 | { |
---|
| 185 | fortran77 = 1 ; |
---|
| 186 | } |
---|
| 187 | else if (!strcasecmp(argv[i],"-SubloopScalar")) /* file to parse */ |
---|
| 188 | { |
---|
| 189 | SubloopScalar = 1 ; |
---|
| 190 | } |
---|
| 191 | else if (!strcasecmp(argv[i],"-SubloopScalar1")) /* file to parse */ |
---|
| 192 | { |
---|
| 193 | SubloopScalar = 2 ; |
---|
| 194 | } |
---|
| 195 | else if (!strcasecmp(argv[i],"-rm")) |
---|
| 196 | { |
---|
| 197 | checkexistcommon=0; |
---|
| 198 | } |
---|
| 199 | else |
---|
| 200 | { |
---|
| 201 | printf("Unkwon option : %s\n",argv[i]); |
---|
| 202 | exit(0); |
---|
| 203 | } |
---|
| 204 | i++; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | /******************************************************************************/ |
---|
| 208 | /* 3- Parsing of the conv file <name>.in */ |
---|
| 209 | /******************************************************************************/ |
---|
| 210 | |
---|
| 211 | if ((yyin=fopen(argv[1],"r"))==NULL) |
---|
| 212 | { |
---|
| 213 | printf("the file %s doesn't exist \n",argv[1]); |
---|
| 214 | exit(0); |
---|
| 215 | } |
---|
| 216 | strcpy(mainfile,argv[1]); |
---|
| 217 | |
---|
| 218 | yyparse(); |
---|
| 219 | |
---|
| 220 | /******************************************************************************/ |
---|
| 221 | /* 4- Preparation of the file parsing */ |
---|
| 222 | /******************************************************************************/ |
---|
| 223 | if ((yyin=fopen(filetoparse,"r"))==NULL) /* Is the file to parse exist ? */ |
---|
| 224 | { |
---|
| 225 | printf("the file %s doesn't exist \n",filetoparse); |
---|
| 226 | exit(0); |
---|
| 227 | } |
---|
| 228 | /* NameTamponfile : the name of the model file extract from the name */ |
---|
| 229 | /* of agrif_module_<NameTamponfile> */ |
---|
| 230 | tmp = strchr(filetoparse, '.'); |
---|
| 231 | NameTamponfile=(char *)malloc( |
---|
| 232 | (strlen(filetoparse)-strlen(tmp)+1)*sizeof(char)); |
---|
| 233 | strncpy(NameTamponfile,filetoparse,strlen(filetoparse)-strlen(tmp)+1); |
---|
| 234 | strcpy (&NameTamponfile[strlen(filetoparse)-strlen(tmp)], "\0"); |
---|
| 235 | /* mainfile : the name of the file to parse */ |
---|
| 236 | strcpy(mainfile,filetoparse); |
---|
| 237 | /* We should verify that this file has not been read before */ |
---|
| 238 | /* if it is the case we record the old globliste in the tmplocallist */ |
---|
[530] | 239 | tmplocallist = (listvar *)NULL; |
---|
| 240 | tmpuselocallist = (listusemodule *)NULL; |
---|
[396] | 241 | Did_filetoparse_treated = Did_filetoparse_readed(NameTamponfile); |
---|
| 242 | /* if Did_filetoparse_treated = 1 then the file to parse has been treated */ |
---|
| 243 | if ( Did_filetoparse_treated == 0 ) |
---|
| 244 | { |
---|
| 245 | /* if the filetoparse has not been treated, we should know the last */ |
---|
| 246 | /* tabvars indices which has been used */ |
---|
| 247 | if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) |
---|
| 248 | { |
---|
| 249 | fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars); |
---|
| 250 | fclose(dependglobaloutput); |
---|
| 251 | oldindicemaxtabvars = indicemaxtabvars; |
---|
| 252 | } |
---|
| 253 | } |
---|
[530] | 254 | /* Read the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
[396] | 255 | /* nbmailleY and nbmailleZ */ |
---|
| 256 | Readthedependnbxnbyfile(); |
---|
| 257 | |
---|
| 258 | /******************************************************************************/ |
---|
| 259 | /* 4- Parsing of the input file (2 times) */ |
---|
| 260 | /******************************************************************************/ |
---|
| 261 | |
---|
| 262 | firstpass = 1; |
---|
| 263 | processfortran(filetoparse); |
---|
| 264 | firstpass = 0; |
---|
| 265 | processfortran(filetoparse); |
---|
| 266 | |
---|
| 267 | /******************************************************************************/ |
---|
| 268 | /* 5- Write informations in output files */ |
---|
| 269 | /******************************************************************************/ |
---|
| 270 | |
---|
| 271 | if ( Did_filetoparse_treated == 0 ) /* if the file has never been treated */ |
---|
| 272 | { |
---|
| 273 | /* Write the .dependglobal file which contain the max indice */ |
---|
| 274 | /* of the tabvars table */ |
---|
| 275 | dependglobaloutput = fopen(".dependglobal","w"); |
---|
| 276 | fprintf(dependglobaloutput,"%d\n",indicemaxtabvars); |
---|
| 277 | fclose(dependglobaloutput); |
---|
| 278 | /* Write the .depend<namefile> file which contain general informations */ |
---|
| 279 | /* about variable of this file */ |
---|
| 280 | parcours = modulelist; |
---|
| 281 | while( parcours ) |
---|
| 282 | { |
---|
| 283 | Writethedependfile(parcours->nom,globliste); |
---|
| 284 | parcours=parcours->suiv; |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | /******************************************************************************/ |
---|
| 289 | /* 7- Remove the non grid dependent variables */ |
---|
| 290 | /******************************************************************************/ |
---|
| 291 | |
---|
| 292 | /* we should remove from the globliste the non grid dependent variables */ |
---|
| 293 | RemoveNotgriddependFromGlobliste(); |
---|
| 294 | |
---|
| 295 | /******************************************************************************/ |
---|
| 296 | /* 8- Write informations in output files */ |
---|
| 297 | /******************************************************************************/ |
---|
| 298 | |
---|
| 299 | /* if this file has been treated in past called, */ |
---|
| 300 | /* we should compare the old parsing (record in the tmplocallist) */ |
---|
| 301 | /* and the new one contained in the globliste */ |
---|
| 302 | if ( Did_filetoparse_treated == 1 ) |
---|
| 303 | { |
---|
| 304 | parcours = modulelist; |
---|
| 305 | while( parcours ) |
---|
| 306 | { |
---|
[530] | 307 | tmplocallist= Readthedependfile( parcours->nom ,tmplocallist ); |
---|
[396] | 308 | parcours=parcours->suiv; |
---|
| 309 | } |
---|
| 310 | /* if the filetoparse has not been treated, we should know */ |
---|
| 311 | /* the last tabvars indices which has been used */ |
---|
| 312 | if ((dependglobaloutput=fopen(".dependglobal","r"))!=NULL) |
---|
| 313 | { |
---|
| 314 | fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars); |
---|
| 315 | fclose(dependglobaloutput); |
---|
| 316 | oldindicemaxtabvars = indicemaxtabvars; |
---|
| 317 | } |
---|
| 318 | /* Read the list of available indice */ |
---|
| 319 | Readthedependavailablefile(); |
---|
| 320 | /* the old treatement has been recorded in the tmplocallist */ |
---|
| 321 | /* Now we should compare the old treatement with the new one */ |
---|
| 322 | /*mazauric for each module */ |
---|
| 323 | CompareNewparsingandoldone(); |
---|
| 324 | /* Write the .dependglobal file which contain general informations */ |
---|
| 325 | /* about globlist */ |
---|
| 326 | dependglobaloutput = fopen(".dependglobal","w"); |
---|
| 327 | fprintf(dependglobaloutput,"%d\n",indicemaxtabvars); |
---|
| 328 | fclose(dependglobaloutput); |
---|
| 329 | /* Write the list of available indice */ |
---|
| 330 | Writethedependavailablefile(); |
---|
| 331 | /* Write the .depend<namefile> file which contain general */ |
---|
| 332 | /* informations about variable of this file */ |
---|
| 333 | parcours = modulelist; |
---|
| 334 | while( parcours ) |
---|
| 335 | { |
---|
| 336 | Writethedependfile(parcours->nom,globliste); |
---|
| 337 | parcours=parcours->suiv; |
---|
| 338 | } |
---|
| 339 | /* Write the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
| 340 | /* nbmailleY and nbmailleZ */ |
---|
| 341 | Writethedependnbxnbyfile(); |
---|
| 342 | } |
---|
| 343 | /* Write the .dependnbxnby file which contains indices of nbmaillsX, */ |
---|
| 344 | /* nbmailleY and nbmailleZ */ |
---|
| 345 | Writethedependnbxnbyfile(); |
---|
| 346 | /* Write the list of module used in this file */ |
---|
| 347 | Writethedependlistofmoduleused(NameTamponfile); |
---|
| 348 | WritedependParameterList(NameTamponfile); |
---|
| 349 | /******************************************************************************/ |
---|
| 350 | /* 8- Create files in AGRIF_INC directory */ |
---|
| 351 | /******************************************************************************/ |
---|
| 352 | creefichieramr(NameTamponfile); |
---|
[530] | 353 | if ( todebug == 1 ) deallocation_all(); |
---|
[396] | 354 | return 0; |
---|
| 355 | } |
---|