2.3.6/test17.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 : test17.c
00020  *
00021  * - Description : lecture d'elements de maillages MED ecrits par test16
00022  *                 via les routines de niveau 2
00023  *                 - equivalent a test7.c
00024  *
00025  *****************************************************************************/
00026 
00027 #include <med.h>
00028 #define MESGERR 1
00029 #include "med_utils.h"
00030 #include <string.h>
00031 
00032 #ifdef DEF_LECT_ECR
00033 #define MODE_ACCES MED_LECTURE_ECRITURE
00034 #elif DEF_LECT_AJOUT
00035 #define MODE_ACCES MED_LECTURE_AJOUT
00036 #else
00037 #define MODE_ACCES MED_CREATION
00038 #endif
00039 
00040 int main (int argc, char **argv)
00041 
00042 
00043 {
00044   med_err ret = 0;
00045   med_idt fid;
00046   med_int nse2;
00047   med_int *se2;
00048   char *nomse2;
00049   med_int *numse2;
00050   med_int *nufase2; 
00051   med_int ntr3;
00052   med_int *tr3;
00053   char *nomtr3;
00054   med_int *numtr3;
00055   med_int *nufatr3;
00056   char maa[MED_TAILLE_NOM+1] ="maa1";
00057   med_int mdim;
00058   med_booleen inoele1,inoele2,inuele1,inuele2;
00059   med_int tse2,ttr3;
00060   med_int i;
00061   char str[MED_TAILLE_PNOM+1];
00062   char desc[MED_TAILLE_DESC+1];
00063   med_maillage type;
00064 
00065   /* Ouverture du fichier test16.med en lecture seule */
00066   if ((fid = MEDouvrir("test16.med",MED_LECTURE)) < 0) {
00067     MESSAGE("Erreur a l'ouverture du fichier test16.med");
00068     return -1;
00069   }
00070 
00071   /* Lecture des infos sur le 1er maillage */
00072   if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
00073     MESSAGE("Erreur a la lecture des infos sur le 1er maillage");
00074     return -1;
00075   }
00076   printf("Maillage de nom : %s et de dimension "IFORMAT" \n",maa,mdim);
00077 
00078   /* Lecture du nombre de triangle et de segment */
00079   if ((nse2 = MEDnEntMaa(fid,maa,MED_CONN,MED_ARETE,MED_SEG2,MED_DESC)) < 0) {
00080     MESSAGE("Erreur a la lecture du nombre de segments ");
00081     return -1;
00082   }
00083   if ((ntr3 = MEDnEntMaa(fid,maa,MED_CONN,MED_MAILLE,MED_TRIA3,MED_DESC))<0) {
00084     MESSAGE("Erreur a la lecture du nombre de triangles ");
00085     return -1;
00086   }
00087   printf("Nombre de MED_SEG2 : "IFORMAT" - nombre de MED_TRIA3 :"IFORMAT"\n",nse2,ntr3);
00088 
00089   /* Allocations memoire */ 
00090   tse2 = 2;
00091   se2  = (med_int*) malloc(sizeof(med_int)*tse2*nse2);
00092   nomse2 = (char*) malloc(MED_TAILLE_PNOM*nse2+1);
00093   numse2 = (med_int*) malloc(sizeof(med_int)*nse2);
00094   nufase2 = (med_int*) malloc(sizeof(med_int)*nse2);
00095 
00096   ttr3 = 3;
00097   tr3 = (med_int*) malloc(sizeof(med_int)*ntr3*ttr3);
00098   nomtr3 = (char*) malloc(MED_TAILLE_PNOM*ntr3+1);
00099   numtr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
00100   nufatr3 = (med_int*) malloc(sizeof(med_int)*ntr3);
00101 
00102   /* Lecture des aretes segments MED_SEG2 : 
00103      - Connectivite,
00104      - Noms (optionnel)
00105      - Numeros (optionnel)
00106      - Numeros de familles */
00107   if (MEDelementsLire(fid,maa,mdim,se2,MED_NO_INTERLACE,nomse2,&inoele1,numse2,&inuele1,
00108                       nufase2,nse2,MED_ARETE,MED_SEG2,MED_DESC) < 0) {
00109     MESSAGE("Erreur a la lecture des segments");
00110     ret = -1;
00111   }
00112 
00113   /* Lecture des mailles triangles MED_TRIA3 : 
00114      - Connectivite,
00115      - Noms (optionnel)
00116      - Numeros (optionnel)
00117      - Numeros de familles */
00118   if (MEDelementsLire(fid,maa,mdim,tr3,MED_NO_INTERLACE,nomtr3,&inoele2,numtr3,&inuele2,
00119                       nufatr3,ntr3,MED_MAILLE,MED_TRIA3,MED_DESC) < 0) {
00120     MESSAGE("Erreur a la lecture des triangles");
00121     ret = -1;
00122   }
00123 
00124   /* Fermeture du fichier */
00125   if (MEDfermer(fid) < 0) {
00126     MESSAGE("Erreur a la fermeture du fichier");
00127     ret = -1;
00128   }
00129 
00130   /* Affichage */
00131   if (ret == 0) {
00132     if (nse2 > 0) {
00133       printf("Connectivite des segments : \n");
00134       for (i=0;i<nse2*tse2;i++)
00135         printf(IFORMAT" ",*(se2+i));
00136       if (inoele1) {
00137         printf("\nNoms des segments :\n");
00138         for (i=0;i<nse2;i++) {
00139           strncpy(str,nomse2+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00140           str[MED_TAILLE_PNOM] = '\0';
00141           printf("%s ",str);
00142         }
00143       }
00144       if (inuele1) {
00145         printf("\nNumeros des segments :\n");
00146         for (i=0;i<nse2;i++)
00147           printf(IFORMAT" ",*(numse2+i));
00148       }      
00149       printf("\nNumeros des familles des segments :\n");
00150       for (i=0;i<nse2;i++)
00151         printf(IFORMAT" ",*(nufase2+i));
00152     }
00153 
00154     if (ntr3 > 0) {
00155       printf("\nConnectivite des triangles : \n");
00156       for (i=0;i<ntr3*ttr3;i++)
00157         printf(IFORMAT" ",*(tr3+i));
00158       if (inoele2) {
00159         printf("\nNoms des triangles :\n");
00160         for (i=0;i<ntr3;i++) {
00161           strncpy(str,nomtr3+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00162           str[MED_TAILLE_PNOM] = '\0';
00163           printf("%s ",str);
00164         }
00165       }
00166       if (inuele2) {
00167         printf("\nNumeros des triangles :\n");
00168         for (i=0;i<ntr3;i++)
00169           printf(IFORMAT" ",*(numtr3+i));
00170       }      
00171       printf("\nNumeros des familles des triangles :\n");
00172       for (i=0;i<ntr3;i++)
00173         printf(IFORMAT" ",*(nufatr3+i));
00174 
00175       printf("\n");
00176     }
00177   }
00178 
00179   /* Nettoyage memoire */
00180   free(se2);
00181   free(nomse2);
00182   free(numse2);
00183   free(nufase2);
00184 
00185   free(tr3);
00186   free(nomtr3);
00187   free(numtr3);
00188   free(nufatr3);
00189 
00190   return ret;
00191 }
00192 
00193 
00194 
00195 

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