en fr

Sysquake Pro – Table of Contents

Sysquake – Table of Contents

Sysquake for LaTeX – Table of Contents

Input/Output Functions

bwrite

Store data in an array of bytes.

Syntax

s = bwrite(data)
s = bwrite(data, precision)

Description

bwrite(data) stores the contents of the matrix data into an array of class uint8. The second parameter is the precision, whose meaning is the same as for fread. Its default value is 'uint8'.

Examples

bwrite(12345, 'uint32;l')
  1x4 uint8 array
    57  48   0   0
bwrite(12345, 'uint32;b')
  1x4 uint8 array
     0   0  48  57

See also

swrite, sread, fwrite, sprintf, typecast

clc

Clear the text window or panel.

Syntax

clc
clc(fd)

Description

clc (clear console) clears the contents of the command-line window or panel.

clc(fd) clears the contents of the window or panel associated with file descriptor fd.

disp

Simple display on the standard output.

Syntax

disp(obj)
disp(obj, fd=fd)

Description

disp(obj) displays the object obj. Command format may be used to control how numbers are formatted.

With named argument fd, disp(obj,fd=fd) writes obj to the file descriptor fd.

Example

disp('hello')
hello

See also

format, fprintf

fclose

Close a file.

Syntax

fclose(fd)
fclose('all')

Description

fclose(fd) closes the file descriptor fd which was obtained with functions such as fopen. Then fd should not be used anymore. fclose('all') closes all the open file descriptors.

feof

Check end-of-file status.

Syntax

b = feof(fd)

Description

feof(fd) is false if more data can be read from file descriptor fd, and true if the end of the file has been reached.

Example

Count the number of lines and characters in a file (fopen and fclose are not available in all LME applications):

fd = fopen('data.txt');
lines = 0;
characters = 0;
while ~feof(fd)
  str = fgets(fd);
  lines = lines + 1;
  characters = characters + length(str);
end
fclose(fd);

See also

ftell

fflush

Flush the input and output buffers.

Syntax

fflush(fd)

Description

fflush(fd) discards all the data in the input buffer and forces data out of the output buffer, when the device and their driver permits it. fflush can be useful to recover from errors.

fgetl

Reading of a single line.

Syntax

line = fgetl(fd)
line = fgetl(fd, n)

Description

A single line (of at most n characters) is read from a text file. The end of line character is discarded. Upon end of file, fgetl gives an empty string.

See also

fgets, fscanf

fgets

Reading of a single line.

Syntax

line = fgets(fd)
line = fgets(fd, n)

Description

A single line (of at most n characters) is read from a text file. Unless the end of file is encountered before, the end of line (always a single line feed) is preserved. Upon end of file, fgets gives an empty string.

See also

fgetl, fscanf

fionread

Number of bytes which can be read without blocking.

Syntax

n = fionread(fd)

Description

fionread(fd) returns the number of bytes which can be read without blocking. For a file, all the data until the end of the file can be read; but for a device or a network connection, fionread gives the number of bytes which have already been received and are stored in the read buffer.

If the number of bytes cannot be determined, fionread returns -1.

See also

fread

format

Default output format.

Syntax

format
format short
format short e
format short eng
format short g
format long
format long e
format long eng
format long g
format int
format int d
format int u
format int x
format int o
format int b
format bank
format rat
format '+'
format i
format j
format loose
format compact

Description

format changes the format used by command disp and for output produced with expressions which do not end with a semicolon. The following arguments are recognized:

ArgumentsMeaning
(none)fixed format with 0 or 4 digits, loose spacing
shortfixed format with 0 or 4 digits
short eexponential format with 4 digits
short engengineering format with 4 digits
short ggeneral format with up to 4 digits
longfixed format with 0 or 15 digits
long eexponential format with 15 digits
long engengineering format with 15 digits
long ggeneral format with up to 15 digits
intsigned decimal integer
int dsigned decimal integer
int uunsigned decimal integer
int xhexadecimal integer
int ooctal integer
int bbinary integer
bankfixed format with 2 digits (for currencies)
ratrational approximation
+'+', '-' or 'I' for nonzero, space for zero
isymbol i to represent the imaginary unit
jsymbol j to represent the imaginary unit
looseempty lines to improve readability
compactno empty line

Format for numbers, for imaginary unit symbol and for spacing is set separately. Format rat displays rational approximations like rat with the default tolerance, but also displays the imaginary part if it exists. Format '+' displays compactly numeric and boolean arrays: positive numbers and complex numbers with a positive real part are displayed as +, negative numbers or complex numbers with a negative real part as -, pure imaginary nonzero numbers as I, and zeros as spaces.

The default format is format short g, format j, and format compact.

See also

disp, fprintf, rat

fprintf

Formatted output.

Syntax

n = fprintf(fd,format,a,b,...)
n = fprintf(format,a,b,...)
n = fprintf(..., fd=fd, NPrec=nPrec)

Description

fprintf(format,a,b,...) converts its arguments to a string and writes it to the standard output.

fprintf(fd,format,a,b,...) specifies the output file descriptor. The file descriptor can also be specified as a named argument fd.

In addition to fd, fprintf also accepts named argument NPrec for the default number of digits in floating-point numbers.

See sprintf for a description of the conversion process.

Example

fprintf('%d %.2f %.3E %g\n',1:3,pi)
1 2.00 3.000E0 3.1416
  22

See also

sprintf, fwrite

fread

Raw input.

Syntax

(a, count) = fread(fd)
(a, count) = fread(fd, size)
(a, count) = fread(fd, size, precision)

Description

fread(fd) reads signed bytes from the file descriptor fd until it reaches the end of file. It returns a column vector whose elements are signed bytes (between -128 and 127), and optionally in the second output argument the number of elements it has read.

fread(fd,size) reads the number of bytes specified by size. If size is a scalar, that many bytes are read and result in a column vector. If size is a vector of two elements [m,n], m*n elements are read row by row and stored in an m-by-n matrix. If the end of the file is reached before the specified number of elements have been read, the number of rows is reduced without throwing an error. The optional second output argument always gives the number of elements in the result. If size is the empty array [], elements are read until the end of the file; it must be specified if there is a third argument.

With a third argument, fread(fd,size,precision) reads integer words of 1, 2, or 4 bytes, or IEEE floating-point numbers of 4 bytes (single precision) or 8 bytes (double precision). The meaning of the string precision is described in the table below.

PrecisionMeaning
int8signed 8-bit integer (-128 <= x <= 127)
charsigned 8-bit integer (-128 <= x <= 127)
int16signed 16-bit integer (-32768 <= x <= 32767)
int32signed 32-bit integer (-2147483648 <= x <= 2147483647)
int64signed 64-bit integer (-9.223372e18 <= x <= 9.223372e18)
uint8unsigned 8-bit integer (0 <= x <= 255)
ucharunsigned 8-bit integer (0 <= x <= 255)
uint16unsigned 16-bit integer (0 <= x <= 65535)
uint32unsigned 32-bit integer (0 <= x <= 4294967295)
uint64unsigned 64-bit integer (0 <= x <= 18.446744e18)
single32-bit IEEE floating-point
double64-bit IEEE floating-point

By default, multibyte words are encoded with the least significant byte first (little endian). The characters ';b' can be appended to specify that they are encoded with the most significant byte first (big endian); for symmetry, ';l' is accepted and ignored.

By default, the output is a double array. To get an output which has the same type as what is specified by precision, the character * can be inserted at the beginning. For instance '*uint8' reads bytes and stores them in an array of class uint8, '*int32;b' reads signed 32-bit words and stores them in an array of class int32 after performing byte swapping if necessary, and '*char' reads bytes and stores them in a character row vector (i.e. a plain string).

Precisions 'int64' and 'uint64' are supported only if types int64 and uint64 are supported.

See also

fwrite, sread

frewind

Rewind current read or write position in a file.

Syntax

frewind(fd)

Description

frewind(fd) sets the position in an open file where the next input/output commands will read or write data to the beginning of the file. The argument fd is the file descriptor returned by fopen or similar functions (fopen is not available in all LME applications).

frewind(fd) has the same effect as fseek(fd,0) or fseek(fd,0,'b').

See also

fseek, ftell

fscanf

Reading of formatted numbers.

Syntax

r = fscanf(fd, format)
(r, count) = fscanf(fd, format)

Description

A single line is read from a text file, and numbers, characters and strings are decoded according to the format string. The format string follows the same rules as sscanf.

The optional second output argument is set to the number of elements decoded successfully (may be different than the length of the first argument if decoding strings).

Example

Read a number from a file (fopen and fclose are not available in all LME applications):

fd = fopen('test.txt', 'rt');
fscanf(fd, '%f')
  2.3
fclose(fd);

See also

sscanf

fseek

Change the current read or write position in a file.

Syntax

status = fseek(fd, position)
status = fseek(fd, position, mode)

Description

fseek(fd,position,mode) changes the position in an open file where the next input/output commands will read or write data. The first argument fd is the file descriptor returned by fopen or similar functions (fopen is not available in all LME applications). The second argument is the new position. The third argument mode specifies how the position is used:

ModeDescription
babsolute position from the beginning of the file
crelative position from the current position
eoffset from the end of the file (must be <= 0)

The default value is 'b'. Only the first character is checked, so 'beginning' is a valid alternative for 'b'. fseek returns 0 if successful or -1 if the position is outside the limits of the file contents.

See also

frewind, ftell

ftell

Get the current read or write position in a file.

Syntax

position = ftell(fd)

Description

ftell(fd) gives the current file position associated with file descriptor fd. The file position is the offset (with respect to the beginning of the file) at which the next input function will read or the next output function will write. The offset is expressed in bytes. With text files, ftell may not always correspond to the number of characters read or written.

See also

fseek, feof

fwrite

Raw output.

Syntax

count = fwrite(fd, data)
count = fwrite(fd, data, precision)

Description

fwrite(fd, data) writes the contents of the matrix data to the output referenced by the file descriptor fd. The third parameter is the precision, whose meaning is the same as for fread. Its default value is 'uint8'.

See also

fread, swrite, bwrite

redirect

Redirect or copy standard output or error to another file descriptor.

Syntax

redirect(fd, fdTarget)
redirect(fd, fdTarget, copy)
redirect(fd)
R = redirect(fd)
redirect
R = redirect

Description

redirect(fd,fdTarget) redirects output from file descriptor fd to fdTarget. fd must be 1 for standard output or 2 for standard error. If fdTarget==fd, the normal behavior is restored.

redirect(fd,fdTarget,copy) copies output to both fd and fdTarget if copy is true, instead of redirecting it only to fdTarget. If copy is false, the result is the same as with two input arguments.

With zero or one input argument and without output argument, redirect displays the current redirection for the specified file descriptor (1 or 2) or for both of them. Note that the redirection itself may alter where the result is displayed.

With an output argument, redirect returns a 1-by-2 row vector if the file descriptor is specified, or a 2-by-2 matrix otherwise. The first column contains the target file descriptor and the second column, 1 for copy mode and 0 for pure redirection mode.

Examples

Create a new file diary.txt and copy to it both standard output and error:

fd = fopen('diary.txt', 'w');
redirect(1, fd, true);
redirect(2, fd, true);

Stop copying standard output and error and close file:

redirect(1, 1);
redirect(2, 2);
fclose(fd);

Redirect standard error to standard output and get the redirection state:

redirect(2, 1)
redirect
  stdout (fd=1) -> fd=1
  stderr (fd=2) -> fd=1
redirect(2)
  stderr (fd=2) -> fd=1
R = redirect
  R =
    1 0
    1 0
R = redirect(2)
  R =
    1 0

sprintf

Formatted conversion of objects into a string.

Syntax

s = sprintf(format,a,b, ...)
s = sprintf(..., NPrec=nPrec)

Description

sprintf converts its arguments to a string. The first parameter is the format string. All the characters are copied verbatim to the output string, except for the control sequences which all begin with the character '%'. They have the form

     %fn.dt

where f is zero, one or more of the following flags:

FlagDescription
-left alignment (default is right alignment)
+display of a + sign for positive numbers
0zero padding instead of spaces
#alternate format (see below)
spacesign replaced with space for positive numbers

n is the optional width of the field as one or more decimal digits (default is the minimum width to display the data).

d is the number of digits after the decimal separator for a number displayed with a fractional part (default is 4 or what is specified by named argument NPrec), the minimum number of displayed digits for a number displayed as an integer, or the number of characters for a string (one or more decimal digits).

t is a single character denoting the type of conversion. In most cases, each control sequence corresponds to an additional argument.

All elements of arrays are used sequentially as if they were provided separately; strings are used as a whole. The table below gives the valid values of t.

Char.Conversion
%single %
ddecimal number as an integer
isame as d
xhexadecimal number (for integers between 0 and 2^32-1)
Xsame as x, with uppercase digits
ooctal number (for integers between 0 and 2^32-1)
ffixed number of decimals (exp. notation if abs(x)>1e18)
Fsame as f, with an uppercase E
escientific notation such as 1e5
Escientific notation such as 1E5
nengineering notation such as 100e3
Nengineering notation such as 100E3
gdecimal or scientific notation
Gsame as g, with an uppercase E
ksame as g, with as few characters as possible
Ksame as k, with an uppercase E
PSI prefix (k=1e3, u=1e-6) or engineering notation
ccharacter
sstring

The # flag forces octal numbers to begin with 0, nonzero hexadecimal numbers to begin with 0x, and floating-point numbers to always have a decimal point even if they do not have a fractional part.

Integer formats %d, %i, %o and %x round fractional numbers to the nearest integer.

Instead of decimal digits, the width n and/or the precision d can be replaced with character *; then one or two additional arguments (or elements of an array) are consumed and used as the width or precision.

Examples

Numbers:

sprintf('%d %.2f %.2e %.2E %.2g',pi*ones(1,5))
  3 3.14 3.14e0 3.14E0 3.14

Compact representation with '%k':

sprintf('%.1k ', 0.001, 0.11, 111, 1000)
  1e-3 0.11 111 1e3

Width and precision:

sprintf('*%8.3f*%8.6s*%-8.6s*',pi,'abcdefgh','abcdefgh')
  *   3.142*  abcdef*abcdef  *

Repetition of format string to convert all values:

sprintf('%c_','a':'z')
  a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z_

Width and precision provided as expressions:

sprintf('%*.*f', 15, 7, pi)
      3.1415927

Zero padding for integer format:

sprintf('%.3d,%.3d', 12, 12345)
  012,12345

Default precision:

sprintf('%f %e', pi, pi)
  3.1416 3.1416e0
sprintf('%f %e', pi, pi, NPrec=2)
  3.14 3.14e0

See also

fprintf, sscanf, swrite

sread

Raw input from a string or an array of bytes.

Syntax

(a, count) = sread(str, size, precision)
(a, count) = sread(str, [], precision)
(a, count) = sread(bytes, ...)

Description

sread(str) reads data from string str or array of class uint8 or int8 the same way as fread reads data from a file.

Examples

(data, count) = sread('abc')
  data =
    97
    98
    99
  count =
    3
(data, count) = sread('abcdef',[2,2])
  data =
    97 98
    99 100
  count =
    4
(data, count) = sread('abcd',[inf,3])
  data =
    97 98 99
  count =
    3

See also

swrite, bwrite, fread, typecast

sscanf

Decoding of formatted numbers.

Syntax

r = sscanf(str, format)
(r, count) = scanf(str, format)
(r, count, nchar) = scanf(str, format)

Description

Numbers, characters and strings are extracted from the first argument. Exactly what is extracted is controlled by the second argument, which can contain the following elements:

Substring in formatMeaning
%csingle character
%sstring
%dinteger number in decimal
%xunsigned integer number in hexadecimal
%ounsigned integer number in octal
%iinteger number
%ffloating-point number
%efloating-point number
%gfloating-point number
%%%
other characterexact match

%i recognizes an optional sign followed by a decimal number, an hexadecimal number prefixed with 0x or 0X, a binary number prefixed with 0b or 0B, or an octal number prefixed with 0.

The decoded elements are accumulated in the output argument, either as a column vector if the format string contains %d, %o, %x, %i, %f, %e or %g, or a string if the format string contains only %c, %s or literal values. If a star is inserted after the percent character, the value is decoded and discarded. A width (as one or more decimal characters) can be inserted before s, d, x, o, i, f, e or g; it limits the number of characters to be decoded. In the input string, spaces and tabulators are skipped before decoding %s, %d, %x, %o, %i, %f, %e or %g.

The format string is recycled as many times as necessary to decode the whole input string. The decoding is interrupted if a mismatch occurs.

The optional second output argument is set to the number of elements decoded successfully (may be different than the length of the first argument if decoding strings). The optional third output argument is set to the number of characters which were consumed in the input string.

Examples

sscanf('f(2.3)', 'f(%f)')
  2.3
sscanf('12a34x778', '%d%c')
  12
  97
  34
 120
 778
sscanf('abc def', '%s')
 abcdef
sscanf('abc def', '%c')
 abc def
sscanf('12,34','%*d,%d')
 34
sscanf('0275a0ff', '%2x')
   2
 117
 160
 255

See also

sprintf

swrite

Store data in a string.

Syntax

s = swrite(data)
s = swrite(data, precision)

Description

swrite(data) stores the contents of the matrix data into a string. The second parameter is the precision, whose meaning is the same as for fread. Its default value is 'uint8'.

Examples

swrite(65:68)
  ABCD
double(swrite([1,2], 'int16'))
  1 0 2 0
double(swrite([1,2], 'int16;b'))
  0 1 0 2

See also

bwrite, fwrite, sprintf, sread