toamr.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include "decl.h"
  39. const char * tabvarsname(const variable *var)
  40. {
  41. static char * tname[5] = {
  42. "tabvars", // v_catvar == 0
  43. "tabvars_c", // v_catvar == 1
  44. "tabvars_r", // v_catvar == 2
  45. "tabvars_l", // v_catvar == 3
  46. "tabvars_i" // v_catvar == 4
  47. };
  48. return tname[var->v_catvar]; // v_catvar should never be ouside the range [0:4].
  49. }
  50. /******************************************************************************/
  51. /* variablecurgridtabvars */
  52. /******************************************************************************/
  53. /* This subroutine is used to create the string */
  54. /******************************************************************************/
  55. /* */
  56. /* -----------> Agrif_Curgrid % tabvars (i) */
  57. /* */
  58. /******************************************************************************/
  59. const char * variablecurgridtabvars(int which_grid)
  60. {
  61. static char * varname[4] = {
  62. " Agrif_%s(%d)", // which_grid == 0
  63. " Agrif_%s(%d) %% parent_var", // which_grid == 1
  64. " Agrif_Mygrid %% %s(%d)", // which_grid == 2
  65. " Agrif_Curgrid %% %s(%d)", // which_grid == 3
  66. };
  67. return varname[which_grid];
  68. }
  69. void WARNING_CharSize(const variable *var)
  70. {
  71. if ( var->v_nbdim == 0 )
  72. {
  73. if ( convert2int(var->v_dimchar) > 2400 )
  74. {
  75. printf("WARNING : The dimension of the character %s \n", var->v_nomvar);
  76. printf(" is upper than 2400. You must change \n");
  77. printf(" the dimension of carray0 \n");
  78. printf(" in the file AGRIF/AGRIF_FILES/modtypes.F90 \n");
  79. printf(" line 161. Replace 2400 with %d. \n", convert2int(var->v_dimchar)+100);
  80. }
  81. Save_Length_int(convert2int(var->v_dimchar),1);
  82. }
  83. else if ( var->v_nbdim == 1 )
  84. {
  85. if ( convert2int(var->v_dimchar) > 200 )
  86. {
  87. printf("WARNING : The dimension of the character %s \n", var->v_nomvar);
  88. printf(" is upper than 200. You must change \n");
  89. printf(" the dimension of carray1 \n");
  90. printf(" in the file AGRIF/AGRIF_FILES/modtypes.F90 \n");
  91. printf(" line 162. Replace 200 with %d. \n", convert2int(var->v_dimchar)+100);
  92. }
  93. Save_Length_int(convert2int(var->v_dimchar),2);
  94. }
  95. else if ( var->v_nbdim == 2 )
  96. {
  97. if ( convert2int(var->v_dimchar) > 200 )
  98. {
  99. printf("WARNING : The dimension of the character %s \n", var->v_nomvar);
  100. printf(" is upper than 200. You must change \n");
  101. printf(" the dimension of carray2 \n");
  102. printf(" in the file AGRIF/AGRIF_FILES/modtypes.F90 \n");
  103. printf(" line 163. Replace 200 with %d. \n", convert2int(var->v_dimchar)+100);
  104. }
  105. Save_Length_int(convert2int(var->v_dimchar),3);
  106. }
  107. else if ( var->v_nbdim == 3 )
  108. {
  109. if ( convert2int(var->v_dimchar) > 200 )
  110. {
  111. printf("WARNING : The dimension of the character %s \n", var->v_nomvar);
  112. printf(" is upper than 200. You must change \n");
  113. printf(" the dimension of carray3 \n");
  114. printf(" in the file AGRIF/AGRIF_FILES/modtypes.F90 \n");
  115. printf(" line 164. Replace 200 with %d. \n", convert2int(var->v_dimchar)+100);
  116. }
  117. Save_Length_int(convert2int(var->v_dimchar),4);
  118. }
  119. }
  120. /******************************************************************************/
  121. /* vargridnametabvars */
  122. /******************************************************************************/
  123. /* This subroutine is used to create the string */
  124. /******************************************************************************/
  125. /* */
  126. /* if iorindice == 0 -----------> Agrif_Gr % tabvars (i) % array1 */
  127. /* */
  128. /* if iorindice == 1 -----------> Agrif_Gr % tabvars (12) % array1 */
  129. /* */
  130. /******************************************************************************/
  131. const char *vargridnametabvars (const variable * var, int iorindice)
  132. {
  133. static char tname_1[LONG_C];
  134. static char tname_2[LONG_C];
  135. if ( iorindice == 0 ) sprintf(tname_1, "Agrif_Gr %% %s(%d)", tabvarsname(var), var->v_indicetabvars);
  136. else sprintf(tname_1, "Agrif_Gr %% %s(i)", tabvarsname(var));
  137. if (!strcasecmp(var->v_typevar, "REAL"))
  138. {
  139. if ( !strcasecmp(var->v_nameinttypename,"8") ) sprintf(tname_2, "%% darray%d", var->v_nbdim);
  140. else if ( !strcasecmp(var->v_nameinttypename,"4") ) sprintf(tname_2, "%% sarray%d", var->v_nbdim);
  141. else sprintf(tname_2, "%% array%d", var->v_nbdim);
  142. }
  143. else if (!strcasecmp(var->v_typevar, "integer"))
  144. {
  145. sprintf(tname_2, "%% iarray%d", var->v_nbdim);
  146. }
  147. else if (!strcasecmp(var->v_typevar, "logical"))
  148. {
  149. sprintf(tname_2, "%% larray%d", var->v_nbdim);
  150. }
  151. else if (!strcasecmp(var->v_typevar, "character"))
  152. {
  153. WARNING_CharSize(var);
  154. sprintf (tname_2, "%% carray%d", var->v_nbdim);
  155. }
  156. strcat(tname_1, tname_2);
  157. Save_Length(tname_1, 46);
  158. return tname_1;
  159. }
  160. /******************************************************************************/
  161. /* vargridcurgridtabvars */
  162. /******************************************************************************/
  163. /* This subroutine is used to create the string */
  164. /******************************************************************************/
  165. /* */
  166. /* if which_grid == 0 --> Agrif_Curgrid % tabvars (i) % array1 */
  167. /* */
  168. /* if which_grid == 1 --> Agrif_tabvars (i) % parent_var % array1 */
  169. /* */
  170. /* if which_grid == 2 --> Agrif_Gr % tabvars (i) % array1 */
  171. /* */
  172. /******************************************************************************/
  173. const char *vargridcurgridtabvars(const variable *var, int which_grid)
  174. {
  175. static char tname_1[LONG_C];
  176. static char tname_2[LONG_C];
  177. if (!strcasecmp(var->v_typevar,"type"))
  178. {
  179. sprintf(tname_1, "Agrif_%s_var(Agrif_Curgrid%%fixedrank)%%%s", var->v_modulename, var->v_nomvar);
  180. }
  181. else
  182. {
  183. sprintf(tname_1, variablecurgridtabvars(which_grid), tabvarsname(var), var->v_indicetabvars);
  184. if (!strcasecmp(var->v_typevar, "REAL"))
  185. {
  186. if ( !strcasecmp(var->v_nameinttypename,"8") ) sprintf(tname_2, "%% darray%d", var->v_nbdim);
  187. else if ( !strcasecmp(var->v_nameinttypename,"4") ) sprintf(tname_2, "%% sarray%d", var->v_nbdim);
  188. else sprintf(tname_2, "%% array%d", var->v_nbdim);
  189. }
  190. else if (!strcasecmp(var->v_typevar, "INTEGER"))
  191. {
  192. sprintf(tname_2, "%% iarray%d", var->v_nbdim);
  193. }
  194. else if (!strcasecmp(var->v_typevar, "LOGICAL"))
  195. {
  196. sprintf(tname_2, "%% larray%d", var->v_nbdim);
  197. }
  198. else if (!strcasecmp(var->v_typevar, "CHARACTER"))
  199. {
  200. WARNING_CharSize(var);
  201. sprintf(tname_2, "%% carray%d", var->v_nbdim);
  202. }
  203. strcat(tname_1, tname_2);
  204. }
  205. Save_Length(tname_1, 46);
  206. return tname_1;
  207. }
  208. /******************************************************************************/
  209. /* vargridcurgridtabvarswithoutAgrif_Gr */
  210. /******************************************************************************/
  211. /* This subroutine is used to create the string */
  212. /******************************************************************************/
  213. /* */
  214. /******************************************************************************/
  215. const char *vargridcurgridtabvarswithoutAgrif_Gr(const variable *var)
  216. {
  217. static char tname_1[LONG_C];
  218. static char tname_2[LONG_C];
  219. sprintf(tname_1, "(%d)", var->v_indicetabvars);
  220. if (!strcasecmp (var->v_typevar, "REAL"))
  221. {
  222. if ( !strcasecmp(var->v_nameinttypename,"8") ) sprintf(tname_2, "%% darray%d", var->v_nbdim);
  223. else if ( !strcasecmp(var->v_nameinttypename,"4") ) sprintf(tname_2, "%% sarray%d", var->v_nbdim);
  224. else sprintf(tname_2, "%% array%d", var->v_nbdim);
  225. }
  226. else if (!strcasecmp(var->v_typevar, "INTEGER"))
  227. {
  228. sprintf(tname_2, "%% iarray%d", var->v_nbdim);
  229. }
  230. else if (!strcasecmp(var->v_typevar, "LOGICAL"))
  231. {
  232. sprintf(tname_2, "%% larray%d", var->v_nbdim);
  233. }
  234. else if (!strcasecmp(var->v_typevar, "CHARACTER"))
  235. {
  236. WARNING_CharSize(var);
  237. sprintf(tname_2, "%% carray%d", var->v_nbdim);
  238. }
  239. strcat(tname_1, tname_2);
  240. Save_Length(tname_1, 46);
  241. return tname_1;
  242. }
  243. /******************************************************************************/
  244. /* vargridparam */
  245. /******************************************************************************/
  246. /* This subroutine is used to create the string which contains */
  247. /* dimension list */
  248. /******************************************************************************/
  249. /* */
  250. /* DIMENSION(jpi,0:jpj) ----------->"1:jpi,0:jpj" */
  251. /* */
  252. /******************************************************************************/
  253. const char * vargridparam(const variable *var)
  254. {
  255. typedim dim;
  256. listdim *newdim;
  257. char newname[LONG_M];
  258. newdim = var->v_dimension;
  259. if (!newdim) return "";
  260. strcpy (tmpvargridname, "(");
  261. while (newdim)
  262. {
  263. dim = newdim->dim;
  264. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.first,List_Global_Var));
  265. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(newname,List_Common_Var));
  266. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(newname,List_ModuleUsed_Var));
  267. strcat(tmpvargridname, newname);
  268. strcat(tmpvargridname, " : ");
  269. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(dim.last,List_Global_Var));
  270. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(newname, List_Common_Var));
  271. strcpy(newname,ChangeTheInitalvaluebyTabvarsName(newname, List_ModuleUsed_Var));
  272. strcat(tmpvargridname, newname);
  273. newdim = newdim->suiv;
  274. if (newdim) strcat(tmpvargridname, ",");
  275. }
  276. strcat(tmpvargridname, ")\0");
  277. Save_Length(tmpvargridname,40);
  278. return tmpvargridname;
  279. }
  280. /******************************************************************************/
  281. /* write_probdimagrif_file */
  282. /******************************************************************************/
  283. /* This subroutine is used to create the file probdim_agrif.h */
  284. /******************************************************************************/
  285. /* */
  286. /* probdim_agrif.h */
  287. /* */
  288. /* Agrif_probdim = <number> */
  289. /* */
  290. /******************************************************************************/
  291. void write_probdimagrif_file()
  292. {
  293. FILE *probdim;
  294. char ligne[LONG_M];
  295. probdim = open_for_write("probdim_agrif.h");
  296. sprintf (ligne, "Agrif_Probdim = %d", dimprob);
  297. tofich (probdim, ligne,1);
  298. fclose (probdim);
  299. }
  300. /******************************************************************************/
  301. /* write_keysagrif_file */
  302. /******************************************************************************/
  303. /* This subroutine is used to create the file keys_agrif.h */
  304. /******************************************************************************/
  305. /* */
  306. /* keys_agrif.h */
  307. /* */
  308. /* AGRIF_USE_FIXED_GRIDS = 0 */
  309. /* AGRIF_USE_ONLY_FIXED_GRIDS = 0 */
  310. /* AGRIF_USE_(ONLY)_FIXED_GRIDS = 1 */
  311. /* */
  312. /******************************************************************************/
  313. void write_keysagrif_file()
  314. {
  315. FILE *keys;
  316. keys = open_for_write("keys_agrif.h");
  317. fprintf(keys," AGRIF_USE_FIXED_GRIDS = %d\n", fixedgrids);
  318. fprintf(keys," AGRIF_USE_ONLY_FIXED_GRIDS = %d\n", onlyfixedgrids);
  319. fclose(keys);
  320. }
  321. /******************************************************************************/
  322. /* write_modtypeagrif_file */
  323. /******************************************************************************/
  324. /* This subroutine is used to create the file typedata */
  325. /******************************************************************************/
  326. /* */
  327. /* modtype_agrif.h */
  328. /* */
  329. /* Agrif_NbVariables = */
  330. /* */
  331. /******************************************************************************/
  332. void write_modtypeagrif_file()
  333. {
  334. char ligne[LONG_M];
  335. FILE *typedata;
  336. int i;
  337. typedata = open_for_write("modtype_agrif.h");
  338. /* AGRIF_NbVariables : number of variables */
  339. for (i=0;i<NB_CAT_VARIABLES;i++)
  340. {
  341. sprintf (ligne, "Agrif_NbVariables(%d) = %d",i,indicemaxtabvars[i]);
  342. tofich(typedata,ligne,1);
  343. }
  344. fclose (typedata);
  345. }
  346. /******************************************************************************/
  347. /* write_createvarnameagrif_file */
  348. /******************************************************************************/
  349. /* This subroutine is used to create the file createvarname */
  350. /******************************************************************************/
  351. /* */
  352. /* Agrif_Gr % tabvars (i) % namevar = "variable" */
  353. /* */
  354. /******************************************************************************/
  355. void write_createvarnameagrif_file(variable *v,FILE *createvarname, int *InitEmpty)
  356. {
  357. char ligne[LONG_M];
  358. *InitEmpty = 0 ;
  359. sprintf(ligne, "Agrif_Gr %% %s(%d) %% namevar = \"%s\"",tabvarsname(v),v->v_indicetabvars,v->v_nomvar);
  360. tofich(createvarname,ligne,1);
  361. }
  362. /******************************************************************************/
  363. /* write_Setnumberofcells_file */
  364. /******************************************************************************/
  365. /* This subroutine is used to create the file setnumberofcells */
  366. /******************************************************************************/
  367. /* */
  368. /* Agrif_Gr % n(i) = nbmailles */
  369. /* */
  370. /******************************************************************************/
  371. void write_Setnumberofcells_file()
  372. {
  373. char ligne[LONG_VNAME];
  374. char cformat[LONG_VNAME];
  375. FILE *setnumberofcells;
  376. if ( IndicenbmaillesX == 0 ) return;
  377. setnumberofcells = open_for_write("SetNumberofcells.h");
  378. if ( onlyfixedgrids == 1 )
  379. strcpy(cformat, "Agrif_Gr %% nb(%d) = Agrif_Curgrid %% tabvars_i(%d) %% iarray0");
  380. else
  381. strcpy(cformat, "Agrif_Gr %% nb(%d) = Agrif_Gr %% tabvars_i(%d) %% iarray0");
  382. sprintf(ligne, cformat, 1, IndicenbmaillesX);
  383. tofich(setnumberofcells, ligne, 1);
  384. if ( dimprob > 1 )
  385. {
  386. sprintf(ligne, cformat, 2, IndicenbmaillesY);
  387. tofich(setnumberofcells, ligne, 1);
  388. }
  389. if ( dimprob > 2 )
  390. {
  391. sprintf(ligne, cformat, 3, IndicenbmaillesZ);
  392. tofich(setnumberofcells, ligne, 1);
  393. }
  394. fclose(setnumberofcells);
  395. }
  396. /******************************************************************************/
  397. /* write_Getnumberofcells_file */
  398. /******************************************************************************/
  399. /* This subroutine is used to create the file getnumberofcells */
  400. /******************************************************************************/
  401. /* */
  402. /* nbmailles = Agrif_Gr % n(i) */
  403. /* */
  404. /******************************************************************************/
  405. void write_Getnumberofcells_file()
  406. {
  407. char ligne[LONG_VNAME];
  408. char cformat[LONG_VNAME];
  409. FILE *getnumberofcells;
  410. if ( IndicenbmaillesX == 0 ) return;
  411. strcpy(cformat, "Agrif_Curgrid %% tabvars_i(%d) %% iarray0 = Agrif_Gr %% nb(%d)");
  412. getnumberofcells = open_for_write("GetNumberofcells.h");
  413. sprintf(ligne, cformat, IndicenbmaillesX, 1);
  414. tofich(getnumberofcells, ligne, 1);
  415. if (dimprob > 1)
  416. {
  417. sprintf(ligne, cformat, IndicenbmaillesY, 2);
  418. tofich(getnumberofcells, ligne,1);
  419. }
  420. if (dimprob > 2)
  421. {
  422. sprintf(ligne, cformat, IndicenbmaillesZ, 3);
  423. tofich(getnumberofcells, ligne,1);
  424. }
  425. fclose(getnumberofcells);
  426. }
  427. /******************************************************************************/
  428. /* write_initialisationsagrif_file */
  429. /******************************************************************************/
  430. /* This subroutine is used to create the file initproc */
  431. /******************************************************************************/
  432. /* */
  433. /* ! variable */
  434. /* Agrif_Gr % tabvars(i) % nbdim = 1 */
  435. /* */
  436. /******************************************************************************/
  437. void write_initialisationsagrif_file(variable *v,FILE *initproc,int *VarnameEmpty)
  438. {
  439. char ligne[LONG_M];
  440. if ( v->v_nbdim != 0 )
  441. {
  442. *VarnameEmpty = 0 ;
  443. sprintf(ligne,"Agrif_Mygrid %% %s(%d) %% nbdim = %d", tabvarsname(v), v->v_indicetabvars, v->v_nbdim);
  444. tofich (initproc, ligne,1);
  445. }
  446. }
  447. void Write_Alloc_Agrif_Files()
  448. {
  449. listnom *parcours;
  450. FILE *alloccalls;
  451. FILE *AllocUSE;
  452. AllocUSE= open_for_write("include_use_Alloc_agrif.h");
  453. alloccalls = open_for_write("allocations_calls_agrif.h");
  454. parcours = List_Subroutine_For_Alloc;
  455. while ( parcours )
  456. {
  457. fprintf(AllocUSE," use %s, only: Alloc_agrif_%s\n", parcours -> o_nom, parcours -> o_nom );
  458. fprintf (alloccalls," call Alloc_agrif_%s(Agrif_Gr)\n", parcours -> o_nom );
  459. parcours = parcours -> suiv;
  460. }
  461. fclose (AllocUSE);
  462. fclose (alloccalls);
  463. }
  464. int IndiceInlist(int indic, listindice *listin)
  465. {
  466. listindice *parcoursindic;
  467. int out;
  468. out = 0 ;
  469. parcoursindic = listin;
  470. while ( parcoursindic && out == 0 )
  471. {
  472. if ( parcoursindic->i_indice == indic ) out = 1;
  473. else parcoursindic = parcoursindic -> suiv;
  474. }
  475. return out;
  476. }
  477. void write_allocation_Common_0()
  478. {
  479. listnom *parcours_nom;
  480. listnom *neededparameter;
  481. listvar *parcours;
  482. listvar *parcoursprec;
  483. listvar *parcours1;
  484. FILE *allocationagrif;
  485. FILE *paramtoamr;
  486. char ligne[LONG_M];
  487. char ligne2[LONG_M];
  488. variable *v;
  489. int IndiceMax;
  490. int IndiceMin;
  491. int compteur;
  492. int out;
  493. int indiceprec;
  494. int ValeurMax;
  495. char initialvalue[LONG_M];
  496. listindice **list_indic;
  497. listindice *parcoursindic;
  498. int i;
  499. parcoursprec = (listvar *) NULL;
  500. parcours_nom = List_NameOfCommon;
  501. ValeurMax = 2;
  502. while ( parcours_nom )
  503. {
  504. if ( parcours_nom->o_val == 1 )
  505. {
  506. /* Open the file to create the Alloc_agrif subroutine */
  507. sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
  508. allocationagrif = open_for_write(ligne);
  509. fprintf(allocationagrif,"#include \"Param_toamr_%s.h\" \n", parcours_nom->o_nom);
  510. sprintf(ligne,"Param_toamr_%s.h",parcours_nom->o_nom);
  511. paramtoamr = open_for_write(ligne);
  512. neededparameter = (listnom *) NULL;
  513. list_indic = (listindice **) calloc(NB_CAT_VARIABLES,sizeof(listindice *));
  514. // shouldincludempif = 1 ;
  515. parcours = List_Common_Var;
  516. while ( parcours )
  517. {
  518. if ( !strcasecmp(parcours->var->v_commonname,parcours_nom->o_nom) &&
  519. IndiceInlist(parcours->var->v_indicetabvars,list_indic[parcours->var->v_catvar]) == 0 )
  520. {
  521. v = parcours->var;
  522. IndiceMax = 0;
  523. IndiceMin = indicemaxtabvars[v->v_catvar];
  524. /* body of the file */
  525. if ( !strcasecmp(v->v_commoninfile,cur_filename) )
  526. {
  527. if ( (onlyfixedgrids != 1) && (v->v_nbdim != 0) )
  528. {
  529. sprintf(ligne,"if (.not. allocated(%s)) then", vargridnametabvars(v,0));
  530. tofich(allocationagrif,ligne,1);
  531. }
  532. if ( (v->v_allocatable != 1) && (v->v_dimsempty != 1) )
  533. {
  534. /* ALLOCATION */
  535. if ( v->v_dimension != 0 )
  536. {
  537. if ( v->v_indicetabvars < IndiceMin || v->v_indicetabvars > IndiceMax )
  538. {
  539. parcours1 = parcours;
  540. compteur = -1;
  541. out = 0;
  542. indiceprec = parcours->var->v_indicetabvars -1 ;
  543. while ( parcours1 && out == 0
  544. && !strcasecmp(parcours->var->v_readedlistdimension,parcours1->var->v_readedlistdimension)
  545. && !strcasecmp(parcours->var->v_typevar, parcours1->var->v_typevar)
  546. && (parcours1->var->v_indicetabvars == indiceprec+1) )
  547. {
  548. if ( !strcasecmp(parcours1->var->v_modulename,parcours_nom->o_nom) ||
  549. !strcasecmp(parcours1->var->v_commonname,parcours_nom->o_nom) )
  550. {
  551. compteur = compteur +1 ;
  552. indiceprec = parcours1->var->v_indicetabvars;
  553. parcoursprec = parcours1;
  554. parcours1 = parcours1->suiv;
  555. }
  556. else out = 1;
  557. }
  558. sprintf(ligne,"!! ALLOCATION OF VARIABLE : %s",v->v_nomvar);
  559. tofich(allocationagrif,ligne,1);
  560. if ( compteur > ValeurMax )
  561. {
  562. sprintf(ligne,"do i = %d,%d", parcours->var->v_indicetabvars,
  563. parcours->var->v_indicetabvars+compteur);
  564. tofich(allocationagrif,ligne,1);
  565. IndiceMin = parcours->var->v_indicetabvars;
  566. IndiceMax = parcours->var->v_indicetabvars+compteur;
  567. sprintf(ligne," allocate(%s", vargridnametabvars(v,1));
  568. sprintf(ligne2,"%s)", vargridparam(v));
  569. strcat(ligne,ligne2);
  570. tofich(allocationagrif,ligne,1);
  571. tofich(allocationagrif,"enddo",1);
  572. i = parcours->var->v_indicetabvars;
  573. do
  574. {
  575. parcoursindic = (listindice *)calloc(1,sizeof(listindice));
  576. parcoursindic -> i_indice = i;
  577. parcoursindic -> suiv = list_indic[parcours->var->v_catvar];
  578. list_indic[parcours->var->v_catvar] = parcoursindic;
  579. i = i + 1;
  580. } while ( i <= parcours->var->v_indicetabvars+compteur );
  581. parcours = parcoursprec;
  582. }
  583. else
  584. {
  585. sprintf(ligne,"allocate(%s", vargridnametabvars(v,0));
  586. sprintf(ligne2,"%s)", vargridparam(v));
  587. strcat(ligne,ligne2);
  588. tofich(allocationagrif,ligne,1);
  589. parcoursindic = (listindice *) calloc(1,sizeof(listindice));
  590. parcoursindic -> i_indice = parcours->var->v_indicetabvars;
  591. parcoursindic -> suiv = list_indic[parcours->var->v_catvar];
  592. list_indic[parcours->var->v_catvar] = parcoursindic;
  593. }
  594. neededparameter = writedeclarationintoamr(List_Parameter_Var,
  595. paramtoamr,v,parcours_nom->o_nom,neededparameter,v->v_commonname);
  596. }
  597. } /* end of the allocation part */
  598. /* INITIALISATION */
  599. if ( strcasecmp(v->v_initialvalue,"") )
  600. {
  601. strcpy(ligne, vargridnametabvars(v,0));
  602. /* We should modify the initialvalue in the case of variable has been defined with others variables */
  603. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_Global_Var));
  604. if ( !strcasecmp(initialvalue,v->v_initialvalue) )
  605. {
  606. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_Common_Var));
  607. }
  608. if ( !strcasecmp(initialvalue,v->v_initialvalue) )
  609. {
  610. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_ModuleUsed_Var));
  611. }
  612. strcat (ligne," = ");
  613. if (v->v_nbdim == 0)
  614. {
  615. strcpy(ligne2,initialvalue);
  616. }
  617. else
  618. {
  619. sprintf(ligne2,"reshape(%s,shape(%s))",initialvalue,vargridnametabvars(v,0));
  620. }
  621. strcat(ligne,ligne2);
  622. tofich(allocationagrif,ligne,1);
  623. }
  624. }
  625. if ( (onlyfixedgrids != 1) && (v->v_nbdim != 0) )
  626. {
  627. tofich(allocationagrif,"endif",1);
  628. }
  629. }
  630. }
  631. parcours = parcours -> suiv;
  632. }
  633. /* Close the file Alloc_agrif */
  634. fclose(allocationagrif);
  635. fclose(paramtoamr);
  636. }
  637. parcours_nom = parcours_nom -> suiv;
  638. }
  639. }
  640. void write_allocation_Global_0()
  641. {
  642. listnom *parcours_nom;
  643. listvar *parcours;
  644. listvar *parcoursprec;
  645. listvar *parcours1;
  646. FILE *allocationagrif;
  647. char ligne[LONG_M];
  648. char ligne2[LONG_M];
  649. variable *v;
  650. int IndiceMax;
  651. int IndiceMin;
  652. int compteur;
  653. int out;
  654. int indiceprec;
  655. int ValeurMax;
  656. char initialvalue[LONG_M];
  657. int typeiswritten ;
  658. parcoursprec = (listvar *) NULL;
  659. parcours_nom = List_NameOfModule;
  660. ValeurMax = 2;
  661. while ( parcours_nom )
  662. {
  663. if ( parcours_nom->o_val == 1 )
  664. {
  665. IndiceMax = 0;
  666. IndiceMin = indicemaxtabvars[0];
  667. /* Open the file to create the Alloc_agrif subroutine */
  668. sprintf(ligne,"alloc_agrif_%s.h",parcours_nom->o_nom);
  669. allocationagrif = open_for_write(ligne);
  670. // if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
  671. // {
  672. // /* add the call to initworkspace */
  673. // tofich(allocationagrif,"if (.not. Agrif_Root() ) then",1);
  674. // tofich(allocationagrif,"#include \"GetNumberofcells.h\"\n",0);
  675. // tofich(allocationagrif,"else",1);
  676. // tofich(allocationagrif,"#include \"SetNumberofcells.h\"\n",0);
  677. // tofich(allocationagrif,"endif",1);
  678. // tofich(allocationagrif,"call Agrif_InitWorkspace",1);
  679. // }
  680. typeiswritten = 0;
  681. parcours = List_Global_Var;
  682. while ( parcours )
  683. {
  684. if ( !strcasecmp(parcours->var->v_modulename,parcours_nom->o_nom) &&
  685. parcours->var->v_VariableIsParameter == 0 &&
  686. parcours->var->v_notgrid == 0 )
  687. {
  688. v = parcours->var;
  689. IndiceMax = 0;
  690. IndiceMin = indicemaxtabvars[v->v_catvar];
  691. /* body of the file */
  692. if ( !strcasecmp(v->v_commoninfile,cur_filename) )
  693. {
  694. if ( (onlyfixedgrids != 1) && (v->v_nbdim != 0) )
  695. {
  696. sprintf(ligne,"if (.not. allocated(%s)) then", vargridnametabvars(v,0));
  697. tofich(allocationagrif,ligne,1);
  698. }
  699. if ( (v->v_allocatable != 1) && (v->v_dimsempty != 1) )
  700. {
  701. /* ALLOCATION */
  702. if ( v->v_dimension != 0 )
  703. {
  704. if ( v->v_indicetabvars < IndiceMin || v->v_indicetabvars > IndiceMax )
  705. {
  706. parcours1 = parcours;
  707. compteur = -1;
  708. out = 0;
  709. indiceprec = parcours->var->v_indicetabvars -1 ;
  710. while ( parcours1 && out == 0
  711. && !strcasecmp(parcours->var->v_readedlistdimension,parcours1->var->v_readedlistdimension)
  712. && !strcasecmp(parcours->var->v_typevar, parcours1->var->v_typevar)
  713. && (parcours1->var->v_indicetabvars == indiceprec+1) )
  714. {
  715. if ( !strcasecmp(parcours1->var->v_modulename, parcours_nom->o_nom) ||
  716. !strcasecmp(parcours1->var->v_commonname, parcours_nom->o_nom) )
  717. {
  718. compteur = compteur +1 ;
  719. indiceprec = parcours1->var->v_indicetabvars;
  720. parcoursprec = parcours1;
  721. parcours1 = parcours1->suiv;
  722. }
  723. else out = 1;
  724. }
  725. sprintf(ligne,"!! ALLOCATION OF VARIABLE : %s",v->v_nomvar);
  726. tofich(allocationagrif,ligne,1);
  727. if ( compteur > ValeurMax )
  728. {
  729. sprintf(ligne,"do i = %d,%d", parcours->var->v_indicetabvars,
  730. parcours->var->v_indicetabvars+compteur);
  731. tofich(allocationagrif,ligne,1);
  732. IndiceMin = parcours->var->v_indicetabvars;
  733. IndiceMax = parcours->var->v_indicetabvars+compteur;
  734. sprintf(ligne," allocate(%s", vargridnametabvars(v,1));
  735. sprintf(ligne2,"%s)", vargridparam(v));
  736. strcat(ligne,ligne2);
  737. tofich(allocationagrif,ligne,1);
  738. tofich(allocationagrif,"enddo",1);
  739. parcours = parcoursprec;
  740. }
  741. else
  742. {
  743. sprintf(ligne,"allocate(%s", vargridnametabvars(v,0));
  744. sprintf(ligne2,"%s)", vargridparam(v));
  745. strcat(ligne,ligne2);
  746. tofich(allocationagrif,ligne,1);
  747. }
  748. }
  749. } /* end of the allocation part */
  750. /* INITIALISATION */
  751. if ( strcasecmp(v->v_initialvalue,"") )
  752. {
  753. strcpy(ligne, vargridnametabvars(v,0));
  754. /* We should modify the initialvalue in the case of variable has been defined with others variables */
  755. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_Global_Var));
  756. if ( !strcasecmp(initialvalue,v->v_initialvalue) )
  757. {
  758. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_Common_Var));
  759. }
  760. if ( !strcasecmp(initialvalue,v->v_initialvalue) )
  761. {
  762. strcpy(initialvalue,ChangeTheInitalvaluebyTabvarsName(v->v_initialvalue,List_ModuleUsed_Var));
  763. }
  764. strcat (ligne," = ");
  765. strcat (ligne,initialvalue);
  766. Save_Length(ligne,48);
  767. tofich(allocationagrif,ligne,1);
  768. }
  769. }
  770. /* Case of structure types */
  771. if ( (typeiswritten == 0) && !strcasecmp(v->v_typevar,"type") )
  772. {
  773. sprintf(ligne,"if (.not. allocated(Agrif_%s_var)) then",v->v_modulename);
  774. tofich(allocationagrif, ligne, 1);
  775. sprintf(ligne," allocate(Agrif_%s_var(0:Agrif_NbMaxGrids))",v->v_modulename);
  776. tofich(allocationagrif, ligne, 1);
  777. tofich(allocationagrif, "endif", 1);
  778. typeiswritten = 1;
  779. }
  780. if ( (onlyfixedgrids != 1) && (v->v_nbdim != 0) )
  781. {
  782. tofich(allocationagrif,"endif",1);
  783. }
  784. }
  785. }
  786. parcours = parcours -> suiv;
  787. }
  788. if ( ModuleIsDefineInInputFile(parcours_nom->o_nom) == 1 )
  789. {
  790. fprintf(allocationagrif, " if ( .not.Agrif_Root() ) then\n");
  791. fprintf(allocationagrif, "#include \"GetNumberofcells.h\"\n");
  792. fprintf(allocationagrif, " else\n");
  793. fprintf(allocationagrif, "#include \"SetNumberofcells.h\"\n");
  794. fprintf(allocationagrif, " endif\n");
  795. fprintf(allocationagrif, " call Agrif_InitWorkspace\n");
  796. }
  797. fclose(allocationagrif);
  798. }
  799. parcours_nom = parcours_nom -> suiv;
  800. }
  801. }
  802. /******************************************************************************/
  803. /* creefichieramr */
  804. /******************************************************************************/
  805. /* This subroutine is the main one to create AGRIF_INC files */
  806. /******************************************************************************/
  807. /* */
  808. /******************************************************************************/
  809. void creefichieramr ()
  810. {
  811. listvar *newvar;
  812. variable *v;
  813. int erreur;
  814. char filefich[LONG_M];
  815. int InitEmpty;
  816. int VarnameEmpty;
  817. int donotwrite;
  818. FILE *initproc;
  819. FILE *initglobal;
  820. FILE *createvarname;
  821. FILE *createvarnameglobal;
  822. if ( todebug == 1 ) printf("Enter in creefichieramr\n");
  823. sprintf(filefich, "cd %s", include_dir);
  824. erreur = system (filefich);
  825. if (erreur)
  826. {
  827. sprintf(filefich, "mkdir -p %s", include_dir);
  828. system(filefich);
  829. printf("%s: Directory created\n", include_dir);
  830. }
  831. /******************************************************************************/
  832. /******************** Creation of AGRIF_INC files *****************************/
  833. /******************************************************************************/
  834. if ( todebug == 1 )
  835. {
  836. const char *NameTampon = "toto";
  837. sprintf(filefich,"initialisations_agrif_%s.h", NameTampon);
  838. initproc = open_for_write(filefich);
  839. sprintf(filefich,"createvarname_agrif_%s.h", NameTampon);
  840. createvarname = open_for_write(filefich);
  841. InitEmpty = 1 ;
  842. VarnameEmpty = 1 ;
  843. newvar = List_Global_Var;
  844. while ( newvar )
  845. {
  846. donotwrite = 0;
  847. v = newvar->var;
  848. if ( ( v->v_common == 1 || v->v_module == 1 ) && donotwrite == 0 )
  849. {
  850. write_createvarnameagrif_file(v,createvarname,&VarnameEmpty);
  851. write_initialisationsagrif_file(v,initproc,&InitEmpty);
  852. }
  853. newvar = newvar->suiv;
  854. }
  855. fclose (createvarname);
  856. fclose (initproc);
  857. if ( is_dependfile_created(curmodulename) == 0 )
  858. {
  859. if ( InitEmpty != 1 )
  860. {
  861. initglobal = open_for_append("initialisations_agrif.h");
  862. fprintf(initglobal,"#include \"initialisations_agrif_%s.h\"\n", NameTampon);
  863. fclose(initglobal);
  864. }
  865. if ( VarnameEmpty != 1 )
  866. {
  867. createvarnameglobal= open_for_append("createvarname_agrif.h");
  868. fprintf(createvarnameglobal,"#include \"createvarname_agrif_%s.h\"\n", NameTampon);
  869. fclose(createvarnameglobal);
  870. }
  871. }
  872. }
  873. write_allocation_Common_0();
  874. write_allocation_Global_0();
  875. Write_Alloc_Agrif_Files();
  876. write_probdimagrif_file();
  877. write_keysagrif_file();
  878. write_modtypeagrif_file();
  879. if ( NbMailleXDefined == 1 )
  880. {
  881. write_Setnumberofcells_file();
  882. write_Getnumberofcells_file();
  883. }
  884. if ( todebug == 1 ) printf("Out of creefichieramr\n");
  885. }