comparison data/fileio/CSVFileReader.cpp @ 491:6f8ee19984ad

* When loading data with timestamps in seconds, round each time to its nearest neighbouring frame instead of rounding down * Count from 1 when numbering points loaded from files without labels, rather than 0 (and also when printing errors with line numbers)
author Chris Cannam
date Mon, 24 Nov 2008 12:26:21 +0000
parents 183ee2a55fc7
children 3ccf48fb81d6
comparison
equal deleted inserted replaced
490:c3fb8258e34d 491:6f8ee19984ad
187 numeric.remove(nonNumericRx); 187 numeric.remove(nonNumericRx);
188 188
189 if (timeUnits == CSVFormat::TimeSeconds) { 189 if (timeUnits == CSVFormat::TimeSeconds) {
190 190
191 double time = numeric.toDouble(&ok); 191 double time = numeric.toDouble(&ok);
192 frameNo = int(time * sampleRate + 0.00001); 192 frameNo = int(time * sampleRate + 0.5);
193 193
194 } else { 194 } else {
195 195
196 frameNo = numeric.toInt(&ok); 196 frameNo = numeric.toInt(&ok);
197 197
203 if (!ok) { 203 if (!ok) {
204 if (warnings < warnLimit) { 204 if (warnings < warnLimit) {
205 std::cerr << "WARNING: CSVFileReader::load: " 205 std::cerr << "WARNING: CSVFileReader::load: "
206 << "Bad time format (\"" << s.toStdString() 206 << "Bad time format (\"" << s.toStdString()
207 << "\") in data line " 207 << "\") in data line "
208 << lineno << ":" << std::endl; 208 << lineno+1 << ":" << std::endl;
209 std::cerr << line.toStdString() << std::endl; 209 std::cerr << line.toStdString() << std::endl;
210 } else if (warnings == warnLimit) { 210 } else if (warnings == warnLimit) {
211 std::cerr << "WARNING: Too many warnings" << std::endl; 211 std::cerr << "WARNING: Too many warnings" << std::endl;
212 } 212 }
213 ++warnings; 213 ++warnings;
220 if (modelType == CSVFormat::OneDimensionalModel) { 220 if (modelType == CSVFormat::OneDimensionalModel) {
221 221
222 SparseOneDimensionalModel::Point point 222 SparseOneDimensionalModel::Point point
223 (frameNo, 223 (frameNo,
224 tidyList.size() > 0 ? tidyList[tidyList.size()-1] : 224 tidyList.size() > 0 ? tidyList[tidyList.size()-1] :
225 QString("%1").arg(lineno)); 225 QString("%1").arg(lineno+1));
226 226
227 model1->addPoint(point); 227 model1->addPoint(point);
228 228
229 } else if (modelType == CSVFormat::TwoDimensionalModel) { 229 } else if (modelType == CSVFormat::TwoDimensionalModel) {
230 230
231 SparseTimeValueModel::Point point 231 SparseTimeValueModel::Point point
232 (frameNo, 232 (frameNo,
233 tidyList.size() > 0 ? tidyList[0].toFloat() : 0.0, 233 tidyList.size() > 0 ? tidyList[0].toFloat() : 0.0,
234 tidyList.size() > 1 ? tidyList[1] : QString("%1").arg(lineno)); 234 tidyList.size() > 1 ? tidyList[1] : QString("%1").arg(lineno+1));
235 235
236 model2->addPoint(point); 236 model2->addPoint(point);
237 237
238 } else if (modelType == CSVFormat::ThreeDimensionalModel) { 238 } else if (modelType == CSVFormat::ThreeDimensionalModel) {
239 239
251 if (!ok) { 251 if (!ok) {
252 if (warnings < warnLimit) { 252 if (warnings < warnLimit) {
253 std::cerr << "WARNING: CSVFileReader::load: " 253 std::cerr << "WARNING: CSVFileReader::load: "
254 << "Non-numeric value \"" 254 << "Non-numeric value \""
255 << list[i].toStdString() 255 << list[i].toStdString()
256 << "\" in data line " << lineno 256 << "\" in data line " << lineno+1
257 << ":" << std::endl; 257 << ":" << std::endl;
258 std::cerr << line.toStdString() << std::endl; 258 std::cerr << line.toStdString() << std::endl;
259 ++warnings; 259 ++warnings;
260 } else if (warnings == warnLimit) { 260 } else if (warnings == warnLimit) {
261 // std::cerr << "WARNING: Too many warnings" << std::endl; 261 // std::cerr << "WARNING: Too many warnings" << std::endl;