public class H5File extends FileFormat
The HDF5 file structure is stored in a tree that is made up of Java TreeNode objects. Each tree node represents an HDF5 object: a Group, Dataset, or Named Datatype. Starting from the root of the tree, rootNode, the tree can be traversed to find a specific object.
The following example shows the implementation of finding an object for a given path in FileFormat. User applications can directly call the static method FileFormat.findObject(file, objPath) to get the object.
HObject findObject(FileFormat file, String path) { if (file == null || path == null) return null; if (!path.endsWith("/")) path = path + "/"; DefaultMutableTreeNode theRoot = (DefaultMutableTreeNode) file .getRootNode(); if (theRoot == null) return null; else if (path.equals("/")) return (HObject) theRoot.getUserObject(); Enumeration local_enum = ((DefaultMutableTreeNode) theRoot) .breadthFirstEnumeration(); DefaultMutableTreeNode theNode = null; HObject theObj = null; while (local_enum.hasMoreElements()) { theNode = (DefaultMutableTreeNode) local_enum.nextElement(); theObj = (HObject) theNode.getUserObject(); String fullPath = theObj.getFullName() + "/"; if (path.equals(fullPath) && theObj.getPath() != null ) { break; } return theObj; }
CREATE, fid, FILE_CREATE_DELETE, FILE_CREATE_EARLY_LIB, FILE_CREATE_OPEN, FILE_OBJ_SEP, FILE_TYPE_HDF4, FILE_TYPE_HDF5, fullFileName, isReadOnly, OPEN_NEW, READ, WRITE
pathSeparator, pathSeparatorChar, separator, separatorChar
Constructor and Description |
---|
H5File()
Constructs an H5File instance with an empty file name and read-only access.
|
H5File(String fileName)
Constructs an H5File instance with specified file name and read/write access.
|
H5File(String fileName,
int access)
Constructs an H5File instance with specified file name and access.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes file associated with this H5File instance.
|
TreeNode |
copy(HObject srcObj,
Group dstGroup,
String dstName)
Copies the source object to a new destination.
|
static void |
copyAttributes(HObject src,
HObject dst)
Copies the attributes of one object to another object.
|
static void |
copyAttributes(int src_id,
int dst_id)
Copies the attributes of one object to another object.
|
Dataset |
createCompoundDS(String name,
Group pgroup,
long[] dims,
long[] maxdims,
long[] chunks,
int gzip,
String[] memberNames,
Datatype[] memberDatatypes,
int[] memberSizes,
Object data)
Creates a new compound dataset in a file with/without chunking and
compression.
|
Datatype |
createDatatype(int tclass,
int tsize,
int torder,
int tsign)
Methods related to Datatypes and HObjects in HDF5 Files.
|
Datatype |
createDatatype(int tclass,
int tsize,
int torder,
int tsign,
Datatype tbase)
Creates a new datatype in memory.
|
Datatype |
createDatatype(int tclass,
int tsize,
int torder,
int tsign,
Datatype tbase,
String name)
Creates a named datatype in a file.
|
Datatype |
createDatatype(int tclass,
int tsize,
int torder,
int tsign,
String name)
Creates a named datatype in a file.
|
FileFormat |
createFile(String filename,
int createFlag)
Creates an HDF5 file with the specified name and returns a new H5File instance associated with the file.
|
int |
createGcpl(int creationorder,
int maxcompact,
int mindense)
Creates the group creation property list identifier, gcpl.
|
Group |
createGroup(String name,
Group pgroup)
Creates a new group with specified name in existing group.
|
Group |
createGroup(String name,
Group pgroup,
int... gplist)
Creates a new group with specified name in existing group and with the group creation properties list, gplist.
|
Dataset |
createImage(String name,
Group pgroup,
Datatype type,
long[] dims,
long[] maxdims,
long[] chunks,
int gzip,
int ncomp,
int interlace,
Object data)
Creates a new image in a file.
|
FileFormat |
createInstance(String filename,
int access)
Creates an H5File instance with specified file name and access.
|
HObject |
createLink(Group parentGroup,
String name,
HObject currentObj,
int lType)
Creates a link to an object in the open file.
|
HObject |
createLink(Group parentGroup,
String name,
Object currentObj)
Creates a link to an existing object in the open file.
|
HObject |
createLink(Group parentGroup,
String name,
String currentObj,
int lType)
Creates a soft or external link to object in a file that does not exist at the time the link is created.
|
Dataset |
createScalarDS(String name,
Group pgroup,
Datatype type,
long[] dims,
long[] maxdims,
long[] chunks,
int gzip,
Object fillValue,
Object data)
Creates a new dataset in a file with/without chunking/compression.
|
void |
delete(HObject obj)
Deletes an object from a file.
|
void |
exportDataset(String file_export_name,
String file_name,
String object_path,
int binary_order)
Export dataset.
|
HObject |
get(String path)
Gets the HObject with the specified path from the file.
|
static List<Attribute> |
getAttribute(int objID)
Returns a list of attributes for the specified object.
|
static List<Attribute> |
getAttribute(int objID,
int idx_type,
int order)
Returns a list of attributes for the specified object, in creation or alphabetical order.
|
int |
getIndexOrder() |
int |
getIndexOrder(String strorder) |
static int |
getIndexOrderValue(String strorder) |
int |
getIndexType() |
int |
getIndexType(String strtype) |
static int |
getIndexTypeValue(String strtype) |
int[] |
getLibBounds()
Gets the bounds of library versions.
|
String |
getLibversion()
Returns the version of the HDF5 library.
|
static String |
getLinkTargetName(HObject obj)
Retrieves the name of the target object that is being linked to.
|
TreeNode |
getRootNode()
Returns the root node of the open HDF5 File.
|
boolean |
isThisType(FileFormat theFile)
Checks if the specified FileFormat instance has the HDF5 format.
|
boolean |
isThisType(String filename)
Checks if the specified file has the HDF5 format.
|
int |
open()
Opens file and returns a file identifier.
|
int |
open(int... indexList)
Opens file and returns a file identifier.
|
int |
open(int plist)
Opens a file with specific file access property list.
|
void |
reloadTree(Group g)
reload the sub-tree structure from file.
|
void |
renameAttribute(HObject obj,
String oldAttrName,
String newAttrName)
Renames an attribute.
|
static void |
renameObject(HObject obj,
String newName)
Rename the given object
|
void |
setIndexOrder(int indexOrder) |
void |
setIndexType(int indexType) |
void |
setLibBounds(int low,
int high)
Sets the bounds of library versions.
|
static void |
updateReferenceDataset(H5File srcFile,
H5File dstFile)
Updates values of scalar dataset object references in copied file.
|
void |
writeAttribute(HObject obj,
Attribute attr,
boolean attrExisted)
Attaches a given attribute to an object.
|
addFileExtension, addFileFormat, copy, create, createCompoundDS, createScalarDS, findObject, findObject, getFID, getFileExtensions, getFileFormat, getFileFormatKeys, getFileFormats, getFilePath, getHObject, getHObject, getInstance, getMaxMembers, getNumberOfMembers, getStartMembers, isReadOnly, open, removeFileFormat, setMaxMembers, setStartMembers
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
public H5File()
public H5File(String fileName)
This constructor does not open the file for access, nor does it confirm that the file can be opened read/write.
fileName
- A valid file name, with a relative or absolute path.NullPointerException
- If the fileName
argument is null
.public H5File(String fileName, int access)
The access parameter values and corresponding behaviors:
This constructor does not open the file for access, nor does it confirm that the file can later be opened read/write or created.
The flag returned by FileFormat.isReadOnly()
is set to true if the access parameter value is READ, even though the
file isn't yet open.
fileName
- A valid file name, with a relative or absolute path.access
- The file access flag, which determines behavior when file is opened. Acceptable values are
READ, WRITE,
and CREATE
.NullPointerException
- If the fileName
argument is null
.public static final void copyAttributes(HObject src, HObject dst)
This method copies all the attributes from one object (source object) to another (destination object). If an attribute already exists in the destination object, the attribute will not be copied. Attribute names exceeding 256 characters will be truncated in the destination object.
The object can be an H5Group, an H5Dataset, or a named H5Datatype. This method is in the H5File class because there is no H5Object class and it is specific to HDF5 objects.
The copy can fail for a number of reasons, including an invalid source or destination object, but no exceptions
are thrown. The actual copy is carried out by the method: copyAttributes(int, int)
src
- The source object.dst
- The destination object.copyAttributes(int, int)
public static final void copyAttributes(int src_id, int dst_id)
This method copies all the attributes from one object (source object) to another (destination object). If an attribute already exists in the destination object, the attribute will not be copied. Attribute names exceeding 256 characters will be truncated in the destination object.
The object can be an H5Group, an H5Dataset, or a named H5Datatype. This method is in the H5File class because there is no H5Object class and it is specific to HDF5 objects.
The copy can fail for a number of reasons, including an invalid source or destination object identifier, but no exceptions are thrown.
src_id
- The identifier of the source object.dst_id
- The identifier of the destination object.public static final List<Attribute> getAttribute(int objID) throws hdf.hdf5lib.exceptions.HDF5Exception
This method returns a list containing the attributes associated with the identified object. If there are no associated attributes, an empty list will be returned.
Attribute names exceeding 256 characters will be truncated in the returned list.
objID
- The identifier for the object whose attributes are to be returned.hdf.hdf5lib.exceptions.HDF5Exception
- If an underlying HDF library routine is unable to perform a step necessary to retrieve the
attributes. A variety of failures throw this exception.getAttribute(int,int,int)
public static final List<Attribute> getAttribute(int objID, int idx_type, int order) throws hdf.hdf5lib.exceptions.HDF5Exception
This method returns a list containing the attributes associated with the identified object. If there are no associated attributes, an empty list will be returned. The list of attributes returned can be in increasing or decreasing, creation or alphabetical order.
Attribute names exceeding 256 characters will be truncated in the returned list.
objID
- The identifier for the object whose attributes are to be returned.idx_type
- The type of index. Valid values are:
order
- The index traversal order. Valid values are:
hdf.hdf5lib.exceptions.HDF5Exception
- If an underlying HDF library routine is unable to perform a step necessary to retrieve the
attributes. A variety of failures throw this exception.public static final void updateReferenceDataset(H5File srcFile, H5File dstFile) throws Exception
This method has very specific functionality as documented below, and the user is advised to pay close attention when dealing with files that contain references.
When a copy is made from one HDF file to another, object references and dataset region references are copied, but the references in the destination file are not updated by the copy and are therefore invalid.
When an entire file is copied, this method updates the values of the object references and dataset region references that are in scalar datasets in the destination file so that they point to the correct object(s) in the destination file. The method does not update references that occur in objects other than scalar datasets.
In the current release, the updating of object references is not handled completely as it was not required by the projects that funded development. There is no support for updates when the copy does not include the entire file. Nor is there support for updating objects other than scalar datasets in full-file copies. This functionality will be extended as funding becomes available or, possibly, when the underlying HDF library supports the reference updates itself.
srcFile
- The file that was copied.dstFile
- The destination file where the object references will be updated.Exception
- If there is a problem in the update process.public String getLibversion()
getLibversion
in class FileFormat
FileFormat.getLibversion()
public boolean isThisType(FileFormat theFile)
isThisType
in class FileFormat
theFile
- The FileFormat to be checked.FileFormat.isThisType(hdf.object.FileFormat)
public boolean isThisType(String filename)
isThisType
in class FileFormat
filename
- The name of the file to be checked.FileFormat.isThisType(java.lang.String)
public FileFormat createFile(String filename, int createFlag) throws Exception
createFile
in class FileFormat
filename
- The filename; a pathname string.createFlag
- The creation flag, which determines behavior when the file
already exists. Acceptable values are
FILE_CREATE_DELETE
and
FILE_CREATE_OPEN
.Exception
- If the file cannot be created or if createFlag has unexpected value.FileFormat.createFile(java.lang.String, int)
,
H5File(String, int)
public FileFormat createInstance(String filename, int access) throws Exception
createInstance
in class FileFormat
filename
- The filename; a pathname string.access
- The file access flag, which determines behavior when file is
opened. Acceptable values are READ, WRITE,
and
CREATE
.Exception
- If there is a failure.FileFormat.createInstance(java.lang.String, int)
,
H5File(String, int)
public int open() throws Exception
open
in class FileFormat
Exception
- If the file cannot be opened. The exceptions thrown vary
depending on the implementing class.FileFormat.open()
public int open(int... indexList) throws Exception
open
in class FileFormat
indexList
- The property list is the list of parameters, like index type
and the index order. The index type can be alphabetical or
creation. The index order can be increasing order or
decreasing order.Exception
- The exceptions thrown vary depending on the implementing class.FileFormat.open(int...)
public void setLibBounds(int low, int high) throws Exception
setLibBounds
in class FileFormat
low
- The earliest version of the library.high
- The latest version of the library.hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.Exception
- The exceptions thrown vary depending on the implementing class.public int[] getLibBounds() throws Exception
getLibBounds
in class FileFormat
hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.Exception
- The exceptions thrown vary depending on the implementing class.public void close() throws hdf.hdf5lib.exceptions.HDF5Exception
close
in class FileFormat
hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.FileFormat.close()
public TreeNode getRootNode()
getRootNode
in class FileFormat
null
there is no
associated file or if the associated file has not yet been
opened.FileFormat.getRootNode()
public HObject get(String path) throws Exception
FileFormat
This method returns the specified object from the file associated with this FileFormat instance.
If the specified object is a group, groups and datasets that are members
of the group will be accessible via the returned HObject instance. The
exact contents of the returned HObject instance depends on whether or not
FileFormat.open()
was called previously for this file.
The decision to have different behaviors was made to give users some control over the "cost" of the method. In many cases, a user wants only one level of a tree, and the performance penalty for loading the entire hierarchy of objects in a large and complex file can be significant. In the case where open() has already been called, the HObject instances have already been created in memory and can be returned quickly. If open() has not been called, this method creates the HObject instances before returning the requested HObject.
For example, say we have the following structure in our file:
/g0 Group /g0/dataset_comp Dataset {50, 10} /g0/dataset_int Dataset {50, 10} /g0/g00 Group /g0/g00/dataset_float Dataset {50, 10} /g0/g01 Group /g0/g01/dataset_string Dataset {50, 10}
get("/g0")
returns the
instance for /g0 with the information necessary to access
/g0/dataset_comp, /g0/dataset_int, /g0/g00, /g0/g00/dataset_float,
/g0/g01, and /g0/g01/dataset_string.
get("/go")
returns the instance for /g0 with the information necessary to access
/g0/dataset_comp, /g0/dataset_int, /g0/g00, and /g0/g01.
get
in class FileFormat
path
- Full path of the data object to be returned.null
.Exception
- If there are unexpected problems in trying to retrieve the
object. The exceptions thrown vary depending on the
implementing class.public Datatype createDatatype(int tclass, int tsize, int torder, int tsign, String name) throws Exception
FileFormat
The following code creates a named datatype in a file.
H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE); H5Datatype dtype = file.createDatatype( Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE, "Native Integer");
createDatatype
in class FileFormat
tclass
- class of datatype, e.g. Datatype.CLASS_INTEGERtsize
- size of the datatype in bytes, e.g. 4 for 32-bit integer.torder
- order of the byte endianing, e.g. Datatype.ORDER_LE.tsign
- signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.name
- name of the datatype to create, e.g. "Native Integer".Exception
- The exceptions thrown vary depending on the implementing
class.public Datatype createDatatype(int tclass, int tsize, int torder, int tsign, Datatype tbase, String name) throws Exception
FileFormat
The following code creates a named datatype in a file.
H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE); H5Datatype dtype = file.createDatatype( Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE, basetype, "Native Integer");
createDatatype
in class FileFormat
tclass
- class of datatype, e.g. Datatype.CLASS_INTEGERtsize
- size of the datatype in bytes, e.g. 4 for 32-bit integer.torder
- order of the byte endianing, e.g. Datatype.ORDER_LE.tsign
- signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.tbase
- the base datatype of the new datatypename
- name of the datatype to create, e.g. "Native Integer".Exception
- The exceptions thrown vary depending on the implementing
class.public Datatype createDatatype(int tclass, int tsize, int torder, int tsign) throws Exception
createDatatype
in class FileFormat
tclass
- class of datatype, e.g. Datatype.CLASS_INTEGERtsize
- size of the datatype in bytes, e.g. 4 for 32-bit integer.torder
- order of the byte endian, e.g. Datatype.ORDER_LE.tsign
- signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.Exception
- The exceptions thrown vary depending on the implementing
class.public Datatype createDatatype(int tclass, int tsize, int torder, int tsign, Datatype tbase) throws Exception
FileFormat
The following code creates an instance of H5Datatype in memory.
H5File file = (H5File) h5file.createInstance("test_hdf5.h5", FileFormat.WRITE); H5Datatype dtype = file.createDatatype( Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE, basetype);
createDatatype
in class FileFormat
tclass
- class of datatype, e.g. Datatype.CLASS_INTEGERtsize
- size of the datatype in bytes, e.g. 4 for 32-bit integer.torder
- order of the byte endian, e.g. Datatype.ORDER_LE.tsign
- signed or unsigned of an integer, e.g. Datatype.SIGN_NONE.tbase
- the base datatype of the new datatypeException
- The exceptions thrown vary depending on the implementing
class.public Dataset createScalarDS(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, Object fillValue, Object data) throws Exception
FileFormat
The following example creates a 2D integer dataset of size 100X50 at the root group in an HDF5 file.
String name = "2D integer"; Group pgroup = (Group) getRootObject(); Datatype dtype = new H5Datatype( Datatype.CLASS_INTEGER, // class 4, // size in bytes Datatype.ORDER_LE, // byte order Datatype.SIGN_NONE); // signed or unsigned long[] dims = {100, 50}; long[] maxdims = dims; long[] chunks = null; // no // chunking int gzip = 0; // no compression Object data = null; // no initial data values Dataset d = (H5File) file.createScalarDS(name, pgroup, dtype, dims, maxdims, chunks, gzip, data);
createScalarDS
in class FileFormat
name
- name of the new dataset, e.g. "2D integer"pgroup
- parent group where the new dataset is created.type
- datatype of the new dataset.dims
- dimension sizes of the new dataset, e.g. long[] dims = {100,
50}.maxdims
- maximum dimension sizes of the new dataset, null if maxdims is
the same as dims.chunks
- chunk sizes of the new dataset, null if no chunking.gzip
- GZIP compression level (1 to 9), 0 or negative values if no
compression.fillValue
- default value.data
- data written to the new dataset, null if no data is written to
the new dataset.Exception
- The exceptions thrown vary depending on the implementing
class.public Dataset createCompoundDS(String name, Group pgroup, long[] dims, long[] maxdims, long[] chunks, int gzip, String[] memberNames, Datatype[] memberDatatypes, int[] memberSizes, Object data) throws Exception
FileFormat
The following example creates a compressed 2D compound dataset with size of 100X50 in a root group. The compound dataset has two members, x and y. Member x is an interger, member y is an 1-D float array of size 10.
String name = "2D compound"; Group pgroup = (Group)((DefaultMutableTreeNode)getRootNode).getUserObject(); long[] dims = {100, 50}; long[] chunks = {1, 50}; int gzip = 9; String[] memberNames = {"x", "y"}; Datatype[] memberDatatypes = { new H5Datatype(Datatype.CLASS_INTEGER, Datatype.NATIVE, Datatype.NATIVE, Datatype.NATIVE) new H5Datatype(Datatype.CLASS_FLOAT, Datatype.NATIVE, Datatype.NATIVE, Datatype.NATIVE)); int[] memberSizes = {1, 10}; Object data = null; // no initial data values Dataset d = (H5File)file.createCompoundDS(name, pgroup, dims, null, chunks, gzip, memberNames, memberDatatypes, memberSizes, null);
createCompoundDS
in class FileFormat
name
- name of the new datasetpgroup
- parent group where the new dataset is created.dims
- dimension sizes of the new dataset.maxdims
- maximum dimension sizes of the new dataset, null if maxdims is
the same as dims.chunks
- chunk sizes of the new dataset, null if no chunking.gzip
- GZIP compression level (1 to 9), 0 or negative values if no
compression.memberNames
- names of the members.memberDatatypes
- datatypes of the members.memberSizes
- array sizes of the members.data
- data written to the new dataset, null if no data is written to
the new dataset.UnsupportedOperationException
- If the implementing class does not support compound datasets.Exception
- The exceptions thrown vary depending on the implementing
class.public Dataset createImage(String name, Group pgroup, Datatype type, long[] dims, long[] maxdims, long[] chunks, int gzip, int ncomp, int interlace, Object data) throws Exception
FileFormat
The following example creates a 2D image of size 100X50 in a root group.
String name = "2D image"; Group pgroup = (Group) ((DefaultMutableTreeNode) getRootNode).getUserObject(); Datatype dtype = new H5Datatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.SIGN_NONE); long[] dims = {100, 50}; long[] maxdims = dims; long[] chunks = null; // no chunking int gzip = 0; // no compression int ncomp = 3; // RGB true color image int interlace = ScalarDS.INTERLACE_PIXEL; Object data = null; // no initial data values Dataset d = (H5File) file.createScalarDS(name, pgroup, dtype, dims, maxdims, chunks, gzip, ncomp, interlace, data);
createImage
in class FileFormat
name
- name of the new image, "2D image".pgroup
- parent group where the new image is created.type
- datatype of the new image.dims
- dimension sizes of the new dataset, e.g. long[] dims = {100,
50}.maxdims
- maximum dimension sizes of the new dataset, null if maxdims is
the same as dims.chunks
- chunk sizes of the new dataset, null if no chunking.gzip
- GZIP compression level (1 to 9), 0 or negative values if no
compression.ncomp
- number of components of the new image, e.g. int ncomp = 3; //
RGB true color image.interlace
- interlace mode of the image. Valid values are
ScalarDS.INTERLACE_PIXEL, ScalarDS.INTERLACE_PLANEL and
ScalarDS.INTERLACE_LINE.data
- data value of the image, null if no data.Exception
- The exceptions thrown vary depending on the implementing
class.public Group createGroup(String name, Group pgroup) throws Exception
createGroup
in class FileFormat
name
- The name of the new group.pgroup
- The parent group, or null.Exception
- The exceptions thrown vary depending on the implementing
class.FileFormat.createGroup(java.lang.String, hdf.object.Group)
public Group createGroup(String name, Group pgroup, int... gplist) throws Exception
createGroup
in class FileFormat
name
- The name of a new group.pgroup
- The parent group object.gplist
- The group creation properties, in which the order of the
properties conforms the HDF5 library API, H5Gcreate(), i.e.
lcpl, gcpl and gapl, where
Exception
- The exceptions thrown vary depending on the implementing class.H5Group.create(java.lang.String, hdf.object.Group, int...)
public int createGcpl(int creationorder, int maxcompact, int mindense) throws Exception
createGcpl
in class FileFormat
creationorder
- The order in which the objects in a group should be created.
It can be Tracked or Indexed.maxcompact
- The maximum number of links to store in the group in a compact
format.mindense
- The minimum number of links to store in the indexed
format.Groups which are in indexed format and in which the
number of links falls below this threshold are automatically
converted to compact format.Exception
- The exceptions thrown vary depending on the implementing class.FileFormat.createGcpl(int, int, int)
public HObject createLink(Group parentGroup, String name, Object currentObj) throws Exception
FileFormat
If linkGroup is null, the new link is created in the root group.
createLink
in class FileFormat
parentGroup
- The group where the link is created.name
- The name of the link.currentObj
- The existing object the new link will reference.Exception
- The exceptions thrown vary depending on the implementing class.public HObject createLink(Group parentGroup, String name, HObject currentObj, int lType) throws Exception
If parentGroup is null, the new link is created in the root group.
createLink
in class FileFormat
parentGroup
- The group where the link is created.name
- The name of the link.currentObj
- The existing object the new link will reference.lType
- The type of link to be created. It can be a hard link, a soft link or an external link.Exception
- The exceptions thrown vary depending on the implementing class.public HObject createLink(Group parentGroup, String name, String currentObj, int lType) throws Exception
createLink
in class FileFormat
parentGroup
- The group where the link is created.name
- The name of the link.currentObj
- The name of the object the new link will reference. The object doesn't have to exist.lType
- The type of link to be created.Exception
- The exceptions thrown vary depending on the implementing class.public void reloadTree(Group g)
reloadTree(Group g) is useful when the structure of the group in file is changed while the group structure in memory is not changed.
g
- the group where the structure is to be reloaded in memorypublic TreeNode copy(HObject srcObj, Group dstGroup, String dstName) throws Exception
FileFormat
This method copies the source object to a destination group, and assigns the specified name to the new object.
The copy may take place within a single file or across files. If the source object and destination group are in different files, the files must have the same file format (both HDF5 for example).
The source object can be a group, a dataset, or a named datatype. This method copies the object along with all of its attributes and other properties. If the source object is a group, this method also copies all objects and sub-groups below the group.
The following example shows how to use the copy method to create two copies of an existing HDF5 file structure in a new HDF5 file. One copy will be under /copy1 and the other under /copy2 in the new file.
// Open the existing file with the source object. H5File existingFile = new H5File("existingFile.h5", FileFormat.READ); existingFile.open(); // Our source object will be the root group. HObject srcObj = existingFile.get("/"); // Create a new file. H5File newFile = new H5File("newFile.h5", FileFormat.CREATE); newFile.open(); // Both copies in the new file will have the root group as their // destination group. Group dstGroup = (Group) newFile.get("/"); // First copy goes to "/copy1" and second goes to "/copy2". // Notice that we can use either H5File instance to perform the copy. HObject copy1 = existingFile.copy(srcObj, dstGroup, "copy1"); HObject copy2 = newFile.copy(srcObj, dstGroup, "copy2"); // Close both the files. file.close(); newFile.close();
copy
in class FileFormat
srcObj
- The object to copy.dstGroup
- The destination group for the new object.dstName
- The name of the new object. If dstName is null, the name of
srcObj will be used.Exception
- are specific to the implementing class.public void delete(HObject obj) throws Exception
FileFormat
delete
in class FileFormat
obj
- The object to delete.Exception
- The exceptions thrown vary depending on the implementing
class.public void writeAttribute(HObject obj, Attribute attr, boolean attrExisted) throws hdf.hdf5lib.exceptions.HDF5Exception
FileFormat
If an HDF(4&5) attribute exists in file, the method updates its value. If the attribute does not exist 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 writeAttribute() to write the value.
writeAttribute
in class FileFormat
obj
- The object to which the attribute is attached to.attr
- The atribute to attach.attrExisted
- The indicator if the given attribute exists.hdf.hdf5lib.exceptions.HDF5Exception
public int open(int plist) throws Exception
This function does the same as "int open()" except the you can also pass an HDF5 file access property to file open. For example,
// All open objects remaining in the file are closed then file is closed int plist = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS); H5.H5Pset_fclose_degree(plist, HDF5Constants.H5F_CLOSE_STRONG); int fid = open(plist);
plist
- a file access property list identifier.Exception
- If there is a failure.public static String getLinkTargetName(HObject obj) throws Exception
obj
- The current link object.hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.Exception
public void exportDataset(String file_export_name, String file_name, String object_path, int binary_order) throws Exception
exportDataset
in class FileFormat
file_export_name
- The file name to export data into.file_name
- The name of the HDF5 file containing the dataset.object_path
- The full path of the dataset to be exported.binary_order
- The data byte orderException
- If there is a failure.public void renameAttribute(HObject obj, String oldAttrName, String newAttrName) throws Exception
renameAttribute
in class FileFormat
obj
- The object whose attribute is to be renamed.oldAttrName
- The current name of the attribute.newAttrName
- The new name of the attribute.hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.Exception
- The exceptions thrown vary depending on the implementing class.public static void renameObject(HObject obj, String newName) throws Exception
obj
- the object to be renamed.newName
- the new name of the object.Exception
- If there is a failure.public static int getIndexTypeValue(String strtype)
public static int getIndexOrderValue(String strorder)
public int getIndexType(String strtype)
getIndexType
in class FileFormat
public int getIndexType()
public void setIndexType(int indexType)
setIndexType
in class FileFormat
public int getIndexOrder(String strorder)
getIndexOrder
in class FileFormat
public int getIndexOrder()
public void setIndexOrder(int indexOrder)
setIndexOrder
in class FileFormat
Copyright © 2017. All Rights Reserved.