Initial Commit
[HECS.git] / DoubleReader.cpp
blobb9466f27463eda8a36979fc964af2b9b2284f973
1 /***************************************************************************
2 * *
3 * DoubleReader.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 "DoubleReader.h"
28 const char COMMENT = '#';
30 DoubleReader::DoubleReader () {}
32 DoubleReader::DoubleReader (const QString& fileName)
34 m_fileName = new QFile (fileName);
35 //m_numElems = numElems;
36 TableReader::openFile();
37 parseFileD();
38 closeFile();
41 DoubleReader::~DoubleReader () {}
43 void DoubleReader::readFile(const QString& fileNameIn)
45 delete m_fileName;
46 m_fileName = new QFile (fileNameIn);
47 openFile();
48 parseFile();
49 closeFile();
52 void DoubleReader::parseFileD()
55 QTextStream in (m_fileName);
56 while (!in.atEnd()) {
58 QString line = in.readLine().trimmed();
60 if (line.startsWith(COMMENT))
61 continue; //Skip for comments !!
63 parseLineD(line,ValueMap);
67 void DoubleReader::parseLineD(QString lineIn, QMap<double, QList <double> >& ValueMap)
70 double key = 0.00;
71 QList <double> valueList;
73 vals = lineIn.split(",");
74 key = vals.at(0).toDouble();
75 for (int i = 1; i < vals.size(); ++i)
76 valueList.append(vals.at(1).toDouble());
77 ValueMap.insert(key,valueList);
80 QMap <double,QList <double> > DoubleReader::getDoubleMap()
82 return ValueMap;
85 // END OF DoubleReader.cpp