| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include <med.h> |
| 33 |
#define MESGERR 1 |
| 34 |
#include <med_utils.h> |
| 35 |
|
| 36 |
#include <string.h> |
| 37 |
|
| 38 |
int main (int argc, char **argv) { |
| 39 |
med_idt fid; |
| 40 |
const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; |
| 41 |
const med_int spacedim = 2; |
| 42 |
const med_int meshdim = 2; |
| 43 |
|
| 44 |
const char axisname[2*MED_SNAME_SIZE+1] = "x y "; |
| 45 |
const char unitname[2*MED_SNAME_SIZE+1] = "cm cm "; |
| 46 |
|
| 47 |
const med_float coordinates[2*10] = { 0.5, 0., |
| 48 |
1.5, 0., |
| 49 |
0., 0.5, |
| 50 |
1., 0.5, |
| 51 |
2., 0.5, |
| 52 |
0., 1., |
| 53 |
1., 1., |
| 54 |
2., 1., |
| 55 |
0.5, 2., |
| 56 |
1.5, 2. }; |
| 57 |
const med_int nnodes = 10; |
| 58 |
const med_int indexsize = 3; |
| 59 |
const med_int index[3] = {1,7,13}; |
| 60 |
|
| 61 |
const med_int connectivity[12] = {1,4,7,9,6,3, |
| 62 |
2,5,8,10,7,4}; |
| 63 |
int ret=-1; |
| 64 |
|
| 65 |
|
| 66 |
fid = MEDfileOpen("UsesCase_MEDmesh_13.med", MED_ACC_CREAT); |
| 67 |
if (fid < 0) { |
| 68 |
MESSAGE("ERROR : file creation ..."); |
| 69 |
goto ERROR; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
if (MEDfileCommentWr(fid, "A 2D unstructured mesh : 12, 12 polygons") < 0) |
| 74 |
{ MESSAGE("ERROR : write file description ..."); |
| 75 |
goto ERROR; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
if (MEDmeshCr(fid, meshname, spacedim, meshdim, |
| 80 |
MED_UNSTRUCTURED_MESH, "A 2D mesh with 2 polygons", |
| 81 |
"", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0) |
| 82 |
{ MESSAGE("ERROR : mesh creation ..."); |
| 83 |
goto ERROR; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, |
| 90 |
MED_FULL_INTERLACE, nnodes, coordinates) < 0) |
| 91 |
{ MESSAGE("ERROR : nodes coordinates ..."); |
| 92 |
goto ERROR; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
if (MEDmeshPolygonWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, |
| 98 |
MED_CELL, MED_NODAL, indexsize, index, connectivity) < 0) |
| 99 |
{ MESSAGE("ERROR : polygon connectivity ..."); |
| 100 |
goto ERROR; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) |
| 106 |
{ MESSAGE("ERROR : family 0 creation ..."); |
| 107 |
goto ERROR; |
| 108 |
} |
| 109 |
|
| 110 |
ret=0; |
| 111 |
ERROR: |
| 112 |
|
| 113 |
|
| 114 |
if (MEDfileClose(fid) < 0) { |
| 115 |
MESSAGE("ERROR : close file ..."); |
| 116 |
ret=-1; |
| 117 |
} |
| 118 |
|
| 119 |
return ret; |
| 120 |
} |