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_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 = 0;
00043   char    maa[MED_NAME_SIZE+1] ="maa1";
00044   med_int mdim = 2;
00045   char    nomfam[MED_NAME_SIZE+1]="";
00046   med_int numfam;
00047   med_int ngro;
00048   char    gro[MED_LNAME_SIZE+1]="";
00049   int     i;
00050   int     nfame = 3;
00051   int     nfamn = 2;
00052   char    nomcoo[2*MED_SNAME_SIZE+1] = "x               y               ";
00053   char    unicoo[2*MED_SNAME_SIZE+1] = "cm              cm              ";
00054 
00055   /* Creation du fichier "test8.med" */
00056   if ((fid = MEDfileOpen("test8.med",MODE_ACCES)) < 0) {
00057     MESSAGE("Erreur a la creation du fichier test8.med");
00058     return -1;
00059   }
00060 
00061   if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH,
00062                  "un maillage pour test8","s", MED_SORT_DTIT,
00063                  MED_CARTESIAN, nomcoo, unicoo) < 0) {
00064     MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa);
00065     return -1;
00066   }
00067 
00068   /* Ecriture des familles                                                */
00069   /* Conventions appliquees dans MED :
00070      - Toujours creer une famille de numero 0 ne comportant aucun attribut
00071      ni groupe (famille de reference pour les noeuds ou les elements
00072      qui ne sont rattaches a aucun groupe ni attribut)
00073      - Les numeros de familles de noeuds sont > 0
00074      - Les numeros de familles des elements sont < 0
00075      - Rien d'imposer sur les noms de familles.
00076      */
00077 
00078   /* Creation de la  famille 0 */
00079   strcpy(nomfam,"FAMILLE_0");
00080   numfam = 0;
00081   if (MEDfamilyCr(fid,maa,nomfam,numfam,0,"") < 0) {
00082     MESSAGE("Erreur a la creation de la famille 0");
00083     return -1;
00084   }
00085 
00086   /* Creation pour correspondre aux cas test precedent de :
00087      - 3 familles d'elements (-1,-2,-3)
00088      - 2 familles de noeuds (1,2) */
00089   nfame = 3;
00090   for (i=0;i<nfame;i++) {
00091     strcpy(nomfam,"FAMILLE_ELEMENT_");
00092     numfam = -(i+1);
00093     sprintf(nomfam,"%s"IFORMAT,nomfam,-numfam);
00094     strcpy(gro,"groupe1");
00095     ngro = 1;
00096     printf("%s - "IFORMAT" - "IFORMAT" \n",nomfam,numfam,
00097            ngro);
00098     if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
00099       MESSAGE("Erreur a la creation de la famille :");
00100       SSCRUTE(nomfam); ISCRUTE(numfam);
00101       return -1;
00102     }
00103   }
00104 
00105   nfamn = 2;
00106   for (i=0;i<nfamn;i++) {
00107     strcpy(nomfam,"FAMILLE_NOEUD_");
00108     numfam = i+1;
00109     sprintf(nomfam,"%s"IFORMAT,nomfam,numfam);
00110     strcpy(gro,"groupe1");
00111     ngro = 1;
00112     if (MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro) < 0) {
00113       MESSAGE("Erreur a la creation de la famille :");
00114       SSCRUTE(nomfam); ISCRUTE(numfam);
00115       return -1;
00116     }
00117   }
00118 
00119 
00120   /* Fermeture du fichier */
00121   if (MEDfileClose(fid) < 0) {
00122     MESSAGE("Erreur a la fermeture du fichier :");
00123     return -1;
00124   }
00125 
00126   return 0;
00127 }
00128 
00129 
00130 
00131 

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