How to skip a member in a struct

Hello,
I have an array of structs that I need to write to a dataset. One of the
members of the struct is a pointer to an array of floats. Right now I am
creating a compound datatype and treating the pointer as an unsigned int,
and this works, but the pointer information is obviously useless data. Is
there a way to write this array, but skip the pointer memeber?

Here is what I am currently doing:

Thanks!

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3527822.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Hi,

  you just need a different HDF5 type for the memory (the struct including
your pointer) and for the layout on disk (struct with same member names
and compatible data types, but omitting the pointer member). Then HDF5
will just do this conversion and write only those disk-struct members,
reading data from the memory-struct, except your pointer which is not
used for disk output then.

  Werner

···

On Tue, 22 Nov 2011 08:21:34 -0600, jwomble <jwomble@trideum.com> wrote:

Hello,
I have an array of structs that I need to write to a dataset. One of the
members of the struct is a pointer to an array of floats. Right now I am
creating a compound datatype and treating the pointer as an unsigned int,
and this works, but the pointer information is obviously useless data. Is
there a way to write this array, but skip the pointer memeber?

Here is what I am currently doing:

Thanks!

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3527822.html
Sent from the hdf-forum mailing list archive at Nabble.com.

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

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
211 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

Hi,

There are two options:
  * define a struct which includes the array of floats and write the data as a compound. Disadvantage, as always you can read individual members of your structure, but this goes much faster is your structure is small. Thus if you also access the data of your structure without the float-array data then do not use this option, but
  * write the float-array data to a separate dataset, with the fastest axis the size of the float-array and the slower axis the number of structs that write.

Note that your code is not portable to 64-bit, it now only works on 32-bit environments.

Greetings, Richard

···

On 11/22/2011 03:21 PM, jwomble wrote:

Hello,
I have an array of structs that I need to write to a dataset. One of the
members of the struct is a pointer to an array of floats. Right now I am
creating a compound datatype and treating the pointer as an unsigned int,
and this works, but the pointer information is obviously useless data. Is
there a way to write this array, but skip the pointer memeber?

Here is what I am currently doing:

Thanks!

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3527822.html
Sent from the hdf-forum mailing list archive at Nabble.com.

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

If I try to create a datatype without the pointer in it, when I write to the
file, the offsets don't match up, so my data is corrupted. How do I create
a second datatype and tell HDF5 that the two datatypes are equivalent?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3528191.html
Sent from the hdf-forum mailing list archive at Nabble.com.

I tried to include my code in the original message, but it doesn't seem to have made it - sorry about that. Here is the struct I'm working with:

    typedef struct {
         char name[50];
         int partType;
         int faceType;
         int materialNumber;
         float thickness;
         unsigned int numberOfPolygons;
         APolygon *facets; //array of polygons
    } ASubGroup;

The last memeber, .facets, is what's causing me problems. When I'm setting up my compound datatype, how do I account for this member, but not write it to the H5 file?

This is how I'm setting up the datatype now:

         ASubGroup tempGroup;
         hid_t tPartID = H5Tcreate(H5T_COMPOUND, sizeof(tempGroup));
         hsize_t arrDim[] = {50};
         hid_t tPartNameID = H5Tarray_create2(H5T_NATIVE_CHAR,1,arrDim);
         H5Tinsert(tPartID, "Name", HOFFSET(ASubGroup, name),
                   tPartNameID);
         H5Tinsert(tPartID, "PartType",HOFFSET(ASubGroup, partType),
                   H5T_NATIVE_INT);
         H5Tinsert(tPartID, "FaceType",HOFFSET(ASubGroup, faceType),
                   H5T_NATIVE_INT);
         H5Tinsert(tPartID, "Material",HOFFSET(ASubGroup, materialNumber),
                   H5T_NATIVE_INT);
         H5Tinsert(tPartID, "Thickness",HOFFSET(ASubGroup, thickness),
                   H5T_NATIVE_FLOAT);
         H5Tinsert(tPartID, "NumberOfFacets",HOFFSET(ASubGroup,
    numberOfPolygons),
                   H5T_NATIVE_UINT);
         H5Tinsert(tPartID, "reference", HOFFSET(ASubGroup, facets),
                   H5T_NATIVE_UINT32);

···

On 11/22/2011 09:30 AM, Werner Benger wrote:

Hi,

you just need a different HDF5 type for the memory (the struct including
your pointer) and for the layout on disk (struct with same member names
and compatible data types, but omitting the pointer member). Then HDF5
will just do this conversion and write only those disk-struct members,
reading data from the memory-struct, except your pointer which is not
used for disk output then.

    Werner

On Tue, 22 Nov 2011 08:21:34 -0600, jwomble <jwomble@trideum.com> wrote:

Hello,
I have an array of structs that I need to write to a dataset. One of the
members of the struct is a pointer to an array of floats. Right now I am
creating a compound datatype and treating the pointer as an unsigned int,
and this works, but the pointer information is obviously useless data. Is
there a way to write this array, but skip the pointer memeber?

Here is what I am currently doing:

Thanks!

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3527822.html
Sent from the hdf-forum mailing list archive at Nabble.com.

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

Hi!

···

On Nov 22, 2011, at 10:22 AM, jwomble wrote:

If I try to create a datatype without the pointer in it, when I write to the
file, the offsets don't match up, so my data is corrupted. How do I create
a second datatype and tell HDF5 that the two datatypes are equivalent?

  HDF5 matches fields in compound datatypes by names (recursively), so just create a memory datatype with the fields you would like to access in the file datatype and the library will fill just those fields in. (See the example code in the HDF5 distribution: example/h5_compund.c)

  Quincey

You will need to create two datatypes. The one below seems ok for 32-bit pointers, though maybe you could also create a (temporary) atomic datatype for your pointer member, using

   herr_t H5Tset_size( hid_t dtype_id, sizeof(APolygon*) )

just for this pointer member, so it'd be portable for 32 and 64 bit (and also 16 bit, if you want to run it under MSDOS :slight_smile: ).

This datatype as you create below is the memory datatype. In addition, you need a disk datatype, which looks exactly the same, but without the pointer member, so on H5Tcreate() it will be of size sizeof(tempGroup)-sizeof(APolygon*) , and you don't insert the pointer member on this second datatype.

This disk datatype is the one to be used for H5Dcreate(). The memory datatype is the one that you use when calling H5Dwrite().

  I assume currently you're using the same datatype for both functions. However, they don't need to be the same, and if they're not, HDF5 does that automatic data conversion, based on the names of the compound members.

        Werner

···

On Tue, 22 Nov 2011 09:47:44 -0600, Jeff Womble <jwomble@trideum.com> wrote:

I tried to include my code in the original message, but it doesn't seem to have made it - sorry about that. Here is the struct I'm working with:

typedef struct {
   char name[50];
   int partType;
   int faceType;
   int materialNumber;
   float thickness;
   unsigned int numberOfPolygons;
   APolygon *facets; //array of polygons
} ASubGroup;

The last memeber, .facets, is what's causing me problems. When I'm setting up my compound datatype, how do I account for this member, but not write it to the H5 file?

This is how I'm setting up the datatype now:

   ASubGroup tempGroup;
   hid_t tPartID = H5Tcreate(H5T_COMPOUND, sizeof(tempGroup));
   hsize_t arrDim[] = {50};
   hid_t tPartNameID = H5Tarray_create2(H5T_NATIVE_CHAR,1,arrDim);
   H5Tinsert(tPartID, "Name", HOFFSET(ASubGroup, name),
             tPartNameID);
   H5Tinsert(tPartID, "PartType",HOFFSET(ASubGroup, partType),
             H5T_NATIVE_INT);
   H5Tinsert(tPartID, "FaceType",HOFFSET(ASubGroup, faceType),
             H5T_NATIVE_INT);
   H5Tinsert(tPartID, "Material",HOFFSET(ASubGroup, materialNumber),
             H5T_NATIVE_INT);
   H5Tinsert(tPartID, "Thickness",HOFFSET(ASubGroup, thickness),
             H5T_NATIVE_FLOAT);
   H5Tinsert(tPartID, "NumberOfFacets",HOFFSET(ASubGroup, numberOfPolygons),
             H5T_NATIVE_UINT);
   H5Tinsert(tPartID, "reference", HOFFSET(ASubGroup, facets),
             H5T_NATIVE_UINT32);

On 11/22/2011 09:30 AM, Werner Benger wrote:

Hi,
you just need a different HDF5 type for the memory (the struct includingyour pointer) and for the layout on disk (struct with same member namesand compatible data types, but omitting the pointer member). Then HDF5will just do this conversion and write only those disk-struct members,reading data from the memory-struct, except your pointer which is notused for disk output then.
   Werner
On Tue, 22 Nov 2011 08:21:34 -0600, jwomble <jwomble@trideum.com> wrote:

Hello,I have an array of structs that I need to write to a dataset. One of themembers of the struct is a pointer to an array of floats. Right now I amcreating a compound datatype and treating the pointer as an unsigned int,and this works, but the pointer information is obviously useless data. Isthere a way to write this array, but skip the pointer memeber?
Here is what I am currently doing:

Thanks!

--View this message in context: http://hdf-forum.184993.n3.nabble.com/How-to-skip-a-member-in-a-struct-tp3527822p3527822.html
Sent from the hdf-forum mailing list archive at Nabble.com.
_______________________________________________Hdf-forum is for HDF software users discussion.Hdf-forum@hdfgroup.orghttp://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
211 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362