00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <med.h>
00025 #define MESGERR 1
00026 #include <med_utils.h>
00027
00028 #include <string.h>
00029
00030 int main (int argc, char **argv) {
00031 med_idt fid;
00032 const char meshname[MED_NAME_SIZE+1] = "3D unstructured mesh";
00033 char meshdescription[MED_COMMENT_SIZE+1];
00034 med_int meshdim;
00035 med_int spacedim;
00036 med_sorting_type sortingtype;
00037 med_int nstep;
00038 med_mesh_type meshtype;
00039 med_axis_type axistype;
00040 char axisname[3*MED_SNAME_SIZE+1];
00041 char unitname[3*MED_SNAME_SIZE+1];
00042 char dtunit[MED_SNAME_SIZE+1];
00043 med_float *coordinates = NULL;
00044 med_int nnodes = 0;
00045 med_int npoly = 0;
00046 med_int indexsize;
00047 med_int faceIndexSize;
00048 med_int *index = NULL;
00049 med_int *faceindex = NULL;
00050 med_int *connectivity = NULL;
00051 med_int connectivitysize;
00052 med_bool coordinatechangement;
00053 med_bool geotransformation;
00054 int i;
00055 int k,ind1,ind2;
00056 int j, jind1,jind2;
00057
00058
00059 fid = MEDfileOpen("./UsesCase_MEDmesh_15.med",MED_ACC_RDONLY);
00060 if (fid < 0) {
00061 MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
00062 return -1;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
00072 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
00073 MESSAGE("ERROR : mesh info ...");
00074 return -1;
00075 }
00076
00077
00078 if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_POINT1,
00079 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00080 &geotransformation)) < 0) {
00081 MESSAGE("ERROR : number of nodes ...");
00082 return -1;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 if ((indexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00093 MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,
00094 &coordinatechangement,
00095 &geotransformation)) < 0) {
00096 MESSAGE("ERROR : read number of polyedron ...");
00097 return -1;
00098 }
00099 npoly = indexsize-1;
00100 ISCRUTE(npoly);
00101
00102 if ((faceIndexSize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00103 MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,
00104 &coordinatechangement,
00105 &geotransformation)) < 0) {
00106 MESSAGE("ERROR : read number of polyedron ...");
00107 return -1;
00108 }
00109 ISCRUTE(faceIndexSize);
00110
00111
00112 if ((connectivitysize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00113 MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,
00114 &coordinatechangement,
00115 &geotransformation)) < 0) {
00116 MESSAGE("ERROR : read connevity size ...");
00117 return -1;
00118 }
00119 ISCRUTE(connectivitysize);
00120
00121
00122 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
00123 MESSAGE("ERROR : memory allocation ...");
00124 return -1;
00125 }
00126
00127 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00128 coordinates) < 0) {
00129 MESSAGE("ERROR : nodes coordinates ...");
00130 return -1;
00131 }
00132 for (i=0;i<nnodes*spacedim;i++)
00133 printf("%f - ",*(coordinates+i));
00134 printf("\n");
00135
00136
00137
00138 index = (med_int *) malloc(sizeof(med_int)*indexsize);
00139 faceindex = (med_int *) malloc(sizeof(med_int)*faceIndexSize);
00140 connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize);
00141
00142 if (MEDmeshPolyhedronRd(fid,meshname,MED_NO_DT,MED_NO_IT,MED_CELL,MED_NODAL,
00143 index,faceindex,connectivity) < 0) {
00144 MESSAGE("ERROR : read polygon connectivity ...");
00145 return -1;
00146 }
00147
00148 for (i=0;i<npoly;i++)
00149 {
00150 printf(">> MED_POLYHEDRON "IFORMAT" : \n",i+1);
00151 printf("---- Face Index ----- : [ ");
00152 ind1 = *(index+i)-1;
00153 ind2 = *(index+i+1)-1;
00154 for (k=ind1;k<ind2;k++)
00155 printf(IFORMAT" ",*(faceindex+k));
00156 printf(" ] \n");
00157 printf("---- Connectivity ----- : [ ");
00158 for (k=ind1;k<ind2;k++)
00159 {
00160 jind1 = *(faceindex+k)-1;
00161 jind2 = *(faceindex+k+1)-1;
00162 for (j=jind1;j<jind2;j++)
00163 printf(IFORMAT" ",*(connectivity+j));
00164 printf(" \n");
00165 }
00166 printf(" ] \n");
00167 }
00168
00169
00170
00171
00172
00173
00174 if (MEDfileClose(fid) < 0) {
00175 MESSAGE("ERROR : close file");
00176 return -1;
00177 }
00178
00179
00180 if (coordinates)
00181 free(coordinates);
00182
00183 if (index)
00184 free(index);
00185
00186 if (faceindex)
00187 free(faceindex);
00188
00189 if (connectivity)
00190 free(connectivity);
00191
00192 return 0;
00193 }