How to Write String Object to HDF5?

Hello.

I am new to HDF5 and I would really appreciate if somebody can help me
finding correct approach for the following.

How to write String Object to HDF5 file using native HDF5 java library?
What I am trying?

According to Javadoc java.lang.String is mapped to H5T_C_S1 constant and I
am using it in the following form:

<see screen shot>

    private int createDataspace() throws HDF5LibraryException,
HDF5Exception {
        return H5.H5Screate_simple(3, new long[]{3, 3, 1}, null);
    }

    private int createDataset(int fileId, String datasetName) throws
HDF5LibraryException, HDF5Exception {
        return H5.H5Dcreate(datasetName,
                HDF5Constants.H5T_C_S1, createDataspace(),
                HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
    }

    private int writeDataset(String fileName, String datasetName,
String[][] table) throws HDF5LibraryException, HDF5Exception {
        int datasetId = -1;

        int returnCode = H5.H5Dwrite(datasetId = createDataset(fileId ,
datasetName), HDF5Constants.H5T_C_S1,
                HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
                HDF5Constants.H5P_DEFAULT, table);
        H5.H5Dclose(datasetId);
        H5.H5Fclose(fileId);
        return returnCode;
    }

And it throws following exception:

Exception in thread "main" ncsa.hdf.hdf5lib.exceptions.HDF5JavaException:
ArrayDesciptor: Error: String array not supported yet
                at
ncsa.hdf.hdf5lib.ArrayDescriptor.<init>(HDFArray.java:1030)
                at ncsa.hdf.hdf5lib.HDFArray.<init>(HDFArray.java:68)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1971)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1883)

Thank you.

Hello HDF developer,

Sorry, but I am not coding in Java – merely I am doing it in C.
But for HDF5 strings are variable length / derived data types.

See here: http://www.hdfgroup.org/HDF5/Tutor/crtdat.html#datatypes
And here: http://www.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#CreateVLString

Someone might have had strings in mind as an Java API level extension – maybe it is not yet realized.
There might be an option going for fixed length strings – but indeed that might waste your storage.
On the other hand fixed length strings might be faster than variable lengths ones – but that is only a wild guess from me.

Regards, Alex.

···

Von: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] Im Auftrag von Hdfdev Hdfdev
Gesendet: Sonntag, 19. Oktober 2014 23:32
An: HDF Users Discussion List
Betreff: [Hdf-forum] How to Write String Object to HDF5?

Hello.

I am new to HDF5 and I would really appreciate if somebody can help me finding correct approach for the following.

How to write String Object to HDF5 file using native HDF5 java library?
What I am trying?

According to Javadoc java.lang.String is mapped to H5T_C_S1 constant and I am using it in the following form:

<see screen shot>

    private int createDataspace() throws HDF5LibraryException, HDF5Exception {
        return H5.H5Screate_simple(3, new long[]{3, 3, 1}, null);
    }

    private int createDataset(int fileId, String datasetName) throws HDF5LibraryException, HDF5Exception {
        return H5.H5Dcreate(datasetName,
                HDF5Constants.H5T_C_S1, createDataspace(),
                HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
    }

    private int writeDataset(String fileName, String datasetName, String[][] table) throws HDF5LibraryException, HDF5Exception {
        int datasetId = -1;

        int returnCode = H5.H5Dwrite(datasetId = createDataset(fileId , datasetName), HDF5Constants.H5T_C_S1,
                HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
                HDF5Constants.H5P_DEFAULT, table);
        H5.H5Dclose(datasetId);
        H5.H5Fclose(fileId);
        return returnCode;
    }

And it throws following exception:

Exception in thread "main" ncsa.hdf.hdf5lib.exceptions.HDF5JavaException: ArrayDesciptor: Error: String array not supported yet
                at ncsa.hdf.hdf5lib.ArrayDescriptor.<init>(HDFArray.java:1030)
                at ncsa.hdf.hdf5lib.HDFArray.<init>(HDFArray.java:68)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1971)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1883)

Thank you.

We provide examples of writing string data in HDF-Java on this page:

  http://www.hdfgroup.org/HDF5/examples/api18-java.html

If you go to the very bottom of the page, you will see an example of writing a fixed length string and a variable length
string, using both the HDF-Java wrappers and the Object package.

If you have questions about these let me know!

-Barbara
help@hdfgroup.org<mailto:help@hdfgroup.org>

(Note that the examples expect to be run in the “examples/datasets” directory. Just comment out the “package examples.datasets;”
line at the top of the code to run them elsewhere.)

···

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Hdfdev Hdfdev
Sent: Sunday, October 19, 2014 4:32 PM
To: HDF Users Discussion List
Subject: [Hdf-forum] How to Write String Object to HDF5?

Hello.

I am new to HDF5 and I would really appreciate if somebody can help me finding correct approach for the following.

How to write String Object to HDF5 file using native HDF5 java library?
What I am trying?

According to Javadoc java.lang.String is mapped to H5T_C_S1 constant and I am using it in the following form:

<see screen shot>

    private int createDataspace() throws HDF5LibraryException, HDF5Exception {
        return H5.H5Screate_simple(3, new long[]{3, 3, 1}, null);
    }

    private int createDataset(int fileId, String datasetName) throws HDF5LibraryException, HDF5Exception {
        return H5.H5Dcreate(datasetName,
                HDF5Constants.H5T_C_S1, createDataspace(),
                HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
    }

    private int writeDataset(String fileName, String datasetName, String[][] table) throws HDF5LibraryException, HDF5Exception {
        int datasetId = -1;

        int returnCode = H5.H5Dwrite(datasetId = createDataset(fileId , datasetName), HDF5Constants.H5T_C_S1,
                HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
                HDF5Constants.H5P_DEFAULT, table);
        H5.H5Dclose(datasetId);
        H5.H5Fclose(fileId);
        return returnCode;
    }

And it throws following exception:

Exception in thread "main" ncsa.hdf.hdf5lib.exceptions.HDF5JavaException: ArrayDesciptor: Error: String array not supported yet
                at ncsa.hdf.hdf5lib.ArrayDescriptor.<init>(HDFArray.java:1030)
                at ncsa.hdf.hdf5lib.HDFArray.<init>(HDFArray.java:68)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1971)
                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1883)

Thank you.

Thank you Barbara, for sharing the link.

The example worked like a charm <g>. I have so more questions and will
start a new thread.

Best regards

···

On 20 October 2014 18:51, Barbara Jones <bljones@hdfgroup.org> wrote:

We provide examples of writing string data in HDF-Java on this page:

  http://www.hdfgroup.org/HDF5/examples/api18-java.html

If you go to the very bottom of the page, you will see an example of
writing a fixed length string and a variable length

string, using both the HDF-Java wrappers and the Object package.

If you have questions about these let me know!

-Barbara

help@hdfgroup.org

(Note that the examples expect to be run in the “examples/datasets”
directory. Just comment out the “package examples.datasets;”

line at the top of the code to run them elsewhere.)

*From:* Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] *On
Behalf Of *Hdfdev Hdfdev
*Sent:* Sunday, October 19, 2014 4:32 PM
*To:* HDF Users Discussion List
*Subject:* [Hdf-forum] How to Write String Object to HDF5?

Hello.

I am new to HDF5 and I would really appreciate if somebody can help me
finding correct approach for the following.

How to write String Object to HDF5 file using native HDF5 java library?

What I am trying?

According to Javadoc java.lang.String is mapped to H5T_C_S1 constant and I
am using it in the following form:

<see screen shot>

    private int createDataspace() throws HDF5LibraryException,
HDF5Exception {

        return H5.H5Screate_simple(3, new long[]{3, 3, 1}, null);

    }

    private int createDataset(int fileId, String datasetName) throws
HDF5LibraryException, HDF5Exception {

        return H5.H5Dcreate(datasetName,

                HDF5Constants.H5T_C_S1, createDataspace(),

                HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);

    }

    private int writeDataset(String fileName, String datasetName,
String[][] table) throws HDF5LibraryException, HDF5Exception {

        int datasetId = -1;

        int returnCode = H5.H5Dwrite(datasetId = createDataset(fileId ,
datasetName), HDF5Constants.H5T_C_S1,

                HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,

                HDF5Constants.H5P_DEFAULT, table);

        H5.H5Dclose(datasetId);

        H5.H5Fclose(fileId);

        return returnCode;

    }

And it throws following exception:

Exception in thread "main" ncsa.hdf.hdf5lib.exceptions.HDF5JavaException:
ArrayDesciptor: Error: String array not supported yet

                at
ncsa.hdf.hdf5lib.ArrayDescriptor.<init>(HDFArray.java:1030)

                at ncsa.hdf.hdf5lib.HDFArray.<init>(HDFArray.java:68)

                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1971)

                at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1883)

Thank you.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org

http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5