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   char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00034   med_int spacedim = 2;
00035   med_int meshdim = 2;
00036   char axisname[2*MED_SNAME_SIZE+1] = "x               y               ";
00037   char unitname[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00038   med_float coordinates[30] = { 2.,1.,  7.,1.,  12.,1.,  17.,1.,  22.,1.,
00039                                 2.,6.,  7.,6.,  12.,6.,  17.,6.,  22.,6.,
00040                                 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.};
00041   med_int nnodes = 15;
00042   med_int triaconnectivity[24] = { 1,7,6,   2,7,1,  3,7,2,   8,7,3,   
00043                                    13,7,8, 12,7,13, 11,7,12, 6,7,11 };
00044   med_int ntria3 = 8;
00045   med_int quadconnectivity[16] = {3,4,9,8,    4,5,10,9, 
00046                                   15,14,9,10, 13,8,9,14};
00047   med_int nquad4 = 4;
00048   
00049   
00050   fid = MEDfileOpen("UsesCase_MEDmesh_1.med",MED_ACC_CREAT);
00051   if (fid < 0) {
00052     MESSAGE("ERROR : file creation ...");
00053     return -1;
00054   }
00055 
00056   
00057   if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) {
00058     MESSAGE("ERROR : write file description ...");
00059     return -1;
00060   }
00061   
00062   
00063   if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, 
00064                 "A 2D unstructured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) {
00065     MESSAGE("ERROR : mesh creation ...");
00066     return -1;
00067   }
00068 
00069   
00070 
00071 
00072   if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
00073                               MED_FULL_INTERLACE, nnodes, coordinates) < 0) {
00074     MESSAGE("ERROR : nodes coordinates ...");
00075     return -1;
00076   }
00077 
00078   
00079   if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3,
00080                                    MED_NODAL, MED_FULL_INTERLACE, ntria3, triaconnectivity) < 0) {
00081     MESSAGE("ERROR : triangular cells connectivity ...");
00082     return -1;
00083   }
00084 
00085   if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4,
00086                                    MED_NODAL, MED_FULL_INTERLACE, nquad4, quadconnectivity) < 0) {
00087     MESSAGE("ERROR : quadrangular cells connectivity ...");
00088     return -1;
00089   }
00090 
00091   
00092   if (MEDfamilyCr(fid, meshname,"", 0, 0, "") < 0) {
00093     MESSAGE("ERROR : quadrangular cells connectivity ...");
00094     return -1;
00095   }
00096   
00097   
00098   if (MEDfileClose(fid)  < 0) {
00099     MESSAGE("ERROR : close file ...");
00100     return -1;
00101   }
00102 
00103   return 0;
00104 }