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