Initial Commit
[HECS.git] / TableReader.cpp
blob9512f06e88b161773ca24796ede1e6d54679ddd8
1 /***************************************************************************
2 * *
3 * TableReader.cpp Copyright (C) 2008 by Jon Rumble *
4 * j.w.rumble@reading.ac.uk *
5 * *
6 * *
7 * This file is part of HECS, *
8 * *
9 * HECS is free software: you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation, either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * *
15 * HECS is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
22 ***************************************************************************/
25 #include "TableReader.h"
28 const char COMMENT = '#';
30 TableReader::TableReader () {}
32 TableReader::TableReader (QString fileName)
34 m_fileName = new QFile (fileName);
35 //m_numElems = numElems;
36 openFile();
37 parseFile();
38 closeFile();
42 TableReader::~TableReader () {}
44 void TableReader::readFile(QString fileNameIn)
46 m_fileName = new QFile (fileNameIn);
47 openFile();
48 parseFile();
49 closeFile();
52 void TableReader::openFile ()
54 if (!m_fileName->open(QIODevice::ReadOnly | QIODevice::Text))
55 return;
58 void TableReader::closeFile ()
60 m_fileName->close();
63 void TableReader::parseFile ()
66 QTextStream in (m_fileName);
67 int lineNum =1;
68 while (!in.atEnd()) {
70 QString line = in.readLine().trimmed();
72 if (line.startsWith(COMMENT))
73 continue; //Skip for comments !!
74 dValueMap.insert(lineNum,parseLine(line));
75 lineNum++;
79 QList <double> TableReader::parseLine (QString lineIn)
82 QList <double> valueList;
83 vals = lineIn.split(",");
84 for (int i = 0; i < vals.size(); ++i)
85 valueList.append(vals.at(i).toDouble());
87 return valueList;
90 QMap <int, QList <double> > TableReader::getTableMap()
92 return dValueMap;
95 void TableReader::initVars()
99 // END OF TableReader.cpp