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 const med_int nquad4 = 8;
00042
00043 const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 ";
00044 const char familyname [MED_NAME_SIZE+1] = "CART_GRID_QUAD_FAMILY";
00045 const char groupname [MED_LNAME_SIZE+1] = "CART_GRID_GROUP";
00046 const med_int familynumbers[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
00047 int ret=-1;
00048
00049
00050 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
00051 if (fid < 0) {
00052 MESSAGE("ERROR : file creation ...");
00053 goto ERROR;
00054 }
00055
00056
00057 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,
00058 "A 2D structured mesh","",MED_SORT_DTIT,
00059 MED_CARTESIAN, axisname, unitname) < 0) {
00060 MESSAGE("ERROR : mesh creation ...");
00061 goto ERROR;
00062 }
00063
00064
00065 if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
00066 MESSAGE("ERROR : write grid type ...");
00067 goto ERROR;
00068 }
00069
00070
00071 axis = 1;
00072 size = 5;
00073 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
00074 axis, size, cooXaxis) < 0) {
00075 MESSAGE("ERROR : write of axis X coordinates ...");
00076 goto ERROR;
00077 }
00078 axis++;
00079 size = 3;
00080 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
00081 axis, size, cooYaxis) < 0) {
00082 MESSAGE("ERROR : write of axis Y coordinates ...");
00083 goto ERROR;
00084 }
00085
00086
00087
00088 if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
00089 MED_CELL, MED_QUAD4, nquad4, cellsnames) < 0) {
00090 MESSAGE("ERROR : cells names ...");
00091 goto ERROR;
00092 }
00093
00094
00095 if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
00096 MESSAGE("ERROR : quadrangular cells connectivity ...");
00097 goto ERROR;
00098 }
00099
00100
00101
00102 if (MEDfamilyCr(fid, meshname,familyname, 1, -1, groupname) < 0) {
00103 MESSAGE("ERROR : family creation ...");
00104 goto ERROR;
00105 }
00106
00107
00108 if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
00109 MED_CELL, MED_QUAD4, nquad4, familynumbers) < 0) {
00110 MESSAGE("ERROR : nodes family numbers ...");
00111 goto ERROR;
00112 }
00113
00114 ret = 0;
00115 ERROR:
00116
00117
00118 if (MEDfileClose(fid) < 0) {
00119 MESSAGE("ERROR : close file ...");
00120 ret = -1;
00121 }
00122
00123 return ret;
00124 }
00125