-
Notifications
You must be signed in to change notification settings - Fork 4
/
service_stuff.h
82 lines (59 loc) · 1.65 KB
/
service_stuff.h
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
/*
service_stuff.h: service functions for dump and conversions.
See file COPYING for copyright and licensing information.
*/
#ifndef __SERVICE_STUFF__
#define __SERVICE_STUFF__
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
template <typename T>
std::string NumberToString ( T Number )
{
std::stringstream ss;
ss << Number;
return ss.str();
}
std::vector<std::string> files_vector;
// std::vector<std::ofstream*> files_descriptor_vector;
void create_dump_files(unsigned int quanti, std::string pa, unsigned int gpu) {
for (unsigned int i=0; i<quanti; i++) {
std::string p(pa);
p.append( "_" );
p.append( NumberToString(i) );
p.append( "_GPU" );
p.append( NumberToString(gpu) );
files_vector.push_back(p);
// std::cout << files_vector.back() << std::endl;
std::ofstream* myfile = new std::ofstream(p.c_str());
if (! myfile->is_open() ) {
perror("ERROR: cannot open output file. Directory does not exist? ");
exit(-1);
}
myfile->close();
}
}
void write_dump_files( std::vector< std::vector<double>* > v ) {
// v è un vettore dei vettori timestamp + stato corrente
for (unsigned int i=0; i<v.size(); i++) {
std::ofstream* myfile = new std::ofstream();
myfile->open( files_vector[i].c_str() , std::fstream::app);
for (unsigned int j=0; j<v[i]->size(); j++) {
*myfile << v[i]->at(j) << "\t";
// printf("%d, %d, %d\n", i,j, );
}
*myfile << "\n";
myfile->close();
}
}
void close_dump_files(void) {
/*
for (unsigned int i=0; i<files_descriptor_vector.size(); i++) {
*files_descriptor_vector[i] << "\n";
files_descriptor_vector[i]->close();
}
*/
}
#endif