Salome HOME
First stable version after merging with V3_2_2
[modules/kernel.git] / src / HDFPersist / HDFdatasetCreate.c
1 // Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 //           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 // 
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 // 
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 // 
19 /*----------------------------------------------------------------------------
20 SALOME HDFPersist : implementation of HDF persitent ( save/ restore )
21   File   : HDFdatasetCreate.c
22   Module : SALOME
23 ----------------------------------------------------------------------------*/
24
25 #include "hdfi.h"
26
27 /*
28  * - Name : HDFdatasetCreate
29  * - Description : creates a HDF dataset
30  * - Parameters :
31  *     - pid  (IN)     : father ID
32  *     - name (IN)     : dataset name
33  *     - type (IN)     : dataset type (HDF_STRING,HDF_INT32,HDF_INT64,HDF_FLOAT64)
34  *     - dimd (IN)     : dataset size
35  *     - order(IN)     : byte order (H5T_ORDER_NONE, H5T_ORDER_LE, H5T_ORDER_BE)
36  * - Result : 
37  *     - if success : returns dataset ID
38  *     - if failure : -1
39  */ 
40
41 hdf_idt HDFdatasetCreate(hdf_idt pid,char *name,hdf_type type,
42                          hdf_size *dimd, int ndim, hdf_byte_order order)
43 {
44   hdf_idt dataset, dataspace = 0;
45   hdf_err ret;
46   hdf_idt type_hdf, new_type_hdf = -1;
47
48   switch(type)
49     {
50     case HDF_FLOAT64 :
51 #ifdef PCLINUX
52       type_hdf = H5T_IEEE_F64BE;
53 #else 
54       type_hdf = H5T_IEEE_F64LE;
55 #endif
56       break;
57
58     case HDF_INT32 :
59 #ifdef PCLINUX
60       type_hdf = H5T_STD_I32BE;  
61 #else
62       type_hdf = H5T_NATIVE_INT;
63 #endif
64       break;
65  
66     case HDF_INT64 :
67       type_hdf = H5T_NATIVE_LONG;
68       break;
69
70     case HDF_STRING :           
71       if((new_type_hdf = H5Tcopy(H5T_C_S1)) < 0)
72         return -1;
73       if((ret = H5Tset_size(new_type_hdf,1)) < 0)
74         return -1;
75       break;
76
77     default :
78       return -1;
79     }
80
81   /* set order */
82   if ( order != H5T_ORDER_ERROR && 
83        order != H5T_ORDER_NONE && 
84        type  != HDF_STRING )
85     {
86       if (( new_type_hdf = H5Tcopy( type_hdf )) < 0 )
87         return -1;
88       if (( ret = H5Tset_order (new_type_hdf, order )) < 0 )
89         return -1;
90     }
91
92   if ((dataset = H5Dopen(pid,name)) < 0)
93     {
94       if ((dataspace = H5Screate_simple(ndim, dimd, NULL)) < 0)                                                         
95         return -1;
96       if ((dataset = H5Dcreate(pid,name,
97                                new_type_hdf < 0 ? type_hdf : new_type_hdf,
98                                dataspace, H5P_DEFAULT)) < 0)
99         return -1;
100     }
101   else
102     return -1;
103
104   if ( ! (new_type_hdf < 0) && (ret = H5Tclose(new_type_hdf)) < 0)
105     return -1;
106   if ((ret = H5Sclose(dataspace)) < 0)
107     return -1;
108
109   return dataset;
110 }