public static (int success, long CreatedgroupId) WriteStrings(long groupId, string name, IEnumerable <string> strs) { // create UTF-8 encoded test datasets long datatype = H5T.create(H5T.class_t.STRING, H5T.VARIABLE); H5T.set_cset(datatype, H5T.cset_t.ASCII); H5T.set_strpad(datatype, H5T.str_t.NULLTERM); int strSz = strs.Count(); long spaceId = H5S.create_simple(1, new[] { (ulong)strSz }, null); string normalizedName = Hdf5Utils.NormalizedName(name); var datasetId = Hdf5Utils.GetDatasetId(groupId, normalizedName, datatype, spaceId); if (datasetId == -1L) { return(-1, -1L); } GCHandle[] hnds = new GCHandle[strSz]; IntPtr[] wdata = new IntPtr[strSz]; int cntr = 0; foreach (string str in strs) { hnds[cntr] = GCHandle.Alloc( Encoding.UTF8.GetBytes(str), GCHandleType.Pinned); wdata[cntr] = hnds[cntr].AddrOfPinnedObject(); cntr++; } var hnd = GCHandle.Alloc(wdata, GCHandleType.Pinned); var result = H5D.write(datasetId, datatype, H5S.ALL, H5S.ALL, H5P.DEFAULT, hnd.AddrOfPinnedObject()); hnd.Free(); for (int i = 0; i < strSz; ++i) { hnds[i].Free(); } H5D.close(datasetId); H5S.close(spaceId); H5T.close(datatype); return(result, datasetId); }