MED fichier
MEDmeshComputationStepCr.c
Aller à la documentation de ce fichier.
1/* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2025 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#include <string.h>
23#include <stdlib.h>
24
37
38
41 const char * const meshname,
42 const med_int numdt1,
43 const med_int numit1,
44 const med_int numdt2,
45 const med_int numit2,
46 const med_float dt2 )
47{
48
49 med_access_mode _MED_ACCESS_MODE;
50 med_err _ret=-1;
51 med_idt _meshid=0,_datagroup1=0,_datagroup2=0,_datagroup3=0;
52 char _meshpath [MED_MESH_SUPPORT_GRP_SIZE+MED_NAME_SIZE+1]="";
53 char _datagroupname [2*MED_MAX_PARA+1]="";
54 char _datagroupname2[2*MED_MAX_PARA+1]="";
55 char _datagroupname1bis[2*MED_MAX_PARA+1]="";
56 char _latestcpstname[2*MED_MAX_PARA+1]="";
57 char* _datagroupname1=_datagroupname;
58 char _datagroupname3[2*MED_MAX_PARA+1]="";
61 med_bool _isasupportmesh = MED_FALSE;
62 med_int _nextdt=MED_NO_DT, _nextit=MED_NO_IT,_pvdt=MED_NO_DT, _pvit=MED_NO_IT;
63 med_int _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
64 med_int _numdt1=numdt1,_numit1=numit1;
65 med_int _false = 0;
66 med_sorting_type _sortingtype;
67 med_int _intsortingtype;
68 /*
69 * On inhibe le gestionnaire d'erreur
70 */
72 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
73
74 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
76 goto ERROR;
77 }
78
79 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
81 ISCRUTE_int(_MED_ACCESS_MODE);
82 goto ERROR;
83 }
84
85/* strcat( _meshpath, meshname); */
86/* strcat( _pathsrc , meshname);strcat( _pathsrc , "/"); */
87/* strcat( _pathdst , meshname);strcat( _pathdst , "/"); */
88/* if ((_meshid = _MEDdatagroupOuvrir(fid,_meshpath)) < 0) { */
89/* MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_meshpath); */
90/* SSCRUTE(_meshid);goto ERROR; */
91/* } */
92
93 if ((_meshid=_MEDmeshDatagroupOpen(fid,meshname,_meshpath,&_isasupportmesh)) < 0) {
95 SSCRUTE(_meshpath); goto ERROR;
96 }
97 strcat( _pathsrc , _meshpath);strcat( _pathsrc , "/");
98 strcat( _pathdst , _meshpath);strcat( _pathdst , "/");
99
100 if ( _MEDattrEntierLire(_meshid,MED_NOM_NXT,&_lastnumdt) < 0) {
101/* MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
102/* SSCRUTE(meshname);SSCRUTE(_meshpath);SSCRUTE(MED_NOM_NXT); */
103/* goto ERROR; */
104 _lastnumdt = MED_NO_DT;
105 }
106
107 if ( _MEDattrEntierLire(_meshid,MED_NOM_NXI,&_lastnumit) < 0) {
108/* MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
109/* SSCRUTE(meshname);SSCRUTE(_meshpath);SSCRUTE(MED_NOM_NXI); */
110/* goto ERROR; */
111 _lastnumit = MED_NO_IT;
112 }
113
114 if ( _MEDattrEntierLire(_meshid,MED_NOM_SRT,&_intsortingtype) < 0) {
116 SSCRUTE(meshname);SSCRUTE(MED_NOM_SRT);
117 ISCRUTE(_intsortingtype);goto ERROR;
118 }
119 _sortingtype = (med_sorting_type) (_intsortingtype);
120
121 _MEDgetComputationStepName(_sortingtype,numdt1,numit1,_datagroupname);
122 _MEDgetComputationStepName(_sortingtype,numdt2,numit2,_datagroupname2);
123 _MEDgetComputationStepName(_sortingtype,_lastnumdt,_lastnumit,_latestcpstname);
124
125 /*
126 L'utilisateur peut demander la création d'une nouvelle étape de calcul postérieure
127 à toutes les autres en indiquant (numdt1 == numdt2) && (numit1 == numit2)
128 Celà fonctionne aussi pour MED_NO_DT, NED_NO_IT
129 */
130
131 if ( (numdt1 == numdt2) && (numit1 == numit2) ) {
132 _numdt1 = _lastnumdt;
133 _numit1 = _lastnumit;
134 _datagroupname1 = _latestcpstname;
135 }
136 /*Vérifie que le _datagroupname2 est bien postérieur ou égal au _datagroupname1
137 REM: _datagroupname1 peut être la première/dernière étape de calcul
138 ou une étape intermédiaire */
139 if ( strncmp(_datagroupname2,_datagroupname1,2*MED_MAX_PARA+1) < 0) {
140 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,_datagroupname2);
141 SSCRUTE(meshname);SSCRUTE(_datagroupname1);goto ERROR;
142 }
143
144 strcat( _pathsrc , _datagroupname1 );strcat( _pathsrc , "/");
145 strcat( _pathdst , _datagroupname2 );strcat( _pathdst , "/");
146
147 /* On accepte l'absence de _datagroupname1 uniquement si
148 numdt2 == MED_NO_DT && numit2 == MED_NO_IT */
149 if ( (_datagroup1 = _MEDdatagroupOuvrir(_meshid,_datagroupname1)) < 0 ) {
150 if ( (numdt2 != MED_NO_DT ) || (numit2 != MED_NO_IT) ) {
152 SSCRUTE(meshname);goto ERROR;
153 }
154 }
155
156 /*L'étape de calcul à créer ne doit pas déjà exister*/
157 if ( (_datagroup2 = _MEDdatagroupOuvrir(_meshid,_datagroupname2)) >= 0 ) {
158 MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_COMPUTINGSTEP,_datagroupname2);
159 SSCRUTE(meshname);goto ERROR;
160 }
161
162
163 if ( _datagroup1 > 0 ) {
164
165
166 /*Lecture NEXT et PREV du datagroup1 */
167 if ( _MEDattrEntierLire(_datagroup1,MED_NOM_NXT,&_nextdt) < 0) {
169 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXT);
170 goto ERROR;
171 }
172
173 if ( _MEDattrEntierLire(_datagroup1,MED_NOM_NXI,&_nextit) < 0) {
175 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI);
176 goto ERROR;
177 }
178
179 /* On vérifie que la nouvelle étape de calcul s'insère correctement :
180 < au next du datagroup1 */
181/* if ( !((_nextdt == MED_NO_DT) && (_nextit == MED_NO_IT) )) { */
182 if ( (_nextdt != MED_NO_DT) || (_nextit != MED_NO_IT) ) {
183 _MEDgetComputationStepName(_sortingtype,_nextdt,_nextit,_datagroupname3);
184
185 if ( strncmp(_datagroupname3,_datagroupname2,2*MED_MAX_PARA+1) <= 0) {
186 MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,_datagroupname2);
187 SSCRUTE(meshname);SSCRUTE(_datagroupname3);goto ERROR;
188 }
189 }
190
191 /*On crée la nouvelle étape de calcul (au plus tard, après vérifs...)*/
192 if ((_datagroup2 = _MEDdatagroupCreer(_meshid,_datagroupname2)) < 0 ) {
193 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
194 SSCRUTE(meshname);goto ERROR;
195 }
196
197 /*On crée les datagroups, attributs et liens sur les datatsets et les liens symboliques
198 pour avoir une image de l'étape de calcul précedente.*/
199 if ( _MEDvisit(fid,_pathsrc,_pathdst,(medvisitorfunc) _MEDlinkobjs ) < 0 ) {
201 SSCRUTE(meshname);SSCRUTE(_pathsrc);SSCRUTE(_pathdst);
202 goto ERROR;
203 }
204
205 /*Ecriture NEXT et PREV du nouveau datagroup2 */
206 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXT,&_nextdt) < 0) {
208 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
209 goto ERROR;
210 }
211
212 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXI,&_nextit) < 0) {
214 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
215 goto ERROR;
216 }
217
218
219 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVT,&_numdt1) < 0) {
221 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVT);
222 goto ERROR;
223 }
224
225 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVI,&_numit1) < 0) {
227 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVI);
228 goto ERROR;
229 }
230
231
232 /*Modification du NEXT du datagroup1 */
233 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXT,&numdt2) < 0) {
235 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXT);
236 goto ERROR;
237 }
238
239 if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXI,&numit2) < 0) {
241 SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI);
242 goto ERROR;
243 }
244
245 /*Modification de PREV du ( NEXT de datagroup1 ) s'il existe*/
246 if (strlen(_datagroupname3) ) {
247
248 if ( (_datagroup3 = _MEDdatagroupOuvrir(_meshid,_datagroupname3)) < 0 ) {
249 MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_COMPUTINGSTEP,_datagroupname3);
250 SSCRUTE(meshname);goto ERROR;
251 }
252
253 if ( _MEDattrEntierLire(_datagroup3,MED_NOM_PVT,&_pvdt) < 0) {
255 SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVT);
256 goto ERROR;
257 }
258
259 if ( _MEDattrEntierLire(_datagroup3,MED_NOM_PVI,&_pvit) < 0) {
261 SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVI);
262 goto ERROR;
263 }
264 _MEDgetComputationStepName(_sortingtype,_pvdt,_pvit,_datagroupname1bis);
265
266 if ( strncmp(_datagroupname1,_datagroupname1bis,2*MED_MAX_PARA+1) != 0) {
267 MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_COMPUTINGSTEP,_datagroupname1);
268 SSCRUTE(meshname);SSCRUTE(_datagroupname1bis);goto ERROR;
269 }
270
271 if ( _MEDattributeIntWr(_datagroup3,MED_NOM_PVT,&numdt2) < 0) {
273 SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVT);
274 goto ERROR;
275 }
276
277 if ( _MEDattributeIntWr(_datagroup3,MED_NOM_PVI,&numit2) < 0) {
279 SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVI);
280 goto ERROR;
281 }
282
283 }
284
285 } else { /* Création de la première étape de calcul */
286
287 /*On crée la nouvelle étape de calcul (au plus tard, après vérifs...) */
288 if ((_datagroup2 = _MEDdatagroupCreer(_meshid,_datagroupname2)) < 0 ) {
289 MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
290 SSCRUTE(meshname);goto ERROR;
291 }
292
293 /* Ecriture de MED_NO_IT, MED_NO_DT pour NEXT et PREV de la première
294 étape de calcul */
295 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXT,&numdt2) < 0) {
297 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
298 goto ERROR;
299 }
300
301 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXI,&numit2) < 0) {
303 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
304 goto ERROR;
305 }
306
307 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVT,&numdt2) < 0) {
309 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVT);
310 goto ERROR;
311 }
312
313 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVI,&numit2) < 0) {
315 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVI);
316 goto ERROR;
317 }
318
319 }
320
321 /*Cree ou ouvre l'attribut MED_NOM_NDT pour écriture */
322 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NDT,&numdt2) < 0) {
324 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NDT);
325 ISCRUTE(numdt2);goto ERROR;
326 }
327
328 /*Cree ou ouvre l'attribut MED_NOM_PDT pour écriture */
329 if ( _MEDattrFloatEcrire(_datagroup2,MED_NOM_PDT,&dt2) < 0) {
331 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PDT);
332 RSCRUTE(dt2);goto ERROR;
333 }
334
335 /*Cree ou ouvre l'attribut MED_NOM_NOR pour écriture */
336 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NOR,&numit2) < 0) {
338 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NOR);
339 ISCRUTE(numit2); goto ERROR;
340 }
341
342 /* Une nouvelle étape de calcul est vierge de toute modifiation*/
343 if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_false) < 0) {
345 SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_CGT);
346 goto ERROR;
347 }
348
349
350 /* Ecriture de NEXT et PREV au niveau meshid (dernière étape de calcul créée */
351 if ( strncmp(_datagroupname2,_latestcpstname,2*MED_MAX_PARA+1) >= 0) {
352
353 if ( _MEDattributeIntWr(_meshid,MED_NOM_NXT,&numdt2) < 0) {
355 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
356 goto ERROR;
357 }
358
359 if ( _MEDattributeIntWr(_meshid,MED_NOM_NXI,&numit2) < 0) {
361 SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
362 goto ERROR;
363 }
364 }
365
366 _ret = 0;
367 ERROR:
368
369 if (_datagroup3>0) if (_MEDdatagroupFermer(_datagroup3) < 0) {
370 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname3);
371 ISCRUTE_id(_datagroup3);
372 }
373
374 if (_datagroup2>0) if (_MEDdatagroupFermer(_datagroup2) < 0) {
375 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
376 ISCRUTE_id(_datagroup2);
377 }
378
379 if (_datagroup1>0) if (_MEDdatagroupFermer(_datagroup1) < 0) {
380 MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
381 ISCRUTE_id(_datagroup1);
382 }
383
384 if (_meshid>0) if (_MEDdatagroupFermer(_meshid) < 0) {
386 ISCRUTE_id(_meshid);
387 }
388
389 return _ret;
390}
#define MED_NAME_SIZE
#define MED_MAX_PARA
#define MED_ERR_(rt, r1, r2, r3)
#define SSCRUTE(chaine)
#define RSCRUTE(reel)
#define ISCRUTE(entier)
#define ISCRUTE_id(entier)
#define ISCRUTE_int(entier)
med_err MEDmeshComputationStepCr(const med_idt fid, const char *const meshname, const med_int numdt1, const med_int numit1, const med_int numdt2, const med_int numit2, const med_float dt2)
Cette routine permet de créer une nouvelle étape de calcul dans un maillage.
#define MED_ERR_OPEN
Definition med_err.h:37
#define MED_ERR_ACCESSMODE
Definition med_err.h:104
#define MED_ERR_DATAGROUP
Definition med_err.h:99
#define MED_ERR_CLOSE
Definition med_err.h:30
#define MED_ERR_DOESNTEXIST
Definition med_err.h:38
#define MED_ERR_MESH_MSG
Definition med_err.h:134
#define MED_ERR_INVALID
Definition med_err.h:40
#define MED_ERR_ATTRIBUTE
Definition med_err.h:100
#define MED_ERR_CREATE
Definition med_err.h:27
#define MED_ERR_EXIST
Definition med_err.h:43
#define MED_ERR_COMPUTINGSTEP
Definition med_err.h:113
#define MED_ERR_NOTEQUAL
Definition med_err.h:42
#define MED_ERR_READ
Definition med_err.h:28
#define MED_ERR_RANGE
Definition med_err.h:34
#define MED_ERR_FILE_MSG
Definition med_err.h:133
#define MED_ERR_WRITE
Definition med_err.h:29
#define MED_ERR_UNRECOGNIZED
Definition med_err.h:39
#define MED_ERR_VISIT
Definition med_err.h:49
herr_t(* medvisitorfunc)(hid_t g_id, const char *name, const H5L_info_t *info, void *op_data)
Definition med_hdfi.h:522
MEDC_EXPORT med_err _MEDlinkobjs(med_idt id, const char *lname, const H5L_info_t *linfo, visitordatas *data)
#define _MEDattrEntierLire(x, y, z)
Definition med_hdfi.h:68
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)
#define _MEDattrFloatEcrire(w, x, y)
Definition med_hdfi.h:48
MEDC_EXPORT med_err _MEDvisit(const med_idt fid, const char *const srcpath, const char *const dstpath, medvisitorfunc)
MEDC_EXPORT med_err _MEDdatagroupFermer(med_idt id)
MEDC_EXPORT med_err _MEDgetComputationStepName(const med_sorting_type sortingtype, const med_int numdt, const med_int numit, char *const datagroupname)
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_NOR
Definition med_outils.h:146
#define MED_MESH_SUPPORT_GRP_SIZE
Definition med_outils.h:172
#define MED_NOM_PVT
Definition med_outils.h:72
#define MED_NOM_SRT
Definition med_outils.h:76
#define MED_NOM_PVI
Definition med_outils.h:73
#define MED_NOM_NXI
Definition med_outils.h:71
#define MED_NOM_CGT
Definition med_outils.h:74
#define MED_NOM_NXT
Definition med_outils.h:70
#define MED_NOM_NDT
Definition med_outils.h:143
#define MED_NOM_PDT
Definition med_outils.h:145
MEDC_EXPORT med_idt _MEDmeshDatagroupOpen(const med_idt fid, const char *const meshname, char *const usedpath, med_bool *const isasupportmesh)