1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2019 EDF R&D, CEA/DEN
4 * MED is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * MED is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with MED. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 #include <med.h>
20 #include <med_config.h>
21 #include <med_outils.h>
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 med_err
MEDfamLire(med_idt fid,char * maa,med_int * fam,med_int n,med_entite_maillage type_ent,med_geometrie_element type_geo)27 MEDfamLire(med_idt fid,char *maa, med_int *fam, med_int n,
28 med_entite_maillage type_ent,med_geometrie_element type_geo)
29 {
30 med_idt root;
31 med_idt maaid = 0;
32 med_idt entid = 0;
33 med_idt geoid = 0;
34 med_err ret = -1;
35 char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
36 char nom_ent[MED_TAILLE_NOM_ENTITE+1];
37 char nom_geo[MED_TAILLE_NOM_ENTITE+1];
38 med_int i;
39 med_entite_maillage _type_ent=type_ent;
40
41 if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
42
43 /*
44 * On inhibe le gestionnaire d'erreur HDF 5
45 */
46 _MEDmodeErreurVerrouiller();
47 if (MEDcheckVersion(fid) < 0) return -1;
48
49
50 /*
51 * Si le maillage n'existe pas => erreur
52 */
53 strcpy(chemin,MED_MAA);
54 strcat(chemin,maa);
55 if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0) {
56 MESSAGE("Impossible d'acceder au maillage");
57 SSCRUTE(chemin);
58 goto ERREUR;
59 }
60
61 /*
62 * On met a jour le nom du Data Group representant
63 * le type des entites
64 */
65 if (_MEDnomEntite(nom_ent,_type_ent) < 0) {
66 MESSAGE("L'entité demandée n'est pas une entité <med_entite_maillage> : ");
67 SSCRUTE(nom_ent);
68 ISCRUTE(_type_ent);
69 goto ERREUR;
70 }
71
72 /*
73 * Si le "Data Group" des entites n'existe pas => erreur
74 */
75 if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0) {
76 MESSAGE("Impossible d'accéder au groupe des entités : ");
77 SSCRUTE(nom_ent);
78 ISCRUTE(_type_ent);
79 goto ERREUR;
80 }
81
82
83 /*
84 * Pour les mailles, les faces et le aretes, on cree
85 * si le "Data Group" du type geometrique => erreur
86 */
87 if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
88 {
89 if (_MEDnomGeometrie30(nom_geo,type_geo) < 0) {
90 MESSAGE("L'entité demandée n'est pas un élément <med_geometrie_element> : ");
91 SSCRUTE(nom_geo);
92 ISCRUTE(type_geo);
93 goto ERREUR;
94 }
95 if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0) {
96 MESSAGE("Impossible d'accéder au groupe des éléments géométriques : ");
97 SSCRUTE(nom_geo);
98 ISCRUTE(type_geo);
99 goto ERREUR;
100 }
101
102 }
103 else
104 geoid = -1;
105
106 /*
107 * lecture du Data Set "FAM"
108 * - En cas d'erreur, pas de message car la presence des
109 * numeros est optionnelle dans un fichier MED (à partir de la V2.2)
110 * Dans ce cas de figure, on considère que tous les numéros sont à 0
111 */
112 if (geoid == -1)
113 root = entid;
114 else
115 root = geoid;
116 #if defined(HAVE_F77INT64)
117 if (_MEDdatasetNumLire(root,MED_NOM_FAM,MED_INT64,
118 MED_NO_INTERLACE,1,MED_ALL,
119 MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
120 (unsigned char *)fam) < 0)
121 for (i=0; i<n; i++)
122 *(fam+i) = 0;
123 #else
124 if (_MEDdatasetNumLire(root,MED_NOM_FAM,MED_INT32,
125 MED_NO_INTERLACE,1,MED_ALL,
126 MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
127 (unsigned char *)fam) < 0)
128 for (i=0; i<n; i++)
129 *(fam+i) = 0;
130 #endif
131
132 /*
133 * Tout s'est bien passé si on est parvenu jusqu'ici
134 */
135 ret = 0;
136
137 /*
138 * On ferme tout
139 */
140 ERREUR:
141 if (geoid > 0)
142 if (_MEDdatagroupFermer(geoid) < 0)
143 return -1;
144 if (entid > 0)
145 if (_MEDdatagroupFermer(entid) < 0)
146 return -1;
147 if (maaid > 0)
148 if (_MEDdatagroupFermer(maaid) < 0)
149 return -1;
150
151 /* Code retour :
152 * - ret == 0 en cas de succès
153 * - ret == -1 en cas d'échec
154 */
155 return (ret);
156 }
157