예제 #1
0
void CSVIO::read(std::vector<std::vector<std::string> >& strOut){
	CSVRow row;

	std::vector<string> rowStr;
	int rowindex = 0;

	row.read(ifs);
	rowStr = row.getData();

	while(!ifs.fail() && !ifs.eof() && (++rowindex < nrow)){
		row.read(ifs);
		rowStr = row.getData();
		strOut.push_back(rowStr);
		rowStr.clear();
	}
	if(nrow == std::numeric_limits<int>::max())
		strOut.erase(strOut.end());
}
예제 #2
0
std::vector<double> CSVIO::readColumn(){
	CSVRow row;
	std::vector<string> rowStr;
	std::vector<double> out;
	row.read(ifs);
	rowStr = row.getData();


	do{
		row.read(ifs);
		rowStr = row.getData();

		for(int i = 0; i < rowStr.size(); i++){
			out.push_back(std::stof(rowStr.at(i)));
		}
	}while(!(ifs.fail() && ifs.eof()));

	return out;
}
예제 #3
0
void CSVIO::read(std::vector<std::vector<std::string> >& strOut, std::vector<std::vector<double> >& dblOut){
	CSVRow row;

	std::vector<int>::iterator dblColItr = dblCols.begin();
	std::vector<int>::iterator strColItr = strCols.begin();

	std::vector<std::string> rowStr;
	std::vector<double> tDbl(dblCols.size());
	std::vector<std::string> tStr(strCols.size());
	int rowindex = 0;
	std::string temp;
	row.read(ifs);
	rowStr = row.getData();

	while(!ifs.fail() && !ifs.eof() && (rowindex < nrow)){
		row.read(ifs);
		rowStr = row.getData();

		for(int i = 0; i < rowStr.size(); i++){
			if((strColItr != strCols.end()) && (i == *strColItr)){
				tStr.push_back(rowStr.at(i));
				++strColItr;
			}else if((dblColItr != dblCols.end()) && (i == *dblColItr)){
				temp = rowStr.at(i);
				boost::algorithm::trim(temp);
				if(temp == "." ){
					tDbl.push_back(NA_DOUBLE);
				}else{
					tDbl.push_back(std::stof(rowStr.at(i)));
				}
				++dblColItr;
			}
		}

		dblOut.push_back(tDbl);
		strOut.push_back(tStr);
		++rowindex;
		rowStr.clear();
		tStr.clear();
		tDbl.clear();
	}
}
예제 #4
0
void CSVIO::read(std::vector<std::vector<double> >& out){
	CSVRow row;
	std::vector<string> rowStr;
	row.read(ifs);
	rowStr = row.getData();
	std::vector<double> tVec(rowStr.size());
	int rowindex = 0;

	while(!ifs.fail() && !ifs.eof() && (rowindex < nrow)){
		row.read(ifs);
		rowStr = row.getData();

		for(int i = 0; i < rowStr.size(); i++){
			tVec[i] =  std::stof(rowStr.at(i));
		}
		out.push_back(tVec);
		++rowindex;
		rowStr.clear();

	}
}