Back to index

salome-kernel  6.5.0
HDFdatasetCreate.c
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 /*----------------------------------------------------------------------------
00024 SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
00025   File   : HDFdatasetCreate.c
00026   Module : SALOME
00027 ----------------------------------------------------------------------------*/
00028 
00029 #include "hdfi.h"
00030 
00031 /*
00032  * - Name : HDFdatasetCreate
00033  * - Description : creates a HDF dataset
00034  * - Parameters :
00035  *     - pid  (IN)     : father ID
00036  *     - name (IN)     : dataset name
00037  *     - type (IN)     : dataset type (HDF_STRING,HDF_INT32,HDF_INT64,HDF_FLOAT64)
00038  *     - dimd (IN)     : dataset size
00039  *     - order(IN)     : byte order (H5T_ORDER_NONE, H5T_ORDER_LE, H5T_ORDER_BE)
00040  * - Result : 
00041  *     - if success : returns dataset ID
00042  *     - if failure : -1
00043  */ 
00044 
00045 hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type,
00046                          hdf_size *dimd, int ndim, hdf_byte_order order, hdf_idt arrayId)
00047 {
00048   hdf_idt dataset, dataspace = 0;
00049   hdf_err ret;
00050   hdf_idt type_hdf, new_type_hdf = -1;
00051 
00052   switch(type)
00053     {
00054     case HDF_FLOAT64 :
00055 #if defined (PCLINUX) || defined (PCLINUX64)
00056       type_hdf = H5T_IEEE_F64BE;
00057 #else 
00058       type_hdf = H5T_IEEE_F64LE;
00059 #endif
00060       break;
00061 
00062     case HDF_INT32 :
00063 #if defined (PCLINUX) || defined (PCLINUX64)
00064       type_hdf = H5T_STD_I32BE;  
00065 #else
00066       type_hdf = H5T_NATIVE_INT;
00067 #endif
00068       break;
00069  
00070     case HDF_INT64 :
00071       type_hdf = H5T_NATIVE_LONG;
00072       break;
00073 
00074     case HDF_STRING :           
00075       if((new_type_hdf = H5Tcopy(H5T_C_S1)) < 0)
00076         return -1;
00077       if((ret = H5Tset_size(new_type_hdf,1)) < 0)
00078         return -1;
00079       break;    
00080 
00081     case HDF_ARRAY :
00082       type_hdf = arrayId;
00083       break;
00084       
00085     default :
00086       return -1;
00087     }
00088 
00089   /* set order */
00090   if ( order != H5T_ORDER_ERROR && 
00091        order != H5T_ORDER_NONE && 
00092        type  != HDF_STRING )
00093     {
00094       if (( new_type_hdf = H5Tcopy( type_hdf )) < 0 )
00095         return -1;
00096       if (( ret = H5Tset_order (new_type_hdf, order )) < 0 )
00097         return -1;
00098     }
00099 
00100   if ((dataset = H5Dopen(pid,name)) < 0)
00101     {
00102       if ((dataspace = H5Screate_simple(ndim, dimd, NULL)) < 0)                                                         
00103         return -1;
00104       if ((dataset = H5Dcreate(pid,name,
00105                                new_type_hdf < 0 ? type_hdf : new_type_hdf,
00106                                dataspace, H5P_DEFAULT)) < 0)
00107         return -1;
00108     }
00109   else
00110     return -1;
00111 
00112   if ( ! (new_type_hdf < 0) && (ret = H5Tclose(new_type_hdf)) < 0)
00113     return -1;
00114   if ((ret = H5Sclose(dataspace)) < 0)
00115     return -1;
00116 
00117   return dataset;
00118 }