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