Mercurial > hg > octave-lyh
changeset 5933:1bcd9dd629c3
[project @ 2006-08-17 08:01:14 by jwe]
author | jwe |
---|---|
date | Thu, 17 Aug 2006 08:01:14 +0000 |
parents | 51cbaa2539f4 |
children | 8702f00329bf |
files | src/ChangeLog src/ls-mat5.cc |
diffstat | 2 files changed, 23 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2006-08-17 John W. Eaton <jwe@octave.org> + + * ls-mat5.cc (save_mat5_element_length): Correctly compute element + length for character data. Handle N-d character data + (save_mat5_binary_element): Handle N-d character data. + 2006-08-16 John W. Eaton <jwe@octave.org> * parse.y (gobble_leading_white_space): New arg, SKIP_CODE.
--- a/src/ls-mat5.cc +++ b/src/ls-mat5.cc @@ -1352,10 +1352,10 @@ if (tc.is_string ()) { - charMatrix chm = tc.char_matrix_value (); + charNDArray chm = tc.char_array_value (); ret += 8; - if (chm.nelem () > 1) - ret += PAD (2 * chm.rows () * chm.cols ()); + if (chm.nelem () > 2) + ret += PAD (2 * chm.nelem ()); } else if (cname == "sparse") { @@ -1618,27 +1618,26 @@ // data element if (tc.is_string ()) { - charMatrix chm = tc.char_matrix_value (); - int nr = chm.rows (); - int nc = chm.cols (); - int len = nr*nc*2; - int paddedlength = PAD (nr*nc*2); + charNDArray chm = tc.char_array_value (); + int nel = chm.nelem (); + int len = nel*2; + int paddedlength = PAD (len); - OCTAVE_LOCAL_BUFFER (int16_t, buf, nc*nr+3); + OCTAVE_LOCAL_BUFFER (int16_t, buf, nel+3); write_mat5_tag (os, miUINT16, len); - for (int i = 0; i < nr; i++) - { - std::string tstr = chm.row_as_string (i); - const char *s = tstr.data (); + const char *s = chm.data (); - for (int j = 0; j < nc; j++) - buf[j*nr+i] = *s++ & 0x00FF; - } - os.write (reinterpret_cast<char *> (buf), nr*nc*2); + for (int i = 0; i < nel; i++) + buf[i] = *s++ & 0x00FF; + + os.write (reinterpret_cast<char *> (buf), len); if (paddedlength > len) - os.write (reinterpret_cast<char *> (buf), paddedlength - len); + { + static char padbuf[9]="\x00\x00\x00\x00\x00\x00\x00\x00"; + os.write (padbuf, paddedlength - len); + } } else if (cname == "sparse") {