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 : test9.c
22 *
23 * - Description : lecture des familles d'un maillage 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 char maa[MED_TAILLE_NOM+1];
46 med_int mdim;
47 med_int nfam;
48 med_int i,j;
49 med_int natt,ngro;
50 char *attdes,*gro;
51 med_int *attval,*attide;
52 char nomfam[MED_TAILLE_NOM+1];
53 med_int numfam;
54 char str1[MED_TAILLE_DESC+1];
55 char str2[MED_TAILLE_LNOM+1];
56 char desc[MED_TAILLE_DESC+1];
57 med_maillage type;
58
59 /* Ouverture du fichier "test8.med" en lecture seule */
60 if ((fid = MEDouvrir("test8.med",MED_LECTURE)) < 0) {
61 MESSAGE("Erreur a l'ouverture du fichier test8.med");
62 return -1;
63 }
64
65 /* Lecture des information sur le 1er maillage */
66 if (MEDmaaInfo(fid,1,maa,&mdim,&type,desc) < 0) {
67 MESSAGE("Erreur a la lecture des informations du premier maillage");
68 return -1;
69 }
70
71 /* Lecture du nombre de familles */
72 if ((nfam = MEDnFam(fid,maa)) < 0) {
73 MESSAGE("Erreur a la lecture du nombre de famille");
74 return -1;
75 }
76 printf("Nombre de familles : %d \n",nfam);
77
78 /* Lecture de chaque famille */
79 for (i=0;i<nfam;i++) {
80
81 /* Lecture du nombre de groupe */
82 if ((ngro = MEDnGroupe(fid,maa,i+1)) < 0) {
83 MESSAGE("Erreur a la lecture du nombre de groupe de la famille d'indice : ");
84 ISCRUTE(i+1);
85 ret = -1;
86 }
87
88 /* Lecture du nombre d'attribut */
89 if ((natt = MEDnAttribut(fid,maa,i+1)) < 0) {
90 MESSAGE("Erreur a la lecture du nombre d'attribut de la famille d'indice : ");
91 ISCRUTE(i+1);
92 ret = -1;
93 }
94
95 if (ret == 0)
96 printf("Famille %d a %d attributs et %d groupes \n",i+1,natt,ngro);
97
98 /* Lecture des informations sur la famille */
99 if (ret == 0) {
100 /* Allocations memoire */
101 attide = (med_int*) malloc(sizeof(med_int)*natt);
102 attval = (med_int*) malloc(sizeof(med_int)*natt);
103 attdes = (char *) malloc(MED_TAILLE_DESC*natt+1);
104 gro = (char*) malloc(MED_TAILLE_LNOM*ngro+1);
105
106 if (MEDfamInfo(fid,maa,i+1,nomfam,&numfam,attide,attval,attdes,
107 &natt,gro,&ngro) < 0) {
108 MESSAGE("Erreur a la lecture des informations de la famille d'indice : ");
109 ISCRUTE(i+1);
110 ret = -1;
111 }
112
113 if (ret == 0) {
114 printf("Famille de nom %s et de numero %d : \n",nomfam,numfam);
115 printf("Attributs : \n");
116 for (j=0;j<natt;j++) {
117 strncpy(str1,attdes+j*MED_TAILLE_DESC,MED_TAILLE_DESC);
118 str1[MED_TAILLE_DESC] = '\0';
119 printf("ide = %d - val = %d - des = %s\n",*(attide+j),
120 *(attval+j),str1);
121 }
122 free(attide);
123 free(attval);
124 free(attdes);
125
126 for (j=0;j<ngro;j++) {
127 strncpy(str2,gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
128 str2[MED_TAILLE_LNOM] = '\0';
129 printf("gro = %s\n",str2);
130 }
131 free(gro);
132 }
133 }
134 }
135
136 /* Fermeture du fichier */
137 if (MEDfermer(fid) < 0) {
138 MESSAGE("Erreur a la fermeture du fichier");
139 return -1;
140 }
141
142 return ret;
143 }