103 std::ifstream * input;
106 double from_time = 0.0;
107 double to_time = -1.0;
108 double seconds_to_extract_from_end = -1.0;
110 bool debug_output =
false;
113 po::options_description desc(
"Allowed options");
115 (
"help,h",
"produce help message")
116 (
"version,v",
"show version information")
117 (
"debug,d",
"show verbose debug output")
118 (
"input,i", po::value<std::string>(),
"input file")
119 (
"output,o", po::value<std::string>(),
"output file (output to stout if not given)")
120 (
"from,f", po::value<double>(),
"'from time' in seconds")
121 (
"to,t", po::value<double>(),
"'to time' in seconds")
122 (
"last,l", po::value<double>(),
"last x seconds (overrides from/to)")
125 po::variables_map vm;
126 po::store(po::parse_command_line(ac, av, desc), vm);
129 if (vm.count(
"help")) {
130 std::cout << desc <<
"\n";
134 if (vm.count(
"version")) {
136 std::cout <<
"Auryn Binary Extract version " 143 if (vm.count(
"debug")) {
147 if (vm.count(
"input")) {
151 if (vm.count(
"output")) {
155 if (vm.count(
"from")) {
156 from_time = vm[
"from"].as<
double>();
159 if (vm.count(
"to")) {
160 to_time = vm[
"to"].as<
double>();
163 if (vm.count(
"last")) {
164 seconds_to_extract_from_end = vm[
"last"].as<
double>();
168 catch(std::exception& e) {
169 std::cerr <<
"error: " << e.what() <<
"\n";
173 std::cerr <<
"Exception of unknown type!\n";
176 double last_time = 0.0;
179 if ( input_filename.empty() ) {
180 std::cerr <<
"Missing input file." << std::endl;
184 input =
new std::ifstream( input_filename.c_str(), std::ios::binary );
186 std::cerr <<
"Unable to open input file " 192 double tmp_last_time = 0;
195 read_header( input, tmp_dt, tmp_num_events, tmp_last_time, input_filename );
197 if ( debug_output ) {
198 std::cerr <<
"# Last frame in file:" << tmp_num_events << std::endl;
204 if ( dt != tmp_dt ) {
205 std::cerr <<
"Not all input file headers match." << std::endl;
210 if ( tmp_last_time > last_time ) {
211 last_time = tmp_last_time;
219 if ( seconds_to_extract_from_end > 0 ) {
220 from_time = to_time-seconds_to_extract_from_end;
223 if ( from_time < 0 ) from_time = 0.0 ;
225 if ( from_time > to_time || from_time < 0 ) {
226 std::cerr <<
"Times must be positive and start " 227 "time needs to be < to time." << std::endl;
235 if ( debug_output ) {
236 std::cerr <<
"# Timestep: " << dt << std::endl;
237 std::cerr <<
"# Sizeof SpikeEvent struct: " <<
sizeof(
StateValue_type) << std::endl;
238 std::cerr <<
"# Time of last event in files: " << last_time << std::endl;
239 std::cerr <<
"# From time: " << from_time << std::endl;
240 std::cerr <<
"# To time: " << to_time << std::endl;
252 if ( debug_output ) {
253 std::cerr <<
"# Start frame stream: " 254 << start_frame << std::endl;
262 int decimal_places = -std::log(dt)/std::log(10)+2;
266 bool write_to_stdout =
true;
267 if( !output_file_name.empty() ) {
268 write_to_stdout =
false;
269 of.open( output_file_name.c_str(), std::ofstream::out );
270 of << std::fixed << std::setprecision(decimal_places);
273 std::cout << std::fixed << std::setprecision(decimal_places);
276 time_reference = frame.time;
277 if ( time_reference >= to_auryn_time || input->eof() )
break;
279 if ( debug_output &&
false ) {
280 std::cout <<
"# time_reference " << time_reference << std::endl;
284 while ( frame.time <= time_reference && !input->eof() ) {
285 if ( write_to_stdout )
286 std::cout << std::fixed << std::setprecision(decimal_places)
287 << frame.time*dt <<
" " 289 << frame.value <<
"\n";
291 of << std::fixed << std::setprecision(decimal_places)
292 << frame.time*dt <<
" " 294 << frame.value <<
"\n";
299 if ( !write_to_stdout )
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:201
Container class providing Auryn version number.
Definition: AurynVersion.h:37
AurynLong find_frame(std::ifstream *file, AurynTime target)
Definition: aubs.cpp:39
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
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
void read_header(std::ifstream *input, double &dt, AurynLong num_events, double &last_time, std::string filename)
Definition: aubs.cpp:63
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156