2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
5
* This file must be used under the terms of the CeCILL.
6
* This source file is licensed as described in the file COPYING, which
7
* you should have received as part of this distribution. The terms
8
* are also available at
9
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13
package org.scilab.modules.hdf5.read;
15
import ncsa.hdf.hdf5lib.H5;
16
import ncsa.hdf.hdf5lib.HDF5Constants;
17
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
19
import org.scilab.modules.types.ScilabDouble;
21
public class H5ReadScilabDouble {
22
public static void readData(int dataSetId, ScilabDouble data) throws NullPointerException, HDF5Exception {
24
if (H5Read.isEmpty(dataSetId)) {
25
data.setRealPart(null);
26
data.setImaginaryPart(null);
27
H5.H5Dclose(dataSetId);
31
* Complex Matrix have 2 refs
32
* Real Matrix only have one.
34
byte[][] dataRefs = new byte[2][8];
36
H5.H5Dread(dataSetId, HDF5Constants.H5T_STD_REF_OBJ,
37
HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dataRefs);
39
data.setRealPart(getDoubleMatrix(H5.H5Rdereference(dataSetId, HDF5Constants.H5R_OBJECT, dataRefs[0])));
40
if (H5Read.isComplex(dataSetId)) {
41
data.setImaginaryPart(getDoubleMatrix(H5.H5Rdereference(dataSetId, HDF5Constants.H5R_OBJECT, dataRefs[1])));
44
data.setImaginaryPart(null);
46
H5.H5Dclose(dataSetId);
49
private static double[][] getDoubleMatrix(int dataSetId) throws NullPointerException, HDF5Exception {
50
int[] nbElems = H5Read.getAllDims(dataSetId);
51
double[] data = new double[nbElems[0] * nbElems[1]];
52
double[][] result = new double[nbElems[0]][nbElems[1]];
54
int space = H5.H5Dget_space(dataSetId);
55
H5.H5Dread_double(dataSetId, HDF5Constants.H5T_NATIVE_DOUBLE, space,
56
HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, data);
59
for(int i = 0 ; i < nbElems[0] ; i++) {
60
for(int j = 0 ; j < nbElems[1] ; j++) {
61
result[i][j] = data[i+ j * nbElems[0]];
66
H5.H5Dclose(dataSetId);