The hierarchical data format allows you to store different types of image and digital data in file formats, and can be transmitted on different types of machines, along with a library of functions that unify the file format. This file format is supported by most ordinary computers. HDF is a self-describing, multiple-object file format for storing and distributing scientific data. HDF was created by the National Center for Supercomputing Applications (NCSA) to meet the needs of different groups of scientists in different engineering areas.
For an introduction to HDF5, please check the official page of HDF5. and reference to this article: Scientific Storage data Format-HDF5
In addition, HDF5 provides a Java interface, and the following are some considerations and related code for Java using HDF5.
1.Eclipse Configuration
To the HDF5 installation folder, add Jarhdf5.jar, Slf4j-api.jar,slf4j-simple.jar to the functional Lib directory, and add hdf5_java.dll files to a directory X. Note that in this procedure, add and add only these three files, and the fourth Slf4j-nop-1.7.5.jar is temporarily unused.
HDF5 is a third party library for C + + native, and joins Eclipse Engineering in accordance with the general steps of importing into the warehouse. Windows->preference->java->userlibraries->new. Add the name of the library yourself. My name is HDF5.
Then in the new user library, add JARS, adding Jarhdf5.jar, Slf4j-api.jar,slf4j-simple.jar three files, and configuring native library location under Jarhdf5.jar. Link to the X directory to invoke the native dynamic library Hdf5_java.dll.
Then, in the project's source code file, introduce the HDF5 package.
For example:
Import hdf.hdf5lib.H5;
Import hdf.hdf5lib.HDF5Constants;
2. Read HDF5 file
Initial use, using C + + written files, test read, can run the code as follows:
public static void Main (string[] args) {
String fname = "D:/dataset/recosys/javatest/hdf5datasetread.h5";
private static
String DSName = e = "Training_data";
try {
//Create the HDF5 file and add groups and dataset into the file
//save_to_file (fname, DSName, dims2d);
catch (Exception ex) {
ex.printstacktrace ();
}
Test read out
try {
load_from_file (fname, dsname);
} catch (Exception ex) {
ex.printstacktrace ();
}
}
Load function:
The public static int Load_from_file (String fname, String dsname) throws Exception {//read successively used Fileid,spaceid
, Datasetid long file_id =-1;
Long space_id =-1;
Long dataset_id =-1;
The Open file using the default properties. try {file_id = H5.
H5fopen (fname, Hdf5constants.h5f_acc_rdwr, Hdf5constants.h5p_default);
catch (Exception e) {e.printstacktrace ();
The//Open dataset using the default properties. try {if (file_id >= 0) dataset_id = H5.
H5dopen (file_id, DSName, Hdf5constants.h5p_default);
catch (Exception e) {e.printstacktrace ();
}//Allocate array of pointers to two-dimensional arrays (theelements of the dataset.
int L = 20;
int w = 20;
Long[] dims = {0,0};
Long[] Dims2 = {0,0}; Get space_id = H5.
H5dget_space (dataset_id); H5.
H5sget_simple_extent_dims (SPACE_ID,DIMS,DIMS2);
l= (int) dims[0];
w= (int) dims[1];
int[][] Dataread = new INT[L][W]; try {if (dataset_id >= 0) H5. H5dread (dataset_id, Hdf5constants.h5t_native_int, Hdf5constants.h5s_all, Hdf5constants.h5s_all, Hdf5constants.h5p_default, dataRe
AD);
catch (Exception e) {e.printstacktrace ();
}//Print out the data values System.out.println ("\n\noriginal data Values");
for (int i = 0; i < L; i++) {System.out.print ("\ n" + dataread[i][0]);
for (int j = 1; J < W J + +) {System.out.print ("," + dataread[i][j]);
}
}
}
Implement to read the data into the dataread.
3. Save HDF5 File
.............. To be finished ..........