[hdf-forum] HDF5DotNet questions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[hdf-forum] HDF5DotNet questions

Mitchell, Scott - IS
Hi Jesse,

#2) I'm only starting to use the H5A functionality. But yes, I ran into the same problem of no examples of string attributes in HDF5DotNet. There is one example of using strings in all of the examples/tests. The dtypes test creates a string type, but does not use it.


I created a couple of file attributes using arrays of C_S1, which is how the string type is created in the dtypes test:

            H5DataTypeId stringID = H5T.copy(H5T.H5Type.C_S1);
            H5T.setSize(stringID, 30);
            H5DataTypeId vStringID = H5T.copy(H5T.H5Type.C_S1);
            H5T.setSize(vStringID, 0xFFFFFFFF);

            H5AttributeId strID = H5A.create(raeFile.HDF5FileID, "String",
                stringID, attributeSpace);
            H5AttributeId vstrID = H5A.create(raeFile.HDF5FileID, "vString",
                vStringID, attributeSpace);

            H5A.write<char>( strID, stringID,
                           new H5Array<char>(testID_c));
            H5A.write<char>( vstrID, vStringID,
                           new H5Array<char>(testID_c));

I can programmatically read & write the fixed length string just fine. But when I look at it in HDFView, I only get the first character. The variable length string is just junk, programmatically or in a viewing app.

Incidentally this same string problem occurs when the string is part of a compound data type in a dataset.

I'm afraid this approach to strings isn't right for the HDF5DotNet wrappers. But it is the one example that exists, incomplete as it is.


Scott

> -----Original Message-----
> From: Jesse Lai [mailto:jlai.matlab at gmail.com]
> Sent: Tuesday, May 26, 2009 11:20 PM
> To: hdf-forum at hdfgroup.org
> Subject: [hdf-forum] HDF5DotNet questions
>
> Hello,
>
> I've been using the HDF5DotNet wrapper library successfully with v1.8.2
> of the HDF5 libraries.  I'm programming in C#.  I have a few questions
> about the functionality that I couldn't quite figure out.  I'm a very
> novice programmer, so its likely these are very simple questions.
>
> 1) Is there a way using the functionality exposed by the current
> wrapper
> to query the version of the HDF5 libraries that are being used?  I have
> an about box in my application, and I'd like to display the version of
> the library (e.g. v1.8.2).
>
> 2) I would like to be able to read some attributes that are associated
> with a dataset.  I'm a little unsure of the H5A.read usage in the
> wrapper.  I saw the examples for a numeric attribute, but I didn't see
> any good examples for reading a string attribute.  I'm unsure of which
> type to use for the read generic and H5Array generic buffer.  I tried
> using a string type and I also tried using a char array that was
> initialized to the correct size since I could query the number of
> characters in the attribute correctly.  They both didn't seem to work
> right.  I can provide the code I'm trying if that helps, but is there
> an
> example of reading a character array attribute that I could look at?
>
> 3) I tried compiling the HDF5DotNet wrapper and I did it successfully
> with v1.8.2 of the HDF5 libraries.  However, I tried using v1.8.3 and
> it
> threw a bunch of errors.  I don't have those handy right now.  I'm not
> sure that they work with the already compiled version either.  Was
> there
> changes from v1.8.2. to v1.8.3 that would cause the wrapper to not
> compile correctly?
>
> Thanks for your help.
>
> Regards,
>
> Jesse
>
> ----------------------------------------------------------------------
> This mailing list is for HDF software users discussion.
> To subscribe to this list, send a message to hdf-forum-
> subscribe at hdfgroup.org.
> To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.


This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.

----------------------------------------------------------------------
This mailing list is for HDF software users discussion.
To subscribe to this list, send a message to hdf-forum-subscribe at hdfgroup.org.
To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.




Reply | Threaded
Open this post in threaded view
|

[hdf-forum] HDF5DotNet questions

Jesse Lai
Hi Scott,

Thank you very much for that example.  I believe that our string attributes
are currently fixed length, but we were looking into make them variable
length strings.  I'm thinking that I ran into some of the problems you just
described because the data that was being returned looked garbled and didn't
match what I can view in HDFView.  I will continue to look further and look
closer at your example to see if I can figure it out.

Thanks,

Jesse

On Wed, May 27, 2009 at 8:18 AM, Mitchell, Scott - AES <
Scott.Mitchell at itt.com> wrote:

> Hi Jesse,
>
> #2) I'm only starting to use the H5A functionality. But yes, I ran into the
> same problem of no examples of string attributes in HDF5DotNet. There is one
> example of using strings in all of the examples/tests. The dtypes test
> creates a string type, but does not use it.
>
>
> I created a couple of file attributes using arrays of C_S1, which is how
> the string type is created in the dtypes test:
>
>            H5DataTypeId stringID = H5T.copy(H5T.H5Type.C_S1);
>            H5T.setSize(stringID, 30);
>            H5DataTypeId vStringID = H5T.copy(H5T.H5Type.C_S1);
>            H5T.setSize(vStringID, 0xFFFFFFFF);
>
>            H5AttributeId strID = H5A.create(raeFile.HDF5FileID, "String",
>                stringID, attributeSpace);
>            H5AttributeId vstrID = H5A.create(raeFile.HDF5FileID, "vString",
>                vStringID, attributeSpace);
>
>            H5A.write<char>( strID, stringID,
>                           new H5Array<char>(testID_c));
>            H5A.write<char>( vstrID, vStringID,
>                           new H5Array<char>(testID_c));
>
> I can programmatically read & write the fixed length string just fine. But
> when I look at it in HDFView, I only get the first character. The variable
> length string is just junk, programmatically or in a viewing app.
>
> Incidentally this same string problem occurs when the string is part of a
> compound data type in a dataset.
>
> I'm afraid this approach to strings isn't right for the HDF5DotNet
> wrappers. But it is the one example that exists, incomplete as it is.
>
>
> Scott
>
> > -----Original Message-----
> > From: Jesse Lai [mailto:jlai.matlab at gmail.com]
> > Sent: Tuesday, May 26, 2009 11:20 PM
> > To: hdf-forum at hdfgroup.org
> > Subject: [hdf-forum] HDF5DotNet questions
> >
> > Hello,
> >
> > I've been using the HDF5DotNet wrapper library successfully with v1.8.2
> > of the HDF5 libraries.  I'm programming in C#.  I have a few questions
> > about the functionality that I couldn't quite figure out.  I'm a very
> > novice programmer, so its likely these are very simple questions.
> >
> > 1) Is there a way using the functionality exposed by the current
> > wrapper
> > to query the version of the HDF5 libraries that are being used?  I have
> > an about box in my application, and I'd like to display the version of
> > the library (e.g. v1.8.2).
> >
> > 2) I would like to be able to read some attributes that are associated
> > with a dataset.  I'm a little unsure of the H5A.read usage in the
> > wrapper.  I saw the examples for a numeric attribute, but I didn't see
> > any good examples for reading a string attribute.  I'm unsure of which
> > type to use for the read generic and H5Array generic buffer.  I tried
> > using a string type and I also tried using a char array that was
> > initialized to the correct size since I could query the number of
> > characters in the attribute correctly.  They both didn't seem to work
> > right.  I can provide the code I'm trying if that helps, but is there
> > an
> > example of reading a character array attribute that I could look at?
> >
> > 3) I tried compiling the HDF5DotNet wrapper and I did it successfully
> > with v1.8.2 of the HDF5 libraries.  However, I tried using v1.8.3 and
> > it
> > threw a bunch of errors.  I don't have those handy right now.  I'm not
> > sure that they work with the already compiled version either.  Was
> > there
> > changes from v1.8.2. to v1.8.3 that would cause the wrapper to not
> > compile correctly?
> >
> > Thanks for your help.
> >
> > Regards,
> >
> > Jesse
> >
> > ----------------------------------------------------------------------
> > This mailing list is for HDF software users discussion.
> > To subscribe to this list, send a message to hdf-forum-
> > subscribe at hdfgroup.org.
> > To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org.
>
>
> This e-mail and any files transmitted with it may be proprietary and are
> intended solely for the use of the individual or entity to whom they are
> addressed. If you have received this e-mail in error please notify the
> sender.
> Please note that any views or opinions presented in this e-mail are solely
> those of the author and do not necessarily represent those of ITT
> Corporation. The recipient should check this e-mail and any attachments for
> the presence of viruses. ITT accepts no liability for any damage caused by
> any virus transmitted by this e-mail.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20090527/25302e67/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] HDF5DotNet questions

Ruth Aydt
Administrator
A user contributed an example of variable-length strings with C# that  
perhaps would be of interest.  You can find it at

ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/hdf5/HDF5dotNetEnv/examples/


On May 27, 2009, at 1:53 PM, Jesse Lai wrote:

> Hi Scott,
>
> Thank you very much for that example.  I believe that our string  
> attributes are currently fixed length, but we were looking into make  
> them variable length strings.  I'm thinking that I ran into some of  
> the problems you just described because the data that was being  
> returned looked garbled and didn't match what I can view in  
> HDFView.  I will continue to look further and look closer at your  
> example to see if I can figure it out.
>
> Thanks,
>
> Jesse
>
> On Wed, May 27, 2009 at 8:18 AM, Mitchell, Scott - AES <Scott.Mitchell at itt.com
> > wrote:
> Hi Jesse,
>
> #2) I'm only starting to use the H5A functionality. But yes, I ran  
> into the same problem of no examples of string attributes in  
> HDF5DotNet. There is one example of using strings in all of the  
> examples/tests. The dtypes test creates a string type, but does not  
> use it.
>
>
> I created a couple of file attributes using arrays of C_S1, which is  
> how the string type is created in the dtypes test:
>
>            H5DataTypeId stringID = H5T.copy(H5T.H5Type.C_S1);
>            H5T.setSize(stringID, 30);
>            H5DataTypeId vStringID = H5T.copy(H5T.H5Type.C_S1);
>            H5T.setSize(vStringID, 0xFFFFFFFF);
>
>            H5AttributeId strID = H5A.create(raeFile.HDF5FileID,  
> "String",
>                stringID, attributeSpace);
>            H5AttributeId vstrID = H5A.create(raeFile.HDF5FileID,  
> "vString",
>                vStringID, attributeSpace);
>
>            H5A.write<char>( strID, stringID,
>                           new H5Array<char>(testID_c));
>            H5A.write<char>( vstrID, vStringID,
>                           new H5Array<char>(testID_c));
>
> I can programmatically read & write the fixed length string just  
> fine. But when I look at it in HDFView, I only get the first  
> character. The variable length string is just junk, programmatically  
> or in a viewing app.
>
> Incidentally this same string problem occurs when the string is part  
> of a compound data type in a dataset.
>
> I'm afraid this approach to strings isn't right for the HDF5DotNet  
> wrappers. But it is the one example that exists, incomplete as it is.
>
>
> Scott
>
> > -----Original Message-----
> > From: Jesse Lai [mailto:jlai.matlab at gmail.com]
> > Sent: Tuesday, May 26, 2009 11:20 PM
> > To: hdf-forum at hdfgroup.org
> > Subject: [hdf-forum] HDF5DotNet questions
> >
> > Hello,
> >
> > I've been using the HDF5DotNet wrapper library successfully with  
> v1.8.2
> > of the HDF5 libraries.  I'm programming in C#.  I have a few  
> questions
> > about the functionality that I couldn't quite figure out.  I'm a  
> very
> > novice programmer, so its likely these are very simple questions.
> >
> > 1) Is there a way using the functionality exposed by the current
> > wrapper
> > to query the version of the HDF5 libraries that are being used?  I  
> have
> > an about box in my application, and I'd like to display the  
> version of
> > the library (e.g. v1.8.2).
> >
> > 2) I would like to be able to read some attributes that are  
> associated
> > with a dataset.  I'm a little unsure of the H5A.read usage in the
> > wrapper.  I saw the examples for a numeric attribute, but I didn't  
> see
> > any good examples for reading a string attribute.  I'm unsure of  
> which
> > type to use for the read generic and H5Array generic buffer.  I  
> tried
> > using a string type and I also tried using a char array that was
> > initialized to the correct size since I could query the number of
> > characters in the attribute correctly.  They both didn't seem to  
> work
> > right.  I can provide the code I'm trying if that helps, but is  
> there
> > an
> > example of reading a character array attribute that I could look at?
> >
> > 3) I tried compiling the HDF5DotNet wrapper and I did it  
> successfully
> > with v1.8.2 of the HDF5 libraries.  However, I tried using v1.8.3  
> and
> > it
> > threw a bunch of errors.  I don't have those handy right now.  I'm  
> not
> > sure that they work with the already compiled version either.  Was
> > there
> > changes from v1.8.2. to v1.8.3 that would cause the wrapper to not
> > compile correctly?
> >
> > Thanks for your help.
> >
> > Regards,
> >
> > Jesse
> >
> >  
> ----------------------------------------------------------------------
> > This mailing list is for HDF software users discussion.
> > To subscribe to this list, send a message to hdf-forum-
> > subscribe at hdfgroup.org.
> > To unsubscribe, send a message to hdf-forum-
> unsubscribe at hdfgroup.org.
>
>
> This e-mail and any files transmitted with it may be proprietary and  
> are intended solely for the use of the individual or entity to whom  
> they are addressed. If you have received this e-mail in error please  
> notify the sender.
> Please note that any views or opinions presented in this e-mail are  
> solely those of the author and do not necessarily represent those of  
> ITT Corporation. The recipient should check this e-mail and any  
> attachments for the presence of viruses. ITT accepts no liability  
> for any damage caused by any virus transmitted by this e-mail.
>

------------------------------------------------------------
Ruth Aydt
The HDF Group

aydt at hdfgroup.org      (217)265-7837
------------------------------------------------------------




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20090527/e8130936/attachment.html>

Reply | Threaded
Open this post in threaded view
|

[hdf-forum] HDF5DotNet questions

Mitchell, Scott - IS
Thanks Ruth,

I took that example and added code which did the string attribute creation. Finding the right conversion function was key, because in part C# uses 2 byte chars. But I note that the variable length version works, the fixed length version still gets me junk in the attribute.

    static public H5AttributeId createStringAttribute(H5ObjectWithAttributes loc, string title, string attrText, bool variableLength)
    {
        const bool VERIFY_ATTR = true;
        H5AttributeId attrID = null;
        ulong len = (ulong)attrText.Length + 1;
        ulong[] one = { len };

        H5DataSpaceId attributeSpace;
        attributeSpace = H5S.create_simple(1, one);

        H5DataTypeId stringID = H5T.copy(H5T.H5Type.C_S1);
        if (variableLength)
            H5T.setSize(stringID, 0xFFFFFFFF); // 0xFFFFFFFF is variable
        else
            H5T.setSize(stringID, (uint)len);         // is fixed

        try
        {
            // Create the Attribute
            attrID = H5A.create(loc, title, stringID, attributeSpace);

            unsafe
            {
                // Setup output string
                Chararray[] inArray = new Chararray[1];
                IntPtr ipp = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(attrText);
                inArray[0].recordedText = (char*)ipp;

                // Write
                H5A.write(attrID, stringID, new H5Array<Chararray>(inArray));

                // Cleanup
                System.Runtime.InteropServices.Marshal.FreeHGlobal(ipp);

                if (VERIFY_ATTR)
                {
                    Chararray[] outArray = new Chararray[1];
                    H5A.read(attrID, stringID, new H5Array<Chararray>(outArray));
                    string readAttr = outArray[0].ToString();
                    if (readAttr.CompareTo(attrText) != 0)
                        Console.WriteLine("createStringAttribute: VERIFY_ATTR failed - read value differs from input:\n\tread: {0}\n\tinput: {1}", readAttr, attrText);
                }
            }// unsafe

        }
        catch (Exception ex)
        {
            System.Console.WriteLine(ex.ToString());
            attrID = null;
        }
        finally
        {
            // Cleanup
            if (attributeSpace != null) H5S.close(attributeSpace);
            if (stringID != null) H5T.close(stringID);
            if (attrID != null) H5A.close(attrID);
        }

        return attrID;
    }

Also, I took the output code from the example and added it as a ToString() override in Chararray.
        public override string ToString()
        {
            string s;
            //the HDF5 STRING is not a string but in fact a char *
            //since it is we need to translate the return into a pointer address

            IntPtr ipp = (IntPtr)this.recordedText;
            //This call is used to transform the pointer into the value of the pointer.

            //NOTE:  this only works with null-terminated strings.
            s = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ipp);

            return s;
        }

BTW, who is responsible for freeing the memory that is stored in recordedText? It is filled in H5A.read<>.

Scott

From: Ruth Aydt [mailto:aydt at hdfgroup.org]
Sent: Wednesday, May 27, 2009 3:49 PM
To: hdf-forum forum
Subject: Re: [hdf-forum] HDF5DotNet questions

A user contributed an example of variable-length strings with C# that perhaps would be of interest.  You can find it at

ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/hdf5/HDF5dotNetEnv/examples/


On May 27, 2009, at 1:53 PM, Jesse Lai wrote:


Hi Scott,

Thank you very much for that example.  I believe that our string attributes are currently fixed length, but we were looking into make them variable length strings.  I'm thinking that I ran into some of the problems you just described because the data that was being returned looked garbled and didn't match what I can view in HDFView.  I will continue to look further and look closer at your example to see if I can figure it out.

Thanks,

Jesse
On Wed, May 27, 2009 at 8:18 AM, Mitchell, Scott - AES <Scott.Mitchell at itt.com<mailto:Scott.Mitchell at itt.com>> wrote:
Hi Jesse,

#2) I'm only starting to use the H5A functionality. But yes, I ran into the same problem of no examples of string attributes in HDF5DotNet. There is one example of using strings in all of the examples/tests. The dtypes test creates a string type, but does not use it.


I created a couple of file attributes using arrays of C_S1, which is how the string type is created in the dtypes test:

           H5DataTypeId stringID = H5T.copy(H5T.H5Type.C_S1);
           H5T.setSize(stringID, 30);
           H5DataTypeId vStringID = H5T.copy(H5T.H5Type.C_S1);
           H5T.setSize(vStringID, 0xFFFFFFFF);

           H5AttributeId strID = H5A.create(raeFile.HDF5FileID, "String",
               stringID, attributeSpace);
           H5AttributeId vstrID = H5A.create(raeFile.HDF5FileID, "vString",
               vStringID, attributeSpace);

           H5A.write<char>( strID, stringID,
                          new H5Array<char>(testID_c));
           H5A.write<char>( vstrID, vStringID,
                          new H5Array<char>(testID_c));

I can programmatically read & write the fixed length string just fine. But when I look at it in HDFView, I only get the first character. The variable length string is just junk, programmatically or in a viewing app.

Incidentally this same string problem occurs when the string is part of a compound data type in a dataset.

I'm afraid this approach to strings isn't right for the HDF5DotNet wrappers. But it is the one example that exists, incomplete as it is.


Scott

> -----Original Message-----
> From: Jesse Lai [mailto:jlai.matlab at gmail.com<mailto:jlai.matlab at gmail.com>]
> Sent: Tuesday, May 26, 2009 11:20 PM
> To: hdf-forum at hdfgroup.org<mailto:hdf-forum at hdfgroup.org>
> Subject: [hdf-forum] HDF5DotNet questions
>
> Hello,
>
> I've been using the HDF5DotNet wrapper library successfully with v1.8.2
> of the HDF5 libraries.  I'm programming in C#.  I have a few questions
> about the functionality that I couldn't quite figure out.  I'm a very
> novice programmer, so its likely these are very simple questions.
>
> 1) Is there a way using the functionality exposed by the current
> wrapper
> to query the version of the HDF5 libraries that are being used?  I have
> an about box in my application, and I'd like to display the version of
> the library (e.g. v1.8.2).
>
> 2) I would like to be able to read some attributes that are associated
> with a dataset.  I'm a little unsure of the H5A.read usage in the
> wrapper.  I saw the examples for a numeric attribute, but I didn't see
> any good examples for reading a string attribute.  I'm unsure of which
> type to use for the read generic and H5Array generic buffer.  I tried
> using a string type and I also tried using a char array that was
> initialized to the correct size since I could query the number of
> characters in the attribute correctly.  They both didn't seem to work
> right.  I can provide the code I'm trying if that helps, but is there
> an
> example of reading a character array attribute that I could look at?
>
> 3) I tried compiling the HDF5DotNet wrapper and I did it successfully
> with v1.8.2 of the HDF5 libraries.  However, I tried using v1.8.3 and
> it
> threw a bunch of errors.  I don't have those handy right now.  I'm not
> sure that they work with the already compiled version either.  Was
> there
> changes from v1.8.2. to v1.8.3 that would cause the wrapper to not
> compile correctly?
>
> Thanks for your help.
>
> Regards,
>
> Jesse
>
> ----------------------------------------------------------------------
> This mailing list is for HDF software users discussion.
> To subscribe to this list, send a message to hdf-forum-
> subscribe at hdfgroup.org<mailto:subscribe at hdfgroup.org>.
> To unsubscribe, send a message to hdf-forum-unsubscribe at hdfgroup.org<mailto:hdf-forum-unsubscribe at hdfgroup.org>.


This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.


------------------------------------------------------------
Ruth Aydt
The HDF Group

aydt at hdfgroup.org<mailto:aydt at hdfgroup.org>      (217)265-7837
------------------------------------------------------------





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/attachments/20090601/afdf9db8/attachment.html>