MED fichier
MEDlocalizationWr.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2020 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
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;
69
70 /*
71 * On inhibe le gestionnaire d'erreur HDF 5
72 */
74 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
75
76 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
78 goto ERROR;
79 }
80
81 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
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) {
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) {
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) {
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) {
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 ) {
164 goto ERROR;
165 }
166
167 if ( _MEDdatasetWr(_lzid,MED_NOM_COO,MED_INTERNAL_FLOAT64,&_filter, elementcoordinate) < 0) {
169 goto ERROR;
170 }
171
172 if ( MEDfilterClose(&_filter) < 0 ) {
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) {
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) {
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 ) {
207 goto ERROR;
208 }
209
210 if ( _MEDdatasetWr(_lzid,MED_NOM_GAU,MED_INTERNAL_FLOAT64,&_filter, ipointcoordinate) < 0) {
212 goto ERROR;
213 }
214
215 if ( MEDfilterClose(&_filter) < 0 ) {
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 ) {
229 goto ERROR;
230 }
231
232 if ( _MEDdatasetWr(_lzid,MED_NOM_VAL,MED_INTERNAL_FLOAT64,&_filter, weight) < 0) {
234 goto ERROR;
235 }
236
237 if ( MEDfilterClose(&_filter) < 0 ) {
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) {
254 ISCRUTE_id(_root);
255 }
256
257 return _ret;
258
259}
260
MEDC_EXPORT med_err MEDfilterClose(med_filter *const filter)
Désalloue les ressources hdf détenues par un filtre.
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)
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...
#define MED_NAME_SIZE
Definition: med.h:81
med_switch_mode
Definition: med.h:96
int med_geometry_type
Definition: med.h:194
#define MED_FILTER_INIT
Definition: med.h:365
@ MED_UNDEF_STMODE
Definition: med.h:108
#define MED_ALL_CONSTITUENT
Definition: med.h:293
#define MED_STRUCT_GEO_SUP_INTERNAL
Definition: med.h:229
#define MED_GAUSS_ELNO
Definition: med.h:262
int med_int
Definition: med.h:333
#define MED_UNDEF_SIZE
Definition: med.h:297
@ MED_INTERNAL_FLOAT64
Definition: med.h:156
#define MED_NO_PROFILE
Definition: med.h:279
double med_float
Definition: med.h:327
herr_t med_err
Definition: med.h:323
#define MED_STRUCT_GEO_INTERNAL
Definition: med.h:228
med_access_mode
Definition: med.h:120
@ MED_ACC_UNDEF
Definition: med.h:124
@ MED_ACC_RDONLY
Definition: med.h:120
hid_t med_idt
Definition: med.h:322
#define MED_ERR_ACCESSMODE
Definition: med_err.h:104
#define MED_ERR_FILTER
Definition: med_err.h:93
#define MED_ERR_DATAGROUP
Definition: med_err.h:99
#define MED_ERR_CLOSE
Definition: med_err.h:30
#define MED_ERR_INVALID
Definition: med_err.h:40
#define MED_ERR_LOCALIZATION_MSG
Definition: med_err.h:139
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:100
#define MED_ERR_CREATE
Definition: med_err.h:27
#define MED_ERR_INTERNAL_MSG
Definition: med_err.h:196
#define MED_ERR_FILE_MSG
Definition: med_err.h:132
#define MED_ERR_LOCALIZATION
Definition: med_err.h:89
#define MED_ERR_WRITE
Definition: med_err.h:29
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:39
#define MED_ERR_DATASET
Definition: med_err.h:98
MEDC_EXPORT med_err _MEDattributeStringWr(med_idt pid, const char *const attname, const med_size attsize, const char *const val)
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)
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
#define _MEDattributeIntWr(w, x, y)
Definition: med_hdfi.h:45
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
MEDC_EXPORT med_idt _MEDdatagroupOuvrir(med_idt pid, const char *const nom)
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
#define MED_NOM_DIM
Definition: med_outils.h:49
#define MED_NOM_NOM
Definition: med_outils.h:41
#define MED_NOM_COO
Definition: med_outils.h:56
#define MED_NOM_VAL
Definition: med_outils.h:53
#define MED_LOCALIZATION_GRP_SIZE
Definition: med_outils.h:239
#define MED_NOM_GAU
Definition: med_outils.h:138
#define MED_NOM_GEO
Definition: med_outils.h:133
#define MED_LOCALIZATION_GRP
Definition: med_outils.h:238
#define MED_NOM_NBR
Definition: med_outils.h:40
#define MED_NOM_INM
Definition: med_outils.h:150
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
#define SSCRUTE(chaine)
Definition: med_utils.h:323
#define ISCRUTE(entier)
Definition: med_utils.h:313
#define ISCRUTE_id(entier)
Definition: med_utils.h:319
#define NOFINALBLANK(chaine, label)
Definition: med_utils.h:311
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
Filtre de sélection.
Definition: med.h:346