public static int WriteUnicodeString(hid_t groupId, string name, string str, H5T.str_t strPad = H5T.str_t.SPACEPAD)
        {
            byte[] wdata = Encoding.UTF8.GetBytes(str);

            hid_t spaceId = H5S.create(H5S.class_t.SCALAR);

            hid_t dtype = H5T.create(H5T.class_t.STRING, new IntPtr(wdata.Length));

            H5T.set_cset(dtype, H5T.cset_t.UTF8);
            H5T.set_strpad(dtype, strPad);

            hid_t datasetId = H5D.create(groupId, name, dtype, spaceId);

            GCHandle hnd    = GCHandle.Alloc(wdata, GCHandleType.Pinned);
            int      result = H5D.write(datasetId, dtype, H5S.ALL,
                                        H5S.ALL, H5P.DEFAULT, hnd.AddrOfPinnedObject());

            hnd.Free();

            H5T.close(dtype);
            H5D.close(datasetId);
            H5S.close(spaceId);
            return(result);
        }
Exemple #2
0
        public static int WriteUnicodeString(long groupId, string name, string str, H5T.str_t strPad = H5T.str_t.SPACEPAD)
        {
            byte[] wdata = Hdf5Utils.StringToByte(str);

            long spaceId = H5S.create(H5S.class_t.SCALAR);

            long dtype = H5T.create(H5T.class_t.STRING, new IntPtr(wdata.Length));

            H5T.set_cset(dtype, Hdf5Utils.GetCharacterSet(Settings.CharacterSetType));
            H5T.set_strpad(dtype, strPad);

            long datasetId = H5D.create(groupId, Hdf5Utils.NormalizedName(name), dtype, spaceId);

            GCHandle hnd    = GCHandle.Alloc(wdata, GCHandleType.Pinned);
            int      result = H5D.write(datasetId, dtype, H5S.ALL,
                                        H5S.ALL, H5P.DEFAULT, hnd.AddrOfPinnedObject());

            hnd.Free();

            H5T.close(dtype);
            H5D.close(datasetId);
            H5S.close(spaceId);
            return(result);
        }