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