00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <med.h>
00020 #define MESGERR 1
00021 #include <med_utils.h>
00022 #include <string.h>
00023
00024 #ifdef DEF_LECT_ECR
00025 #define MODE_ACCES MED_ACC_RDWR
00026 #elif DEF_LECT_AJOUT
00027 #define MODE_ACCES MED_ACC_RDEXT
00028 #else
00029 #define MODE_ACCES MED_ACC_CREAT
00030 #endif
00031
00032 int main (int argc, char **argv)
00033
00034 {
00035 med_err _ret=0;
00036 med_idt _fid=0;
00037 int _i =0,_j=0,_k=0,_l=0,_n=0;
00038 med_int _nstructelement=0;
00039
00040 med_geometry_type _geotype=MED_NONE;
00041
00042 char _elementname[MED_NAME_SIZE+1]="";
00043 med_int _elementdim=0;
00044 char _supportmeshname[MED_NAME_SIZE+1]="";
00045 med_entity_type _entitytype=MED_UNDEF_ENTITY_TYPE;
00046 med_int _nnode=0;
00047 med_int _ncell=0;
00048 med_geometry_type _geocelltype=MED_NONE;
00049 med_int _nconstantattribute=0;
00050 med_bool _anyprofile=0;
00051 med_int _nvariableattribute=0;
00052
00053 char _constattname[MED_NAME_SIZE+1]="";
00054 med_attribute_type _constatttype=MED_ATT_UNDEF;
00055 med_int _ncomponent=0;
00056 med_entity_type _attentitytype=MED_UNDEF_ENTITY_TYPE;
00057 char _profilename[MED_NAME_SIZE+1]="";
00058 med_int _profilesize=0;
00059
00060 unsigned char * _value=NULL;
00061
00062
00063 _fid = MEDfileOpen("current.med",MED_ACC_RDONLY);
00064 if (_fid < 0) {
00065 MESSAGE("Erreur à la lecture du fichier current.med");
00066 return -1;
00067 }
00068
00069 if ( (_nstructelement = MEDnStructElement(_fid)) <0) _ret=_nstructelement;
00070
00071 for ( _i=1; _i<= _nstructelement; ++_i) {
00072
00073 if (MEDstructElementInfo(_fid,
00074 _i,
00075 _elementname,
00076 &_geotype,
00077 &_elementdim,
00078 _supportmeshname,
00079 &_entitytype,
00080 &_nnode,
00081 &_ncell,
00082 &_geocelltype,
00083 &_nconstantattribute,
00084 &_anyprofile,
00085 &_nvariableattribute
00086 ) ) return -1;
00087
00088 fprintf(stdout,"Elément de structure n° %d |%s| de type géométrique n° %d et de dimension %"IFORMAT"\n",
00089 _i,_elementname,_geotype,_elementdim);
00090 if ( strlen(_supportmeshname) ) {
00091 fprintf(stdout,"\t Maillage support de nom |%s|",_supportmeshname);
00092 if (_ncell)
00093 fprintf(stdout," avec %d maille(s) de type %d et ",_ncell,_geocelltype);
00094 if (_nnode)
00095 fprintf(stdout," avec %d noeud(s)\n",_nnode);
00096 else {
00097 fprintf(stderr,"\n Erreur : les noeuds doivent être définis s'il existe un maillage support\n");
00098 }
00099 } else
00100 fprintf(stdout,"\t Maillage support implicite sur noeud\n");
00101 fprintf(stdout,"\t Nombre d'attribut(s) constant(s) : %d",_nconstantattribute);
00102 if (_anyprofile) fprintf(stdout,", avec profil.\n"); else fprintf(stdout,", sans profil.\n");
00103 if ( _nconstantattribute ) {
00104 for (_j=1;_j<=_nconstantattribute;++_j) {
00105 if ( MEDstructElementConstAttInfo(_fid, _elementname,_j,
00106 _constattname, &_constatttype, &_ncomponent,
00107 &_attentitytype, _profilename, &_profilesize ) ) return -1;
00108
00109 fprintf(stdout,"\t\t Attribut constant de nom |%s| de type %d à "IFORMAT" composantes\n",
00110 _constattname,_constatttype,_ncomponent);
00111 fprintf(stdout,"\t\t Cet Attribut est attaché au type d'entité %d avec un profil |%s| de taille "IFORMAT"\n",
00112 _attentitytype,_profilename,_profilesize);
00113
00114 if (!_profilesize)
00115 if (_attentitytype == MED_NODE) _profilesize = _nnode; else _profilesize=_ncell;
00116 _n = _ncomponent*_profilesize;
00117 if ( _attentitytype == MED_ATT_NAME) ++_n;
00118 _value = (unsigned char *) malloc(_n*MEDstructElementAttSizeof(_constatttype));
00119 if ( _attentitytype == MED_ATT_NAME) --_n;
00120
00121
00122 if ( MEDstructElementConstAttRd(_fid, _elementname,_constattname, _value ) < 0 ) return -1;
00123
00124 fprintf(stdout,"\t\t Cet Attribut a pour valeurs : \n");
00125 for (_k=0; _k < _n; ++_k) {
00126 switch (_constatttype) {
00127 case MED_ATT_FLOAT64 :
00128 printf("%f ", ((med_float*)(_value))[ _k]) ;
00129 break;
00130
00131 case MED_ATT_INT :
00132 printf("%d ",((med_int*)(_value))[_k]);
00133 break;
00134
00135 case MED_ATT_NAME :
00136 for (_l=_k*MED_NAME_SIZE; _l < (_k+1)*MED_NAME_SIZE; ++_l) printf("%c",((char *)_value)[_l]);printf("\n");
00137 break;
00138 default:
00139 break;
00140 }
00141 }
00142 printf("\n");
00143 free(_value);
00144
00145 }
00146 }
00147 fprintf(stdout,"\t Nombre d'attributs variables : %d\n",_nvariableattribute);
00148
00149 }
00150
00151
00152 if (MEDfileClose(_fid) < 0) {
00153 MESSAGE("ERROR : file closing");
00154 return -1;
00155 }
00156
00157 return _ret;
00158
00159
00160 }
00161