Back to index

salome-med  6.5.0
MEDnChamp.cxx
Go to the documentation of this file.
00001 /*************************************************************************
00002 * COPYRIGHT (C) 1999 - 2002  EDF R&D
00003 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
00004 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
00005 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00006 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00007 *  
00008 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
00009 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
00010 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
00011 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
00012 *
00013 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
00014 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
00015 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
00016 *
00017 *************************************************************************/
00018 
00019 #include "med.hxx"
00020 #include <string.h>
00021 #include <stdlib.h>
00022 #include "med_outils.hxx"
00023 
00024 namespace med_2_1{
00025 
00026 med_int 
00027 MEDnChamp(med_idt fid, int indice)
00028 {
00029   int n1;
00030   med_int n2;
00031   med_idt datagroup;
00032   med_err ret;
00033   char nomdatagroup[MED_TAILLE_NOM+1];
00034   int num;
00035   char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1];
00036 
00037   if (indice < 0)
00038     return -1;
00039 
00040   /*
00041    * On inhibe le gestionnaire d'erreur HDF 
00042    */
00043   _MEDmodeErreurVerrouiller();
00044   
00045   /* 
00046    * Si le Data Group cha n'existe pas et indice == 0 => 0
00047    * sinon erreur => erreur
00048    */
00049   strcpy(chemin,MED_CHA);
00050 
00051   /*
00052    * Si indice == 0 => nombre de champs
00053    */
00054   if (indice == 0)
00055     {
00056       n1 = 0;
00057       _MEDnObjets(fid,chemin,&n1);
00058       n2 = n1;
00059     }
00060 
00061   /*
00062    * Si indice > 0 => nbre de composants
00063    */
00064   if (indice > 0)
00065     {
00066       /*
00067        * On recupere le nom du champ 
00068        */
00069       num = indice-1;
00070       if ((ret = _MEDobjetIdentifier(fid,chemin,num,nomdatagroup)) < 0)
00071         return -1;
00072       strcat(chemin,nomdatagroup);
00073       /*
00074        * On recupere le nombre de composants
00075        */
00076       if ((datagroup = _MEDdatagroupOuvrir(fid,chemin)) < 0) 
00077         return -1;
00078       if ((ret = _MEDattrEntierLire(datagroup,MED_NOM_NCO,&n2)) < 0)
00079         return -1;
00080       if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
00081         return -1;
00082     }
00083 
00084   return n2;
00085 }
00086 
00087 }