comparison src/ov-cx-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
274 } 274 }
275 275
276 bool 276 bool
277 octave_complex_matrix::load_ascii (std::istream& is) 277 octave_complex_matrix::load_ascii (std::istream& is)
278 { 278 {
279 int mdims = 0;
280 bool success = true; 279 bool success = true;
281 std::streampos pos = is.tellg (); 280
282 281 string_vector keywords(2);
283 if (extract_keyword (is, "ndims", mdims, true)) 282
284 { 283 keywords[0] = "ndims";
285 if (mdims >= 0) 284 keywords[1] = "rows";
286 { 285
287 dim_vector dv; 286 std::string kw;
288 dv.resize (mdims); 287 int val = 0;
289 288
290 for (int i = 0; i < mdims; i++) 289 if (extract_keyword (is, keywords, kw, val, true))
291 is >> dv(i); 290 {
292 291 if (kw == "ndims")
293 ComplexNDArray tmp(dv); 292 {
294 is >> tmp; 293 int mdims = val;
295 294
296 if (!is) 295 if (mdims >= 0)
297 { 296 {
298 error ("load: failed to load matrix constant"); 297 dim_vector dv;
299 success = false; 298 dv.resize (mdims);
300 } 299
301 matrix = tmp; 300 for (int i = 0; i < mdims; i++)
302 } 301 is >> dv(i);
303 else 302
304 { 303 ComplexNDArray tmp(dv);
305 error ("load: failed to extract number of rows and columns");
306 success = false;
307 }
308 }
309 else
310 {
311 int nr = 0;
312 int nc = 0;
313
314 // re-read the same line again
315 is.clear ();
316 is.seekg (pos);
317
318 if (extract_keyword (is, "rows", nr) && nr >= 0
319 && extract_keyword (is, "columns", nc) && nc >= 0)
320 {
321 if (nr > 0 && nc > 0)
322 {
323 ComplexMatrix tmp (nr, nc);
324 is >> tmp; 304 is >> tmp;
305
325 if (!is) 306 if (!is)
326 { 307 {
327 error ("load: failed to load matrix constant"); 308 error ("load: failed to load matrix constant");
328 success = false; 309 success = false;
329 } 310 }
330 matrix = tmp; 311 matrix = tmp;
331 } 312 }
332 else if (nr == 0 || nc == 0)
333 matrix = ComplexMatrix (nr, nc);
334 else 313 else
335 panic_impossible (); 314 {
336 } 315 error ("load: failed to extract number of rows and columns");
337 else 316 success = false;
338 { 317 }
339 error ("load: failed to extract number of rows and columns"); 318 }
340 success = false; 319 else if (kw == "rows")
341 } 320 {
321 int nr = val;
322 int nc = 0;
323
324 if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
325 {
326 if (nr > 0 && nc > 0)
327 {
328 ComplexMatrix tmp (nr, nc);
329 is >> tmp;
330 if (!is)
331 {
332 error ("load: failed to load matrix constant");
333 success = false;
334 }
335 matrix = tmp;
336 }
337 else if (nr == 0 || nc == 0)
338 matrix = ComplexMatrix (nr, nc);
339 else
340 panic_impossible ();
341 }
342 else
343 {
344 error ("load: failed to extract number of rows and columns");
345 success = false;
346 }
347 }
348 else
349 panic_impossible ();
350 }
351 else
352 {
353 error ("load: failed to extract number of rows and columns");
354 success = false;
342 } 355 }
343 356
344 return success; 357 return success;
345 } 358 }
346 359