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