Thanks Peter, but I was looking for an example of strings with
compression, and I also don't understand how the array of strings
(String) maps to a single string in the file. (are they just
concatenated?)
I got it working by translating my C code more or less verbatim into
Java using the low-level H5.* functions.
-----Original Message-----
From: hdf-forum-bounces@hdfgroup.org
[mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of Peter Cao
Sent: Tuesday, July 14, 2009 10:27 AM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] storing a string dataset in HDF5 using Java
Hi Jason,
Below is the test program. It work fine for me.
2) Is there any way to incrementally write the dataset, rather than
having to get all the data in memory ahead of time?
you can set the max dim size to unlimited or some size larger than the current
dim size. you can write data incrementally. There are some C examples.
--Peter
========================
public static final void testStrings(String fname) throws Exception
{
final int strLen = 20;
final long dims = {5};
final String data = new String[(int)dims[0]];
// retrieve an instance of H5File
final FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
if (fileFormat == null)
{
System.err.println("Cannot find HDF5 FileFormat.");
return;
}
// create a new file with a given file name.
final H5File testFile = (H5File)fileFormat.create(fname);
if (testFile == null)
{
System.err.println("Failed to create file:"+fname);
return;
}
for (int i=0; i<data.length; i++) {
data[i] = "test string "+i;;
}
// open the file and retrieve the root group
testFile.open();
final 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
("dset", root, dtype, dims, null, null, 0, data);
testFile.close();
}
Jason Sachs wrote:
I'll ask a simplified set of questions to rephrase my original
question
about using the high-level Object API in Java.
I would like to create a gzip-compressed string dataset in an HDF5
file
using Java, based around a datatype that is H5T_C_S1 with a known
string
length. I have done it in C/C++, just trying to port to Java. The
datatype code is initialized roughly as follows.
int tid = H5.H5Tcopy( HDF5Constants.H5T_C_S1);
H5.H5Tset_size(tid, x);
Datatype dtype = new H5Datatype(tid);
FileFormat ff = g.getFileFormat();
ncsa.hdf.object.Dataset ds = ff.createScalarDS(
"ESPDF", g, dtype, dims, maxdims,
chunks, gzip, null);
1) How do I use FileFormat.createScalarDS with string data? The
examples
in
http://www.hdfgroup.org/hdf-java-html/hdf-object/use.html#read_dataset
talk only about arrays of integers.
2) Is there any way to incrementally write the dataset, rather than
having to get all the data in memory ahead of time?
________________________________________________________________________
_________________
This e-mail and the information, including any attachments, it
contains are intended to be a confidential communication only to the
person or entity to whom it is addressed and may contain information
that is privileged. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this communication is strictly prohibited. If you have
received this communication in error, please immediately notify the
sender and destroy the original message.
Thank you.
Please consider the environment before printing this email.
_______________________________________________
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