Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 390:21e79997e80f
* Fix failure to handle scientific notation for time field; tidy up some
warnings and handling of empty fields
author | Chris Cannam |
---|---|
date | Thu, 13 Mar 2008 12:41:20 +0000 |
parents | 14e0f60435b8 |
children | 183ee2a55fc7 |
comparison
equal
deleted
inserted
replaced
389:a1b6d2e33cab | 390:21e79997e80f |
---|---|
97 | 97 |
98 CSVFormatDialog::ModelType modelType = dialog->getModelType(); | 98 CSVFormatDialog::ModelType modelType = dialog->getModelType(); |
99 CSVFormatDialog::TimingType timingType = dialog->getTimingType(); | 99 CSVFormatDialog::TimingType timingType = dialog->getTimingType(); |
100 CSVFormatDialog::TimeUnits timeUnits = dialog->getTimeUnits(); | 100 CSVFormatDialog::TimeUnits timeUnits = dialog->getTimeUnits(); |
101 QString separator = dialog->getSeparator(); | 101 QString separator = dialog->getSeparator(); |
102 QString::SplitBehavior behaviour = dialog->getSplitBehaviour(); | |
102 size_t sampleRate = dialog->getSampleRate(); | 103 size_t sampleRate = dialog->getSampleRate(); |
103 size_t windowSize = dialog->getWindowSize(); | 104 size_t windowSize = dialog->getWindowSize(); |
104 | 105 |
105 delete dialog; | 106 delete dialog; |
106 | 107 |
146 | 147 |
147 QString line = lines[li]; | 148 QString line = lines[li]; |
148 | 149 |
149 if (line.startsWith("#")) continue; | 150 if (line.startsWith("#")) continue; |
150 | 151 |
151 QStringList list = line.split(separator, QString::KeepEmptyParts); | 152 QStringList list = line.split(separator, behaviour); |
152 | 153 |
153 if (!model) { | 154 if (!model) { |
154 | 155 |
155 switch (modelType) { | 156 switch (modelType) { |
156 | 157 |
172 break; | 173 break; |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
176 QStringList tidyList; | 177 QStringList tidyList; |
177 QRegExp nonNumericRx("[^0-9.,+-]"); | 178 QRegExp nonNumericRx("[^0-9eE.,+-]"); |
178 | 179 |
179 for (int i = 0; i < list.size(); ++i) { | 180 for (int i = 0; i < list.size(); ++i) { |
180 | 181 |
181 QString s(list[i].trimmed()); | 182 QString s(list[i].trimmed()); |
182 | 183 |
255 if ((lineno == 0 && i == 0) || value > max) max = value; | 256 if ((lineno == 0 && i == 0) || value > max) max = value; |
256 | 257 |
257 if (!ok) { | 258 if (!ok) { |
258 if (warnings < warnLimit) { | 259 if (warnings < warnLimit) { |
259 std::cerr << "WARNING: CSVFileReader::load: " | 260 std::cerr << "WARNING: CSVFileReader::load: " |
260 << "Non-numeric value in data line " << lineno | 261 << "Non-numeric value \"" |
262 << list[i].toStdString() | |
263 << "\" in data line " << lineno | |
261 << ":" << std::endl; | 264 << ":" << std::endl; |
262 std::cerr << line.toStdString() << std::endl; | 265 std::cerr << line.toStdString() << std::endl; |
263 ++warnings; | 266 ++warnings; |
264 } else if (warnings == warnLimit) { | 267 } else if (warnings == warnLimit) { |
265 std::cerr << "WARNING: Too many warnings" << std::endl; | 268 // std::cerr << "WARNING: Too many warnings" << std::endl; |
266 } | 269 } |
267 } | 270 } |
268 } | 271 } |
269 | 272 |
270 std::cerr << "Setting bin values for count " << lineno << ", frame " | 273 // std::cerr << "Setting bin values for count " << lineno << ", frame " |
271 << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl; | 274 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl; |
272 | 275 |
273 model3->setColumn(frameNo / model3->getResolution(), values); | 276 model3->setColumn(frameNo / model3->getResolution(), values); |
274 } | 277 } |
275 | 278 |
276 ++lineno; | 279 ++lineno; |
294 size_t defaultSampleRate) : | 297 size_t defaultSampleRate) : |
295 QDialog(parent), | 298 QDialog(parent), |
296 m_modelType(OneDimensionalModel), | 299 m_modelType(OneDimensionalModel), |
297 m_timingType(ExplicitTiming), | 300 m_timingType(ExplicitTiming), |
298 m_timeUnits(TimeAudioFrames), | 301 m_timeUnits(TimeAudioFrames), |
299 m_separator("") | 302 m_separator(""), |
303 m_behaviour(QString::KeepEmptyParts) | |
300 { | 304 { |
301 setModal(true); | 305 setModal(true); |
302 setWindowTitle(tr("Select Data Format")); | 306 setWindowTitle(tr("Select Data Format")); |
303 | 307 |
304 (void)guessFormat(file); | 308 (void)guessFormat(file); |
541 | 545 |
542 QString line = lines[li]; | 546 QString line = lines[li]; |
543 | 547 |
544 if (line.startsWith("#")) continue; | 548 if (line.startsWith("#")) continue; |
545 | 549 |
550 m_behaviour = QString::KeepEmptyParts; | |
551 | |
546 if (m_separator == "") { | 552 if (m_separator == "") { |
547 //!!! to do: ask the user | 553 //!!! to do: ask the user |
548 if (line.split(",").size() >= 2) m_separator = ","; | 554 if (line.split(",").size() >= 2) m_separator = ","; |
549 else if (line.split("\t").size() >= 2) m_separator = "\t"; | 555 else if (line.split("\t").size() >= 2) m_separator = "\t"; |
550 else if (line.split("|").size() >= 2) m_separator = "|"; | 556 else if (line.split("|").size() >= 2) m_separator = "|"; |
551 else if (line.split("/").size() >= 2) m_separator = "/"; | 557 else if (line.split("/").size() >= 2) m_separator = "/"; |
552 else if (line.split(":").size() >= 2) m_separator = ":"; | 558 else if (line.split(":").size() >= 2) m_separator = ":"; |
553 else m_separator = " "; | 559 else { |
560 m_separator = " "; | |
561 m_behaviour = QString::SkipEmptyParts; | |
562 } | |
554 } | 563 } |
555 | 564 |
556 QStringList list = line.split(m_separator); | 565 QStringList list = line.split(m_separator, m_behaviour); |
557 QStringList tidyList; | 566 QStringList tidyList; |
558 | 567 |
559 for (int i = 0; i < list.size(); ++i) { | 568 for (int i = 0; i < list.size(); ++i) { |
560 | 569 |
561 QString s(list[i]); | 570 QString s(list[i]); |