|
36 | 36 | MSG(stderr, "ERROR", "File: %s, line: %d\n", __FILE__, __LINE__); \
|
37 | 37 | exit((error_code));
|
38 | 38 |
|
| 39 | +#define MSG_WARNING(error_code, fmt, ...) \ |
| 40 | + MSG(stderr, "WARNING", (fmt), ##__VA_ARGS__); \ |
| 41 | + MSG(stderr, "WARNING", "File: %s, line: %d\n", __FILE__, __LINE__); |
| 42 | + |
39 | 43 | #ifdef DEBUG
|
40 | 44 | #define MSG_DEBUG(fmt, ...) MSG(stdout, "DEBUG", (fmt), ##__VA_ARGS__);
|
41 | 45 | #else
|
@@ -83,8 +87,8 @@ double ComputeSampen(double A, double B, unsigned N, unsigned m);
|
83 | 87 | /**
|
84 | 88 | * @brief Read data from file.
|
85 | 89 | *
|
86 |
| - * @param filename: The name of the file to read. |
87 |
| - * @return Read data. |
| 90 | + * @param[out] result where to store the read result |
| 91 | + * @param filename the name of the file to read |
88 | 92 | */
|
89 | 93 | template <typename T>
|
90 | 94 | void ReadData(std::vector<T> &result, std::string filename,
|
@@ -317,34 +321,42 @@ void ReadData(std::vector<T> &result, std::string filename,
|
317 | 321 | exit(-1);
|
318 | 322 | }
|
319 | 323 | unsigned org_n = n;
|
320 |
| - if (n == 0) |
321 |
| - n = std::numeric_limits<unsigned>::max(); |
| 324 | + if (n == 0) { |
| 325 | + n = 1024 * 1024; |
| 326 | + } else { |
| 327 | + result.reserve(n); |
| 328 | + result.resize(n); |
| 329 | + } |
322 | 330 | unsigned count = 0;
|
| 331 | + unsigned result_i = 0; |
323 | 332 | T x = 0;
|
324 | 333 | if (input_type == "simple") {
|
325 | 334 | while (count < n + line_offset && ifs >> x) {
|
326 |
| - if (count >= line_offset) |
327 |
| - result.push_back(x); |
| 335 | + if (count >= line_offset) { |
| 336 | + result[result_i] = x; |
| 337 | + ++result_i; |
| 338 | + } |
328 | 339 | ++count;
|
329 | 340 | }
|
330 | 341 | } else if (input_type == "multirecord") {
|
331 | 342 | std::string line;
|
332 | 343 | while (count < n + line_offset && std::getline(ifs, line)) {
|
333 | 344 | std::istringstream iss(line);
|
334 | 345 | if (!(iss >> x >> x)) {
|
335 |
| - std::cerr << "Input file foramt error. \n"; |
336 |
| - exit(-1); |
| 346 | + MSG_ERROR(-1, "Input file foramt error.\n"); |
| 347 | + } |
| 348 | + if (count >= line_offset) { |
| 349 | + result[result_i] = x; |
| 350 | + ++result_i; |
337 | 351 | }
|
338 |
| - if (count >= line_offset) |
339 |
| - result.push_back(x); |
340 | 352 | ++count;
|
341 | 353 | }
|
342 | 354 | } else {
|
343 | 355 | MSG_ERROR(-1, "Invalid input-type: %s\n", input_type.c_str());
|
344 | 356 | }
|
345 | 357 | if (org_n && org_n != result.size()) {
|
346 |
| - MSG_ERROR(-1, "Cannot read %u element from file %s. Only %zu read.\n", |
347 |
| - org_n, filename.c_str(), result.size()); |
| 358 | + MSG_WARNING(-1, "Cannot read %u element from file %s. Only %zu read.\n", |
| 359 | + org_n, filename.c_str(), result.size()); |
348 | 360 | }
|
349 | 361 | ifs.close();
|
350 | 362 | }
|
|
0 commit comments