Debian Codegraph @

tools/medimport/3.1.0/MAJ_310_320_familles.c

raw
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_config.h"
20 #include "med_outils.h"
21 #include "med.h"
22
23 #include <string.h>
24
25 #include "MAJ_310_320.h"
26 #include "MAJ_version.h"
27
28 static void _move_families(med_idt fid, char * const _pathi,char * const _pathf) {
29 med_err _ret=0;
30 med_int _nfam=0;
31 med_int _sizei,_sizef;
32 med_size _size=0;
33 int i=0;
34
35 _ret=_MEDnObjects(fid,_pathi,&_size);
36 MED_ERR_EXIT_IF(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_pathi);
37 _nfam = (med_int ) _size;
38
39 _sizef=strlen(_pathf); _sizei =_sizef-1;
40
41 /* MAJ des familles */
42 for (i=0;i<_nfam;i++) {
43
44 _pathi[_sizei]='/';
45 _pathf[_sizef]='/';
46 _pathi[++_sizei]='\0';
47 _pathf[++_sizef]='\0';
48 /* SSCRUTE(_pathi); */
49 /* SSCRUTE(_pathf); */
50
51 /*
52 * On recupere le nom de la famille
53 */
54
55 /* Attention : On enlève les groupes fam au fur et à mesure,
56 il ne faut pas utiliser _num mais 0.
57 ret = _MEDobjectGetName(fid, _pathi ,_num, &_pathi[_sizei]) < 0;
58 */
59 _ret = _MEDobjectGetName(fid, _pathi ,0, &_pathi[_sizei]) < 0;
60 MED_ERR_EXIT_IF(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
61
62 strncpy(&_pathf[_sizef],&_pathi[_sizei],MED_NAME_SIZE+1);
63
64 /* SSCRUTE(_pathi); */
65 /* SSCRUTE(_pathf); */
66
67 EXIT_IF( H5Lmove( fid, _pathi, fid, _pathf, H5P_DEFAULT, H5P_DEFAULT ) < 0, "Failed to move family ",_pathi);
68 --_sizei;--_sizef;
69 }
70 }
71
72
73 void MAJ_310_320_familles(med_idt fid)
74 {
75 med_err _ret=0;
76 htri_t _datasetexist;
77 char _pathi[(MED_FAMILY_GRP_SIZE+MED_NAME_SIZE+1) + MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = MED_FAMILY_GRP;
78 char _pathf[(MED_FAMILY_GRP_SIZE+1+MED_NAME_SIZE+1)+ MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = "/FAS_/";
79 /* char _pathtmp[MED_FAMILY_GRP_SIZE+3]="/FAS__/"; */
80 int _meshi=0;
81 med_size _sizei=0,_sizef=0,_size=0,_nmesh=0;
82 med_idt _famId=0,_famMeshId=0,_famZeId=0,_famElId=0,_famNoeId=0;
83 MAJ_version_num(fid,3,1,0);
84
85 /*Itération sur les différents maillages présents dans le groupe famille*/
86 _ret=_MEDnObjects(fid,_pathi,&_nmesh);
87 MED_ERR_EXIT_IF(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_pathi);
88
89 for (_meshi=0;_meshi<_nmesh;_meshi++) {
90
91 /*
92 * On recupere le nom du maillage
93 */
94 _pathi[MED_FAMILY_GRP_SIZE ]='\0';
95 _pathf[MED_FAMILY_GRP_SIZE+1]='\0';
96
97 _ret = _MEDobjectGetName(fid, _pathi ,_meshi, &_pathi[MED_FAMILY_GRP_SIZE]) < 0;
98 MED_ERR_EXIT_IF(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
99 /* SSCRUTE(_pathi); */
100
101 /*Création du chemin cible _pathf s'il n'existe pas dans le fichier*/
102 _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
103 if(!_datasetexist) {
104 _famId = _MEDdatagroupCreer(fid,_pathf);
105 MED_ERR_EXIT_IF(_famId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
106 if (_famId>0) _ret=_MEDdatagroupFermer(_famId);
107 MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
108 }
109 /*Création de la famille sur le maillage courant*/
110 strncpy(&_pathf[MED_FAMILY_GRP_SIZE+1],&_pathi[MED_FAMILY_GRP_SIZE],MED_NAME_SIZE+1);
111 _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
112 if(!_datasetexist) {
113 _famMeshId = _MEDdatagroupCreer(fid,_pathf);
114 MED_ERR_EXIT_IF(_famMeshId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
115 if (_famMeshId>0) _ret=_MEDdatagroupFermer(_famMeshId);
116 MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
117 }
118
119 _sizef=strlen(_pathf);_sizei =_sizef-1;
120
121 /* Si une famille d'éléments existe ds pathi crée la dans _path */
122 strncpy(&_pathi[_sizei],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE-1);
123 _pathi[_sizei+(MED_TAILLE_FAS_ENTITE-1)]='\0';
124 _datasetexist=H5Lexists( fid, _pathi, H5P_DEFAULT );
125 if (_datasetexist) {
126 strncpy(&_pathf[_sizef],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE-1);
127 _pathf[_sizef+(MED_TAILLE_FAS_ENTITE-1)]='\0';
128 _famNoeId = _MEDdatagroupCrOrderCr(fid,_pathf);
129 MED_ERR_EXIT_IF(_famNoeId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
130 if (_famNoeId>0) _ret=_MEDdatagroupFermer(_famNoeId);
131 MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
132 _move_families( fid, _pathi,_pathf);
133 }
134
135
136 /* Si une famille de noeud existe crée la dans _path */
137 strncpy(&_pathi[_sizei],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE-1);
138 _pathi[_sizei+(MED_TAILLE_FAS_ENTITE-1)]='\0';
139 _datasetexist=H5Lexists( fid, _pathi, H5P_DEFAULT );
140 if (_datasetexist) {
141 strncpy(&_pathf[_sizef],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE-1);
142 _pathf[_sizef+(MED_TAILLE_FAS_ENTITE-1)]='\0';
143 _famElId = _MEDdatagroupCrOrderCr(fid,_pathf);
144 MED_ERR_EXIT_IF(_famElId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
145 if (_famElId>0) _ret=_MEDdatagroupFermer(_famElId);
146 MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
147 _move_families( fid, _pathi,_pathf);
148 }
149
150 /* Création de la famille zéro dans _pathf */
151 strncpy(&_pathf[_sizef],MED_FAS_ZERO,MED_TAILLE_FAS_ZERO-1);
152 _pathf[_sizef+(MED_TAILLE_FAS_ZERO-1)]='\0';
153 _famZeId = _MEDdatagroupCrOrderCr(fid,_pathf);
154 MED_ERR_EXIT_IF(_famZeId < 0, MED_ERR_CREATE,MED_ERR_FAMILY,_pathf);
155 if (_famZeId>0) _ret=_MEDdatagroupFermer(_famZeId);
156 MED_ERR_EXIT_IF(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_pathf);
157 }
158
159 _pathi[MED_FAMILY_GRP_SIZE ]='\0';
160 _pathf[MED_FAMILY_GRP_SIZE+1]='\0';
161 _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
162
163 if (_datasetexist ) {
164 EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
165 EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathf);
166 }
167
168 /* _MEDobjetsOuverts(fid); */
169
170 /* MAJ_version_num(fid,3,1,0); */
171
172 }