[6133] | 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 <stdio.h> |
---|
| 36 | #include <stdlib.h> |
---|
| 37 | #include <string.h> |
---|
| 38 | |
---|
| 39 | #include "decl.h" |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | /******************************************************************************/ |
---|
| 44 | /* RecordUseModulesVariables */ |
---|
| 45 | /******************************************************************************/ |
---|
| 46 | /* */ |
---|
| 47 | /******************************************************************************/ |
---|
| 48 | void RecordUseModulesVariables() |
---|
| 49 | { |
---|
| 50 | listusemodule *tmplistmodule; |
---|
| 51 | |
---|
| 52 | /* we should record all variables defined in modules used in this file */ |
---|
| 53 | if ( List_NameOfModuleUsed ) |
---|
| 54 | { |
---|
| 55 | tmplistmodule = List_NameOfModuleUsed; |
---|
| 56 | while ( tmplistmodule ) |
---|
| 57 | { |
---|
| 58 | if ( tmplistmodule->u_firstuse == 1 ) |
---|
| 59 | { |
---|
| 60 | /* check if the file .depend<u_usemodule> exist */ |
---|
| 61 | List_ModuleUsed_Var = Readthedependfile |
---|
| 62 | (tmplistmodule->u_usemodule,List_ModuleUsed_Var); |
---|
| 63 | List_GlobParamModuleUsed_Var = ReaddependParameterList |
---|
| 64 | (tmplistmodule->u_usemodule,List_GlobParamModuleUsed_Var); |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | tmplistmodule = tmplistmodule->suiv; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /******************************************************************************/ |
---|
| 74 | /* RecordUseModulesUseModulesVariables */ |
---|
| 75 | /******************************************************************************/ |
---|
| 76 | /******************************************************************************/ |
---|
| 77 | void RecordUseModulesUseModulesVariables() |
---|
| 78 | { |
---|
| 79 | listusemodule *tmplistmodule; |
---|
| 80 | listusemodule *save_list; |
---|
| 81 | |
---|
| 82 | if ( ! List_NameOfModuleUsed ) return; |
---|
| 83 | |
---|
| 84 | /* we should record all variables defined in modules used in this file */ |
---|
| 85 | /* and we should read the .depend of the module used by the module used */ |
---|
| 86 | tmplistmodule = List_NameOfModuleUsed; |
---|
| 87 | while ( tmplistmodule ) |
---|
| 88 | { |
---|
| 89 | Readthedependlistofmoduleused(tmplistmodule->u_usemodule); |
---|
| 90 | while( tmpuselocallist ) |
---|
| 91 | { |
---|
| 92 | Addmoduletothelisttmp(tmpuselocallist->u_usemodule); |
---|
| 93 | save_list = tmpuselocallist->suiv; |
---|
| 94 | free(tmpuselocallist); |
---|
| 95 | tmpuselocallist = save_list; |
---|
| 96 | } |
---|
| 97 | tmplistmodule = tmplistmodule->suiv; |
---|
| 98 | } |
---|
| 99 | tmplistmodule = listofmoduletmp; |
---|
| 100 | while ( tmplistmodule ) |
---|
| 101 | { |
---|
| 102 | Readthedependlistofmoduleused(tmplistmodule->u_usemodule); |
---|
| 103 | while( tmpuselocallist ) |
---|
| 104 | { |
---|
| 105 | Addmoduletothelisttmp(tmpuselocallist->u_usemodule); |
---|
| 106 | save_list = tmpuselocallist->suiv; |
---|
| 107 | free(tmpuselocallist); |
---|
| 108 | tmpuselocallist = save_list; |
---|
| 109 | } |
---|
| 110 | tmplistmodule = tmplistmodule->suiv; |
---|
| 111 | } |
---|
| 112 | tmplistmodule = listofmoduletmp; |
---|
| 113 | while ( tmplistmodule ) |
---|
| 114 | { |
---|
| 115 | // check if the file .depend<u_usemodule> exists |
---|
| 116 | List_ModuleUsedInModuleUsed_Var = |
---|
| 117 | Readthedependfile(tmplistmodule->u_usemodule,List_ModuleUsedInModuleUsed_Var); |
---|
| 118 | |
---|
| 119 | List_GlobParamModuleUsedInModuleUsed_Var = |
---|
| 120 | ReaddependParameterList(tmplistmodule->u_usemodule,List_GlobParamModuleUsedInModuleUsed_Var); |
---|
| 121 | tmplistmodule = tmplistmodule->suiv; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | /******************************************************************************/ |
---|
| 126 | /* Add_NameOfModuleUsed_1 */ |
---|
| 127 | /******************************************************************************/ |
---|
| 128 | /* This subroutine is used to add a record to a list of struct */ |
---|
| 129 | /* listusemodule */ |
---|
| 130 | /******************************************************************************/ |
---|
| 131 | /* */ |
---|
| 132 | /* subroutine sub ... USE mod1 ===> insert in list */ |
---|
| 133 | /* _______ _______ _______ _______ _______ */ |
---|
| 134 | /* + + + + + + + + + + */ |
---|
| 135 | /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */ |
---|
| 136 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
| 137 | /* */ |
---|
| 138 | /* list = List_NameOfModuleUsed */ |
---|
| 139 | /* */ |
---|
| 140 | /******************************************************************************/ |
---|
| 141 | void Add_NameOfModuleUsed_1(char *name) |
---|
| 142 | { |
---|
| 143 | listusemodule *newmodule; |
---|
| 144 | listusemodule *parcours; |
---|
| 145 | int out; |
---|
| 146 | |
---|
| 147 | newmodule = (listusemodule*) calloc(1, sizeof(listusemodule)); |
---|
| 148 | strcpy(newmodule->u_usemodule, name); |
---|
| 149 | strcpy(newmodule->u_charusemodule, charusemodule); |
---|
| 150 | strcpy(newmodule->u_modulename, curmodulename); |
---|
| 151 | strcpy(newmodule->u_cursubroutine, subroutinename); |
---|
| 152 | newmodule->u_firstuse = 1 ; |
---|
| 153 | newmodule->suiv = NULL; |
---|
| 154 | |
---|
| 155 | if ( List_NameOfModuleUsed == NULL ) |
---|
| 156 | { |
---|
| 157 | List_NameOfModuleUsed = newmodule ; |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | parcours = List_NameOfModuleUsed; |
---|
| 162 | while ( parcours && newmodule->u_firstuse ) |
---|
| 163 | { |
---|
| 164 | if ( !strcasecmp(name,parcours->u_usemodule) ) |
---|
| 165 | { |
---|
| 166 | newmodule->u_firstuse = 0 ; |
---|
| 167 | } |
---|
| 168 | parcours = parcours->suiv; |
---|
| 169 | } |
---|
| 170 | /* we can not add the same module twice for the same subroutine */ |
---|
| 171 | parcours = List_NameOfModuleUsed; |
---|
| 172 | out = 0 ; |
---|
| 173 | while ( parcours && out == 0 ) |
---|
| 174 | { |
---|
| 175 | if ( !strcasecmp(name,parcours->u_usemodule) && |
---|
| 176 | !strcasecmp(subroutinename,parcours->u_cursubroutine) ) |
---|
| 177 | { |
---|
| 178 | out = 1 ; |
---|
| 179 | free(newmodule); |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | parcours = parcours->suiv; |
---|
| 183 | } |
---|
| 184 | if ( out == 0 ) |
---|
| 185 | { |
---|
| 186 | newmodule->suiv = List_NameOfModuleUsed; |
---|
| 187 | List_NameOfModuleUsed = newmodule; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /******************************************************************************/ |
---|
| 193 | /* Addmoduletothelist */ |
---|
| 194 | /******************************************************************************/ |
---|
| 195 | /* This subroutine is used to add a record to a list of struct */ |
---|
| 196 | /* listusemodule */ |
---|
| 197 | /******************************************************************************/ |
---|
| 198 | /* */ |
---|
| 199 | /* subroutine sub ... USE mod1 ===> insert in list */ |
---|
| 200 | /* _______ _______ _______ _______ _______ */ |
---|
| 201 | /* + + + + + + + + + + */ |
---|
| 202 | /* + NEW +--->+ list +--->+ list +--->+ list +--->+ list + */ |
---|
| 203 | /* +______+ +______+ +______+ +______+ +______+ */ |
---|
| 204 | /* */ |
---|
| 205 | /* list = List_NameOfModuleUsed */ |
---|
| 206 | /* */ |
---|
| 207 | /******************************************************************************/ |
---|
| 208 | void Addmoduletothelist(const char *name) |
---|
| 209 | { |
---|
| 210 | listusemodule *newmodule; |
---|
| 211 | listusemodule *parcours; |
---|
| 212 | int out; |
---|
| 213 | |
---|
| 214 | newmodule = (listusemodule*) calloc(1,sizeof(listusemodule)); |
---|
| 215 | strcpy(newmodule->u_usemodule, name); |
---|
| 216 | strcpy(newmodule->u_charusemodule, charusemodule); |
---|
| 217 | strcpy(newmodule->u_cursubroutine, subroutinename); |
---|
| 218 | newmodule->u_firstuse = 1 ; |
---|
| 219 | newmodule->suiv = NULL; |
---|
| 220 | |
---|
| 221 | if ( !List_NameOfModuleUsed ) |
---|
| 222 | { |
---|
| 223 | List_NameOfModuleUsed = newmodule ; |
---|
| 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
| 227 | parcours = List_NameOfModuleUsed; |
---|
| 228 | while ( parcours && newmodule->u_firstuse == 1 ) |
---|
| 229 | { |
---|
| 230 | if ( !strcasecmp(name,parcours->u_usemodule) ) |
---|
| 231 | { |
---|
| 232 | newmodule->u_firstuse = 0 ; |
---|
| 233 | } |
---|
| 234 | parcours=parcours->suiv; |
---|
| 235 | } |
---|
| 236 | /* we can not add the same module twice for the same subroutine */ |
---|
| 237 | parcours = List_NameOfModuleUsed; |
---|
| 238 | out = 0 ; |
---|
| 239 | while ( parcours && out == 0 ) |
---|
| 240 | { |
---|
| 241 | if ( !strcasecmp(name,parcours->u_usemodule) && |
---|
| 242 | !strcasecmp(subroutinename,parcours->u_cursubroutine) ) |
---|
| 243 | { |
---|
| 244 | out = 1 ; |
---|
| 245 | free(newmodule); |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | parcours=parcours->suiv; |
---|
| 249 | } |
---|
| 250 | if ( out == 0 ) |
---|
| 251 | { |
---|
| 252 | newmodule->suiv = List_NameOfModuleUsed; |
---|
| 253 | List_NameOfModuleUsed = newmodule; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | /******************************************************************************/ |
---|
| 260 | /* WriteUsemoduleDeclaration */ |
---|
| 261 | /******************************************************************************/ |
---|
| 262 | /* Firstpass 0 */ |
---|
| 263 | /******************************************************************************/ |
---|
| 264 | /* */ |
---|
| 265 | /******************************************************************************/ |
---|
| 266 | void WriteUsemoduleDeclaration(const char *cursubroutinename) |
---|
| 267 | { |
---|
| 268 | listusemodule *newmodule; |
---|
| 269 | listvarpointtovar *pointtmp; |
---|
| 270 | long int fictifpos; |
---|
| 271 | int findcoupled; |
---|
| 272 | |
---|
| 273 | fprintf(fortran_out,"\n"); |
---|
| 274 | newmodule = List_NameOfModuleUsed; |
---|
| 275 | |
---|
| 276 | while ( newmodule ) |
---|
| 277 | { |
---|
| 278 | if ( !strcasecmp(newmodule->u_cursubroutine, cursubroutinename) ) |
---|
| 279 | { |
---|
| 280 | if (strcmp(newmodule->u_charusemodule,"")) |
---|
| 281 | { |
---|
| 282 | /* |
---|
| 283 | findcoupled = 0; |
---|
| 284 | pointtmp = List_CouplePointed_Var; |
---|
| 285 | while(pointtmp) |
---|
| 286 | { |
---|
| 287 | if ((!strcasecmp(pointtmp->t_usemodule, newmodule->u_charusemodule)) && \ |
---|
| 288 | (!strcasecmp(pointtmp->t_cursubroutine, cursubroutinename))) |
---|
| 289 | { |
---|
| 290 | fictifpos = setposcur(); |
---|
| 291 | variableisglobalinmodule(pointtmp->t_couple,newmodule->u_charusemodule,fortran_out,fictifpos); |
---|
| 292 | findcoupled = 1; |
---|
| 293 | } |
---|
| 294 | pointtmp=pointtmp->suiv; |
---|
| 295 | } |
---|
| 296 | if (findcoupled == 0) fprintf(fortran_out," use %s\n",newmodule->u_charusemodule); |
---|
| 297 | */ |
---|
| 298 | fprintf(fortran_out," use %s\n", newmodule->u_charusemodule); |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | newmodule = newmodule ->suiv; |
---|
| 302 | } |
---|
| 303 | } |
---|