csvReader.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #include <GeneralDefine.h>
6 #include <algorithm>
7 #include <iostream>
8 #include <vector>
9 #include <fstream>
10 #include <sstream>
11 #include <string>
12 #include <locale>
13 #include <Logger.h>
14 
15 #ifndef CSVREADER_H
16 #define CSVREADER_H
17 
24 class csvReader
25 {
26 
27 public:
32 
36  void read(const std::string& filename);
37 
41  std::vector<std::string> getHeaderVector();
42 
46  void setHeader(bool headings);
47 
51  std::vector<std::vector<std::string>> getNumArray();
52 
56  std::vector<Mdouble> getFirstColumn(Mdouble scalingFactor);
57 
61  std::vector<Mdouble> getSecondColumn(Mdouble scalingFactor);
62 
63 private:
64 
68  std::vector<std::vector<std::string>> numArray_;
69 
74  std::vector<std::string> headerVector_;
75 
79  std::vector<Mdouble> CSVFirstColumn_;
80 
84  std::vector<Mdouble> CSVSecondColumn_;
85 
89  bool hasHeader_ = false;
90 };
91 
92 #endif //CSVREADER_H
Enables reading of .csv files into MercuryDPM.
Definition: csvReader.h:25
std::vector< Mdouble > CSVSecondColumn_
Definition: csvReader.h:84
std::vector< std::string > getHeaderVector()
Get the Header string vector of a .csv file.
Definition: csvReader.cc:80
std::vector< Mdouble > getSecondColumn(Mdouble scalingFactor)
Get second column of a .csv file and return it as a double.
Definition: csvReader.cc:124
csvReader()
Constructor.
std::vector< std::vector< std::string > > getNumArray()
Get the 2D array with the .csv file values.
Definition: csvReader.cc:97
std::vector< std::string > headerVector_
Definition: csvReader.h:74
bool hasHeader_
Definition: csvReader.h:89
std::vector< std::vector< std::string > > numArray_
Definition: csvReader.h:68
void read(const std::string &filename)
Reads .csv files into Mercury.
Definition: csvReader.cc:19
void setHeader(bool headings)
Set the boolean hasHeader_.
Definition: csvReader.cc:88
std::vector< Mdouble > CSVFirstColumn_
Definition: csvReader.h:79
std::vector< Mdouble > getFirstColumn(Mdouble scalingFactor)
Get first column of a .csv file and return it as a double.
Definition: csvReader.cc:107
string filename
Definition: MergeRestartFiles.py:39
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286