MED fichier

MEDlocalizationWr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2021 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
48 med_err
49 MEDlocalizationWr(const med_idt fid,
50 const char * const localizationname,
51 const med_geometry_type geotype,
52 const med_int spacedimension,
53 const med_float* const elementcoordinate,
54 const med_switch_mode switchmode,
55 const med_int nipoint,
56 const med_float* const ipointcoordinate,
57 const med_float* const weight,
58 const char * const geointerpname,
59 const char * const sectionmeshname
60 )
61 {
62 med_access_mode _MED_ACCESS_MODE;
63 med_err _ret = -1;
64 med_idt _lzid=0, _root=0;
65 med_int _nentity=0;
66 med_int _intgeotype = -1;
67 char _path[MED_LOCALIZATION_GRP_SIZE+MED_NAME_SIZE+1]=MED_LOCALIZATION_GRP;
68 med_filter _filter = MED_FILTER_INIT;
69
70 /*
71 * On inhibe le gestionnaire d'erreur HDF 5
72 */
73 _MEDmodeErreurVerrouiller();
74 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
75
76 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
77 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
78 goto ERROR;
79 }
80
81 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
82 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
83 ISCRUTE_int(_MED_ACCESS_MODE);
84 goto ERROR;
85 }
86
87 /*
88 * MED_GAUSS_ELNO est un mot cle reserve
89 */
90 if (! strcmp(localizationname,MED_GAUSS_ELNO)) {
91 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_LOCALIZATION,localizationname);
92 goto ERROR;
93 }
94
95 /*
96 * Si le DataGroup /GAUSS/ n'existe pas, on le cree
97 */
98 if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
99 if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
100 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
101 goto ERROR;
102 }
103
104 NOFINALBLANK(localizationname,ERROR);
105 /*
106 * Si le DataGroup /GAUSS/<localizationname> n'existe pas, on le cree
107 */
108 if ((_lzid = _MEDdatagroupOuvrir(_root,localizationname)) < 0)
109 if ((_lzid = _MEDdatagroupCreer(_root,localizationname)) < 0) {
110 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,localizationname);
111 SSCRUTE(_path);goto ERROR;
112 }
113
114 strcat(_path,localizationname);
115
116
117 /*
118 * On stocke <nipoint> sous forme d'attribut
119 */
120 if (_MEDattributeIntWr(_lzid,MED_NOM_NBR,&nipoint) < 0) {
121 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
122 SSCRUTE(localizationname);SSCRUTE(MED_NOM_NBR);ISCRUTE(nipoint);
123 goto ERROR;
124 }
125
126
127 /*
128 * On stocke <typgeo> sous forme d'attribut
129 */
130 _intgeotype = (med_int) geotype;
131 /* sizeof(enum) tjrs = sizeof(int) en C, or
132 sur machines 64 bits par d�faut med_int==long,
133 du coup sur machines 64 bits _MEDattributeIntWr utilise
134 le type hdf NATIVE_LONG, ce qui pose un probl�me qd on passe
135 un enum.
136 */
137 if (_MEDattributeIntWr(_lzid,MED_NOM_GEO,&_intgeotype) < 0) {
138 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
139 SSCRUTE(localizationname);SSCRUTE(MED_NOM_GEO);ISCRUTE(_intgeotype);
140 goto ERROR;
141 };
142
143 /*
144 * On stocke <spacedimension> sous forme d'attribut
145 */
146 if (_MEDattributeIntWr(_lzid,MED_NOM_DIM,&spacedimension) < 0) {
147 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
148 SSCRUTE(localizationname);SSCRUTE(MED_NOM_DIM);ISCRUTE(spacedimension);
149 goto ERROR;
150 };
151
152
153 if ( ! ((geotype > MED_STRUCT_GEO_INTERNAL ) &&
154 (geotype < MED_STRUCT_GEO_SUP_INTERNAL) ) ) {
155 /*
156 * On stocke les coordonn�es de r�f�rence dans un dataset
157 */
158 _nentity = (geotype%100);
159
160 if ( MEDfilterEntityCr(fid,_nentity, 1, spacedimension, MED_ALL_CONSTITUENT,
161 switchmode,MED_UNDEF_STMODE,
162 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
163 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
164 goto ERROR;
165 }
166
167 if ( _MEDdatasetWr(_lzid,MED_NOM_COO,MED_INTERNAL_FLOAT64,&_filter, elementcoordinate) < 0) {
168 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COO);SSCRUTE(_path);
169 goto ERROR;
170 }
171
172 if ( MEDfilterClose(&_filter) < 0 ) {
173 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
174 goto ERROR;
175 }
176 } else {
177
178 /*
179 * Creation/Ecriture de l'attribut MED_NOM_NOM (nom du maillage de section)
180 */
181 if ( _MEDattributeStringWr(_lzid,MED_NOM_NOM,MED_NAME_SIZE,sectionmeshname) < 0) {
182 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
183 SSCRUTE(localizationname);SSCRUTE(MED_NOM_NOM);SSCRUTE(sectionmeshname);
184 goto ERROR;
185 }
186 }
187
188 /*
189 * Creation/Ecriture de l'attribut MED_NOM_INM (nom de l'interpolation géométrique)
190 */
191 if ( _MEDattributeStringWr(_lzid,MED_NOM_INM,MED_NAME_SIZE,geointerpname) < 0) {
192 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LOCALIZATION_MSG);
193 SSCRUTE(localizationname);SSCRUTE(MED_NOM_INM);SSCRUTE(geointerpname);
194 goto ERROR;
195 }
196
197
198 /*
199 * On stocke les points d'int�gration dans un dataset
200 */
201
202 _nentity = nipoint;
203 if ( MEDfilterEntityCr(fid,_nentity, 1, spacedimension, MED_ALL_CONSTITUENT,
204 switchmode,MED_UNDEF_STMODE,
205 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
206 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
207 goto ERROR;
208 }
209
210 if ( _MEDdatasetWr(_lzid,MED_NOM_GAU,MED_INTERNAL_FLOAT64,&_filter, ipointcoordinate) < 0) {
211 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_GAU);SSCRUTE(_path);
212 goto ERROR;
213 }
214
215 if ( MEDfilterClose(&_filter) < 0 ) {
216 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
217 goto ERROR;
218 }
219
220 /*
221 * On stocke les poids dans un dataset
222 */
223
224 _nentity = nipoint;
225 if ( MEDfilterEntityCr(fid,_nentity, 1, 1, MED_ALL_CONSTITUENT,
226 switchmode,MED_UNDEF_STMODE,
227 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
228 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
229 goto ERROR;
230 }
231
232 if ( _MEDdatasetWr(_lzid,MED_NOM_VAL,MED_INTERNAL_FLOAT64,&_filter, weight) < 0) {
233 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_VAL);SSCRUTE(_path);
234 goto ERROR;
235 }
236
237 if ( MEDfilterClose(&_filter) < 0 ) {
238 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LOCALIZATION_MSG); SSCRUTE(_path);
239 goto ERROR;
240 }
241
242
243 _ret = 0;
244
245 ERROR:
246
247 if (_lzid>0) if (_MEDdatagroupFermer(_lzid) < 0) {
248 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,localizationname);
249 ISCRUTE_id(_lzid);
250 }
251
252 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
253 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_LOCALIZATION_GRP);
254 ISCRUTE_id(_root);
255 }
256
257 return _ret;
258
259 }
260
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
MEDfilterEntityCr
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)
Definition: MEDfilterEntityCr.c:55
MED_STRUCT_GEO_INTERNAL
#define MED_STRUCT_GEO_INTERNAL
Definition: med.h:228
_MEDdatagroupFermer
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
med_filter
Filtre de sélection.
Definition: med.h:355
MED_NOM_DIM
#define MED_NOM_DIM
Definition: med_outils.h:49
MED_FILTER_INIT
#define MED_FILTER_INIT
Definition: med.h:374
ISCRUTE_id
#define ISCRUTE_id(entier)
Definition: med_utils.h:319
MED_ERR_LOCALIZATION
#define MED_ERR_LOCALIZATION
Definition: med_err.h:89
MED_UNDEF_SIZE
#define MED_UNDEF_SIZE
Definition: med.h:306
med_geometry_type
int med_geometry_type
Definition: med.h:194
_MEDmodeAcces
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
med_idt
hid_t med_idt
Definition: med.h:331
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
_MEDattributeIntWr
#define _MEDattributeIntWr(w, x, y)
Definition: med_hdfi.h:45
MED_ACC_RDONLY
Definition: med.h:120
MED_ERR_LOCALIZATION_MSG
#define MED_ERR_LOCALIZATION_MSG
Definition: med_err.h:139
MED_ERR_INVALID
#define MED_ERR_INVALID
Definition: med_err.h:40
MED_UNDEF_STMODE
Definition: med.h:108
MED_ERR_ATTRIBUTE
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:100
med_err
herr_t med_err
Definition: med.h:332
_MEDdatasetWr
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)
MED_NOM_NOM
#define MED_NOM_NOM
Definition: med_outils.h:41
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition: med_err.h:30
MED_INTERNAL_FLOAT64
Definition: med.h:156
MED_ERR_FILTER
#define MED_ERR_FILTER
Definition: med_err.h:93
MED_NOM_INM
#define MED_NOM_INM
Definition: med_outils.h:150
MED_NOM_GEO
#define MED_NOM_GEO
Definition: med_outils.h:133
med_int
int med_int
Definition: med.h:342
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition: med_err.h:29
MED_NOM_GAU
#define MED_NOM_GAU
Definition: med_outils.h:138
med.h
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
med_float
double med_float
Definition: med.h:336
med_access_mode
med_access_mode
Definition: med.h:120
MED_LOCALIZATION_GRP_SIZE
#define MED_LOCALIZATION_GRP_SIZE
Definition: med_outils.h:239
MEDfilterClose
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
Definition: MEDfilterClose.c:35
MED_ERR_INTERNAL_MSG
#define MED_ERR_INTERNAL_MSG
Definition: med_err.h:196
MED_ERR_ACCESSMODE
#define MED_ERR_ACCESSMODE
Definition: med_err.h:104
_MEDattributeStringWr
MEDC_EXPORT med_err _MEDattributeStringWr(med_idt pid, const char *const attname, const med_size attsize, const char *const val)
MED_STRUCT_GEO_SUP_INTERNAL
#define MED_STRUCT_GEO_SUP_INTERNAL
Definition: med.h:229
_MEDdatagroupCreer
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MED_ERR_DATASET
#define MED_ERR_DATASET
Definition: med_err.h:98
MED_ERR_DATAGROUP
#define MED_ERR_DATAGROUP
Definition: med_err.h:99
med_switch_mode
med_switch_mode
Definition: med.h:96
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
med_outils.h
med_config.h
MED_GAUSS_ELNO
#define MED_GAUSS_ELNO
Definition: med.h:262
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:299
MED_NOM_VAL
#define MED_NOM_VAL
Definition: med_outils.h:53
MED_NO_PROFILE
#define MED_NO_PROFILE
Definition: med.h:281
MED_LOCALIZATION_GRP
#define MED_LOCALIZATION_GRP
Definition: med_outils.h:238
MED_NOM_NBR
#define MED_NOM_NBR
Definition: med_outils.h:40
NOFINALBLANK
#define NOFINALBLANK(chaine, label)
Definition: med_utils.h:311
MED_NOM_COO
#define MED_NOM_COO
Definition: med_outils.h:56
MED_ERR_UNRECOGNIZED
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:39
MED_ERR_FILE_MSG
#define MED_ERR_FILE_MSG
Definition: med_err.h:132
_MEDdatagroupOuvrir
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
MEDlocalizationWr
med_err MEDlocalizationWr(const med_idt fid, const char *const localizationname, const med_geometry_type geotype, const med_int spacedimension, const med_float *const elementcoordinate, const med_switch_mode switchmode, const med_int nipoint, const med_float *const ipointcoordinate, const med_float *const weight, const char *const geointerpname, const char *const sectionmeshname)
Cette routine permet l'écriture d'une localisation localizationname de points d'intégration dans/auto...
Definition: MEDlocalizationWr.c:49
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
MED_ACC_UNDEF
Definition: med.h:124