64 template <
class T,
bool is_
signed = true,
bool can_be_too_big = true>
132 if (this->matrix.nelem () == 1)
155 typename T::element_type tmp = this->matrix(i);
157 typedef typename T::element_type::val_type val_type;
159 val_type ival = tmp.value ();
161 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
162 static const bool can_be_larger_than_uchar_max
166 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
174 ::warning (
"range error for conversion to character value");
179 chm (i) =
static_cast<char> (ival);
193 os <<
"# ndims: " << d.
length () <<
"\n";
195 for (
int i = 0; i < d.
length (); i++)
198 os <<
"\n" << this->matrix;
217 for (
int i = 0; i < mdims; i++)
226 error (
"load: failed to load matrix constant");
234 error (
"load: failed to extract number of rows and columns");
239 error (
"load: failed to extract number of dimensions");
253 int32_t tmp = - d.
length ();
254 os.write (reinterpret_cast<char *> (&tmp), 4);
255 for (
int i=0; i < d.
length (); i++)
258 os.write (reinterpret_cast<char *> (&tmp), 4);
261 os.write (reinterpret_cast<const char *> (this->matrix.data ()),
273 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
285 for (
int i = 0; i < mdims; i++)
287 if (! is.read (reinterpret_cast<char *> (&di), 4))
308 if (! is.read (reinterpret_cast<char *> (m.fortran_vec ()), m.byte_size ()))
313 int nel = dv.
numel ();
314 int bytes = nel / m.byte_size ();
315 for (
int i = 0; i < nel; i++)
343 #if defined (HAVE_HDF5)
345 hid_t save_type_hid = HDF5_SAVE_TYPE;
352 hid_t space_hid, data_hid;
353 space_hid = data_hid = -1;
357 for (
int i = 0; i < rank; i++)
358 hdims[i] = dv (rank-i-1);
360 space_hid = H5Screate_simple (rank, hdims, 0);
362 if (space_hid < 0)
return false;
364 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
365 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
367 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
372 H5Sclose (space_hid);
376 retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
377 H5P_DEFAULT, this->matrix.data ()) >= 0;
380 H5Sclose (space_hid);
383 this->gripe_save (
"hdf5");
395 #if defined (HAVE_HDF5)
397 hid_t save_type_hid = HDF5_SAVE_TYPE;
401 this->matrix.resize (dv);
406 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT);
408 hid_t data_hid = H5Dopen (loc_id, name);
410 hid_t space_id = H5Dget_space (data_hid);
412 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
424 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
436 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--)
441 if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
442 H5P_DEFAULT, m.fortran_vec ()) >= 0)
452 this->gripe_load (
"hdf5");
461 bool pr_as_read_syntax)
const
464 this->current_print_indent_level ());
475 typedef typename T::val_type val_type;
477 val_type ival = tmp.value ();
479 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
480 static const bool can_be_larger_than_uchar_max
484 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
490 ::warning (
"range error for conversion to character value");
493 retval =
octave_value (std::string (1, static_cast<char> (ival)), type);
502 os << this->
scalar <<
"\n";
513 error (
"load: failed to load scalar constant");
523 os.write (reinterpret_cast<char *> (&(this->
scalar)), this->byte_size ());
533 if (! is.read (reinterpret_cast<char *> (&tmp), this->byte_size ()))
537 switch (this->byte_size ())
562 #if defined (HAVE_HDF5)
564 hid_t save_type_hid = HDF5_SAVE_TYPE;
566 hid_t space_hid, data_hid;
567 space_hid = data_hid = -1;
569 space_hid = H5Screate_simple (0, dimens, 0);
570 if (space_hid < 0)
return false;
573 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
574 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
576 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
581 H5Sclose (space_hid);
585 retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
586 H5P_DEFAULT, &(this->
scalar)) >= 0;
589 H5Sclose (space_hid);
592 this->gripe_save (
"hdf5");
602 #if defined (HAVE_HDF5)
604 hid_t save_type_hid = HDF5_SAVE_TYPE;
606 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT);
608 hid_t data_hid = H5Dopen (loc_id, name);
610 hid_t space_id = H5Dget_space (data_hid);
612 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
621 if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
622 H5P_DEFAULT, &tmp) < 0)
635 this->gripe_load (
"hdf5");
static bool char_value_out_of_range(T)
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool save_binary(std::ostream &os, bool &)
void resize(int n, int fill_value=0)
void swap_bytes< 8 >(void *ptr)
bool load_ascii(std::istream &is)
void error(const char *fmt,...)
void swap_bytes< 2 >(void *ptr)
static bool char_value_out_of_range(T val)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
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)
bool save_binary(std::ostream &os, bool &)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
void swap_bytes< 4 >(void *ptr)
octave_base_value * try_narrowing_conversion(void)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool)
bool load_binary(std::istream &is, bool swap, oct_mach_info::float_format)
octave_value convert_to_str_internal(bool, bool, char type) const
bool load_ascii(std::istream &is)
bool load_binary(std::istream &is, bool swap, oct_mach_info::float_format)
static bool char_value_out_of_range(T val)
static const bool can_be_larger_than_uchar_max
void warning(const char *fmt,...)
charNDArray max(char d, const charNDArray &m)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_value convert_to_str_internal(bool, bool, char type) const
void octave_print_internal(std::ostream &, char, bool)
bool save_ascii(std::ostream &os)
int save_hdf5_empty(hid_t loc_id, const char *name, const dim_vector d)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
bool save_ascii(std::ostream &os)
static bool char_value_out_of_range(T val)
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static bool scalar(const dim_vector &dims)