| 1 | /****************************************************************************/cxx . . $ `<file>/src/medit/inmsh2.c`/ |
| 2 | /* This file is part of FreeFEM. */ |
| 3 | /* */ |
| 4 | /* FreeFEM is free software: you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU Lesser General Public License as */ |
| 6 | /* published by the Free Software Foundation, either version 3 of */ |
| 7 | /* the License, or (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* FreeFEM is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 12 | /* GNU Lesser General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU Lesser General Public License */ |
| 15 | /* along with FreeFEM. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | /****************************************************************************/ |
| 17 | /* SUMMARY : ... */ |
| 18 | /* LICENSE : LGPLv3 */ |
| 19 | /* ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE */ |
| 20 | /* AUTHORS : Pascal Frey */ |
| 21 | /* E-MAIL : [email protected] */ |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | #include "medit.h"cxx . . $ `<file>/src/medit/medit.h`/ |
| 28 | #include "extern.h"cxx . . $ `<file>/src/medit/extern.h`/ |
| 29 | #include "sproto.h"cxx . . $ `<file>/src/medit/sproto.h`/ |
| 30 | |
| 31 | int inmsh2cxx . . $ inmsh2(74d1544b4222ab53).(pMeshcxx . . $ pMesh# mesh) { |
| 32 | FILEcxx . . $ FILE# *inp, *inf; |
| 33 | pPointcxx . . $ pPoint# pp0, pp1, pp2, pp3; |
| 34 | pTrianglecxx . . $ pTriangle# pt1; |
| 35 | pQuadcxx . . $ pQuad# pq1; |
| 36 | pEdgecxx . . $ pEdge# pr; |
| 37 | int k, disc, degree, dum, ref, tag, ret; |
| 38 | char data[256], sx[128], sy[128], sz[128]; |
| 39 | |
| 40 | /* check for .points */ |
| 41 | strcpycxx . . $ strcpy(b7b3a83273496486).(data, mesh->namecxx . . $ mesh#name.); |
| 42 | strcatcxx . . $ strcat(b7b3a83273496486).(data, ".points"); |
| 43 | inp = fopencxx . . $ fopen(82ec0787cd37e0a3).(data, "r"); |
| 44 | if (!inp) return (0); |
| 45 | |
| 46 | /* check for .faces */ |
| 47 | strcpycxx . . $ strcpy(b7b3a83273496486).(data, mesh->namecxx . . $ mesh#name.); |
| 48 | strcatcxx . . $ strcat(b7b3a83273496486).(data, ".faces"); |
| 49 | inf = fopencxx . . $ fopen(82ec0787cd37e0a3).(data, "r"); |
| 50 | if (!inf) { |
| 51 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 52 | return (0); |
| 53 | } |
| 54 | |
| 55 | if (!quietcxx . . $ quiet.) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " Reading %s.{points,.faces}\n", mesh->namecxx . . $ mesh#name.); |
| 56 | |
| 57 | /* get number of elements */ |
| 58 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inp, "%d", &mesh->npcxx . . $ mesh#np.); |
| 59 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 60 | EatLinecxx . . $ EatLine(89bc1efcdac0ca22).(inp); |
| 61 | |
| 62 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d", &mesh->necxx . . $ mesh#ne.); |
| 63 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 64 | EatLinecxx . . $ EatLine(89bc1efcdac0ca22).(inf); |
| 65 | if (!mesh->npcxx . . $ mesh#np.) { |
| 66 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " ## No vertex.\n"); |
| 67 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 68 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 69 | return (-1); |
| 70 | } |
| 71 | |
| 72 | mesh->dimcxx . . $ mesh#dim. = 3; |
| 73 | mesh->ntcxx . . $ mesh#nt. = mesh->nqcxx . . $ mesh#nq. = mesh->ntetcxx . . $ mesh#ntet. = mesh->nhexcxx . . $ mesh#nhex. = mesh->nvncxx . . $ mesh#nvn. = 0; |
| 74 | |
| 75 | /* first pass get number of faces */ |
| 76 | for (k = 1; k <= mesh->necxx . . $ mesh#ne.; k++) { |
| 77 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d", °ree); |
| 78 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 79 | if (degree < 2 || degree > 4) { |
| 80 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " ## Wrong degree\n"); |
| 81 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 82 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 83 | return (0); |
| 84 | } else if (degree == 2) { |
| 85 | mesh->nacxx . . $ mesh#na.++; |
| 86 | } else if (degree == 3) { |
| 87 | mesh->ntcxx . . $ mesh#nt.++; |
| 88 | } else if (degree == 4) { |
| 89 | mesh->nqcxx . . $ mesh#nq.++; |
| 90 | } |
| 91 | |
| 92 | EatLinecxx . . $ EatLine(89bc1efcdac0ca22).(inf); |
| 93 | } |
| 94 | |
| 95 | /* check if vertices and elements found */ |
| 96 | if (!mesh->npcxx . . $ mesh#np.) { |
| 97 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 98 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 99 | return (0); |
| 100 | } |
| 101 | |
| 102 | /* memory allocation for mesh */ |
| 103 | if (zaldy1cxx . . $ zaldy1(74d1544b4222ab53).(mesh) != TRUEcxx . . $ `src/medit/medit.h:76:9`!) { |
| 104 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 105 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 106 | return (0); |
| 107 | } |
| 108 | |
| 109 | /* read mesh vertices */ |
| 110 | for (k = 1; k <= mesh->npcxx . . $ mesh#np.; k++) { |
| 111 | char *ptr; |
| 112 | pPointcxx . . $ pPoint# ppt; |
| 113 | |
| 114 | ppt = &mesh->pointcxx . . $ mesh#point.[k]; |
| 115 | /* parse coordinates into strings */ |
| 116 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inp, "%127s %127s %127s %d", sx, sy, sz, &ref); |
| 117 | if (ret != 4) { |
| 118 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 119 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 120 | return (0); |
| 121 | } |
| 122 | |
| 123 | if ((ptr = strpbrkcxx . . $ strpbrk(a713fe7b9a57cf96).(sx, "dD"))) *ptr = 'E'; |
| 124 | |
| 125 | if ((ptr = strpbrkcxx . . $ strpbrk(a713fe7b9a57cf96).(sy, "dD"))) *ptr = 'E'; |
| 126 | |
| 127 | if ((ptr = strpbrkcxx . . $ strpbrk(a713fe7b9a57cf96).(sz, "dD"))) *ptr = 'E'; |
| 128 | |
| 129 | ppt->ccxx . . $ spoint#c.[0] = atofcxx . . $ atof(9a18bdb0e56c1bc2).(sx); |
| 130 | ppt->ccxx . . $ spoint#c.[1] = atofcxx . . $ atof(9a18bdb0e56c1bc2).(sy); |
| 131 | ppt->ccxx . . $ spoint#c.[2] = atofcxx . . $ atof(9a18bdb0e56c1bc2).(sz); |
| 132 | |
| 133 | ppt->refcxx . . $ spoint#ref. = ref; |
| 134 | ppt->tagcxx . . $ spoint#tag. = M_UNUSEDcxx . . $ `src/medit/mesh.h:35:9`!; |
| 135 | } |
| 136 | |
| 137 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inp); |
| 138 | |
| 139 | /* allocate memory for mesh edges */ |
| 140 | if (mesh->nacxx . . $ mesh#na. > 0) { |
| 141 | mesh->edgecxx . . $ mesh#edge. = (pEdgecxx . . $ pEdge#)M_calloccxx . . $ M_calloc(bd9d5902f7a1c84b).(mesh->nacxx . . $ mesh#na. + 1, sizeof(Edgecxx . . $ Edge#), "inmsh2.edge"); |
| 142 | if (!mesh->edgecxx . . $ mesh#edge.) { |
| 143 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, " ## WARN 0004, INMESH, %d\n", mesh->nacxx . . $ mesh#na.); |
| 144 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 145 | return (1); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* read mesh faces */ |
| 150 | rewindcxx . . $ rewind(8d4262d45fc644ab).(inf); |
| 151 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d", &mesh->necxx . . $ mesh#ne.); |
| 152 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 153 | EatLinecxx . . $ EatLine(89bc1efcdac0ca22).(inf); |
| 154 | mesh->ntcxx . . $ mesh#nt. = 0; |
| 155 | mesh->nqcxx . . $ mesh#nq. = 0; |
| 156 | mesh->nacxx . . $ mesh#na. = 0; |
| 157 | disc = 0; |
| 158 | |
| 159 | for (k = 1; k <= mesh->necxx . . $ mesh#ne.; k++) { |
| 160 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d", °ree); |
| 161 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 162 | |
| 163 | if (degree == 2) { |
| 164 | pr = &mesh->edgecxx . . $ mesh#edge.[++mesh->nacxx . . $ mesh#na.]; |
| 165 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d %d %d %d %d\n", &pr->vcxx . . $ edge#v.[0], &pr->vcxx . . $ edge#v.[1], &tag, &dum, &dum); |
| 166 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 167 | pr->tagcxx . . $ edge#tag. = tag == 0 ? M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`! : M_TAGcxx . . $ `src/medit/mesh.h:34:9`!; |
| 168 | pp0 = &mesh->pointcxx . . $ mesh#point.[pr->vcxx . . $ edge#v.[0]]; |
| 169 | pp1 = &mesh->pointcxx . . $ mesh#point.[pr->vcxx . . $ edge#v.[1]]; |
| 170 | pp0->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 171 | pp1->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 172 | } else if (degree == 3) { |
| 173 | pt1 = &mesh->triacxx . . $ mesh#tria.[++mesh->ntcxx . . $ mesh#nt.]; |
| 174 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d %d %d %d %d %d %d\n", &pt1->vcxx . . $ striangle#v.[0], &pt1->vcxx . . $ striangle#v.[1], &pt1->vcxx . . $ striangle#v.[2], &ref, &dum, |
| 175 | &dum, &dum); |
| 176 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 177 | if (pt1->vcxx . . $ striangle#v.[0] <= 0 || pt1->vcxx . . $ striangle#v.[0] > mesh->npcxx . . $ mesh#np. || pt1->vcxx . . $ striangle#v.[1] <= 0 || pt1->vcxx . . $ striangle#v.[1] > mesh->npcxx . . $ mesh#np. || |
| 178 | pt1->vcxx . . $ striangle#v.[2] <= 0 || pt1->vcxx . . $ striangle#v.[2] > mesh->npcxx . . $ mesh#np.) { |
| 179 | ret = fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " ## Wrong index\n"); |
| 180 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 181 | disc++; |
| 182 | pt1->vcxx . . $ striangle#v.[0] = 0; |
| 183 | continue; |
| 184 | } |
| 185 | |
| 186 | pt1->refcxx . . $ striangle#ref. = abscxx . . $ abs(7864480464b09eea).(ref); |
| 187 | pp0 = &mesh->pointcxx . . $ mesh#point.[pt1->vcxx . . $ striangle#v.[0]]; |
| 188 | pp1 = &mesh->pointcxx . . $ mesh#point.[pt1->vcxx . . $ striangle#v.[1]]; |
| 189 | pp2 = &mesh->pointcxx . . $ mesh#point.[pt1->vcxx . . $ striangle#v.[2]]; |
| 190 | pp0->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 191 | pp1->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 192 | pp2->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 193 | } else if (degree == 4) { |
| 194 | pq1 = &mesh->quadcxx . . $ mesh#quad.[++mesh->nqcxx . . $ mesh#nq.]; |
| 195 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d %d %d %d", &pq1->vcxx . . $ squad#v.[0], &pq1->vcxx . . $ squad#v.[1], &pq1->vcxx . . $ squad#v.[2], &pq1->vcxx . . $ squad#v.[3]); |
| 196 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 197 | ret = fscanfcxx . . $ fscanf(bc216f8e5b1ebeac).(inf, "%d %d %d %d %d", &ref, &dum, &dum, &dum, &dum); |
| 198 | if (ret == EOFcxx . . $ `<external>/232824719582829767/stdio.h:109:9`!) printfcxx . . $ printf(581fddd72a8db8fc).("fscanf error\n"); |
| 199 | if (pq1->vcxx . . $ squad#v.[0] <= 0 || pq1->vcxx . . $ squad#v.[0] > mesh->npcxx . . $ mesh#np. || pq1->vcxx . . $ squad#v.[1] <= 0 || pq1->vcxx . . $ squad#v.[1] > mesh->npcxx . . $ mesh#np. || |
| 200 | pq1->vcxx . . $ squad#v.[2] <= 0 || pq1->vcxx . . $ squad#v.[2] > mesh->npcxx . . $ mesh#np. || pq1->vcxx . . $ squad#v.[3] <= 0 || pq1->vcxx . . $ squad#v.[3] > mesh->npcxx . . $ mesh#np.) { |
| 201 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " ## Wrong index\n"); |
| 202 | disc++; |
| 203 | pq1->vcxx . . $ squad#v.[0] = 0; |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | pq1->refcxx . . $ squad#ref. = abscxx . . $ abs(7864480464b09eea).(ref); |
| 208 | pp0 = &mesh->pointcxx . . $ mesh#point.[pq1->vcxx . . $ squad#v.[0]]; |
| 209 | pp1 = &mesh->pointcxx . . $ mesh#point.[pq1->vcxx . . $ squad#v.[1]]; |
| 210 | pp2 = &mesh->pointcxx . . $ mesh#point.[pq1->vcxx . . $ squad#v.[2]]; |
| 211 | pp3 = &mesh->pointcxx . . $ mesh#point.[pq1->vcxx . . $ squad#v.[3]]; |
| 212 | pp0->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 213 | pp1->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 214 | pp2->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 215 | pp3->tagcxx . . $ spoint#tag. = M_NOTAGcxx . . $ `src/medit/mesh.h:30:9`!; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(inf); |
| 220 | if (disc > 0) fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, " ## %d entities discarded\n", disc); |
| 221 | |
| 222 | return (1); |
| 223 | } |
| 224 | |
| 225 | #ifdef __cplusplus |
| 226 | } |
| 227 | #endif |