Skip to content
Snippets Groups Projects
Commit 969cc35a authored by Matthew Webster's avatar Matthew Webster
Browse files

Fixed matrix reading routines

parent 77c1754f
No related branches found
No related tags found
No related merge requests found
/* miscmaths.cc /* miscmaths.cc
Mark Jenkinson & Mark Woolrich & Christian Beckmann & Tim Behrens, FMRIB Image Analysis Group Mark Jenkinson, Mark Woolrich, Christian Beckmann, Tim Behrens and Matthew Webster, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */ Copyright (C) 1999-2009 University of Oxford */
/* CCOPYRIGHT */ /* CCOPYRIGHT */
...@@ -74,9 +74,9 @@ namespace MISCMATHS { ...@@ -74,9 +74,9 @@ namespace MISCMATHS {
getline(fs,cline); getline(fs,cline);
cline += " "; // force extra entry in parsing cline += " "; // force extra entry in parsing
istringstream ss(cline.c_str()); istringstream ss(cline.c_str());
string cc=""; string firstToken="";
ss >> cc; ss >> firstToken; //Put first non-whitespace sequence into cc
if (isNumber(cc.substr(0,2))) { if (isNumber(firstToken)) {
if (!fs.eof()) { fs.seekg(curpos); } else { fs.clear(); fs.seekg(0,ios::beg); } if (!fs.eof()) { fs.seekg(curpos); } else { fs.clear(); fs.seekg(0,ios::beg); }
return cline; return cline;
} }
...@@ -154,36 +154,36 @@ namespace MISCMATHS { ...@@ -154,36 +154,36 @@ namespace MISCMATHS {
ReturnMatrix read_ascii_matrix(ifstream& fs) ReturnMatrix read_ascii_matrix(ifstream& fs)
{ {
int rcount=0, cmax=0; int nRows(0), nColumns(0);
string cline; string currentLine;
// skip initial non-numeric lines // skip initial non-numeric lines
// and count the number of columns in the first numeric line // and count the number of columns in the first numeric line
cline = skip_alpha(fs); currentLine = skip_alpha(fs);
cline += " "; currentLine += " ";
{ {
istringstream ss(cline.c_str()); istringstream ss(currentLine.c_str());
string cc=""; string dummyToken="";
while (!ss.eof()) { while (!ss.eof()) {
cmax++; nColumns++;
ss >> cc; ss >> dummyToken;
} }
} }
cmax--; nColumns--;
do { do {
getline(fs,cline); getline(fs,currentLine);
cline += " "; // force extra entry in parsing currentLine += " "; // force extra entry in parsing
istringstream ss(cline.c_str()); istringstream ss(currentLine.c_str());
string cc=""; string firstToken("");
ss >> cc; ss >> firstToken; //Put first non-whitespace sequence into cc
if (!isNumber(cc.substr(0,2))) break; // stop processing when non-numeric line found if (!isNumber(firstToken)) break; // stop processing when non-numeric line found
rcount++; // add new row to matrix nRows++; // add new row to matrix
} while (!fs.eof()); } while (!fs.eof());
// now know the size of matrix // now know the size of matrix
fs.clear(); fs.clear();
fs.seekg(0,ios::beg); fs.seekg(0,ios::beg);
return read_ascii_matrix(fs,rcount,cmax); return read_ascii_matrix(fs,nRows,nColumns);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment