27 #if defined (HAVE_CONFIG_H) 55 if (
is.peek () == std::istream::traits_type::eof ())
59 if (::isalpha (
is.peek ()))
62 while (
is && ::isalpha (
is.peek ()))
98 if (ch ==
'.' || ch ==
':')
118 if (ch ==
'.' || ch ==
':')
124 if (!
is || ch !=
'.')
135 if (!
is || !
is.eof ())
144 if (!
is || !
is.eof ())
196 int nargin = args.length ();
198 double empty_value = 0.0;
201 && args(
nargin-2).string_value () ==
"emptyvalue")
203 empty_value = args(
nargin-1).double_value ();
211 std::istream *
input =
nullptr;
212 std::ifstream input_file;
214 if (args(0).is_string ())
223 input_file.open (tname.c_str (), std::ios::in);
226 error (
"dlmread: unable to open file '%s'",
fname.c_str ());
230 else if (args(0).is_scalar_type ())
239 error (
"dlmread: stream FILE not open for input");
242 error (
"dlmread: FILE argument must be a string or file id");
248 if (args(1).is_sq_string ())
251 sep = args(1).string_value ();
264 error (
"dlmread: error parsing RANGE");
268 r0 = args(2).idx_type_value ();
269 c0 = args(3).idx_type_value ();
272 if (r0 < 0 || c0 < 0)
273 error (
"dlmread: left & top must be positive");
276 if (r1 < r0 || c1 < c0)
288 Matrix rdata (rmax, cmax, empty_value);
291 bool iscmplx =
false;
292 bool sep_is_wspace = (sep.find_first_of (
" \t") != std::string::npos);
293 bool auto_sep_is_wspace =
false;
299 while (rcnt > 0 && getline (*
input,
line))
307 std::istringstream tmp_stream;
313 if ((! sep_is_wspace || auto_sep_is_wspace)
314 &&
line.find_first_not_of (
" \t") == std::string::npos)
321 size_t pos1 =
line.find_first_not_of (
" \t");
325 size_t n =
line.find_first_of (
",:; \t", pos1);
326 if (n == std::string::npos)
329 auto_sep_is_wspace =
true;
333 char ch =
line.at (n);
340 auto_sep_is_wspace =
true;
354 if (auto_sep_is_wspace)
355 pos1 =
line.find_first_not_of (
" \t");
361 pos2 =
line.find_first_of (sep, pos1);
363 if (auto_sep_is_wspace && pos2 != std::string::npos)
366 pos2 =
line.find_first_not_of (sep, pos2);
367 if (pos2 != std::string::npos)
372 if (pos2 != std::string::npos)
377 while (pos2 != std::string::npos);
382 cdata.
resize (rmax, cmax, empty_value);
384 rdata.
resize (rmax, cmax, empty_value);
387 r = (r >
i + 1 ? r :
i + 1);
391 if (auto_sep_is_wspace)
392 pos1 =
line.find_first_not_of (
" \t");
400 pos2 =
line.find_first_of (sep, pos1);
403 if (auto_sep_is_wspace && pos2 != std::string::npos)
406 pos2 =
line.find_first_not_of (sep, pos2);
407 if (pos2 != std::string::npos)
410 pos2 =
line.length () - 1;
414 if (pos2 == std::string::npos &&
str.empty ())
417 c = (
c > j + 1 ?
c : j + 1);
418 if (r > rmax ||
c > cmax)
425 cdata.
resize (rmax, cmax, empty_value);
427 rdata.
resize (rmax, cmax, empty_value);
430 tmp_stream.str (
str);
436 if (tmp_stream.eof ())
445 int next_char = std::tolower (tmp_stream.peek ());
446 if (next_char ==
'i' || next_char ==
'j')
461 if (! iscmplx &&
y != 0.)
475 cdata(
i,j++) = empty_value;
477 rdata(
i,j++) = empty_value;
481 while (pos2 != std::string::npos);
497 if ((
i == 0 && j == 0) || (c0 > c1))
500 cdata = cdata.
extract (0, c0, r1, c1);
505 if ((
i == 0 && j == 0) || (c0 > c1))
508 rdata = rdata.
extract (0, c0, r1, c1);
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
double octave_read_double(std::istream &is)
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)
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
std::string string_value(bool force=false) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
OCTINTERP_API void print_usage(void)
static const double idx_max_dbl
bool is_real_matrix(void) const
std::string tilde_expand(const std::string &name)
octave::stream_list & streams
void error(const char *fmt,...)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
stream lookup(int fid, const std::string &who="") const
octave_idx_type numel(const octave_value_list &idx)
static const octave_idx_type idx_max
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical input
Matrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
charNDArray max(char d, const charNDArray &m)
ComplexMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
void resize(octave_idx_type nr, octave_idx_type nc, const Complex &rfv=Complex(0))
subroutine stat(x, n, av, var, xmin, xmax)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
OCTINTERP_API std::string do_string_escapes(const std::string &s)
static bool read_cell_spec(std::istream &is, octave_idx_type &row, octave_idx_type &col)
the element is set to zero In other the statement xample y
bool is_string(void) const
std::complex< double > Complex
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical each element is converted to the corresponding ASCII character A range error results if an input is outside the ASCII range(0-255). For cell arrays
write the output to stdout if nargout is
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
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
charNDArray min(char d, const charNDArray &m)