test19.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  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  * - Nom du fichier : test19.c
00020  *
00021  * - Description : conversion groupes => famille 
00022  *
00023  *****************************************************************************/
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include "med_utils.h"
00028 #include <string.h>
00029 
00030 #ifdef DEF_LECT_ECR
00031 #define MODE_ACCES MED_ACC_RDWR
00032 #elif DEF_LECT_AJOUT
00033 #define MODE_ACCES MED_ACC_RDEXT
00034 #else
00035 #define MODE_ACCES MED_ACC_CREAT
00036 #endif
00037 
00038 int main (int argc, char **argv)
00039 
00040 
00041 {
00042   med_idt fid;
00043   char maa[MED_NAME_SIZE+1] = "maillage_test19";
00044   char desc[MED_COMMENT_SIZE+1]="un maillage pour test19.med";
00045   med_int mdim=2;
00046   /* Donnees de tests pour MEDgro2FamCr() 
00047      Les noeuds/mailles sont numerotes de 1 a 5 et les
00048      groupes de 1 a 3.
00049      Au depart, on a :
00050      - G1 : 1,2
00051      - G2 : 3,4,6
00052      - G3 : 1,4
00053      Au retour, on foit avoir 4 familles de noeuds + 4 familles de mailles 
00054      + la famille 0 dans le fichier :
00055      - F0 : 5       - groupes : aucun groupe par defaut (convention habituelle).
00056      - F1 : 1       - groupes : G1,G3  
00057      - F2 : 2       - groupes : G1
00058      - F3 : 3,6     - groupes : G2
00059      - F4 : 4       - groupes : G2,G3
00060   */
00061   med_int ngroup = 3;
00062   med_int nent = 6;
00063   char nom_groupes[MED_LNAME_SIZE*3+1];
00064   /*                     0 1  2 3 4  5 6 */
00065   med_int entites[7] = { 1,2, 3,4,6, 1,4};
00066   med_int index[4] =   { 1,   3,     6,   8};
00067   int i;
00068   char nom_famille0[MED_NAME_SIZE+1] = "FAMILLE0";
00069   /* on fait la meme distribution pour des mailles */
00070   med_int ngeo = 3;
00071   med_geometry_type geo[3] = {MED_SEG2,MED_TRIA3,MED_TETRA4};
00072   /* MED_SEG2 : M1,M2,M3 - MED_TRI3 : M4,M5 - MED_TETRA4 : M6 */
00073   med_int index_geo[4] = {1,4,6,7};
00074 
00075   /* Creation du fichier test19.med */
00076   if ((fid = MEDfileOpen("test19.med",MODE_ACCES)) < 0) {
00077     MESSAGE("Erreur a la creation du fichier test19.med");
00078     return -1;
00079   }
00080   printf("Creation du fichier test19.med \n");
00081 
00082   /* Creation du maillage */
00083   if (MEDmaaCr(fid,maa,mdim,MED_UNSTRUCTURED_MESH,desc) < 0) {
00084     MESSAGE("Erreur a la creation du maillage");
00085     return -1;
00086   }
00087   printf("Creation du maillage \n");
00088 
00089   /* on teste la fonction MEDgro2fam() */
00090   /* on definit les noms des groupes */
00091   strcpy(nom_groupes,"GROUPE 1");
00092   for (i=8;i<MED_LNAME_SIZE;i++)
00093     nom_groupes[i] = ' ';
00094   nom_groupes[MED_LNAME_SIZE] = '\0';
00095   strcat(nom_groupes,"GROUPE 2");
00096   for (i=8;i<MED_LNAME_SIZE;i++)
00097     nom_groupes[MED_LNAME_SIZE+i] = ' ';
00098   nom_groupes[2*MED_LNAME_SIZE] = '\0';
00099   strcat(nom_groupes,"GROUPE 3");
00100   for (i=8;i<MED_LNAME_SIZE;i++)
00101     nom_groupes[2*MED_LNAME_SIZE+i] = ' ';
00102   nom_groupes[3*MED_LNAME_SIZE] = '\0';
00103 
00104   /* On cree la famille 0 */
00105   if (MEDfamCr(fid,maa,nom_famille0,0,NULL,NULL,NULL,0,NULL,0) < 0) {
00106     MESSAGE("Erreur a la creation de la famille 0");
00107     return -1;
00108   }
00109   printf("Creation de la famille 0 \n");
00110 
00111   /* 
00112    * On definit et on archive les familles de noeuds dans test.19.med 
00113    */
00114   if (MEDgro2famCr(fid,maa,nom_groupes,index,ngroup,entites,nent,
00115                    MED_NODE,NULL,NULL,0) < 0) {
00116     MESSAGE("Erreur a la creation des familles de noeuds ");
00117     return -1;
00118   }
00119   printf("On constuit les familles de noeuds et on les stocke dans test19.med \n");
00120 
00121   /* 
00122    * On fait la meme chose pour des mailles de differents types 
00123    */
00124   if (MEDgro2famCr(fid,maa,nom_groupes,index,ngroup,entites,nent,
00125                    MED_CELL,geo,index_geo,ngeo) < 0) {
00126     MESSAGE("Erreur a la creation des familles d'elements ");
00127     return -1;
00128   }
00129   printf("On constuit les familles d'elements et on les stocke dans test19.med \n");  
00130 
00131   /* Fermeture du fichier */
00132   if (MEDfermer(fid) <0) {
00133     MESSAGE("Erreur a la fermeture du fichier");
00134     return -1;
00135   }
00136   printf("Fermeture du fichier \n");
00137   
00138   return 0;
00139 }

Généré le Thu Oct 8 14:26:17 2015 pour MED fichier par  doxygen 1.6.1