Subset dataset using Java HDF Object Package


#1

I’m trying to write code that retrieves single values from a 4-D dataset using the Java HDF Object Package. My code is working well right up until I request the dimensions of the dataset to prepare to do the read. The calls to getDims(), getSelectedDims(), getStartDims(), and getStride() are all returning null. When I look at the file in HDFView, everything looks great.

Any ideas?

Thanks,
Scott

Java HDF Object Package from the HDFView 3.0.0 beta release on Windows 10, though I will be running this eventually on RHEL 7).


#2

Hi Scott,

Please try the HDF-Java wrapper for HDF5 rather than the HDF-Java Object package. You should be
able to use the HDF-Java wrapper to subset a 4D dataset.

The HDF-Java Object package is limited in what it can do and targets common use-cases.

The HDF-Java wrapper for HDF5 is the native interface for Java HDF5 (JHI5), which “wraps around”
the HDF5 library. As of HDF5-1.10, HDF-Java is included with the HDF5-1.10 source code. See this
page for details:

https://portal.hdfgroup.org/display/support/HDF-Java

-Barbara


#3

Hi Barbara,

I’ve managed to get 1.10.2 built using CMake (whew) and then installed with the MSI. Now I’m getting a failure when I run.

Thread [main] (Suspended (exception ClassNotFoundException))
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available
H5.() line: 230
HDF5Constants.() line: 29
VolumetricReaderDriver.main(String[]) line: 12

In Eclipse:
I reference “C:\Program Files\HDF_Group\HDF5\1.10.2\lib\jarhdf5-1.10.2.jar.”
I have VM argument -Djava.library.path=“C:\Program Files\HDF_Group\HDF5\1.10.2\lib”
I set environment variable PATH=“C:\Program Files\HDF_Group\HDF5\1.10.2\lib”

The code:

import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.exceptions.HDF5LibraryException;

public class VolumetricReaderDriver {

public static void main(String[] args) {
	String volumetricFilePath = "C:\\Users\\scott\\Documents\\TEMP\\WxThreats\\SavedForTesting\\WindDirectionGPML\\WindDirectionGPML.h5";

	long h5File = -1;
	try {
		h5File = H5.H5Fopen(volumetricFilePath, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
	} catch (HDF5LibraryException | NullPointerException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.exit(100);
	}
	
	try {
		H5.H5Fclose(h5File);
	} catch (HDF5LibraryException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.exit(110);
	}
}

}

Any ideas what I’m missing?

Thanks,
Scott


#4

Hi Scott,
I’m not exactly sure what the issue is. Can you check the file path and name to make sure it can find the file?
-Barbara


#5

It seems I was missing an SLF4J library (found this a little while ago).