Salome HOME
efb1552ce613224fe15887c738241f2a9b3fb128
[tools/medcoupling.git] / src / MEDLoader / libmesh5.hxx
1 // Copyright (C) 2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef MESHFORMATPARSER_HXX
21 #define MESHFORMATPARSER_HXX
22 /*----------------------------------------------------------*/
23 /*                                                                                                                      */
24 /*                                              LIBMESH V 5.46                                          */
25 /*                                                                                                                      */
26 /*----------------------------------------------------------*/
27 /*                                                                                                                      */
28 /*      Description:            handle .meshb file format I/O           */
29 /*      Author:                         Loic MARECHAL                                           */
30 /*      Creation date:          feb 16 2007                                                     */
31 /*      Last modification:      dec 12 2020                                                     */
32 /*                                                                                                                      */
33 /*----------------------------------------------------------*/
34
35
36 /*----------------------------------------------------------*/
37 /* Defines                                                                                                      */
38 /*----------------------------------------------------------*/
39
40
41 #define GmfStrSiz 1024
42 #define GmfMaxTyp 1000
43 #define GmfMaxKwd 81
44 #define GmfMshVer 1
45 #define GmfRead 1
46 #define GmfWrite 2
47 #define GmfSca 1
48 #define GmfVec 2
49 #define GmfSymMat 3
50 #define GmfMat 4
51 #define GmfFloat 1
52 #define GmfDouble 2
53
54
55 /*----------------------------------------------------------*/
56 /* Defines                                                                                                      */
57 /*----------------------------------------------------------*/
58
59 #define Asc 1
60 #define Bin 2
61 #define MshFil 4
62 #define SolFil 8
63 #define MaxMsh 100
64 #define InfKwd 1
65 #define RegKwd 2
66 #define SolKwd 3
67 #define WrdSiz 4
68 #define BufSiz 10000
69
70
71 // see MeshGems/Docs/meshgems_formats_description.pdf
72 extern const char* GmfKwdFmt[ GmfMaxKwd + 1 ][4];
73 /*----------------------------------------------------------*/
74 /* Structures                                                                                           */
75 /*----------------------------------------------------------*/
76 namespace  MeshFormat {
77 typedef struct
78 {
79     int typ, SolSiz, NmbWrd, NmbLin, NmbTyp, TypTab[ GmfMaxTyp ];
80     long pos;
81     char fmt[ GmfMaxTyp*9 ];
82 } KwdSct;
83
84 typedef struct
85 {
86     int dim, ver, mod, typ, cod, pos;
87     long NexKwdPos, siz;
88     KwdSct KwdTab[ GmfMaxKwd + 1 ];
89     FILE *hdl;
90     int *IntBuf;
91     float *FltBuf;
92     unsigned char *buf;
93     char FilNam[ GmfStrSiz ];
94     double DblBuf[1000/8];
95     unsigned char blk[ BufSiz + 1000 ];
96 } GmfMshSct;
97
98
99
100
101
102 // see MeshGems/Docs/meshgems_formats_description.pdf
103 enum GmfKwdCod
104 {
105     GmfReserved1, \
106     GmfVersionFormatted, \
107     GmfReserved2, \
108     GmfDimension, \
109     GmfVertices, \
110     GmfEdges, \
111     GmfTriangles, \
112     GmfQuadrilaterals, \
113     GmfTetrahedra, \
114     GmfPrisms, \
115     GmfHexahedra, \
116     GmfIterationsAll, \
117     GmfTimesAll, \
118     GmfCorners, \
119     GmfRidges, \
120     GmfRequiredVertices, \
121     GmfRequiredEdges, \
122     GmfRequiredTriangles, \
123     GmfRequiredQuadrilaterals, \
124     GmfTangentAtEdgeVertices, \
125     GmfNormalAtVertices, \
126     GmfNormalAtTriangleVertices, \
127     GmfNormalAtQuadrilateralVertices, \
128     GmfAngleOfCornerBound, \
129     GmfTrianglesP2, \
130     GmfEdgesP2, \
131     GmfSolAtPyramids, \
132     GmfQuadrilateralsQ2, \
133     GmfISolAtPyramids, \
134     GmfSubDomainFromGeom, \
135     GmfTetrahedraP2, \
136     GmfFault_NearTri, \
137     GmfFault_Inter, \
138     GmfHexahedraQ2, \
139     GmfExtraVerticesAtEdges, \
140     GmfExtraVerticesAtTriangles, \
141     GmfExtraVerticesAtQuadrilaterals, \
142     GmfExtraVerticesAtTetrahedra, \
143     GmfExtraVerticesAtPrisms, \
144     GmfExtraVerticesAtHexahedra, \
145     GmfVerticesOnGeometricVertices, \
146     GmfVerticesOnGeometricEdges, \
147     GmfVerticesOnGeometricTriangles, \
148     GmfVerticesOnGeometricQuadrilaterals, \
149     GmfEdgesOnGeometricEdges, \
150     GmfFault_FreeEdge, \
151     GmfPolyhedra, \
152     GmfPolygons, \
153     GmfFault_Overlap, \
154     GmfPyramids, \
155     GmfBoundingBox, \
156     GmfBody, \
157     GmfPrivateTable, \
158     GmfFault_BadShape, \
159     GmfEnd, \
160     GmfTrianglesOnGeometricTriangles, \
161     GmfTrianglesOnGeometricQuadrilaterals, \
162     GmfQuadrilateralsOnGeometricTriangles, \
163     GmfQuadrilateralsOnGeometricQuadrilaterals, \
164     GmfTangents, \
165     GmfNormals, \
166     GmfTangentAtVertices, \
167     GmfSolAtVertices, \
168     GmfSolAtEdges, \
169     GmfSolAtTriangles, \
170     GmfSolAtQuadrilaterals, \
171     GmfSolAtTetrahedra, \
172     GmfSolAtPrisms, \
173     GmfSolAtHexahedra, \
174     GmfDSolAtVertices, \
175     GmfISolAtVertices, \
176     GmfISolAtEdges, \
177     GmfISolAtTriangles, \
178     GmfISolAtQuadrilaterals, \
179     GmfISolAtTetrahedra, \
180     GmfISolAtPrisms, \
181     GmfISolAtHexahedra, \
182     GmfIterations, \
183     GmfTime, \
184     GmfFault_SmallTri, \
185     GmfCoarseHexahedra, \
186     GmfFault_MultipleEdge
187 };
188
189
190
191 class MeshFormatParser {
192     /*----------------------------------------------------------*/
193     /* External procedures                                                                          */
194     /*----------------------------------------------------------*/
195 public :
196     MeshFormatParser();
197     int GmfOpenMesh(const char *, int, ...);
198     int GmfCloseMesh(int);
199     int GmfStatKwd(int, int, ...);
200     int GmfGotoKwd(int, int);
201     int GmfSetKwd(int, int, ...);
202     void GmfGetLin(int, int, ...);
203     void GmfSetLin(int, int, ...);
204 private :
205
206
207     /*----------------------------------------------------------*/
208     /*  private procedures methods                                                       */
209     /*----------------------------------------------------------*/
210
211     void ScaWrd(GmfMshSct *, unsigned char *);
212     void ScaDblWrd(GmfMshSct *, unsigned char *);
213     void ScaBlk(GmfMshSct *, unsigned char *, int);
214     long GetPos(GmfMshSct *);
215     void RecWrd(GmfMshSct *, unsigned char *);
216     void RecDblWrd(GmfMshSct *, unsigned char *);
217     void RecBlk(GmfMshSct *, unsigned char *, int);
218     void SetPos(GmfMshSct *, long);
219     int ScaKwdTab(GmfMshSct *);
220     void ExpFmt(GmfMshSct *, int);
221     void ScaKwdHdr(GmfMshSct *, int);
222
223     void GmfCpyLin(int, int, int);
224
225
226     int GmfIniFlg;
227     GmfMshSct *GmfMshTab[ MaxMsh + 1 ];
228
229
230
231
232
233 };
234
235 }
236 #endif // MESHFORMATPARSER_HXX