2.3.6/test13.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 : test13.c
00020  *
00021  * - Description : lecture des equivalences d'un maillage MED.
00022  *
00023  *****************************************************************************/
00024 
00025 #include <med.h>
00026 #define MESGERR 1
00027 #include <med_utils.h>
00028 
00029 #ifdef DEF_LECT_ECR
00030 #define MODE_ACCES MED_LECTURE_ECRITURE
00031 #elif DEF_LECT_AJOUT
00032 #define MODE_ACCES MED_LECTURE_AJOUT
00033 #else
00034 #define MODE_ACCES MED_CREATION
00035 #endif
00036 
00037 /* On prend en compte tous les types de mailles concernees
00038  *    par les equivalences */
00039 #define MED_NBR_MAILLE_EQU 8
00040  
00041 int main (int argc, char **argv)
00042 
00043 
00044 {
00045   med_err ret = 0;
00046   med_idt fid;
00047   char maa[MED_TAILLE_NOM+1];
00048   med_int mdim;
00049   med_int nequ,ncor;
00050   med_int *cor;
00051   char equ[MED_TAILLE_NOM+1];
00052   char des[MED_TAILLE_DESC+1];
00053   med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+1] = {MED_POINT1,MED_SEG2, 
00054                                                               MED_SEG3,MED_TRIA3,
00055                                                               MED_TRIA6,MED_QUAD4,
00056                                                               MED_QUAD8,MED_POLYGONE};
00057   med_geometrie_element typfac[MED_NBR_GEOMETRIE_FACE+1] = {MED_TRIA3,MED_TRIA6,
00058                                                             MED_QUAD4,MED_QUAD8,
00059                                                             MED_POLYGONE};
00060   med_geometrie_element typare[MED_NBR_GEOMETRIE_ARETE] = {MED_SEG2,MED_SEG3};  
00061   int i,j,k;
00062   med_maillage type;
00063 
00064   if (argc != 2) {
00065     MESSAGE("Il faut passer un fichier MED en paramètre");
00066     return -1;
00067   }
00068 
00069   /* Ouverture du fichier passe en argument en lecture seule */
00070   if ((fid = MEDouvrir(argv[1],MED_LECTURE)) < 0) {
00071     MESSAGE("Erreur a l'ouverture du fichier : "); SSCRUTE(argv[1]);
00072     return -1;
00073   }
00074   
00075   /* Lecture des infos sur le premier maillage */
00076   if (MEDmaaInfo(fid,1,maa,&mdim,&type,des) < 0) {
00077     MESSAGE("Erreur a lecture des infos sur le 1er maillage"); 
00078     return -1;
00079   }
00080   printf("Maillage de nom %s et de dimension "IFORMAT" \n",maa,mdim);
00081 
00082   /* Lecture du nombre d'equivalence */
00083   if ((nequ = MEDnEquiv(fid,maa)) < 0) {
00084     MESSAGE("Erreur a la lecture du nombre d'equivalence"); 
00085     return -1;
00086   }
00087   printf("Nombre d'equivalences : "IFORMAT" \n",nequ);
00088 
00089   /* Lecture de toutes les equivalences du maillage */
00090   if (nequ > 0)
00091     for (i = 0;i<nequ;i++) {
00092       printf("Equivalence numero : %d \n",i+1);
00093 
00094       /* Lecture des infos sur l'equivalence */
00095       if (MEDequivInfo(fid,maa,i+1,equ,des) < 0) {
00096         MESSAGE("Erreur a la lecture de l'equivalence d'indice");
00097         ISCRUTE_int(i+1);
00098         return -1;
00099       }
00100       printf("Nom de l'equivalence: %s \n",equ);
00101       printf("Description de l'equivalence : %s \n",des);
00102 
00103       /* Lecture des correspondances sur les differents types d'entites */
00104 
00105       /* Les noeuds */
00106       if ((ncor = MEDnCorres(fid,maa,equ,MED_NOEUD,0)) < 0) {
00107         MESSAGE("Erreur a la lecture du nombre de correspondance sur les noeuds");
00108         return -1;
00109       }
00110       printf("Il y a "IFORMAT" correspondances sur les noeuds \n",ncor);
00111       if (ncor > 0) {
00112         cor = (med_int*) malloc(sizeof(med_int)*ncor*2);
00113         if (MEDequivLire(fid,maa,equ,cor,ncor,MED_NOEUD,0) < 0) {
00114           MESSAGE("Erreur a la lecture des correspondances sur les noeuds");
00115           ret = -1;
00116         }
00117         if (ret == 0)
00118           for (j=0;j<ncor;j++)
00119             printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",j+1,*(cor+2*j),
00120                    *(cor+2*j+1));
00121         free(cor);
00122       }
00123             
00124       /* Les mailles : on ne prend pas en compte les mailles 3D */
00125       if (ret == 0)
00126         for (j=0;j<MED_NBR_MAILLE_EQU;j++) {
00127 
00128           if ((ncor = MEDnCorres(fid,maa,equ,MED_MAILLE,typmai[j])) < 0) {
00129             MESSAGE("Erreur a la lecture du nombre de correspondance sur les mailles : ");
00130             ISCRUTE_int(typmai[j]);
00131             return -1;
00132           }
00133           printf("Il y a "IFORMAT" correspondances sur les mailles %d \n",ncor,
00134                  typmai[j]);
00135           if (ncor > 0) {
00136             cor = (med_int*) malloc(sizeof(med_int)*ncor*2);
00137             if (MEDequivLire(fid,maa,equ,cor,ncor,MED_MAILLE,
00138                              typmai[j]) < 0) {
00139               MESSAGE("Erreur a la lecture des correspondances sur les mailles : ");
00140               ISCRUTE_int(typmai[j]);
00141               ret = -1;
00142             }
00143             if (ret == 0)
00144               for (k=0;k<ncor;k++)
00145                 printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",k+1,*(cor+2*k),
00146                        *(cor+2*k+1));
00147             free(cor);
00148           }
00149         }
00150 
00151       /* Les faces */
00152       if (ret == 0)
00153         for (j=0;j<MED_NBR_GEOMETRIE_FACE+1;j++) {
00154           if ((ncor = MEDnCorres(fid,maa,equ,MED_FACE,typfac[j])) < 0) {
00155             MESSAGE("Erreur a la lecture du nombre de correspondance sur les faces : ");
00156             ISCRUTE_int(typfac[j]);
00157             return -1;
00158           }
00159           printf("Il y a %d correspondances sur les faces "IFORMAT" \n",ncor,
00160                  typfac[j]);
00161           if (ncor > 0) {
00162             cor = (med_int*) malloc(sizeof(med_int)*ncor*2);
00163             if (MEDequivLire(fid,maa,equ,cor,ncor,MED_FACE,
00164                              typfac[j]) < 0) {
00165               MESSAGE("Erreur a la lecture des correspondances sur les faces : ");
00166               ISCRUTE_int(typfac[j]);
00167               ret = -1;
00168             }
00169             if (ret == 0)  
00170               for (k=0;k<ncor;k++)
00171                 printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",k+1,*(cor+2*k),
00172                        *(cor+2*k+1));
00173             free(cor);
00174           }
00175         }
00176 
00177       /*  Les aretes */
00178       if (ret == 0)
00179         for (j=0;j<MED_NBR_GEOMETRIE_ARETE;j++) {
00180           if ((ncor = MEDnCorres(fid,maa,equ,MED_ARETE,typare[j])) < 0) {
00181             MESSAGE("Erreur a la lecture du nombre de correspondance sur les aretes : ");
00182             ISCRUTE_int(typare[j]);
00183             return -1;
00184           }
00185           printf("Il y a "IFORMAT" correspondances sur les aretes %d \n",ncor,
00186                  typare[j]);
00187           if (ncor > 0) {
00188             cor = (med_int*) malloc(sizeof(med_int)*ncor*2);
00189            if (MEDequivLire(fid,maa,equ,cor,ncor,MED_ARETE,
00190                                typare[j]) < 0) {
00191              MESSAGE("Erreur a la lecture des correspondances sur les faces : ");
00192              ISCRUTE_int(typare[j]);
00193              ret = -1;
00194            }
00195            if (ret == 0)
00196              for (k=0;k<ncor;k++)
00197                printf("Correspondance %d : "IFORMAT" et "IFORMAT" \n",k+1,*(cor+2*k),
00198                       *(cor+2*k+1));
00199            free(cor);
00200           }
00201         }
00202 
00203     }                       
00204 
00205   /* Fermeture du fichier */
00206   if (MEDfermer(fid) < 0) {
00207     MESSAGE("Erreur a la fermeture du fichier ");
00208     return -1;
00209   }
00210 
00211   return ret;
00212 }
00213 
00214 
00215 
00216 

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