public class H4File extends FileFormat
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 |
---|
H4File()
Creates an H4File with read only access.
|
H4File(String pathname)
Creates an H4File with read only access.
|
H4File(String fileName,
int access)
Creates an H4File instance with specified file name and access.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes file associated with this instance.
|
TreeNode |
copy(HObject srcObj,
Group dstGroup,
String dstName)
Copy an object to a group.
|
Datatype |
createDatatype(int tclass,
int tsize,
int torder,
int tsign)
Creates a new datatype in memory.
|
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 HDF4 file with the specified name and returns a new H4File
instance associated with the file.
|
Group |
createGroup(String name,
Group pgroup)
Creates a new group with specified name in existing group.
|
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 H4File instance with specified file name and access.
|
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)
Delete an object from the file.
|
HObject |
get(String path)
Get an individual HObject with a given path.
|
(package private) int |
getGRAccessID()
Returns the GR identifier, which is returned from GRstart(fid).
|
String |
getLibversion()
Returns the version of the HDF4 library.
|
TreeNode |
getRootNode()
Returns the root node for the file associated with this instance.
|
(package private) int |
getSDAccessID()
Returns the SDS identifier, which is returned from SDstart(fname, flag).
|
boolean |
isThisType(FileFormat fileformat)
Checks if the given file format is an HDF4 file.
|
boolean |
isThisType(String filename)
Checks if the given file is an HDF4 file or netCDF.
|
int |
open()
Opens file and returns a file identifier.
|
void |
writeAttribute(HObject obj,
Attribute attr,
boolean isSDglobalAttr)
Creates a new attribute and attaches it to the object if the
attribute does not exist.
|
addFileExtension, addFileFormat, copy, create, createCompoundDS, createCompoundDS, createGcpl, createGroup, createLink, createLink, createLink, createScalarDS, exportDataset, findObject, findObject, getFID, getFileExtensions, getFileFormat, getFileFormatKeys, getFileFormats, getFilePath, getHObject, getHObject, getIndexOrder, getIndexOrderValue, getIndexType, getIndexTypeValue, getInstance, getLibBounds, getMaxMembers, getNumberOfMembers, getStartMembers, isReadOnly, open, open, removeFileFormat, renameAttribute, setIndexOrder, setIndexType, setLibBounds, 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 H4File()
public H4File(String pathname)
pathname
- The file path string.public H4File(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 boolean isThisType(FileFormat fileformat)
isThisType
in class FileFormat
fileformat
- the fileformat to be checked.FileFormat.isThisType(String)
public boolean isThisType(String filename)
isThisType
in class FileFormat
filename
- the file to be checked.FileFormat.isThisType(FileFormat)
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
.hdf.hdflib.HDFException
- If the file cannot be created or if createFlag has unexpected
value.NullPointerException
- If the filename
argument is null
.UnsupportedOperationException
- If the implementing class does not support the file creation
operation.Exception
- If the file cannot be created or if the creation flag has an
unexpected value. The exceptions thrown vary depending on the
implementing class.FileFormat.createFile(java.lang.String, int)
,
H4File(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
.NullPointerException
- If the filename
argument is null
.Exception
- If the instance cannot be created or if the access flag has
an unexpected value. The exceptions thrown vary depending on
the implementing class.FileFormat.createInstance(java.lang.String, int)
,
H4File(String, int)
public int open() throws Exception
FileFormat
This method uses the filename
and access
parameters specified in the createFile(), createInstance(),
or getInstance() call to open the file. It returns the file
identifier if successful, or a negative value in case of failure.
The method also loads the file structure and basic information (name, type) for data objects in the file into the FileFormat instance. It does not load the contents of any data object.
The structure of the file is stored in a tree starting from the root node.
open
in class FileFormat
Exception
- If the file cannot be opened. The exceptions thrown vary
depending on the implementing class.FileFormat.createFile(String, int)
,
FileFormat.createInstance(String, int)
,
FileFormat.getInstance(String)
,
FileFormat.getRootNode()
public void close() throws hdf.hdflib.HDFException
FileFormat
This method closes the file associated with this FileFormat instance, as well as all objects associated with the file.
close
in class FileFormat
hdf.hdflib.HDFException
FileFormat.open()
public TreeNode getRootNode()
FileFormat
The root node is a Java TreeNode object
(javax.swing.tree.DefaultMutableTreeNode) that represents the root group
of a file. If the file has not yet been opened, or if there is no file
associated with this instance, null
will be returned.
Starting from the root, applications can descend through the tree structure and navigate among the file's objects. In the tree structure, internal nodes represent non-empty groups. Leaf nodes represent datasets, named datatypes, or empty groups.
getRootNode
in class FileFormat
null
there is no
associated file or if the associated file has not yet been
opened.FileFormat.open()
public Group createGroup(String name, Group pgroup) throws Exception
FileFormat
If the parent group is null, the new group will be created in the root group.
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.public Datatype createDatatype(int tclass, int tsize, int torder, int tsign) 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);
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 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 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 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 void delete(HObject obj) throws Exception
delete
in class FileFormat
obj
- the data object to delete.Exception
- if the object can not be deletedpublic TreeNode copy(HObject srcObj, Group dstGroup, String dstName) throws Exception
copy
in class FileFormat
srcObj
- the object to copy.dstGroup
- the destination group.dstName
- The name of the new object. If dstName is null, the name of
srcObj will be used.Exception
- if the object can not be copiedpublic void writeAttribute(HObject obj, Attribute attr, boolean isSDglobalAttr) throws hdf.hdflib.HDFException
writeAttribute
in class FileFormat
obj
- the object which the attribute is to be attached to.attr
- the attribute to attach.isSDglobalAttr
- The indicator if the given attribute exists.hdf.hdflib.HDFException
- if the attribute can not be writtenint getGRAccessID()
int getSDAccessID()
public String getLibversion()
getLibversion
in class FileFormat
public HObject get(String path) throws Exception
get
in class FileFormat
path
- the path of the objectnull
.Exception
- if the object cannot be foundCopyright © 2017. All Rights Reserved.