2.3.6/test8.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 : test8.c
00020  *
00021  * - Description : exemple d'ecriture de familles dans un maillage MED 
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_LECTURE_ECRITURE
00032 #elif DEF_LECT_AJOUT
00033 #define MODE_ACCES MED_LECTURE_AJOUT
00034 #else
00035 #define MODE_ACCES MED_CREATION
00036 #endif
00037 
00038 int main (int argc, char **argv)
00039 
00040 
00041 {
00042   med_idt fid;
00043   char maa[MED_TAILLE_NOM+1] ="maa1";
00044   med_int mdim = 2;
00045   char nomfam[MED_TAILLE_NOM+1]="";
00046   med_int numfam;
00047   char attdes[MED_TAILLE_DESC+1]="";
00048   med_int natt;
00049   med_int attide;
00050   med_int attval;
00051   med_int ngro;
00052   char gro[MED_TAILLE_LNOM+1]="";
00053   int i;
00054   int nfame = 3; 
00055   int nfamn = 2;
00056 
00057   /* Creation du fichier "test8.med" */
00058   if ((fid = MEDouvrir("test8.med",MODE_ACCES)) < 0) {
00059     MESSAGE("Erreur a la creation du fichier test8.med");
00060     return -1;
00061   }
00062   
00063   /* Creation d'un maillage */
00064   if (MEDmaaCr(fid,maa,2,MED_NON_STRUCTURE,
00065                "un maillage pour test8") < 0) {
00066     MESSAGE("Erreur a la creation du maillage");
00067     return -1;
00068   }
00069   
00070   /* Ecriture des familles                                                */
00071   /* Conventions appliquees dans MED :
00072      - Toujours creer une famille de numero 0 ne comportant aucun attribut
00073      ni groupe (famille de reference pour les noeuds ou les elements
00074      qui ne sont rattaches a aucun groupe ni attribut)
00075      - Les numeros de familles de noeuds sont > 0
00076      - Les numeros de familles des elements sont < 0
00077      - Rien d'imposer sur les noms de familles. 
00078      */ 
00079   
00080   /* Creation de la  famille 0 */
00081   strcpy(nomfam,"FAMILLE_0");
00082   numfam = 0;
00083   if (MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,0,
00084                  gro,0) < 0) {
00085     MESSAGE("Erreur a la creation de la famille 0");
00086     return -1;
00087   }
00088   
00089   /* Creation pour correspondre aux cas test precedent de :
00090      - 3 familles d'elements (-1,-2,-3) 
00091      - 2 familles de noeuds (1,2) */
00092   nfame = 3;
00093   for (i=0;i<nfame;i++) {
00094     numfam = -(i+1);
00095     sprintf(nomfam,"%s"IFORMAT,"FAMILLE_ELEMENT_",-numfam);
00096     attide = 1;
00097     attval = numfam*100;
00098     natt = 1;
00099     strcpy(attdes,"description attribut");
00100     strcpy(gro,"groupe1");
00101     ngro = 1;
00102     printf("%s - "IFORMAT" - "IFORMAT" - "IFORMAT" - "IFORMAT" \n",nomfam,numfam,attide,attval,
00103            ngro);
00104     if (MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
00105                  natt,gro,ngro) < 0) {
00106       MESSAGE("Erreur a la creation de la famille :");
00107       SSCRUTE(nomfam); ISCRUTE(numfam);
00108       return -1;
00109     }
00110   }
00111   
00112   nfamn = 2;
00113   for (i=0;i<nfamn;i++) {
00114     numfam = i+1;
00115     sprintf(nomfam,"%s"IFORMAT,"FAMILLE_NOEUD_",numfam);
00116     attide = 1;
00117     attval = numfam*100;
00118     natt = 1;
00119     strcpy(attdes,"description attribut");
00120     strcpy(gro,"groupe1");
00121     ngro = 1;
00122     if (MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
00123                  natt,gro,ngro) < 0) {
00124       MESSAGE("Erreur a la creation de la famille :");
00125       SSCRUTE(nomfam); ISCRUTE(numfam);
00126       return -1;
00127     }
00128   }
00129   
00130   
00131   /* Fermeture du fichier */
00132   if (MEDfermer(fid) < 0) {
00133     MESSAGE("Erreur a la fermeture du fichier :");
00134     return -1;
00135   }          
00136   
00137   return 0;
00138 }
00139 
00140 
00141 
00142 

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