UsesCase_MEDmesh_14.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2016  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  *  Use case 14 : read a 2D unstructured mesh with 2 polygons
00020  */
00021 
00022 #include <med.h>
00023 #define MESGERR 1
00024 #include <med_utils.h>
00025 
00026 #include <string.h>
00027 
00028 int main (int argc, char **argv) {
00029 
00030   med_idt           fid;
00031   const char        meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
00032   char              meshdescription[MED_COMMENT_SIZE+1]="";
00033   med_int           meshdim;
00034   med_int           spacedim;
00035   med_sorting_type  sortingtype;
00036   med_int           nstep;
00037   med_mesh_type     meshtype;
00038   med_axis_type     axistype;
00039   char              axisname[2*MED_SNAME_SIZE+1]="";
00040   char              unitname[2*MED_SNAME_SIZE+1]="";
00041   char              dtunit[MED_SNAME_SIZE+1]="";
00042   med_float         *coordinates = NULL;
00043   med_int           nnodes = 0;
00044   med_int           npoly = 0;
00045   med_int           indexsize;
00046   med_int           *index = NULL;
00047   med_int           *connectivity = NULL;
00048   med_int           connectivitysize;
00049   med_bool          coordinatechangement;
00050   med_bool          geotransformation;
00051   int               i, k, ind1, ind2;
00052   int               ret=-1;
00053 
00054   /* open MED file with READ ONLY access mode */
00055   fid = MEDfileOpen("UsesCase_MEDmesh_13.med",MED_ACC_RDONLY);
00056   if (fid < 0) {
00057     MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
00058     goto ERROR;
00059   }
00060 
00061   /* 
00062    * ... we know that the MED file has only one mesh, 
00063    * a real code would check ... 
00064    */
00065 
00066   /* read mesh informations : mesh dimension, space dimension ... */
00067   if (MEDmeshInfoByName(fid, meshname, &spacedim, &meshdim, &meshtype, meshdescription, 
00068                         dtunit, &sortingtype, &nstep, &axistype, axisname, unitname) < 0) {
00069     MESSAGE("ERROR : mesh info ...");
00070     goto ERROR;
00071   }
00072 
00073   /* read how many nodes in the mesh */
00074   if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_POINT1,
00075                                MED_COORDINATE, MED_NO_CMODE,&coordinatechangement, &geotransformation)) < 0)
00076     { MESSAGE("ERROR : number of nodes ...");
00077       goto ERROR;
00078     }
00079   
00080   /* 
00081    * ... we know that we only have MED_POLYGON celles in the mesh, 
00082    * a real code would check all MED geometry cell types ... 
00083    */
00084 
00085   /* How many polygon in the mesh in nodal connectivity mode */
00086   /* For the polygons, we get the size of array index */
00087   if ((indexsize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00088                                   MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,
00089                                   &coordinatechangement, &geotransformation)) < 0)
00090     { MESSAGE("ERROR : read number of polygon ...");
00091       goto ERROR;
00092     }
00093   npoly = indexsize-1;
00094 
00095   /* how many nodes for the polygon connectivity ? */
00096   if ((connectivitysize = MEDmeshnEntity(fid,meshname,MED_NO_DT,MED_NO_IT,
00097                                          MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,
00098                                          &coordinatechangement, &geotransformation)) < 0)
00099     { MESSAGE("ERROR : read connevity size ...");
00100       goto ERROR;
00101     }
00102 
00103   /* read mesh nodes coordinates */
00104   if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
00105     MESSAGE("ERROR : memory allocation ...");
00106     goto ERROR;
00107   }
00108 
00109   if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, coordinates) < 0)
00110     { MESSAGE("ERROR : nodes coordinates ...");
00111       free(coordinates);
00112       goto ERROR;
00113     }
00114   free(coordinates);
00115 
00116   /* read polygons connectivity */
00117   index        = (med_int *) malloc(sizeof(med_int)*indexsize);
00118   connectivity = (med_int *) malloc(sizeof(med_int)*connectivitysize);
00119 
00120   if (MEDmeshPolygonRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, MED_NODAL, index, connectivity) < 0)
00121     { MESSAGE("ERROR : read polygon connectivity ...");
00122       free(index);
00123       free(connectivity);
00124       goto ERROR;
00125     }
00126   free(index);
00127   free(connectivity);
00128   
00129   /* 
00130    * ... we know that the family number of nodes and elements is 0, a real code would check ...
00131    */
00132 
00133   ret=0;
00134  ERROR:
00135 
00136   /* close MED file */
00137   if (MEDfileClose(fid) < 0) {
00138     MESSAGE("ERROR : close file");             
00139     ret=-1; 
00140   } 
00141 
00142   return ret;
00143 }
00144 

Généré le Thu Jan 21 18:06:09 2016 pour MED fichier par  doxygen 1.6.1