comparison runner/LabFeatureWriter.cpp @ 206:704a8b27f3ed

Add & test the digits option in the Lab file writer
author Chris Cannam
date Tue, 03 Nov 2015 13:42:11 +0000
parents 089f1a13963d
children ef03350baec7
comparison
equal deleted inserted replaced
205:7a287e5d5df6 206:704a8b27f3ed
30 30
31 LabFeatureWriter::LabFeatureWriter() : 31 LabFeatureWriter::LabFeatureWriter() :
32 FileFeatureWriter(SupportOneFilePerTrackTransform | 32 FileFeatureWriter(SupportOneFilePerTrackTransform |
33 SupportStdOut, 33 SupportStdOut,
34 "lab"), 34 "lab"),
35 m_forceEnd(false) 35 m_forceEnd(false),
36 m_digits(6)
36 { 37 {
37 } 38 }
38 39
39 LabFeatureWriter::~LabFeatureWriter() 40 LabFeatureWriter::~LabFeatureWriter()
40 { 41 {
56 p.name = "fill-ends"; 57 p.name = "fill-ends";
57 p.description = "Include end times even for features without duration, by using the gap to the next feature instead."; 58 p.description = "Include end times even for features without duration, by using the gap to the next feature instead.";
58 p.hasArg = false; 59 p.hasArg = false;
59 pl.push_back(p); 60 pl.push_back(p);
60 61
62 p.name = "digits";
63 p.description = "Specify the number of significant digits to use when printing transform outputs. Outputs are represented internally using single-precision floating-point, so digits beyond the 8th or 9th place are usually meaningless. The default is 6.";
64 p.hasArg = true;
65 pl.push_back(p);
66
61 return pl; 67 return pl;
62 } 68 }
63 69
64 void 70 void
65 LabFeatureWriter::setParameters(map<string, string> &params) 71 LabFeatureWriter::setParameters(map<string, string> &params)
68 74
69 for (map<string, string>::iterator i = params.begin(); 75 for (map<string, string>::iterator i = params.begin();
70 i != params.end(); ++i) { 76 i != params.end(); ++i) {
71 if (i->first == "fill-ends") { 77 if (i->first == "fill-ends") {
72 m_forceEnd = true; 78 m_forceEnd = true;
79 } else if (i->first == "digits") {
80 int digits = atoi(i->second.c_str());
81 if (digits <= 0 || digits > 100) {
82 cerr << "LabFeatureWriter: ERROR: Invalid or out-of-range value for number of significant digits: " << i->second << endl;
83 cerr << "LabFeatureWriter: NOTE: Continuing with default settings" << endl;
84 } else {
85 m_digits = digits;
86 }
73 } 87 }
74 } 88 }
75 } 89 }
76 90
77 void 91 void
167 e.replace(QRegExp("^ +"), ""); 181 e.replace(QRegExp("^ +"), "");
168 stream << sep << e; 182 stream << sep << e;
169 } 183 }
170 184
171 for (unsigned int j = 0; j < f.values.size(); ++j) { 185 for (unsigned int j = 0; j < f.values.size(); ++j) {
172 stream << sep << f.values[j]; 186 stream << sep << QString("%1").arg(f.values[j], 0, 'g', m_digits);
173 } 187 }
174 188
175 if (f.label != "") { 189 if (f.label != "") {
176 stream << sep << "\"" << f.label.c_str() << "\""; 190 stream << sep << "\"" << f.label.c_str() << "\"";
177 } 191 }