69 NDArray nda = v.array_value (
true);
73 if (nda.
numel () == 1)
91 bool resize_ok,
char type)
129 idx_vec(i) = idx(i).index_vector ();
153 #define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \
156 if (! force_string_conv) \
157 gripe_invalid_conversion ("string", TNAME); \
160 warning_with_id ("Octave:str-to-num", \
161 "implicit conversion from %s to %s", \
164 retval = octave_char_matrix::FCN (); \
223 error (
"invalid conversion of charNDArray to string_vector");
240 error (
"invalid conversion of charNDArray to string");
254 retval.
clear (nr, 1);
259 error (
"cellstr: cannot convert multidimensional arrays");
266 bool pr_as_read_syntax)
const
280 size_t max_len = 100;
282 os << (tmp.length () > max_len ? tmp.substr (0, 100) : tmp);
293 os <<
"# ndims: " << d.
length () <<
"\n";
294 for (
int i=0; i < d.
length (); i++)
306 os <<
"# elements: " << elements <<
"\n";
309 unsigned len = chm.
cols ();
310 os <<
"# length: " << len <<
"\n";
312 const char *tmp = tstr.data ();
313 if (tstr.length () > len)
330 keywords[0] =
"ndims";
331 keywords[1] =
"elements";
332 keywords[2] =
"length";
348 for (
int i = 0; i < mdims; i++)
363 if (! is.read (ftmp, dv.
numel ()) || !is)
365 error (
"load: failed to load string constant");
374 error (
"load: failed to read dimensions");
380 error (
"load: failed to extract matrix size");
384 else if (kw ==
"elements")
394 for (
int i = 0; i < elements; i++)
405 if (len > 0 && ! is.read (ptmp, len))
407 error (
"load: failed to load string constant");
416 chm.
resize (elements, max_len, 0);
424 error (
"load: failed to extract string length for element %d",
435 error (
"load: failed to extract number of string elements");
439 else if (kw ==
"length")
453 if (len > 0 && ! is.read (ptmp, len))
455 error (
"load: failed to load string constant");
462 error (
"load: failed to load string constant");
471 error (
"load: failed to extract number of rows and columns");
487 int32_t tmp = - d.
length ();
488 os.write (reinterpret_cast<char *> (&tmp), 4);
489 for (
int i=0; i < d.
length (); i++)
492 os.write (reinterpret_cast<char *> (&tmp), 4);
505 if (! is.read (reinterpret_cast<char *> (&elements), 4))
512 int32_t mdims = - elements;
517 for (
int i = 0; i < mdims; i++)
519 if (! is.read (reinterpret_cast<char *> (&di), 4))
540 is.read (tmp, dv.
numel ());
550 for (
int i = 0; i < elements; i++)
553 if (! is.read (reinterpret_cast<char *> (&len), 4))
558 char *pbtmp = btmp.fortran_vec ();
559 if (! is.read (pbtmp, len))
564 chm.
resize (elements, max_len, 0);
579 #if defined (HAVE_HDF5)
587 hid_t space_hid, data_hid;
588 space_hid = data_hid = -1;
594 for (
int i = 0; i < rank; i++)
595 hdims[i] = dv (rank-i-1);
597 space_hid = H5Screate_simple (rank, hdims, 0);
601 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
602 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
604 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid,
609 H5Sclose (space_hid);
615 for (
int i = 0; i < dv.
numel (); ++i)
618 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL,
619 H5P_DEFAULT, s) >= 0;
622 H5Sclose (space_hid);
636 #if defined (HAVE_HDF5)
646 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT);
648 hid_t data_hid = H5Dopen (loc_id, name);
650 hid_t space_hid = H5Dget_space (data_hid);
651 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
652 hid_t type_hid = H5Dget_type (data_hid);
653 hid_t type_class_hid = H5Tget_class (type_hid);
655 if (type_class_hid == H5T_INTEGER)
660 H5Sclose (space_hid);
668 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
680 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
686 if (H5Dread (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL,
687 H5P_DEFAULT, str) >= 0)
694 H5Sclose (space_hid);
705 int slen = H5Tget_size (type_hid);
709 H5Sclose (space_hid);
718 hid_t st_id = H5Tcopy (H5T_C_S1);
719 H5Tset_size (st_id, slen+1);
720 if (H5Dread (data_hid, st_id, H5S_ALL,
721 H5S_ALL, H5P_DEFAULT, s) < 0)
725 H5Sclose (space_hid);
734 H5Sclose (space_hid);
742 hsize_t elements, maxdim;
743 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim);
744 int slen = H5Tget_size (type_hid);
748 H5Sclose (space_hid);
762 hid_t st_id = H5Tcopy (H5T_C_S1);
763 H5Tset_size (st_id, slen+1);
765 if (H5Dread (data_hid, st_id, H5S_ALL,
766 H5S_ALL, H5P_DEFAULT, s) < 0)
770 H5Sclose (space_hid);
776 for (hsize_t i = 0; i < elements; ++i)
778 chm.
insert (s + i*(slen+1), i, 0);
785 H5Sclose (space_hid);
793 H5Sclose (space_hid);
bool is_empty(void) const
octave_value do_index_op_internal(const octave_value_list &idx, bool resize_ok, char type= '"')
static octave_base_value * default_numeric_conversion_function(const octave_base_value &a)
void short_disp(std::ostream &os) const
string_vector all_strings(bool pad=false) const
octave_idx_type numel(void) const
Number of elements in the array.
void gripe_load(const char *type) const
octave_idx_type length(void) const
bool save_binary(std::ostream &os, bool &save_as_floats)
octave_idx_type numel(void) const
void resize(int n, int fill_value=0)
octave_value resize(const dim_vector &dv, bool fill=false) const
void error(const char *fmt,...)
double double_value(bool=false) const
NDArray array_value(bool=false) const
Array< std::string > cellstr_value(void) const
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
void gripe_save(const char *type) const
void skip_preceeding_newline(std::istream &is)
Complex complex_value(bool=false) const
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
std::string string_value(bool force=false) const
octave_idx_type rows(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
F77_RET_T const double const double double * d
int load_hdf5_empty(hid_t loc_id, const char *name, dim_vector &d)
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
#define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
void swap_bytes< 4 >(void *ptr)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
void resize(octave_idx_type n, const std::string &rfv=std::string())
static int static_type_id(void)
void resize(const dim_vector &dv, const T &rfv)
#define panic_impossible()
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
void resize(octave_idx_type nr, octave_idx_type nc, char rfv=0)
bool load_ascii(std::istream &is)
charMatrix char_matrix_value(bool=false) const
virtual bool is_sq_string(void) const
ComplexNDArray complex_array_value(bool=false) const
friend class octave_value
T & xelem(octave_idx_type n)
type_conv_info numeric_conversion_function(void) const
dim_vector dims(void) const
Handles the reference counting for all the derived classes.
charNDArray char_array_value(bool=false) const
int current_print_indent_level(void) const
bool save_ascii(std::ostream &os)
void octave_print_internal(std::ostream &, char, bool)
int save_hdf5_empty(hid_t loc_id, const char *name, const dim_vector d)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
static const pair_type keywords[]
bool load_binary(std::istream &is, bool swap, oct_mach_info::float_format fmt)
std::complex< double > Complex
const T * fortran_vec(void) const
octave_idx_type cols(void) const
ComplexMatrix complex_matrix_value(bool=false) const
Matrix matrix_value(bool=false) const
Array< T > index(const idx_vector &i) const
Indexing without resizing.