00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
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   
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   
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       
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       
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       
00092 
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       
00101 
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       
00110 
00111 
00112 
00113 
00114 
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       
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        
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       
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       
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       
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           
00176           ind1 = *(indexp+j) - 1;
00177           for (k=0;k<nfaces;k++) {
00178             
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           
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       
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   
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 }