2.3.6/test8.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  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     strcpy(nomfam,"FAMILLE_ELEMENT_");
00095     numfam = -(i+1);
00096     sprintf(nomfam,"%s"IFORMAT,nomfam,-numfam);
00097     attide = 1;
00098     attval = numfam*100;
00099     natt = 1;
00100     strcpy(attdes,"description attribut");
00101     strcpy(gro,"groupe1");
00102     ngro = 1;
00103     printf("%s - "IFORMAT" - "IFORMAT" - "IFORMAT" - "IFORMAT" \n",nomfam,numfam,attide,attval,
00104            ngro);
00105     if (MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
00106                  natt,gro,ngro) < 0) {
00107       MESSAGE("Erreur a la creation de la famille :");
00108       SSCRUTE(nomfam); ISCRUTE(numfam);
00109       return -1;
00110     }
00111   }
00112   
00113   nfamn = 2;
00114   for (i=0;i<nfamn;i++) {
00115     strcpy(nomfam,"FAMILLE_NOEUD_");
00116     numfam = i+1;
00117     sprintf(nomfam,"%s"IFORMAT,nomfam,numfam);
00118     attide = 1;
00119     attval = numfam*100;
00120     natt = 1;
00121     strcpy(attdes,"description attribut");
00122     strcpy(gro,"groupe1");
00123     ngro = 1;
00124     if (MEDfamCr(fid,maa,nomfam,numfam,&attide,&attval,attdes,
00125                  natt,gro,ngro) < 0) {
00126       MESSAGE("Erreur a la creation de la famille :");
00127       SSCRUTE(nomfam); ISCRUTE(numfam);
00128       return -1;
00129     }
00130   }
00131   
00132   
00133   /* Fermeture du fichier */
00134   if (MEDfermer(fid) < 0) {
00135     MESSAGE("Erreur a la fermeture du fichier :");
00136     return -1;
00137   }          
00138   
00139   return 0;
00140 }
00141 
00142 
00143 
00144 

Généré le Mon May 16 17:10:24 2011 pour MED fichier par  doxygen 1.6.1