# MEDstructElementConstAttRd.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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 #include <med_config.h>
    00021 #include <med_outils.h>
    00022
    00023 #include <string.h>
    00024 #include <stdlib.h>
    00025
    00041 med_err
    00042 MEDstructElementConstAttRd(
    00043                            const med_idt                  fid,
    00044                            const char*              const modelname,
    00045                            const char*              const constattname,
    00046                            void*              const value
    00047                            )
    00048 {
    00049   med_err            _ret=-1;
    00050   med_idt            _attid=0, _elemid=0 ;
    00051   char               _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1+MED_TAILLE_CSTATR+MED_NAME_SIZE+1]=MED_STRCT;
    00052   med_int            _intentitytype = 0;
    00053   med_int            _nentity       = 0;
    00054   med_attribute_type _constatttype  = MED_ATT_UNDEF;
    00055   med_int            _nbofcomponent = 0;
    00056   med_entity_type    _entitytype    = MED_UNDEF_ENTITY_TYPE;
    00057   char               _supportmeshname[MED_NAME_SIZE+1]="";
    00058   char               _profilename    [MED_NAME_SIZE+1]="";
    00059   med_int            _profilesize   = 0;
    00060   med_filter         _filter        = MED_FILTER_INIT;
    00061   med_int            _medintsgeotype      = MED_NONE;
    00062   med_bool           _chgt=MED_FALSE,_trsf=MED_FALSE;
    00063
    00064   NOFINALBLANK(modelname,ERROR);
    00065   NOFINALBLANK(constattname,ERROR);
    00066
    00067   strcat(_path,modelname);
    00068
    00069
    00070   /*
    00071    * Si le DataGroup /STRUCT/<modelname> n'existe pas => erreur
    00072    */
    00073   if ((_elemid = _MEDdatagroupOpen(fid,_path)) < 0)  {
    00074     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
    00075     goto ERROR;
    00076   }
    00077
    00078   strcat(_path,MED_CSTATR);
    00079   strcat(_path,constattname);
    00080
    00081   /*
    00082    * Si le DataGroup /STRUCT/<modelname>/CSTATT/<constattributename> n'existe pas => erreur
    00083    */
    00084   if ((_attid = _MEDdatagroupOpen(fid,_path)) < 0)  {
    00085     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
    00086     goto ERROR;
    00087   }
    00088
    00089
    00090   /*
    00091    * Lecture de l'attribut MED_NOM_NOM (nom du maillage support)
    00092    */
    00093   /* Chercher plutôt ds le maillage support et supprimer les attributs NBM et NBN */
    00094   if ( _MEDattrStringLire(_elemid,MED_NOM_NOM,MED_NAME_SIZE,_supportmeshname) < 0) {
    00095     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
    00096     SSCRUTE(MED_NOM_NOM);SSCRUTE(_supportmeshname);
    00097     goto ERROR;
    00098   }
    00099
    00100   if (
    00101       MEDstructElementConstAttInfoByName(fid,
    00102                                          modelname,
    00103                                          constattname,
    00104                                          &_constatttype,
    00105                                          &_nbofcomponent,
    00106                                          &_entitytype,
    00107                                          _profilename,
    00108                                          &_profilesize
    00109                                          ) < 0 ) {
    00110     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,MED_ERR_STRUCT_MSG);
    00111     SSCRUTE(modelname);SSCRUTE(_path);SSCRUTE("MEDstructElementConstAttInfoByName");
    00112     goto ERROR;
    00113   }
    00114
    00115
    00116   if (strlen(_supportmeshname) ) {
    00117
    00118     if (_entitytype == MED_CELL )
    00119
    00120       /*
    00121        * Lecture de l'attribut MED_NOM_GEO (type géométrique des mailles support)
    00122        */
    00123       if ( _MEDattrEntierLire(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) {
    00124         MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
    00125         SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype);
    00126         goto ERROR;
    00127       }
    00128
    00129       if ( (_nentity = MEDmeshnEntity(fid,_supportmeshname,MED_NO_DT,MED_NO_IT,
    00130                                       MED_CELL,(med_geometry_type) _medintsgeotype,
    00131                                       MED_CONNECTIVITY,MED_NODAL,
    00132                                      &_chgt,&_trsf) )  < 0) {
    00133       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
    00134       ISCRUTE(_nentity);goto ERROR;
    00135     }
    00136
    00137     if (_entitytype == MED_NODE )
    00138       if ( (_nentity = MEDmeshnEntity(fid,_supportmeshname,MED_NO_DT,MED_NO_IT,
    00139                                       MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
    00140                                       &_chgt,&_trsf) )  <= 0) {
    00141         MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
    00142         ISCRUTE(_nentity);goto ERROR;
    00143       }
    00144   } else
    00145     _nentity = 1;
    00146
    00147   if ( MEDfilterEntityCr(fid, _nentity, 1, _nbofcomponent, MED_ALL_CONSTITUENT,
    00148                          MED_FULL_INTERLACE,MED_COMPACT_PFLMODE,
    00149                          _profilename, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00150     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00151     goto ERROR;
    00152   }
    00153
    00154   if ( _MEDdatasetRd(_attid,MED_NOM_COR,_constatttype,&_filter, (unsigned char * ) value) < 0) {
    00155     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
    00156     SSCRUTE(_path);
    00157     goto ERROR;
    00158   }
    00159
    00160   if ( MEDfilterClose(&_filter) < 0 ) {
    00161     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_STRUCT_ELEMENT_MSG);
    00162     SSCRUTE(_path);
    00163     goto ERROR;
    00164   }
    00165
    00166   _ret=0;
    00167  ERROR:
    00168
    00169   if (_attid>0)            if (_MEDdatagroupFermer(_attid) < 0) {
    00170     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname);
    00171     ISCRUTE_id(_attid);
    00172   }
    00173
    00174   if (_elemid>0)            if (_MEDdatagroupFermer(_elemid) < 0) {
    00175     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,modelname);
    00176     ISCRUTE_id(_elemid);
    00177   }
    00178
    00179   return _ret;
    00180 }
    00181