1 /************************************************************************* 2 * COPYRIGHT (C) 1999 - 2007 EDF R&D, CEA/DEN 3 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY 4 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 5 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 6 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION. 7 * 8 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT 9 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF 10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU 11 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS. 12 * 13 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE 14 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION, 15 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA 16 * 17 *************************************************************************/ 18 19 20 /****************************************************************************** 21 * - Nom du fichier : test3.c 22 * 23 * - Description : lecture des informations sur les maillages d'un fichier MED. 24 * 25 *****************************************************************************/ 26 27 #include <med.h> 28 #define MESGERR 29 #include <med_utils.h> 30 31 #ifdef DEF_LECT_ECR 32 #define MODE_ACCES MED_LECTURE_ECRITURE 33 #elif DEF_LECT_AJOUT 34 #define MODE_ACCES MED_LECTURE_AJOUT 35 #else 36 #define MODE_ACCES MED_CREATION 37 #endif 38 39 int main (int argc, char **argv) 40 41 42 { 43 med_err ret = 0; 44 med_idt fid; 45 med_int nmaa,i,mdim,edim; 46 char maa[MED_TAILLE_NOM+1]; 47 char nomu[MED_TAILLE_LNOM+1]; 48 char desc[MED_TAILLE_DESC+1]; 49 med_maillage type; 50 med_err inomu; 51 52 /* Ouverture du fichier "test2.med" en lecture seule */ 53 fid = MEDouvrir("test2.med",MED_LECTURE); 54 if (fid < 0) { 55 MESSAGE("Erreur a l'ouverture du fichier test2.med"); 56 return -1; 57 } 58 59 /* Lecture du nombre de maillage dans le fichier */ 60 nmaa = MEDnMaa(fid); 61 if (nmaa < 0) { 62 MESSAGE("Erreur a la lecture du nombre de maillage"); 63 ret = -1; 64 } 65 if (ret == 0) 66 printf("- Nombre de maillage dans test2.med = %d\n",nmaa); 67 68 /* Boucle sur tous les maillages, pour chaque maillage, on lit : 69 - Le nom. 70 - Le type 71 - La dimension 72 - La description 73 - La dimension de l'espace si elle existe 74 - Le nom universel s'il existe 75 */ 76 if (ret == 0) 77 for (i=0;i<nmaa;i++) { 78 /* lecture des informations */ 79 if (MEDmaaInfo(fid,i+1,maa,&mdim,&type,desc) < 0) { 80 MESSAGE("Erreur a la lecture des informations du maillage :"); SSCRUTE(maa); 81 ret = -1; 82 } 83 /* lecture de la dimension de l'espace */ 84 edim = MEDdimEspaceLire(fid,maa); 85 /* lecture du nom universel */ 86 inomu = MEDunvLire(fid,maa,nomu); 87 /* affichage des donnees lues */ 88 if (inomu < 0) 89 printf("maillage %d de nom %s, de dimension %d \n",i+1,maa,mdim); 90 else 91 printf("maillage %d de nom %s, de dimension %d et de nom univ. %s\n",i+1,maa,mdim,nomu); 92 if (edim > 0) 93 printf("La dimension de l'espace est %d \n",edim); 94 else 95 printf("La dimension de l'espace est %d \n",mdim); 96 if (type == MED_STRUCTURE) 97 printf("Il s'agit d'un maillage structure \n"); 98 else 99 printf("Il s'agit d'un maillage non structure \n"); 100 printf("Description associee au maillage : %s \n\n",desc); 101 } 102 103 /* Fermeture du fichier */ 104 ret = MEDfermer(fid); 105 if (ret < 0) { 106 MESSAGE("Erreur a la fermeture du fichier test2.med"); 107 return -1; 108 } 109 110 return ret; 111 } 112 113 114 115