ncsa.hdf.object.h4

## Class H4Vdata

- java.lang.Object
- - ncsa.hdf.object.HObject
  - - ncsa.hdf.object.Dataset
    - - ncsa.hdf.object.CompoundDS
      - - ncsa.hdf.object.h4.H4Vdata

All Implemented Interfaces:
  java.io.Serializable, DataFormat

    public class H4Vdata
    extends CompoundDS

H4Vdata describes a multi-dimension array of HDF4 vdata, inheriting CompoundDS.

A vdata is like a table that consists of a collection of records whose values are stored in fixed-length fields. All records have the same structure and all values in each field have the same data type. Vdatas are uniquely identified by a name, a class, and a series of individual field names.

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<rank; i++) {
             start[i] = 0;
             selected[i] = 1;
             stride[i] = 1;
        }

        // set stride to 2 on dim1 and dim2 so that every other data points are selected.
        stride[1] = 2;
        stride[2] = 2;

        // set the selection size of dim1 and dim2
        selected[1] = dims[1]/stride[1];
        selected[2] = dims[1]/stride[2];

        // when dataset.read() is called, the slection above will be used since
        // the dimension arrays is passed by reference. Changes of these arrays
        // outside the dataset object directly change the values of these array
        // in the dataset object.

     </pre>

Version:
  1.1 9/4/2007
Author:
  Peter X. Cao
See Also:
  Serialized Form

### Field Summary

### Fields inherited from class ncsa.hdf.object.CompoundDS

`isMemberSelected, memberDims, memberNames, memberOrders, memberTypes, numberOfMembers, separator`

### Fields inherited from class ncsa.hdf.object.Dataset

`chunkSize, compression, convertByteToString, convertedBuf, data, datatype, dimNames, dims, enumConverted, isDataLoaded, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, startDims`

### Fields inherited from class ncsa.hdf.object.HObject

`linkTargetObjName, oid`

### Constructor Summary

Constructors
Constructor and Description
`H4Vdata(FileFormat theFile, java.lang.String name, java.lang.String path)`
`H4Vdata(FileFormat theFile, java.lang.String name, java.lang.String path, long[] oid)` Creates an H4Vdata object with specific name and path.

### Method Summary

Methods
`void` `close(int vsid)` Closes access to the object.
`Datatype` `getDatatype()` Returns the datatype object of the dataset.
`int` `getFieldCount()` Returns the number of fields.
`int[]` `getFieldOrders()` Returns the orders of fields
`java.util.List` `getMetadata()` Retrieves the metadata such as attributes from file.
`java.util.List` `getMetadata(int... attrPropList)`
`int` `getRecordCount()` Returns the number of records.
`boolean` `hasAttribute()` Check if the object has any attributes attached.
`void` `init()` Initializes the H4Vdata such as dimension sizes of this dataset.
`int` `open()` Opens an existing object such as dataset or group for access.
`java.lang.Object` `read()` Reads the data from file.
`byte[]` `readBytes()` Reads the raw data of the dataset from file to a byte array.
`void` `removeMetadata(java.lang.Object info)` Deletes an existing metadata from this data object.
`void` `write(java.lang.Object buf)` Writes a memory buffer to the dataset in file.
`void` `writeMetadata(java.lang.Object info)` Writes a specific metadata (such as attribute) into file.

### Methods inherited from class ncsa.hdf.object.CompoundDS

`copy, getMemberCount, getMemberNames, getMemberOrders, getMemberTypes, getMemeberDims, getSelectedMemberCount, getSelectedMemberOrders, getSelectedMemberTypes, isMemberSelected, selectMember, setMemberSelection`

### Methods inherited from class ncsa.hdf.object.Dataset

`byteToString, clear, clearData, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDimNames, getDims, getHeight, getMaxDims, getRank, getSelectedDims, getSelectedIndex, getSize, getStartDims, getStride, getWidth, isEnumConverted, isString, setConvertByteToString, setData, setEnumConverted, stringToByte, write`

### Methods inherited from class ncsa.hdf.object.HObject

`debug, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setLinkTargetObjName, setName, setPath, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### H4Vdata

    public H4Vdata(FileFormat theFile,
           java.lang.String name,
           java.lang.String path)

#### H4Vdata

    public H4Vdata(FileFormat theFile,
           java.lang.String name,
           java.lang.String path,
           long[] oid)

Creates an H4Vdata object with specific name and path.

Parameters:
  `theFile` - the HDF file.
  `name` - the name of this H4Vdata.
  `path` - the full path of this H4Vdata.
  `oid` - the unique identifier of this data object.

### Method Detail

#### hasAttribute

    public boolean hasAttribute()

Description copied from interface: `DataFormat`
Check if the object has any attributes attached.

Returns:
  true if it has any attribute(s), false otherwise.

#### getDatatype

    public Datatype getDatatype()

Description copied from class: `Dataset`
Returns the datatype object of the dataset.

Specified by:
  `getDatatype` in class `Dataset`
Returns:
  the datatype object of the dataset.

#### readBytes

    public byte[] readBytes()
                     throws HDFException

Description copied from class: `Dataset`
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.

Specified by:
  `readBytes` in class `Dataset`
Returns:
  the byte array of the raw data.
Throws:
  `HDFException`

#### read

    public java.lang.Object read()
                          throws HDFException

Description copied from class: `Dataset`
Reads the data from file.

read() reads the data from file to a memory buffer and returns the memory buffer. The dataset object does not hold the memobry buffer. To store the memory buffer in the dataset object, one must call getData().

By default, the whole dataset is read into memory. Users can also select subset to read. Subsetting is done in an implicit way.

How to Select a Subset

A selection is specified by three arrays: start, stride and count.

1. start: offset of a selection
2. stride: determining how many elements to move in each dimension
3. count: number of elements to select in each dimension

getStartDims(), getStartDims() and getSelectedDims() returns the start, stride and count arrays respectively. Applications can make a selection by changing the values of the arrays.

The following example shows how to make a subset. In the example, the dataset is a 4-dimensional array 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 point 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 < rank; i++) {
         start[i] = 0;
         selected[i] = 1;
         stride[i] = 1;
     }

     // set stride to 2 on dim1 and dim2 so that every other data points are selected.
     stride[1] = 2;
     stride[2] = 2;

     // set the selection size of dim1 and dim2
     selected[1] = dims[1] / stride[1];
     selected[2] = dims[1] / stride[2];

     // when dataset.getData() is called, the slection above will be used since
     // the dimension arrays are passed by reference. Changes of these arrays
     // outside the dataset object directly change the values of these array
     // in the dataset object.

For ScalarDS, the memory data buffer is an one-dimensional array of byte, short, int, float, double or String type based on the datatype of the dataset.

For CompoundDS, the meory data object is an java.util.List object. Each element of the list is a data array that corresponds to a compound field.

For example, if compound dataset "comp" has the following nested structure, and memeber datatypes

     comp --> m01 (int)
     comp --> m02 (float)
     comp --> nest1 --> m11 (char)
     comp --> nest1 --> m12 (String)
     comp --> nest1 --> nest2 --> m21 (long)
     comp --> nest1 --> nest2 --> m22 (double)

getData() returns a list of six arrays: {int[], float[], char[], Stirng[], long[] and double[]}.

Specified by:
  `read` in class `Dataset`
Returns:
  the data read from file.
Throws:
  `HDFException`
See Also:
  `#getData()}`

#### write

    public void write(java.lang.Object buf)
               throws HDFException

Description copied from class: `Dataset`
Writes a memory buffer to the dataset in file.

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

#### getMetadata

    public java.util.List getMetadata()
                               throws HDFException

Description copied from interface: `DataFormat`
Retrieves the metadata such as attributes from file.

Metadata such as attributes are stored in a List.

Returns:
  the list of metadata objects.
Throws:
  `HDFException`

#### writeMetadata

    public void writeMetadata(java.lang.Object info)
                       throws java.lang.Exception

Description copied from interface: `DataFormat`
Writes a specific metadata (such as attribute) into file.

If an HDF(4&5) attribute exists in file, the method updates its value. If the attribute does not exists in file, it creates the attribute in file and attaches it to the object. It will fail to write a new attribute to the object where an attribute with the same name already exists. To update the value of an existing attribute in file, one needs to get the instance of the attribute by getMetadata(), change its values, and use writeMetadata() to write the value.

Parameters:
  `info` - the metadata to write.
Throws:
  `java.lang.Exception`

#### removeMetadata

    public void removeMetadata(java.lang.Object info)
                        throws HDFException

Description copied from interface: `DataFormat`
Deletes an existing metadata from this data object.

Parameters:
  `info` - the metadata to delete.
Throws:
  `HDFException`

#### open

    public int open()

Description copied from class: `HObject`
Opens an existing object such as dataset or group for access. The return value is an object identifier obtained by implementing classes such as H5.H5Dopen(). This function is needed to allow other objects to be able to access the object. For instance, H5File class uses the open() function to obtain object identifier for copyAttributes(int src_id, int dst_id) and other purposes. The open() function should be used in pair with close(int) function.

Specified by:
  `open` in class `HObject`
Returns:
  the object identifier if successful; otherwise returns a negative value.
See Also:
  `HObject.close(int)`

#### close

    public void close(int vsid)

Description copied from class: `HObject`
Closes access to the object.

Sub-classes must implement this interface because different data objects have their own ways of how the data resources are closed.

For example, H5Group.close() calls the ncsa.hdf.hdf5lib.H5.H5Gclose() method and closes the group resource specified by the group id.

Specified by:
  `close` in class `HObject`
Parameters:
  `vsid` - The object identifier.

#### init

    public void init()

Initializes the H4Vdata such as dimension sizes of this dataset.

Specified by:
  `init` in class `Dataset`

#### getRecordCount

    public int getRecordCount()

Returns the number of records.

#### getFieldCount

    public int getFieldCount()

Returns the number of fields.

#### getFieldOrders

    public int[] getFieldOrders()

Returns the orders of fields

#### getMetadata

    public java.util.List getMetadata(int... attrPropList)
                               throws java.lang.Exception

Throws:
  `java.lang.Exception`