70 NDArray nda = v.array_value (
true);
74 if (nda.
numel () == 1)
92 bool resize_ok,
char type)
130 idx_vec(i) = idx(i).index_vector ();
154 #define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \
157 if (! force_string_conv) \
158 gripe_invalid_conversion ("string", TNAME); \
161 warning_with_id ("Octave:str-to-num", \
162 "implicit conversion from %s to %s", \
165 retval = octave_char_matrix::FCN (); \
224 error (
"invalid conversion of charNDArray to string_vector");
241 error (
"invalid conversion of charNDArray to string");
255 retval.
clear (nr, 1);
260 error (
"cellstr: cannot convert multidimensional arrays");
267 bool pr_as_read_syntax)
const
281 size_t max_len = 100;
283 os << (tmp.length () > max_len ? tmp.substr (0, 100) : tmp);
294 os <<
"# ndims: " << d.
length () <<
"\n";
295 for (
int i=0; i < d.
length (); i++)
307 os <<
"# elements: " << elements <<
"\n";
310 unsigned len = chm.
cols ();
311 os <<
"# length: " << len <<
"\n";
313 const char *tmp = tstr.data ();
314 if (tstr.length () > len)
331 keywords[0] =
"ndims";
332 keywords[1] =
"elements";
333 keywords[2] =
"length";
349 for (
int i = 0; i < mdims; i++)
364 if (! is.read (ftmp, dv.
numel ()) || !is)
366 error (
"load: failed to load string constant");
375 error (
"load: failed to read dimensions");
381 error (
"load: failed to extract matrix size");
385 else if (kw ==
"elements")
395 for (
int i = 0; i < elements; i++)
406 if (len > 0 && ! is.read (ptmp, len))
408 error (
"load: failed to load string constant");
417 chm.
resize (elements, max_len, 0);
425 error (
"load: failed to extract string length for element %d",
436 error (
"load: failed to extract number of string elements");
440 else if (kw ==
"length")
454 if (len > 0 && ! is.read (ptmp, len))
456 error (
"load: failed to load string constant");
463 error (
"load: failed to load string constant");
472 error (
"load: failed to extract number of rows and columns");
488 int32_t tmp = - d.
length ();
489 os.write (reinterpret_cast<char *> (&tmp), 4);
490 for (
int i=0; i < d.
length (); i++)
493 os.write (reinterpret_cast<char *> (&tmp), 4);
506 if (! is.read (reinterpret_cast<char *> (&elements), 4))
513 int32_t mdims = - elements;
518 for (
int i = 0; i < mdims; i++)
520 if (! is.read (reinterpret_cast<char *> (&di), 4))
541 is.read (tmp, dv.
numel ());
551 for (
int i = 0; i < elements; i++)
554 if (! is.read (reinterpret_cast<char *> (&len), 4))
559 char *pbtmp = btmp.fortran_vec ();
560 if (! is.read (pbtmp, len))
565 chm.
resize (elements, max_len, 0);
574 #if defined (HAVE_HDF5)
586 hid_t space_hid = -1, data_hid = -1;
593 for (
int i = 0; i < rank; i++)
594 hdims[i] = dv (rank-i-1);
596 space_hid = H5Screate_simple (rank, hdims, 0);
600 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
601 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
603 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
608 H5Sclose (space_hid);
614 for (
int i = 0; i < dv.
numel (); ++i)
617 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL,
618 H5P_DEFAULT, s) >= 0;
621 H5Sclose (space_hid);
639 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT);
641 hid_t data_hid = H5Dopen (loc_id, name);
643 hid_t space_hid = H5Dget_space (data_hid);
644 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
645 hid_t type_hid = H5Dget_type (data_hid);
646 hid_t type_class_hid = H5Tget_class (type_hid);
648 if (type_class_hid == H5T_INTEGER)
653 H5Sclose (space_hid);
661 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
673 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
679 if (H5Dread (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL,
680 H5P_DEFAULT, str) >= 0)
687 H5Sclose (space_hid);
698 int slen = H5Tget_size (type_hid);
702 H5Sclose (space_hid);
711 hid_t st_id = H5Tcopy (H5T_C_S1);
712 H5Tset_size (st_id, slen+1);
713 if (H5Dread (data_hid, st_id, H5S_ALL,
714 H5S_ALL, H5P_DEFAULT, s) < 0)
718 H5Sclose (space_hid);
727 H5Sclose (space_hid);
735 hsize_t elements, maxdim;
736 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim);
737 int slen = H5Tget_size (type_hid);
741 H5Sclose (space_hid);
755 hid_t st_id = H5Tcopy (H5T_C_S1);
756 H5Tset_size (st_id, slen+1);
758 if (H5Dread (data_hid, st_id, H5S_ALL,
759 H5S_ALL, H5P_DEFAULT, s) < 0)
763 H5Sclose (space_hid);
769 for (hsize_t i = 0; i < elements; ++i)
771 chm.
insert (s + i*(slen+1), i, 0);
778 H5Sclose (space_hid);
786 H5Sclose (space_hid);