23 #if defined (HAVE_CONFIG_H)
40 #if defined (OCTAVE_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 ();
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 (
"invalid repeat count in '%s'", str.c_str ());
400 if (pos != std::string::npos)
408 s1 = s.substr (1, pos-1);
410 (*current_liboctave_warning_with_id_handler)
411 (
"Octave:fread-precision-syntax",
412 "warning: ignoring leading * in fread precision");
415 s1 = s.substr (0, pos);
422 (
"fread: invalid precision specified");
432 output_type = input_type;
447 size_t len = s.length ();
449 while (pos < len && isdigit (s[pos]))
456 block_size = atoi (s.c_str ());
457 s = s.substr (pos+1);
461 (
"invalid repeat count in '%s'", str.c_str ());
519 retval =
"signed char";
523 retval =
"unsigned char";
531 retval =
"unsigned short";
539 retval =
"unsigned int";
547 retval =
"unsigned long";
551 retval =
"long long";
555 retval =
"unsigned long long";
575 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \
580 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
581 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
582 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
584 swap_bytes< size > (ptr, len); \
585 for (octave_idx_type i = 0; i < len; i++) \
594 #define LS_DO_WRITE(TYPE, data, size, len, stream) \
599 char tmp_type = type; \
600 stream.write (&tmp_type, 1); \
601 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
602 for (octave_idx_type i = 0; i < len; i++) \
603 ptr[i] = static_cast<TYPE> (data[i]); \
604 std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
605 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
612 OCTAVE_NORETURN
static
616 (*current_liboctave_error_handler)
617 (
"unrecognized floating point format requested");
693 (*current_liboctave_error_handler)
694 (
"impossible state reached in file '%s' at line %d",
740 (*current_liboctave_error_handler)
741 (
"impossible state reached in file '%s' at line %d",
763 (*current_liboctave_error_handler)
764 (
"impossible state reached in file '%s' at line %d",
782 LS_DO_READ (uint16_t, swap, data, 2, len, is);
786 LS_DO_READ (uint32_t, swap, data, 4, len, is);
804 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
805 is.read (reinterpret_cast<char *> (ptr), n_bytes);
814 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
815 is.read (reinterpret_cast<char *> (data), n_bytes);
818 for (
int i = 0;
i < len;
i++)
824 is.clear (std::ios::failbit | is.rdstate ());
841 LS_DO_READ (uint16_t, swap, data, 2, len, is);
845 LS_DO_READ (uint32_t, swap, data, 4, len, is);
862 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
863 is.read (reinterpret_cast<char *> (data), n_bytes);
871 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
872 is.read (reinterpret_cast<char *> (ptr), n_bytes);
880 is.clear (std::ios::failbit | is.rdstate ());
921 char tmp_type =
static_cast<char> (
type);
922 os.write (&tmp_type, 1);
923 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
924 os.write (reinterpret_cast<const char *> (data), n_bytes);
929 (*current_liboctave_error_handler)
930 (
"unrecognized data format requested");
967 char tmp_type =
static_cast<char> (
type);
968 os.write (&tmp_type, 1);
969 std::streamsize n_bytes = 4 *
static_cast<std::streamsize
> (len);
970 os.write (reinterpret_cast<const char *> (data), n_bytes);
979 (*current_liboctave_error_handler)
980 (
"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)
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 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 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)
=val(i)}if ode{val(i)}occurs in table i
issues an error eealso double
#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)