c# read different datatypes

Hi,I have a problem with reading datatypes in HDF5.
If i know that there is <int>
  H5D.read(datasetID, dataType, new H5Array<int>(dataint));
it's ok.
But in the dataset there is a table with mixed datatypes.
To grab data i used
  struct metadata
{
public string a;
public int b;
public float c;
public float d;
public string f; (and so on)
}

metadata[] s1 = new metadata[1];

H5D.read(datasetID, dataType, new H5Array<metadata_song>(s1));
But strings are returned as null, float data is not correct as well as int.
Can u show the point wich i have missed?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Insane,

Due to the way string objects are handled in .NET, you've got to do a workaround. There are some examples in the archives, the keyword is Chararray. We use the Chararray class to generate a character array which is what the HDF library ends up using. There were some examples in the .NET docs, but I can't find them after the migration to the hdf5.net domain.

http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/2009-June/000216.html
http://mail.hdfgroup.org/pipermail/hdf-forum_hdfgroup.org/2009-September/001765.html

Scott

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Tuesday, April 09, 2013 10:16 AM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] c# read different datatypes

Hi,I have a problem with reading datatypes in HDF5.
If i know that there is <int>
  H5D.read(datasetID, dataType, new H5Array<int>(dataint)); it's ok.
But in the dataset there is a table with mixed datatypes.
To grab data i used
  struct metadata
{
public string a;
public int b;
public float c;
public float d;
public string f; (and so on)
}

metadata[] s1 = new metadata[1];

H5D.read(datasetID, dataType, new H5Array<metadata_song>(s1)); But
strings are returned as null, float data is not correct as well as
int.
Can u show the point wich i have missed?

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

Thx,I got the idea with <string> ,hope i`ll cope with this,
but how should i solve the problem with other data types?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026059.html
Sent from the hdf-forum mailing list archive at Nabble.com.

With the string/Chararray fix, I think things will work. String is probably screwing up the offset of the rest of the fields. I think if you had an int/float/etc. first that one would work, but all after the string go 'bad'.

Perhaps you need to add a [StructLayout(LayoutKind.Sequential)] to your struct. I do, but I'm not sure it's necessary.

Scott

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Tuesday, April 09, 2013 11:31 AM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

Thx,I got the idea with <string> ,hope i`ll cope with this, but how
should i solve the problem with other data types?

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026059.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

Maybe, I am misunderstanding smth.
I used this code
[StructLayout(LayoutKind.Sequential)]
        public unsafe struct Chararray
        {
            private double* recordedText;

            //an initializer to get and set the char* since it is unsafe
            public double* RecordedText
            {
                get
                {
                    return recordedText;
                }
                set
                {
                    recordedText = value;
                }
            }

            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
pointeraddress

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

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

                return s;
            }
        }

···

-------------
and added <CharArray> instead of <char>

now the returning value of "CharArray" (is "0x000007ce " double*)

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026061.html
Sent from the hdf-forum mailing list archive at Nabble.com.

[StructLayout(LayoutKind.Sequential)] should be at the head of your metadata struct not Chararray.

So,

[StructLayout(LayoutKind.Sequential)]
struct metadata
{
        public Chararray a;
        public int b;
        public float c;
        public float d;
        public Chararray f;
        (and so on)
}

And define your strings within the HDF dataType as C_S1 and H5T.setVariableSize().

Scott

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Tuesday, April 09, 2013 3:58 PM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

Maybe, I am misunderstanding smth.
I used this code
[StructLayout(LayoutKind.Sequential)]
        public unsafe struct Chararray
        {
            private double* recordedText;

            //an initializer to get and set the char* since it is
unsafe
            public double* RecordedText
            {
                get
                {
                    return recordedText;
                }
                set
                {
                    recordedText = value;
                }
            }

            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
pointeraddress

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

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

                return s;
            }
        }
-------------
and added <CharArray> instead of <char>

now the returning value of "CharArray" (is "0x000007ce " double*)

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026061.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

Also I'm not sure why you're using a double* in Chararray. It should be a char* and is only used as a replacement for string. This is what I use:

        /// <summary>
        /// Chararray is a helper struct to marshal the strings into/out of unmanaged HDF.
        /// </summary>
        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct Chararray
        {
            /// <summary>
            /// internal C-string pointer.
            /// </summary>
            [System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]
            private char* mText;

            /// <summary>
            /// Creator to Load text value
            /// </summary>
            /// <param name="text">string to load</param>
            public Chararray(string text)
            {
                // Duplicate 'Load' functionality
                IntPtr ipp = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(text);
                this.mText = (char*)ipp;
            }

            /// <summary>
            /// an initializer to get and set the char* since it is unsafe
            /// </summary>
            public char* Text
            {
                get
                {
                    return mText;
                }
            }

            /// <summary>
            /// free the text entered with Load
            /// </summary>
            public void Cleanup()
            {
                if (mText != null)
                {
                    System.Runtime.InteropServices.Marshal.FreeHGlobal((IntPtr)mText);
                    mText = null;
                }
            }

            /// <summary>
            /// Override of ToString to get a .NET string from C.
            /// </summary>
            /// <returns>a .NET string</returns>
            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.Text;
                //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;
            }
        } // Chararray

Scott

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Tuesday, April 09, 2013 3:58 PM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

Maybe, I am misunderstanding smth.
I used this code
[StructLayout(LayoutKind.Sequential)]
        public unsafe struct Chararray
        {
            private double* recordedText;

            //an initializer to get and set the char* since it is
unsafe
            public double* RecordedText
            {
                get
                {
                    return recordedText;
                }
                set
                {
                    recordedText = value;
                }
            }

            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
pointeraddress

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

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

                return s;
            }
        }
-------------
and added <CharArray> instead of <char>

now the returning value of "CharArray" (is "0x000007ce " double*)

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026061.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

Sorry,what do you mean by
"And define your strings within the HDF dataType as C_S1 and
H5T.setVariableSize(). "?
I got the dataType this way:
var dataType = H5D.getType(datasetID);

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026066.html
Sent from the hdf-forum mailing list archive at Nabble.com.

In my code I build the dataset via brute force to write the data. So I build out the H5T struct(s) that I use.

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Tuesday, April 09, 2013 4:46 PM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

Sorry,what do you mean by
"And define your strings within the HDF dataType as C_S1 and
H5T.setVariableSize(). "?
I got the dataType this way:
var dataType = H5D.getType(datasetID);

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026066.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

I still can't get the idea ,what is not correct,where and how u define the
datatype
If i get the datatype from the dataset, what for should we make strict
definition?
Btw,are there any examples with method?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026068.html
Sent from the hdf-forum mailing list archive at Nabble.com.

I got stuck with it.When i use call s1[0].a.ToString() ,it returns "
",the rest of the data wich distinguishes from CharArray is not also
correct.How should i define the datatype of the dataset in another
way?Should i define the datatype only for string data and is it possible?
            H5AttributeId attributeId=null;
            H5DataTypeId dataType = null;
            H5DataSetId dsetId = H5D.open(fileID, "/metadata/songs");
            dt = H5D.getType(dsetId);
            H5D.read(dsetId, dataType, new H5Array<metadata>(s1));

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026071.html
Sent from the hdf-forum mailing list archive at Nabble.com.

It looks ok at first glance. Do you define s1?

I have no code I can extract for a simple example, but I have many where I use strings in a compound data type.

S

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Wednesday, April 10, 2013 4:57 PM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

I got stuck with it.When i use call s1[0].a.ToString() ,it returns
"
",the rest of the data wich distinguishes from CharArray is not also
correct.How should i define the datatype of the dataset in another
way?Should i define the datatype only for string data and is it
possible?
            H5AttributeId attributeId=null;
            H5DataTypeId dataType = null;
            H5DataSetId dsetId = H5D.open(fileID, "/metadata/songs");
            dt = H5D.getType(dsetId);
            H5D.read(dsetId, dataType, new H5Array<metadata>(s1));

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026071.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

The only thing I saw in examples was next:
H5DataTypeId typeId = H5T.copy(H5T.H5Type.C_S1);
But i don't actually know how it can help.Can u explain exactly how it
should be defined ?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026073.html
Sent from the hdf-forum mailing list archive at Nabble.com.

You need to allocate a buffer where H5D.read() stores the data. H5Array doesn't do that, it's just a wrapper. You should have something like:

                Metadata[] s1 = new Metadata[datasetSize];
            H5DataSetId dsetId = H5D.open(fileID, "/metadata/songs");
            H5DataTypeId dataType = H5D.getType(dsetId);
            H5D.read(dsetId, dataType, new H5Array<metadata>(s1));

Scott

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of
Insane
Sent: Wednesday, April 10, 2013 5:17 PM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] c# read different datatypes

The only thing I saw in examples was next:
H5DataTypeId typeId = H5T.copy(H5T.H5Type.C_S1); But i don't actually
know how it can help.Can u explain exactly how it should be defined ?

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-
read-different-datatypes-tp4026057p4026073.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

________________________________

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 Exelis Inc. The recipient should check this e-mail and any attachments for the presence of viruses. Exelis Inc. accepts no liability for any damage caused by any virus transmitted by this e-mail.

Ah,i have done it already,i just didn't get your question from the very
beginning.
Sure, i defined s1
metadata[] s1 = new metadata[1];
After H5D.read ,i have data in s1 but the data is not correct.

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026075.html
Sent from the hdf-forum mailing list archive at Nabble.com.

example of h5 file,i took it from million song dataset
TRAAAVO128F93133D4.h5
<http://hdf-forum.184993.n3.nabble.com/file/n4026076/TRAAAVO128F93133D4.h5>
table is /metadata/songs
even when i debug ToString the data is wrong.
Should i set fixed sizes for strings or do smth else?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026076.html
Sent from the hdf-forum mailing list archive at Nabble.com.

If you watch the file in Hdfview <string> has different length *32* and
*1024*. Can it influence the results?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026081.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Can anyone show how to read string data and compound data,cause all my
attempts end up with unreadable output and without this data i can't go
ahead -__- to make some calculations.
TRAAAVO128F93133D4.h5
<http://hdf-forum.184993.n3.nabble.com/file/n4026086/TRAAAVO128F93133D4.h5>
The majority of similar questions in this forum are unanswered (

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026086.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Here is a C# class that i created for my application to read / write some 2D
and 3D arrays and basic data types. It has functions to read / write
strings. I have not used compound data. Hope this helps a bit.

Shashi

class HDFFileHandler
    {
        public enum DataTypes
        {
            STRING,
            INTEGER,
            DOUBLE,
            BYTE,
            USHORT,
            FLOAT
        }

        public H5FileId CreateFile(string filename)
        {
            return H5F.create(filename, H5F.CreateMode.ACC_TRUNC);
        }
        public H5GroupId CreateGroup(string groupName, H5LocId parentGroup)
        {
            return H5G.create(parentGroup, groupName);
        }
        public H5DataSetId Create1DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int size)
        {
            long[] dims = new long[1];
            dims[0] = size;

            H5DataSpaceId spaceId = H5S.create_simple(1, dims);
            H5DataTypeId typeId = null;
            switch (datatype)
            {
                case DataTypes.BYTE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
                    break;
                case DataTypes.DOUBLE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
                    break;
                case DataTypes.INTEGER:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
                    break;
                case DataTypes.STRING:
                    typeId = H5T.copy(H5T.H5Type.C_S1);
                    break;
                case DataTypes.FLOAT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
                    break;
                case DataTypes.USHORT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
                    break;
                default:
                    break;
            }
            return H5D.create(parentGroup, datasetName, typeId, spaceId);
        }
        public H5DataSetId Create2DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int sizeX, int sizeY)
        {
            long[] dims = new long[2];
            dims[0] = sizeX;
            dims[1] = sizeY;

            H5DataSpaceId spaceId = H5S.create_simple(2, dims);
            H5DataTypeId typeId = null;
            switch (datatype)
            {
                case DataTypes.BYTE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
                    break;
                case DataTypes.DOUBLE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
                    break;
                case DataTypes.INTEGER:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
                    break;
                case DataTypes.STRING:
                    typeId = H5T.copy(H5T.H5Type.C_S1);
                    break;
                case DataTypes.FLOAT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
                    break;
                case DataTypes.USHORT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
                    break;
                default:
                    break;
            }
            return H5D.create(parentGroup, datasetName, typeId, spaceId);
        }
        public H5DataSetId Create3DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int sizeX, int sizeY, int
nSizeZ)
        {
            long[] dims = new long[3];
            dims[0] = sizeX;
            dims[1] = sizeY;
            dims[2] = nSizeZ;

            H5DataSpaceId spaceId = H5S.create_simple(3, dims);
            H5DataTypeId typeId = null;
            switch (datatype)
            {
                case DataTypes.BYTE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
                    break;
                case DataTypes.DOUBLE:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
                    break;
                case DataTypes.INTEGER:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
                    break;
                case DataTypes.STRING:
                    typeId = H5T.copy(H5T.H5Type.C_S1);
                    break;
                case DataTypes.FLOAT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
                    break;
                case DataTypes.USHORT:
                    typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
                    break;
                default:
                    break;
            }
            return H5D.create(parentGroup, datasetName, typeId, spaceId);
        }
        public void CloseFile(H5FileId fileId)
        {
            H5F.close(fileId);
        }
        public void CloseGroup(H5GroupId grpId)
        {
            H5G.close(grpId);
        }
        public void CloseDataset(H5DataSetId datasetId)
        {
            H5D.close(datasetId);
        }
        public H5FileId OpenFile(string filename, H5F.OpenMode mode)
        {
            return H5F.open(filename, mode);
        }
        public H5GroupId OpenGroup(string grpName, H5LocId parentID)
        {
            return H5G.open(parentID, grpName);
        }
        public H5DataSetId OpenDataset(string datasetName, H5FileOrGroupId
parentID)
        {
            return H5D.open(parentID, datasetName);
        }

        public void WriteByteArray(H5DataSetId dataSetId, byte[] byteArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
            H5D.write(dataSetId, typeId, new H5Array<byte>(byteArray));
        }
        public void ReadByteArray(H5DataSetId dataSetId, byte[] byteArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
            H5D.read(dataSetId, typeId, new H5Array<byte>(byteArray));
        }
        public void WriteIntegerArray(H5DataSetId dataSetId, int[] intArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
            H5D.write(dataSetId, typeId, new H5Array<int>(intArray));
        }
        public void ReadIntegerArray(H5DataSetId dataSetId, int[] intArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
            H5D.read(dataSetId, typeId, new H5Array<int>(intArray));
        }
        public void WriteFloatArray(H5DataSetId dataSetId, float[]
floatArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
            H5D.write(dataSetId, typeId, new H5Array<float>(floatArray));
        }
        public void ReadFloatArray(H5DataSetId dataSetId, float[]
floatArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
            H5D.read(dataSetId, typeId, new H5Array<float>(floatArray));
        }
        public void WriteDoubleArray(H5DataSetId dataSetId, double[]
dblArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
            H5D.write(dataSetId, typeId, new H5Array<double>(dblArray));
        }
        public void ReadDoubleArray(H5DataSetId dataSetId, double[]
dblArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
            H5D.read(dataSetId, typeId, new H5Array<double>(dblArray));
        }
        public void WriteUShortArray(H5DataSetId dataSetId, ushort[]
ushortArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
            H5D.write(dataSetId, typeId, new H5Array<ushort>(ushortArray));
        }
        public void ReadUShortArray(H5DataSetId dataSetId, ushort[]
ushortArray)
        {
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
            H5D.read(dataSetId, typeId, new H5Array<ushort>(ushortArray));
        }
        public void WriteInteger(H5DataSetId dataSetId, int nValue)
        {
            int[] data = new int[1];
            data[0] = nValue;
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
            H5D.write(dataSetId, typeId, new H5Array<int>(data));
        }
        public int ReadInteger(H5DataSetId dataSetId)
        {
            int[] data = new int[1];
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
            H5D.read(dataSetId, typeId, new H5Array<int>(data));
            return data[0];
        }
        public void WriteFloat(H5DataSetId dataSetId, float fValue)
        {
            float[] data = new float[1];
            data[0] = fValue;
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
            H5D.write(dataSetId, typeId, new H5Array<float>(data));
        }
        public float ReadFloat(H5DataSetId dataSetId)
        {
            float[] data = new float[1];
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
            H5D.read(dataSetId, typeId, new H5Array<float>(data));
            return data[0];
        }
        public void WriteDouble(H5DataSetId dataSetId, ref double dValue)
        {
            double[] data = new double[1];
            data[0] = dValue;
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
            H5D.write(dataSetId, typeId, new H5Array<double>(data));
        }
        public double ReadDouble(H5DataSetId dataSetId)
        {
            double[] data = new double[1];
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
            H5D.read(dataSetId, typeId, new H5Array<double>(data));
            return data[0];
        }
        public void WriteString(H5DataSetId dataSetId, string strData)
        {
            byte[] byteArray = Encoding.ASCII.GetBytes(strData);
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.C_S1);
            H5D.write(dataSetId, typeId, new H5Array<byte>(byteArray));
        }
        public string ReadString(H5DataSetId dataSetId, int nSize)
        {
            byte[] byteArray = new byte[nSize];
            H5DataTypeId typeId = H5T.copy(H5T.H5Type.C_S1);
            H5D.read(dataSetId, typeId, new H5Array<byte>(byteArray));
            return System.Text.Encoding.ASCII.GetString(byteArray);
        }
    }

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026087.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Thx,unfortunately,i have already tried reading string as byte array and it
returns 0 .

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026088.html
Sent from the hdf-forum mailing list archive at Nabble.com.