23 #if defined (HAVE_CONFIG_H) 45 #if defined (OCTAVE_HAVE_LONG_LONG_INT) 46 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ 49 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 50 if (sizeof (TQ char) == sz) \ 51 VAL = oct_data_conv::dt_ ## Q ## char; \ 52 else if (sizeof (TQ short) == sz) \ 53 VAL = oct_data_conv::dt_ ## Q ## short; \ 54 else if (sizeof (TQ int) == sz) \ 55 VAL = oct_data_conv::dt_ ## Q ## int; \ 56 else if (sizeof (TQ long) == sz) \ 57 VAL = oct_data_conv::dt_ ## Q ## long; \ 58 else if (sizeof (TQ long long) == sz) \ 59 VAL = oct_data_conv::dt_ ## Q ## longlong; \ 61 VAL = oct_data_conv::dt_unknown; \ 65 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \ 68 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 69 if (sizeof (TQ char) == sz) \ 70 VAL = oct_data_conv::dt_ ## Q ## char; \ 71 else if (sizeof (TQ short) == sz) \ 72 VAL = oct_data_conv::dt_ ## Q ## short; \ 73 else if (sizeof (TQ int) == sz) \ 74 VAL = oct_data_conv::dt_ ## Q ## int; \ 75 else if (sizeof (TQ long) == sz) \ 76 VAL = oct_data_conv::dt_ ## Q ## long; \ 78 VAL = oct_data_conv::dt_unknown; \ 83 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \ 86 int sz = BITS / std::numeric_limits<unsigned char>::digits; \ 87 if (sizeof (float) == sz) \ 88 VAL = oct_data_conv::dt_float; \ 89 else if (sizeof (double) == sz) \ 90 VAL = oct_data_conv::dt_double; \ 92 VAL = oct_data_conv::dt_unknown; \ 124 for (
int i = 0;
i < 4;
i++)
139 size_t n =
str.length ();
145 for (
size_t i = 0;
i < n;
i++)
146 if (! isspace (
str[
i]))
147 s[
k++] = tolower (
str[
i]);
154 #define GET_SIZED_INT_TYPE(T, U) \ 157 switch (sizeof (T)) \ 160 retval = dt_ ## U ## int8; \ 164 retval = dt_ ## U ## int16; \ 168 retval = dt_ ## U ## int32; \ 172 retval = dt_ ## U ## int64; \ 176 retval = dt_unknown; \ 194 retval =
sizeof (uint8_t);
198 retval =
sizeof (int16_t);
202 retval =
sizeof (uint16_t);
206 retval =
sizeof (int32_t);
210 retval =
sizeof (uint32_t);
214 retval =
sizeof (int64_t);
218 retval =
sizeof (uint64_t);
235 retval =
sizeof (
signed char);
239 retval =
sizeof (
unsigned char);
247 retval =
sizeof (
unsigned short);
255 retval =
sizeof (
unsigned int);
263 retval =
sizeof (
unsigned long);
267 retval =
sizeof (
long long);
271 retval =
sizeof (
unsigned long long);
280 (*current_liboctave_error_handler)
281 (
"oct_data_conv::data_type_size: unknown data type");
309 else if (
s ==
"double" ||
s ==
"float64" ||
s ==
"real*8")
311 else if (
s ==
"single" ||
s ==
"float" ||
s ==
"float32" ||
s ==
"real*4")
313 else if (
s ==
"char" ||
s ==
"char*1")
317 else if (
s ==
"uchar" ||
s ==
"unsignedchar")
319 else if (
s ==
"schar" ||
s ==
"signedchar")
321 else if (
s ==
"int8" ||
s ==
"integer*1")
323 else if (
s ==
"int16" ||
s ==
"integer*2")
325 else if (
s ==
"uint16")
327 else if (
s ==
"int32" ||
s ==
"integer*4")
329 else if (
s ==
"uint32")
331 else if (
s ==
"int64" ||
s ==
"integer*8")
333 else if (
s ==
"uint64")
335 else if (
s ==
"short")
337 else if (
s ==
"ushort" ||
s ==
"unsignedshort")
339 else if (
s ==
"uint" ||
s ==
"unsignedint")
341 else if (
s ==
"long")
343 else if (
s ==
"ulong" ||
s ==
"unsignedlong")
346 else if (
s ==
"longlong")
348 else if (
s ==
"ulonglong" ||
s ==
"unsignedlonglong")
350 else if (
s ==
"logical")
356 (*current_liboctave_error_handler)
357 (
"unable to find matching native data type for %s",
s.c_str ());
371 bool input_is_output =
false;
378 input_is_output =
true;
381 size_t len =
s.length ();
383 while (pos < len && isdigit (
s[pos]))
390 block_size = atoi (
s.c_str ());
391 s =
s.substr (pos+1);
395 (
"invalid repeat count in '%s'",
str.c_str ());
401 if (pos != std::string::npos)
409 s1 =
s.substr (1, pos-1);
411 (*current_liboctave_warning_with_id_handler)
412 (
"Octave:fread-precision-syntax",
413 "warning: ignoring leading * in fread precision");
416 s1 =
s.substr (0, pos);
423 (
"fread: invalid precision specified");
433 output_type = input_type;
448 size_t len =
s.length ();
450 while (pos < len && isdigit (
s[pos]))
457 block_size = atoi (
s.c_str ());
458 s =
s.substr (pos+1);
462 (
"invalid repeat count in '%s'",
str.c_str ());
532 retval =
"unsigned short";
556 retval =
"unsigned long long";
576 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \ 581 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ 582 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \ 583 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \ 585 swap_bytes< size > (ptr, len); \ 586 for (octave_idx_type i = 0; i < len; i++) \ 595 #define LS_DO_WRITE(TYPE, data, size, len, stream) \ 600 char tmp_type = type; \ 601 stream.write (&tmp_type, 1); \ 602 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \ 603 for (octave_idx_type i = 0; i < len; i++) \ 604 ptr[i] = static_cast<TYPE> (data[i]); \ 605 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \ 606 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \ 613 OCTAVE_NORETURN
static 617 (*current_liboctave_error_handler)
618 (
"unrecognized floating point format requested");
694 (*current_liboctave_error_handler)
695 (
"impossible state reached in file '%s' at line %d",
741 (*current_liboctave_error_handler)
742 (
"impossible state reached in file '%s' at line %d",
764 (*current_liboctave_error_handler)
765 (
"impossible state reached in file '%s' at line %d",
805 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
806 is.read (reinterpret_cast<char *> (ptr), n_bytes);
815 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
816 is.read (reinterpret_cast<char *> (data), n_bytes);
819 for (
int i = 0;
i < len;
i++)
825 is.clear (std::ios::failbit |
is.rdstate ());
863 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
864 is.read (reinterpret_cast<char *> (data), n_bytes);
872 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
873 is.read (reinterpret_cast<char *> (ptr), n_bytes);
881 is.clear (std::ios::failbit |
is.rdstate ());
922 char tmp_type =
static_cast<char> (
type);
924 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
925 os.
write (reinterpret_cast<const char *> (data), n_bytes);
930 (*current_liboctave_error_handler)
931 (
"unrecognized data format requested");
968 char tmp_type =
static_cast<char> (
type);
970 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
971 os.
write (reinterpret_cast<const char *> (data), n_bytes);
980 (*current_liboctave_error_handler)
981 (
"unrecognized data format requested");
static void init_sized_type_lookup_table(oct_data_conv::data_type table[3][4])
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
double __lo_ieee_replace_old_NA(double x)
#define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q)
#define LS_DO_WRITE(TYPE, data, size, len, stream)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
void swap_bytes< 8 >(void *ptr)
static OCTAVE_NORETURN void err_unrecognized_float_fmt(void)
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
#define LS_DO_READ(TYPE, swap, data, size, len, stream)
static void IEEE_little_float_to_IEEE_big_float(void *d, octave_idx_type len)
void read_floats(std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
void do_double_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
static void IEEE_big_double_to_IEEE_little_double(void *d, octave_idx_type len)
void swap_bytes< 4 >(void *ptr)
static void IEEE_big_float_to_IEEE_little_float(void *d, octave_idx_type len)
#define FIND_SIZED_FLOAT_TYPE(VAL, BITS)
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
static std::string data_type_as_string(data_type dt)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void do_float_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
static data_type string_to_data_type(const std::string &s)
write the output to stdout if nargout is
#define GET_SIZED_INT_TYPE(T, U)
static size_t data_type_size(data_type dt)
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
static std::string strip_spaces(const std::string &str)
static void IEEE_little_double_to_IEEE_big_double(void *d, octave_idx_type len)