MED fichier: Fichier source de MEDstructElementCr.c

MED fichier

MEDstructElementCr.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2023 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
47 /*PENSEZ A DOCUMENTER LE CAS DE PARTICULE (SANS MAILLAGE SUPPORT : MOT CLE A DEFINIR )*/
48
49 med_geometry_type
50 MEDstructElementCr(const med_idt fid,
51 const char* const modelname,
52 const med_int modeldim,
53 const char* const supportmeshname,
54 const med_entity_type sentitytype,
55 const med_geometry_type sgeotype
56 )
57 {
58 med_access_mode _MED_ACCESS_MODE;
59 med_err _err=-1;
60 med_idt _root=0,_elemid=0;
61 med_int _ret=-1;
62 char _path[MED_ELSTRUCT_GRP_SIZE+MED_NAME_SIZE+1]=MED_ELSTRUCT_GRP;
63 med_size _tmpn=0;
64 med_geometry_type _stgeotype=0;
65 med_int _medintstgeotype = 0;
66 med_int _medintsgeotype = sgeotype;
67 med_int _intentitytype = sentitytype;
68 med_int _nnode=0,_ncell=0;
69 med_bool _chgt=MED_FALSE,_trsf=MED_FALSE;
70
71 /* char _entitytypename[MED_TAILLE_NOM_ENTITE+1]=""; */
72
73 /*
74 * On inhibe le gestionnaire d'erreur
75 */
76 _MEDmodeErreurVerrouiller();
77 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
78
79 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
80 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
81 goto ERROR;
82 }
83
84 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
85 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
86 ISCRUTE_int(_MED_ACCESS_MODE);
87 goto ERROR;
88 }
89
90 /*
91 * Si le DataGroup /STRUCT/ n'existe pas, on le cree
92 */
93 if ((_root = _MEDdatagroupOpen(fid,_path)) < 0)
94 if ((_root = _MEDdatagroupCrOrderCr(fid,_path)) < 0) {
95 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
96 goto ERROR;
97 }
98
99 NOFINALBLANK(modelname,ERROR);
100
101 /*
102 * Si le DataGroup /STRUCT/<modelname> n'existe pas, on le cree
103 */
104 if ((_elemid = _MEDdatagroupOpen(_root,modelname)) < 0) {
105 if ((_elemid = _MEDdatagroupCreer(_root,modelname)) < 0) {
106 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,modelname);
107 SSCRUTE(_path);goto ERROR;
108 }
109 } else {
110 /*
111 * Lecture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure)
112 */
113 if ( _MEDattrEntierLire(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
114 MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
115 SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
116 goto ERROR;
117 }
118 _stgeotype = _medintstgeotype;
119 }
120 strcat(_path,modelname);
121
122 /*
123 * Creation/Ecriture de l'attribut MED_NOM_DIM (dimension de l'�l�ment)
124 */
125 if ( _MEDattributeIntWr(_elemid,MED_NOM_DIM,&modeldim) < 0 ) {
126 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
127 SSCRUTE(MED_NOM_DIM);ISCRUTE(modeldim);
128 goto ERROR;
129 }
130
131 /*
132 * Creation/Ecriture de l'attribut MED_NOM_NOM (nom du maillage support)
133 */
134 if ( _MEDattributeStringWr(_elemid,MED_NOM_NOM,MED_NAME_SIZE,supportmeshname) < 0) {
135 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
136 SSCRUTE(MED_NOM_NOM);SSCRUTE(supportmeshname);
137 goto ERROR;
138 }
139
140 /*
141 * Creation/Ecriture de l'attribut MED_NOM_ENT (type d'entit� support)
142 */
143 /* if (_MEDgetEntityTypeName(_entitytypename,sentitytype) < 0) { */
144 /* MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG); */
145 /* ISCRUTE_int(sentitytype);SSCRUTE(_entitytypename);SSCRUTE(_path); */
146 /* goto ERROR; */
147 /* } */
148
149 if ( _MEDattributeIntWr(_elemid,MED_NOM_ENT,&_intentitytype) < 0 ) {
150 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
151 SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype);
152 goto ERROR;
153 }
154
155 /*
156 Lecture dans le maillages support du nombre de noeuds
157 S'il n'y a pas de maillage support : 1
158 */
159 if (strlen(supportmeshname)) {
160 if ( (_nnode = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
161 MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
162 &_chgt,&_trsf) ) <= 0) {
163 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
164 ISCRUTE(_nnode);goto ERROR;
165 }
166 } else {
167 _nnode=1;
168 }
169
170 if (strlen(supportmeshname)) {
171 if ( (_ncell = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
172 MED_CELL,sgeotype,MED_CONNECTIVITY,MED_NODAL,
173 &_chgt,&_trsf) ) < 0) {
174 MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
175 ISCRUTE(_ncell);goto ERROR;
176 }
177 } else {
178 _ncell=0;
179 }
180
181 /*
182 * Creation/Ecriture de l'attribut MED_NOM_GEO (type g�om�trique des mailles support)
183 */
184 _medintsgeotype = sgeotype;
185 if ( _MEDattributeIntWr(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) {
186 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
187 SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype);
188 goto ERROR;
189 }
190
191 /*
192 * Creation/Ecriture de l'attribut MED_NOM_NAV (nombre d'attributs variables associ�s � un �l�ment de structure)
193 */
194 /* if ( _MEDattributeIntWr(_elemid,MED_NOM_NAV,&nvariableattribute) < 0 ) { */
195 /* MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */
196 /* SSCRUTE(MED_NOM_NAV);ISCRUTE(nvariableattribute); */
197 /* goto ERROR; */
198 /* } */
199
200 /*
201 * Creation/Ecriture de l'attribut MED_NOM_NAC (nombre d'attributs constant associ�s � un �l�ment de structure)
202 */
203 /* if ( _MEDattributeIntWr(_elemid,MED_NOM_NAC,&nconstattribute) < 0 ) { */
204 /* MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */
205 /* SSCRUTE(MED_NOM_NAC);ISCRUTE(nconstattribute); */
206 /* goto ERROR; */
207 /* } */
208
209
210 /*
211 * Nombre d'�l�ments de structure
212 */
213 if ( !_stgeotype ) {
214
215 /*Si l'�l�ment de struture ne pr�-existait pas,
216 il a �t� cr�e en d�but de proc�dure (il y a au moins 1 �l�ment dans le groupe) */
217 if ((_err=_MEDnObjects(fid,MED_ELSTRUCT_GRP,&_tmpn)) <0) {
218 MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_STRUCT,MED_ELSTRUCT_GRP);
219 goto ERROR;
220 }
221
222 _stgeotype=_tmpn+MED_STRUCT_GEO_INTERNAL;
223 _medintstgeotype=_stgeotype;
224
225 /*
226 * Ecriture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure)
227 */
228 if ( _MEDattributeIntWr(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
229 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
230 SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
231 goto ERROR;
232 }
233 }
234
235 _ret = _stgeotype;
236
237 ERROR:
238
239 if (_elemid>0) if (_MEDdatagroupFermer(_elemid) < 0) {
240 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
241 ISCRUTE_id(_elemid);
242 }
243
244 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
245 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_ELSTRUCT_GRP);
246 ISCRUTE_id(_root);
247 }
248
249 return _ret;
250
251 }
MED_STRUCT_GEO_INTERNAL
#define MED_STRUCT_GEO_INTERNAL
Definition: med.h:230
MED_ACC_RDONLY
Definition: med.h:122
MED_ERR_API
#define MED_ERR_API
Definition: med_err.h:111
MED_ERR_CREATE
#define MED_ERR_CREATE
Definition: med_err.h:27
MED_ERR_COUNT
#define MED_ERR_COUNT
Definition: med_err.h:47
_MEDnObjects
MEDC_EXPORT med_err _MEDnObjects(const med_idt fid, const char *const path, med_size *n)
ISCRUTE_id
#define ISCRUTE_id(entier)
Definition: med_utils.h:319
med_geometry_type
int med_geometry_type
Definition: med.h:196
_MEDattributeIntWr
#define _MEDattributeIntWr(w, x, y)
Definition: med_hdfi.h:45
MED_NOM_DIM
#define MED_NOM_DIM
Definition: med_outils.h:49
ISCRUTE_int
#define ISCRUTE_int(entier)
Definition: med_utils.h:314
_MEDmodeAcces
MEDC_EXPORT med_access_mode _MEDmodeAcces(med_idt oid)
med_size
hsize_t med_size
Definition: med.h:331
med_idt
hid_t med_idt
Definition: med.h:333
MED_FALSE
Definition: med.h:262
MED_ERR_
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:160
_MEDdatagroupOpen
MEDC_EXPORT med_idt _MEDdatagroupOpen(const med_idt pid, const char *const name)
MED_ERR_ATTRIBUTE
#define MED_ERR_ATTRIBUTE
Definition: med_err.h:100
MED_ERR_STRUCT
#define MED_ERR_STRUCT
Definition: med_err.h:123
MED_ERR_INVALID
#define MED_ERR_INVALID
Definition: med_err.h:40
med_err
herr_t med_err
Definition: med.h:334
med_outils.h
med_entity_type
med_entity_type
Definition: med.h:145
MED_ERR_CLOSE
#define MED_ERR_CLOSE
Definition: med_err.h:30
MED_NOM_NOM
#define MED_NOM_NOM
Definition: med_outils.h:41
MED_NOM_GEO
#define MED_NOM_GEO
Definition: med_outils.h:133
MED_NOM_NEO
#define MED_NOM_NEO
Definition: med_outils.h:134
med_int
int med_int
Definition: med.h:344
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:313
MED_ERR_WRITE
#define MED_ERR_WRITE
Definition: med_err.h:29
med_config.h
med_bool
med_bool
Definition: med.h:262
MED_ERR_CALL
#define MED_ERR_CALL
Definition: med_err.h:48
MEDmeshnEntity
MEDC_EXPORT med_int MEDmeshnEntity(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_data_type datatype, const med_connectivity_mode cmode, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une étape de calcul donnée.
Definition: MEDmeshnEntity.c:44
MED_ERR_READ
#define MED_ERR_READ
Definition: med_err.h:28
MED_COORDINATE
Definition: med.h:151
MED_NO_CMODE
Definition: med.h:257
MED_ACC_UNDEF
Definition: med.h:126
MED_NO_DT
#define MED_NO_DT
Definition: med.h:322
med_access_mode
med_access_mode
Definition: med.h:122
MED_NONE
#define MED_NONE
Definition: med.h:233
_MEDattributeStringWr
MEDC_EXPORT med_err _MEDattributeStringWr(med_idt pid, const char *const attname, const med_size attsize, const char *const val)
MED_ELSTRUCT_GRP
#define MED_ELSTRUCT_GRP
Definition: med_outils.h:174
MED_ERR_DATAGROUP
#define MED_ERR_DATAGROUP
Definition: med_err.h:99
_MEDdatagroupCreer
MEDC_EXPORT med_idt _MEDdatagroupCreer(med_idt pid, const char *const nom)
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:323
MED_ERR_ACCESSMODE
#define MED_ERR_ACCESSMODE
Definition: med_err.h:104
_MEDdatagroupCrOrderCr
MEDC_EXPORT med_idt _MEDdatagroupCrOrderCr(const med_idt pid, const char *const name)
MED_CELL
Definition: med.h:145
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:83
_MEDcheckVersion30
MEDC_EXPORT med_err _MEDcheckVersion30(med_idt fid)
_MEDattrEntierLire
#define _MEDattrEntierLire(x, y, z)
Definition: med_hdfi.h:68
MED_NODE
Definition: med.h:145
med.h
NOFINALBLANK
#define NOFINALBLANK(chaine, label)
Definition: med_utils.h:311
MEDstructElementCr
med_geometry_type MEDstructElementCr(const med_idt fid, const char *const modelname, const med_int modeldim, const char *const supportmeshname, const med_entity_type sentitytype, const med_geometry_type sgeotype)
Cette routine permet de créer un nouveau modèle d'éléments de structure dans un fichier MED.
Definition: MEDstructElementCr.c:50
MED_CONNECTIVITY
Definition: med.h:151
MED_ERR_UNRECOGNIZED
#define MED_ERR_UNRECOGNIZED
Definition: med_err.h:39
MED_NO_IT
#define MED_NO_IT
Definition: med.h:323
MED_NOM_ENT
#define MED_NOM_ENT
Definition: med_outils.h:135
_MEDmodeErreurVerrouiller
MEDC_EXPORT void _MEDmodeErreurVerrouiller(void)
MED_ERR_FILE_MSG
#define MED_ERR_FILE_MSG
Definition: med_err.h:132
MED_ELSTRUCT_GRP_SIZE
#define MED_ELSTRUCT_GRP_SIZE
Definition: med_outils.h:175
MED_NODAL
Definition: med.h:257
_MEDdatagroupFermer
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)