00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <med.h>
00023 #define MESGERR 1
00024 #include <med_utils.h>
00025
00026 #include <string.h>
00027
00028 int main (int argc, char **argv) {
00029 med_idt fid;
00030 const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00031 char meshdescription[MED_COMMENT_SIZE+1];
00032 med_int meshdim;
00033 med_int spacedim;
00034 med_sorting_type sortingtype;
00035 med_int nstep;
00036 med_mesh_type meshtype;
00037 med_axis_type axistype;
00038 char axisname[2*MED_SNAME_SIZE+1];
00039 char unitname[2*MED_SNAME_SIZE+1];
00040 char dtunit[MED_SNAME_SIZE+1];
00041 med_float *coordinates = NULL;
00042 med_int nnodes = 0;
00043 med_int *triaconnectivity = NULL;
00044 med_int ntria3 = 0;
00045 med_int *quadconnectivity = NULL;
00046 med_int nquad4 = 0;
00047 med_bool coordinatechangement;
00048 med_bool geotransformation;
00049 int i;
00050 int ret = -1;
00051
00052
00053 fid = MEDfileOpen("UsesCase_MEDmesh_1.med",MED_ACC_RDONLY);
00054 if (fid < 0) {
00055 MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
00056 goto ERROR;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
00066 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
00067 MESSAGE("ERROR : mesh info ...");
00068 goto ERROR;
00069 }
00070
00071
00072 if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE,
00073 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
00074 &geotransformation)) < 0) {
00075 MESSAGE("ERROR : number of nodes ...");
00076 goto ERROR;
00077 }
00078
00079
00080
00081
00082
00083
00084
00085 if ((ntria3 = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_TRIA3,
00086 MED_CONNECTIVITY, MED_NODAL,&coordinatechangement,
00087 &geotransformation)) < 0) {
00088 MESSAGE("ERROR : number of MED_TRIA3 ...");
00089 goto ERROR;
00090 }
00091
00092
00093 if ((nquad4 = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_QUAD4,
00094 MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
00095 &geotransformation)) < 0) {
00096 MESSAGE("ERROR : number of MED_QUAD4 ...");
00097 goto ERROR;
00098 }
00099
00100
00101
00102 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
00103 MESSAGE("ERROR : memory allocation ...");
00104 goto ERROR;
00105 }
00106
00107 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
00108 coordinates) < 0) {
00109 MESSAGE("ERROR : nodes coordinates ...");
00110 goto ERROR;
00111 }
00112
00113
00114 if ((triaconnectivity = (med_int *) malloc(sizeof(med_int)*ntria3*3)) == NULL) {
00115 MESSAGE("ERROR : memory allocation ...");
00116 goto ERROR;
00117 }
00118 if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
00119 MED_TRIA3, MED_NODAL, MED_FULL_INTERLACE, triaconnectivity) < 0) {
00120 MESSAGE("ERROR : MED_TRIA3 connectivity ...");
00121 goto ERROR;
00122 }
00123
00124 if ((quadconnectivity = (med_int *) malloc(sizeof(med_int)*nquad4*4)) == NULL) {
00125 MESSAGE("ERROR : memory allocation ...");
00126 goto ERROR;
00127 }
00128 if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
00129 MED_QUAD4, MED_NODAL, MED_FULL_INTERLACE, quadconnectivity) < 0) {
00130 MESSAGE("ERROR : MED_TRIA3 connectivity ...");
00131 goto ERROR;
00132 }
00133
00134
00135
00136
00137 ret = 0;
00138 ERROR :
00139
00140
00141 if (coordinates)
00142 free(coordinates);
00143
00144 if (triaconnectivity)
00145 free(triaconnectivity);
00146
00147 if (quadconnectivity)
00148 free(quadconnectivity);
00149
00150
00151 if (MEDfileClose(fid) < 0) {
00152 MESSAGE("ERROR : close file");
00153 ret = -1;
00154 }
00155
00156 return ret;
00157 }
00158