22 #include "FileReaderAscii.h" 24 FileReaderAscii::FileReaderAscii(
void)
25 : m_min(0),m_max(0),m_minRow(0),m_maxRow(0),m_fs(
' '),m_comment(
'#'){
28 FileReaderAscii::FileReaderAscii(
const std::string& filename)
29 : m_min(0),m_max(0),m_minRow(0),m_maxRow(0),m_fs(
' '),m_comment(
'#'){
33 FileReaderAscii::FileReaderAscii(
const std::string& filename,
const char& fieldseparator)
34 : m_min(0),m_max(0),m_minRow(0),m_maxRow(0),m_fs(fieldseparator),m_comment(
'#'){
38 FileReaderAscii::~FileReaderAscii(
void)
42 void FileReaderAscii::open(
const std::string& filename){
44 m_ifstream.open(filename.c_str(),std::ios_base::in);
46 std::string errorString;
47 errorString=
"Error: could not open file ";
48 errorString+=filename;
53 void FileReaderAscii::close(){
58 unsigned int FileReaderAscii::nrOfCol(
bool checkCols,
bool verbose){
60 unsigned int totalCol=0;
62 if(m_fs>
' '&&m_fs<=
'~'){
64 std::cout <<
"reading csv file " << m_filename << std::endl;
65 std::string csvRecord;
66 while(getline(m_ifstream,csvRecord)){
67 std::istringstream csvstream(csvRecord);
71 while(getline(csvstream,item,m_fs)){
73 std::cout << item <<
" ";
74 size_t pos=item.find(m_comment);
75 if(pos!=std::string::npos){
77 item=item.substr(0,pos-1);
81 std::cout <<
"comment found, string is " << item << std::endl;
89 std::cout << std::endl <<
"number of columns: " << ncol << std::endl;
94 std::ostringstream ess;
95 ess <<
"Error: different number of cols found in line " << nrow <<
" (" << ncol <<
"!=" << totalCol <<
")" << std::endl;
106 std::cout <<
"space or tab delimited fields" << std::endl;
107 std::string spaceRecord;
108 while(!getline(m_ifstream, spaceRecord).eof()){
110 std::cout << spaceRecord << std::endl;
111 std::istringstream lineStream(spaceRecord);
114 bool isComment=
false;
115 while(lineStream >> item){
117 std::cout << item <<
" ";
118 size_t pos=item.find(m_comment);
119 if(pos!=std::string::npos){
121 item=item.substr(0,pos-1);
125 std::cout <<
"comment found, string is " << item << std::endl;
133 std::cout << std::endl <<
"number of columns: " << ncol << std::endl;
138 std::ostringstream ess;
139 ess <<
"Error: different number of cols found in line " << nrow <<
" (" << ncol <<
"!=" << totalCol <<
")" << std::endl;
151 unsigned int FileReaderAscii::nrOfRow(
bool checkCols,
bool verbose){
153 unsigned int totalCol=0;
155 unsigned int ncomment=0;
156 if(m_fs>
' '&&m_fs<=
'~'){
158 std::cout <<
"reading csv file " << m_filename << std::endl;
159 std::string csvRecord;
160 while(getline(m_ifstream,csvRecord)){
161 std::istringstream csvstream(csvRecord);
164 bool isComment=
false;
165 while(getline(csvstream,item,m_fs)){
167 std::cout << item <<
" ";
168 size_t pos=item.find(m_comment);
169 if(pos!=std::string::npos){
172 std::cout <<
"comment found, string is " << item << std::endl;
185 std::cout << std::endl;
188 std::ostringstream ess;
189 ess <<
"Error: different number of cols found in line " << nrow <<
" (" << ncol <<
"!=" << totalCol <<
")" << std::endl;
198 std::cout <<
"space or tab delimited fields" << std::endl;
199 std::string spaceRecord;
201 while(!getline(m_ifstream, spaceRecord).eof()){
203 std::cout << spaceRecord << std::endl;
204 std::istringstream lineStream(spaceRecord);
207 bool isComment=
false;
208 while(lineStream >> item){
210 std::cout << item <<
" ";
211 size_t pos=item.find(m_comment);
212 if(pos!=std::string::npos){
215 std::cout <<
"comment found, string is " << item << std::endl;
228 std::cout << std::endl <<
"number of columns: " << ncol << std::endl;
231 std::ostringstream ess;
232 ess <<
"Error: different number of cols found in line " << nrow <<
" (" << ncol <<
"!=" << totalCol <<
")" << std::endl;