Debian Codegraph @

tools/medimport/3.0.0/MAJ_300_310_champs.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_300_310.h"
26 #include "MAJ_version.h"
27
28 void MAJ_300_310_champs(med_idt fid)
29 {
30 med_err ret;
31 med_field_type typcha;
32 char nomcha [MED_NAME_SIZE+1]="";
33 char _meshname [MED_NAME_SIZE+1]="";
34 char _dtunit [MED_SNAME_SIZE+1]="";
35 char *comp= NULL, *unit= NULL;
36 med_int ncomp,ncha;
37 med_int _ncstp=0;
38 med_bool _local=MED_FALSE;
39 htri_t _datasetexist;
40 char _pathi[(MED_FIELD_GRP_SIZE+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1 ] = MED_FIELD_GRP;
41 char _pathf[(MED_FIELD_GRP_SIZE+1+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = "/CHA_/";
42 char _pathtmp[MED_FIELD_GRP_SIZE+3]="/CHA__/";
43 int i=0,_num=0;
44 med_size _sizei=0,_sizef=0;
45 char _cstpname[2*MED_MAX_PARA+1]="";
46
47 MAJ_version_num(fid,3,0,8);
48
49 /* combien de champs dans le fichier */
50 ncha = MEDnField(fid);
51 EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL);
52
53 /* MAJ des champs */
54 for (i=0;i<ncha;i++) {
55
56 /* Lecture du nombre de composantes */
57 ncomp = MEDfieldnComponent(fid,i+1);
58 if (ncomp < 0) {
59 MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp);
60 exit(1);
61 }
62
63 /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/
64 comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
65 EXIT_IF(comp == NULL,NULL,NULL);
66 unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
67 EXIT_IF(unit == NULL,NULL,NULL);
68
69 ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp);
70 MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha);
71
72 /* Création du champ destination */
73 /* ATTENTION appel de MAJ_version avec fid,num
74 et non juste fid --> futures procédures de MAJ_310_... */
75 /* MAJ_version(fid); */
76 MAJ_version_num(fid,3,1,0);
77
78 EXIT_IF( H5Gmove(fid, _pathi, _pathtmp ) < 0,"Switch to ",_pathtmp);
79 /* Nous sommes dans une boucle sur les champs :
80 On récupère donc les champs en cours de transformation
81 */
82 _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
83 if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathi); }
84 /* Ajout du champ au nouveau format dans le _pathi */
85 MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0,
86 MED_ERR_CREATE,MED_ERR_FIELD,_pathf);
87
88 EXIT_IF( H5Gmove(fid, _pathi , _pathf ) < 0,"Switch to ",_pathf);
89 EXIT_IF( H5Gmove(fid, _pathtmp, _pathi ) < 0,"Switch to ",_pathi);
90
91 strncpy(&_pathi[MED_FIELD_GRP_SIZE] ,nomcha,MED_NAME_SIZE+1);
92 strncpy(&_pathf[MED_FIELD_GRP_SIZE+1],nomcha,MED_NAME_SIZE+1);
93 _sizei = MED_FIELD_GRP_SIZE+strlen(nomcha);
94 _sizef = _sizei+1;
95 _pathi[_sizei]='/';++_sizei;
96 _pathf[_sizef]='/';++_sizef;
97
98
99 for (_num=0; _num<_ncstp; ++_num) {
100
101 _pathi[_sizei]='\0';
102 _pathf[_sizef]='\0';
103 /* SSCRUTE(_pathi); */
104 /* SSCRUTE(_pathf); */
105
106 /*
107 * On recupere le nom de l'étape de calcul
108 */
109
110 /* Attention : On enlève les groupes DTIT au fur et à mesure,
111 il ne faut pas utiliser _num mais 0.
112 ret = _MEDobjectGetName(fid, _pathi ,_num, &_pathi[_sizei]) < 0;
113 */
114 ret = _MEDobjectGetName(fid, _pathi ,0, &_pathi[_sizei]) < 0;
115 MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathi);
116
117 strncpy(&_pathf[_sizef],&_pathi[_sizei],2*MED_MAX_PARA+1);
118
119 /* SSCRUTE(_pathi); */
120 /* SSCRUTE(_pathf); */
121 EXIT_IF( H5Lmove( fid, _pathi, fid, _pathf, H5P_DEFAULT, H5P_DEFAULT ) < 0, "Failed to move field ",_pathi);
122 }
123
124 _pathi[MED_FIELD_GRP_SIZE]='\0';
125 _pathf[MED_FIELD_GRP_SIZE+1]='\0';
126
127
128 MAJ_version_num(fid,3,0,8);
129
130 free(comp);
131 free(unit);
132
133 }
134
135 _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
136
137 if (_datasetexist ) {
138 EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
139 EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathf);
140 }
141
142 /* _MEDobjetsOuverts(fid); */
143
144 }