Mercurial > hg > octave-nkf
diff src/ov-re-mat.cc @ 5099:f7e39f977fe8
[project @ 2004-12-24 19:06:01 by jwe]
author | jwe |
---|---|
date | Fri, 24 Dec 2004 19:06:01 +0000 |
parents | 44046bbaa52c |
children | e35b034d3523 |
line wrap: on
line diff
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -329,70 +329,83 @@ bool octave_matrix::load_ascii (std::istream& is) { - int mdims = 0; bool success = true; - std::streampos pos = is.tellg (); + + string_vector keywords(2); + + keywords[0] = "ndims"; + keywords[1] = "rows"; - if (extract_keyword (is, "ndims", mdims, true)) + std::string kw; + int val = 0; + + if (extract_keyword (is, keywords, kw, val, true)) { - if (mdims >= 0) + if (kw == "ndims") { - dim_vector dv; - dv.resize (mdims); + int mdims = val; - for (int i = 0; i < mdims; i++) - is >> dv(i); - - NDArray tmp(dv); - is >> tmp; - - if (!is) + if (mdims >= 0) { - error ("load: failed to load matrix constant"); - success = false; - } - matrix = tmp; - } - else - { - error ("load: failed to extract number of rows and columns"); - success = false; - } - } - else - { - int nr = 0; - int nc = 0; + dim_vector dv; + dv.resize (mdims); - // re-read the same line again - is.clear (); - is.seekg (pos); + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (extract_keyword (is, "rows", nr) && nr >= 0 - && extract_keyword (is, "columns", nc) && nc >= 0) - { - if (nr > 0 && nc > 0) - { - Matrix tmp (nr, nc); + NDArray tmp(dv); is >> tmp; - if (is) - matrix = tmp; - else + + if (!is) { error ("load: failed to load matrix constant"); success = false; } + matrix = tmp; } - else if (nr == 0 || nc == 0) - matrix = Matrix (nr, nc); else - panic_impossible (); + { + error ("load: failed to extract number of rows and columns"); + success = false; + } } - else + else if (kw == "rows") { - error ("load: failed to extract number of rows and columns"); - success = false; + int nr = val; + int nc = 0; + + if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0) + { + if (nr > 0 && nc > 0) + { + Matrix tmp (nr, nc); + is >> tmp; + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } + } + else if (nr == 0 || nc == 0) + matrix = Matrix (nr, nc); + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; + } } + else + panic_impossible (); + } + else + { + error ("load: failed to extract number of rows and columns"); + success = false; } return success;