| 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_400_410.h" |
| 26 |
#include "MAJ_version.h" |
| 27 |
|
| 28 |
#define USER_MODE MED_COMPACT_STMODE |
| 29 |
|
| 30 |
#include "_MEDfieldValueUpdateEntityList41.c" |
| 31 |
|
| 32 |
med_err getFieldsOn40(med_idt fid, |
| 33 |
const char * const nommaa, |
| 34 |
med_int nmodels, |
| 35 |
const med_geometry_type* geotype_elst, |
| 36 |
const char * geotypename_elst, |
| 37 |
const char * const nomcha, |
| 38 |
const char * const dtunit, |
| 39 |
const med_field_type typcha, |
| 40 |
const med_int ncomp, |
| 41 |
const char * const comp, |
| 42 |
const char * const unit, |
| 43 |
const med_entity_type entite, |
| 44 |
const med_switch_mode stockage, |
| 45 |
const med_int ncstp) { |
| 46 |
|
| 47 |
int i,j,k,l,m,n,nb_geo=0; |
| 48 |
med_int nbpdtnor=0,pflsize,*pflval,ngauss=0,ngroup,nval; |
| 49 |
med_int numdt=0,numo=0,nprofile=0; |
| 50 |
med_int meshnumdt=0, meshnumit=0 ; |
| 51 |
med_size medtype_size=0; |
| 52 |
med_size _sizei=0,_sizef=0,_sizeNbr=0; |
| 53 |
med_float dt=0.0; |
| 54 |
unsigned char *val = NULL; |
| 55 |
med_err ret=0; |
| 56 |
char pflname [MED_NAME_SIZE+1]=""; |
| 57 |
char _profilename [MED_NAME_SIZE+1]=""; |
| 58 |
char locname [MED_NAME_SIZE+1]=""; |
| 59 |
char _pathi[(MED_FIELD_GRP_SIZE +MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = MED_FIELD_GRP; |
| 60 |
char _pathf[(MED_FIELD_GRP_SIZE+1+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = "/CHA_/"; |
| 61 |
char _pathtmp[MED_FIELD_GRP_SIZE+3]="/CHA__/"; |
| 62 |
char _getNBR[(MED_FIELD_GRP_SIZE+1+MED_NAME_SIZE+1)+(2*MED_MAX_PARA+1)+(2*MED_TAILLE_NOM_ENTITE+2)+(MED_NAME_SIZE+1)+MED_TAILLE_NOM_ENTITE+1] = MED_FIELD_GRP; |
| 63 |
char _entitygeotypename[2*MED_TAILLE_NOM_ENTITE+2]=""; |
| 64 |
char * lien = NULL; |
| 65 |
med_bool _fieldexist = MED_FALSE; |
| 66 |
med_bool _meshexist = MED_FALSE; |
| 67 |
med_int _nentFromMesh = 0; |
| 68 |
med_int _nentFromField = 0; |
| 69 |
med_int _nent = 0; |
| 70 |
med_geometry_type *type_geo; |
| 71 |
med_data_type meddatatype = MED_CONNECTIVITY; |
| 72 |
med_bool changement = MED_FALSE; |
| 73 |
med_bool transformation = MED_FALSE; |
| 74 |
htri_t _datasetexist; |
| 75 |
|
| 76 |
char _gidname [MED_FIELD_GRP_SIZE+MED_NAME_SIZE+1]=MED_FIELD_GRP; |
| 77 |
char _datagroupname1 [2*MED_MAX_PARA+1]=""; |
| 78 |
med_idt _gid=0,_datagroup1 =0; |
| 79 |
|
| 80 |
const char * const * AFF; |
| 81 |
const char * const * AFF_ENT=MED_GET_ENTITY_TYPENAME+1; |
| 82 |
const char * * AFF_STRUCT = NULL; |
| 83 |
|
| 84 |
switch (entite) { |
| 85 |
case MED_NODE : |
| 86 |
type_geo = MED_GET_NODE_GEOMETRY_TYPE; |
| 87 |
nb_geo = MED_N_NODE_FIXED_GEO; |
| 88 |
AFF = MED_GET_NODE_GEOMETRY_TYPENAME; |
| 89 |
meddatatype = MED_COORDINATE; |
| 90 |
break; |
| 91 |
case MED_CELL : |
| 92 |
case MED_NODE_ELEMENT : |
| 93 |
type_geo = MED_GET_CELL_GEOMETRY_TYPE; |
| 94 |
nb_geo = MED_N_CELL_FIXED_GEO; |
| 95 |
AFF = MED_GET_CELL_GEOMETRY_TYPENAME; |
| 96 |
break; |
| 97 |
case MED_DESCENDING_FACE : |
| 98 |
type_geo = MED_GET_FACE_GEOMETRY_TYPE; |
| 99 |
nb_geo = MED_N_FACE_FIXED_GEO; |
| 100 |
AFF = MED_GET_FACE_GEOMETRY_TYPENAME; |
| 101 |
break; |
| 102 |
case MED_DESCENDING_EDGE : |
| 103 |
type_geo = MED_GET_EDGE_GEOMETRY_TYPE; |
| 104 |
nb_geo = MED_N_EDGE_FIXED_GEO; |
| 105 |
AFF = MED_GET_EDGE_GEOMETRY_TYPENAME; |
| 106 |
break; |
| 107 |
case MED_STRUCT_ELEMENT : |
| 108 |
AFF_STRUCT = (const char * *) calloc(sizeof(const char * ),nmodels+1); |
| 109 |
for(i=0;i<nmodels;++i) AFF_STRUCT[i+1]= &geotypename_elst[(MED_NAME_SIZE+1)*i]; |
| 110 |
type_geo = (med_geometry_type*)(geotype_elst)-1; |
| 111 |
nb_geo = nmodels; |
| 112 |
AFF = AFF_STRUCT; |
| 113 |
break; |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
strcat(_gidname,nomcha); |
| 118 |
MED_ERR_EXIT_IF((_gid = _MEDdatagroupOuvrir(fid,_gidname)) < 0, MED_ERR_OPEN, MED_ERR_DATAGROUP,nomcha); |
| 119 |
|
| 120 |
for (k=1;k<=nb_geo;k++) { |
| 121 |
|
| 122 |
/* Combien de séquences (PDT,NOR) a lire */ |
| 123 |
nbpdtnor = ncstp; |
| 124 |
if (nbpdtnor < 1 ) continue; |
| 125 |
|
| 126 |
for (j=0;j<nbpdtnor;j++) { |
| 127 |
|
| 128 |
if ( MEDfieldComputingStepMeshInfo(fid, nomcha, j+1, &numdt, &numo, |
| 129 |
&dt, &meshnumdt, &meshnumit) < 0 ) { |
| 130 |
MESSAGE("Erreur a l'appel de MEDfieldComputingStepMeshInfo : "); |
| 131 |
EXIT_IF(NULL == NULL,NULL,NULL); |
| 132 |
} |
| 133 |
|
| 134 |
_datagroup1 = 0; |
| 135 |
_MEDgetComputationStepName(MED_SORT_DTIT,numdt,numo,_datagroupname1); |
| 136 |
MED_ERR_EXIT_IF(( _datagroup1 = _MEDdatagroupOuvrir(_gid,_datagroupname1)) < 0, MED_ERR_OPEN,MED_ERR_DATAGROUP,_datagroupname1); |
| 137 |
|
| 138 |
|
| 139 |
/* printf("\n +Pas de Temps n."IFORMAT" (%f) [%s], n. d'ordre "IFORMAT", avec "IFORMAT" valeur(s) par entité.\n",numdt,dt,dtunit,numo,ngauss); */ |
| 140 |
/* printf("\t- Il y a "IFORMAT" entités qui portent des valeurs en mode %i. Chaque entite %s\ */ |
| 141 |
/* de type geometrique %s associes au profile |%s| a "IFORMAT" valeurs associées \n", */ |
| 142 |
/* nval,USER_MODE,AFF_ENT[(int)entite],AFF[k],pflname,ngauss); */ |
| 143 |
|
| 144 |
/*Ajout des méta-data au champ */ |
| 145 |
|
| 146 |
/*Mise à jour de la liste des types d'entités au niveau des deux groupes _gid et _datagroup1 */ |
| 147 |
MED_ERR_EXIT_IF(( _MEDfieldValueUpdateEntityList(nomcha,_datagroupname1,_gid,_datagroup1,entite,type_geo[k] ,1)) < 0 , |
| 148 |
MED_ERR_WRITE,MED_ERR_FIELD,nomcha); |
| 149 |
/*Mise à jour de la liste des types géométriques pour le type d'entité <entitype> au niveau _gid et _datagroup1 */ |
| 150 |
MED_ERR_EXIT_IF(( _MEDfieldValueUpdateEntityList(nomcha,_datagroupname1,_gid,_datagroup1,entite,type_geo[k] ,0)) < 0 , |
| 151 |
MED_ERR_WRITE,MED_ERR_FIELD,nomcha); |
| 152 |
|
| 153 |
/* fprintf(stdout," ... Ajout des meta-données du champ effectuée...\n"); */ |
| 154 |
|
| 155 |
if (_datagroup1>0) ret= (_MEDdatagroupFermer(_datagroup1) < 0); |
| 156 |
MED_ERR_EXIT_IF(ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1); |
| 157 |
|
| 158 |
|
| 159 |
} /* fin for sur les étapes de calcul */ |
| 160 |
|
| 161 |
|
| 162 |
} /* fin for sur les types géométriques de maille */ |
| 163 |
|
| 164 |
if (_gid>0) ret= (_MEDdatagroupFermer(_gid) < 0); |
| 165 |
MED_ERR_EXIT_IF(ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_gidname); |
| 166 |
|
| 167 |
|
| 168 |
free(AFF_STRUCT); |
| 169 |
return ret; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
void MAJ_400_410_champs(med_idt fid) |
| 175 |
{ |
| 176 |
med_err ret=0,lret=0; |
| 177 |
med_field_type typcha; |
| 178 |
char nomcha [MED_NAME_SIZE+1]=""; |
| 179 |
char meshname [MED_NAME_SIZE+1]=""; |
| 180 |
char dtunit [MED_SNAME_SIZE+1]=""; |
| 181 |
char *comp= NULL, *unit= NULL; |
| 182 |
med_int ncomp,ncha; |
| 183 |
med_int ncstp=0; |
| 184 |
med_bool local=MED_FALSE; |
| 185 |
htri_t _datasetexist; |
| 186 |
char _pathi[(MED_FIELD_GRP_SIZE +MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = MED_FIELD_GRP; |
| 187 |
char _pathf[(MED_FIELD_GRP_SIZE+1+MED_NAME_SIZE+1)+2*MED_MAX_PARA+1] = "/CHA_/"; |
| 188 |
char _pathtmp[MED_FIELD_GRP_SIZE+3]="/CHA__/"; |
| 189 |
int i=0,_num=0; |
| 190 |
/* char _cstpname[2*MED_MAX_PARA+1]=""; */ |
| 191 |
med_int _nmodels=0; |
| 192 |
med_switch_mode mode_coo = MED_NO_INTERLACE; |
| 193 |
|
| 194 |
med_geometry_type * geotype_elst; |
| 195 |
char * geotypename_elst; |
| 196 |
|
| 197 |
med_geometry_type _geotype=MED_NONE; |
| 198 |
char _elementname[MED_NAME_SIZE+1]=""; |
| 199 |
med_int _elementdim=0; |
| 200 |
char _supportmeshname[MED_NAME_SIZE+1]=""; |
| 201 |
med_entity_type _entitytype=MED_UNDEF_ENTITY_TYPE; |
| 202 |
med_int _nnode=0; |
| 203 |
med_int _ncell=0; |
| 204 |
med_geometry_type _geocelltype=MED_NONE; |
| 205 |
char _geocelltypename[MED_SNAME_SIZE+1]=""; |
| 206 |
med_int _nconstantattribute=0; |
| 207 |
med_bool _anyprofile=MED_FALSE; |
| 208 |
med_int _nvariableattribute=0; |
| 209 |
|
| 210 |
MAJ_version_num(fid,4,0,0); |
| 211 |
|
| 212 |
_nmodels = MEDnStructElement(fid); |
| 213 |
EXIT_IF(_nmodels < 0,"lors de la lecture du nombre d'éléments de structure",NULL); |
| 214 |
|
| 215 |
/* nmailles_elst = (med_int *) malloc(_nmodels*sizeof(med_int)); */ |
| 216 |
geotype_elst = (med_geometry_type *) malloc(_nmodels*sizeof(med_geometry_type)); |
| 217 |
geotypename_elst = (char *) malloc(_nmodels*sizeof(char)*(MED_NAME_SIZE+1)); |
| 218 |
|
| 219 |
for (i=0; i < _nmodels; i++) { |
| 220 |
ret= MEDstructElementInfo(fid, i+1, &geotypename_elst[i*(MED_NAME_SIZE+1)], &geotype_elst[i], |
| 221 |
&_elementdim, _supportmeshname, |
| 222 |
&_entitytype, &_nnode, &_ncell, &_geocelltype, |
| 223 |
&_nconstantattribute, &_anyprofile, &_nvariableattribute ); |
| 224 |
EXIT_IF(ret < 0,"lors de la demande d'information sur les éléments de structure",NULL); |
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
/* combien de champs dans le fichier */ |
| 229 |
ncha = MEDnField(fid); |
| 230 |
EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL); |
| 231 |
|
| 232 |
/* MAJ des champs */ |
| 233 |
for (i=0;i<ncha;i++) { |
| 234 |
|
| 235 |
/* Lecture du nombre de composantes */ |
| 236 |
ncomp = MEDfieldnComponent(fid,i+1); |
| 237 |
if (ncomp < 0) { |
| 238 |
MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp); |
| 239 |
exit(1); |
| 240 |
} |
| 241 |
|
| 242 |
/* Lecture du type du champ, des noms des composantes et du nom de l'unité*/ |
| 243 |
comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1); |
| 244 |
EXIT_IF(comp == NULL,NULL,NULL); |
| 245 |
unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1); |
| 246 |
EXIT_IF(unit == NULL,NULL,NULL); |
| 247 |
|
| 248 |
ret = MEDfieldInfo(fid,i+1,nomcha,meshname,&local,&typcha,comp,unit,dtunit,&ncstp); |
| 249 |
MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha); |
| 250 |
|
| 251 |
fprintf(stdout," >>> Normalisation du champ [%s] \n",nomcha); |
| 252 |
|
| 253 |
/* champs aux noeuds */ |
| 254 |
lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst,geotypename_elst, |
| 255 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_NODE, mode_coo, ncstp); |
| 256 |
|
| 257 |
/* champs sur les elements et aux points de Gauss */ |
| 258 |
if (lret == 0) lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst, geotypename_elst, |
| 259 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_CELL, mode_coo, ncstp); |
| 260 |
else { MESSAGE("Erreur à la lecture des champs aux noeuds "); ret = -1; continue;} |
| 261 |
|
| 262 |
if (lret == 0) lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst, geotypename_elst, |
| 263 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_DESCENDING_FACE, mode_coo, ncstp); |
| 264 |
else { MESSAGE("Erreur à la lecture des champs aux mailles "); ret = -1; continue;} |
| 265 |
|
| 266 |
if (lret == 0) lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst, geotypename_elst, |
| 267 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_DESCENDING_EDGE, mode_coo, ncstp); |
| 268 |
else {MESSAGE("Erreur à la lecture des champs aux faces "); ret = -1; continue;} |
| 269 |
|
| 270 |
if (lret == 0) lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst, geotypename_elst, |
| 271 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_NODE_ELEMENT,mode_coo, ncstp); |
| 272 |
else {MESSAGE("Erreur a la lecture des champs aux aretes "); ret = -1; continue;} |
| 273 |
|
| 274 |
if (lret != 0) {MESSAGE("Erreur a la lecture des champs aux noeuds des mailles "); ret = -1;}; |
| 275 |
|
| 276 |
if (_nmodels) |
| 277 |
lret = getFieldsOn40(fid, meshname, _nmodels, geotype_elst,geotypename_elst, |
| 278 |
nomcha, dtunit, typcha, ncomp, comp, unit, MED_STRUCT_ELEMENT,mode_coo, ncstp); |
| 279 |
if (lret != 0) {MESSAGE("Erreur a la lecture des champs aux éléments de sructure "); ret = -1;}; |
| 280 |
|
| 281 |
|
| 282 |
fprintf(stdout," >>> Normalisation du champ [%s] : ... OK ... \n",nomcha); |
| 283 |
|
| 284 |
|
| 285 |
CONT: |
| 286 |
|
| 287 |
free(comp); |
| 288 |
free(unit); |
| 289 |
/* MAJ_version_num(fid,4,0,0); */ |
| 290 |
} |
| 291 |
|
| 292 |
free(geotype_elst); |
| 293 |
free(geotypename_elst); |
| 294 |
|
| 295 |
/* _MEDobjetsOuverts(fid); */ |
| 296 |
|
| 297 |
} |
| 298 |
|