Back to index

salome-med  6.5.0
MEDchampInfo.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 "med_outils.hxx"
00021 
00022 #include <cstring>
00023 
00024 namespace med_2_1{
00025 
00026 med_err 
00027 MEDchampInfo(med_idt fid,int indice,char *champ,
00028              med_type_champ *type,char *comp,char *unit, 
00029              med_int ncomp)
00030 {
00031   med_err ret=0;
00032   med_idt gid;
00033   char chemin[MED_TAILLE_CHA+MED_TAILLE_LNOM+1]; //SRN: Changed to MED_TAILLE_LNOM to avoid a crash 
00034                                                  //     in case if a field name longer than MED_TAILLE_NOM
00035   int num;
00036 
00037   /*
00038    * On inhibe le gestionnaire d'erreur HDF 5
00039    */
00040   _MEDmodeErreurVerrouiller();
00041 
00042   /*
00043    * On recupere le nom du champ
00044    */
00045   num = indice - 1;
00046   strcpy(chemin,MED_CHA);
00047   if ((ret = _MEDobjetIdentifier(fid,chemin,num,champ)) < 0)
00048     return -1;
00049 
00050   if(strlen(champ) > MED_TAILLE_NOM) return -1;
00051 
00052   /* 
00053    * Si le Data Group cha n'existe pas => erreur
00054    */
00055   strcat(chemin,champ);
00056   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00057     return -1;
00058 
00059 
00060   /*
00061    * La liste des attributs
00062    */
00063 
00064   // MPV 05.10.2006
00065   // BUG IPAL 13482: on 64bit Mandriva OS sizeof(med_int)=8, but sizeof(med_type_champ)=4
00066   med_int aType;
00067   //  if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,(med_int*) type)) < 0)
00068   if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&aType)) < 0)
00069     return -1;
00070   *type = (med_type_champ)aType;
00071   
00072   if ((ret = _MEDattrStringLire(gid,MED_NOM_NOM,ncomp*MED_TAILLE_PNOM,
00073                                 comp)) < 0)
00074     return -1;
00075   if ((ret = _MEDattrStringLire(gid,MED_NOM_UNI,ncomp*MED_TAILLE_PNOM,
00076                                 unit)) < 0)
00077     return -1;
00078 
00079   /*
00080    * On ferme tout
00081    */
00082   if ((ret = _MEDdatagroupFermer(gid)) < 0)
00083     return -1; 
00084 
00085   return 0;
00086 }
00087 
00088 }