-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbraintofile.cc
88 lines (67 loc) · 2.22 KB
/
braintofile.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* braintofile.cc
*
* Copyright (C) 2016 Örjan Ekeberg <[email protected]>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <music.hh>
#include "OurUDPProtocol.hh"
MPI::Intracomm comm;
struct OurUDPProtocol::fromMusicPackage package;
int
main (int argc, char* argv[])
{
MUSIC::Setup* setup = new MUSIC::Setup (argc, argv);
if (argc != 2) {
std::cerr << "Usage: braintofile <filname>" << std::endl;
exit(1);
}
std::ofstream keyfile;
keyfile.open(argv[1]);
if (!keyfile.is_open()) {
std::cerr << "Can not open file " << argv[1] << " for writing." << std::endl;
exit(1);
}
MUSIC::ContInputPort* theport =
setup->publishContInput ("in");
comm = setup->communicator ();
if (comm.Get_size() != 1) {
std::cerr << "braintofile must run on a single processor" << std::endl;
exit(1);
}
// Declare what data we have to export
MUSIC::ArrayData dmap (&package.keysPressed,
MPI_DOUBLE,
0,
OurUDPProtocol::KEYBOARDSIZE);
theport->map (&dmap);
double stoptime;
if (!setup->config ("stoptime", &stoptime))
throw std::runtime_error("braintofile: stoptime must be set from the music configuration file");
MUSIC::Runtime* runtime = new MUSIC::Runtime (setup, OurUDPProtocol::TIMESTEP);
for (; runtime->time () < stoptime; runtime->tick ()) {
std::for_each(package.keysPressed.begin(), package.keysPressed.end()-1,
[&keyfile] (double key) { keyfile << key << " "; });
keyfile << *package.keysPressed.end()-1 << std::endl;
}
runtime->finalize ();
delete runtime;
keyfile.close();
return 0;
}