| 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.h> |
| 20 |
#define MESGERR 1 |
| 21 |
#include <med_utils.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#ifdef DEF_LECT_ECR |
| 25 |
#define MODE_ACCES MED_ACC_RDWR |
| 26 |
#elif DEF_LECT_AJOUT |
| 27 |
#define MODE_ACCES MED_ACC_RDEXT |
| 28 |
#else |
| 29 |
#define MODE_ACCES MED_ACC_CREAT |
| 30 |
#endif |
| 31 |
|
| 32 |
int main (int argc, char **argv) |
| 33 |
|
| 34 |
{ |
| 35 |
med_err _ret=0; |
| 36 |
med_idt _fid=0; |
| 37 |
int _i =0,_j=0,_k=0,_l=0,_n=0; |
| 38 |
med_int _nstructelement=0; |
| 39 |
|
| 40 |
med_geometry_type _geotype=MED_NONE; |
| 41 |
|
| 42 |
char _elementname[MED_NAME_SIZE+1]=""; |
| 43 |
med_int _elementdim=0; |
| 44 |
char _supportmeshname[MED_NAME_SIZE+1]=""; |
| 45 |
med_entity_type _entitytype=MED_UNDEF_ENTITY_TYPE; |
| 46 |
med_int _nnode=0; |
| 47 |
med_int _ncell=0; |
| 48 |
med_geometry_type _geocelltype=MED_NONE; |
| 49 |
med_int _nconstantattribute=0; |
| 50 |
med_bool _anyprofile=0; |
| 51 |
med_int _nvariableattribute=0; |
| 52 |
|
| 53 |
char _constattname[MED_NAME_SIZE+1]=""; |
| 54 |
med_attribute_type _constatttype=MED_ATT_UNDEF; |
| 55 |
med_int _ncomponent=0; |
| 56 |
med_entity_type _attentitytype=MED_UNDEF_ENTITY_TYPE; |
| 57 |
char _profilename[MED_NAME_SIZE+1]=""; |
| 58 |
med_int _profilesize=0; |
| 59 |
|
| 60 |
unsigned char * _value=NULL; |
| 61 |
med_int _allocsize=0; |
| 62 |
|
| 63 |
/* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */ |
| 64 |
_fid = MEDfileOpen("current.med",MED_ACC_RDONLY); |
| 65 |
if (_fid < 0) { |
| 66 |
MESSAGE("Erreur à la lecture du fichier current.med"); |
| 67 |
return -1; |
| 68 |
} |
| 69 |
|
| 70 |
if ( (_nstructelement = MEDnStructElement(_fid)) <0) _ret=_nstructelement; |
| 71 |
|
| 72 |
for ( _i=1; _i<= _nstructelement; ++_i) { |
| 73 |
|
| 74 |
if (MEDstructElementInfo(_fid, |
| 75 |
_i, |
| 76 |
_elementname, |
| 77 |
&_geotype, |
| 78 |
&_elementdim, |
| 79 |
_supportmeshname, |
| 80 |
&_entitytype, |
| 81 |
&_nnode, |
| 82 |
&_ncell, |
| 83 |
&_geocelltype, |
| 84 |
&_nconstantattribute, |
| 85 |
&_anyprofile, |
| 86 |
&_nvariableattribute |
| 87 |
) ) return -1; |
| 88 |
|
| 89 |
fprintf(stdout,"Elément de structure n° %d |%s| de type géométrique n° %d et de dimension %"IFORMAT"\n", |
| 90 |
_i,_elementname,_geotype,_elementdim); |
| 91 |
|
| 92 |
if ( strlen(_supportmeshname) ) { |
| 93 |
fprintf(stdout,"\t Maillage support de nom |%s|",_supportmeshname); |
| 94 |
if (_ncell) fprintf(stdout," avec %d maille(s) de type %d et ",_ncell,_geocelltype); |
| 95 |
if (_nnode) fprintf(stdout," avec %d noeud(s)\n",_nnode); |
| 96 |
else { |
| 97 |
fprintf(stderr,"\n Erreur : les noeuds doivent être définis s'il existe un maillage support\n"); |
| 98 |
} |
| 99 |
} else |
| 100 |
fprintf(stdout,"\t Maillage support implicite sur noeud\n"); |
| 101 |
|
| 102 |
fprintf(stdout,"\t Nombre d'attribut(s) constant(s) : %d",_nconstantattribute); |
| 103 |
if (_anyprofile) fprintf(stdout,", avec profil.\n"); else fprintf(stdout,", sans profil.\n"); |
| 104 |
if ( _nconstantattribute ) { |
| 105 |
for (_j=1;_j<=_nconstantattribute;++_j) { |
| 106 |
if ( MEDstructElementConstAttInfo(_fid, _elementname,_j, |
| 107 |
_constattname, &_constatttype, &_ncomponent, |
| 108 |
&_attentitytype, _profilename, &_profilesize ) ) return -1; |
| 109 |
|
| 110 |
fprintf(stdout,"\t\t Attribut constant de nom |%s| de type %d à "IFORMAT" composantes\n", |
| 111 |
_constattname,_constatttype,_ncomponent); |
| 112 |
fprintf(stdout,"\t\t Cet Attribut est attaché au type d'entité %d avec un profil |%s| de taille "IFORMAT"\n", |
| 113 |
_attentitytype,_profilename,_profilesize); |
| 114 |
|
| 115 |
/*Il serait pratique que profilesize renvoie les valeurs suivantes (avec un _profilename=MED_NO_PROFILE) :*/ |
| 116 |
if (!_profilesize) |
| 117 |
if (_attentitytype == MED_NODE) _profilesize = _nnode; else _profilesize=_ncell; |
| 118 |
_n = _ncomponent*_profilesize; |
| 119 |
|
| 120 |
_allocsize =_n*MEDstructElementAttSizeof(_constatttype); |
| 121 |
if ( _constatttype == MED_ATT_NAME) ++_allocsize; |
| 122 |
_value = (unsigned char *) malloc(_allocsize); |
| 123 |
|
| 124 |
/* ISCRUTE(_ncomponent);ISCRUTE(_profilesize);ISCRUTE(MEDstructElementAttSizeof(_constatttype)); */ |
| 125 |
if ( MEDstructElementConstAttRd(_fid, _elementname,_constattname, _value ) < 0 ) return -1; |
| 126 |
|
| 127 |
fprintf(stdout,"\t\t Cet Attribut a pour valeurs : \n"); |
| 128 |
for (_k=0; _k < _n; ++_k) { |
| 129 |
switch (_constatttype) { |
| 130 |
case MED_ATT_FLOAT64 : printf("%f ", ((med_float*)(_value))[ _k]) ; |
| 131 |
break; |
| 132 |
|
| 133 |
case MED_ATT_INT : printf("%d ",((med_int*)(_value))[_k]); |
| 134 |
break; |
| 135 |
|
| 136 |
case MED_ATT_NAME : for (_l=_k*MED_NAME_SIZE; _l < (_k+1)*MED_NAME_SIZE; ++_l) |
| 137 |
printf("%c",((char *)_value)[_l]);printf("\n"); |
| 138 |
break; |
| 139 |
default: |
| 140 |
break; |
| 141 |
} |
| 142 |
} |
| 143 |
printf("\n"); |
| 144 |
free(_value); |
| 145 |
} |
| 146 |
} |
| 147 |
fprintf(stdout,"\t Nombre d'attributs variables : %d\n",_nvariableattribute); |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
if (MEDfileClose(_fid) < 0) { |
| 153 |
MESSAGE("ERROR : file closing"); |
| 154 |
return -1; |
| 155 |
} |
| 156 |
|
| 157 |
return _ret; |
| 158 |
|
| 159 |
|
| 160 |
} |
| 161 |
|