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 
26 void
_MEDequivalenceCorrespondenceWr30(int dummy,...)27 _MEDequivalenceCorrespondenceWr30(int dummy, ...) {
28 
29   med_access_mode     _MED_ACCESS_MODE;
30   med_idt            _root=0,_eqid=0,_meshid=0,_cstpid=0,_datagroup2=0;
31   med_idt            _dataset=0;
32   med_err            _ret=-1;
33   char               _path[MED_EQUIVALENCE_GRP_SIZE+2*MED_NAME_SIZE+2]=MED_EQUIVALENCE_GRP;
34   char               _computationstepname[2*MED_MAX_PARA+1]="";
35   char               _datagroupname2[2*MED_TAILLE_NOM_ENTITE+2]="";
36   char               _geotypename   [MED_TAILLE_NOM_ENTITE+1]="";
37   med_sorting_type   _sortingtype=0;
38   med_filter         _filter        = MED_FILTER_INIT;
39   med_int             _geotype  = MED_NONE;
40   med_int             _entitype =0 ;
41 
42 
43   MED_VARGS_DECL(const, med_idt            , , fid            );
44   MED_VARGS_DECL(const, char * , const       , meshname       );
45   MED_VARGS_DECL(const, char * , const       , equivname      );
46   MED_VARGS_DECL(const, med_int            , , numdt          );
47   MED_VARGS_DECL(const, med_int            , , numit          );
48   MED_VARGS_DECL(const, med_entity_type    , , entitype       );
49   MED_VARGS_DECL(const, med_geometry_type  , , geotype        );
50   MED_VARGS_DECL(const, med_int            , , nentity        );
51   MED_VARGS_DECL(const, med_int *, const          , correspondence );
52   MED_VARGS_DECL(, med_err *                ,, fret           );
53 
54   va_list params;
55   va_start(params,dummy);
56 
57   MED_VARGS_DEF(const, med_idt            , , fid            );
58   MED_VARGS_DEF(const, char * , const       , meshname       );
59   MED_VARGS_DEF(const, char * , const       , equivname      );
60   MED_VARGS_DEF(const, med_int            , , numdt          );
61   MED_VARGS_DEF(const, med_int            , , numit          );
62   MED_VARGS_DEF(const, med_entity_type    , , entitype       );
63   MED_VARGS_DEF(const, med_geometry_type  , , geotype        );
64   MED_VARGS_DEF(const, med_int            , , nentity        );
65   MED_VARGS_DEF(const, med_int *, const          , correspondence );
66   MED_VARGS_DEF(, med_err *                ,, fret           );
67 
68   if ( entitype == MED_NODE_ELEMENT ) _geotype=MED_NODE ;
69 
70   if ( (geotype / 100 ) > 2 )  {
71     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GEOMETRIC,MED_ERR_EQUIVALENCE_MSG);
72     SSCRUTE(equivname);ISCRUTE_int(geotype);
73     goto ERROR;
74   }
75 
76   if ( entitype != MED_NODE ) _geotype=geotype ;
77 
78   /*
79    * On inhibe le gestionnaire d'erreur
80    */
81   _MEDmodeErreurVerrouiller();
82  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
83 
84   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
85     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
86     goto ERROR;
87   }
88 
89   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
90     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
91     ISCRUTE_int(_MED_ACCESS_MODE);
92     goto ERROR;
93   }
94 
95   /*
96    * Ouverture du dataGroup /EQS/
97    */
98   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
99     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
100     goto ERROR;
101   }
102 
103   /*
104    * Ouverture du dataGroup <meshname>
105    */
106   if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0) {
107     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,meshname);
108     SSCRUTE(_path);goto ERROR;
109   }
110 
111   strcat(_path,meshname);
112 
113   /*
114    * Ouverure du datagroup "/EQS/<meshname>/<equivname>"
115    */
116   if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0) {
117       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,equivname);
118       SSCRUTE(_path);goto ERROR;
119   }
120 
121   strcat(_path,"/");
122   strcat(_path,equivname);
123 
124   if ( MEDmeshSortingTypeRd(fid,meshname,&_sortingtype) < 0 ) {
125     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
126     SSCRUTE(meshname);ISCRUTE_int(_sortingtype);goto ERROR;
127   }
128 
129   _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);
130 
131   if ((_cstpid = _MEDdatagroupOuvrir(_eqid,_computationstepname)) < 0)
132     if ((_cstpid = _MEDdatagroupCreer(_eqid,_computationstepname)) < 0 ) {
133       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_computationstepname);
134       SSCRUTE(_path);goto ERROR;
135     }
136 
137   /*Cree ou ouvre l'attribut MED_NOM_NDT pour �criture */
138   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NDT,&numdt) < 0) {
139     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
140     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
141     goto ERROR;
142   }
143 
144 
145   /*Cree ou ouvre l'attribut MED_NOM_NOR pour �criture */
146   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NOR,&numit) < 0) {
147     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
148     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
149     goto ERROR;
150   }
151 
152   /*Cree ou ouvre l'attribut MED_NOM_PDT pour �criture */
153   /*   if ( _MEDattrFloatEcrire(_cstpid,MED_NOM_PDT,&dt2) < 0) { */
154   /*  goto ERROR; */
155   /*   } */
156 
157   /*
158    *  Creation/Ouverture du datagroup de niveau <entitype>[.<geotype>]
159    */
160   if (_MEDgetEntityTypeName(_datagroupname2,entitype) < 0) {
161     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
162     ISCRUTE_int(entitype);SSCRUTE(equivname);goto ERROR;
163   }
164   if ( entitype != MED_NODE ) {
165     if ( _MEDgetInternalGeometryTypeName(fid,_geotypename,geotype) < 0) {
166       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
167       ISCRUTE_int(geotype);SSCRUTE(equivname);goto ERROR;
168     }
169       strcat(_datagroupname2,".");
170       strcat(_datagroupname2,_geotypename);
171   }
172 
173   if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0)
174     if ((_datagroup2 = _MEDdatagroupCreer(_cstpid,_datagroupname2)) < 0) {
175       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
176       SSCRUTE(_path);SSCRUTE(equivname);goto ERROR;
177     }
178 
179   /*Cree ou ouvre l'attribut MED_NOM_ENT pour �criture */
180   _entitype = entitype;
181   if (_MEDattributeIntWr(_datagroup2,MED_NOM_ENT,&_entitype) < 0) {
182     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_ENT);
183     ISCRUTE(_entitype);goto ERROR;
184   }
185 
186   /*Cree ou ouvre l'attribut MED_NOM_GEO pour �criture */
187   if (_MEDattributeIntWr(_datagroup2,MED_NOM_GEO,&_geotype) < 0) {
188     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
189     ISCRUTE(_geotype);goto ERROR;
190   }
191 
192 
193   if ( MEDfilterEntityCr(fid, nentity, 1, 2, MED_ALL_CONSTITUENT,
194 			 MED_NO_INTERLACE,MED_UNDEF_STMODE,
195 			 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
196     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
197     goto ERROR;
198   }
199 
200   if ( _MEDdatasetWr(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, correspondence) < 0) {
201     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
202     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
203     goto ERROR;
204   }
205 
206   if ( MEDfilterClose(&_filter) < 0 ) {
207     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_EQUIVALENCE_MSG);
208     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
209     goto ERROR;
210   }
211 
212   if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
213     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR);
214     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
215     goto ERROR;
216   }
217 
218   if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) {
219     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
220     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
221     SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR;
222   }
223 
224 
225 
226   _ret=0;
227  ERROR:
228 
229   if (_dataset>0)     if (_MEDdatasetFermer(_dataset) < 0) {
230     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATASET,MED_NOM_COR);
231     ISCRUTE_id(_dataset);
232   }
233 
234   if (_datagroup2>0)            if (_MEDdatagroupFermer(_datagroup2) < 0) {
235     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
236     ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
237   }
238 
239   if (_cstpid>0)            if (_MEDdatagroupFermer(_cstpid) < 0) {
240     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
241     ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
242   }
243 
244   if (_eqid>0)            if (_MEDdatagroupFermer(_eqid) < 0) {
245     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
246     ISCRUTE_id(_eqid);SSCRUTE(_path);
247   }
248 
249   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
250     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
251     ISCRUTE_id(_meshid);
252   }
253 
254   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
255     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_EQUIVALENCE_GRP);
256     ISCRUTE_id(_root);
257   }
258 
259   va_end(params);
260   *fret = _ret;
261 
262   return;
263 }
264