Below are two exmaples:
testH5Vlen() uses the HDF5 Java wrapper
testH5VlenObj() uses the object level (high level)

=================
    private static void testH5Vlen(final String filename) throws Exception
    {
        String buf[] = {"Parting", "is such", "sweet", "sorrow."};

        // Case 1, may run into infinite loop
        // int tid = H5.H5Tvlen_create(HDF5Constants.H5T_C_S1);

        // Case 2, differnt failure on differnt platforms
        int tid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
        H5.H5Tset_size(tid, HDF5Constants.H5T_VARIABLE);

int fid = H5.H5Fcreate(filename, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
        int sid = H5.H5Screate_simple(1, new long[] {4}, null);
int did = H5.H5Dcreate(fid, "/str", tid, sid, HDF5Constants.H5P_DEFAULT);

        // write() fails on both case 1 and 2
H5.H5Dwrite(did, tid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, buf);

        // clean up
        H5.H5Dclose(did);
        H5.H5Sclose(sid);
        H5.H5Tclose(tid);
        H5.H5Fclose(fid);
    }

    private static void testH5VlenObj(final String fname) throws Exception
    {
        int strLen = -1;
        long[] dims = {4};
        String buf[] = {"Parting", "is such", "sweet", "sorrow."};

        // create a new file with a given file name.
        H5File testFile = new H5File(fname, H5File.CREATE);

        testFile.open();
Group root = (Group)((javax.swing.tree.DefaultMutableTreeNode)testFile.getRootNode()).getUserObject(); Datatype dtype = testFile.createDatatype(Datatype.CLASS_STRING, strLen, Datatype.NATIVE, Datatype.NATIVE); Dataset dataset = testFile.createScalarDS ("/str", root, dtype, dims, null, null, 0, buf);

        testFile.close();
     }



On 3/24/2011 11:54 AM, Konrad Hinsen wrote:
My next problem with the high-level Java API is creating variable-length strings, either in datasets or as attribute values. Nothing but strange error messages... To start with, if I create a H5Datatype of CLASS_VLEN and ask for its description, it is "unknown". Any use of such a datatype leads to exceptions. Does anyone have a working example?

Thanks in advance,
  Konrad.

_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to