| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <med.h> |
| 23 |
#define MESGERR 1 |
| 24 |
#include <med_utils.h> |
| 25 |
|
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
int main (int argc, char **argv) { |
| 29 |
|
| 30 |
med_idt fid; |
| 31 |
const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; |
| 32 |
char meshdescription[MED_COMMENT_SIZE+1]=""; |
| 33 |
med_int meshdim; |
| 34 |
med_int spacedim; |
| 35 |
med_sorting_type sortingtype; |
| 36 |
med_int nstep; |
| 37 |
med_mesh_type meshtype; |
| 38 |
med_axis_type axistype; |
| 39 |
char axisname[2*MED_SNAME_SIZE+1]=""; |
| 40 |
char unitname[2*MED_SNAME_SIZE+1]=""; |
| 41 |
char dtunit[MED_SNAME_SIZE+1]=""; |
| 42 |
med_float *coordinates = NULL; |
| 43 |
med_int nnodes = 0; |
| 44 |
med_int npoly = 0; |
| 45 |
med_int indexsize; |
| 46 |
med_int *index = NULL; |
| 47 |
med_int *connectivity = NULL; |
| 48 |
med_int connectivitysize; |
| 49 |
med_bool coordinatechangement; |
| 50 |
med_bool geotransformation; |
| 51 |
int i, k, ind1, ind2; |
| 52 |
int ret=-1; |
| 53 |
|
| 54 |
|
| 55 |
fid = MEDfileOpen("UsesCase_MEDmesh_13.med",MED_ACC_RDONLY); |
| 56 |
if (fid < 0) { |
| 57 |
MESSAGE("ERROR : open file in READ ONLY ACCESS mode ..."); |
| 58 |
goto ERROR; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription, |
| 68 |
dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) { |
| 69 |
MESSAGE("ERROR : mesh info ..."); |
| 70 |
goto ERROR; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_POINT1, |
| 75 |
MED_COORDINATE, MED_NO_CMODE,&coordinatechangement, &geotransformation)) < 0) |
| 76 |
{ MESSAGE("ERROR : number of nodes ..."); |
| 77 |
goto ERROR; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if ((indexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT, |
| 88 |
MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL, |
| 89 |
&coordinatechangement, &geotransformation)) < 0) |
| 90 |
{ MESSAGE("ERROR : read number of polygon ..."); |
| 91 |
goto ERROR; |
| 92 |
} |
| 93 |
npoly = indexsize-1; |
| 94 |
|
| 95 |
|
| 96 |
if ((connectivitysize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT, |
| 97 |
MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL, |
| 98 |
&coordinatechangement, &geotransformation)) < 0) |
| 99 |
{ MESSAGE("ERROR : read connectivity size ..."); |
| 100 |
goto ERROR; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) { |
| 105 |
MESSAGE("ERROR : memory allocation ..."); |
| 106 |
goto ERROR; |
| 107 |
} |
| 108 |
|
| 109 |
if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, coordinates) < 0) |
| 110 |
{ MESSAGE("ERROR : nodes coordinates ..."); |
| 111 |
free(coordinates); |
| 112 |
goto ERROR; |
| 113 |
} |
| 114 |
free(coordinates); |
| 115 |
|
| 116 |
|
| 117 |
index = (med_int *) malloc(sizeof(med_int)*indexsize); |
| 118 |
connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize); |
| 119 |
|
| 120 |
if (MEDmeshPolygonRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, MED_NODAL, index, connectivity) < 0) |
| 121 |
{ MESSAGE("ERROR : read polygon connectivity ..."); |
| 122 |
free(index); |
| 123 |
free(connectivity); |
| 124 |
goto ERROR; |
| 125 |
} |
| 126 |
free(index); |
| 127 |
free(connectivity); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
ret=0; |
| 134 |
ERROR: |
| 135 |
|
| 136 |
|
| 137 |
if (MEDfileClose(fid) < 0) { |
| 138 |
MESSAGE("ERROR : close file"); |
| 139 |
ret=-1; |
| 140 |
} |
| 141 |
|
| 142 |
return ret; |
| 143 |
} |
| 144 |
|