15 std::string buffer =
"";
16 std::string substring =
"";
20 unsigned int NodeNumber = 0;
21 unsigned int ColumnNr = 0;
22 unsigned int ColumnNumber[VariableNameList.size()];
23 double DoubleDataTable[VariableNameList.size()];
26 for (
unsigned long int i = 0; i < VariableNameList.size(); i++) {
28 DoubleDataTable[i] = 0;
32 std::ifstream FileInput(DataFilePath);
33 if (!FileInput.good()) {
34 std::cout <<
"Data file not found: " << DataFilePath << std::endl;
42 std::getline(FileInput, buffer);
43 for (
unsigned long int i = 0; i < VariableNameList.size(); i++) {
48 while (substring != VariableNameList.at(i)) {
49 pos2 = buffer.find(
",", pos1);
50 if (pos2 != std::string::npos)
51 substring = buffer.substr(pos1, pos2 - pos1);
53 substring = buffer.substr(pos1);
55 while (pos3 != std::string::npos)
57 pos3 = substring.find(
"\"");
58 if (pos3 != std::string::npos)
59 substring = substring.erase(pos3, 1);
61 if ((substring != VariableNameList.at(i)) & (pos2 == std::string::npos))
63 std::cout <<
"Column name " << VariableNameList.at(i) <<
" not found in the file: " << DataFilePath << std::endl;
75 while (!FileInput.eof()) {
76 std::getline(FileInput, buffer);
77 pos1 = buffer.find_first_of(
"-0123456789");
82 while (pos2 != std::string::npos) {
83 pos2 = buffer.find(
",", pos1);
84 if (pos2 != std::string::npos)
85 substring = buffer.substr(pos1, pos2 - pos1);
87 substring = buffer.substr(pos1);
88 for (
unsigned long int i = 0; i < VariableNameList.size(); i++)
89 if (ColumnNumber[i] == ColumnNr)
90 DoubleDataTable[i] = boost::lexical_cast<
double>(substring);
94 for (
unsigned long int i = 0; i < VariableNameList.size(); i++)
95 pDataArray->push_back(DoubleDataTable[i]);
100 std::cout << NodeNumber <<
" data values are read from the file: " << DataFilePath << std::endl;
static void DataReadFromCSVFile(const std::string &DataFilePath, const std::vector< std::string > &VariableNameList, std::vector< double > *pDataArray)
Reads data from text file.