diff --git a/Source/Processors/RecordNode/HDF5FileFormat.cpp b/Source/Processors/RecordNode/HDF5FileFormat.cpp index 62a7466c5079695a0dd4ffd445d506e9ed1eec26..0e1d1e2c3c83482a08355566cc0fa0b778a5413f 100644 --- a/Source/Processors/RecordNode/HDF5FileFormat.cpp +++ b/Source/Processors/RecordNode/HDF5FileFormat.cpp @@ -117,6 +117,12 @@ void HDF5FileBase::close() } int HDF5FileBase::setAttribute(DataTypes type, void* data, String path, String name) +{ + return setAttributeArray(type, data, 1, path, name); +} + + +int HDF5FileBase::setAttributeArray(DataTypes type, void* data, int size, String path, String name) { Group loc; Attribute attr; @@ -131,6 +137,13 @@ int HDF5FileBase::setAttribute(DataTypes type, void* data, String path, String n H5type = getH5Type(type); origType = getNativeType(type); + if (size > 1) + { + hsize_t dims = size; + H5type = ArrayType(H5type,1,&dims); + origType = ArrayType(origType,1,&dims); + } + if (loc.attrExists(name.toUTF8())) { attr = loc.openAttribute(name.toUTF8()); @@ -605,6 +618,8 @@ void KWDFile::startNewRecording(int recordingNumber, int nChannels, HDF5Recordin // CHECK_ERROR(setAttribute(U32,&(info->start_sample),recordPath,String("start_sample"))); CHECK_ERROR(setAttribute(F32,&(info->sample_rate),recordPath,String("sample_rate"))); CHECK_ERROR(setAttribute(U32,&(info->bit_depth),recordPath,String("bit_depth"))); + CHECK_ERROR(createGroup(recordPath+"/application_data")); + CHECK_ERROR(setAttributeArray(F32,info->bitVolts.getRawDataPointer(),info->bitVolts.size(),recordPath+"/application_data",String("channel_bit_volts"))); recdata = createDataSet(I16,0,nChannels,CHUNK_XSIZE,recordPath+"/data"); if (!recdata.get()) std::cerr << "Error creating data set" << std::endl; diff --git a/Source/Processors/RecordNode/HDF5FileFormat.h b/Source/Processors/RecordNode/HDF5FileFormat.h index 1fc8e675fb5d9c5d9dae130ec4fc0317e5f14f86..c228647ef344a5565f75474ee3229daed6e79a5c 100644 --- a/Source/Processors/RecordNode/HDF5FileFormat.h +++ b/Source/Processors/RecordNode/HDF5FileFormat.h @@ -41,6 +41,7 @@ struct HDF5RecordingInfo uint32 start_sample; float sample_rate; uint32 bit_depth; + Array<float> bitVolts; }; class HDF5FileBase @@ -64,6 +65,7 @@ protected: int setAttribute(DataTypes type, void* data, String path, String name); int setAttributeStr(String value, String path, String name); + int setAttributeArray(DataTypes type, void* data, int size, String path, String name); int createGroup(String path); HDF5RecordingData* getDataSet(String path); diff --git a/Source/Processors/RecordNode/HDF5Recording.cpp b/Source/Processors/RecordNode/HDF5Recording.cpp index 31ad28329d580eeb6cdf83c24ed47717b1052b72..d128b08b817e7a95ee431f921d3792e089d37727 100644 --- a/Source/Processors/RecordNode/HDF5Recording.cpp +++ b/Source/Processors/RecordNode/HDF5Recording.cpp @@ -54,7 +54,7 @@ void HDF5Recording::registerProcessor(GenericProcessor* proc) info->bit_depth = 16; infoArray.add(info); fileArray.add(new KWDFile()); - activeChannelCount.add(0); + bitVoltsArray.add(new Array<float>); processorIndex++; } @@ -62,7 +62,7 @@ void HDF5Recording::resetChannels() { processorIndex = -1; fileArray.clear(); - activeChannelCount.clear(); + bitVoltsArray.clear(); processorMap.clear(); infoArray.clear(); if (spikesFile) @@ -103,7 +103,7 @@ void HDF5Recording::openFiles(File rootFolder, int experimentNumber, int record fileArray[index]->initFile(getChannel(i)->nodeId,basepath); fileArray[index]->open(); } - activeChannelCount.set(index,activeChannelCount[index]+1); + bitVoltsArray[index]->add(getChannel(i)->bitVolts); } } for (int i = 0; i < fileArray.size(); i++) @@ -116,7 +116,8 @@ void HDF5Recording::openFiles(File rootFolder, int experimentNumber, int record infoArray[i]->name = String("Open-Ephys Recording #") + String(recordingNumber); infoArray[i]->start_time = timestamp; infoArray[i]->start_sample = 0; - fileArray[i]->startNewRecording(recordingNumber,activeChannelCount[i],infoArray[i]); + infoArray[i]->bitVolts.addArray(*bitVoltsArray[i]); + fileArray[i]->startNewRecording(recordingNumber,bitVoltsArray[i]->size(),infoArray[i]); } } } @@ -131,7 +132,7 @@ void HDF5Recording::closeFiles() { fileArray[i]->stopRecording(); fileArray[i]->close(); - activeChannelCount.set(i,0); + bitVoltsArray[i]->clear(); } } diff --git a/Source/Processors/RecordNode/HDF5Recording.h b/Source/Processors/RecordNode/HDF5Recording.h index 50a2657348bbac75fcdec3f8f1a21924b932fffc..9be5e3942929b93014826b0f7b6f1a474075e5d7 100644 --- a/Source/Processors/RecordNode/HDF5Recording.h +++ b/Source/Processors/RecordNode/HDF5Recording.h @@ -51,7 +51,7 @@ private: int processorIndex; Array<int> processorMap; - Array<int> activeChannelCount; + OwnedArray<Array<float>> bitVoltsArray; OwnedArray<KWDFile> fileArray; OwnedArray<HDF5RecordingInfo> infoArray; ScopedPointer<KWIKFile> mainFile; diff --git a/Source/Processors/RecordNode/OriginalRecording.cpp b/Source/Processors/RecordNode/OriginalRecording.cpp index f91596b9e191f19a8b499380c575e57ca44418b1..c03b27491e1d451d0249ea9ced5ac20e30a8c360 100644 --- a/Source/Processors/RecordNode/OriginalRecording.cpp +++ b/Source/Processors/RecordNode/OriginalRecording.cpp @@ -157,6 +157,7 @@ void OriginalRecording::openFile(File rootFolder, Channel* ch) else { std::cout << "File already exists, just opening." << std::endl; + fseek(chFile, 0, SEEK_END ); } if (isEvent) @@ -176,6 +177,7 @@ void OriginalRecording::openFile(File rootFolder, Channel* ch) c->filename = fileName; c->name = ch->name; c->startPos = ftell(chFile); + c->bitVolts = ch->bitVolts; processorArray.getLast()->channels.add(c); } diskWriteLock.exit(); @@ -678,6 +680,7 @@ void OriginalRecording::writeXml() ChannelInfo* c = processorArray[i]->channels[j]; XmlElement* chan = new XmlElement("CHANNEL"); chan->setAttribute("name",c->name); + chan->setAttribute("bitVolts",c->bitVolts); chan->setAttribute("filename",c->filename); chan->setAttribute("position",(double)(c->startPos)); //As long as the file doesnt exceed 2^53 bytes, this will have integer precission. Better than limiting to 32bits. proc->addChildElement(chan); diff --git a/Source/Processors/RecordNode/OriginalRecording.h b/Source/Processors/RecordNode/OriginalRecording.h index 433731bfef6d210c8b88361ceb08f953e4a9e31b..f269d06634ea174a9b21da166bfcfae28de19a9c 100644 --- a/Source/Processors/RecordNode/OriginalRecording.h +++ b/Source/Processors/RecordNode/OriginalRecording.h @@ -106,6 +106,7 @@ private: struct ChannelInfo { String name; String filename; + float bitVolts; long int startPos; }; struct ProcInfo {