[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 | /* preparation and write of the argument list of a subroutine */ |
---|
| 43 | /******************************************************************************/ |
---|
[663] | 44 | |
---|
| 45 | |
---|
[396] | 46 | /******************************************************************************/ |
---|
[530] | 47 | /* writeheadnewsub_0 */ |
---|
[396] | 48 | /******************************************************************************/ |
---|
| 49 | /* Firstpass 0 */ |
---|
| 50 | /* We should write the head of the subroutine sub_loop_<subroutinename> */ |
---|
| 51 | /******************************************************************************/ |
---|
| 52 | /* */ |
---|
| 53 | /******************************************************************************/ |
---|
[774] | 54 | void writeheadnewsub_0() |
---|
[396] | 55 | { |
---|
[774] | 56 | char ligne[LONG_C]; |
---|
[530] | 57 | |
---|
| 58 | if ( firstpass == 0 && IsTabvarsUseInArgument_0() == 1 ) |
---|
[396] | 59 | { |
---|
[663] | 60 | if ( todebug == 1 ) printf("Enter in writeheadnewsub_0\n"); |
---|
| 61 | /* we should add the use agrif_uti l if it is necessary */ |
---|
| 62 | WriteHeadofSubroutineLoop(); |
---|
[396] | 63 | WriteUsemoduleDeclaration(); |
---|
| 64 | if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout, |
---|
| 65 | " IMPLICIT NONE\n"); |
---|
[663] | 66 | WriteIncludeDeclaration(); |
---|
| 67 | /* */ |
---|
[396] | 68 | /* We should write once the declaration of tables (extract */ |
---|
| 69 | /* from pointer) in the new subroutine */ |
---|
[663] | 70 | if ( mark == 1 ) fprintf(fortranout,"!!! 000000000000000 \n"); |
---|
| 71 | if ( SubInList_ContainsSubroutine() == 0 ) WriteLocalParamDeclaration(); |
---|
| 72 | if ( mark == 1 ) fprintf(fortranout,"!!! 111111111111111 \n"); |
---|
| 73 | |
---|
| 74 | sprintf(ligne,"\n#include \"ParamFile%s.h\" \n",subroutinename); |
---|
| 75 | tofich(fortranout,ligne,1); |
---|
| 76 | |
---|
| 77 | WriteArgumentDeclaration_Sort(); |
---|
| 78 | |
---|
| 79 | if ( mark == 1 ) fprintf(fortranout,"!!! 222222222222222 \n"); |
---|
| 80 | writesub_loopdeclaration_tab(List_UsedInSubroutine_Var,fortranout); |
---|
| 81 | if ( mark == 1 ) fprintf(fortranout,"!!! 333333333333333 \n"); |
---|
| 82 | writesub_loopdeclaration_scalar(List_UsedInSubroutine_Var,paramout); |
---|
| 83 | if ( mark == 1 ) fprintf(fortranout,"!!! 444444444444444 \n"); |
---|
[396] | 84 | /* now we should write the function declaration */ |
---|
| 85 | /* case if it is the */ |
---|
[663] | 86 | WriteFunctionDeclaration(); |
---|
| 87 | if ( mark == 1 ) fprintf(fortranout,"!!! 555555555555555 \n"); |
---|
| 88 | if ( SubInList_ContainsSubroutine() == 0 ) WriteSubroutineDeclaration(1); |
---|
| 89 | if ( mark == 1 ) fprintf(fortranout,"!!! 666666666666666 \n"); |
---|
| 90 | if ( todebug == 1 ) printf("Out of writeheadnewsub_0\n"); |
---|
[396] | 91 | } |
---|
[663] | 92 | else if ( firstpass == 0 ) |
---|
[396] | 93 | { |
---|
[663] | 94 | AddUseAgrifUtil_0(fortranout); |
---|
[396] | 95 | WriteUsemoduleDeclaration(); |
---|
| 96 | WriteIncludeDeclaration(); |
---|
[663] | 97 | if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout, |
---|
| 98 | " IMPLICIT NONE\n"); |
---|
| 99 | if ( mark == 1 ) fprintf(fortranout,"!!! aaaaaaaaaaaaaaa \n"); |
---|
| 100 | WriteLocalParamDeclaration(); |
---|
| 101 | if ( mark == 1 ) fprintf(fortranout,"!!! bbbbbbbbbbbbbbb \n"); |
---|
| 102 | if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration(); |
---|
| 103 | WriteArgumentDeclaration_beforecall(); |
---|
| 104 | /* writesub_loopdeclaration_scalar(List_SubroutineArgument_Var,fortranout); |
---|
| 105 | writesub_loopdeclaration_tab(List_SubroutineArgument_Var,fortranout);*/ |
---|
| 106 | if ( mark == 1 ) fprintf(fortranout,"!!! ccccccccccccccc \n"); |
---|
| 107 | if ( mark == 1 ) fprintf(fortranout,"!!! ddddddddddddddd \n"); |
---|
| 108 | WriteSubroutineDeclaration(1); |
---|
| 109 | if ( mark == 1 ) fprintf(fortranout,"!!! eeeeeeeeeeeeeee \n"); |
---|
[396] | 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | /******************************************************************************/ |
---|
| 115 | /* WriteVariablelist_subloop */ |
---|
| 116 | /******************************************************************************/ |
---|
| 117 | /* This subroutine is used to write the list of the variable which */ |
---|
| 118 | /* should be called by the sub_loop_<name> subroutine */ |
---|
| 119 | /* The first part is composed by the list of the local variables */ |
---|
| 120 | /******************************************************************************/ |
---|
| 121 | /* */ |
---|
[663] | 122 | /* List_SubroutineDeclaration_Var a,b,c, & */ |
---|
[396] | 123 | /* d,e,f, & */ |
---|
| 124 | /* a,b,c,d,e,f,g,h ========> g,h */ |
---|
| 125 | /* */ |
---|
| 126 | /******************************************************************************/ |
---|
| 127 | void WriteVariablelist_subloop(FILE *outputfile) |
---|
| 128 | { |
---|
[663] | 129 | listvar *parcours; |
---|
[774] | 130 | char ligne[LONG_C]; |
---|
[396] | 131 | int compteur; |
---|
[663] | 132 | |
---|
| 133 | if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop\n"); |
---|
| 134 | parcours = List_SubroutineArgument_Var; |
---|
[396] | 135 | didvariableadded = 0; |
---|
| 136 | compteur = 0 ; |
---|
[663] | 137 | |
---|
| 138 | while ( parcours ) |
---|
[396] | 139 | { |
---|
| 140 | /* if the readed variable is a variable of the subroutine */ |
---|
| 141 | /* subroutinename we should write the name of this variable */ |
---|
| 142 | /* in the output file */ |
---|
[663] | 143 | if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) ) |
---|
| 144 | { |
---|
[396] | 145 | if ( didvariableadded == 0 ) |
---|
| 146 | { |
---|
| 147 | strcpy(ligne,""); |
---|
| 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | if ( compteur == 0 ) strcpy(ligne,""); |
---|
| 152 | strcat(ligne,","); |
---|
| 153 | } |
---|
[663] | 154 | strcat(ligne,parcours->var->v_nomvar); |
---|
[396] | 155 | didvariableadded = 1; |
---|
| 156 | compteur = compteur + 1; |
---|
[663] | 157 | if ( compteur == 3 ) |
---|
[396] | 158 | { |
---|
[663] | 159 | if ( retour77 == 0 ) |
---|
| 160 | { |
---|
| 161 | strcat(ligne," &"); |
---|
| 162 | fprintf(outputfile,"\n %s",ligne); |
---|
| 163 | } |
---|
[396] | 164 | else fprintf(outputfile,"\n & %s",ligne); |
---|
| 165 | compteur = 0; |
---|
| 166 | } |
---|
| 167 | } |
---|
[663] | 168 | parcours = parcours -> suiv; |
---|
[396] | 169 | } |
---|
[663] | 170 | parcours = List_FunctionType_Var; |
---|
| 171 | while ( parcours ) |
---|
[396] | 172 | { |
---|
[663] | 173 | if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) ) |
---|
| 174 | { |
---|
| 175 | if ( didvariableadded == 0 ) |
---|
| 176 | { |
---|
| 177 | strcpy(ligne,""); |
---|
| 178 | } |
---|
| 179 | else |
---|
| 180 | { |
---|
| 181 | if ( compteur == 0 ) strcpy(ligne,""); |
---|
| 182 | strcat(ligne,","); |
---|
| 183 | } |
---|
| 184 | strcat(ligne,parcours->var->v_nomvar); |
---|
| 185 | didvariableadded = 1; |
---|
| 186 | compteur = compteur + 1; |
---|
| 187 | if ( compteur == 3 ) |
---|
| 188 | { |
---|
| 189 | if ( retour77 == 0 ) |
---|
| 190 | { |
---|
| 191 | strcat(ligne," &"); |
---|
| 192 | fprintf(outputfile,"\n %s",ligne); |
---|
| 193 | } |
---|
| 194 | else fprintf(outputfile,"\n & %s",ligne); |
---|
| 195 | compteur = 0; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | parcours = parcours -> suiv; |
---|
| 199 | } |
---|
| 200 | if ( compteur != 3 && compteur != 0 ) |
---|
| 201 | { |
---|
| 202 | if ( retour77 == 0 ) fprintf(outputfile,"\n %s &",ligne); |
---|
[396] | 203 | else fprintf(outputfile,"\n & %s ",ligne); |
---|
| 204 | } |
---|
[663] | 205 | if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop\n"); |
---|
[396] | 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | /******************************************************************************/ |
---|
| 210 | /* WriteVariablelist_subloop_Call */ |
---|
| 211 | /******************************************************************************/ |
---|
| 212 | /* This subroutine is used to write the list of the variable which */ |
---|
| 213 | /* should be called by the sub_loop_<name> subroutine into the called */ |
---|
| 214 | /* The second part is composed by the list of the global table */ |
---|
| 215 | /******************************************************************************/ |
---|
| 216 | /* */ |
---|
[663] | 217 | /* List_UsedInSubroutine_Var SubloopScalar = 0 | SubloopScalar = 1 */ |
---|
[396] | 218 | /* a,b,c, & | a,b(1,1),c, & */ |
---|
| 219 | /* a,b,c,d,e,f,g,h =====> d,e,f, & | d(1),e(1,1,1),f, & */ |
---|
| 220 | /* g,h | g,h(1,1) */ |
---|
| 221 | /* */ |
---|
| 222 | /******************************************************************************/ |
---|
[663] | 223 | void WriteVariablelist_subloop_Call(FILE *outputfile) |
---|
[396] | 224 | { |
---|
[663] | 225 | listvar *parcours; |
---|
[774] | 226 | char ligne[LONG_40M]; |
---|
[396] | 227 | char ligne2[10]; |
---|
| 228 | int i; |
---|
[774] | 229 | int compteur ; |
---|
[663] | 230 | |
---|
| 231 | if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop_Call\n"); |
---|
| 232 | parcours = List_UsedInSubroutine_Var; |
---|
[774] | 233 | compteur = 0 ; |
---|
[663] | 234 | while ( parcours ) |
---|
[396] | 235 | { |
---|
| 236 | /* if the readed variable is a variable of the subroutine */ |
---|
| 237 | /* subroutinename we should write the name of this variable */ |
---|
| 238 | /* in the output file */ |
---|
[663] | 239 | if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) && |
---|
| 240 | parcours->var->v_allocatable == 0 && |
---|
| 241 | parcours->var->v_pointerdeclare == 0 |
---|
| 242 | ) |
---|
[396] | 243 | { |
---|
| 244 | if ( didvariableadded == 0 ) |
---|
| 245 | { |
---|
[774] | 246 | if ( retour77 == 1 ) strcpy(ligne,"\n & "); |
---|
| 247 | else strcpy(ligne,"\n "); |
---|
[396] | 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
[774] | 251 | if ( compteur == 0 ) |
---|
| 252 | { |
---|
| 253 | if ( retour77 == 1 ) strcpy(ligne,"\n & "); |
---|
| 254 | else strcpy(ligne,"\n "); |
---|
| 255 | } |
---|
| 256 | strcat(ligne," , "); |
---|
[396] | 257 | } |
---|
| 258 | strcat(ligne,vargridcurgridtabvars(parcours->var,0)); |
---|
| 259 | /* if it is asked in the call of the conv we should give */ |
---|
| 260 | /* scalar in argument, so we should put (1,1,1) after the */ |
---|
| 261 | /* the name of the variable */ |
---|
[663] | 262 | if ( SubloopScalar != 0 && |
---|
| 263 | (IsVarAllocatable_0(parcours->var->v_nomvar) == 0 && |
---|
| 264 | parcours->var->v_pointerdeclare == 0 ) && |
---|
| 265 | parcours->var->v_nbdim != 0 ) |
---|
[396] | 266 | { |
---|
| 267 | i = 1; |
---|
[663] | 268 | while ( i <= parcours->var->v_nbdim ) |
---|
[396] | 269 | { |
---|
| 270 | if ( i == 1 ) strcat(ligne,"( "); |
---|
| 271 | if ( SubloopScalar == 2 ) |
---|
| 272 | { |
---|
| 273 | strcat(ligne,":"); |
---|
[663] | 274 | if ( i != parcours->var->v_nbdim ) strcat(ligne,","); |
---|
[396] | 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | strcat(ligne," lbound( "); |
---|
| 279 | strcat(ligne,vargridcurgridtabvars(parcours->var,0)); |
---|
| 280 | strcat(ligne,","); |
---|
| 281 | strcpy(ligne2,""); |
---|
| 282 | sprintf(ligne2,"%d",i); |
---|
| 283 | strcat(ligne,ligne2); |
---|
[663] | 284 | if ( i != parcours->var->v_nbdim ) strcat(ligne,"),"); |
---|
[396] | 285 | } |
---|
[663] | 286 | if ( i == parcours->var->v_nbdim ) strcat(ligne,"))"); |
---|
[396] | 287 | i++; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | didvariableadded = 1; |
---|
[774] | 291 | compteur = compteur +1 ; |
---|
| 292 | /*if ( retour77 == 0 ) |
---|
[663] | 293 | { |
---|
| 294 | strcat(ligne," &"); |
---|
| 295 | fprintf(outputfile,"\n"); |
---|
| 296 | } |
---|
[774] | 297 | else fprintf(outputfile,"\n & ");*/ |
---|
| 298 | /*tofich(outputfile,ligne,0);*/ |
---|
[396] | 299 | } |
---|
[663] | 300 | parcours = parcours -> suiv; |
---|
[396] | 301 | } |
---|
[774] | 302 | Save_Length(ligne,41); |
---|
| 303 | tofich(outputfile,ligne,0); |
---|
[396] | 304 | /* Now we should replace the last ", &" by " &" */ |
---|
[774] | 305 | /* if ( didvariableadded != 0 && retour77 == 0 ) fseek(outputfile,-1,SEEK_CUR); |
---|
| 306 | if ( didvariableadded == 0 ) fseek(outputfile,-1,SEEK_CUR);*/ |
---|
[663] | 307 | if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop_Call\n"); |
---|
[396] | 308 | } |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | /******************************************************************************/ |
---|
| 312 | /* WriteVariablelist_subloop_Def */ |
---|
| 313 | /******************************************************************************/ |
---|
| 314 | /* This subroutine is used to write the list of the variable which */ |
---|
| 315 | /* should be called by the sub_loop_<name> subroutine into the def */ |
---|
| 316 | /* The second part is composed by the list of the global table */ |
---|
| 317 | /* <name>_tmp */ |
---|
| 318 | /******************************************************************************/ |
---|
| 319 | /* */ |
---|
[663] | 320 | /* List_UsedInSubroutine_Var */ |
---|
[396] | 321 | /* a-tmp,b-tmp,c_tmp, & */ |
---|
| 322 | /* a,b,c,d,e,f,g,h =====> d_tmp,e_tmp,f_tmp, & */ |
---|
| 323 | /* g_tmp,h_tmp */ |
---|
| 324 | /* */ |
---|
| 325 | /******************************************************************************/ |
---|
[663] | 326 | void WriteVariablelist_subloop_Def(FILE *outputfile) |
---|
[396] | 327 | { |
---|
[663] | 328 | listvar *parcours; |
---|
[774] | 329 | char ligne[LONG_40M]; |
---|
[396] | 330 | int compteur; |
---|
| 331 | |
---|
[663] | 332 | if ( todebug == 1 ) printf("Enter in WriteVariablelist_subloop_Def\n"); |
---|
| 333 | parcours = List_UsedInSubroutine_Var; |
---|
[396] | 334 | compteur = 0 ; |
---|
[663] | 335 | while ( parcours ) |
---|
[396] | 336 | { |
---|
| 337 | /* if the readed variable is a variable of the subroutine */ |
---|
| 338 | /* subrotinename we should write the name of this variable */ |
---|
| 339 | /* in the output file */ |
---|
[663] | 340 | if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) && |
---|
| 341 | parcours->var->v_allocatable == 0 && |
---|
| 342 | parcours->var->v_pointerdeclare == 0 |
---|
| 343 | ) |
---|
[396] | 344 | { |
---|
| 345 | if ( didvariableadded == 0 ) |
---|
| 346 | { |
---|
[774] | 347 | if ( retour77 == 1 ) strcpy(ligne,"\n &"); |
---|
| 348 | else strcpy(ligne,"\n "); |
---|
[396] | 349 | } |
---|
| 350 | else |
---|
| 351 | { |
---|
[774] | 352 | if ( compteur == 0 ) |
---|
| 353 | { |
---|
| 354 | if ( retour77 == 1 ) strcpy(ligne,"\n & "); |
---|
| 355 | else strcpy(ligne,"\n "); |
---|
| 356 | } |
---|
[396] | 357 | strcat(ligne,","); |
---|
| 358 | } |
---|
[663] | 359 | strcat(ligne,parcours->var->v_nomvar); |
---|
[396] | 360 | compteur = compteur + 1; |
---|
| 361 | didvariableadded = 1; |
---|
[774] | 362 | /* if ( compteur == 3 ) |
---|
[396] | 363 | { |
---|
[663] | 364 | if ( retour77 == 0 ) |
---|
| 365 | { |
---|
| 366 | strcat(ligne," &"); |
---|
| 367 | fprintf(outputfile,"\n %s",ligne); |
---|
| 368 | } |
---|
[396] | 369 | else fprintf(outputfile,"\n & %s",ligne); |
---|
| 370 | compteur = 0; |
---|
[774] | 371 | }*/ |
---|
[396] | 372 | } |
---|
[663] | 373 | parcours = parcours -> suiv; |
---|
| 374 | } |
---|
[774] | 375 | /* if ( compteur != 3 && compteur != 0 ) |
---|
[396] | 376 | { |
---|
[663] | 377 | if ( retour77 == 0 ) fprintf(outputfile,"\n %s &",ligne); |
---|
[396] | 378 | else fprintf(outputfile,"\n & %s",ligne); |
---|
[774] | 379 | }*/ |
---|
| 380 | Save_Length(ligne,41); |
---|
| 381 | tofich(outputfile,ligne,0); |
---|
[396] | 382 | |
---|
| 383 | /* Now we should replace the last ", &" by " &" */ |
---|
[774] | 384 | /* if ( didvariableadded != 0 && retour77 == 0 ) fseek(outputfile,-1,SEEK_CUR); |
---|
| 385 | if ( didvariableadded == 0 ) fseek(outputfile,-1,SEEK_CUR);*/ |
---|
[663] | 386 | if ( todebug == 1 ) printf("Out of WriteVariablelist_subloop_Def\n"); |
---|
[396] | 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
[663] | 390 | |
---|
[396] | 391 | /******************************************************************************/ |
---|
| 392 | /* WriteHeadofSubroutineLoop */ |
---|
| 393 | /******************************************************************************/ |
---|
| 394 | /* This subroutine is used to write the head of the subroutine */ |
---|
| 395 | /* Sub_Loop_<name> */ |
---|
| 396 | /******************************************************************************/ |
---|
| 397 | /* Sub_loop_subroutine.h */ |
---|
| 398 | /* */ |
---|
| 399 | /* subroutine Sub_Loop_subroutine ( & */ |
---|
| 400 | /* a,b,c, & */ |
---|
| 401 | /* SubLoopScalar d,e(1,1),f(1,1,1), & */ |
---|
| 402 | /* g,h & */ |
---|
| 403 | /* ) */ |
---|
| 404 | /******************************************************************************/ |
---|
[663] | 405 | void WriteHeadofSubroutineLoop() |
---|
[396] | 406 | { |
---|
[774] | 407 | char ligne[LONG_C]; |
---|
[396] | 408 | FILE * subloop; |
---|
| 409 | |
---|
[663] | 410 | if ( todebug == 1 ) printf("Enter in WriteHeadofSubroutineLoop\n"); |
---|
[396] | 411 | tofich(fortranout,"\n",1); |
---|
| 412 | /* Open this newfile */ |
---|
| 413 | sprintf(ligne,"Sub_Loop_%s.h",subroutinename); |
---|
| 414 | subloop = associate(ligne); |
---|
| 415 | /* */ |
---|
[663] | 416 | if ( retour77 == 0 ) sprintf(ligne," subroutine Sub_Loop_%s( &" |
---|
[396] | 417 | ,subroutinename); |
---|
| 418 | else sprintf(ligne," subroutine Sub_Loop_%s( ",subroutinename); |
---|
| 419 | fprintf(subloop,ligne); |
---|
| 420 | /* */ |
---|
| 421 | WriteVariablelist_subloop(subloop); |
---|
| 422 | WriteVariablelist_subloop_Def(subloop); |
---|
| 423 | /* */ |
---|
| 424 | sprintf(ligne,")"); |
---|
[774] | 425 | fprintf(subloop,ligne); |
---|
[663] | 426 | /* if USE agrif_Uti l should be add */ |
---|
| 427 | AddUseAgrifUtil_0(subloop); |
---|
[396] | 428 | /* */ |
---|
| 429 | oldfortranout = fortranout; |
---|
| 430 | fortranout = subloop; |
---|
[663] | 431 | if ( todebug == 1 ) printf("Out of WriteHeadofSubroutineLoop\n"); |
---|
[396] | 432 | } |
---|
| 433 | |
---|
| 434 | /******************************************************************************/ |
---|
[530] | 435 | /* closeandcallsubloopandincludeit_0 */ |
---|
[396] | 436 | /******************************************************************************/ |
---|
| 437 | /* Firstpass 0 */ |
---|
| 438 | /* We should close the sub_loop subroutine, call it and close the */ |
---|
| 439 | /* function (suborfun = 0) */ |
---|
| 440 | /* subroutine (suborfun = 1) */ |
---|
| 441 | /* end (suborfun = 2) */ |
---|
| 442 | /* end program (suborfun = 3) */ |
---|
| 443 | /* and include the sub_loop subroutine after */ |
---|
| 444 | /******************************************************************************/ |
---|
| 445 | /* */ |
---|
| 446 | /******************************************************************************/ |
---|
[774] | 447 | void closeandcallsubloopandincludeit_0(int suborfun) |
---|
[396] | 448 | { |
---|
[774] | 449 | char ligne[LONG_C]; |
---|
[396] | 450 | |
---|
[663] | 451 | if ( firstpass == 0 ) |
---|
[396] | 452 | { |
---|
[663] | 453 | if ( todebug == 1 ) printf("Enter in closeandcallsubloopandincludeit_0\n"); |
---|
[530] | 454 | if ( IsTabvarsUseInArgument_0() == 1 ) |
---|
[396] | 455 | { |
---|
| 456 | /* We should remove the key word end subroutine */ |
---|
[663] | 457 | RemoveWordCUR_0(fortranout,(long)(-(pos_cur-pos_endsubroutine)), |
---|
| 458 | pos_cur-pos_endsubroutine); |
---|
[396] | 459 | /* We should close the loop subroutine */ |
---|
| 460 | sprintf(ligne,"\n end subroutine Sub_Loop_%s",subroutinename); |
---|
| 461 | tofich(fortranout,ligne,1); |
---|
[663] | 462 | fclose(fortranout); |
---|
[396] | 463 | fortranout = oldfortranout; |
---|
[663] | 464 | AddUseAgrifUtilBeforeCall_0(fortranout); |
---|
| 465 | if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration(); |
---|
| 466 | WriteArgumentDeclaration_beforecall(); |
---|
| 467 | if ( !strcasecmp(subofagrifinitgrids,subroutinename) ) |
---|
| 468 | fprintf(oldfortranout," Call Agrif_Init_Grids () \n"); |
---|
[396] | 469 | /* Now we add the call af the new subroutine */ |
---|
[663] | 470 | if ( retour77 == 0 ) sprintf(ligne,"\n Call Sub_Loop_%s( &" |
---|
[396] | 471 | ,subroutinename); |
---|
| 472 | else sprintf(ligne,"\n Call Sub_Loop_%s( ",subroutinename); |
---|
| 473 | fprintf(fortranout,ligne); |
---|
| 474 | /* Write the list of the local variables used in this new subroutine */ |
---|
| 475 | WriteVariablelist_subloop(fortranout); |
---|
| 476 | /* Write the list of the global tables used in this new subroutine */ |
---|
| 477 | /* in doloop */ |
---|
[663] | 478 | WriteVariablelist_subloop_Call(fortranout); |
---|
[396] | 479 | /* Close the parenthesis of the new subroutine called */ |
---|
| 480 | sprintf(ligne,")"); |
---|
[774] | 481 | fprintf(fortranout,ligne); |
---|
[396] | 482 | /* We should close the original subroutine */ |
---|
| 483 | if ( suborfun == 3 ) sprintf(ligne,"\n end program %s" |
---|
| 484 | ,subroutinename); |
---|
| 485 | if ( suborfun == 2 ) sprintf(ligne,"\n end"); |
---|
| 486 | if ( suborfun == 1 ) sprintf(ligne,"\n end subroutine %s" |
---|
| 487 | ,subroutinename); |
---|
| 488 | if ( suborfun == 0 ) sprintf(ligne,"\n end function %s" |
---|
| 489 | ,subroutinename); |
---|
| 490 | tofich(fortranout,ligne,1); |
---|
| 491 | /* we should include the above file in the original code */ |
---|
| 492 | sprintf(ligne,"\n#include \"Sub_Loop_%s.h\" \n",subroutinename); |
---|
| 493 | tofich(fortranout,ligne,1); |
---|
| 494 | } |
---|
[663] | 495 | if ( todebug == 1 ) printf("Out of closeandcallsubloopandincludeit_0\n"); |
---|
[396] | 496 | } |
---|
| 497 | } |
---|
[663] | 498 | |
---|
| 499 | |
---|
| 500 | |
---|
| 501 | |
---|
[774] | 502 | void closeandcallsubloop_contains_0() |
---|
[663] | 503 | { |
---|
[774] | 504 | char ligne[LONG_C]; |
---|
[663] | 505 | |
---|
| 506 | if ( firstpass == 0 ) |
---|
| 507 | { |
---|
| 508 | if ( todebug == 1 ) printf("Enter in closeandcallsubloopandincludeit_0\n"); |
---|
| 509 | if ( IsTabvarsUseInArgument_0() == 1 ) |
---|
| 510 | { |
---|
| 511 | Remove_Word_Contains_0(); |
---|
| 512 | sprintf(ligne,"\n end subroutine Sub_Loop_%s",subroutinename); |
---|
| 513 | tofich(fortranout,ligne,1); |
---|
| 514 | fclose(fortranout); |
---|
| 515 | fortranout = oldfortranout; |
---|
| 516 | AddUseAgrifUtilBeforeCall_0(fortranout); |
---|
| 517 | if ( ImplicitNoneInSubroutine() == 1 ) fprintf(fortranout, |
---|
| 518 | " IMPLICIT NONE\n"); |
---|
| 519 | WriteLocalParamDeclaration(); |
---|
| 520 | if ( functiondeclarationisdone == 0 ) WriteFunctionDeclaration(); |
---|
| 521 | WriteArgumentDeclaration_beforecall(); |
---|
| 522 | WriteSubroutineDeclaration(0); |
---|
| 523 | if ( !strcasecmp(subofagrifinitgrids,subroutinename) ) |
---|
| 524 | fprintf(oldfortranout," Call Agrif_Init_Grids () \n"); |
---|
| 525 | /* Now we add the call af the new subroutine */ |
---|
| 526 | if ( retour77 == 0 ) sprintf(ligne,"\n Call Sub_Loop_%s( &" |
---|
| 527 | ,subroutinename); |
---|
| 528 | else sprintf(ligne,"\n Call Sub_Loop_%s( ",subroutinename); |
---|
| 529 | fprintf(fortranout,ligne); |
---|
| 530 | /* Write the list of the local variables used in this new subroutine */ |
---|
| 531 | WriteVariablelist_subloop(fortranout); |
---|
| 532 | /* Write the list of the global tables used in this new subroutine */ |
---|
| 533 | /* in doloop */ |
---|
| 534 | WriteVariablelist_subloop_Call(fortranout); |
---|
| 535 | /* Close the parenthesis of the new subroutine called */ |
---|
| 536 | sprintf(ligne,")"); |
---|
| 537 | tofich(fortranout,ligne,1); |
---|
| 538 | /* We should close the original subroutine */ |
---|
| 539 | sprintf(ligne,"\n contains"); |
---|
| 540 | tofich(fortranout,ligne,1); |
---|
| 541 | /* we should include the above file in the original code */ |
---|
| 542 | sprintf(ligne,"\n#include \"Sub_Loop_%s.h\" \n",subroutinename); |
---|
| 543 | tofich(fortranout,ligne,1); |
---|
| 544 | } |
---|
| 545 | if ( todebug == 1 ) printf("Out of closeandcallsubloopandincludeit_0\n"); |
---|
| 546 | } |
---|
| 547 | } |
---|