2.3.6/test26.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 /******************************************************************************
00020  * - Nom du fichier : test26.c
00021  *
00022  * - Description : lecture de mailles de type MED_POLYEDRE
00023  *                 dans le maillage MED du fichier test25.med 
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   char maa[MED_TAILLE_NOM+1];  
00047   med_int nmaa,i,mdim,npoly,j;
00048   char desc[MED_TAILLE_DESC+1];  
00049   med_int taille,nf,np;
00050   med_int taille2,nf2,np2;
00051   med_int *conn, *conn2, *indexf, *indexf2, *num, *fam;
00052   med_int *indexp, *indexp2;
00053   char *nom;
00054   char tmp[MED_TAILLE_PNOM+1];
00055   int ind1, ind2,k,nfaces,nnoeuds,l;
00056   med_maillage type;
00057 
00058   /* Ouverture du fichier test25.med en lecture seule */
00059   fid = MEDouvrir("test25.med",MED_LECTURE);
00060   if (fid < 0) {
00061     MESSAGE("Erreur a l'ouverture du fichier test25.med");
00062     return -1;
00063   }
00064   printf("Ouverture du fichier test25.med \n");
00065 
00066   /* Lecture du nombre de maillages */
00067   nmaa = MEDnMaa(fid);
00068   if (nmaa < 0) {
00069     MESSAGE("Erreur a lecture du nombre de maillage");
00070     return -1;
00071   }
00072   printf("Nombre de maillages = "IFORMAT"\n",nmaa);
00073 
00074   for (i=0;i<nmaa;i++)
00075     if (ret == 0) {
00076       
00077       /* Lecture des infos sur le maillage */
00078       if (MEDmaaInfo(fid,i+1,maa,&mdim,&type,desc) < 0) {
00079         MESSAGE("Erreur a lecture des infos sur le maillage");
00080         return -1;
00081       }
00082       printf("maillage "IFORMAT" de nom [%s] et de dimension : "IFORMAT" \n",i+1,maa,mdim);
00083       
00084       /* Combien de mailles polyedres en mode nodal */
00085       if ((npoly = MEDnEntMaa(fid,maa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD)) < 0) {
00086         MESSAGE("Erreur a lecture du nombre de maille MED_POLYEDRE en mode nodal");
00087         return -1;
00088       }
00089       printf("Nombre de mailles polyedres : "IFORMAT" \n",npoly); 
00090       
00091       /* Quelle taille pour le tableau des connectivites et d'indexation 
00092          en mode MED_NOD */
00093       if (MEDpolyedreInfo(fid,maa,MED_NOD,&nf,&taille) < 0) {
00094         MESSAGE("Erreur a lecture des infos sur les polyedres");
00095         return -1;
00096       }
00097       printf("Taille a allouer pour la connectivite nodale des polyedres : "IFORMAT" \n",taille);
00098       printf("Taille a allouer pour le tableau d'indexation des faces : "IFORMAT" \n",nf); 
00099       
00100       /* Quelle taille pour le tableau des connectivites et d'indexation 
00101          en mode MED_DESC */
00102       if (MEDpolyedreInfo(fid,maa,MED_DESC,&nf2,&taille2) < 0) {
00103         MESSAGE("Erreur a la lecture des infos sur les polyedres");
00104         return -1;
00105       }
00106       printf("Taille a allouer pour la connectivite descendante des polyedres : "IFORMAT" \n",taille2);
00107       printf("Taille a allouer pour le tableau d'indexation des types de faces : "IFORMAT" \n",nf2); 
00108       
00109       /* Allocation memoire : 
00110        *  - tableau indexp et indexp2 : npoly + 1
00111        *  - tableau indexf et indexf2 : nf et nf2
00112        *  - tableau des connectivites : consize
00113        *  - tableaux numeros et numeros de familles : npoly
00114        *  - tableau des noms : MED_TAILLE_PNOM*npoly + 1 
00115        */
00116       indexp   = (med_int *) malloc(sizeof(med_int)*(npoly+1));
00117       indexp2  = (med_int *) malloc(sizeof(med_int)*(npoly+1));
00118       indexf   = (med_int *) malloc(sizeof(med_int)*nf);
00119       indexf2  = (med_int *) malloc(sizeof(med_int)*nf2);
00120       conn     = (med_int *) malloc(sizeof(med_int)*taille);
00121       conn2    = (med_int *) malloc(sizeof(med_int)*taille2);
00122       num      = (med_int *) malloc(sizeof(med_int)*npoly);
00123       fam      = (med_int *) malloc(sizeof(med_int)*npoly);
00124       nom      = (char *) malloc(sizeof(char)*MED_TAILLE_PNOM*npoly+1);
00125       
00126       /* Lecture de la connectivite des mailles polyedres en mode nodal */
00127       if (MEDpolyedreConnLire(fid,maa,indexp,npoly+1,indexf,nf,conn,MED_NOD) < 0) {
00128         MESSAGE("Erreur a lecture de la connectivite nodale des polyedres");
00129         ret = -1;
00130       }
00131       printf("Lecture de la connectivite des mailles MED_POLYEDRE en mode nodal \n");
00132       
00133       /* Lecture de la connectivite des mailles polyedres en mode descendant */ 
00134       if (ret == 0) {
00135         if (MEDpolyedreConnLire(fid,maa,indexp2,npoly+1,indexf2,nf2,conn2,MED_DESC) < 0) {
00136           MESSAGE("Erreur a lecture de la connectivite descendante des polyedres");
00137           ret = -1;
00138         }
00139         printf("Lecture de la connectivite des mailles MED_POLYEDRE en mode descendant \n");
00140       }
00141       
00142       /* Lecture noms */
00143       if (ret == 0) {
00144         if (MEDnomLire(fid,maa,nom,npoly,MED_MAILLE,MED_POLYEDRE) < 0) {
00145           MESSAGE("Erreur a lecture des noms des polyedres");
00146           ret = -1;
00147         }
00148         printf("Lecture des noms des mailles MED_POLYEDRE \n");
00149       }
00150       
00151       /* Lecture des numeros */
00152       if (ret == 0) {
00153         if (MEDnumLire(fid,maa,num,npoly,MED_MAILLE,MED_POLYEDRE) < 0) {
00154           MESSAGE("Erreur a lecture des numeros des polyedres");
00155           ret = -1;
00156         }
00157         printf("Lecture des numeros des mailles MED_POLYEDRE \n");
00158       }
00159       
00160       /* Lecture des numeros de familles */
00161       if (ret == 0) {
00162         if (MEDfamLire(fid,maa,fam,npoly,MED_MAILLE,MED_POLYEDRE) < 0) {
00163           MESSAGE("Erreur a lecture des numeros de famille des polyedres");
00164           ret = -1;
00165         }
00166         printf("Lecture des numeros de familles des mailles MED_POLYEDRE \n");
00167       }
00168       
00169       if (ret == 0) {
00170         printf("Affichage des resultats \n");
00171         for (j=0;j<npoly;j++) {
00172           printf(">> Maille MED_POLYEDRE "IFORMAT" : \n",j+1);
00173           printf("---- Connectivite nodale      ----- : \n"); 
00174           nfaces  = *(indexp+j+1) - *(indexp+j);
00175           /* ind1 = indice dans "indexf" pour acceder aux numeros des faces */
00176           ind1 = *(indexp+j) - 1;
00177           for (k=0;k<nfaces;k++) {
00178             /* ind2 = indice dans "conn" pour acceder au premier noeud de la face */
00179             ind2 = *(indexf+ind1+k) - 1;
00180             nnoeuds = *(indexf+ind1+k+1) - *(indexf+ind1+k);
00181             printf("   - Face %d : [ ", k+1);
00182             for (l=0;l<nnoeuds;l++)
00183               printf(" "IFORMAT" ",*(conn+ind2+l));
00184             printf(" ] \n"); 
00185           }
00186           printf("---- Connectivite descendante ----- : \n");
00187           nfaces  = *(indexp2+j+1) - *(indexp2+j);
00188           /* ind1 = indice dans "conn2" pour acceder aux numeros des faces */
00189           ind1 = *(indexp2+j) - 1;
00190           for (k=0;k<nfaces;k++) 
00191             printf("   - Face %d de numero : "IFORMAT" et de type "IFORMAT" \n", k+1,*(conn2+ind1+k),*(indexf2+ind1+k));
00192           strncpy(tmp,nom+j*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00193           tmp[MED_TAILLE_PNOM] = '\0';
00194           printf("---- Nom                      ----- : %s \n",tmp);
00195           printf("---- Numero                   ----- : "IFORMAT" \n",*(num+j));
00196           printf("---- Numero de famille        ----- : "IFORMAT" \n",*(fam+j));
00197         }
00198       }
00199       
00200       /* liberation de la memoire */
00201       free(indexp);
00202       free(indexp2);
00203       free(indexf);
00204       free(indexf2);
00205       free(conn);
00206       free(conn2);
00207       free(num);
00208       free(fam);
00209       free(nom);
00210     }
00211   
00212   /* Fermeture du fichier */
00213   if (MEDfermer(fid) < 0) {
00214     MESSAGE("Erreur a fermeture du fichier");
00215     return -1;
00216   }
00217   printf("Fermeture du fichier \n");
00218   
00219   return ret; 
00220 }

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