ncsa.hdf.object.h5
Class H5ScalarDS

java.lang.Object
  extended byncsa.hdf.object.HObject
      extended byncsa.hdf.object.Dataset
          extended byncsa.hdf.object.ScalarDS
              extended byncsa.hdf.object.h5.H5ScalarDS
All Implemented Interfaces:
DataFormat, java.io.Serializable

public class H5ScalarDS
extends ScalarDS

H5ScalarDS describes an multi-dimension array of HDF5 scalar or atomic data types, such as byte, int, short, long, float, double and string, and operations performed on the scalar dataset

The library predefines a modest number of datatypes. For details, read The Datatype Interface (H5T)

How to Select a Subset

Dataset defines APIs for read, write and subet a dataset. No function is defined to select a subset of a data array. The selection is done in an implicit way. Function calls to dimension information such as getSelectedDims() return an array of dimension values, which is a reference to the array in the dataset object. Changes of the array outside the dataset object directly change the values of the array in the dataset object. It is like pointers in C.

The following is an example of how to make a subset. In the example, the dataset is a 4-dimension with size of [200][100][50][10], i.e. dims[0]=200; dims[1]=100; dims[2]=50; dims[3]=10;
We want to select every other data points in dims[1] and dims[2]

     int rank = dataset.getRank();   // number of dimension of the dataset
     long[] dims = dataset.getDims(); // the dimension sizes of the dataset
     long[] selected = dataset.getSelectedDims(); // the selected size of the dataet
     long[] start = dataset.getStartDims(); // the off set of the selection
     long[] stride = dataset.getStride(); // the stride of the dataset
     int[]  selectedIndex = dataset.getSelectedIndex(); // the selected dimensions for display

     // select dim1 and dim2 as 2D data for display,and slice through dim0
     selectedIndex[0] = 1;
     selectedIndex[1] = 2;
     selectedIndex[1] = 0;

     // reset the selection arrays
     for (int i=0; i

 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class ncsa.hdf.object.ScalarDS
imageDataRange, interlace, INTERLACE_LINE, INTERLACE_PIXEL, INTERLACE_PLANE, isImage, isText, isTrueColor, isUnsigned, nativeDatatype, palette, unsignedConverted
 
Fields inherited from class ncsa.hdf.object.Dataset
chunkSize, compression, data, datatype, dimNames, dims, H5Z_FILTER_CONFIG_DECODE_ENABLED, H5Z_FILTER_CONFIG_ENCODE_ENABLED, rank, selectedDims, selectedIndex, selectedStride, startDims
 
Fields inherited from class ncsa.hdf.object.HObject
hasAttribute, oid, separator
 
Constructor Summary
H5ScalarDS(FileFormat fileFormat, java.lang.String name, java.lang.String path)
           
H5ScalarDS(FileFormat fileFormat, java.lang.String name, java.lang.String path, long[] oid)
          Constructs an H5ScalarDS object with specific name and path.
 
Method Summary
 void close(int did)
          Closes access to this object.
 Dataset copy(Group pgroup, java.lang.String dstName, long[] dims, java.lang.Object buff)
          Copy this dataset to another group.
static H5ScalarDS create(java.lang.String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, java.lang.Object data)
          Creates a new dataset.
 Datatype getDatatype()
          returns the datatype of this dataset.
 java.util.List getMetadata()
          Loads the metadata such as attributes and type of the the data object into memory if the metadata is not loaded.
 byte[][] getPalette()
          Returns the palette of this scalar dataset or null if palette does not exist.
 byte[] getPaletteRefs()
          returns the byte array of palette refs.
 void init()
          Retrieve and initialize dimensions and member information.
 int open()
          Opens access to this object.
 java.lang.Object read()
          Loads and returns the data value from file.
 byte[] readBytes()
          Read data values of this dataset into byte array.
 byte[][] readPalette(int idx)
          read specific image palette from file.
 void removeMetadata(java.lang.Object info)
          Deletes an existing metadata from this data object.
 void setName(java.lang.String newName)
          Sets the name of the data object.
 void write(java.lang.Object buf)
          Write data values into file.
 void writeMetadata(java.lang.Object info)
          Saves a specific metadata into file.
 
Methods inherited from class ncsa.hdf.object.ScalarDS
clearData, convertFromUnsignedC, convertToUnsignedC, getImageDataRange, getInterlace, getNativeDataType, isImage, isText, isTrueColor, isUnsigned, setPalette
 
Methods inherited from class ncsa.hdf.object.Dataset
byteToString, convertFromUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getData, getDimNames, getDims, getHeight, getRank, getSelectedDims, getSelectedIndex, getStartDims, getStride, getWidth, setData, stringToByte, write
 
Methods inherited from class ncsa.hdf.object.HObject
equalsOID, getFID, getFile, getFileFormat, getName, getOID, getPath, hasAttribute, setPath, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

H5ScalarDS

public H5ScalarDS(FileFormat fileFormat,
                  java.lang.String name,
                  java.lang.String path)

H5ScalarDS

public H5ScalarDS(FileFormat fileFormat,
                  java.lang.String name,
                  java.lang.String path,
                  long[] oid)
Constructs an H5ScalarDS object with specific name and path.

Parameters:
fileFormat - the HDF file.
name - the name of this H5ScalarDS.
path - the full path of this H5ScalarDS.
oid - the unique identifier of this data object.
Method Detail

copy

public Dataset copy(Group pgroup,
                    java.lang.String dstName,
                    long[] dims,
                    java.lang.Object buff)
             throws java.lang.Exception
Description copied from class: Dataset
Copy this dataset to another group.

Specified by:
copy in class Dataset
Parameters:
pgroup - the group which the dataset is copied to.
dstName - the name of the new dataset.
dims - the dimension sizes of the the new dataset.
buff - the data to be copied.
Returns:
the new dataset.
Throws:
java.lang.Exception

readBytes

public byte[] readBytes()
                 throws HDF5Exception
Description copied from class: Dataset
Read data values of this dataset into byte array. readBytes() loads data as arry 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 a int array of 5.

readBytes() is most used for copy data values, at which case, data do not need to be changed or displayed.

Specified by:
readBytes in class Dataset
Throws:
HDF5Exception

read

public java.lang.Object read()
                      throws HDF5Exception
Description copied from class: Dataset
Loads and returns the data value from file.

Specified by:
read in class Dataset
Throws:
HDF5Exception

write

public void write(java.lang.Object buf)
           throws HDF5Exception
Description copied from class: Dataset
Write data values into file.

Specified by:
write in class Dataset
Parameters:
buf - the data to write
Throws:
HDF5Exception

getMetadata

public java.util.List getMetadata()
                           throws HDF5Exception
Description copied from interface: DataFormat
Loads the metadata such as attributes and type of the the data object into memory if the metadata is not loaded. If the metadata is loaded, it returns the metadata. The metadata is stored as a collection of metadata ojbects in a List.

Returns:
the list of metadata objects.
Throws:
HDF5Exception
See Also:
List

writeMetadata

public void writeMetadata(java.lang.Object info)
                   throws java.lang.Exception
Description copied from interface: DataFormat
Saves a specific metadata into file. If the metadata exists, it updates its value. If the metadata does not exists, it creates and attach the new metadata to the object and saves it into file.

Parameters:
info - the specific metadata.
Throws:
java.lang.Exception

removeMetadata

public void removeMetadata(java.lang.Object info)
                    throws HDF5Exception
Description copied from interface: DataFormat
Deletes an existing metadata from this data object.

Parameters:
info - the metadata to delete.
Throws:
HDF5Exception

open

public int open()
Description copied from class: HObject
Opens access to this object.

Sub-classes have to implement this interface so that different data objects have their own ways of how the data resources are opened.

Specified by:
open in class HObject
Returns:
the interface identifier for access this object.

close

public void close(int did)
Description copied from class: HObject
Closes access to this object.

Specified by:
close in class HObject
Parameters:
did - the object identifier. Sub-classes have to implement this interface so that different data objects have their own ways of how the data resources are closed.

init

public void init()
Retrieve and initialize dimensions and member information.

Specified by:
init in class Dataset

getPalette

public byte[][] getPalette()
Description copied from class: ScalarDS
Returns the palette of this scalar dataset or null if palette does not exist.

Scalar dataset can be displayed as spreadsheet data or image. When a scalar dataset is chosen to display as an image, the palette or color table may be needed to translate a pixel value to color components (for example, red, green, and blue). Some scalar datasets have no palette and some datasets have one or more than one palettes. If an associated palette exists but not loaded, this interface retrieves the palette from the file and returns the palette. If the palette is loaded, it returnd the palette. It returns null if there is no palette assciated with the dataset.

Current implementation only supports palette model of indexed RGB with 256 colors. Other models such as YUV", "CMY", "CMYK", "YCbCr", "HSV will be supported in the future.

The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.

Sub-classes have to implement this interface. HDF4 and HDF5 images use different library to retrieve the associated palette.

Specified by:
getPalette in class ScalarDS

readPalette

public byte[][] readPalette(int idx)
read specific image palette from file.

Specified by:
readPalette in class ScalarDS
Parameters:
idx - the palette index to read
Returns:
the palette data into two-dimension byte array, byte[3][256]

create

public static H5ScalarDS create(java.lang.String name,
                                Group pgroup,
                                Datatype type,
                                long[] dims,
                                long[] maxdims,
                                long[] chunks,
                                int gzip,
                                java.lang.Object data)
                         throws java.lang.Exception
Creates a new dataset.

Parameters:
name - the name of the dataset to create.
pgroup - the parent group of the new dataset.
type - the datatype of the dataset.
dims - the dimension size of the dataset.
maxdims - the max dimension size of the dataset.
gzip - the level of the gzip compression.
data - the array of data values.
Returns:
the new dataset if successful. Otherwise returns null.
Throws:
java.lang.Exception

getPaletteRefs

public byte[] getPaletteRefs()
returns the byte array of palette refs. returns null if there is no palette attribute attached to this dataset.

Specified by:
getPaletteRefs in class ScalarDS

getDatatype

public Datatype getDatatype()
Description copied from class: Dataset
returns the datatype of this dataset.

Specified by:
getDatatype in class Dataset

setName

public void setName(java.lang.String newName)
             throws java.lang.Exception
Sets the name of the data object.

Overrides:
setName in class HObject
Parameters:
newName - the new name of the object.
Throws:
java.lang.Exception