29 #if defined (HAVE_CONFIG_H)
59 if (is.peek () == std::istream::traits_type::eof ())
63 if (::isalpha (is.peek ()))
66 while (is && ::isalpha (is.peek ()))
100 char ch = is.peek ();
102 if (ch ==
'.' || ch ==
':')
122 if (ch ==
'.' || ch ==
':')
128 if (! is || ch !=
'.')
139 if (! is || ! is.eof ())
145 if (
stat && is && ! is.eof ())
148 if (! is || ! is.eof ())
155 error (
"dlmread: NaN is not a valid row or column specifier");
204 int nargin = args.length ();
206 double empty_value = 0.0;
208 if (nargin > 2 && args(nargin-2).is_string ()
209 && args(nargin-2).string_value () ==
"emptyvalue")
211 empty_value = args(nargin-1).double_value ();
216 if (nargin < 1 || nargin > 4)
219 std::istream *
input =
nullptr;
222 if (args(0).is_string ())
225 std::string fname (args(0).string_value ());
231 #if defined (OCTAVE_USE_WINDOWS_API)
233 input_file.open (wname.c_str (), std::ios::in);
235 input_file.open (tname.c_str (), std::ios::in);
239 error (
"dlmread: unable to open file '%s'", fname.c_str ());
243 else if (args(0).is_scalar_type ())
252 error (
"dlmread: stream FILE not open for input");
255 error (
"dlmread: FILE argument must be a string or file id");
261 if (args(1).is_sq_string ())
264 sep = args(1).string_value ();
277 error (
"dlmread: error parsing RANGE");
279 else if (nargin == 4)
281 r0 = args(2).idx_type_value ();
282 c0 = args(3).idx_type_value ();
285 if (r0 < 0 || c0 < 0)
286 error (
"dlmread: left (R0) and top (C0) must be positive");
289 if (r1 < r0 || c1 < c0)
301 Matrix rdata (rmax, cmax, empty_value);
304 bool iscmplx =
false;
305 bool sep_is_wspace = (sep.find_first_of (
" \t") != std::string::npos);
306 bool auto_sep_is_wspace =
false;
312 while (rcnt > 0 && getline (*
input,
line))
320 std::istringstream tmp_stream;
326 if ((! sep_is_wspace || auto_sep_is_wspace)
327 &&
line.find_first_not_of (
" \t") == std::string::npos)
334 size_t pos1 =
line.find_first_not_of (
" \t");
338 size_t n =
line.find_first_of (
",:; \t", pos1);
339 if (
n == std::string::npos)
342 auto_sep_is_wspace =
true;
346 char ch =
line.at (
n);
353 auto_sep_is_wspace =
true;
367 if (auto_sep_is_wspace)
368 pos1 =
line.find_first_not_of (
" \t");
374 pos2 =
line.find_first_of (sep, pos1);
376 if (auto_sep_is_wspace && pos2 != std::string::npos)
379 pos2 =
line.find_first_not_of (sep, pos2);
380 if (pos2 != std::string::npos)
385 if (pos2 != std::string::npos)
390 while (pos2 != std::string::npos);
395 cdata.
resize (rmax, cmax, empty_value);
397 rdata.
resize (rmax, cmax, empty_value);
400 r = (
r > i + 1 ?
r : i + 1);
404 if (auto_sep_is_wspace)
405 pos1 =
line.find_first_not_of (
" \t");
413 pos2 =
line.find_first_of (sep, pos1);
414 std::string str =
line.substr (pos1, pos2 - pos1);
416 if (auto_sep_is_wspace && pos2 != std::string::npos)
419 pos2 =
line.find_first_not_of (sep, pos2);
420 if (pos2 != std::string::npos)
423 pos2 =
line.length () - 1;
427 if (pos2 == std::string::npos && str.empty ())
430 c = (c > j + 1 ? c : j + 1);
431 if (
r > rmax || c > cmax)
438 cdata.
resize (rmax, cmax, empty_value);
440 rdata.
resize (rmax, cmax, empty_value);
443 tmp_stream.str (str);
449 if (tmp_stream.eof ())
458 int next_char = tmp_stream.peek ();
459 if (next_char ==
'i' || next_char ==
'j'
460 || next_char ==
'I' || next_char ==
'J')
464 next_char = tmp_stream.peek ();
465 if (next_char == std::istringstream::traits_type::eof ())
490 if (! iscmplx && y != 0.0)
511 while (pos2 != std::string::npos);
527 if ((i == 0 && j == 0) || (c0 > c1))
530 cdata = cdata.
extract (0, c0, r1, c1);
535 if ((i == 0 && j == 0) || (c0 > c1))
538 rdata = rdata.
extract (0, c0, r1, c1);
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
ComplexMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
void resize(octave_idx_type nr, octave_idx_type nc, const Complex &rfv=Complex(0))
Matrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
bool any_element_is_nan(void) const
stream lookup(int fid, const std::string &who="") const
std::istream * input_stream(void)
octave_idx_type numel(void) const
bool is_string(void) const
std::string string_value(bool force=false) const
NDArray array_value(bool frc_str_conv=false) const
bool is_real_matrix(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
static bool read_cell_spec(std::istream &is, octave_idx_type &row, octave_idx_type &col)
static bool parse_range_spec(const octave_value &range_spec, octave_idx_type &rlo, octave_idx_type &clo, octave_idx_type &rup, octave_idx_type &cup)
static const double idx_max_dbl
static const octave_idx_type idx_max
void error(const char *fmt,...)
F77_RET_T const F77_DBLE * x
double octave_read_double(std::istream &is)
std::string tilde_expand(const std::string &name)
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
std::wstring u8_to_wstring(const std::string &utf8_string)
std::string do_string_escapes(const std::string &s)
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
std::complex< double > Complex
static int input(yyscan_t yyscanner)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
subroutine stat(x, n, av, var, xmin, xmax)