int Data::readFromCSV(const char* csv_filepath) { std::ifstream csvStream(csv_filepath, std::ios::in); if(csvStream.is_open()) { std::string line; std::stringstream lineStream; auto readVal = [&] () { std::string val; std::getline(lineStream, val , ','); return std::stringstream(val); }; std::getline(csvStream, line); lineStream = std::stringstream(line); std::vector<std::string> keys; std::string key; while(std::getline(lineStream, key , ',')) keys.push_back(key); while(std::getline(csvStream, line)) { lineStream = std::stringstream(line); DataLine dataLine; float w, x, y, z; for(unsigned int k = 0; k < keys.size(); k++) { if(keys[k].compare("Time") == 0) { std::string time; readVal() >> time; std::stringstream timeStream(time); auto readTime = [&] () { std::string val; std::getline(timeStream, val , ':'); return std::stringstream(val); }; int hr, min, sec; readTime() >> hr; readTime() >> min; readTime() >> sec; dataLine.Time = hr * 3600 + min * 60 + sec; } else if(keys[k].compare("Package N.O") == 0) readVal() >> dataLine.Package_NO; else if(keys[k].compare("Outside Temperature") == 0) readVal() >> dataLine.OutsideTemperature;
Foam::instantList Foam::Time::findTimes ( const fileName& directory, const word& constantName ) { if (debug) { InfoInFunction << "Finding times in directory " << directory << endl; } // Read directory entries into a list fileNameList dirEntries ( fileHandler().readDir ( directory, fileName::DIRECTORY ) ); // Initialise instant list instantList Times(dirEntries.size() + 1); label nTimes = 0; // Check for "constant" bool haveConstant = false; forAll(dirEntries, i) { if (dirEntries[i] == constantName) { Times[nTimes].value() = 0; Times[nTimes].name() = dirEntries[i]; nTimes++; haveConstant = true; break; } } // Read and parse all the entries in the directory forAll(dirEntries, i) { IStringStream timeStream(dirEntries[i]); token timeToken(timeStream); if (timeToken.isNumber() && timeStream.eof()) { Times[nTimes].value() = timeToken.number(); Times[nTimes].name() = dirEntries[i]; nTimes++; } }