40 #if defined HAVE_LONG_LONG_INT
41 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
44 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
45 if (sizeof (TQ char) == sz) \
46 VAL = oct_data_conv::dt_ ## Q ## char; \
47 else if (sizeof (TQ short) == sz) \
48 VAL = oct_data_conv::dt_ ## Q ## short; \
49 else if (sizeof (TQ int) == sz) \
50 VAL = oct_data_conv::dt_ ## Q ## int; \
51 else if (sizeof (TQ long) == sz) \
52 VAL = oct_data_conv::dt_ ## Q ## long; \
53 else if (sizeof (TQ long long) == sz) \
54 VAL = oct_data_conv::dt_ ## Q ## longlong; \
56 VAL = oct_data_conv::dt_unknown; \
60 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
63 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
64 if (sizeof (TQ char) == sz) \
65 VAL = oct_data_conv::dt_ ## Q ## char; \
66 else if (sizeof (TQ short) == sz) \
67 VAL = oct_data_conv::dt_ ## Q ## short; \
68 else if (sizeof (TQ int) == sz) \
69 VAL = oct_data_conv::dt_ ## Q ## int; \
70 else if (sizeof (TQ long) == sz) \
71 VAL = oct_data_conv::dt_ ## Q ## long; \
73 VAL = oct_data_conv::dt_unknown; \
78 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \
81 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
82 if (sizeof (float) == sz) \
83 VAL = oct_data_conv::dt_float; \
84 else if (sizeof (double) == sz) \
85 VAL = oct_data_conv::dt_double; \
87 VAL = oct_data_conv::dt_unknown; \
119 for (
int i = 0; i < 4; i++)
134 size_t n = str.length ();
138 std::string s (n,
' ');
140 for (
size_t i = 0; i < n; i++)
141 if (! isspace (str[i]))
142 s[k++] = tolower (str[i]);
149 #define GET_SIZED_INT_TYPE(T, U) \
152 switch (sizeof (T)) \
155 retval = dt_ ## U ## int8; \
159 retval = dt_ ## U ## int16; \
163 retval = dt_ ## U ## int32; \
167 retval = dt_ ## U ## int64; \
171 retval = dt_unknown; \
185 retval =
sizeof (int8_t);
189 retval =
sizeof (uint8_t);
193 retval =
sizeof (int16_t);
197 retval =
sizeof (uint16_t);
201 retval =
sizeof (int32_t);
205 retval =
sizeof (uint32_t);
209 retval =
sizeof (int64_t);
213 retval =
sizeof (uint64_t);
218 retval =
sizeof (
float);
226 retval =
sizeof (
char);
230 retval =
sizeof (
signed char);
234 retval =
sizeof (
unsigned char);
238 retval =
sizeof (short);
242 retval =
sizeof (
unsigned short);
246 retval =
sizeof (
int);
250 retval =
sizeof (
unsigned int);
254 retval =
sizeof (long);
258 retval =
sizeof (
unsigned long);
262 retval =
sizeof (
long long);
266 retval =
sizeof (
unsigned long long);
270 retval =
sizeof (
bool);
287 static bool initialized =
false;
300 if (s ==
"int8" || s ==
"integer*1")
302 else if (s ==
"uint8")
304 else if (s ==
"int16" || s ==
"integer*2")
306 else if (s ==
"uint16")
308 else if (s ==
"int32" || s ==
"integer*4")
310 else if (s ==
"uint32")
312 else if (s ==
"int64" || s ==
"integer*8")
314 else if (s ==
"uint64")
316 else if (s ==
"single" || s ==
"float32" || s ==
"real*4")
318 else if (s ==
"double" || s ==
"float64" || s ==
"real*8")
320 else if (s ==
"char" || s ==
"char*1")
322 else if (s ==
"schar" || s ==
"signedchar")
324 else if (s ==
"uchar" || s ==
"unsignedchar")
326 else if (s ==
"short")
328 else if (s ==
"ushort" || s ==
"unsignedshort")
332 else if (s ==
"uint" || s ==
"unsignedint")
334 else if (s ==
"long")
336 else if (s ==
"ulong" || s ==
"unsignedlong")
338 else if (s ==
"longlong")
340 else if (s ==
"ulonglong" || s ==
"unsignedlonglong")
342 else if (s ==
"float")
344 if (
sizeof (
float) ==
sizeof (
double))
349 else if (s ==
"logical")
355 (*current_liboctave_error_handler)
356 (
"unable to find matching native data type for %s", s.c_str ());
370 bool input_is_output =
false;
377 input_is_output =
true;
380 size_t len = s.length ();
382 while (pos < len && isdigit (s[pos]))
389 block_size = atoi (s.c_str ());
390 s = s.substr (pos+1);
394 (*current_liboctave_error_handler)
395 (
"invalid repeat count in '%s'", str.c_str ());
404 if (pos != std::string::npos)
412 s1 = s.substr (1, pos-1);
414 (*current_liboctave_warning_with_id_handler)
415 (
"Octave:fread-precision-syntax",
416 "warning: ignoring leading * in fread precision");
419 s1 = s.substr (0, pos);
426 (
"fread: invalid precision specified");
436 output_type = input_type;
451 size_t len = s.length ();
453 while (pos < len && isdigit (s[pos]))
460 block_size = atoi (s.c_str ());
461 s = s.substr (pos+1);
465 (*current_liboctave_error_handler)
466 (
"invalid repeat count in '%s'", str.c_str ());
527 retval =
"signed char";
531 retval =
"unsigned char";
539 retval =
"unsigned short";
547 retval =
"unsigned int";
555 retval =
"unsigned long";
559 retval =
"long long";
563 retval =
"unsigned long long";
583 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \
588 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
589 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
590 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
592 swap_bytes< size > (ptr, len); \
593 for (octave_idx_type i = 0; i < len; i++) \
602 #define LS_DO_WRITE(TYPE, data, size, len, stream) \
607 char tmp_type = type; \
608 stream.write (&tmp_type, 1); \
609 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
610 for (octave_idx_type i = 0; i < len; i++) \
611 ptr[i] = static_cast<TYPE> (data[i]); \
612 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
613 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
623 (*current_liboctave_error_handler)
624 (
"unrecognized floating point format requested");
700 (*current_liboctave_error_handler)
701 (
"impossible state reached in file '%s' at line %d",
747 (*current_liboctave_error_handler)
748 (
"impossible state reached in file '%s' at line %d",
770 (*current_liboctave_error_handler)
771 (
"impossible state reached in file '%s' at line %d",
789 LS_DO_READ (uint16_t, swap, data, 2, len, is);
793 LS_DO_READ (uint32_t, swap, data, 4, len, is);
811 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
812 is.read (reinterpret_cast<char *> (ptr), n_bytes);
821 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
822 is.read (reinterpret_cast<char *> (data), n_bytes);
825 for (
int i = 0; i < len; i++)
831 is.clear (std::ios::failbit|is.rdstate ());
848 LS_DO_READ (uint16_t, swap, data, 2, len, is);
852 LS_DO_READ (uint32_t, swap, data, 4, len, is);
869 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
870 is.read (reinterpret_cast<char *> (data), n_bytes);
878 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
879 is.read (reinterpret_cast<char *> (ptr), n_bytes);
887 is.clear (std::ios::failbit|is.rdstate ());
928 char tmp_type =
static_cast<char> (
type);
929 os.write (&tmp_type, 1);
930 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
931 os.write (reinterpret_cast <const char *> (data), n_bytes);
936 (*current_liboctave_error_handler)
937 (
"unrecognized data format requested");
974 char tmp_type =
static_cast<char> (
type);
975 os.write (&tmp_type, 1);
976 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
977 os.write (reinterpret_cast <const char *> (data), n_bytes);
986 (*current_liboctave_error_handler)
987 (
"unrecognized data format requested");
static void init_sized_type_lookup_table(oct_data_conv::data_type table[3][4])
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
void do_float_format_conversion(void *data, octave_idx_type len, oct_mach_info::float_format from_fmt, oct_mach_info::float_format to_fmt)
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)
void swap_bytes< 8 >(void *ptr)
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 do_double_format_conversion(void *data, octave_idx_type len, oct_mach_info::float_format from_fmt, oct_mach_info::float_format to_fmt)
F77_RET_T const double const double double * d
static void IEEE_big_double_to_IEEE_little_double(void *d, octave_idx_type len)
liboctave_error_handler current_liboctave_error_handler
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)
static void gripe_unrecognized_float_fmt(void)
static std::string data_type_as_string(data_type dt)
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, oct_mach_info::float_format fmt)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
static data_type string_to_data_type(const std::string &s)
#define GET_SIZED_INT_TYPE(T, U)
static size_t data_type_size(data_type dt)
static std::string strip_spaces(const std::string &str)
void read_floats(std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, oct_mach_info::float_format fmt)
static void IEEE_little_double_to_IEEE_big_double(void *d, octave_idx_type len)