# MEDfamilyInfo.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  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 <stdlib.h>
    00024 #include <string.h>
    00025
    00038 med_err
    00039 MEDfamilyInfo(const med_idt  fid,
    00040               const char *   meshname,
    00041               const int      famit,
    00042               char * const   familyname,
    00043               med_int *const familynumber,
    00044               char *const    groupname)
    00045 {
    00046   med_err    _ret=-1,_err=-1;
    00047   med_idt    _datagroup=0,_famid=0;
    00048   char       _path   [MED_TAILLE_FAS+MED_NAME_SIZE+
    00049                      MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = MED_FAS;
    00050   med_int    _n          = 0;
    00051   med_size   _tmpn       = 0;
    00052   int        _pathreflen = 0;
    00053   int        _num        = famit-1;
    00054   int        _nfammai=0;
    00055   med_int    _ngroup=0;
    00056   med_filter _filter=MED_FILTER_INIT;
    00057   /*
    00058    * On inhibe le gestionnaire d'erreur HDF 5
    00059    */
    00060   _MEDmodeErreurVerrouiller();
    00061 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00062
    00063   /*
    00064    * On recupere le nom de la famille
    00065    */
    00066
    00067   /* Acces a la famille :
    00068    * nfam = nfamnoe + 1 + nfammai
    00069    * Repartition selon l'indice "num" dans le datagroup :
    00070    *    - 0..nfammai - 1 : familles des mailles/faces/aretes
    00071    *    - nfamai : famille 0
    00072    *    - (nfamai + 1)..(nfammai+nfamnoe) : familles de noeuds
    00073    */
    00074
    00075   /* Comptage des familles de mailles/faces/aretes */
    00076   strcat(_path,meshname);
    00077   _pathreflen=strlen(_path);
    00078
    00079   strncpy(&_path[_pathreflen],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE+1);
    00080   if ( (_err = _MEDnObjects(fid,_path,&_tmpn)) < 0 )
    00081     if ( _err == (MED_ERR_COUNT + MED_ERR_DATAGROUP) ) {
    00082       MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_path);
    00083       goto ERROR;
    00084     }
    00085
    00086   _nfammai = (med_int ) _tmpn;
    00087
    00088 /*   SSCRUTE(_path); */
    00089 /*   ISCRUTE(_nfammai); */
    00090
    00091   /* Pour la famille 0 */
    00092   if (_num == _nfammai) {
    00093     strcpy(familyname,FAMILLE_ZERO);
    00094     groupname[0]='\0';
    00095     *familynumber=0;
    00096     return 0;
    00097   }
    00098
    00099
    00100   /* C'est une _family de noeuds */
    00101   if (_num > _nfammai) {
    00102     strncpy(&_path[_pathreflen],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE+1);
    00103     _num = _num - _nfammai - 1;
    00104   }
    00105
    00106 /*   SSCRUTE(_path); */
    00107
    00108   /*
    00109    * Si le Data Group de la famille n'existe pas => erreur
    00110    */
    00111   if ( _MEDobjectGetName(fid, _path ,_num, familyname) < 0 ) {
    00112     MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_path);ISCRUTE_int(famit);
    00113     goto ERROR;
    00114   }
    00115 /*   SSCRUTE(familyname); */
    00116   strcat(_path,familyname);
    00117 /*   SSCRUTE(_path); */
    00118
    00119   if ((_famid = _MEDdatagroupOuvrir(fid,_path)) < 0) {
    00120     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FAMILY_MSG);
    00121     SSCRUTE(_path);
    00122     goto ERROR;
    00123   }
    00124
    00125   /*
    00126    * L'attribut NUM
    00127    */
    00128   if ( _MEDattrEntierLire(_famid,MED_NOM_NUM,familynumber) < 0) {
    00129       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FAMILY_MSG);
    00130       SSCRUTE(familyname);SSCRUTE(_path);
    00131       SSCRUTE(MED_NOM_NUM);ISCRUTE(*familynumber);goto ERROR;
    00132   }
    00133 /*   ISCRUTE(*familynumber); */
    00134
    00135   /*
    00136    * Le Data Group "GRO"
    00137    */
    00138   if ((_datagroup = _MEDdatagroupOuvrir(_famid,MED_NOM_GRO)) >= 0) {
    00139
    00140     /*
    00141      * L'attribut "NBR"
    00142      */
    00143     if ( _MEDattrEntierLire(_datagroup,MED_NOM_NBR,&_ngroup) < 0) {
    00144       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FAMILY_MSG);
    00145       SSCRUTE(familyname);SSCRUTE(_path);SSCRUTE(MED_NOM_GRO);
    00146       SSCRUTE(MED_NOM_NBR);
    00147       goto ERROR;
    00148     }
    00149 /*     ISCRUTE(_ngroup); */
    00150
    00151     /*
    00152      * Data Set des noms des groupes "NOM"
    00153      */
    00154     if ( MEDfilterEntityCr(fid, _ngroup, 1, 1, MED_ALL_CONSTITUENT,
    00155                            MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00156                            MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00157       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00158       goto ERROR;
    00159     }
    00160
    00161     if ( _MEDdatasetRd(_datagroup,MED_NOM_NOM,MED_INTERNAL_LNAME,&_filter,
    00162                        (unsigned char * const) groupname) < 0) {
    00163       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_DATASET,MED_NOM_NOM);
    00164       SSCRUTE(_path);SSCRUTE(MED_NOM_GRO);SSCRUTE(groupname);
    00165       goto ERROR;
    00166     }
    00167 /*     SSCRUTE(groupname); */
    00168
    00169     if ( MEDfilterClose(&_filter) < 0 ) {
    00170       MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_FAMILY_MSG);
    00171       SSCRUTE(familyname);SSCRUTE(_path);SSCRUTE(MED_NOM_GRO);
    00172       goto ERROR;
    00173     }
    00174
    00175   }
    00176
    00177  _ret = 0;
    00178
    00179  ERROR:
    00180
    00181  if (_datagroup>0)     if (_MEDdatagroupFermer(_datagroup) < 0) {
    00182    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_GRO);
    00183    ISCRUTE_id(_datagroup);
    00184  }
    00185
    00186  if (_famid>0)         if (_MEDdatagroupFermer(_famid) < 0) {
    00187    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,&_path[_pathreflen]);
    00188    ISCRUTE_id(_famid);
    00189  }
    00190
    00191  return _ret;
    00192 }
    00193
    00194