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 With 2 polyhedrons";
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 faceindexsize;
00047 med_int nodeindexsize;
00048 med_int *faceindex = NULL;
00049 med_int *nodeindex = 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, &geotransformation)) < 0)
00080 { MESSAGE("ERROR : number of nodes ...");
00081 return -1;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 if ((faceindexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00095 MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,
00096 &coordinatechangement, &geotransformation)) < 0)
00097 { MESSAGE("ERROR : read number of polyhedrons ...");
00098 return -1;
00099 }
00100 npoly = faceindexsize-1;
00101 ISCRUTE(npoly);
00102
00103 if ((nodeindexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00104 MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,
00105 &coordinatechangement, &geotransformation)) < 0)
00106 { MESSAGE("ERROR : read number of polyhedrons ...");
00107 return -1;
00108 }
00109 ISCRUTE(nodeindexsize);
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, &geotransformation)) < 0)
00115 { MESSAGE("ERROR : read connevity size ...");
00116 return -1;
00117 }
00118 ISCRUTE(connectivitysize);
00119
00120
00121 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
00122 MESSAGE("ERROR : memory allocation ...");
00123 return -1;
00124 }
00125
00126 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00127 coordinates) < 0) {
00128 MESSAGE("ERROR : nodes coordinates ...");
00129 return -1;
00130 }
00131 for (i=0;i<nnodes*spacedim;i++)
00132 printf("%f - ",*(coordinates+i));
00133 printf("\n");
00134
00135
00136
00137 faceindex = (med_int *) malloc(sizeof(med_int)*faceindexsize);
00138 nodeindex = (med_int *) malloc(sizeof(med_int)*nodeindexsize);
00139 connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize);
00140
00141 if (MEDmeshPolyhedronRd(fid,meshname,MED_NO_DT,MED_NO_IT,MED_CELL,MED_NODAL,
00142 faceindex,nodeindex,connectivity) < 0)
00143 { MESSAGE("ERROR : read polygon connectivity ...");
00144 return -1;
00145 }
00146
00147 for (i=0;i<npoly;i++)
00148 {
00149 printf(">> MED_POLYHEDRON "IFORMAT" : \n",i+1);
00150 printf("---- Face Index ----- : [\n");
00151 ind1 = *(faceindex+i)-1;
00152 ind2 = *(faceindex+i+1)-1;
00153 for (k=ind1;k<ind2;k++)
00154 printf(IFORMAT" ",*(nodeindex+k));
00155 printf(" ] \n");
00156 printf("---- Connectivity ----- : [\n");
00157 for (k=ind1;k<ind2;k++)
00158 {
00159 jind1 = *(nodeindex+k)-1;
00160 jind2 = *(nodeindex+k+1)-1;
00161 for (j=jind1;j<jind2;j++)
00162 printf(IFORMAT" ",*(connectivity+j));
00163 printf(" \n");
00164 }
00165 printf(" ] \n");
00166 }
00167
00168
00169
00170
00171
00172
00173 if (MEDfileClose(fid) < 0) {
00174 MESSAGE("ERROR : close file");
00175 return -1;
00176 }
00177
00178
00179 if (coordinates)
00180 free(coordinates);
00181
00182 if (faceindex)
00183 free(faceindex);
00184
00185 if (nodeindex)
00186 free(nodeindex);
00187
00188 if (connectivity)
00189 free(connectivity);
00190
00191 return 0;
00192 }