Logo Search packages:      
Sourcecode: jhdf version File versions  Download package

byte [] ncsa::hdf::object::h5::H5ScalarDS::readBytes (  )  throws HDF5Exception [inline, virtual]

Reads the raw data of the dataset from file to a byte array.

readBytes() reads raw data to an array of bytes instead of array of its datatype. For example, for an one-dimension 32-bit integer dataset of size 5, the readBytes() returns of a byte array of size 20 instead of an int array of 5.

readBytes() can be used to copy data from one dataset to another efficiently because the raw data is not converted to its native type, it saves memory space and CPU time.

the byte array of the raw data.

Implements ncsa::hdf::object::Dataset.

Definition at line 481 of file H5ScalarDS.java.

References close(), ncsa::hdf::object::Dataset::dims, init(), open(), ncsa::hdf::object::Dataset::rank, ncsa::hdf::object::Dataset::selectedDims, ncsa::hdf::object::Dataset::selectedStride, and ncsa::hdf::object::Dataset::startDims.

Referenced by test::unittests::H5ScalarDSTest::testReadBytes().

        byte[] theData = null;

        if (rank <= 0) {

        int did = open();
        int fspace=-1, mspace=-1, tid=-1;

            long[] lsize = {1};
            for (int j=0; j<selectedDims.length; j++) {
                lsize[0] *= selectedDims[j];

            fspace = H5.H5Dget_space(did);
            mspace = H5.H5Screate_simple(rank, selectedDims, null);

            // set the rectangle selection
            // HDF5 bug: for scalar dataset, H5Sselect_hyperslab gives core dump
            if (rank*dims[0] > 1)
                    null );   // set block to 1

            tid = H5.H5Dget_type(did);
            int size = H5.H5Tget_size(tid)*(int)lsize[0];
            theData = new byte[size];
            H5.H5Dread(did, tid, mspace, fspace, HDF5Constants.H5P_DEFAULT, theData);
            try { H5.H5Sclose(fspace); } catch (Exception ex2) {}
            try { H5.H5Sclose(mspace); } catch (Exception ex2) {}
            try { H5.H5Tclose(tid); } catch (HDF5Exception ex2) {}

        return theData;

Generated by  Doxygen 1.6.0   Back to index