1 // Copyright (C) 2010-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 * TestMedReadDescendingPolyhedron.cxx
23 * Created on: 3 mars 2011
29 #include <med_utils.h>
33 int main (int argc, char **argv) {
35 const char meshname[MED_NAME_SIZE+1] = "3D unstructured mesh";
36 char meshdescription[MED_COMMENT_SIZE+1];
39 med_sorting_type sortingtype;
41 med_mesh_type meshtype;
42 med_axis_type axistype;
43 char axisname[3*MED_SNAME_SIZE+1];
44 char unitname[3*MED_SNAME_SIZE+1];
45 char dtunit[MED_SNAME_SIZE+1];
46 med_float *coordinates = NULL;
50 med_int faceIndexSize;
51 med_int *index = NULL;
52 med_int *faceindex = NULL;
53 med_int *connectivity = NULL;
54 med_int connectivitysize;
55 med_int *triaconnectivity = NULL;
57 med_bool coordinatechangement;
58 med_bool geotransformation;
63 /* open MED file with READ ONLY access mode */
64 fid = MEDfileOpen("./UsesCase_MEDmesh_17.med",MED_ACC_RDONLY);
66 MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
71 * ... we know that the MED file has only one mesh,
72 * a real code working would check ...
75 /* read mesh informations : mesh dimension, space dimension ... */
76 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
77 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
78 MESSAGE("ERROR : mesh info ...");
82 /* read how many nodes in the mesh */
83 if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_POINT1,
84 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
85 &geotransformation)) < 0) {
86 MESSAGE("ERROR : number of nodes ...");
90 /* read how many triangular cells in the mesh */
91 if ((ntria3 = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_DESCENDING_FACE,MED_TRIA3,
92 MED_CONNECTIVITY, MED_NODAL,&coordinatechangement,
93 &geotransformation)) < 0) {
94 MESSAGE("ERROR : number of MED_TRIA3 ...");
99 /* read cells connectivity in the mesh */
100 if ((triaconnectivity = (med_int *) malloc(sizeof(med_int)*ntria3*3)) == NULL) {
101 MESSAGE("ERROR : memory allocation ...");
104 if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_DESCENDING_FACE,
105 MED_TRIA3, MED_NODAL, MED_FULL_INTERLACE, triaconnectivity) < 0) {
106 MESSAGE("ERROR : MED_TRIA3 connectivity ...");
109 for (i=0;i<ntria3*3;i++)
110 printf("%d - ",*(triaconnectivity+i));
113 * ... we know that we only have MED_POLYHEDRON cells in the mesh,
114 * a real code working would check all MED geometry cell types ...
117 /* How many polygon in the mesh in nodal connectivity mode */
118 /* For the polygons, we get the size of array index */
119 if ((faceIndexSize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
120 MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_DESCENDING,
121 &coordinatechangement,
122 &geotransformation)) < 0) {
123 MESSAGE("ERROR : read number of polyedron ...");
126 npoly = faceIndexSize - 1;
129 if ((indexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
130 MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_DESCENDING,
131 &coordinatechangement,
132 &geotransformation)) < 0) {
133 MESSAGE("ERROR : read number of polyedron ...");
138 /* how many nodes for the polyhedron connectivity ? */
139 if ((connectivitysize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
140 MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_DESCENDING,
141 &coordinatechangement,
142 &geotransformation)) < 0) {
143 MESSAGE("ERROR : read connevity size ...");
146 ISCRUTE(connectivitysize);
148 /* read mesh nodes coordinates */
149 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
150 MESSAGE("ERROR : memory allocation ...");
154 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
156 MESSAGE("ERROR : nodes coordinates ...");
159 for (i=0;i<nnodes*spacedim;i++)
160 printf("%f - ",*(coordinates+i));
163 /* read polygons connectivity */
164 if ((index = (med_int *) malloc(sizeof(med_int)*indexsize)) == NULL) {
165 MESSAGE("ERROR : memory allocation ...");
169 if ((faceindex = (med_int *) malloc(sizeof(med_int)*faceIndexSize)) == NULL) {
170 MESSAGE("ERROR : memory allocation ...");
174 if ((connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize)) == NULL) {
175 MESSAGE("ERROR : memory allocation ...");
179 if (MEDmeshPolyhedronRd(fid,meshname,MED_NO_DT,MED_NO_IT,MED_CELL,MED_DESCENDING,
180 faceindex, index, connectivity) < 0) {
181 MESSAGE("ERROR : read polygon connectivity ...");
185 for (i=0;i<npoly;i++)
187 printf(">> MED_POLYHEDRON "IFORMAT" : \n",i+1);
188 printf("---- Face Index ----- : [ ");
190 ind2 = *(index+i+1)-1;
191 for (k=ind1;k<ind2;k++)
192 printf(IFORMAT" ",*(faceindex+k));
194 printf("---- Connectivity ----- : [ ");
195 for (k=0;k<connectivitysize;k++)
199 printf(IFORMAT" ",triaconnectivity[connectivity[k]+j]);
207 * ... we know that the family number of nodes and elements is 0, a real working would check ...
211 if (MEDfileClose(fid) < 0) {
212 MESSAGE("ERROR : close file");
216 /* memory deallocation */
217 printf("Before free(coordinates)\n");
221 printf("Before free(connectivity)\n");
225 printf("Before free(triaconnectivity)\n");
226 if (triaconnectivity)
227 free(triaconnectivity);
229 printf("Before free(index)\n");