29 #include <libeep/cnt/cnt.h>
36 #include "WReaderLibeep.h"
37 #include "core/common/WLogger.h"
38 #include "core/dataHandler/WEEG.h"
39 #include "core/dataHandler/exceptions/WDHNoSuchFile.h"
41 WReaderLibeep::WReaderLibeep( std::string fileName )
46 std::shared_ptr< WDataSet > WReaderLibeep::load()
48 wlog::debug(
"Libeep Reader" ) <<
"Opening " << m_fname;
51 setlocale( LC_NUMERIC,
"C" );
54 FILE* file = fopen( m_fname.c_str(),
"rb" );
60 eeg_t* eeg = eep_init_from_file( m_fname.c_str(), file, &status );
61 if( status != CNTERR_NONE || !eeg )
63 std::ostringstream stream;
64 stream << m_fname <<
" could not be initialized. Libeep status code: " << status;
69 unsigned int numberOfChannels = eep_get_chanc( eeg );
70 slen_t numberOfSamples = eep_get_samplec( eeg );
72 if( numberOfSamples > 8192 )
77 numberOfSamples = 8192;
80 sraw_t* buffer =
new sraw_t[CNTBUF_ARRAYSIZE( eeg, numberOfSamples )];
81 eep_read_sraw( eeg, DATATYPE_EEG, buffer, numberOfSamples );
83 WEEGChannelLabels channelLabels( numberOfChannels );
84 WEEGSegment segment( numberOfChannels );
85 for(
unsigned int channel = 0; channel < numberOfChannels; ++channel )
87 channelLabels[channel].first = eep_get_chan_label( eeg, channel );
89 double scale = eep_get_chan_scale( eeg, channel );
90 WEEGElectrode electrode( numberOfSamples );
91 for( slen_t sample = 0; sample < numberOfSamples; ++sample )
93 electrode[sample] = buffer[sample * numberOfChannels + channel] * scale;
95 segment[channel] = electrode;
102 WEEGElectrodeLibrary electrodeLibrary = extractElectrodePositions();
104 if( electrodeLibrary.size() != numberOfChannels )
106 std::ostringstream stream;
107 stream <<
"Contents of cnt and elc files are not compatible: The cnt has " << numberOfChannels
108 <<
" channels, but the elc has " << electrodeLibrary.size() <<
" channels.";
113 std::shared_ptr< WEEG > out(
new WEEG(
114 WEEGSegmentArray( 1, segment ),
118 out->setFilename( m_fname );
General purpose exception and therefore base class for all DataHandler related exceptions.
Use this for IO error handling.
File not found exception.
Contains EEG recording data.
Abstract base class for all Readers who handle with EEG data.
WStreamedLogger debug(const std::string &source)
Logging a debug message.