Mercurial > hg > octave-lyh
comparison src/ls-mat-ascii.cc @ 8425:2e777f5135a3
support -tabs option for save -ascii
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 25 Dec 2008 12:31:07 +0100 |
parents | 85184151822e |
children | eb63fbe60fab |
comparison
equal
deleted
inserted
replaced
8424:a84d71abdc5b | 8425:2e777f5135a3 |
---|---|
327 return retval; | 327 return retval; |
328 } | 328 } |
329 | 329 |
330 bool | 330 bool |
331 save_mat_ascii_data (std::ostream& os, const octave_value& val, | 331 save_mat_ascii_data (std::ostream& os, const octave_value& val, |
332 int precision) | 332 int precision, bool tabs) |
333 { | 333 { |
334 bool success = true; | 334 bool success = true; |
335 | 335 |
336 if (val.is_complex_type ()) | 336 if (val.is_complex_type ()) |
337 warning ("save: omitting imaginary part for ASCII file"); | 337 warning ("save: omitting imaginary part for ASCII file"); |
351 os.precision (precision); | 351 os.precision (precision); |
352 | 352 |
353 std::ios::fmtflags oflags | 353 std::ios::fmtflags oflags |
354 = os.flags (static_cast<std::ios::fmtflags> (std::ios::scientific)); | 354 = os.flags (static_cast<std::ios::fmtflags> (std::ios::scientific)); |
355 | 355 |
356 os << m; | 356 if (tabs) |
357 { | |
358 for (octave_idx_type i = 0; i < m.rows (); i++) | |
359 { | |
360 for (octave_idx_type j = 0; j < m.cols (); j++) | |
361 { | |
362 // Omit leading tabs. | |
363 if (j != 0) os << '\t'; | |
364 octave_write_double (os, m (i, j)); | |
365 } | |
366 os << "\n"; | |
367 } | |
368 } | |
369 else | |
370 os << m; | |
357 | 371 |
358 os.flags (oflags); | 372 os.flags (oflags); |
359 | 373 |
360 os.precision (old_precision); | 374 os.precision (old_precision); |
361 } | 375 } |