convert.y 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. %{
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include "decl.h"
  40. int line_num=1;
  41. extern FILE * convert_in;
  42. int convert_error(const char *s)
  43. {
  44. printf("##\n## ERROR in conv: '%s' (line %d, file: %s)\n##\n", s, line_num, config_file);
  45. exit(0);
  46. }
  47. %}
  48. %union {
  49. char na[LONG_M];
  50. }
  51. %token TOK_SEP
  52. %token TOK_KIND
  53. %token TOK_EQUAL
  54. %token TOK_USE
  55. %token TOK_MODULEMAIN /* name of the module */
  56. %token TOK_NOTGRIDDEP /* Variable which are not grid dependent */
  57. %token <na> TOK_USEITEM
  58. %token <na> TOK_NAME
  59. %token <na> TOK_CSTINT
  60. %token <na> TOK_PROBTYPE /* dimension of the problem */
  61. %token ','
  62. %token ';'
  63. %%
  64. input :
  65. | input line ;
  66. line :
  67. '\n'
  68. | TOK_PROBTYPE TOK_NAME ';' { initdimprob(1,$2,"0","0"); }
  69. | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ';' { initdimprob(2,$2, $4,"0"); }
  70. | TOK_PROBTYPE TOK_NAME ',' TOK_NAME ',' TOK_NAME ';' { initdimprob(3,$2, $4, $6); }
  71. | TOK_MODULEMAIN TOK_NAME ';'
  72. {
  73. listofmodules = Addtolistnom($2,listofmodules,0);
  74. Addmoduletothelist($2);
  75. }
  76. | TOK_KIND TOK_NAME TOK_EQUAL TOK_CSTINT ';'
  77. {
  78. if (!strcasecmp($4,"4"))
  79. {
  80. listofkind = Addtolistnom($2,listofkind,4);
  81. }
  82. else if (!strcasecmp($4,"8"))
  83. {
  84. listofkind = Addtolistnom($2,listofkind,8);
  85. }
  86. else
  87. {
  88. printf("##\n## Unknown kind type : %s (must be 4 or 8)\n##",$4);
  89. exit(0);
  90. }
  91. }
  92. | TOK_NOTGRIDDEP TOK_SEP TOK_NAME ';'
  93. {
  94. Add_NotGridDepend_Var_1($3);
  95. }
  96. | TOK_USE TOK_USEITEM ';'
  97. {
  98. if (!strcasecmp($2,"FIXED_GRIDS")) fixedgrids = 1;
  99. if (!strcasecmp($2,"ONLY_FIXED_GRIDS")) onlyfixedgrids = 1;
  100. }
  101. ;
  102. %%
  103. void print_usage()
  104. {
  105. printf("usage : conv <config_file> -convfile <FILENAME>\n");
  106. printf(" [-workdir <directory>] [-incdir <directory>]\n");
  107. printf(" [-comdirin <directory>] [-comdirout <directory>]\n");
  108. printf(" [-convfile <FILENAME>] [-SubloopScalar] [-SubloopScalar1] \n");
  109. printf(" [-free|-fixed]\n");
  110. exit(0);
  111. }
  112. int main(int argc,char *argv[])
  113. {
  114. extern FILE * convert_in ;
  115. FILE *dependglobaloutput;
  116. int i;
  117. listnom *parcours;
  118. listvar *newvar;
  119. int stylegiven = 0;
  120. int infreegiven ;
  121. int infixedgiven ;
  122. int lengthmainfile;
  123. char filetoparse[LONG_FNAME];
  124. /******************************************************************************/
  125. /* 1- Variables initialization */
  126. /******************************************************************************/
  127. List_Global_Var = (listvar *) NULL;
  128. List_GlobalParameter_Var = (listvar *) NULL;
  129. List_Common_Var = (listvar *) NULL;
  130. List_Allocate_Var = (listallocate *) NULL;
  131. List_SubroutineWhereAgrifUsed = (listnom *) NULL;
  132. List_Subroutine_For_Alloc = (listnom *) NULL;
  133. List_Include = (listusemodule *) NULL;
  134. List_NameOfModuleUsed = (listusemodule *) NULL;
  135. listofmoduletmp = (listusemodule *) NULL;
  136. List_SubroutineDeclaration_Var = (listvar *) NULL;
  137. List_UsedInSubroutine_Var = (listvar *) NULL;
  138. List_NotGridDepend_Var = (listvar *) NULL;
  139. Listofavailableindices = (listindice *) NULL;
  140. Listofavailableindices_glob = (listindice **) calloc(NB_CAT_VARIABLES,sizeof(listindice *));
  141. List_CouplePointed_Var = (listvarpointtovar *) NULL;
  142. List_ModuleUsed_Var = (listvar *) NULL;
  143. List_ModuleUsedInModuleUsed_Var = (listvar *) NULL;
  144. List_GlobParamModuleUsed_Var = (listparameter *) NULL;
  145. List_GlobParamModuleUsedInModuleUsed_Var = (listparameter *) NULL;
  146. List_SubroutineArgument_Var = (listvar *) NULL;
  147. List_FunctionType_Var = (listvar *) NULL;
  148. tmpuselocallist = (listusemodule *) NULL;
  149. List_ContainsSubroutine = (listnom *) NULL;
  150. oldfortran_out = (FILE *) NULL;
  151. if (argc < 2) print_usage();
  152. strcpy(config_file, argv[1]);
  153. strcpy(work_dir, ".");
  154. strcpy(input_dir, ".");
  155. strcpy(output_dir, "AGRIF_MODELFILES");
  156. strcpy(include_dir, "AGRIF_INC");
  157. strcpy(filetoparse, "");
  158. strcpy(subofagrifinitgrids, "");
  159. strcpy(meetagrifinitgrids, "");
  160. strcpy(mpiinitvar, "");
  161. length_last = 0 ;
  162. length_first = 0 ;
  163. length_v_vallengspec = 0 ;
  164. length_v_commoninfile = 0 ;
  165. length_v_precision = 0 ;
  166. length_v_IntentSpec = 0 ;
  167. length_v_initialvalue = 0 ;
  168. length_v_readedlistdimension = 0 ;
  169. length_a_nomvar = 0 ;
  170. length_toprintglob = 0 ;
  171. length_tmpvargridname = 0 ;
  172. length_ligne_Subloop = 0 ;
  173. length_toprint_utilagrif = 0 ;
  174. length_toprinttmp_utilchar = 0 ;
  175. length_ligne_writedecl = 0 ;
  176. length_newname_toamr = 0 ;
  177. length_newname_writedecl = 0 ;
  178. length_ligne_toamr = 0 ;
  179. length_tmpligne_writedecl = 0 ;
  180. value_char_size = 0 ;
  181. value_char_size1 = 0 ;
  182. value_char_size2 = 0 ;
  183. value_char_size3 = 0 ;
  184. inallocate = 0;
  185. infixed = 1;
  186. infree = 0;
  187. onlyfixedgrids=0;
  188. fixedgrids=0;
  189. InAgrifParentDef = 0;
  190. IndicenbmaillesX=0;
  191. IndicenbmaillesY=0;
  192. IndicenbmaillesZ=0;
  193. created_dimensionlist = 1;
  194. /* current indice in the table tabvars */
  195. for ( i=0 ; i<NB_CAT_VARIABLES ; i++)
  196. {
  197. indicemaxtabvars[i] = 0;
  198. }
  199. SubloopScalar = 0;
  200. todebug = 0;
  201. retour77 = 1 ;
  202. shouldincludempif = 0 ;
  203. Read_val_max();
  204. /******************************************************************************/
  205. /* 2- Program arguments */
  206. /******************************************************************************/
  207. if ( (convert_in=fopen(config_file,"r")) == NULL )
  208. {
  209. printf("##\n## ERROR: the configuration file '%s' doesn't exist.\n##\n", config_file);
  210. print_usage();
  211. }
  212. i=2;
  213. while ( i < argc )
  214. {
  215. if (!strcasecmp(argv[i], "-workdir"))
  216. {
  217. strcpy(work_dir,argv[i+1]);
  218. i++;
  219. }
  220. else if (!strcasecmp(argv[i], "-incdir"))
  221. {
  222. strcpy(include_dir,argv[i+1]);
  223. i++;
  224. }
  225. else if (!strcasecmp(argv[i], "-comdirin")) /* input directory */
  226. {
  227. strcpy(input_dir,argv[i+1]);
  228. i++;
  229. }
  230. else if (!strcasecmp(argv[i], "-comdirout")) /* output directory */
  231. {
  232. strcpy(output_dir,argv[i+1]);
  233. i++;
  234. }
  235. else if (!strcasecmp(argv[i], "-convfile")) /* file to parse */
  236. {
  237. strcpy(filetoparse, argv[i+1]);
  238. i++;
  239. lengthmainfile = strlen(filetoparse);
  240. if (!strcasecmp(&filetoparse[lengthmainfile-4], ".f90"))
  241. {
  242. infixed = 0;
  243. infree = 1;
  244. }
  245. else
  246. {
  247. infixed = 1;
  248. infree = 0;
  249. }
  250. }
  251. else if (!strcasecmp(argv[i], "-free"))
  252. {
  253. stylegiven = 1;
  254. infreegiven = 1 ;
  255. infixedgiven = 0;
  256. }
  257. else if (!strcasecmp(argv[i], "-fixed"))
  258. {
  259. stylegiven = 1;
  260. infreegiven = 0;
  261. infixedgiven = 1;
  262. }
  263. else if (!strcasecmp(argv[i], "-SubloopScalar"))
  264. {
  265. SubloopScalar = 1 ;
  266. }
  267. else if (!strcasecmp(argv[i], "-SubloopScalar1"))
  268. {
  269. SubloopScalar = 2 ;
  270. }
  271. else if (!strcasecmp(argv[i], "-todebug"))
  272. {
  273. todebug = 1 ;
  274. }
  275. else if (!strcasecmp(argv[i],"-rm")) { }
  276. else
  277. {
  278. printf("##\n## Unkwon option : %s\n##\n", argv[i]);
  279. exit(0);
  280. }
  281. i++;
  282. }
  283. // Check input file
  284. if ( strlen(filetoparse) == 0 ) // -convfile has not been specified
  285. {
  286. printf("##\n## ERROR: please provide a file to parse with -convfile.\n##\n");
  287. print_usage();
  288. }
  289. // Setup input & output directories
  290. if ( strcasecmp(work_dir, ".") != 0 ) // -workdir has been changed...
  291. {
  292. if ( strcasecmp(input_dir, ".") == 0 ) // ...and -comdirin has NOT been changed
  293. {
  294. strcpy(input_dir, work_dir);
  295. }
  296. if ( strcasecmp(output_dir, "AGRIF_MODELFILES") == 0 ) // ...and -comdirout has NOT been changed
  297. {
  298. sprintf(output_dir, "%s/%s", work_dir, "AGRIF_MODELFILES");
  299. }
  300. if ( strcasecmp(include_dir, "AGRIF_INC") == 0 ) // ...and -incdir has NOT been changed
  301. {
  302. sprintf(include_dir, "%s/%s", work_dir, "AGRIF_INC");
  303. }
  304. }
  305. if (stylegiven == 1)
  306. {
  307. infree = infreegiven;
  308. infixed = infixedgiven;
  309. }
  310. /******************************************************************************/
  311. /* 3- Parsing of the conv file <name>.in */
  312. /******************************************************************************/
  313. if ( strstr(filetoparse, ".f90") || strstr(filetoparse, ".F90") ) retour77 = 0;
  314. convert_parse();
  315. /******************************************************************************/
  316. /* 4- Preparation of the file parsing */
  317. /******************************************************************************/
  318. sprintf(dependfilename, "%s/.dependglobal_agrif", work_dir);
  319. /* */
  320. if ( (dependglobaloutput=fopen(dependfilename, "r")) != NULL )
  321. {
  322. for (i=0;i<NB_CAT_VARIABLES;i++)
  323. {
  324. fscanf(dependglobaloutput,"%d\n",&indicemaxtabvars[i]);
  325. }
  326. fclose(dependglobaloutput);
  327. }
  328. Readthedependavailablefile();
  329. /* Read the .dependnbxnby file which contains indices of nbmaillsX, nbmailleY and nbmailleZ */
  330. Readthedependnbxnbyfile();
  331. Read_Subroutine_For_Alloc();
  332. /******************************************************************************/
  333. /* 5- Parsing of the input file (2 times) */
  334. /******************************************************************************/
  335. /* Record all variables in list */
  336. firstpass = 1;
  337. process_fortran(filetoparse);
  338. CompleteThelistvarindoloop();
  339. /* Read list of module used */
  340. RecordUseModulesVariables();
  341. /* Read list of module used in module used */
  342. RecordUseModulesUseModulesVariables();
  343. /* Save variables are considered as globals ones */
  344. Update_List_Global_Var_From_List_Save_Var();
  345. /* Update all lists */
  346. ListUpdate();
  347. Clean_List_Global_Var();
  348. /* Indice tabvars identification */
  349. IndiceTabvarsIdentification();
  350. /* Update all lists */
  351. ListUpdate();
  352. /* The allocation subroutine is necessary ???? */
  353. New_Allocate_Subroutine_Is_Necessary();
  354. /* The allocation subroutine is necessary for common list */
  355. New_Allocate_Subroutine_For_Common_Is_Necessary();
  356. /* Sort List_SubroutineArgument_Var */
  357. Sort_List_SubroutineArgument_Var();
  358. /* Clean all lists */
  359. ListClean();
  360. /* Update Indice of List_UsedInSubroutine_Var from module used */
  361. List_UsedInSubroutine_Var_Update_From_Module_Used();
  362. /* Update List_SubroutineWhereAgrifUsed */
  363. UpdateList_SubroutineWhereAgrifUsed();
  364. /* Update List_UsedInSubroutine_Var with v_readedlistdimension */
  365. UpdateList_UsedInSubroutine_With_dimension();
  366. ModifyThelistvarindoloop();
  367. UpdateListDeclarationWithDimensionList();
  368. GiveTypeOfVariables();
  369. /* Build new subroutines */
  370. firstpass = 0;
  371. process_fortran(filetoparse);
  372. newvar = (listvar *) NULL;
  373. while ( newvar )
  374. {
  375. printf("++++ %s %d %s %s %s\n",
  376. newvar->var->v_nomvar,
  377. newvar->var->v_nbdim,
  378. newvar->var->v_subroutinename,
  379. newvar->var->v_modulename,
  380. newvar->var->v_typevar);
  381. newvar = newvar->suiv;
  382. }
  383. /******************************************************************************/
  384. /* 6- Write informations in output files */
  385. /******************************************************************************/
  386. /* Write the .dependglobal_agrif file which contain the max indice */
  387. /* of the tabvars table */
  388. sprintf(dependfilename, "%s/.dependglobal_agrif", work_dir);
  389. dependglobaloutput = fopen(dependfilename, "w");
  390. for (i=0;i<NB_CAT_VARIABLES;i++)
  391. {
  392. fprintf(dependglobaloutput,"%d\n",indicemaxtabvars[i]);
  393. }
  394. fclose(dependglobaloutput);
  395. /* Write the list of available indice */
  396. Writethedependavailablefile();
  397. /* Write the .dependnbxnby file which contains indices of nbmaillsX, */
  398. /* nbmailleY and nbmailleZ */
  399. Writethedependnbxnbyfile();
  400. /* Write the .depend<namefile> file which contain general informations */
  401. /* about variable of this file */
  402. parcours = List_NameOfModule;
  403. while( parcours )
  404. {
  405. Writethedependlistofmoduleused(parcours->o_nom);
  406. WritedependParameterList(parcours->o_nom);
  407. Writethedependfile(parcours->o_nom,List_Global_Var);
  408. parcours=parcours->suiv;
  409. }
  410. parcours = List_NameOfCommon;
  411. while( parcours )
  412. {
  413. Writethedependfile(parcours->o_nom,List_Common_Var);
  414. parcours=parcours->suiv;
  415. }
  416. Write_Subroutine_For_Alloc();
  417. /******************************************************************************/
  418. /* 7- Create files in AGRIF_INC directory */
  419. /******************************************************************************/
  420. creefichieramr();
  421. Write_val_max();
  422. if ( todebug == 1 ) printf("Out of CONV \n");
  423. return 0;
  424. }