# _MEDnFamilyGroup30.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
    00026 void _MEDnFamilyGroup30(int dummy, ... )
    00027 {
    00028
    00029
    00030   med_int   _ret=-1,_err=-1;
    00031   med_idt   _datagroup=0,_famid=0;
    00032   char      _path   [MED_TAILLE_FAS+MED_NAME_SIZE+
    00033                      MED_TAILLE_FAS_ENTITE+MED_NAME_SIZE+1] = MED_FAS;
    00034   char      _family [MED_NAME_SIZE+1] = "";
    00035   med_int   _n          = 0;
    00036   med_size  _tmpn       = 0;
    00037   int       _pathreflen = 0;
    00038   int       _num        ;
    00039   int       _nfamnoe=0,_nfammai=0;
    00040
    00041
    00042   MED_VARGS_DECL(const, med_idt      , , fid      );
    00043   MED_VARGS_DECL(const, char * , const , meshname );
    00044   MED_VARGS_DECL(const, int          , , famit    );
    00045   MED_VARGS_DECL(, med_int *          ,, fret     );
    00046
    00047   va_list params;
    00048   va_start(params,dummy);
    00049
    00050   MED_VARGS_DEF(const, med_idt      , , fid      );
    00051   MED_VARGS_DEF(const, char * , const , meshname );
    00052   MED_VARGS_DEF(const, int          , , famit    );
    00053   MED_VARGS_DEF(, med_int *          ,, fret     );
    00054
    00055   _num        = famit-1;
    00056
    00057   /*
    00058    * On inhibe le gestionnaire d'erreur HDF
    00059    */
    00060   _MEDmodeErreurVerrouiller();
    00061
    00062   strcat(_path,meshname);
    00063   _pathreflen=strlen(_path);
    00064
    00065   /* Acces a la _family :
    00066    * nfam = _nfamnoe + 1 + _nfammai
    00067    * Repartition selon l'indice "num" dans le datagroup :
    00068    *    - 0.._nfammai - 1 : _familys des mailles/faces/aretes
    00069    *    - nfamai : _family 0
    00070    *    - (nfamai + 1)..(_nfammai+_nfamnoe) : familles de noeuds
    00071    */
    00072
    00073   /* Comptage des familles de mailles/faces/aretes */
    00074   strncpy(&_path[_pathreflen],MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE+1);
    00075   if ( (_err = _MEDnObjects(fid,_path,&_tmpn)) < 0 )
    00076     if ( _err == (MED_ERR_COUNT + MED_ERR_DATAGROUP) ) {
    00077       MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_DATAGROUP,_path);
    00078       goto ERROR;
    00079     }
    00080   _nfammai = (med_int ) _tmpn;
    00081
    00082   /* Pour la famille 0 */
    00083   if (_num == _nfammai)  {_n=0;goto SORTIE;}
    00084
    00085   /* C'est une _family de noeuds */
    00086   if (_num > _nfammai) {
    00087     strncpy(&_path[_pathreflen],MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE+1);
    00088     _num = _num - _nfammai - 1;
    00089   }
    00090
    00091   /*
    00092    * Si le Data Group de la _family n'existe pas => erreur
    00093    */
    00094   if ( _MEDobjectGetName(fid, _path ,_num, _family) < 0 ) {
    00095     MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_DATAGROUP,_path);ISCRUTE_int(famit);
    00096     goto ERROR;
    00097   }
    00098   strcat(_path,_family);
    00099
    00100   if ((_famid = _MEDdatagroupOuvrir(fid,_path)) < 0) {
    00101     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_FAMILY_MSG);
    00102     SSCRUTE(_family);SSCRUTE(_path);
    00103     goto ERROR;
    00104   }
    00105
    00106   if ((_datagroup = _MEDdatagroupOuvrir(_famid,MED_NOM_GRO)) < 0)
    00107     _n = 0;
    00108   else {
    00109     if ( _MEDattrEntierLire(_datagroup,MED_NOM_NBR,&_n) < 0) {
    00110       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_FAMILY_MSG);
    00111       SSCRUTE(_family);SSCRUTE(_path);SSCRUTE(MED_NOM_GRO);
    00112       SSCRUTE(MED_NOM_NBR);ISCRUTE(_n);goto ERROR;
    00113     }
    00114   }
    00115
    00116  SORTIE:
    00117   _ret=_n;
    00118
    00119  ERROR:
    00120
    00121  if (_datagroup>0)     if (_MEDdatagroupFermer(_datagroup) < 0) {
    00122    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_GRO);
    00123    SSCRUTE(_path);ISCRUTE_id(_datagroup);
    00124  }
    00125
    00126  if (_famid>0)     if (_MEDdatagroupFermer(_famid) < 0) {
    00127    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_FAS);
    00128    ISCRUTE_id(_famid);
    00129  }
    00130
    00131   va_end(params);
    00132   *fret = _ret;
    00133
    00134   return;
    00135 }