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 <string.h>
24 #include <stdlib.h>
25 void
_MEDequivalenceCorrespondenceRd30(int dummy,...)26 _MEDequivalenceCorrespondenceRd30(int dummy, ...) {
27
28 med_idt _root=0,_eqid=0,_meshid=0,_cstpid=0,_datagroup2=0;
29 med_idt _dataset=0;
30 med_err _ret=-1;
31 char _path[MED_EQUIVALENCE_GRP_SIZE+2*MED_NAME_SIZE+2]=MED_EQUIVALENCE_GRP;
32 char _computationstepname[2*MED_MAX_PARA+1]="";
33 char _datagroupname2[2*MED_TAILLE_NOM_ENTITE+2]="";
34 char _geotypename [MED_TAILLE_NOM_ENTITE+1]="";
35 med_sorting_type _sortingtype=0;
36 med_filter _filter = MED_FILTER_INIT;
37 med_geometry_type _geotype=MED_NONE;
38 med_int _nentity=0;
39
40 MED_VARGS_DECL(const, med_idt , , fid );
41 MED_VARGS_DECL(const, char * , const , meshname );
42 MED_VARGS_DECL(const, char * , const , equivname );
43 MED_VARGS_DECL(const, med_int , , numdt );
44 MED_VARGS_DECL(const, med_int , , numit );
45 MED_VARGS_DECL(const, med_entity_type , , entitype );
46 MED_VARGS_DECL(const, med_geometry_type , , geotype );
47 MED_VARGS_DECL(, med_int *, const , correspondence );
48 MED_VARGS_DECL(, med_err * ,, fret );
49
50 va_list params;
51 va_start(params,dummy);
52
53 MED_VARGS_DEF(const, med_idt , , fid );
54 MED_VARGS_DEF(const, char * , const , meshname );
55 MED_VARGS_DEF(const, char * , const , equivname );
56 MED_VARGS_DEF(const, med_int , , numdt );
57 MED_VARGS_DEF(const, med_int , , numit );
58 MED_VARGS_DEF(const, med_entity_type , , entitype );
59 MED_VARGS_DEF(const, med_geometry_type , , geotype );
60 MED_VARGS_DEF(, med_int *, const , correspondence );
61 MED_VARGS_DEF(, med_err * ,, fret );
62 if ( entitype == MED_NODE_ELEMENT ) _geotype=MED_NODE ;
63
64 if ( (geotype / 100 ) > 2 ) {
65 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GEOMETRIC,MED_ERR_EQUIVALENCE_MSG);
66 SSCRUTE(equivname);ISCRUTE_int(geotype);
67 goto ERROR;
68 }
69
70 if ( entitype != MED_NODE ) _geotype=geotype ;
71
72
73 /*
74 * On inhibe le gestionnaire d'erreur
75 */
76 _MEDmodeErreurVerrouiller();
77
78
79 /*
80 * Ouverture du dataGroup /EQS/
81 */
82 if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
83 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
84 goto ERROR;
85 }
86
87 /*
88 * Ouverture du dataGroup <meshname>
89 */
90 if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0) {
91 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,meshname);
92 SSCRUTE(_path);goto ERROR;
93 }
94
95 strcat(_path,meshname);
96
97 /*
98 * Si le Data Group "/EQS/<meshname>/<equivname>" n'existe pas, on le cree
99 */
100 if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0) {
101 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,equivname);
102 SSCRUTE(_path);goto ERROR;
103 }
104
105 strcat(_path,"/");
106 strcat(_path,equivname);
107
108 if ( MEDmeshSortingTypeRd(fid,meshname,&_sortingtype) < 0 ) {
109 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
110 SSCRUTE(meshname);ISCRUTE_int(_sortingtype);goto ERROR;
111 }
112
113 _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);
114
115 if ((_cstpid = _MEDdatagroupOuvrir(_eqid,_computationstepname)) < 0) {
116 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_computationstepname);
117 SSCRUTE(_path);goto ERROR;
118 }
119
120
121 /*
122 * Ouverture du datagroup de niveau <entitype>[.<geotype>]
123 */
124 if (_MEDgetEntityTypeName(_datagroupname2,entitype) < 0) {
125 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
126 ISCRUTE_int(entitype);SSCRUTE(equivname);goto ERROR;
127 }
128 if ( entitype != MED_NODE ) {
129 if ( _MEDgetInternalGeometryTypeName(fid,_geotypename,geotype) < 0) {
130 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
131 ISCRUTE_int(geotype);SSCRUTE(equivname);goto ERROR;
132 }
133 strcat(_datagroupname2,".");
134 strcat(_datagroupname2,_geotypename);
135 }
136
137 if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0) {
138 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_datagroupname2);
139 SSCRUTE(_path);SSCRUTE(equivname);goto ERROR;
140 }
141
142
143 if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
144 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR);
145 SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
146 goto ERROR;
147 }
148
149 if ( _MEDattrEntierLire(_dataset,MED_NOM_NBR,&_nentity) < 0) {
150 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
151 SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
152 SSCRUTE(MED_NOM_NBR);ISCRUTE(_nentity);goto ERROR;
153 }
154
155 if ( MEDfilterEntityCr(fid, _nentity, 1, 2, MED_ALL_CONSTITUENT,
156 MED_NO_INTERLACE,MED_UNDEF_STMODE,
157 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
158 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
159 goto ERROR;
160 }
161
162 if ( _MEDdatasetRd(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, (unsigned char *) correspondence) < 0) {
163 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
164 SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
165 goto ERROR;
166 }
167
168 if ( MEDfilterClose(&_filter) < 0 ) {
169 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_EQUIVALENCE_MSG);
170 SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
171 goto ERROR;
172 }
173
174 _ret=0;
175 ERROR:
176
177 if (_dataset>0) if (_MEDdatasetFermer(_dataset) < 0) {
178 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATASET,MED_NOM_COR);
179 ISCRUTE_id(_dataset);
180 }
181
182 if (_datagroup2>0) if (_MEDdatagroupFermer(_datagroup2) < 0) {
183 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
184 ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
185 }
186
187 if (_cstpid>0) if (_MEDdatagroupFermer(_cstpid) < 0) {
188 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
189 ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
190 }
191
192 if (_eqid>0) if (_MEDdatagroupFermer(_eqid) < 0) {
193 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
194 ISCRUTE_id(_eqid);SSCRUTE(_path);
195 }
196
197 if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
198 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
199 ISCRUTE_id(_eqid);
200 }
201
202 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
203 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_EQUIVALENCE_GRP);
204 ISCRUTE_id(_eqid);
205 }
206
207 va_end(params);
208 *fret = _ret;
209
210 return;
211 }
212