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",
00067 MED_ACC_CREAT);
00068 if (fid < 0) {
00069 MESSAGE("ERROR : file creation ...");
00070 goto ERROR;
00071 }
00072
00073
00074 if (MEDfileCommentWr(fid,
00075 "A 2D unstructured mesh : 12, 12 polygons") < 0) {
00076 MESSAGE("ERROR : write file description ...");
00077 goto ERROR;
00078 }
00079
00080
00081 if (MEDmeshCr(fid,
00082 meshname,
00083 spacedim,
00084 meshdim,
00085 MED_UNSTRUCTURED_MESH,
00086 "A 2D mesh with 2 polygons",
00087 "",
00088 MED_SORT_DTIT,
00089 MED_CARTESIAN,
00090 axisname,
00091 unitname) < 0) {
00092 MESSAGE("ERROR : mesh creation ...");
00093 goto ERROR;
00094 }
00095
00096
00097
00098
00099 if (MEDmeshNodeCoordinateWr(fid,
00100 meshname,
00101 MED_NO_DT,
00102 MED_NO_IT,
00103 MED_UNDEF_DT,
00104 MED_FULL_INTERLACE,
00105 nnodes,
00106 coordinates) < 0) {
00107 MESSAGE("ERROR : nodes coordinates ...");
00108 goto ERROR;
00109 }
00110
00111
00112
00113 if (MEDmeshPolygonWr(fid,
00114 meshname,
00115 MED_NO_DT,
00116 MED_NO_IT,
00117 MED_UNDEF_DT,
00118 MED_CELL,
00119 MED_NODAL,
00120 indexsize,
00121 index,
00122 connectivity) < 0) {
00123 MESSAGE("ERROR : polygon connectivity ...");
00124 goto ERROR;
00125 }
00126
00127
00128
00129 if (MEDfamilyCr(fid,
00130 meshname,
00131 MED_NO_NAME,
00132 0,
00133 0,
00134 MED_NO_GROUP) < 0) {
00135 MESSAGE("ERROR : family 0 creation ...");
00136 goto ERROR;
00137 }
00138
00139 ret=0;
00140 ERROR:
00141
00142
00143 if (MEDfileClose(fid) < 0) {
00144 MESSAGE("ERROR : close file ...");
00145 ret=-1;
00146 }
00147
00148 return ret;
00149 }