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
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 */
......@@ -74,9 +74,9 @@ namespace MISCMATHS {
getline(fs,cline);
cline += " "; // force extra entry in parsing
istringstream ss(cline.c_str());
string cc="";
ss >> cc;
if (isNumber(cc.substr(0,2))) {
string firstToken="";
ss >> firstToken; //Put first non-whitespace sequence into cc
if (isNumber(firstToken)) {
if (!fs.eof()) { fs.seekg(curpos); } else { fs.clear(); fs.seekg(0,ios::beg); }
return cline;
}
......@@ -154,36 +154,36 @@ namespace MISCMATHS {
ReturnMatrix read_ascii_matrix(ifstream& fs)
{
int rcount=0, cmax=0;
string cline;
int nRows(0), nColumns(0);
string currentLine;
// skip initial non-numeric lines
// and count the number of columns in the first numeric line
cline = skip_alpha(fs);
cline += " ";
currentLine = skip_alpha(fs);
currentLine += " ";
{
istringstream ss(cline.c_str());
string cc="";
istringstream ss(currentLine.c_str());
string dummyToken="";
while (!ss.eof()) {
cmax++;
ss >> cc;
nColumns++;
ss >> dummyToken;
}
}
cmax--;
nColumns--;
do {
getline(fs,cline);
cline += " "; // force extra entry in parsing
istringstream ss(cline.c_str());
string cc="";
ss >> cc;
if (!isNumber(cc.substr(0,2))) break; // stop processing when non-numeric line found
rcount++; // add new row to matrix
getline(fs,currentLine);
currentLine += " "; // force extra entry in parsing
istringstream ss(currentLine.c_str());
string firstToken("");
ss >> firstToken; //Put first non-whitespace sequence into cc
if (!isNumber(firstToken)) break; // stop processing when non-numeric line found
nRows++; // add new row to matrix
} while (!fs.eof());
// now know the size of matrix
fs.clear();
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