00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <med.h>
00033 #define MESGERR 1
00034 #include <med_utils.h>
00035
00036 #include <string.h>
00037
00038 int main (int argc, char **argv) {
00039 med_idt fid;
00040 const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00041 const med_int spacedim = 2;
00042 const med_int meshdim = 2;
00043
00044 const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
00045 const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
00046
00047 const med_float coordinates[2*10] = { 0.5, 0.,
00048 1.5, 0.,
00049 0., 0.5,
00050 1., 0.5,
00051 2., 0.5,
00052 0., 1.,
00053 1., 1.,
00054 2., 1.,
00055 0.5, 2.,
00056 1.5, 2. };
00057 const med_int nnodes = 10;
00058 const med_int indexsize = 3;
00059 const med_int index[3] = {1,7,13};
00060
00061 const med_int connectivity[12] = {1,4,7,9,6,3,
00062 2,5,8,10,7,4};
00063 int ret=-1;
00064
00065
00066 fid = MEDfileOpen("UsesCase_MEDmesh_13.med", MED_ACC_CREAT);
00067 if (fid < 0) {
00068 MESSAGE("ERROR : file creation ...");
00069 goto ERROR;
00070 }
00071
00072
00073 if (MEDfileCommentWr(fid, "A 2D unstructured mesh : 12, 12 polygons") < 0)
00074 { MESSAGE("ERROR : write file description ...");
00075 goto ERROR;
00076 }
00077
00078
00079 if (MEDmeshCr(fid, meshname, spacedim, meshdim,
00080 MED_UNSTRUCTURED_MESH, "A 2D mesh with 2 polygons",
00081 "", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0)
00082 { MESSAGE("ERROR : mesh creation ...");
00083 goto ERROR;
00084 }
00085
00086
00087
00088
00089 if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00090 MED_FULL_INTERLACE, nnodes, coordinates) < 0)
00091 { MESSAGE("ERROR : nodes coordinates ...");
00092 goto ERROR;
00093 }
00094
00095
00096
00097 if (MEDmeshPolygonWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
00098 MED_CELL, MED_NODAL, indexsize, index, connectivity) < 0)
00099 { MESSAGE("ERROR : polygon connectivity ...");
00100 goto ERROR;
00101 }
00102
00103
00104
00105 if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0)
00106 { MESSAGE("ERROR : family 0 creation ...");
00107 goto ERROR;
00108 }
00109
00110 ret=0;
00111 ERROR:
00112
00113
00114 if (MEDfileClose(fid) < 0) {
00115 MESSAGE("ERROR : close file ...");
00116 ret=-1;
00117 }
00118
00119 return ret;
00120 }