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]="2D structured mesh";
00033 med_int spacedim;
00034 med_int meshdim;
00035 char meshdescription[MED_COMMENT_SIZE+1];
00036 char axisname[2*MED_SNAME_SIZE+1];
00037 char unitname[2*MED_SNAME_SIZE+1];
00038 char dtunit[MED_SNAME_SIZE+1];
00039 med_mesh_type meshtype;
00040 med_axis_type axistype;
00041 med_grid_type gridtype;
00042 med_int axis, size ;
00043 med_float *cooXaxis = NULL;
00044 med_float *cooYaxis = NULL;
00045 med_bool coordinatechangement;
00046 med_bool geotransformation;
00047 med_int nstep;
00048 med_sorting_type sortingtype;
00049 int j;
00050 int ret=-1;
00051 int ncell=0;
00052 char *cellsname=NULL;
00053
00054
00055 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_RDONLY);
00056 if (fid < 0) {
00057 MESSAGE("ERROR : open file ...");
00058 goto ERROR;
00059 }
00060
00061
00062 if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
00063 dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
00064 MESSAGE("ERROR : mesh info ...");
00065 goto ERROR;
00066 }
00067
00068
00069 if (MEDmeshGridTypeRd(fid, meshname, &gridtype) < 0) {
00070 MESSAGE("ERROR : read grid type ...");
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080 axis = 1;
00081 if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
00082 MED_NODE, MED_NONE, MED_COORDINATE_AXIS1, MED_NO_CMODE,
00083 &coordinatechangement, &geotransformation)) < 0) {
00084 MESSAGE("ERROR : number of coordinates on X axis ...");
00085 goto ERROR;
00086 }
00087 ncell = size-1;
00088
00089 if ((cooXaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
00090 MESSAGE("ERROR : memory allocation ...");
00091 goto ERROR;
00092 }
00093 if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
00094 axis, cooXaxis) < 0) {
00095 MESSAGE("ERROR : read axis X coordinates ...");
00096 free(cooXaxis);
00097 goto ERROR;
00098 }
00099
00100 free(cooXaxis);
00101
00102
00103 axis = 2;
00104 if ((size = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT,
00105 MED_NODE, MED_NONE, MED_COORDINATE_AXIS2, MED_NO_CMODE,
00106 &coordinatechangement, &geotransformation)) < 0) {
00107 MESSAGE("ERROR : number of coordinates on Y axis ...");
00108 goto ERROR;
00109 }
00110 ncell = ncell * (size-1);
00111
00112 if ((cooYaxis = (med_float *) malloc(sizeof(med_float)*size)) == NULL) {
00113 MESSAGE("ERROR : memory allocation ...");
00114 goto ERROR;
00115 }
00116 if (MEDmeshGridIndexCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT,
00117 axis, cooYaxis) < 0) {
00118 MESSAGE("ERROR : read axis Y coordinates ...");
00119 free(cooYaxis);
00120 goto ERROR;
00121 }
00122
00123 free(cooYaxis);
00124
00125 cellsname = (char *) malloc((sizeof(char))*ncell*MED_SNAME_SIZE+1);
00126 if (MEDmeshEntityNameRd(fid, meshname, MED_NO_DT, MED_NO_IT,
00127 MED_CELL, MED_QUAD4, cellsname) < 0) {
00128 MESSAGE("ERROR : read cells name ...");
00129 free(cellsname);
00130 goto ERROR;
00131 }
00132 free(cellsname);
00133
00134 ret=0;
00135 ERROR:
00136
00137
00138 if (MEDfileClose(fid) < 0) {
00139 MESSAGE("ERROR : close file ...");
00140 ret = -1;
00141 }
00142
00143 return ret;
00144 }