~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/hdf5/src/java/org/scilab/modules/hdf5/read/H5ReadScilabDouble.java

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
 
 *  Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
4
 
 * 
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
10
 
 * 
11
 
 */
12
 
 
13
 
package org.scilab.modules.hdf5.read;
14
 
 
15
 
import ncsa.hdf.hdf5lib.H5;
16
 
import ncsa.hdf.hdf5lib.HDF5Constants;
17
 
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
18
 
 
19
 
import org.scilab.modules.types.ScilabDouble;
20
 
 
21
 
public class H5ReadScilabDouble {
22
 
    public static void readData(int dataSetId, ScilabDouble data) throws NullPointerException, HDF5Exception {
23
 
        /* Empty Matrix */
24
 
        if (H5Read.isEmpty(dataSetId)) {
25
 
            data.setRealPart(null);
26
 
            data.setImaginaryPart(null);
27
 
            H5.H5Dclose(dataSetId);
28
 
            return;
29
 
        }
30
 
        /* 
31
 
         * Complex Matrix have 2 refs
32
 
         * Real Matrix only have one.
33
 
         */
34
 
        byte[][] dataRefs = new byte[2][8];
35
 
 
36
 
        H5.H5Dread(dataSetId, HDF5Constants.H5T_STD_REF_OBJ,
37
 
                HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dataRefs);
38
 
        
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])));
42
 
            }
43
 
        else {
44
 
            data.setImaginaryPart(null);
45
 
        }
46
 
        H5.H5Dclose(dataSetId);
47
 
    }
48
 
 
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]];
53
 
        
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);
57
 
        
58
 
        
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]];
62
 
            }
63
 
        }
64
 
        
65
 
        H5.H5Sclose(space);
66
 
        H5.H5Dclose(dataSetId);
67
 
        return result;
68
 
    }
69
 
}