Back to index

salome-med  6.5.0
MEDdatasetStringEcrire.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 /*
00023  * - Nom de la fonction : _MEDdatasetStringEcrire
00024  * - Description : ecriture d'un dataset tableau de caracteres
00025  * - Parametres :
00026  *     - pere (IN)     : l'ID de l'objet HDF pere ou placer l'attribut
00027  *     - nom  (IN)     : le nom de l'attribut 
00028  *     - dimd (IN)     : profil du tableau
00029  *     - val  (IN)     : valeurs du tableau
00030  *     - mode (IN)     : mode d'ecriture MED
00031  * - Resultat : 0 en cas de succes, -1 sinon
00032  */ 
00033 
00034 namespace med_2_1{
00035 
00036 med_err 
00037 _MEDdatasetStringEcrire(med_idt pere,char *nom,med_size *dimd,
00038                         char *val, med_mode_acces mode)
00039 {
00040   med_idt dataset;
00041   med_idt datatype = 0;
00042   med_idt dataspace = 0;
00043   med_err ret;
00044 
00045   if ((dataset = H5Dopen(pere,nom)) < 0)
00046     {
00047       if ((dataspace = H5Screate_simple(1,dimd,NULL)) < 0)
00048         return -1;
00049       if((datatype = H5Tcopy(H5T_C_S1)) < 0)
00050         return -1;
00051       if((ret = H5Tset_size(datatype,1)) < 0)
00052         return -1;
00053       if ((dataset = H5Dcreate(pere,nom,datatype,dataspace,
00054                              H5P_DEFAULT)) < 0)
00055         return -1;    
00056     }
00057   else
00058     if (mode != MED_REMP)
00059       {
00060         H5Dclose(dataset);
00061         return -1;
00062       }
00063     else
00064       {
00065       if ((dataspace = H5Screate_simple(1,dimd,NULL)) < 0)
00066         return -1;
00067       if((datatype = H5Tcopy(H5T_C_S1)) < 0)
00068         return -1;
00069       if((ret = H5Tset_size(datatype,1)) < 0)
00070         return -1;
00071       }
00072   if ((ret = H5Dwrite(dataset,datatype,H5S_ALL,H5S_ALL,
00073                       H5P_DEFAULT, val)) < 0)
00074     return -1;
00075   if (dataspace)
00076     if((ret = H5Sclose(dataspace)) < 0)
00077       return -1;
00078   if (datatype)
00079     if ((ret = H5Tclose(datatype)) < 0)
00080       return -1;
00081   if ((ret = H5Dclose(dataset)) < 0)
00082     return -1;
00083 
00084   return 0;
00085 }
00086 
00087 }