test24.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 : test24.c
00021  *
00022  * - Description : lecture de mailles/faces de type MED_POLYGONE
00023  *                 dans le maillage MED du fichier test23.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_ACC_RDWR
00034 #elif DEF_LECT_AJOUT
00035 #define MODE_ACCES MED_ACC_RDEXT
00036 #else
00037 #define MODE_ACCES MED_ACC_CREAT
00038 #endif
00039 
00040 int main (int argc, char **argv)
00041 
00042 #define MAXDIM 3
00043 
00044 {
00045   med_err ret = 0;
00046   med_idt fid;
00047   char maa[MED_NAME_SIZE+1];
00048   med_int nmaa,i,mdim,nindex,npoly,j,nind,nnoe;
00049   char desc[MED_COMMENT_SIZE+1];
00050   med_int *con, *index, *num, *fam;
00051   char *nom;
00052   char tmp[MED_SNAME_SIZE+1];
00053   int ind1, ind2,k;
00054   char dtunit[MED_SNAME_SIZE+1]="";
00055   char nomcoo[MAXDIM*MED_SNAME_SIZE+1];
00056   char unicoo[MAXDIM*MED_SNAME_SIZE+1];
00057   med_mesh_type type;
00058   med_sorting_type sort;
00059   med_axis_type rep;
00060   med_int nstep=0,spacedim=0;
00061   med_bool inoele=MED_FALSE,inuele=MED_FALSE,chgt=MED_FALSE,trsf=MED_FALSE;
00062 
00063   /* Ouverture du fichier test23.med en lecture seule */
00064   fid = MEDfileOpen("test23.med",MED_ACC_RDONLY);
00065   if (fid < 0) {
00066     MESSAGE("Erreur a l'ouverture du fichier test23.med");
00067     return -1;
00068   }
00069   printf("Ouverture du fichier test23.med \n");
00070 
00071   /* Lecture du nombre de maillages */
00072   nmaa = MEDnMesh(fid);
00073   if (nmaa < 0) {
00074     MESSAGE("Erreur a la lecture du nombre de maillage");
00075     return -1;
00076   }
00077   printf("Nombre de maillages = "IFORMAT"\n",nmaa);
00078 
00079   for (i=0;i<nmaa;i++) {
00080 
00081     /* Infos sur le maillage */
00082     if ( MEDmeshInfo( fid, i+1,  maa, &spacedim, &mdim, &type, desc, dtunit, &sort,
00083                       &nstep,  &rep, nomcoo,unicoo) < 0 ) {
00084       MESSAGE("Erreur a la lecture des infos sur le maillage");
00085       return -1;
00086     } else {
00087       printf("maillage "IFORMAT" de nom [%s] et de dimension : "IFORMAT" , et de type %d\n",i+1,maa,mdim,type);
00088       printf("\t -Dimension de l'espace : "IFORMAT"\n",spacedim);
00089       printf("\t -Description du maillage : |%s|\n",desc);
00090       printf("\t -Noms des axes : |%s|\n",nomcoo);
00091       printf("\t -Unités des axes : |%s|\n",unicoo);
00092       printf("\t -Type de repère : %d\n",rep);
00093       printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",nstep);
00094       printf("\t -Unité des dates : |%s|\n",dtunit);
00095     }
00096 
00097     /* Combien de mailles polygones en mode nodal */
00098     if ((nind = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00099                                MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,
00100                                &chgt,&trsf)) < 0) {
00101       MESSAGE("Erreur a la lecture du nombre de mailles MED_POLYGONE");
00102       return -1;
00103     }
00104     npoly = nind-1;
00105     printf("Nombre de mailles polygones en mode nodal : "IFORMAT" \n",npoly);
00106 
00107     /* Quelle taille pour le tableau des connectivites, nombre de noeuds
00108        tous polygones confondus*/
00109     if ((nnoe = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT,
00110                                MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,
00111                                &chgt,&trsf)) < 0) {
00112       MESSAGE("Erreur a la lecture du nombre de mailles MED_POLYGONE");
00113       return -1;
00114     }
00115 
00116     printf("Taille a allouer pour la connectivite des polygones : "IFORMAT" \n",nnoe);
00117 
00118     /* Allocation memoire :
00119      *  - tableau d'index : npoly + 1
00120      *  - tableau des connectivites : nnoe
00121      *  - tableaux numeros et numeros de familles : npoly
00122      *  - tableau des noms : MED_SNAME_SIZE*npoly + 1
00123          */
00124     index = (med_int *) malloc(sizeof(med_int)*nind);
00125     con = (med_int *)   malloc(sizeof(med_int)*nnoe);
00126     num = (med_int *)   malloc(sizeof(med_int)*npoly);
00127     fam = (med_int *)   malloc(sizeof(med_int)*npoly);
00128     nom = (char *)      malloc(sizeof(char)*MED_SNAME_SIZE*npoly+1);
00129 
00130     /* Lecture de la connectivite des mailles polygones */
00131     if (MEDmeshPolygonRd(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_NODAL,
00132                          index,con) < 0) {
00133       MESSAGE("Erreur a la lecture de la connectivite des mailles MED_POLYGONE");
00134       return -1;
00135     }
00136     printf("Lecture de la connectivite des mailles MED_POLYGONE en mode nodal \n");
00137 
00138     /* Lecture (optionnelle) des noms des polygones */
00139     if (MEDmeshEntityNameRd(fid, maa, MED_NO_DT, MED_NO_IT,
00140                               MED_CELL, MED_POLYGON,nom) < 0)
00141       inoele = MED_FALSE;
00142     else
00143       inoele = MED_TRUE;
00144 
00145     /* Lecture (optionnelle) des numeros des polygones  */
00146     if ( MEDmeshEntityNumberRd(fid, maa, MED_NO_DT, MED_NO_IT,
00147                                MED_CELL, MED_POLYGON, num) < 0)
00148       inuele = MED_FALSE;
00149     else
00150       inuele = MED_TRUE;
00151 
00152     /* Lecture des numeros des familles des segments */
00153     if (MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT,
00154                                     MED_CELL, MED_POLYGON,fam) < 0) {
00155       MESSAGE("Erreur a la lecture des numéros de famille des segments");
00156       /*TODO : Considérer famille 0 */
00157       return -1;
00158     }
00159 
00160 
00161     if (ret == 0) {
00162       printf("Affichage des resultats \n");
00163       for (j=0;j<npoly;j++) {
00164         printf(">> Maille MED_POLYGONE "IFORMAT" : \n",j+1);
00165         printf("---- Connectivite       ----- : [ ");
00166         ind1 = *(index+j)-1;
00167         ind2 = *(index+j+1)-1;
00168         for (k=ind1;k<ind2;k++)
00169           printf(IFORMAT" ",*(con+k));
00170         printf(" ] \n");
00171         strncpy(tmp,nom+j*MED_SNAME_SIZE,MED_SNAME_SIZE);
00172         tmp[MED_SNAME_SIZE] = '\0';
00173         if (inoele) printf("---- Nom                ----- : |%s| \n",tmp);
00174         if (inuele) printf("---- Numero             ----- : "IFORMAT" \n",*(num+j));
00175         printf("---- Numero de famille  ----- : "IFORMAT" \n",*(fam+j));
00176       }
00177     }
00178 
00179     /* Liberation de la memoire */
00180     free(index);
00181     free(con);
00182     free(num);
00183     free(fam);
00184     free(nom);
00185   }
00186 
00187   /* Fermeture du fichier */
00188   if (MEDfileClose(fid) < 0) {
00189     MESSAGE("Erreur a la fermeture du fichier");
00190     return -1;
00191   }
00192   printf("Fermeture du fichier \n");
00193 
00194   return ret;
00195 }

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