From 8a76bcac985f0107d55c457f720c7508a5100645 Mon Sep 17 00:00:00 2001 From: Mark Jenkinson <mark@fmrib.ox.ac.uk> Date: Tue, 18 Nov 2003 13:33:06 +0000 Subject: [PATCH] Changed read_ascii_matrix to make it _much_ quicker for large matrices of unknown size --- miscmaths.cc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/miscmaths.cc b/miscmaths.cc index 5076b39..08192f6 100644 --- a/miscmaths.cc +++ b/miscmaths.cc @@ -141,8 +141,6 @@ namespace MISCMATHS { ReturnMatrix read_ascii_matrix(ifstream& fs) { - Matrix mat; - int rcount=0, cmax=0; double val; string cline; @@ -159,9 +157,8 @@ namespace MISCMATHS { } } cmax--; - RowVector newrow(cmax); - do { + do { getline(fs,cline); cline += " "; // force extra entry in parsing istrstream ss(cline.c_str()); @@ -169,20 +166,13 @@ namespace MISCMATHS { ss >> cc; if (!isnum(cc)) break; // stop processing when non-numeric line found rcount++; // add new row to matrix - newrow = 0.0; - 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()); + } while (!fs.eof()); - mat.Release(); - return mat; + // now know the size of matrix + fs.clear(); + fs.seekg(0,ios::beg); + return read_ascii_matrix(fs,rcount,cmax); + } #define BINFLAG 42 -- GitLab