hdf.object.h5

## Class H5CompoundDS

- Object
- - hdf.object.HObject
  - - hdf.object.Dataset
    - - hdf.object.CompoundDS
      - - hdf.object.h5.H5CompoundDS

- All Implemented Interfaces:
    CompoundDataFormat, DataFormat, MetaDataContainer, Serializable

      public class H5CompoundDS
      extends CompoundDS

  The H5CompoundDS class defines an HDF5 dataset of compound datatypes.

  An HDF5 dataset is an object composed of a collection of data elements, or raw data, and metadata that stores a description of the data elements, data layout, and all other information necessary to write, read, and interpret the stored data.

  A HDF5 compound datatype is similar to a struct in C or a common block in Fortran: it is a collection of one or more atomic types or small arrays of such types. Each member of a compound type has a name which is unique within that type, and a byte offset that determines the first byte (smallest byte address) of that member in a compound datum.

  For more information on HDF5 datasets and datatypes, read the HDF5 User's Guide.

  There are two basic types of compound datasets: simple compound data and nested compound data. Members of a simple compound dataset have atomic datatypes. Members of a nested compound dataset are compound or array of compound data.

  Since Java does not understand C structures, we cannot directly read/write compound data values as in the following C example.

       typedef struct s1_t {
               int    a;
               float  b;
               double c;
               } s1_t;
           s1_t       s1[LENGTH];
           ...
           H5Dwrite(..., s1);
           H5Dread(..., s1);

  Values of compound data fields are stored in java.util.Vector object. We read and write compound data by fields instead of compound structure. As for the example above, the java.util.Vector object has three elements: int[LENGTH], float[LENGTH] and double[LENGTH]. Since Java understands the primitive datatypes of int, float and double, we will be able to read/write the compound data by field.
  Version:
    1.1 9/4/2007
  Author:
    Peter X. Cao
  See Also:
    Serialized Form

- - ### Field Summary

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

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

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

      `chunkSize, compression, compression_gzip_txt, convertByteToString, convertedBuf, data, datatype, dimNames, dims, filters, inited, isDataLoaded, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, startDims, storage, storage_layout`

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

      `fileFormat, linkTargetObjName, oid`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `H5CompoundDS(FileFormat theFile, String theName, String thePath)` Constructs an instance of a HDF5 compound dataset with given file, dataset name and path.
    `H5CompoundDS(FileFormat theFile, String theName, String thePath, long[] oid)` Deprecated. Not for public use in the future. Using `H5CompoundDS(FileFormat, String, String)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears memory held by the dataset, such as the data buffer.
    `void` | `close(long did)` Closes access to the object.
    `Object` | `convertFromUnsignedC()` Converts the data values of this data object to appropriate Java integers if they are unsigned integers.
    `Object` | `convertToUnsignedC()` Converts Java integer data values of this data object back to unsigned C-type integer data if they are unsigned integers.
    `static Dataset` | `create(String name, Group pgroup, long[] dims, long[] maxdims, long[] chunks, int gzip, String[] memberNames, Datatype[] memberDatatypes, int[] memberRanks, long[][] memberDims, Object data)` Creates a simple compound dataset in a file with/without chunking and compression.
    `static Dataset` | `create(String name, Group pgroup, long[] dims, String[] memberNames, Datatype[] memberDatatypes, int[] memberRanks, long[][] memberDims, Object data)` Deprecated. Not for public use in the future. Using `create(String, Group, long[], long[], long[], int, String[], Datatype[], int[], long[][], Object)`
    `static Dataset` | `create(String name, Group pgroup, long[] dims, String[] memberNames, Datatype[] memberDatatypes, int[] memberSizes, Object data)` Deprecated. Not for public use in the future. Using `create(String, Group, long[], long[], long[], int, String[], Datatype[], int[], long[][], Object)`
    `Datatype` | `getDatatype()` Returns the datatype of the data object.
    `Object` | `getFillValue()` Returns the fill values for the data object.
    `List<Attribute>` | `getMetadata()` Retrieves the object's metadata, such as attributes, from the file.
    `List<Attribute>` | `getMetadata(int... attrPropList)`
    `long` | `getSize(long tid)` Returns the size in bytes of a given datatype.
    `String` | `getVirtualFilename(int index)`
    `int` | `getVirtualMaps()`
    `boolean` | `hasAttribute()` Check if the object has any attributes attached.
    `void` | `init()` Retrieves datatype and dataspace information from file and sets the dataset in memory.
    `boolean` | `isString(long tid)` Checks if a given datatype is a string.
    `boolean` | `isVirtual()`
    `long` | `open()` Opens an existing object such as a dataset or group for access.
    `Object` | `read()` Reads the data from file.
    `byte[]` | `readBytes()` Reads the raw data of the dataset from file to a byte array.
    `void` | `removeMetadata(Object info)` Deletes an existing piece of metadata from this object.
    `void` | `setName(String newName)` Sets the name of the object.
    `void` | `updateMetadata(Object info)` Updates an existing piece of metadata attached to this object.
    `void` | `write(Object buf)` Writes the given data buffer into this dataset in a file.
    `void` | `writeMetadata(Object info)` Writes a specific piece of metadata (such as an attribute) into the file.

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

      `copy, getMemberCount, getMemberDims, getMemberNames, getMemberOrders, getMemberTypes, getSelectedMemberCount, getSelectedMemberOrders, getSelectedMemberTypes, isMemberSelected, selectMember, setAllMemberSelection`

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

      `byteToString, clearData, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDimNames, getDims, getFilters, getHeight, getMaxDims, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getStartDims, getStorage, getStorageLayout, getStride, getWidth, isInited, setConvertByteToString, setData, stringToByte, write`

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

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

    - ### Methods inherited from class Object

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

    - ### Methods inherited from interface hdf.object.DataFormat

      `clearData, getCompression, getData, getDims, getHeight, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getStartDims, getStride, getWidth, isInited, setData, write`

- - ### Constructor Detail

    - #### H5CompoundDS

          public H5CompoundDS(FileFormat theFile,
                              String theName,
                              String thePath)

      Constructs an instance of a HDF5 compound dataset with given file, dataset name and path.

      The dataset object represents an existing dataset in the file. For example, new H5CompoundDS(file, "dset1", "/g0/") constructs a dataset object that corresponds to the dataset,"dset1", at group "/g0/".

      This object is usually constructed at FileFormat.open(), which loads the file structure and object information into memory. It is rarely used elsewhere.

      Parameters:
        `theFile` - the file that contains the data object.
        `theName` - the name of the data object, e.g. "dset".
        `thePath` - the full path of the data object, e.g. "/arrays/".

    - #### H5CompoundDS

          @Deprecated
          public H5CompoundDS(FileFormat theFile,
                                          String theName,
                                          String thePath,
                                          long[] oid)

      Deprecated. Not for public use in the future.
      Using `H5CompoundDS(FileFormat, String, String)`
      Parameters:
        `theFile` - the file that contains the data object.
        `theName` - the name of the data object, e.g. "dset".
        `thePath` - the full path of the data object, e.g. "/arrays/".
        `oid` - the oid of the data object.

  - ### Method Detail

    - #### open

          public long open()

      Description copied from class: `HObject`
      Opens an existing object such as a 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(long src_id, long dst_id) and other purposes. The open() function should be used in pair with close(long) function.
      Specified by:
        `open` in class `HObject`
      Returns:
        the object identifier if successful; otherwise returns a negative value.
      See Also:
        `HObject.close(long)`

    - #### close

          public void close(long did)

      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 hdf.hdf5lib.H5.H5Gclose() method and closes the group resource specified by the group id.

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

    - #### init

          public void init()

      Retrieves datatype and dataspace information from file and sets the dataset in memory.

      The init() is designed to support lazy operation in a dataset object. When a data object is retrieved from file, the datatype, dataspace and raw data are not loaded into memory. When it is asked to read the raw data from file, init() is first called to get the datatype and dataspace information, then load the raw data from file.

      init() is also used to reset the selection of a dataset (start, stride and count) to the default, which is the entire dataset for 1D or 2D datasets. In the following example, init() at step 1) retrieves datatype and dataspace information from file. getData() at step 3) reads only one data point. init() at step 4) resets the selection to the whole dataset. getData() at step 4) reads the values of whole dataset into memory.

           dset = (Dataset) file.get(NAME_DATASET);

           // 1) get datatype and dataspace information from file
           dset.init();
           rank = dset.getRank(); // rank = 2, a 2D dataset
           count = dset.getSelectedDims();
           start = dset.getStartDims();
           dims = dset.getDims();

           // 2) select only one data point
           for (int i = 0; i < rank; i++) {
               start[0] = 0;
               count[i] = 1;
           }

           // 3) read one data point
           data = dset.getData();

           // 4) reset selection to the whole dataset
           dset.init();

           // 5) clean the memory data buffer
           dset.clearData();

           // 6) Read the whole dataset
           data = dset.getData();

    - #### hasAttribute

          public boolean hasAttribute()

      Description copied from interface: `MetaDataContainer`
      Check if the object has any attributes attached.
      Returns:
        true if it has any attributes, false otherwise.

    - #### getDatatype

          public Datatype getDatatype()

      Description copied from interface: `DataFormat`
      Returns the datatype of the data object.
      Specified by:
        `getDatatype` in interface `DataFormat`
      Overrides:
        `getDatatype` in class `Dataset`
      Returns:
        the datatype of the data object.

    - #### getFillValue

          public Object getFillValue()

      Description copied from interface: `DataFormat`
      Returns the fill values for the data object.
      Returns:
        the fill values for the data object.

    - #### clear

          public void clear()

      Description copied from class: `Dataset`
      Clears memory held by the dataset, such as the data buffer.
      Overrides:
        `clear` in class `Dataset`

    - #### readBytes

          public byte[] readBytes()
                           throws hdf.hdf5lib.exceptions.HDF5Exception

      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 a one-dimension 32-bit integer dataset of size 5, readBytes() returns 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:
        `hdf.hdf5lib.exceptions.HDF5Exception`

    - #### read

          public Object read()
                      throws Exception

      Description copied from interface: `DataFormat`
      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 memory 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 a subset to read. Subsetting is done in an implicit way.

      Returns:
        the data read from file.
      Throws:
        `Exception` - if object can not be read
      See Also:
        `DataFormat.getData()`

    - #### write

          public void write(Object buf)
                     throws hdf.hdf5lib.exceptions.HDF5Exception

      Writes the given data buffer into this dataset in a file.

      The data buffer is a vector that contains the data values of compound fields. The data is written into file field by field.

      Parameters:
        `buf` - The vector that contains the data values of compound fields.
      Throws:
        `hdf.hdf5lib.exceptions.HDF5Exception` - If there is an error at the HDF5 library level.

    - #### convertFromUnsignedC

          public Object convertFromUnsignedC()

      Description copied from interface: `DataFormat`
      Converts the data values of this data object to appropriate Java integers if they are unsigned integers.
      Returns:
        the converted data buffer.
      See Also:
        `Dataset.convertToUnsignedC(Object)`, `Dataset.convertFromUnsignedC(Object, Object)`

    - #### convertToUnsignedC

          public Object convertToUnsignedC()

      Description copied from interface: `DataFormat`
      Converts Java integer data values of this data object back to unsigned C-type integer data if they are unsigned integers.
      Returns:
        the converted data buffer.
      See Also:
        `Dataset.convertToUnsignedC(Object)`, `Dataset.convertToUnsignedC(Object, Object)`

    - #### getMetadata

          public List<Attribute> getMetadata()
                                      throws hdf.hdf5lib.exceptions.HDF5Exception

      Description copied from interface: `MetaDataContainer`
      Retrieves the object's metadata, such as attributes, from the file.

      Metadata, such as attributes, is stored in a List.

      Returns:
        the list of metadata objects.
      Throws:
        `hdf.hdf5lib.exceptions.HDF5Exception`

    - #### getMetadata

          public List<Attribute> getMetadata(int... attrPropList)
                                      throws hdf.hdf5lib.exceptions.HDF5Exception

      Throws:
        `hdf.hdf5lib.exceptions.HDF5Exception`

    - #### writeMetadata

          public void writeMetadata(Object info)
                             throws Exception

      Description copied from interface: `MetaDataContainer`
      Writes a specific piece of metadata (such as an attribute) into the file. If an HDF(4&5) attribute exists in the file, this method updates its value. If the attribute does not exist in the file, it creates the attribute in the 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 the file, one needs to get the instance of the attribute by getMetadata(), change its values, then use writeMetadata() to write the value.
      Parameters:
        `info` - the metadata to write.
      Throws:
        `Exception` - if the metadata can not be written

    - #### removeMetadata

          public void removeMetadata(Object info)
                              throws hdf.hdf5lib.exceptions.HDF5Exception

      Description copied from interface: `MetaDataContainer`
      Deletes an existing piece of metadata from this object.
      Parameters:
        `info` - the metadata to delete.
      Throws:
        `hdf.hdf5lib.exceptions.HDF5Exception`

    - #### updateMetadata

          public void updateMetadata(Object info)
                              throws hdf.hdf5lib.exceptions.HDF5Exception

      Description copied from interface: `MetaDataContainer`
      Updates an existing piece of metadata attached to this object.
      Parameters:
        `info` - the metadata to update.
      Throws:
        `hdf.hdf5lib.exceptions.HDF5Exception`

    - #### setName

          public void setName(String newName)
                       throws Exception

      Description copied from class: `HObject`
      Sets the name of the object. setName (String newName) changes the name of the object in the file.
      Overrides:
        `setName` in class `HObject`
      Parameters:
        `newName` - The new name of the object.
      Throws:
        `Exception` - if name is root or contains separator

    - #### create

          @Deprecated
          public static Dataset create(String name,
                                                   Group pgroup,
                                                   long[] dims,
                                                   String[] memberNames,
                                                   Datatype[] memberDatatypes,
                                                   int[] memberSizes,
                                                   Object data)
                                            throws Exception

      Deprecated. Not for public use in the future.
      Using `create(String, Group, long[], long[], long[], int, String[], Datatype[], int[], long[][], Object)`
      Parameters:
        `name` - the name of the dataset to create.
        `pgroup` - parent group where the new dataset is created.
        `dims` - the dimension size of the dataset.
        `memberNames` - the names of compound datatype
        `memberDatatypes` - the datatypes of the compound datatype
        `memberSizes` - the dim sizes of the members
        `data` - list of data arrays written to the new dataset, null if no data is written to the new dataset.
      Returns:
        the new compound dataset if successful; otherwise returns null.
      Throws:
        `Exception` - if there is a failure.

    - #### create

          @Deprecated
          public static Dataset create(String name,
                                                   Group pgroup,
                                                   long[] dims,
                                                   String[] memberNames,
                                                   Datatype[] memberDatatypes,
                                                   int[] memberRanks,
                                                   long[][] memberDims,
                                                   Object data)
                                            throws Exception

      Deprecated. Not for public use in the future.
      Using `create(String, Group, long[], long[], long[], int, String[], Datatype[], int[], long[][], Object)`
      Parameters:
        `name` - the name of the dataset to create.
        `pgroup` - parent group where the new dataset is created.
        `dims` - the dimension size of the dataset.
        `memberNames` - the names of compound datatype
        `memberDatatypes` - the datatypes of the compound datatype
        `memberRanks` - the ranks of the members
        `memberDims` - the dim sizes of the members
        `data` - list of data arrays written to the new dataset, null if no data is written to the new dataset.
      Returns:
        the new compound dataset if successful; otherwise returns null.
      Throws:
        `Exception` - if the dataset can not be created.

    - #### create

          public static Dataset create(String name,
                                       Group pgroup,
                                       long[] dims,
                                       long[] maxdims,
                                       long[] chunks,
                                       int gzip,
                                       String[] memberNames,
                                       Datatype[] memberDatatypes,
                                       int[] memberRanks,
                                       long[][] memberDims,
                                       Object data)
                                throws Exception

      Creates a simple compound dataset in a file with/without chunking and compression.

      This function provides an easy way to create a simple compound dataset in file by hiding tedious details of creating a compound dataset from users.

      This function calls H5.H5Dcreate() to create a simple compound dataset in file. Nested compound dataset is not supported. The required information to create a compound dataset includes the name, the parent group and data space of the dataset, the names, datatypes and data spaces of the compound fields. Other information such as chunks, compression and the data buffer is optional.

      The following example shows how to use this function to create a compound dataset in file.

           H5File file = null;
           String message = "";
           Group pgroup = null;
           int[] DATA_INT = new int[DIM_SIZE];
           float[] DATA_FLOAT = new float[DIM_SIZE];
           String[] DATA_STR = new String[DIM_SIZE];
           long[] DIMs = { 50, 10 };
           long[] CHUNKs = { 25, 5 };

           try {
               file = (H5File) H5FILE.open(fname, H5File.CREATE);
               file.open();
               pgroup = (Group) file.get("/");
           }
           catch (Exception ex) {
           }

           Vector data = new Vector();
           data.add(0, DATA_INT);
           data.add(1, DATA_FLOAT);
           data.add(2, DATA_STR);

           // create groups
           Datatype[] mdtypes = new H5Datatype[3];
           String[] mnames = { "int", "float", "string" };
           Dataset dset = null;
           try {
               mdtypes[0] = new H5Datatype(Datatype.CLASS_INTEGER, 4, -1, -1);
               mdtypes[1] = new H5Datatype(Datatype.CLASS_FLOAT, 4, -1, -1);
               mdtypes[2] = new H5Datatype(Datatype.CLASS_STRING, STR_LEN, -1, -1);
               dset = file.createCompoundDS("/CompoundDS", pgroup, DIMs, null, CHUNKs, 9, mnames, mdtypes, null, data);
           }
           catch (Exception ex) {
               failed(message, ex, file);
               return 1;
           }

      Parameters:
        `name` - the name of the dataset to create.
        `pgroup` - parent group where the new dataset is created.
        `dims` - the dimension size of the dataset.
        `maxdims` - the max dimension size of the dataset. maxdims is set to dims if maxdims = null.
        `chunks` - the chunk size of the dataset. No chunking if chunk = null.
        `gzip` - GZIP compression level (1 to 9). 0 or negative values if no compression.
        `memberNames` - the names of compound datatype
        `memberDatatypes` - the datatypes of the compound datatype
        `memberRanks` - the ranks of the members
        `memberDims` - the dim sizes of the members
        `data` - list of data arrays written to the new dataset, null if no data is written to the new dataset.
      Returns:
        the new compound dataset if successful; otherwise returns null.
      Throws:
        `Exception` - if there is a failure.

    - #### isString

          public boolean isString(long tid)

      Description copied from class: `Dataset`
      Checks if a given datatype is a string. Sub-classes must replace this default implementation.
      Overrides:
        `isString` in class `Dataset`
      Parameters:
        `tid` - The data type identifier.
      Returns:
        true if the datatype is a string; otherwise returns false.

    - #### getSize

          public long getSize(long tid)

      Description copied from class: `Dataset`
      Returns the size in bytes of a given datatype. Sub-classes must replace this default implementation.
      Overrides:
        `getSize` in class `Dataset`
      Parameters:
        `tid` - The data type identifier.
      Returns:
        The size of the datatype

    - #### isVirtual

          public boolean isVirtual()

      Overrides:
        `isVirtual` in class `Dataset`

    - #### getVirtualFilename

          public String getVirtualFilename(int index)

      Overrides:
        `getVirtualFilename` in class `Dataset`

    - #### getVirtualMaps

          public int getVirtualMaps()

      Overrides:
        `getVirtualMaps` in class `Dataset`

Copyright © 2018. All Rights Reserved.