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 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028
00029 #include <string.h>
00030
00031 int main (int argc, char **argv) {
00032 med_idt fid;
00033 const char meshname[MED_NAME_SIZE+1] = "2D structured mesh";
00034 const med_int spacedim = 2;
00035 const med_int meshdim = 2;
00036 const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
00037 const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
00038 med_int axis, size ;
00039 const med_float cooXaxis[5] = {1.,2.,3.,4.,5.};
00040 const med_float cooYaxis[3] = {1.,2.,3.};
00041
00042 const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 ";
00043 const med_int nquad4 = 8;
00044 int ret=-1;
00045
00046
00047 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
00048 if (fid < 0) {
00049 MESSAGE("ERROR : file creation ...");
00050 goto ERROR;
00051 }
00052
00053
00054 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,
00055 "A 2D structured mesh","",MED_SORT_DTIT,
00056 MED_CARTESIAN, axisname, unitname) < 0) {
00057 MESSAGE("ERROR : mesh creation ...");
00058 goto ERROR;
00059 }
00060
00061
00062 if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
00063 MESSAGE("ERROR : write grid type ...");
00064 goto ERROR;
00065 }
00066
00067
00068 axis = 1;
00069 size = 5;
00070 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
00071 axis, size, cooXaxis) < 0) {
00072 MESSAGE("ERROR : write of axis X coordinates ...");
00073 goto ERROR;
00074 }
00075 axis++;
00076 size = 3;
00077 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
00078 axis, size, cooYaxis) < 0) {
00079 MESSAGE("ERROR : write of axis Y coordinates ...");
00080 goto ERROR;
00081 }
00082
00083
00084
00085 if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
00086 MED_CELL, MED_QUAD4, nquad4,
00087 cellsnames) < 0) {
00088 MESSAGE("ERROR : cells names ...");
00089 goto ERROR;
00090 }
00091
00092
00093 if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
00094 MESSAGE("ERROR : quadrangular cells connectivity ...");
00095 goto ERROR;
00096 }
00097
00098 ret = 0;
00099 ERROR:
00100
00101
00102 if (MEDfileClose(fid) < 0) {
00103 MESSAGE("ERROR : close file ...");
00104 ret = -1;
00105 }
00106
00107 return ret;
00108 }
00109