26 #if defined (HAVE_CONFIG_H)
49 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
50 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
53 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
54 if (sizeof (TQ char) == sz) \
55 VAL = oct_data_conv::dt_ ## Q ## char; \
56 else if (sizeof (TQ short) == sz) \
57 VAL = oct_data_conv::dt_ ## Q ## short; \
58 else if (sizeof (TQ int) == sz) \
59 VAL = oct_data_conv::dt_ ## Q ## int; \
60 else if (sizeof (TQ long) == sz) \
61 VAL = oct_data_conv::dt_ ## Q ## long; \
62 else if (sizeof (TQ long long) == sz) \
63 VAL = oct_data_conv::dt_ ## Q ## longlong; \
65 VAL = oct_data_conv::dt_unknown; \
69 # define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
72 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
73 if (sizeof (TQ char) == sz) \
74 VAL = oct_data_conv::dt_ ## Q ## char; \
75 else if (sizeof (TQ short) == sz) \
76 VAL = oct_data_conv::dt_ ## Q ## short; \
77 else if (sizeof (TQ int) == sz) \
78 VAL = oct_data_conv::dt_ ## Q ## int; \
79 else if (sizeof (TQ long) == sz) \
80 VAL = oct_data_conv::dt_ ## Q ## long; \
82 VAL = oct_data_conv::dt_unknown; \
87 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \
90 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
91 if (sizeof (float) == sz) \
92 VAL = oct_data_conv::dt_float; \
93 else if (sizeof (double) == sz) \
94 VAL = oct_data_conv::dt_double; \
96 VAL = oct_data_conv::dt_unknown; \
128 for (
int i = 0; i < 4; i++)
143 std::size_t
n = str.length ();
147 std::string s (
n,
'\0');
149 for (std::size_t i = 0; i <
n; i++)
150 if (! isspace (str[i]))
151 s[k++] = tolower (str[i]);
158 #define GET_SIZED_INT_TYPE(T, U) \
161 switch (sizeof (T)) \
164 retval = dt_ ## U ## int8; \
168 retval = dt_ ## U ## int16; \
172 retval = dt_ ## U ## int32; \
176 retval = dt_ ## U ## int64; \
180 retval = dt_unknown; \
189 std::size_t retval = -1;
194 retval =
sizeof (int8_t);
198 retval =
sizeof (uint8_t);
202 retval =
sizeof (int16_t);
206 retval =
sizeof (uint16_t);
210 retval =
sizeof (int32_t);
214 retval =
sizeof (uint32_t);
218 retval =
sizeof (int64_t);
222 retval =
sizeof (uint64_t);
227 retval =
sizeof (float);
231 retval =
sizeof (double);
235 retval =
sizeof (char);
239 retval =
sizeof (
signed char);
243 retval =
sizeof (
unsigned char);
247 retval =
sizeof (short);
251 retval =
sizeof (
unsigned short);
255 retval =
sizeof (int);
259 retval =
sizeof (
unsigned int);
263 retval =
sizeof (long);
267 retval =
sizeof (
unsigned long);
271 retval =
sizeof (
long long);
275 retval =
sizeof (
unsigned long long);
279 retval =
sizeof (bool);
284 (*current_liboctave_error_handler)
285 (
"oct_data_conv::data_type_size: unknown data type");
297 static bool initialized =
false;
313 else if (s ==
"double" || s ==
"float64" || s ==
"real*8")
315 else if (s ==
"single" || s ==
"float" || s ==
"float32" || s ==
"real*4")
317 else if (s ==
"char" || s ==
"char*1")
321 else if (s ==
"uchar" || s ==
"unsignedchar")
323 else if (s ==
"schar" || s ==
"signedchar")
325 else if (s ==
"int8" || s ==
"integer*1")
327 else if (s ==
"int16" || s ==
"integer*2")
329 else if (s ==
"uint16")
331 else if (s ==
"int32" || s ==
"integer*4")
333 else if (s ==
"uint32")
335 else if (s ==
"int64" || s ==
"integer*8")
337 else if (s ==
"uint64")
339 else if (s ==
"short")
341 else if (s ==
"ushort" || s ==
"unsignedshort")
343 else if (s ==
"uint" || s ==
"unsignedint")
345 else if (s ==
"long")
347 else if (s ==
"ulong" || s ==
"unsignedlong")
350 else if (s ==
"longlong")
352 else if (s ==
"ulonglong" || s ==
"unsignedlonglong")
354 else if (s ==
"logical")
360 (*current_liboctave_error_handler)
361 (
"unable to find matching native data type for %s", s.c_str ());
375 bool input_is_output =
false;
382 input_is_output =
true;
385 std::size_t
len = s.length ();
387 while (pos <
len && isdigit (s[pos]))
394 block_size = atoi (s.c_str ());
395 s = s.substr (pos+1);
399 (
"invalid repeat count in '%s'", str.c_str ());
405 if (pos != std::string::npos)
413 s1 = s.substr (1, pos-1);
415 (*current_liboctave_warning_with_id_handler)
416 (
"Octave:fread-precision-syntax",
417 "warning: ignoring leading * in fread precision");
420 s1 = s.substr (0, pos);
427 (
"fread: invalid precision specified");
437 output_type = input_type;
452 std::size_t
len = s.length ();
454 while (pos <
len && isdigit (s[pos]))
461 block_size = atoi (s.c_str ());
462 s = s.substr (pos+1);
466 (
"invalid repeat count in '%s'", str.c_str ());
524 retval =
"signed char";
528 retval =
"unsigned char";
536 retval =
"unsigned short";
544 retval =
"unsigned int";
552 retval =
"unsigned long";
556 retval =
"long long";
560 retval =
"unsigned long long";
580 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \
585 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
586 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
587 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
589 swap_bytes< size > (ptr, len); \
590 for (octave_idx_type i = 0; i < len; i++) \
599 #define LS_DO_WRITE(TYPE, data, size, len, stream) \
604 char tmp_type = type; \
605 stream.write (&tmp_type, 1); \
606 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
607 for (octave_idx_type i = 0; i < len; i++) \
608 ptr[i] = static_cast<TYPE> (data[i]); \
609 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
610 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
617 OCTAVE_NORETURN
static
621 (*current_liboctave_error_handler)
622 (
"unrecognized floating point format requested");
698 (*current_liboctave_error_handler)
699 (
"impossible state reached in file '%s' at line %d",
745 (*current_liboctave_error_handler)
746 (
"impossible state reached in file '%s' at line %d",
763 case sizeof (double):
768 (*current_liboctave_error_handler)
769 (
"impossible state reached in file '%s' at line %d",
809 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (
len);
810 is.read (
reinterpret_cast<char *
> (ptr), n_bytes);
819 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (
len);
820 is.read (
reinterpret_cast<char *
> (data), n_bytes);
830 is.clear (std::ios::failbit | is.rdstate ());
868 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (
len);
869 is.read (
reinterpret_cast<char *
> (data), n_bytes);
877 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (
len);
878 is.read (
reinterpret_cast<char *
> (ptr), n_bytes);
886 is.clear (std::ios::failbit | is.rdstate ());
927 char tmp_type =
static_cast<char> (type);
928 os.write (&tmp_type, 1);
929 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (
len);
930 os.write (
reinterpret_cast<const char *
> (data), n_bytes);
935 (*current_liboctave_error_handler)
936 (
"unrecognized data format requested");
973 char tmp_type =
static_cast<char> (type);
974 os.write (&tmp_type, 1);
975 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (
len);
976 os.write (
reinterpret_cast<const char *
> (data), n_bytes);
985 (*current_liboctave_error_handler)
986 (
"unrecognized data format requested");
void swap_bytes< 8 >(void *ptr)
void swap_bytes< 4 >(void *ptr)
static std::size_t data_type_size(data_type dt)
static std::string data_type_as_string(data_type dt)
static data_type string_to_data_type(const std::string &s)
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 void IEEE_big_double_to_IEEE_little_double(void *d, octave_idx_type len)
#define LS_DO_READ(TYPE, swap, data, size, len, stream)
#define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q)
static void init_sized_type_lookup_table(oct_data_conv::data_type table[3][4])
#define GET_SIZED_INT_TYPE(T, U)
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
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)
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
#define LS_DO_WRITE(TYPE, data, size, len, stream)
static void IEEE_little_double_to_IEEE_big_double(void *d, octave_idx_type len)
static void IEEE_big_float_to_IEEE_little_float(void *d, octave_idx_type len)
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)
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)
#define FIND_SIZED_FLOAT_TYPE(VAL, BITS)
static std::string strip_spaces(const std::string &str)
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
@ flt_fmt_ieee_big_endian
@ flt_fmt_ieee_little_endian
#define OCTAVE_LOCAL_BUFFER(T, buf, size)