-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxye.cpp
52 lines (45 loc) · 1.2 KB
/
xye.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "xye.h"
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QMessageBox>
int readXYE(const QString &fn, QChar sep, QVector<double> &x,
QVector<double> &y, int skip)
{
int n = 0; // number of points read
QFile xyfile(fn);
if (!xyfile.open(QFile::ReadOnly|QFile::Text))
{
return n;
}
QTextStream inp(&xyfile);
QString line;
if (skip > 0)
{
for (int i=0; i < skip; ++i)
{
line = inp.readLine();
}
}
while (inp.readLineInto(&line))
{
bool a, b;
line = line.simplified(); // simplify whitespace for parsing
QStringList fields = line.split(sep);
if (fields.size()>1)
{
x.append(fields.at(0).simplified().toDouble(&a));
y.append(fields.at(1).simplified().toDouble(&b));
if (!(a && b)) return(n); // unsuccessful conversion
++n;
} else
{
// accept single value at start to allow optional lambda in xye,
// finish reading otherwise (no longer x y format)
if (n > 0) return(n);
}
}
return(n);
}