Object
hdf.object.HObject
hdf.object.Dataset
hdf.object.CompoundDS
hdf.object.h4.H4Vdata
- All Implemented Interfaces:
CompoundDataFormat
,DataFormat
,MetaDataContainer
,Serializable
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 reading, writing and subsetting 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 point in dims[1] and dims[2]
We want to select every other data point in dims[1] and dims[2]
int rank = dataset.getRank(); // number of dimensions 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 offset 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 point is 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 selection 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.
- Version:
- 1.1 9/4/2007
- Author:
- Peter X. Cao
- See Also:
-
Field Summary
Fields inherited from class hdf.object.CompoundDS
flatNameList, flatTypeList, 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, isImage, isNULL, isScalar, isText, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, space_type, startDims, storage, storageLayout
Fields inherited from class hdf.object.HObject
fileFormat, linkTargetObjName, oid
-
Constructor Summary
ConstructorDescriptionH4Vdata
(FileFormat theFile, String name, String path) Creates an H4Vdata object with specific name and path.H4Vdata
(FileFormat theFile, String name, String path, long[] oid) Creates an H4Vdata object with specific name, path and oid. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(long vsid) Closes access to the object.Converts the data values of this data object to appropriate Java integers if they are unsigned integers.Converts Java integer data values of this data object back to unsigned C-type integer data if they are unsigned integers.Creates a new dataset and writes the data buffer to the new dataset.Returns the datatype of the data object.int
Returns the number of fields.int[]
Returns the orders of fieldsReturns the fill values for the data object.Retrieves the object's metadata, such as attributes, from the file.getMetadata
(int... attrPropList) Retrieves the object's metadata, such as attributes, from the file.int
Returns the number of records.boolean
Check if the object has any attributes attached.void
init()
Initializes the H4Vdata such as dimension sizes of this dataset.long
open()
Opens an existing object such as a dataset or group for access.read()
Reads the data from file.byte[]
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
updateMetadata
(Object info) Updates an existing piece of metadata attached to this object.void
Writes a memory buffer to the object in the 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
convertByteMember, convertCompoundByteMembers, getMemberCount, getMemberDims, getMemberNames, getMemberOrders, getMemberTypes, getSelectedMemberCount, getSelectedMemberNames, getSelectedMemberOrders, getSelectedMemberTypes, isMemberSelected, resetSelection, selectMember, setAllMemberSelection
Methods inherited from class hdf.object.Dataset
byteToString, clear, clearData, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDepth, getDimNames, getDims, getFilters, getHeight, getMaxDims, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getSize, getSpaceType, getStartDims, getStorage, getStorageLayout, getStride, getVirtualFilename, getVirtualMaps, getWidth, isInited, isNULL, isScalar, isString, isVirtual, refreshData, setConvertByteToString, setData, stringToByte, toString, toString, toString, write
Methods inherited from class hdf.object.HObject
createFullname, debug, equals, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, hashCode, setFullname, setLinkTargetObjName, setName, setPath, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface hdf.object.DataFormat
clearData, getCompression, getData, getDepth, getDims, getHeight, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getSpaceType, getStartDims, getStride, getWidth, isInited, refreshData, setData, write
Methods inherited from interface hdf.object.MetaDataContainer
clear
-
Constructor Details
-
H4Vdata
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.
-
H4Vdata
Creates an H4Vdata object with specific name, path and oid.- 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 Details
-
hasAttribute
Description copied from interface:MetaDataContainer
Check if the object has any attributes attached.- Specified by:
hasAttribute
in interfaceMetaDataContainer
- Returns:
- true if it has any attributes, false otherwise.
-
getDatatype
Returns the datatype of the data object.- Specified by:
getDatatype
in interfaceDataFormat
- Overrides:
getDatatype
in classDataset
- Returns:
- the datatype of the data object.
-
getFillValue
Returns the fill values for the data object.- Specified by:
getFillValue
in interfaceDataFormat
- Overrides:
getFillValue
in classCompoundDS
- Returns:
- the fill values for the data object.
-
readBytes
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. -
read
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.- Specified by:
read
in interfaceDataFormat
- Returns:
- the data read from file.
- Throws:
hdf.hdflib.HDFException
- if object can not be readOutOfMemoryError
- if memory is exhausted- See Also:
-
write
Writes a memory buffer to the object in the file.- Specified by:
write
in interfaceDataFormat
- Parameters:
buf
- the data to write- Throws:
hdf.hdflib.HDFException
- if data can not be written
-
convertFromUnsignedC
Converts the data values of this data object to appropriate Java integers if they are unsigned integers.- Specified by:
convertFromUnsignedC
in interfaceDataFormat
- Returns:
- the converted data buffer.
- See Also:
-
convertToUnsignedC
Converts Java integer data values of this data object back to unsigned C-type integer data if they are unsigned integers.- Specified by:
convertToUnsignedC
in interfaceDataFormat
- Returns:
- the converted data buffer.
- See Also:
-
getMetadata
Retrieves the object's metadata, such as attributes, from the file. Metadata, such as attributes, is stored in a List.- Specified by:
getMetadata
in interfaceMetaDataContainer
- Returns:
- the list of metadata objects.
- Throws:
hdf.hdflib.HDFException
- if the metadata can not be retrieved
-
writeMetadata
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.- Specified by:
writeMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to write.- Throws:
Exception
- if the metadata can not be written
-
removeMetadata
Deletes an existing piece of metadata from this object.- Specified by:
removeMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to delete.- Throws:
hdf.hdflib.HDFException
- if the metadata can not be removed
-
updateMetadata
Updates an existing piece of metadata attached to this object.- Specified by:
updateMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to update.- Throws:
Exception
- if the metadata can not be updated
-
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. -
close
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. -
init
Initializes the H4Vdata such as dimension sizes of this dataset.- Specified by:
init
in interfaceDataFormat
-
getRecordCount
-
getFieldCount
-
getFieldOrders
-
getMetadata
Retrieves the object's metadata, such as attributes, from the file. Metadata, such as attributes, is stored in a List.- Parameters:
attrPropList
- the list of properties to get- Returns:
- the list of metadata objects.
- Throws:
Exception
- if the metadata can not be retrieved
-
copy
Description copied from class:Dataset
Creates a new dataset and writes the data buffer to the new dataset. This function allows applications to create a new dataset for a given data buffer. For example, users can select a specific interesting part from a large image and create a new image with the selection. The new dataset retains the datatype and dataset creation properties of this dataset.- Overrides:
copy
in classCompoundDS
- Parameters:
pgroup
- the group which the dataset is copied to.name
- the name of the new dataset.dims
- the dimension sizes of the the new dataset.data
- the data values of the subset to be copied.- Returns:
- the new dataset.
- Throws:
Exception
- if dataset can not be copied
-