# MEDnChamp.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 <string.h>
    00022 #include <stdlib.h>
    00023 #include <med_outils.h>
    00024
    00025 med_int
    00026 MEDnChamp(med_idt fid, int indice)
    00027 {
    00028   int n1;
    00029   med_int n2;
    00030   med_idt datagroup;
    00031   med_err ret;
    00032   char nomdatagroup[MED_TAILLE_NOM+1];
    00033   int num;
    00034   char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1];
    00035
    00036   if (indice < 0)
    00037     return -1;
    00038
    00039   /*
    00040    * On inhibe le gestionnaire d'erreur HDF
    00041    */
    00042   _MEDmodeErreurVerrouiller();
    00043 if (MEDcheckVersion(fid) < 0) return -1;
    00044
    00045
    00046   /*
    00047    * Si le Data Group cha n'existe pas et indice == 0 => 0
    00048    * sinon erreur => erreur
    00049    */
    00050   strcpy(chemin,MED_CHA);
    00051
    00052   /*
    00053    * Si indice == 0 => nombre de champs
    00054    */
    00055   if (indice == 0)
    00056     {
    00057       n1 = 0;
    00058       _MEDnObjets(fid,chemin,&n1);
    00059       n2 = n1;
    00060     }
    00061
    00062   /*
    00063    * Si indice > 0 => nbre de composants
    00064    */
    00065   if (indice > 0)
    00066     {
    00067       /*
    00068        * On recupere le nom du champ
    00069        */
    00070       num = indice-1;
    00071       if ((ret = _MEDobjetIdentifier(fid,chemin,num,nomdatagroup)) < 0)
    00072         return -1;
    00073       strcat(chemin,nomdatagroup);
    00074       /*
    00075        * On recupere le nombre de composants
    00076        */
    00077       if ((datagroup = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    00078         return -1;
    00079       if ((ret = _MEDattrEntierLire(datagroup,MED_NOM_NCO,&n2)) < 0)
    00080         return -1;
    00081       if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
    00082         return -1;
    00083     }
    00084
    00085   return n2;
    00086 }
    00087