Mercurial > hg > octave-avbm
changeset 4130:7d9bda865012
[project @ 2002-10-28 21:05:30 by jwe]
author | jwe |
---|---|
date | Mon, 28 Oct 2002 21:05:31 +0000 |
parents | d38de1db3667 |
children | 597fbc55ea40 |
files | ChangeLog Makeconf.in liboctave/CMatrix.cc liboctave/ChangeLog liboctave/dMatrix.cc liboctave/lo-utils.cc liboctave/lo-utils.h src/ChangeLog src/load-save.cc src/oct-conf.h.in src/toplev.cc |
diffstat | 11 files changed, 205 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2002-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Makeconf.in (HAVE_DLOPEN_API, HAVE_SHL_LOAD_API, + HAVE_LOADLIBRARY_API): Delete. + (do-subst-config-vals): Don't substitute them here. + 2002-10-25 John W. Eaton <jwe@bevo.che.wisc.edu> * configure.in (ENABLE_DYNAMIC_LINKING): Rename from
--- a/Makeconf.in +++ b/Makeconf.in @@ -50,10 +50,6 @@ DEFAULT_PAGER = @DEFAULT_PAGER@ -HAVE_DLOPEN_API = @HAVE_DLOPEN_API@ -HAVE_SHL_LOAD_API = @HAVE_SHL_LOAD_API@ -HAVE_LOADLIBRARY_API = @HAVE_LOADLIBRARY_API@ - ENABLE_DYNAMIC_LINKING = @ENABLE_DYNAMIC_LINKING@ STATIC_LIBS = @STATIC_LIBS@ @@ -390,9 +386,6 @@ -e "s;%OCTAVE_CONF_FLIBS%;\"${FLIBS}\";" \ -e "s;%OCTAVE_CONF_FPICFLAG%;\"${FPICFLAG}\";" \ -e "s;%OCTAVE_CONF_GLOB_INCFLAGS%;\"${GLOB_INCFLAGS}\";" \ - -e "s;%OCTAVE_CONF_HAVE_DLOPEN_API%;\"${HAVE_DLOPEN_API}\";" \ - -e "s;%OCTAVE_CONF_HAVE_LOADLIBRARY_API%;\"${HAVE_LOADLIBRARY_API}\";" \ - -e "s;%OCTAVE_CONF_HAVE_SHL_LOAD_API%;\"${HAVE_SHL_LOAD_API}\";" \ -e "s;%OCTAVE_CONF_INCFLAGS%;\"${INCFLAGS}\";" \ -e "s;%OCTAVE_CONF_INCLUDE_LINK_DEPS%;\"${INCLUDE_LINK_DEPS}\";"\ -e "s;%OCTAVE_CONF_LD_CXX%;\"${LD_CXX}\";" \
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -2726,11 +2726,13 @@ std::ostream& operator << (std::ostream& os, const ComplexMatrix& a) { -// int field_width = os.precision () + 7; for (int i = 0; i < a.rows (); i++) { for (int j = 0; j < a.cols (); j++) - os << " " /* setw (field_width) */ << a.elem (i, j); + { + os << " "; + octave_write_complex (os, a.elem (i, j)); + } os << "\n"; } return os; @@ -2750,7 +2752,7 @@ for (int i = 0; i < nr; i++) for (int j = 0; j < nc; j++) { - is >> tmp; + tmp = octave_read_complex (is); if (is) a.elem (i, j) = tmp; else
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,16 @@ +2002-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * lo-utils.cc (read_inf_nan_na, octave_read_double, + octave_read_complex, octave_write_double, octave_write_complex): + New functions. + * CMatrix.cc (operator << (std::ostream&, const ComplexMatrix&)): + Use octave_write_complex. + (operator >> (std::istream&, const ComplexMatrix&)): + Use octave_read_complex. + * dMatrix.cc (operator << (std::ostream&, double)): + Use octave_write_double. + (operator >> (std::istream&, double)): Use octave_read_double. + 2002-10-25 John W. Eaton <jwe@bevo.che.wisc.edu> * oct-kpse.c (octave_kpse_clear_dir_cache): Delete.
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -2216,12 +2216,13 @@ std::ostream& operator << (std::ostream& os, const Matrix& a) { -// int field_width = os.precision () + 7; - for (int i = 0; i < a.rows (); i++) { for (int j = 0; j < a.cols (); j++) - os << " " /* setw (field_width) */ << a.elem (i, j); + { + os << " "; + octave_write_double (os, a.elem (i, j)); + } os << "\n"; } return os; @@ -2241,7 +2242,7 @@ for (int i = 0; i < nr; i++) for (int j = 0; j < nc; j++) { - is >> tmp; + tmp = octave_read_double (is); if (is) a.elem (i, j) = tmp; else
--- a/liboctave/lo-utils.cc +++ b/liboctave/lo-utils.cc @@ -39,6 +39,7 @@ #endif #include "lo-error.h" +#include "lo-ieee.h" #include "lo-mappers.h" #include "lo-utils.h" @@ -175,6 +176,142 @@ return retval; } +static inline double +read_inf_nan_na (std::istream& is, char c) +{ + double d = 0.0; + + switch (c) + { + case 'i': case 'I': + { + is >> c; + if (c == 'n' || c == 'N') + { + is >> c; + if (c == 'f' || c == 'F') + d = octave_Inf; + else + is.putback (c); + } + else + is.putback (c); + } + break; + + case 'n': case 'N': + { + is >> c; + if (c == 'a' || c == 'A') + { + is >> c; + if (c == 'n' || c == 'N') + d = octave_NaN; + else + { + is.putback (c); + d = octave_NA; + } + } + else + is.putback (c); + } + break; + + default: + abort (); + } + + return d; +} + +double +octave_read_double (std::istream& is) +{ + double d = 0.0; + + char c = 0; + + is >> c; + switch (c) + { + case 'i': case 'I': + case 'n': case 'N': + d = read_inf_nan_na (is, c); + break; + + default: + is.putback (c); + is >> d; + } + + return d; +} + +Complex +octave_read_complex (std::istream& is) +{ + double re = 0.0, im = 0.0; + + Complex cx = 0.0; + + char ch = 0; + + is >> ch; + + if (ch == '(') + { + re = octave_read_double (is); + is >> ch; + + if (ch == ',') + { + im = octave_read_double (is); + is >> ch; + + if (ch == ')') + cx = Complex (re, im); + else + is.setstate (std::ios::failbit); + } + else if (ch == ')') + cx = re; + else + is.setstate (std::ios::failbit); + } + else + { + is.putback (ch); + cx = octave_read_double (is); + } + + return cx; + +} + +void +octave_write_double (std::ostream& os, double d) +{ + if (lo_ieee_is_NA (d)) + os << "NA"; + else if (lo_ieee_isnan (d)) + os << "NaN"; + else if (lo_ieee_isinf (d)) + os << (d < 0 ? "-Inf" : "Inf"); + else + os << d; +} + +void +octave_write_complex (std::ostream& os, const Complex& c) +{ + os << "("; + octave_write_double (os, real (c)); + os << ","; + octave_write_double (os, imag (c)); + os << ")"; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/liboctave/lo-utils.h +++ b/liboctave/lo-utils.h @@ -25,8 +25,11 @@ #include <cstdio> +#include <iostream> #include <string> +#include "oct-cmplx.h" + extern int NINT (double x); extern double D_NINT (double x); @@ -46,6 +49,12 @@ extern "C" char *oct_strptime (const char *buf, const char *format, struct tm *tm); +extern double octave_read_double (std::istream& is); +extern Complex octave_read_complex (std::istream& is); + +extern void octave_write_double (std::ostream& os, double d); +extern void octave_write_complex (std::ostream& os, const Complex& c); + #endif /*
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2002-10-28 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-conf.h.in (OCTAVE_CONF_HAVE_DLOPEN_API, + OCTAVE_CONF_HAVE_LOADLIBRARY_API, OCTAVE_CONF_HAVE_SHL_LOAD_API): + Delete. + * toplev.cc (octave_config_info): Delete them from the struct + + * load-save.cc (read_ascii_data): Use octave_read_double and + octave_read_complex so that we handle Inf, NaN, and NA. + (read_mat_ascii_data): Likewise. + (save_ascii_data): Use octave_write_double andoctave_write_complex. + 2002-10-25 John W. Eaton <jwe@bevo.che.wisc.edu> * toplev.cc (octave_config_info): Rename WITH_DYNAMIC_LINKING to
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -595,8 +595,7 @@ if (strncmp (ptr, "scalar", 6) == 0) { - double tmp; - is >> tmp; + double tmp = octave_read_double (is); if (is) tc = tmp; else @@ -629,8 +628,7 @@ } else if (strncmp (ptr, "complex scalar", 14) == 0) { - Complex tmp; - is >> tmp; + Complex tmp = octave_read_complex (is); if (is) tc = tmp; else @@ -2032,7 +2030,7 @@ for (int j = 0; j < nc; j++) { - tmp_stream >> d; + d = octave_read_double (tmp_stream); if (tmp_stream) tmp.elem (i, j) = d; @@ -4498,10 +4496,13 @@ { ascii_save_type (os, "range", mark_as_global); Range tmp = tc.range_value (); - os << "# base, limit, increment\n" - << tmp.base () << " " - << tmp.limit () << " " - << tmp.inc () << "\n"; + os << "# base, limit, increment\n"; + octave_write_double (os, tmp.base ()); + os << " "; + octave_write_double (os, tmp.limit ()); + os << " "; + octave_write_double (os, tmp.inc ()); + os << "\n"; } else if (tc.is_real_scalar ()) { @@ -4519,7 +4520,8 @@ else { d = xisinf (d) ? (d > 0 ? OCT_RBV : -OCT_RBV) : d; - os << d << "\n"; + octave_write_double (os, d); + os << "\n"; } } else @@ -4530,7 +4532,8 @@ infnan_warned = true; } - os << d << "\n"; + octave_write_double (os, d); + os << "\n"; } } else if (tc.is_real_matrix ()) @@ -4575,7 +4578,8 @@ c = Complex (re, im); - os << c << "\n"; + octave_write_complex (os, c); + os << "\n"; } } else @@ -4586,7 +4590,8 @@ infnan_warned = true; } - os << c << "\n"; + octave_write_complex (os, c); + os << "\n"; } } else if (tc.is_complex_matrix ())
--- a/src/oct-conf.h.in +++ b/src/oct-conf.h.in @@ -144,18 +144,6 @@ #define OCTAVE_CONF_GLOB_INCFLAGS %OCTAVE_CONF_GLOB_INCFLAGS% #endif -#ifndef OCTAVE_CONF_HAVE_DLOPEN_API -#define OCTAVE_CONF_HAVE_DLOPEN_API %OCTAVE_CONF_HAVE_DLOPEN_API% -#endif - -#ifndef OCTAVE_CONF_HAVE_LOADLIBRARY_API -#define OCTAVE_CONF_HAVE_LOADLIBRARY_API %OCTAVE_CONF_HAVE_LOADLIBRARY_API% -#endif - -#ifndef OCTAVE_CONF_HAVE_SHL_LOAD_API -#define OCTAVE_CONF_HAVE_SHL_LOAD_API %OCTAVE_CONF_HAVE_SHL_LOAD_API% -#endif - #ifndef OCTAVE_CONF_INCFLAGS #define OCTAVE_CONF_INCFLAGS %OCTAVE_CONF_INCFLAGS% #endif
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -679,9 +679,6 @@ m ["FLIBS"] = OCTAVE_CONF_FLIBS; m ["FPICFLAG"] = OCTAVE_CONF_FPICFLAG; m ["GLOB_INCFLAGS"] = OCTAVE_CONF_GLOB_INCFLAGS; - m ["HAVE_DLOPEN_API"] = OCTAVE_CONF_HAVE_DLOPEN_API; - m ["HAVE_LOADLIBRARY_API"] = OCTAVE_CONF_HAVE_LOADLIBRARY_API; - m ["HAVE_SHL_LOAD_API"] = OCTAVE_CONF_HAVE_SHL_LOAD_API; m ["INCFLAGS"] = OCTAVE_CONF_INCFLAGS; m ["LDFLAGS"] = OCTAVE_CONF_LDFLAGS; m ["LD_CXX"] = OCTAVE_CONF_LD_CXX;