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
MEDnumLire(med_idt fid,char * maa,med_int * num,med_int n,med_entite_maillage type_ent,med_geometrie_element type_geo)27 MEDnumLire(med_idt fid,char *maa, med_int *num, 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 geoid = 0;
33 med_idt entid = 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_entite_maillage _type_ent=type_ent;
39
40 if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
41
42 /*
43 * On inhibe le gestionnaire d'erreur HDF 5
44 */
45 _MEDmodeErreurVerrouiller();
46 if (MEDcheckVersion(fid) < 0) return -1;
47
48
49 /*
50 * Si le maillage n'existe pas => erreur
51 */
52 strcpy(chemin,MED_MAA);
53 strcat(chemin,maa);
54 if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0) {
55 MESSAGE("Impossible d'acceder au maillage");
56 SSCRUTE(chemin);
57 goto ERREUR;
58 }
59
60 /*
61 * On met a jour le nom du "Data Group" representant
62 * le type des entites
63 */
64 if (_MEDnomEntite(nom_ent,_type_ent) < 0) {
65 MESSAGE("L'entité demandée n'est pas une entité <med_entite_maillage> : ");
66 SSCRUTE(nom_ent);
67 ISCRUTE(_type_ent);
68 goto ERREUR;
69 }
70
71 /*
72 * Si le "Data Group" des entites n'existe pas => erreur
73 */
74 if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0) {
75 MESSAGE("Impossible d'accéder au groupe des entités : ");
76 SSCRUTE(nom_ent);
77 ISCRUTE(_type_ent);
78 goto ERREUR;
79 }
80
81 /*
82 * Pour les mailles, les faces et le aretes :
83 * - Si le "Data Group" du type geometrique n'existe pas => erreur
84 */
85 if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
86 {
87 if (_MEDnomGeometrie30(nom_geo,type_geo) < 0) {
88 MESSAGE("L'entité demandée n'est pas un élément <med_geometrie_element> : ");
89 SSCRUTE(nom_geo);
90 ISCRUTE(type_geo);
91 goto ERREUR;
92 }
93 if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0) {
94 MESSAGE("Impossible d'accéder au groupe des éléments géométriques : ");
95 SSCRUTE(nom_geo);
96 ISCRUTE(type_geo);
97 goto ERREUR;
98 }
99 }
100 else
101 geoid = -1;
102
103 /*
104 * lecture du Data Set "NUM" :
105 * - En cas d'erreur, pas de message car la presence des
106 * numeros est optionnelle dans un fichier MED
107 */
108 if (geoid == -1)
109 root = entid;
110 else
111 root = geoid;
112 #if defined(HAVE_F77INT64)
113 if (_MEDdatasetNumLire(root,MED_NOM_NUM,MED_INT64,
114 MED_NO_INTERLACE,1,MED_ALL,
115 MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
116 (unsigned char*) num) < 0)
117 goto ERREUR;
118 #else
119 if (_MEDdatasetNumLire(root,MED_NOM_NUM,MED_INT32,
120 MED_NO_INTERLACE,1,MED_ALL,
121 MED_NOPF,MED_NO_PFLMOD,MED_PFL_NON_COMPACT,0,MED_NOPG,0,
122 (unsigned char*) num) < 0)
123 goto ERREUR;
124 #endif
125
126 /*
127 * Tout s'est bien passé si on est parvenu jusqu'ici
128 */
129 ret = 0;
130
131 /*
132 * On ferme tout y compris en cas d'erreur
133 */
134 ERREUR:
135 if (geoid > 0)
136 if (_MEDdatagroupFermer(geoid) < 0)
137 return -1;
138 if (entid > 0)
139 if (_MEDdatagroupFermer(entid) < 0)
140 return -1;
141 if (maaid > 0)
142 if (_MEDdatagroupFermer(maaid) < 0)
143 return -1;
144
145 /* Code retour :
146 * - ret == 0 en cas de succès
147 * - ret == -1 en cas d'échec
148 */
149 return (ret);
150 }
151