Using h5ex_t_vlen.c as a rough model, I've taken a stab at a Java version. Not surprisingly, it's failing.
Here's the code:
private static final String FNAME = "H5CreateVlen.h5";
private static double a = {1., 2., 3.};
private static double b = {1.};
private static double allData = {
a, b
};
private static void createVlenCompound() throws Exception {
int DIM1 = 2;
long dims = {DIM1};
int fid = H5Fcreate(FNAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
int sid = H5Screate_simple(1, dims, null);
int tid = H5Tvlen_create(HDF5Constants.H5T_NATIVE_DOUBLE);
int did = H5Dcreate(fid, "ds1", tid, sid, HDF5Constants.H5P_DEFAULT);
H5Dwrite(did, tid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, allData);
H5Tclose(tid);
H5Sclose(sid);
H5Dclose(did);
H5Fclose(fid);
}
public static void main( String args ) throws Exception {
createVlenCompound();
}
Here's the stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: doubleToByte: start or len is out of bounds
at ncsa.hdf.hdf5lib.HDFNativeData.doubleToByte(Native Method)
at ncsa.hdf.hdf5lib.HDFArray.byteify(HDFArray.java:230)
at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1172)
at ncsa.hdf.hdf5lib.H5.H5Dwrite(H5.java:1190)
at javaExample.H5createVlen.createVlenCompound(H5createVlen.java:43)
at javaExample.H5createVlen.main(H5createVlen.java:51)
I didn't dig deep enough into the C++ to see how hvl_t (the datatype being used in the sample) is defined, but it seems at the least to have a pointer part and a size part. I was crossing my fingers that the Java H5 class would use reflection or the like to derive the size information needed.
Any further advice for me?
Thanks.
-Josiah
···
On 1/11/2011 11:06 AM, Josiah Slack wrote:
Thanks for the lead - I've grabbed the source and am about to look it over.
-Josiah
On 1/11/2011 11:01 AM, Neil Fortner wrote:
Josiah,
There doesn't seem to be a Java example, but there is a C example:
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/C/H5T/h5ex_t_vlen.c
Also, is there a maximum size for the array of doubles? If so, you may
be better off using a fixed length array and a separate field to store
the actual length, then using compression to mostly eliminate the wasted
space.
Thanks,
-Neil
On 01/11/2011 09:57 AM, Josiah Slack wrote:
I'll have a look, thanks.
-Josiah
On 1/11/2011 10:55 AM, Quincey Koziol wrote:
Hi Josiah,
On Jan 11, 2011, at 9:22 AM, Josiah Slack wrote:
Thanks. Can you point me to any examples using H5Tvlen_create() in
context (preferably Java, but I'll take what I can get)?
Hmm, I don't see any code that uses H5Tvlen_create() in our
examples files, but you can look at test/tvltypes.c for examples of
how it's used in the context of our regression tests. Perhaps Peter
has a pointer to a Java example...
Quincey
-Josiah
On 1/11/2011 7:44 AM, Quincey Koziol wrote:
Hi Josiah,
On Jan 10, 2011, at 3:00 PM, Josiah Slack wrote:
Hi folks -
I've got another naive question about building Datatypes. I've got
a Datatype that I'm forming from arrays of doubles. Ultimately,
I'll be writing an array of this Datatype. The complicating
factor is that the arrays of doubles won't necessarily have the
same dimensions from one instance of the Datatype to the next.
Sounds like you might want a variable-length sequence of
doubles as your datatype. Look at the documentation for
H5Tvlen_create()...
Quincey
Here's a little pseudo-code to more concretely illustrate what I
mean:
Datatype {
double a;
double b;
double c;
};
Datatype allData = {
{ a = {1., 2., 3.} } b = {{1.,2.},{3.,4.}}, c = {1.} },
{ a = {1.,} b = {{1.}}, c = {1., 2.} },
{ a = {}, b = {{1.}, {2.}}, c = {1., 2., 3.} }
};
I'm trying to use the Java H5 class to achieve this.
Thanks in advance for your time.
-Josiah
--
Josiah Slack
MIT Lincoln Laboratory
Group 36
jslack@ll.mit.edu
Ph: (781) 981-1754
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
--
Josiah Slack
MIT Lincoln Laboratory
Group 36
jslack@ll.mit.edu
Ph: (781) 981-1754
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
--
Josiah Slack
MIT Lincoln Laboratory
Group 36
jslack@ll.mit.edu
Ph: (781) 981-1754