Josiah, maybe I'm misreading your code, but your compound type
in the file has only one member ("dummy").
Later you are trying to write a member whose name is contained
in the valueName variable. Unless that name is "dummy", the
H5Dwrite call is not going to find anything suitable to write to.

G.

From: Hdf-forum [mailto:[email protected]] On Behalf Of 
Josiah Slack
Sent: Friday, July 19, 2013 12:44 PM
To: HDF Users Discussion List
Subject: Re: [Hdf-forum] writing part of a compound datatype

I'm not having much success. Let me be pretty concrete about the steps I'm 
taking, and maybe it will be clear where I'm going wrong.
fileId = H5Fcreate(<filename>, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
compoundType = H5Tcreate(HST_COMPOUND, <overall message size>);
H5Tinsert(compoundType, "dummy", 0, HST_NATIVE_INT); // hack so that H5Dcreate2 
doesn't fail
ctSpace = H5Screate_simple(1, dim, NULL);
ctDataSet = H5Dcreate2(fileId, "messageData", compoundType, ctSpace, 
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dwrite(ctDataSet, compoundType, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
&dummyData);
.
.
.
// for each message field
valueDT = H5Tcreate(H5T_COMPOUND, dtSize);
H5Tinsert(valueDT, valueName, 0, dataType);
H5Tinsert(compoundType, valueName, runningOffset, dataType);
runningOffset += dtSize;
status = H5Dwrite(ctDataSet, valueDT, H5S_ALL, ctSpace, H5P_DEFAULT, &value);
status = H5Tclose(valueDT);
.
.
.
status = H5Fflush(fileId, H5F_SCOPE_LOCAL);
status = H5Tclose(compoundType);
status = H5Sclose(ctSpace);
status = H5Dclose(ctDataSet);
status = H5Fclose(fileId);
I've left out error checking and initializations of a few variables for clarity.
There are a dozen or so values that I'm attempting to write out, but the only 
value that shows up in the output is the dummy that I put in initially.

On Thu, Jul 18, 2013 at 9:26 AM, Josiah Slack 
<[email protected]<mailto:[email protected]>> wrote:
Thanks - that seems pretty straightforward.
-Josiah


On Thu, Jul 18, 2013 at 8:57 AM, Gerd Heber 
<[email protected]<mailto:[email protected]>> wrote:
Reading or writing a compound type partially can be controlled via the
mem_type_id argument. Let's say you have a compound type in the file
with components A, B, and C. If you'd like to read only A or write to A,
just construct an in memory compound type with just an A component.
The library will match components by name between the file type and the
memory type.

G.

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

Reply via email to