MED fichier
MEDequivalenceCorrespondenceWr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2016 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 
41 med_err
43  const char * const meshname,
44  const char * const equivname,
45  const med_int numdt,
46  const med_int numit,
47  const med_entity_type entitype,
48  const med_geometry_type geotype,
49  const med_int const nentity,
50  const med_int * const correspondence) {
51 
52  med_access_mode _MED_ACCESS_MODE;
53  med_idt _root=0,_eqid=0,_meshid=0,_cstpid=0,_datagroup2=0;
54  med_idt _dataset=0;
55  med_err _ret=-1;
57  char _computationstepname[2*MED_MAX_PARA+1]="";
58  char _datagroupname2[2*MED_TAILLE_NOM_ENTITE+2]="";
59  char _geotypename [MED_TAILLE_NOM_ENTITE+1]="";
60  med_sorting_type _sortingtype=0;
61  med_filter _filter = MED_FILTER_INIT;
62  med_int _geotype = MED_NONE;
63  med_int _entitype = entitype;
64 
65  if ( entitype == MED_NODE_ELEMENT ) _geotype=MED_NODE ;
66 
67  if ( (geotype / 100 ) > 2 ) {
69  SSCRUTE(equivname);ISCRUTE_int(geotype);
70  goto ERROR;
71  }
72 
73  if ( entitype != MED_NODE ) _geotype=geotype ;
74 
75  /*
76  * On inhibe le gestionnaire d'erreur
77  */
79  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
80 
81  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
83  goto ERROR;
84  }
85 
86  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
88  ISCRUTE_int(_MED_ACCESS_MODE);
89  goto ERROR;
90  }
91 
92  /*
93  * Ouverture du dataGroup /EQS/
94  */
95  if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
97  goto ERROR;
98  }
99 
100  /*
101  * Ouverture du dataGroup <meshname>
102  */
103  if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0) {
104  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,meshname);
105  SSCRUTE(_path);goto ERROR;
106  }
107 
108  strcat(_path,meshname);
109 
110  /*
111  * Ouverure du datagroup "/EQS/<meshname>/<equivname>"
112  */
113  if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0) {
114  MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,equivname);
115  SSCRUTE(_path);goto ERROR;
116  }
117 
118  strcat(_path,"/");
119  strcat(_path,equivname);
120 
121  if ( MEDmeshSortingTypeRd(fid,meshname,&_sortingtype) < 0 ) {
122  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
123  SSCRUTE(meshname);ISCRUTE_int(_sortingtype);goto ERROR;
124  }
125 
126  _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);
127 
128  if ((_cstpid = _MEDdatagroupOuvrir(_eqid,_computationstepname)) < 0)
129  if ((_cstpid = _MEDdatagroupCreer(_eqid,_computationstepname)) < 0 ) {
130  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_computationstepname);
131  SSCRUTE(_path);goto ERROR;
132  }
133 
134  /*Cree ou ouvre l'attribut MED_NOM_NDT pour �criture */
135  if ( _MEDattributeIntWr(_cstpid,MED_NOM_NDT,&numdt) < 0) {
137  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
138  goto ERROR;
139  }
140 
141 
142  /*Cree ou ouvre l'attribut MED_NOM_NOR pour �criture */
143  if ( _MEDattributeIntWr(_cstpid,MED_NOM_NOR,&numit) < 0) {
145  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
146  goto ERROR;
147  }
148 
149  /*Cree ou ouvre l'attribut MED_NOM_PDT pour �criture */
150  /* if ( _MEDattrFloatEcrire(_cstpid,MED_NOM_PDT,&dt2) < 0) { */
151  /* goto ERROR; */
152  /* } */
153 
154  /*
155  * Creation/Ouverture du datagroup de niveau <entitype>[.<geotype>]
156  */
157  if (_MEDgetEntityTypeName(_datagroupname2,entitype) < 0) {
159  ISCRUTE_int(entitype);SSCRUTE(equivname);goto ERROR;
160  }
161  if ( entitype != MED_NODE ) {
162  if ( _MEDgetInternalGeometryTypeName(_geotypename,geotype) < 0) {
164  ISCRUTE_int(geotype);SSCRUTE(equivname);goto ERROR;
165  }
166  strcat(_datagroupname2,".");
167  strcat(_datagroupname2,_geotypename);
168  }
169 
170  if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0)
171  if ((_datagroup2 = _MEDdatagroupCreer(_cstpid,_datagroupname2)) < 0) {
172  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
173  SSCRUTE(_path);SSCRUTE(equivname);goto ERROR;
174  }
175 
176  /*Cree ou ouvre l'attribut MED_NOM_ENT pour �criture */
177  if (_MEDattributeIntWr(_datagroup2,MED_NOM_ENT,&_entitype) < 0) {
179  ISCRUTE(_entitype);goto ERROR;
180  }
181 
182  /*Cree ou ouvre l'attribut MED_NOM_GEO pour �criture */
183  if (_MEDattributeIntWr(_datagroup2,MED_NOM_GEO,&_geotype) < 0) {
185  ISCRUTE(_geotype);goto ERROR;
186  }
187 
188 
189  if ( MEDfilterEntityCr(fid, nentity, 1, 2, MED_ALL_CONSTITUENT,
191  MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
193  goto ERROR;
194  }
195 
196  if ( _MEDdatasetWr(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, correspondence) < 0) {
198  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
199  goto ERROR;
200  }
201 
202  if ( MEDfilterClose(&_filter) < 0 ) {
204  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
205  goto ERROR;
206  }
207 
208  if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
210  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
211  goto ERROR;
212  }
213 
214  if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) {
216  SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
217  SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR;
218  }
219 
220 
221 
222  _ret=0;
223  ERROR:
224 
225  if (_dataset>0) if (_MEDdatasetFermer(_dataset) < 0) {
227  ISCRUTE_id(_dataset);
228  }
229 
230  if (_datagroup2>0) if (_MEDdatagroupFermer(_datagroup2) < 0) {
231  MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
232  ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
233  }
234 
235  if (_cstpid>0) if (_MEDdatagroupFermer(_cstpid) < 0) {
236  MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
237  ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
238  }
239 
240  if (_eqid>0) if (_MEDdatagroupFermer(_eqid) < 0) {
241  MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
242  ISCRUTE_id(_eqid);SSCRUTE(_path);
243  }
244 
245  if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
247  ISCRUTE_id(_meshid);
248  }
249 
250  if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
252  ISCRUTE_id(_root);
253  }
254 
255  return _ret;
256 }
Definition: med.h:136
herr_t med_err
Definition: med.h:310
#define MED_NOM_COR
Definition: med_outils.h:57
Filtre de sélection.
Definition: med.h:326
#define MED_ERR_VALUE_MSG
Definition: med_err.h:179
#define MED_NOM_GEO
Definition: med_outils.h:118
#define MED_NOM_ENT
Definition: med_outils.h:120
#define MED_ERR_INVALID
Definition: med_err.h:37
#define MED_ERR_FILE_MSG
Definition: med_err.h:129
med_access_mode
Definition: med.h:113
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
Definition: MEDmodeAccesC.c:43
#define ISCRUTE_int(entier)
Definition: med_utils.h:307
#define MED_FILTER_INIT
Definition: med.h:345
#define MED_ALL_CONSTITUENT
Definition: med.h:279
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
MEDC_EXPORT med_err MEDmeshSortingTypeRd(const med_idt fid, const char *const meshname, med_sorting_type *const sortingtype)
Cette routine lit l'ordre de tri des séquences évolutives du maillage.
#define MED_EQUIVALENCE_GRP
Definition: med_outils.h:218
med_sorting_type
Definition: med.h:289
#define MED_ERR_ACCESSMODE
Definition: med_err.h:103
MEDC_EXPORT med_err _MEDgetEntityTypeName(char *const entitytypename, const med_entity_type entitytype)
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:36
#define MED_ERR_GEOMETRIC
Definition: med_err.h:104
#define MED_MAX_PARA
Definition: med.h:69
med_entity_type
Definition: med.h:136
#define MED_ERR_WRITE
Definition: med_err.h:26
#define MED_NONE
Definition: med.h:211
#define _MEDattributeIntWr(w, x, y)
Definition: med_hdfi.h:45
MEDC_EXPORT med_err _MEDgetInternalGeometryTypeName(char *const geotypename, med_geometry_type geotype)
#define MED_ERR_CALL
Definition: med_err.h:45
int med_int
Definition: med.h:316
#define MED_ERR_CLOSE
Definition: med_err.h:27
#define MED_EQUIVALENCE_GRP_SIZE
Definition: med_outils.h:219
#define MED_ERR_CREATE
Definition: med_err.h:24
MEDC_EXPORT med_err _MEDdatasetWr(const med_idt id, const char *const datasetname, const med_internal_type datatype, const med_filter *const filter, const void *const value)
#define MED_TAILLE_NOM_ENTITE
Definition: med_outils.h:37
MEDC_EXPORT med_idt _MEDdatasetOuvrir(med_idt pid, char *nom)
#define MED_ERR_EQUIVALENCE_MSG
Definition: med_err.h:166
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
#define MED_NO_PROFILE
Definition: med.h:261
med_err MEDequivalenceCorrespondenceWr(const med_idt fid, const char *const meshname, const char *const equivname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_int const nentity, const med_int *const correspondence)
Cette routine permet d'écrire un tableau de correspondances entre les entités d'un maillage dans une ...
MEDC_EXPORT med_err MEDfilterEntityCr(const med_idt fid, const med_int nentity, const med_int nvaluesperentity, const med_int nconstituentpervalue, const med_int constituentselect, const med_switch_mode switchmode, const med_storage_mode storagemode, const char *const profilename, const med_int filterarraysize, const med_int *const filterarray, med_filter *const filter)
#define ISCRUTE(entier)
Definition: med_utils.h:306
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
#define MED_ERR_DATAGROUP
Definition: med_err.h:98
#define MED_ERR_RANGE
Definition: med_err.h:31
#define ISCRUTE_id(entier)
Definition: med_utils.h:311
#define MED_ERR_INTERNAL_MSG
Definition: med_err.h:191
#define MED_ERR_ENTITY
Definition: med_err.h:84
#define MED_NOM_NDT
Definition: med_outils.h:127
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
MEDC_EXPORT med_err _MEDdatasetFermer(med_idt id)
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
hid_t med_idt
Definition: med.h:309
#define MED_ERR_OPEN
Definition: med_err.h:34
#define MED_NAME_SIZE
Definition: med.h:74
#define MED_UNDEF_SIZE
Definition: med.h:286
#define MED_NOM_NBR
Definition: med_outils.h:39
#define MED_ERR_DATASET
Definition: med_err.h:97
#define MED_ERR_FILTER
Definition: med_err.h:92
#define MED_NOM_NOR
Definition: med_outils.h:130
int med_geometry_type
Definition: med.h:179
#define SSCRUTE(chaine)
Definition: med_utils.h:315
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:99
#define MED_ERR_API
Definition: med_err.h:108
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:158
MEDC_EXPORT med_err _MEDgetComputationStepName(const med_sorting_type sortingtype, const med_int numdt, const med_int numit, char *const datagroupname)