comparison 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
comparison
equal deleted inserted replaced
5098:ab4e64f92526 5099:f7e39f977fe8
327 } 327 }
328 328
329 bool 329 bool
330 octave_matrix::load_ascii (std::istream& is) 330 octave_matrix::load_ascii (std::istream& is)
331 { 331 {
332 int mdims = 0;
333 bool success = true; 332 bool success = true;
334 std::streampos pos = is.tellg (); 333
335 334 string_vector keywords(2);
336 if (extract_keyword (is, "ndims", mdims, true)) 335
337 { 336 keywords[0] = "ndims";
338 if (mdims >= 0) 337 keywords[1] = "rows";
339 { 338
340 dim_vector dv; 339 std::string kw;
341 dv.resize (mdims); 340 int val = 0;
342 341
343 for (int i = 0; i < mdims; i++) 342 if (extract_keyword (is, keywords, kw, val, true))
344 is >> dv(i); 343 {
345 344 if (kw == "ndims")
346 NDArray tmp(dv); 345 {
347 is >> tmp; 346 int mdims = val;
348 347
349 if (!is) 348 if (mdims >= 0)
350 { 349 {
351 error ("load: failed to load matrix constant"); 350 dim_vector dv;
352 success = false; 351 dv.resize (mdims);
353 } 352
354 matrix = tmp; 353 for (int i = 0; i < mdims; i++)
355 } 354 is >> dv(i);
356 else 355
357 { 356 NDArray tmp(dv);
358 error ("load: failed to extract number of rows and columns");
359 success = false;
360 }
361 }
362 else
363 {
364 int nr = 0;
365 int nc = 0;
366
367 // re-read the same line again
368 is.clear ();
369 is.seekg (pos);
370
371 if (extract_keyword (is, "rows", nr) && nr >= 0
372 && extract_keyword (is, "columns", nc) && nc >= 0)
373 {
374 if (nr > 0 && nc > 0)
375 {
376 Matrix tmp (nr, nc);
377 is >> tmp; 357 is >> tmp;
378 if (is) 358
379 matrix = tmp; 359 if (!is)
380 else
381 { 360 {
382 error ("load: failed to load matrix constant"); 361 error ("load: failed to load matrix constant");
383 success = false; 362 success = false;
384 } 363 }
364 matrix = tmp;
385 } 365 }
386 else if (nr == 0 || nc == 0)
387 matrix = Matrix (nr, nc);
388 else 366 else
389 panic_impossible (); 367 {
390 } 368 error ("load: failed to extract number of rows and columns");
391 else 369 success = false;
392 { 370 }
393 error ("load: failed to extract number of rows and columns"); 371 }
394 success = false; 372 else if (kw == "rows")
395 } 373 {
374 int nr = val;
375 int nc = 0;
376
377 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
378 {
379 if (nr > 0 && nc > 0)
380 {
381 Matrix tmp (nr, nc);
382 is >> tmp;
383 if (is)
384 matrix = tmp;
385 else
386 {
387 error ("load: failed to load matrix constant");
388 success = false;
389 }
390 }
391 else if (nr == 0 || nc == 0)
392 matrix = Matrix (nr, nc);
393 else
394 panic_impossible ();
395 }
396 else
397 {
398 error ("load: failed to extract number of rows and columns");
399 success = false;
400 }
401 }
402 else
403 panic_impossible ();
404 }
405 else
406 {
407 error ("load: failed to extract number of rows and columns");
408 success = false;
396 } 409 }
397 410
398 return success; 411 return success;
399 } 412 }
400 413