Back to index

salome-med  6.5.0
MEDchampCr.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 <string.h>
00023 #include <stdlib.h>
00024 
00025 namespace med_2_1{
00026 
00027 med_err
00028 MEDchampCr(med_idt fid, char *champ, med_type_champ type, char *comp,
00029            char *unit,med_int ncomp)
00030 {
00031   med_err ret = 0;
00032   med_idt root,gid;
00033   char chemin[MED_TAILLE_CHA+1];
00034   med_int _type = (med_int) type;
00035   
00036   /*
00037    * On inhibe le gestionnaire d'erreur HDF 5
00038    */
00039   _MEDmodeErreurVerrouiller();
00040 
00041   /* 
00042    * Si le Data Group "/CHA/" n'existe pas, on le cree
00043    */
00044   strncpy(chemin,MED_CHA,MED_TAILLE_CHA-1);
00045   chemin[MED_TAILLE_CHA-1] = '\0';
00046   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00047     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0)
00048       return -1;  
00049 
00050   /* 
00051    * Si le Data Group cha n'existe pas, on le cree
00052    * Sinon => erreur
00053    */
00054   if ((gid = _MEDdatagroupOuvrir(root,champ)) >= 0)
00055     return -1;
00056   if ((gid = _MEDdatagroupCreer(root,champ)) < 0)
00057     return -1;
00058 
00059   /*
00060    * Les infos sur les composants du champ
00061    */
00062   if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_NCO,&ncomp,MED_REMP)) < 0)
00063     return -1;
00064   if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&_type,MED_REMP)) < 0)
00065     return -1;
00066   if ((ret = _MEDattrStringEcrire(gid,MED_NOM_NOM,MED_TAILLE_PNOM*ncomp,comp,MED_REMP)) < 0)
00067     return -1;
00068   if ((ret = _MEDattrStringEcrire(gid,MED_NOM_UNI,MED_TAILLE_PNOM*ncomp,unit,MED_REMP)) < 0)
00069     return -1;
00070 
00071   /*
00072    * On ferme tout
00073    */
00074   if ((ret = _MEDdatagroupFermer(gid)) < 0)
00075     return -1;
00076   if ((ret = _MEDdatagroupFermer(root)) < 0)
00077     return -1;
00078   
00079   return ret;
00080 }
00081 
00082 }