Test_MEDstructElementConstAttRd.c
Aller à la documentation de ce fichier.
/* This file is part of MED.
*
* COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
* MED is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MED is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MED. If not, see <http://www.gnu.org/licenses/>.
*/
#include <med.h>
#define MESGERR 1
#include <med_utils.h>
#include <string.h>
#ifdef DEF_LECT_ECR
#define MODE_ACCES MED_ACC_RDWR
#elif DEF_LECT_AJOUT
#define MODE_ACCES MED_ACC_RDEXT
#else
#define MODE_ACCES MED_ACC_CREAT
#endif
int main (int argc, char **argv)
{
med_err _ret=0;
med_idt _fid=0;
int _i =0,_j=0,_k=0,_l=0,_n=0;
med_int _nstructelement=0;
med_geometry_type _geotype=MED_NONE;
char _elementname[MED_NAME_SIZE+1]="";
med_int _elementdim=0;
char _supportmeshname[MED_NAME_SIZE+1]="";
med_entity_type _entitytype=MED_UNDEF_ENTITY_TYPE;
med_int _nnode=0;
med_int _ncell=0;
med_geometry_type _geocelltype=MED_NONE;
med_int _nconstantattribute=0;
med_bool _anyprofile=0;
med_int _nvariableattribute=0;
char _constattname[MED_NAME_SIZE+1]="";
med_attribute_type _constatttype=MED_ATT_UNDEF;
med_int _ncomponent=0;
med_entity_type _attentitytype=MED_UNDEF_ENTITY_TYPE;
char _profilename[MED_NAME_SIZE+1]="";
med_int _profilesize=0;
unsigned char * _value=NULL;
med_int _allocsize=0;
/* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */
_fid = MEDfileOpen("current.med",MED_ACC_RDONLY);
if (_fid < 0) {
MESSAGE("Erreur à la lecture du fichier current.med");
return -1;
}
if ( (_nstructelement = MEDnStructElement(_fid)) <0) _ret=_nstructelement;
for ( _i=1; _i<= _nstructelement; ++_i) {
if (MEDstructElementInfo(_fid,
_i,
_elementname,
&_geotype,
&_elementdim,
_supportmeshname,
&_entitytype,
&_nnode,
&_ncell,
&_geocelltype,
&_nconstantattribute,
&_anyprofile,
&_nvariableattribute
) ) return -1;
fprintf(stdout,"Elément de structure n° %d |%s| de type géométrique n° %d et de dimension %"IFORMAT"\n",
_i,_elementname,_geotype,_elementdim);
if ( strlen(_supportmeshname) ) {
fprintf(stdout,"\t Maillage support de nom |%s|",_supportmeshname);
if (_ncell) fprintf(stdout," avec %d maille(s) de type %d et ",_ncell,_geocelltype);
if (_nnode) fprintf(stdout," avec %d noeud(s)\n",_nnode);
else {
fprintf(stderr,"\n Erreur : les noeuds doivent être définis s'il existe un maillage support\n");
}
} else
fprintf(stdout,"\t Maillage support implicite sur noeud\n");
fprintf(stdout,"\t Nombre d'attribut(s) constant(s) : %d",_nconstantattribute);
if (_anyprofile) fprintf(stdout,", avec profil.\n"); else fprintf(stdout,", sans profil.\n");
if ( _nconstantattribute ) {
for (_j=1;_j<=_nconstantattribute;++_j) {
if ( MEDstructElementConstAttInfo(_fid, _elementname,_j,
_constattname, &_constatttype, &_ncomponent,
&_attentitytype, _profilename, &_profilesize ) ) return -1;
fprintf(stdout,"\t\t Attribut constant de nom |%s| de type %d à "IFORMAT" composantes\n",
_constattname,_constatttype,_ncomponent);
fprintf(stdout,"\t\t Cet Attribut est attaché au type d'entité %d avec un profil |%s| de taille "IFORMAT"\n",
_attentitytype,_profilename,_profilesize);
/*Il serait pratique que profilesize renvoie les valeurs suivantes (avec un _profilename=MED_NO_PROFILE) :*/
if (!_profilesize)
if (_attentitytype == MED_NODE) _profilesize = _nnode; else _profilesize=_ncell;
_n = _ncomponent*_profilesize;
_allocsize =_n*MEDstructElementAttSizeof(_constatttype);
if ( _constatttype == MED_ATT_NAME) ++_allocsize;
_value = (unsigned char *) malloc(_allocsize);
/* ISCRUTE(_ncomponent);ISCRUTE(_profilesize);ISCRUTE(MEDstructElementAttSizeof(_constatttype)); */
if ( MEDstructElementConstAttRd(_fid, _elementname,_constattname, _value ) < 0 ) return -1;
fprintf(stdout,"\t\t Cet Attribut a pour valeurs : \n");
for (_k=0; _k < _n; ++_k) {
switch (_constatttype) {
case MED_ATT_FLOAT64 : printf("%f ", ((med_float*)(_value))[ _k]) ;
break;
case MED_ATT_INT : printf("%d ",((med_int*)(_value))[_k]);
break;
case MED_ATT_NAME : for (_l=_k*MED_NAME_SIZE; _l < (_k+1)*MED_NAME_SIZE; ++_l)
printf("%c",((char *)_value)[_l]);printf("\n");
break;
default:
break;
}
}
printf("\n");
free(_value);
}
}
fprintf(stdout,"\t Nombre d'attributs variables : %d\n",_nvariableattribute);
}
if (MEDfileClose(_fid) < 0) {
MESSAGE("ERROR : file closing");
return -1;
}
return _ret;
}
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
med_geometry_type
int med_geometry_type
Definition: med.h:194
med_idt
hid_t med_idt
Definition: med.h:331
MED_ACC_RDONLY
Definition: med.h:120
med_err
herr_t med_err
Definition: med.h:332
med_entity_type
med_entity_type
Definition: med.h:143
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
MED_ATT_FLOAT64
Definition: med.h:173
med_int
int med_int
Definition: med.h:342
med_attribute_type
med_attribute_type
Definition: med.h:173
med.h
med_bool
med_bool
Definition: med.h:260
med_float
double med_float
Definition: med.h:336
IFORMAT
#define IFORMAT
Definition: med_utils.h:145
MED_NONE
#define MED_NONE
Definition: med.h:231
MED_NODE
Definition: med.h:143
MEDstructElementConstAttRd
MEDC_EXPORT med_err MEDstructElementConstAttRd(const med_idt fid, const char *const modelname, const char *const constattname, void *const value)
Cette routine lit la valeur d'un attribut caractéristique constant d'un modèle d'éléments de structur...
Definition: MEDstructElementConstAttRd.c:42
MEDnStructElement
MEDC_EXPORT med_int MEDnStructElement(const med_idt fid)
Cette routine renvoie le nombre de modèles d'éléments de structure.
Definition: MEDnStructElement.c:35
MED_ATT_NAME
Definition: med.h:175
main
int main(int argc, char **argv)
Definition: Test_MEDstructElementConstAttRd.c:32
MED_ATT_INT
Definition: med.h:174
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_UNDEF_ENTITY_TYPE
Definition: med.h:145
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MEDstructElementConstAttInfo
MEDC_EXPORT med_err MEDstructElementConstAttInfo(const med_idt fid, const char *const modelname, const int attit, char *const constattname, med_attribute_type *const constatttype, med_int *const ncomponent, med_entity_type *const sentitytype, char *const profilename, med_int *const profilesize)
Cette routine décrit les caractéristiques d'un attribut constant de modèle d'élément de structure par...
Definition: MEDstructElementConstAttInfo.c:45
MEDstructElementInfo
MEDC_EXPORT med_err MEDstructElementInfo(const med_idt fid, const int mit, char *const modelname, med_geometry_type *const mgeotype, med_int *const modeldim, char *const supportmeshname, med_entity_type *const sentitytype, med_int *const snnode, med_int *const sncell, med_geometry_type *const sgeotype, med_int *const nconstantattribute, med_bool *const anyprofile, med_int *const nvariableattribute)
Cette routine décrit les caractéristiques d'un modèle d'élément de structure par itération.
Definition: MEDstructElementInfo.c:50
MED_ATT_UNDEF
Definition: med.h:176
MEDstructElementAttSizeof
MEDC_EXPORT int MEDstructElementAttSizeof(const med_attribute_type atttype)
Cette routine renvoie la taille en octets du type élémentaire atttype.
Definition: MEDstructElementAttSizeof.c:36
med_utils.h