2.3.6/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_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;
00050   med_int *con, *index, *num, *fam;
00051   char *nom;
00052   char tmp[MED_TAILLE_PNOM+1];
00053   int ind1, ind2,k;
00054   med_maillage type;
00055 
00056   /* Ouverture du fichier test23.med en lecture seule */
00057   fid = MEDouvrir("test23.med",MED_LECTURE);
00058   if (fid < 0) {
00059     MESSAGE("Erreur a l'ouverture du fichier test23.med");
00060     return -1;
00061   }
00062   printf("Ouverture du fichier test23.med \n");
00063 
00064   /* Lecture du nombre de maillages */
00065   nmaa = MEDnMaa(fid);
00066   if (nmaa < 0) {
00067     MESSAGE("Erreur a la lecture du nombre de maillage");
00068     return -1;
00069   }
00070   printf("Nombre de maillages = "IFORMAT"\n",nmaa);
00071 
00072   for (i=0;i<nmaa;i++) {
00073 
00074     /* Infos sur le maillage */
00075     if (MEDmaaInfo(fid,i+1,maa,&mdim,&type,desc) < 0) {
00076       MESSAGE("Erreur a la lecture des infos sur le maillage");
00077       return -1;
00078     }
00079     printf("maillage %d de nom [%s] et de dimension : "IFORMAT" \n",i+1,maa,mdim);
00080     
00081     /* Combien de mailles polygones en mode nodal */
00082     if ((npoly = MEDnEntMaa(fid,maa,MED_CONN,MED_MAILLE,MED_POLYGONE,MED_NOD)) < 0) {
00083       MESSAGE("Erreur a la lecture du nombre de mailles MED_POLYGONE");
00084       return -1;
00085     }
00086     printf("Nombre de mailles polygones en mode nodal : "IFORMAT" \n",npoly); 
00087 
00088     /* Quelle taille pour le tableau des connectivites */
00089     if (MEDpolygoneInfo(fid,maa,MED_MAILLE,MED_NOD,&taille) < 0) {
00090       MESSAGE("Erreur a la lecture des infos sur les maillaes MED_POLYGONE");
00091       return -1;
00092     }
00093     printf("Taille a allouer pour la connectivite des polygones : "IFORMAT" \n",taille); 
00094 
00095     /* Allocation memoire : 
00096      *  - tableau d'index : npoly + 1
00097      *  - tableau des connectivites : taille
00098      *  - tableaux numeros et numeros de familles : npoly
00099      *  - tableau des noms : MED_TAILLE_PNOM*npoly + 1 
00100          */
00101     index = (med_int *) malloc(sizeof(med_int)*(npoly+1));
00102     con = (med_int *) malloc(sizeof(med_int)*taille);
00103     num = (med_int *) malloc(sizeof(med_int)*npoly);
00104     fam = (med_int *) malloc(sizeof(med_int)*npoly);
00105     nom = (char *) malloc(sizeof(char)*MED_TAILLE_PNOM*npoly+1);
00106 
00107     /* Lecture de la connectivite des mailles polygones */
00108     if (MEDpolygoneConnLire(fid,maa,index,npoly+1,con,MED_MAILLE,MED_NOD) < 0) {
00109       MESSAGE("Erreur a la lecture de la connectivite des mailles MED_POLYGONE");
00110       ret = -1;
00111     }
00112     printf("Lecture de la connectivite des mailles MED_POLYGONE en mode nodal \n");
00113 
00114     /* Lecture noms */
00115     if (ret == 0) {
00116       if (MEDnomLire(fid,maa,nom,npoly,MED_MAILLE,MED_POLYGONE) < 0) {
00117         MESSAGE("Erreur a la lecture des noms des mailles MED_POLYGONE");
00118         ret = -1;
00119       }
00120       printf("Lecture des noms des mailles MED_POLYGONE \n");
00121     }
00122     
00123     /* Lecture des numeros */
00124     if (ret == 0) {
00125       if (MEDnumLire(fid,maa,num,npoly,MED_MAILLE,MED_POLYGONE) < 0) {
00126         MESSAGE("Erreur a la lecture des numeros des mailles MED_POLYGONE");
00127         ret = -1;
00128       }
00129       printf("Lecture des numeros des mailles MED_POLYGONE \n");
00130     }
00131 
00132     /* lecture des numeros de familles */
00133     if (ret == 0) {
00134       if ((ret = MEDfamLire(fid,maa,fam,npoly,MED_MAILLE,MED_POLYGONE)) < 0) {
00135         MESSAGE("Erreur a la lecture des numeros de famille des mailles MED_POLYGONE");
00136         ret = -1;
00137       }
00138       printf("Lecture des numeros de familles des mailles MED_POLYGONE \n");
00139     }
00140 
00141     if (ret == 0) {
00142       printf("Affichage des resultats \n");
00143       for (j=0;j<npoly;j++) {
00144         printf(">> Maille MED_POLYGONE "IFORMAT" : \n",j+1);
00145         printf("---- Connectivite       ----- : [ ");
00146         ind1 = *(index+j)-1;
00147         ind2 = *(index+j+1)-1;
00148         for (k=ind1;k<ind2;k++)
00149           printf(IFORMAT" ",*(con+k));
00150         printf(" ] \n");
00151         strncpy(tmp,nom+j*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
00152         tmp[MED_TAILLE_PNOM] = '\0';
00153         printf("---- Nom                ----- : %s \n",tmp);
00154         printf("---- Numero             ----- : "IFORMAT" \n",*(num+j));
00155         printf("---- Numero de famille  ----- : "IFORMAT" \n",*(fam+j));
00156       }
00157     }
00158 
00159     /* Liberation de la memoire */
00160     free(index);
00161     free(con);
00162     free(num);
00163     free(fam);
00164     free(nom);
00165   }
00166 
00167   /* Fermeture du fichier */
00168   if (MEDfermer(fid) < 0) {
00169     MESSAGE("Erreur a la fermeture du fichier");
00170     return -1;
00171   }
00172   printf("Fermeture du fichier \n");
00173  
00174   return ret; 
00175 }

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