0

i have an hdf5 file with a table 264x264x1024 filled with uint32 Numbers. I have problems understanding how to get to the data of hdf5-files from within java. I want to write the data from the table to an array. Is there an easy way to do it?

Sadly the system i am working on is still java6.

Sorry if the question is not very specific, if you need more information to help me please ask. As i said, i dont know alot about hdf5 yet.

Thank you

  • See [here](http://stackoverflow.com/questions/9227099/hdf5-in-java-what-are-the-difference-between-the-availabe-apis?rq=1). A programmer's first instinct would be looking for existing libraries. Please consider trying one (e.g. JHDF5), then only ask if you stumble upon a more specific issue. – E_net4 Oct 26 '16 at 10:02

1 Answers1

1

One of the easiest ways to solve this would be to abstract oneself from the low-level details of HDF5 files in Java. You can do this by using HDFql (Hierarchical Data Format query language - http://www.hdfql.com).

Assuming that your HDF5 file is named my_file.h5 and it stores a dataset named my_dataset (dimensions 264x264x1024 of uint32), you could read this into a Java array using HDFql as follows:

// import HDFql package (make sure it can be found by the Java compiler/JVM)
import as.hdfql.*;

public class Example
{
    public static void main(String args[])
    {
        int data[][][] = new int[264][264][1024];
        int x;
        int y;
        int z;

        // select (i.e. read) a dataset name "my_dataset" from HDF5 file "my_file.h5" and store it in variable "data"
        HDFql.execute("SELECT FROM my_file.h5 my_dataset INTO MEMORY " + HDFql.variableTransientRegister(data));

        // display content of variable "data"
        for(x = 0; x < 264; x++)
        {
            for(y = 0; y < 264; y++)
            {
                for(z = 0; z < 1024; z++)
                {
                    System.out.println(data[x][y][z]);
                }
            }
        }
    }
}

This example was successfully run using Java 8 and HDFql version 2.1.0. Additionally, please keep in mind that:

  1. Java does not support unsigned datatypes such as uint32 (you will have to somehow make the conversion by yourself);

  2. You may run into an OutOfMemoryError exception if there is not enough heap space for Java to store an array with these dimensions (to solve this, you will have to play with the parameter -Xmx when launching Java).

SOG
  • 876
  • 6
  • 10