98 std::vector<std::string> input_filenames;
99 std::vector<std::ifstream*> inputs;
102 double from_time = 0.0;
103 double to_time = -1.0;
104 double seconds_to_extract_from_end = -1.0;
105 NeuronID maxid = std::numeric_limits<NeuronID>::max();
107 bool debug_output =
false;
110 po::options_description desc(
"Allowed options");
112 (
"help,h",
"produce help message")
113 (
"version,v",
"show version information")
114 (
"debug,d",
"show verbose debug output")
115 (
"inputs,i", po::value< std::vector<std::string> >()->multitoken(),
"input files")
116 (
"output,o", po::value<std::string>(),
"output file (output to stout if not given)")
117 (
"from,f", po::value<double>(),
"'from time' in seconds")
118 (
"to,t", po::value<double>(),
"'to time' in seconds")
119 (
"last,l", po::value<double>(),
"last x seconds (overrides from/to)")
120 (
"maxid,m", po::value<NeuronID>(),
"maximum neuron id to extract")
123 po::variables_map vm;
124 po::store(po::parse_command_line(ac, av, desc), vm);
127 if (vm.count(
"help")) {
128 std::cout << desc <<
"\n";
132 if (vm.count(
"version")) {
134 std::cout <<
"Auryn Binary Extract version " 141 if (vm.count(
"debug")) {
145 if (vm.count(
"inputs")) {
146 input_filenames = vm[
"inputs"].as< std::vector<std::string> >();
149 if (vm.count(
"output")) {
153 if (vm.count(
"from")) {
154 from_time = vm[
"from"].as<
double>();
157 if (vm.count(
"to")) {
158 to_time = vm[
"to"].as<
double>();
161 if (vm.count(
"last")) {
162 seconds_to_extract_from_end = vm[
"last"].as<
double>();
165 if (vm.count(
"maxid")) {
169 catch(std::exception& e) {
170 std::cerr <<
"error: " << e.what() <<
"\n";
174 std::cerr <<
"Exception of unknown type!\n";
178 std::cout <<
"# Number of input files " << input_filenames.size() << std::endl;
180 double last_time = 0.0;
183 if ( input_filenames.size() == 0 ) {
184 std::cerr <<
"Missing input file." << std::endl;
188 for (
unsigned int i = 0 ; i < input_filenames.size() ; ++i ) {
189 std::ifstream * tmp =
new std::ifstream( input_filenames[i].c_str(), std::ios::binary );
190 inputs.push_back(tmp);
192 std::cerr <<
"Unable to open input file " 193 << input_filenames[i]
198 double tmp_last_time = 0;
201 read_header( tmp, tmp_dt, tmp_num_events, tmp_last_time, input_filenames[i] );
203 if ( debug_output ) {
204 std::cerr <<
"# Last frame in file " << i <<
": " << tmp_num_events << std::endl;
210 if ( dt != tmp_dt ) {
211 std::cerr <<
"Not all input file headers match." << std::endl;
216 if ( tmp_last_time > last_time )
217 last_time = tmp_last_time;
225 if ( seconds_to_extract_from_end > 0 ) {
226 from_time = to_time-seconds_to_extract_from_end;
229 if ( from_time < 0 ) from_time = 0.0 ;
231 if ( from_time > to_time || from_time < 0 ) {
232 std::cerr <<
"Times must be positive and start " 233 "time needs to be < to time." << std::endl;
241 if ( debug_output ) {
242 std::cerr <<
"# Timestep: " << dt << std::endl;
243 std::cerr <<
"# Maxid: " << maxid << std::endl;
244 std::cerr <<
"# Sizeof SpikeEvent struct: " <<
sizeof(
SpikeEvent_type) << std::endl;
245 std::cerr <<
"# Time of last event in files: " << last_time << std::endl;
246 std::cerr <<
"# From time: " << from_time << std::endl;
247 std::cerr <<
"# To time: " << to_time << std::endl;
252 for (
unsigned int i = 0 ; i < inputs.size() ; ++i ) {
257 inputs[i]->seekg (start_frame*
sizeof(
SpikeEvent_type), inputs[i]->beg);
259 if ( debug_output ) {
260 std::cerr <<
"# Start frame stream " 262 << start_frame << std::endl;
268 std::vector<SpikeEvent_type> frames(inputs.size());
269 for (
unsigned int i = 0 ; i < frames.size() ; ++i ) {
274 int decimal_places = -std::log(dt)/std::log(10)+2;
278 bool write_to_stdout =
true;
279 if( !output_file_name.empty() ) {
280 write_to_stdout =
false;
281 of.open( output_file_name.c_str(), std::ofstream::out );
282 of << std::fixed << std::setprecision(decimal_places);
285 std::cout << std::fixed << std::setprecision(decimal_places);
289 int current_stream = 0;
290 AurynLong mintime = std::numeric_limits<AurynLong>::max();
292 for (
unsigned int i = 0 ; i < frames.size() ; ++i ) {
293 eofs = eofs && inputs[i]->eof();
294 if ( inputs[i]->eof() )
continue;
295 if ( frames[i].time < mintime ) {
296 mintime = frames[i].time;
301 time_reference = mintime;
302 if ( time_reference >= to_auryn_time || eofs )
break;
304 if ( debug_output &&
false ) {
305 std::cout <<
"# current_stream " << current_stream << std::endl;
306 std::cout <<
"# time_reference " << time_reference << std::endl;
310 while ( frames[current_stream].time <= time_reference && !inputs[current_stream]->eof() ) {
311 if ( frames[current_stream].neuronID < maxid) {
312 if ( write_to_stdout )
313 std::cout << frames[current_stream].time*dt <<
" " << frames[current_stream].neuronID <<
"\n";
315 of << frames[current_stream].time*dt <<
" " << frames[current_stream].neuronID <<
"\n";
318 inputs[current_stream]->read((
char*)&frames[current_stream],
sizeof(
SpikeEvent_type));
322 if ( !write_to_stdout )
326 for (
unsigned int i = 0 ; i < frames.size() ; ++i ) {
void read_header(std::ifstream *input, double &dt, AurynLong num_events, double &last_time, std::string filename)
Definition: aube.cpp:59
Container class providing Auryn version number.
Definition: AurynVersion.h:37
static int revision_number
Definition: AurynVersion.h:41
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
AurynLong find_frame(std::ifstream *file, AurynTime target)
Definition: aube.cpp:35
static int subversion
Definition: AurynVersion.h:40
static int version
Definition: AurynVersion.h:39
NeuronID AurynTime
Defines Auryns discrete time unit of the System clock. Change to AurynLong if 120h of simtime are not...
Definition: auryn_definitions.h:155
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:194