public Hdf5AcquisitionFileWriter(string aFilename, string groupName = "/EEG") { fileId = Hdf5.CreateFile(aFilename); _groupName = groupName; _groupId = Hdf5.CreateGroup(fileId, _groupName); Header = new Hdf5AcquisitionFile(); _nrOfRecords = 0; _sampleCount = 0; }
// private readonly ReaderWriterLockSlim lock_ = new ReaderWriterLockSlim(); public Hdf5AcquisitionFileWriter(string filename, string groupName = "ROOT") { H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero); //lock_.EnterWriteLock(); _filename = filename; fileId = Hdf5.CreateFile(filename); _groupName = groupName; _groupId = Hdf5.CreateGroup(fileId, _groupName); Header = new Hdf5AcquisitionFile(); _nrOfRecords = 0; _sampleCount = 0; //lock_.ExitWriteLock(); }
/// <summary> /// Writes data to the hdf5 file. /// </summary> public void Write(IList <double[]> signals) { int cols = signals.Count(); if (cols == 0) { return; } int rows = signals[0].Length; if (rows == 0) { return; } double sr = _header.Recording.SampleRate; var data = new short[rows, cols]; //var byteLength = rows * sizeof(short); for (int i = 0; i < cols; i++) { var sig = signals[i]; for (int j = 0; j < rows; j++) { data[j, i] = convert2Short(sig[j], i); } } var dataName = string.Concat("/", _groupName, "/Data"); if (_nrOfRecords == 0) { _header.Recording.StartTime = DateTime.Now; Hdf5.CreateGroup(fileId, _groupName); dset = new ChunkedDataset <short>(dataName, fileId, data); } else { dset.AppendDataset(data); } _nrOfRecords++; }
public static object WriteObject(hid_t groupId, object writeValue, string groupName = null) { if (writeValue == null) { throw new ArgumentNullException(nameof(writeValue)); } bool createGroupName = !string.IsNullOrWhiteSpace(groupName); if (createGroupName) { groupId = Hdf5.CreateGroup(groupId, groupName); } Type tyObject = writeValue.GetType(); foreach (Attribute attr in Attribute.GetCustomAttributes(tyObject)) { Hdf5SaveAttribute legAt = attr as Hdf5SaveAttribute; if (legAt != null) { Hdf5Save kind = legAt.SaveKind; if (kind == Hdf5Save.DoNotSave) { return(writeValue); } } } WriteProperties(tyObject, writeValue, groupId); WriteFields(tyObject, writeValue, groupId); WriteHdf5Attributes(tyObject, groupId, groupName); if (createGroupName) { Hdf5.CloseGroup(groupId); } return(writeValue); }