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 med_err
_MEDmeshCr(const med_idt fid,const char * const root,const char * const meshname,const med_int spacedim,const med_int meshdim,const med_mesh_type meshtype,const char * const description,const char * const dtunit,const med_sorting_type sortingtype,const med_axis_type axistype,const char * const axisname,const char * const axisunit)27 _MEDmeshCr(const med_idt fid, const char * const root,
28 const char * const meshname, const med_int spacedim,
29 const med_int meshdim, const med_mesh_type meshtype,
30 const char * const description, const char * const dtunit,
31 const med_sorting_type sortingtype,
32 const med_axis_type axistype, const char * const axisname,
33 const char * const axisunit)
34 {
35
36 med_access_mode _MED_ACCESS_MODE;
37 med_err _ret=-1;
38 med_idt _root=0,_datagroup1=0;
39 /* _datagroup2=0,_datagroup3=0; */
40 med_int _intmeshtype = (med_int) meshtype;
41 med_int _intaxistype = (med_int) axistype;
42 char _datagroupname1[MED_NAME_SIZE+1]="";
43 /* char _geotypename[MED_NAME_SIZE_ENTITE+1]=""; */
44 med_int _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
45 med_int _intsortingtype =(med_int) MED_SORT_UNDEF;
46 med_int _intexistingmeshtype=(med_int) MED_UNDEF_MESH_TYPE;
47 med_mesh_type _existingmeshtype = meshtype;
48 med_sorting_type _existingsortingtype = sortingtype;
49 med_size _nstep=0;
50
51 /*
52 * On inhibe le gestionnaire d'erreur
53 */
54 _MEDmodeErreurVerrouiller();
55 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
56
57 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
58 MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
59 goto ERROR;
60 }
61
62 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
63 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
64 ISCRUTE_int(_MED_ACCESS_MODE);
65 goto ERROR;
66 }
67
68 if ( sortingtype == MED_SORT_UNDEF) {
69 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"sortingtype");
70 ISCRUTE_int(sortingtype);
71 goto ERROR;
72 }
73
74 /*
75 * Si le DataGroup root n'existe pas, on le cree
76 */
77 if ((_root = _MEDdatagroupOuvrir(fid,root)) < 0)
78 if ((_root = _MEDdatagroupCreer(fid,root)) < 0) {
79 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root);
80 goto ERROR;
81 }
82
83 NOFINALBLANK(meshname,ERROR);
84 /*
85 * Si le Data Group "/MAA.../<meshname>" n'existe pas, on le cree
86 */
87 if ((_datagroup1 = _MEDdatagroupOuvrir(_root,meshname)) < 0)
88 if ((_datagroup1 = _MEDdatagroupCreer(_root,meshname)) < 0 ) {
89 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
90 goto ERROR;
91 }
92
93 /*
94 * Creation de l'attribut dimension du maillage
95 */
96 if (meshdim > spacedim) {
97 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"meshdim");
98 ISCRUTE(meshdim);ISCRUTE(spacedim);
99 SSCRUTE(root);SSCRUTE(meshname);goto ERROR;
100 }
101
102 /*
103 * Creation de l'attribut dimension de l'espace
104 */
105 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_ESP,&spacedim) < 0 ) {
106 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
107 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_ESP);
108 ISCRUTE(spacedim);goto ERROR;
109 }
110
111 /*
112 * Creation de l'attribut dimension du maillage
113 */
114 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_DIM,&meshdim) < 0 ) {
115 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
116 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DIM);
117 ISCRUTE(meshdim);goto ERROR;
118 }
119
120 /* Lecture de l'attribut MED_NOM_TYP */
121 if (_MEDattrEntierLire(_datagroup1,MED_NOM_TYP,&_intexistingmeshtype) >= 0)
122 _existingmeshtype = (med_mesh_type) (_intexistingmeshtype);
123
124 if ( _existingmeshtype != meshtype ) {
125 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_WRITE,MED_ERR_ATTRIBUTE_MSG);
126 SSCRUTE(MED_NOM_TYP);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
127 ISCRUTE_int(_existingmeshtype);ISCRUTE_int(meshtype);goto ERROR;
128
129 }
130 /*
131 * Creation de l'attribut correspondant au type du maillage (MED_STRUCTURE, MED_NON_STRUCTURE)
132 * L'attribut "TYP"
133 */
134 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_intmeshtype) < 0) {
135 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
136 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
137 ISCRUTE(_intmeshtype);goto ERROR;
138 }
139
140 /*
141 * La description associee au maillage
142 */
143 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_DES,MED_COMMENT_SIZE,description) < 0) {
144 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
145 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DES);
146 SSCRUTE(description);goto ERROR;
147 }
148
149
150 /*
151 * Creation de l'attribut nom de l'unit~ des dates
152 */
153 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
154 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
155 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
156 SSCRUTE(dtunit);goto ERROR;
157 }
158
159 /*
160 * Test de l'existence de l'attribut de tri des s~quences de calcul
161 */
162 if ( _MEDattrEntierLire(_datagroup1,MED_NOM_SRT,&_intsortingtype) >= 0) {
163 _existingsortingtype = (med_sorting_type) (_intsortingtype);
164 /* Nombre d'~tapes de calcul existantes */
165 _MEDnObjects(_datagroup1,".",&_nstep);
166 }
167
168 if ( (_existingsortingtype != sortingtype) && _nstep ) {
169 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,MED_ERR_ATTRIBUTE_MSG);
170 SSCRUTE(MED_NOM_SRT);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
171 ISCRUTE_int(_existingsortingtype);ISCRUTE_int(sortingtype);goto ERROR;
172 }
173
174 /*
175 * Creation de l'attribut de tri des s~quences de calcul
176 */
177
178 _intsortingtype = sortingtype;
179 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_SRT,&_intsortingtype) < 0) {
180 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
181 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_SRT);
182 ISCRUTE_int(sortingtype);goto ERROR;
183 }
184
185 /*
186 * Creation de l'attribut de la derni~re it~ration cr~e
187 */
188 /* if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXI,&_lastnumit) < 0) { */
189 /* MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
190 /* SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI); */
191 /* ISCRUTE(_lastnumit);goto ERROR; */
192 /* } */
193
194
195 /*
196 * L'attribut "REP"
197 */
198 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_REP,&_intaxistype) < 0) {
199 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
200 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_REP);
201 ISCRUTE(_intaxistype);goto ERROR;
202 }
203
204 /*
205 * Attribut "NOM"
206 */
207 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,spacedim*MED_SNAME_SIZE,axisname) < 0) {
208 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
209 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
210 SSCRUTE(axisname);goto ERROR;
211 }
212
213 /*
214 * Attribut "UNI"
215 */
216 if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,spacedim*MED_SNAME_SIZE,axisunit) < 0) {
217 MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
218 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
219 SSCRUTE(axisunit);goto ERROR;
220 }
221
222 /*
223 * Cr~ation du datagroup des mailles associ~es ~ un maillage structur~
224 * Cel~ permet d'utiliser les routines famille, num~ros/noms optionnels
225 * de la m~me fa~on que pour les maillages non structur~s
226 */
227 /* if ( meshtype == MED_STRUCTURE ) { */
228
229 /* if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) { */
230 /* MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root); */
231 /* SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);goto ERROR; */
232 /* } */
233
234 /* switch ( meshdim ) { */
235 /* case 1 : strcpy(_geotypename,MED_NOM_SE2); */
236 /* break; */
237 /* case 2 : strcpy(_geotypename,MED_NOM_QU4); */
238 /* break; */
239 /* case 3 : strcpy(_geotypename,MED_NOM_HE8); */
240 /* break; */
241 /* case 0 : strcpy(_geotypename,MED_NOM_PO1); */
242 /* break; */
243 /* default : */
244 /* MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,""); */
245 /* ISCRUTE(meshdim);SSCRUTE(root);SSCRUTE(meshname);goto ERROR; */
246 /* } */
247
248 /* if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) { */
249 /* MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename); */
250 /* SSCRUTE(root);SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);ISCRUTE_int(_geotypename); */
251 /* goto ERROR; */
252 /* } */
253 /* } */
254
255
256 /*
257 * Nettoyages divers
258 */
259 _ret = 0;
260
261 ERROR:
262 /* if (_datagroup3>0) if (_MEDdatagroupFermer(_datagroup3) < 0) { */
263 /* MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename); */
264 /* ISCRUTE_id(_datagroup3); */
265 /* } */
266
267 /* if (_datagroup2>0) if (_MEDdatagroupFermer(_datagroup2) < 0) { */
268 /* MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI); */
269 /* ISCRUTE_id(_datagroup2); */
270 /* } */
271
272 if (_datagroup1>0) if (_MEDdatagroupFermer(_datagroup1) < 0) {
273 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
274 ISCRUTE_id(_datagroup1);
275 }
276
277 if (_root>0) if (_MEDdatagroupFermer(_root) < 0) {
278 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,root);
279 ISCRUTE_id(_root);
280 }
281
282 return _ret;
283
284 }
285
286