# UsesCase_MEDmesh_4.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  EDF R&D, CEA/DEN
    00004  *  MED is free software: you can redistribute it and/or modify
    00005  *  it under the terms of the GNU Lesser General Public License as published by
    00006  *  the Free Software Foundation, either version 3 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  MED is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Lesser General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Lesser General Public License
    00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
    00016  */
    00017
    00018
    00019 /*
    00020  *  How to create a structured mesh
    00021  *
    00022  *  Use case 4 :  write a 2D structured mesh (5x3 cartesian grid)
    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   /*                    12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 */
    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   /* MED file creation */
    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   /* create the structured mesh in the MED file */
    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   /* specify the grid type : MED_CARTESIAN_GRID */
    00062    if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
    00063     MESSAGE("ERROR : write grid type ...");
    00064     goto ERROR;
    00065   }
    00066
    00067    /* write axis "X" and "Y" coordinates */
    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   /* optionnal : names for nodes or elements */
    00084   /* In this case, a name is given to the cells of the mesh */
    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   /* create family 0 : by default, all mesh entities family number is 0 */
    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   /* close MED file  */
    00102   if (MEDfileClose(fid) < 0) {
    00103     MESSAGE("ERROR : close file ...");
    00104     ret = -1;
    00105   }
    00106
    00107   return ret;
    00108 }
    00109