23 #if defined (HAVE_CONFIG_H)
77 assert (idx.
length () == 1);
89 "structure has no member '%s'", nm.c_str ());
97 error (
"invalid index for structure array assignment");
103 error (
"%s cannot be indexed with %c", nm.c_str (),
t);
113 "%s: invalid structure field name '%s'",
117 "invalid structure field name '%s'",
124 const std::list<octave_value_list>& idx,
135 if (type.length () > 1 && type[1] ==
'.')
137 std::list<octave_value_list>::const_iterator
p = idx.begin ();
187 const std::list<octave_value_list>& idx,
198 if (type.length () > 1 && type[1] ==
'.')
200 std::list<octave_value_list>::const_iterator
p = idx.begin ();
205 const Cell t = tmp.
index (idx.front (), auto_add);
243 retval = retval.
next_subsref (auto_add, type, idx, skip);
263 if (type.length () > 0 && type[0] ==
'.' && ! val.
is_map ())
273 const std::list<octave_value_list>& idx,
282 if (idx.front ().empty ())
283 error (
"missing index in indexed assignment");
285 if (n > 1 && ! (type.length () == 2 && type[0] ==
'(' && type[1] ==
'.'))
291 if (type.length () > 1 && type[1] ==
'.')
293 std::list<octave_value_list>::const_iterator
p = idx.begin ();
298 assert (key_idx.
length () == 1);
304 std::list<octave_value_list> next_idx (idx);
309 next_idx.erase (next_idx.begin ());
310 next_idx.erase (next_idx.begin ());
324 if (tmpc.
numel () != 1)
341 t_rhs =(orig_undefined
343 : tmp.
subsasgn (next_type, next_idx, rhs));
354 assert (key_idx.
length () == 1);
360 std::list<octave_value_list> next_idx (idx);
362 next_idx.erase (next_idx.begin ());
376 if (tmpc.
numel () == 1)
392 t_rhs = (orig_undefined
394 : tmp.
subsasgn (next_type, next_idx, rhs));
414 if (n > 1 && type[1] ==
'.')
416 std::list<octave_value_list>::const_iterator
p = idx.begin ();
420 assert (key_idx.
length () == 1);
434 if (! idxf(
k).is_magic_colon ())
435 didx(
k) = idxf(
k).numel ();
437 if (didx.numel () == tmp_cell.
numel ())
438 tmp_cell = tmp_cell.
reshape (didx);
477 error (
"invalid structure assignment");
492 assert (key_idx.
length () == 1);
575 if (Vstruct_levels_to_print >= 0)
577 bool max_depth_reached = Vstruct_levels_to_print-- == 0;
579 bool print_fieldnames_only
587 os << dv.
str () <<
" struct array containing the fields:";
602 if (print_fieldnames_only)
614 if (print_fieldnames_only)
635 if (Vstruct_levels_to_print < 0)
662 os <<
"# ndims: " << dv.
ndims () <<
"\n";
664 for (
int i = 0;
i < dv.
ndims ();
i++)
668 os <<
"# length: " << nf <<
"\n";
701 keywords[0] =
"ndims";
702 keywords[1] =
"length";
708 if (kw == keywords[0])
710 int mdims =
std::max (static_cast<int> (len), 2);
712 for (
int i = 0;
i < mdims;
i++)
721 if (! success || len < 0)
722 error (
"load: failed to extract number of elements in structure");
746 error (
"load: failed to load structure");
770 int32_t di = - dv.
ndims ();
771 os.write (reinterpret_cast<char *> (&di), 4);
772 for (
int i = 0;
i < dv.
ndims ();
i++)
775 os.write (reinterpret_cast<char *> (&di), 4);
779 os.write (reinterpret_cast<char *> (&len), 4);
806 if (! is.read (reinterpret_cast<char *> (&len), 4))
821 for (
int i = 0;
i < mdims;
i++)
823 if (! is.read (reinterpret_cast<char *> (&di), 4))
830 if (! is.read (reinterpret_cast<char *> (&len), 4))
859 error (
"load: failed to load structure");
875 #if defined (HAVE_HDF5)
879 #if defined (HAVE_HDF5_18)
883 data_hid = H5Gcreate (loc_id, name, 0);
885 if (data_hid < 0)
return false;
914 octave_unused_parameter (loc_id);
915 octave_unused_parameter (name);
916 octave_unused_parameter (save_as_floats);
929 #if defined (HAVE_HDF5)
935 int current_item = 0;
937 #if defined (HAVE_HDF5_18)
940 hid_t group_id = H5Gopen (loc_id, name);
942 H5Gget_num_objs (group_id, &num_obj);
948 while (current_item < static_cast<int> (num_obj)
967 octave_unused_parameter (loc_id);
968 octave_unused_parameter (name);
984 for (
int i = 0;
i < nf;
i++)
985 f[
i] = kv[
i].c_str ();
995 for (
int i = 0;
i < nf;
i++)
1002 for (
mwIndex j = i; j < ntot; j += nf)
1003 elts[j] =
new mxArray (p[k++]);
1029 void *here =
reinterpret_cast<void *
>(&sm_ptr);
1045 assert (idx.
length () == 1);
1055 "structure has no member '%s'", nm.c_str ());
1062 const std::list<octave_value_list>& idx)
1070 retval =
dotref (idx.front ());
1072 if (idx.size () > 1)
1083 const std::list<octave_value_list>& idx,
1094 if (idx.size () > 1)
1105 const std::list<octave_value_list>& idx,
1114 retval =
dotref (idx.front (), auto_add);
1116 if (idx.size () > 1)
1117 retval = retval.
next_subsref (auto_add, type, idx, skip);
1140 if (type.length () > 0 && type[0] ==
'.' && ! val.
is_map ())
1150 const std::list<octave_value_list>& idx,
1155 if (idx.front ().empty ())
1156 error (
"missing index in indexed assignment");
1160 int n = type.length ();
1166 assert (key_idx.
length () == 1);
1174 std::list<octave_value_list> next_idx (idx);
1176 next_idx.erase (next_idx.begin ());
1199 t_rhs = (orig_undefined
1201 : tmp.
subsasgn (next_type, next_idx, rhs));
1213 retval = tmp.
subsasgn (type, idx, rhs);
1258 if (Vstruct_levels_to_print >= 0)
1260 bool max_depth_reached = Vstruct_levels_to_print-- == 0;
1262 bool print_fieldnames_only = max_depth_reached;
1270 os <<
"scalar structure containing the fields:";
1285 if (print_fieldnames_only)
1303 os <<
"<structure>";
1316 if (Vstruct_levels_to_print < 0)
1317 os << name <<
" = ";
1337 os <<
"# ndims: " << dv.
ndims () <<
"\n";
1339 for (
int i = 0;
i < dv.
ndims ();
i++)
1343 os <<
"# length: " << nf <<
"\n";
1358 return ! os.fail ();
1370 error (
"load: failed to extract number of elements in structure");
1392 error (
"load: failed to load structure");
1412 os.write (reinterpret_cast<char *> (&len), 4);
1427 return ! os.fail ();
1437 bool success =
true;
1439 if (! is.read (reinterpret_cast<char *> (&len), 4))
1465 error (
"load: failed to load structure");
1481 #if defined (HAVE_HDF5)
1483 hid_t data_hid = -1;
1485 #if defined (HAVE_HDF5_18)
1489 data_hid = H5Gcreate (loc_id, name, 0);
1491 if (data_hid < 0)
return false;
1508 bool retval2 =
add_hdf5_data (data_hid, val, key,
"",
false,
1515 H5Gclose (data_hid);
1520 octave_unused_parameter (loc_id);
1521 octave_unused_parameter (name);
1522 octave_unused_parameter (save_as_floats);
1535 #if defined (HAVE_HDF5)
1541 int current_item = 0;
1542 hsize_t num_obj = 0;
1543 #if defined (HAVE_HDF5_18)
1546 hid_t group_id = H5Gopen (loc_id, name);
1548 H5Gget_num_objs (group_id, &num_obj);
1549 H5Gclose (group_id);
1554 while (current_item < static_cast<int> (num_obj)
1571 octave_unused_parameter (loc_id);
1572 octave_unused_parameter (name);
1588 for (
int i = 0;
i < nf;
i++)
1589 f[
i] = kv[
i].c_str ();
1599 for (
int i = 0;
i < nf;
i++)
1606 for (
mwIndex j = i; j < ntot; j += nf)
1607 elts[j] =
new mxArray (p[k++]);
1700 if (nargin == 1 &&
args(0).is_map ())
1703 if (nargin == 1 &&
args(0).is_object ())
1704 return ovl (
args(0).map_value ());
1706 if ((nargin == 1 || nargin == 2)
1707 &&
args(0).is_empty () &&
args(0).is_real_matrix ())
1711 Array<std::string> cstr =
args(1).xcellstr_value (
"struct: second argument should be a cell array of field names");
1723 if (!
args(
i).is_string () ||
i + 1 >= nargin)
1724 error (
"struct: additional arguments must occur as \"field\", VALUE pairs");
1735 if (
args(
i).is_cell ())
1741 if (! first_dimensioned_value)
1744 first_dimensioned_value =
i + 1;
1746 else if (
dims != argdims)
1748 error (
"struct: dimensions of parameter %d "
1749 "do not match those of parameter %d",
1750 first_dimensioned_value,
i+1);
1774 if (
args(
i+1).is_cell ())
1817 if (
args.length () != 1)
1820 return ovl (
args(0).is_map ());
1843 retval =
Cell (0, 1);
1845 retval =
Cell (keys);
1862 if (
args.length () != 2)
1867 if (
args(0).is_map ())
1873 if (
args(1).is_string ())
1879 else if (
args(1).is_cell ())
1887 if (
c(
i).is_string ())
1911 if (
args.length () != 1)
1914 if (!
args(0).is_map ())
1915 error (
"numfields: argument must be a struct");
1917 return ovl (static_cast<double> (
args(0).nfields ()));
1960 int nargin =
args.length ();
1962 if (nargin < 2 || nargin > 3)
1965 if (!
args(0).is_cell ())
1966 error (
"cell2struct: argument CELL must be of type cell");
1968 if (! (
args(1).is_cellstr () ||
args(1).is_char_matrix ()))
1969 error (
"cell2struct: FIELDS must be a cell array of strings or a character matrix");
1975 if (!
args(2).is_real_scalar ())
1976 error (
"cell2struct: DIM must be a real scalar");
1978 dim = nargin == 2 ? 0 :
args(2).int_value () - 1;
1982 error (
"cell2struct: DIM must be a valid dimension");
1984 const Cell vals =
args(0).cell_value ();
1989 if (ext != fields.
numel ())
1990 error (
"cell2struct: number of FIELDS does not match dimension");
1996 assert (ext == rdv(dim));
1999 rdv(0) = rdv(1-dim);
2004 for (
int i = dim + 1;
i < nd;
i++)
2055 if (
args.length () != 2)
2064 for (
int i = 0;
i < fcell.
numel ();
i++)
2069 error (
"rmfield: structure does not contain field %s", key.c_str ());
static void err_invalid_index_for_assignment(void)
void warning_with_id(const char *id, const char *fmt,...)
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode isstruct
bool is_object(void) const
#define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL)
size_t byte_size(void) const
const Cell & contents(const_iterator p) const
bool is_empty(void) const
scalar structure containing the fields
octave_idx_type nfields(void) const
dim_vector dims(void) const
std::string str(char sep= 'x') const
octave_refcount< octave_idx_type > count
void err_nonbraced_cs_list_assignment(void)
octave_map xmap_value(const char *fmt,...) const
void delete_elements(const idx_vector &i)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
OCTINTERP_API octave_value_list Fcellstr(const octave_value_list &=octave_value_list(), int=0)
void increment_indent_level(void) const
bool fast_elem_insert_self(void *where, builtin_type_t btyp) const
void assign(const std::string &k, const Cell &val)
Cell reshape(const dim_vector &new_dims) const
octave_value fast_elem_extract(octave_idx_type n) const
dim_vector dims(void) const
static const idx_vector colon
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_idx_type length(void) const
const octave_value & contents(const_iterator p) const
octave_scalar_map scalar_map_value(void) const
octave_map map_value(void) const
static bool Vprint_struct_array_contents
bool save_ascii(std::ostream &os)
Cell xcell_value(const char *fmt,...) const
octave_idx_type nfields(void) const
void resize(int n, int fill_value=0)
string_vector map_keys(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
string_vector fieldnames(void) const
#define SET_INTERNAL_VARIABLE(NM)
void indent(std::ostream &os) const
void * get_data(void) const
bool save_ascii(std::ostream &os)
void setfield(const std::string &key, const octave_value &val)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
octave_value to_array(void)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool load_ascii(std::istream &is)
octave_idx_type numel(void) const
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
virtual bool fast_elem_insert_self(void *where, builtin_type_t btyp) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode rmfield
octave_idx_type numel(void) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
void newline(std::ostream &os) const
const_iterator end(void) const
bool is_empty(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Cell cell_value(void) const
void err_indexed_cs_list(void)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
void warn_load(const char *type) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode cell2struct
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
octave_map map_value(void) const
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
static octave_value numeric_conv(const octave_value &val, const std::string &type)
void swap_bytes< 4 >(void *ptr)
static void err_invalid_index_type(const std::string &nm, char t)
bool is_null_value(void) const
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
const_iterator begin(void) const
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_as_global, int precision)
std::string key(const_iterator p) const
bool isfield(const std::string &name) const
bool valid_identifier(const char *s)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_idx_type nfields(void) const
Cell dotref(const octave_value_list &idx, bool auto_add=false)
void error_with_id(const char *id, const char *fmt,...)
nd deftypefn *octave_map m
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool print_name_tag(std::ostream &os, const std::string &name) const
const T * data(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool fast_elem_insert(octave_idx_type n, const octave_scalar_map &rhs)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
const_iterator end(void) const
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
void rmfield(const std::string &key)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
dim_vector redim(int n) const
std::string key(const_iterator p) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode nargin
octave_idx_type length(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
const_iterator begin(void) const
dim_vector dims(void) const
void decrement_indent_level(void) const
void warn_save(const char *type) const
mxArray * as_mxArray(void) const
friend class octave_value
void setfield(const std::string &key, const Cell &val)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave::unwind_protect frame
static int Vstruct_levels_to_print
std::string type_name(void) const
charNDArray max(char d, const charNDArray &m)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_idx_type nfields(void) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode isfield
bool print_name_tag(std::ostream &os, const std::string &name) const
octave_value dotref(const octave_value_list &idx, bool auto_add=false)
std::string type_name(void) const
static octave_value numeric_conv(const octave_value &val, const std::string &type)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
=val(i)}if ode{val(i)}occurs in table i
size_t byte_size(void) const
bool save_binary(std::ostream &os, bool &save_as_floats)
const octave_base_value & get_rep(void) const
bool is_cs_list(void) const
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
void print_with_name(std::ostream &os, const std::string &name) const
octave_idx_type ndims(void) const
Number of dimensions.
Cell index(const octave_value_list &idx, bool resize_ok=false) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
const_iterator seek(const std::string &k) const
mxArray * as_mxArray(void) const
bool is_undefined(void) const
bool load_ascii(std::istream &is)
const octave_hdf5_id octave_H5P_DEFAULT
octave_value_list list_value(void) const
octave_scalar_map checkelem(octave_idx_type n) const
octave_value getfield(const std::string &key) const
octave_idx_type index(const_iterator p) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
bool all_scalars(void) const
octave_fields::const_iterator const_iterator
const_iterator seek(const std::string &k) const
string_vector map_keys(void) const
octave_map map_value(void) const
static void maybe_warn_invalid_field_name(const std::string &key, const char *who)
static const char *const keywords[]
write the output to stdout if nargout is
bool save_binary(std::ostream &os, bool &save_as_floats)
Vector representing the dimensions (size) of an Array.
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
octave_value storable_value(void) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
string_vector fieldnames(void) const
int first_dimensioned_value
void print(std::ostream &os, bool pr_as_read_syntax=false)
bool is_zero_by_zero(void) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
octave_base_value * try_narrowing_conversion(void)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
static bool scalar(const dim_vector &dims)
size_t byte_size(void) const
octave_idx_type numel(void) const