00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <QtDebug>
00026 #include <QFile>
00027 #include <QTextStream>
00028 #include <QVector>
00029 #include <QPoint>
00030
00031 #include <iostream>
00032
00033 #include "filereader.h"
00034 #include "datahandler.h"
00035
00036 FileReader::FileReader(const QString &filename)
00037 {
00038 this->filename = filename;
00039 }
00040
00041 bool FileReader::readFile(const QString &filename)
00042 {
00043 this->filename = filename;
00044 QFile file(filename);
00045 file.open(QIODevice::ReadOnly);
00046
00047 QTextStream in(&file);
00048 bool dummy;
00049 QString line;
00050
00051 while (!in.atEnd())
00052 {
00053 line = in.readLine();
00054 double value = line.toDouble(&dummy);
00055 fileValues.push_back(value);
00056 }
00057 return true;
00058 }
00059
00060 int FileReader::fillData(QVector<QVector<double> > &pDest,
00061 int screennumber,
00062 int channel)
00063 {
00064
00065 int rawLength = fileValues.size();
00066
00067
00068 int samplesprSecond = 500;
00069
00070 int samplesprLine = DataHandler::secondsprLine * samplesprSecond;
00071
00072 int samplesprScreen = DataHandler::numberofLines * samplesprLine;
00073
00074 int numberOfFullScreens = (rawLength / samplesprScreen);
00075
00076 int numberOfFullLines = (rawLength / samplesprLine);
00077
00078 int samplesOnLastLine = rawLength % samplesprLine;
00079
00080 int linesOnLastScreen = numberOfFullLines % DataHandler::numberofLines;
00081
00082 int numberOfScreens = 0;
00083 int screenOffset = 0;
00084
00085 screennumber = qBound(0, screennumber, numberOfFullScreens);
00086
00087 if (numberOfFullScreens != 0)
00088 {
00089 numberOfScreens = numberOfFullScreens;
00090 screenOffset = screennumber * samplesprScreen;
00091 }
00092
00093 numberOfScreens++;
00094
00095 int linesToFill = 0;
00096 bool notFullScreens = false;
00097 if (numberOfScreens - 1 == screennumber)
00098 {
00099 linesToFill = linesOnLastScreen;
00100 notFullScreens = true;
00101 }
00102 else
00103 {
00104 linesToFill = DataHandler::numberofLines;
00105 }
00106
00107 int i, j;
00108 for (i = 0; i < linesToFill; i++)
00109 {
00110 for (j = 0; j < samplesprLine; j++)
00111 {
00112 pDest[i][j] = fileValues[((i * samplesprLine) + screenOffset) + j];
00113 }
00114 }
00115 if (notFullScreens)
00116 {
00117 for (j = 0; j < samplesOnLastLine; j++)
00118 {
00119 pDest[i][j] = fileValues[((i * samplesprLine) + screenOffset) + j];
00120 }
00121 for (; j < samplesprLine; j++)
00122 {
00123 pDest[i][j] = 0.0;
00124 }
00125 i++;
00126 for (; i < DataHandler::numberofLines; i++)
00127 {
00128 for (j = 0; j < samplesprLine; j++)
00129 {
00130 pDest[i][j] = 0.0;
00131 }
00132 }
00133 }
00134
00135 return numberOfScreens;
00136 }