comparison transform/CSVFeatureWriter.cpp @ 1142:870acd589a38

Add & test the digits option in the CSV file writer
author Chris Cannam
date Tue, 03 Nov 2015 14:31:58 +0000
parents 26cf6d5251ec
children d094598f84bd
comparison
equal deleted inserted replaced
1141:99acfd2d9f5d 1142:870acd589a38
35 "csv"), 35 "csv"),
36 m_separator(","), 36 m_separator(","),
37 m_sampleTiming(false), 37 m_sampleTiming(false),
38 m_endTimes(false), 38 m_endTimes(false),
39 m_forceEnd(false), 39 m_forceEnd(false),
40 m_omitFilename(false) 40 m_omitFilename(false),
41 m_digits(6)
41 { 42 {
42 } 43 }
43 44
44 CSVFeatureWriter::~CSVFeatureWriter() 45 CSVFeatureWriter::~CSVFeatureWriter()
45 { 46 {
78 pl.push_back(p); 79 pl.push_back(p);
79 80
80 p.name = "fill-ends"; 81 p.name = "fill-ends";
81 p.description = "Include durations (or end times) even for features without duration, by using the gap to the next feature instead."; 82 p.description = "Include durations (or end times) even for features without duration, by using the gap to the next feature instead.";
82 p.hasArg = false; 83 p.hasArg = false;
84 pl.push_back(p);
85
86 p.name = "digits";
87 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.";
88 p.hasArg = true;
83 pl.push_back(p); 89 pl.push_back(p);
84 90
85 return pl; 91 return pl;
86 } 92 }
87 93
106 m_endTimes = true; 112 m_endTimes = true;
107 } else if (i->first == "fill-ends") { 113 } else if (i->first == "fill-ends") {
108 m_forceEnd = true; 114 m_forceEnd = true;
109 } else if (i->first == "omit-filename") { 115 } else if (i->first == "omit-filename") {
110 m_omitFilename = true; 116 m_omitFilename = true;
117 } else if (i->first == "digits") {
118 int digits = atoi(i->second.c_str());
119 if (digits <= 0 || digits > 100) {
120 cerr << "CSVFeatureWriter: ERROR: Invalid or out-of-range value for number of significant digits: " << i->second << endl;
121 cerr << "CSVFeatureWriter: NOTE: Continuing with default settings" << endl;
122 } else {
123 m_digits = digits;
124 }
111 } 125 }
112 } 126 }
113 } 127 }
114 128
115 void 129 void
260 if (summaryType != "") { 274 if (summaryType != "") {
261 stream << m_separator << summaryType.c_str(); 275 stream << m_separator << summaryType.c_str();
262 } 276 }
263 277
264 for (unsigned int j = 0; j < f.values.size(); ++j) { 278 for (unsigned int j = 0; j < f.values.size(); ++j) {
265 stream << m_separator << f.values[j]; 279 stream << m_separator << QString("%1").arg(f.values[j], 0, 'g', m_digits);
266 } 280 }
267 281
268 if (f.label != "") { 282 if (f.label != "") {
269 stream << m_separator << "\"" << f.label.c_str() << "\""; 283 stream << m_separator << "\"" << f.label.c_str() << "\"";
270 } 284 }