# HG changeset patch # User Chris Cannam # Date 1446561118 0 # Node ID 870acd589a38f7cc100f32728002448291fbe393 # Parent 99acfd2d9f5dea40e94b6a4f2a1050acffde9222 Add & test the digits option in the CSV file writer diff -r 99acfd2d9f5d -r 870acd589a38 transform/CSVFeatureWriter.cpp --- a/transform/CSVFeatureWriter.cpp Tue Nov 03 12:41:15 2015 +0000 +++ b/transform/CSVFeatureWriter.cpp Tue Nov 03 14:31:58 2015 +0000 @@ -37,7 +37,8 @@ m_sampleTiming(false), m_endTimes(false), m_forceEnd(false), - m_omitFilename(false) + m_omitFilename(false), + m_digits(6) { } @@ -82,6 +83,11 @@ p.hasArg = false; pl.push_back(p); + p.name = "digits"; + 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."; + p.hasArg = true; + pl.push_back(p); + return pl; } @@ -108,6 +114,14 @@ m_forceEnd = true; } else if (i->first == "omit-filename") { m_omitFilename = true; + } else if (i->first == "digits") { + int digits = atoi(i->second.c_str()); + if (digits <= 0 || digits > 100) { + cerr << "CSVFeatureWriter: ERROR: Invalid or out-of-range value for number of significant digits: " << i->second << endl; + cerr << "CSVFeatureWriter: NOTE: Continuing with default settings" << endl; + } else { + m_digits = digits; + } } } } @@ -262,7 +276,7 @@ } for (unsigned int j = 0; j < f.values.size(); ++j) { - stream << m_separator << f.values[j]; + stream << m_separator << QString("%1").arg(f.values[j], 0, 'g', m_digits); } if (f.label != "") { diff -r 99acfd2d9f5d -r 870acd589a38 transform/CSVFeatureWriter.h --- a/transform/CSVFeatureWriter.h Tue Nov 03 12:41:15 2015 +0000 +++ b/transform/CSVFeatureWriter.h Tue Nov 03 14:31:58 2015 +0000 @@ -74,6 +74,8 @@ const Vamp::Plugin::Feature &f, const Vamp::Plugin::Feature *optionalNextFeature, std::string summaryType); + + int m_digits; }; #endif