Skip to content
Snippets Groups Projects
Commit 8a76bcac authored by Mark Jenkinson's avatar Mark Jenkinson
Browse files

Changed read_ascii_matrix to make it _much_ quicker for large matrices of unknown size

parent dc82b7a9
No related branches found
No related tags found
No related merge requests found
...@@ -141,8 +141,6 @@ namespace MISCMATHS { ...@@ -141,8 +141,6 @@ namespace MISCMATHS {
ReturnMatrix read_ascii_matrix(ifstream& fs) ReturnMatrix read_ascii_matrix(ifstream& fs)
{ {
Matrix mat;
int rcount=0, cmax=0; int rcount=0, cmax=0;
double val; double val;
string cline; string cline;
...@@ -159,9 +157,8 @@ namespace MISCMATHS { ...@@ -159,9 +157,8 @@ namespace MISCMATHS {
} }
} }
cmax--; cmax--;
RowVector newrow(cmax);
do { do {
getline(fs,cline); getline(fs,cline);
cline += " "; // force extra entry in parsing cline += " "; // force extra entry in parsing
istrstream ss(cline.c_str()); istrstream ss(cline.c_str());
...@@ -169,20 +166,13 @@ namespace MISCMATHS { ...@@ -169,20 +166,13 @@ namespace MISCMATHS {
ss >> cc; ss >> cc;
if (!isnum(cc)) break; // stop processing when non-numeric line found if (!isnum(cc)) break; // stop processing when non-numeric line found
rcount++; // add new row to matrix rcount++; // add new row to matrix
newrow = 0.0; } while (!fs.eof());
int ccount = 1;
do {
val = atof(cc.c_str());
if (ccount<=cmax) newrow(ccount++) = val;
ss >> cc;
} while (!ss.eof());
if (rcount>1) mat = mat & newrow;
else mat = newrow;
} while (!fs.eof());
mat.Release(); // now know the size of matrix
return mat; fs.clear();
fs.seekg(0,ios::beg);
return read_ascii_matrix(fs,rcount,cmax);
} }
#define BINFLAG 42 #define BINFLAG 42
......
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