Test_MEDstructElementConstAttRd.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
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   med_int            _allocsize=0;
00062 
00063   /* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */
00064   _fid = MEDfileOpen("current.med",MED_ACC_RDONLY);
00065   if (_fid < 0) {
00066     MESSAGE("Erreur à la lecture du fichier current.med");
00067     return -1;
00068   }
00069 
00070   if ( (_nstructelement = MEDnStructElement(_fid)) <0) _ret=_nstructelement;
00071 
00072   for ( _i=1; _i<= _nstructelement; ++_i) {
00073 
00074     if (MEDstructElementInfo(_fid,
00075                              _i,
00076                              _elementname,
00077                              &_geotype,
00078                              &_elementdim,
00079                              _supportmeshname,
00080                              &_entitytype,
00081                              &_nnode,
00082                              &_ncell,
00083                              &_geocelltype,
00084                              &_nconstantattribute,
00085                              &_anyprofile,
00086                              &_nvariableattribute
00087                              ) ) return -1;
00088 
00089     fprintf(stdout,"Elément de structure n° %d |%s| de type géométrique n° %d et de dimension %"IFORMAT"\n",
00090             _i,_elementname,_geotype,_elementdim);
00091 
00092     if ( strlen(_supportmeshname) ) {
00093                    fprintf(stdout,"\t Maillage support de nom |%s|",_supportmeshname);
00094       if (_ncell)  fprintf(stdout," avec %d maille(s) de type %d et ",_ncell,_geocelltype);
00095       if (_nnode)  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 
00102     fprintf(stdout,"\t Nombre d'attribut(s) constant(s) : %d",_nconstantattribute);
00103     if (_anyprofile) fprintf(stdout,", avec profil.\n"); else fprintf(stdout,", sans profil.\n");
00104     if ( _nconstantattribute ) {
00105       for (_j=1;_j<=_nconstantattribute;++_j) {
00106         if ( MEDstructElementConstAttInfo(_fid, _elementname,_j,
00107                                           _constattname, &_constatttype, &_ncomponent,
00108                                           &_attentitytype, _profilename, &_profilesize ) ) return -1;
00109 
00110         fprintf(stdout,"\t\t Attribut constant de nom |%s| de type %d à "IFORMAT" composantes\n",
00111                 _constattname,_constatttype,_ncomponent);
00112         fprintf(stdout,"\t\t  Cet Attribut est attaché au type d'entité  %d avec un profil |%s| de taille "IFORMAT"\n",
00113                 _attentitytype,_profilename,_profilesize);
00114 
00115         /*Il serait pratique que profilesize renvoie les valeurs suivantes (avec un _profilename=MED_NO_PROFILE) :*/
00116         if (!_profilesize)
00117           if (_attentitytype == MED_NODE) _profilesize = _nnode; else _profilesize=_ncell;
00118         _n     = _ncomponent*_profilesize;
00119 
00120         _allocsize =_n*MEDstructElementAttSizeof(_constatttype);
00121         if ( _constatttype == MED_ATT_NAME) ++_allocsize;
00122         _value = (unsigned char *) malloc(_allocsize);
00123 
00124         /* ISCRUTE(_ncomponent);ISCRUTE(_profilesize);ISCRUTE(MEDstructElementAttSizeof(_constatttype)); */
00125         if ( MEDstructElementConstAttRd(_fid, _elementname,_constattname, _value ) < 0 ) return -1;
00126 
00127         fprintf(stdout,"\t\t  Cet Attribut a pour valeurs : \n");
00128         for (_k=0; _k < _n; ++_k) {
00129           switch (_constatttype) {
00130           case  MED_ATT_FLOAT64 :    printf("%f ", ((med_float*)(_value))[ _k]) ;
00131             break;
00132             
00133           case MED_ATT_INT :         printf("%d ",((med_int*)(_value))[_k]);
00134             break;
00135             
00136           case MED_ATT_NAME :       for (_l=_k*MED_NAME_SIZE; _l < (_k+1)*MED_NAME_SIZE; ++_l) 
00137                                      printf("%c",((char *)_value)[_l]);printf("\n");
00138             break;
00139           default:
00140             break;
00141           }
00142         }
00143         printf("\n");
00144         free(_value);
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 

Généré le Thu Oct 8 14:26:17 2015 pour MED fichier par  doxygen 1.6.1