Sysquake Miscellaneous Functions

cancel

Cancel an operation.

Syntax

cancel
cancel(false)

Description

In a handler, it is often useful to cancel the whole operation. Avoiding changing any variable is not enough, because it would leave a new set of variables which would make the Undo command not behave as expected. The cancel command tells Sysquake to cancel completely the operation, be it a menu handler or the sequence of mousedown, mousedrag and mouseup handlers. cancel throws an error; hence its effect will be caught if it occurs in a try block.

In the middle of a mousedrag operation, it may happen that the mouse cursor in over an invalid region, but the drag should not be canceled. cancel(false) cancels the current execution of the mousedrag or mousedragcont handler, keeping the current value of the output variables.

Example

if ~dialog('Do you really want to make the system unstable?')
  cancel;
end
closedLoopRoot = 2;

See also

try, error

hasfeature

Check if a feature is available.

Syntax

b = hasfeature(str)

Description

hasfeature(str) returns true if Sysquake supports the feature whose name is given is string str, and false otherwise (even if the feature does not exist in any version). Currently, the following feature is supported in some versions of Sysquake:

Feature nameDescription
fileio low-level file i/o (fopen etc.)

efopen

Open a file embedded in the SQ file.

Syntax

fd = efopen(efblockname)
fd = efopen(efblockname, encoding)

Description

efopen(efblockname) gives a file descriptor to read the contents of a block of type embeddedfile in the current SQ file. The file descriptor can be used exactly as if it was obtained with fopen for a real file in text mode, with functions like fgets, fgetl, fscanf, fread, fseek, and feof. Function fclose must be used to release the file descriptor.

efopen(efblockname,encoding) specifies one of two possible encodings for the contents of the block: 'text' for text (default value), or 'base64' for base64. Base64 is used to represent binary data as text. Each character of encoded data represents 6 bits of binary data; i.e. one needs four characters for three bytes. The six bits represent 64 different values, encoded with the characters 'A' to 'Z', 'a' to 'z', '0' to '9', '+', and '/' in this order. When the binary data have a length which is not a multiple of 3, encoded data are padded with one or two characters '=' to have a multiple of 4. The encoded data is usually split in multiple lines of about 60 characters. The decoder ignores characters not used for encoding.

With a base64 encoding, input functions have the same effect as if an nonencoded file had been opened; i.e. the encoded data are decoded on the fly.

Base64 encoding is an Internet standard described in RFC 1521.

Example

To convert a file to base64 in order to embed it in an SQ file, you can use function base64encode as follow:

fd = fopen(getfile);
while ~feof(fd)
  fprintf('%s\n',base64encode(char(fread(fd,45))));
end
fclose(fd);

If the file is too large to let you easily copy the result from the command-line interface to the SQ file, you can store it in an intermediate file:

fd = fopen(getfile('Input'));
out = fopen(putfile('Output'), 'wt');
while ~feof(fd)
  fprintf(out,'%s\n',base64encode(char(fread(fd,45))));
end
fclose(fd);

See also

fopen, fclose, base64encode, base64decode

idlestate

Control the state of idle processing.

Syntax

idlestate(b)
b = idlestate

Description

idlestate(b) enables the periodic execution of the idle handler if b is true, or disables it otherwise.

With an output argument, idlestate gives the current state of idle handler execution.

movezero

Change the position of a real or complex zero in a real-coefficient polynomial.

Syntax

pol2 = movezero(pol1, p0, p1)
(pol2, p1actual) = movezero(pol1, p0, p1)

Description

movezero should be used in the mousedrag handle when the user drags the zero of a polynomial with real coefficients. It insures a consistent user experience.

If p0 is a real or complex zero of the polynomial pol1, movezero computes a new polynomial pol2, with real coefficients, a zero at p1, and most other zeros unchanged. If p0 and p1 are real,

pol2 = conv(deconv(pol1, [1, -p0]), [1, -p1])

If p0 and p1 are complex and their imaginary part has the same sign,

pol2 = conv(deconv(pol1, poly([p0,conj(p0)])), ...
            poly([p1,conj(p1)]))

Otherwise, a real pole p0 is moved to complex pole p1 if imag(p1) > 0 and there is another real pole in pol0. A complex pole p0 can be moved to real(p1) if imag(p1)*imag(p0) < 0; in that case, conj(p0) is moved to real(p0).

If it exists, the second output argument is set to the actual value of the displaced pole. It can be used to provide feedback to the user during the drag.

Examples

roots(movezero(poly([1,3,2+3j,2-3j]),1,5))
  5
  3
  2+3j
  2-3j
roots(movezero(poly([1,3,2+3j,2-3j]),1,2j))
  2j
  -2j
  2+3j
  2-3j
roots(movezero(poly([1,3,2+3j,2-3j]),2+3j,5+8j))
  1
  3
  5+8j
  5-8j
roots(movezero(poly([1,3,2+3j,2-3j]),2+3j,5-8j))
  1
  3
  5
  2
(pol, newPole) = movezero(poly([1,3,2+3j,2-3j]),2+3j,5-8j);
newPole
  5

quit

Quit Sysquake.

Syntax

quit

Description

quit quits Sysquake. It has the same effect as choosing Quit or Exit in the File menu.

textoutputopen

Create a new text window for output.

Syntax

fd = textoutputopen(title)
fd = textoutputopen(title, markup)

Description

Function textoutputopen(title) creates a new text window with whose title is the string title. It returns a file descriptor which can be used with all output functions, such as fprintf. Text output is accumulated into a buffer which is displayed in the window.

With a second input argument, textoutputopen(title,markup) creates a new text window for plain text if markup is false, or text with markup if markup is true. The markup is the same as what is accepted on file descriptor 4.

The text window can be closed with fclose(fd). The contents of the buffer can be reset with clc(fd). Depending on the application and the platform, the

See also

fprintf, fclose, clc

Example

Create a window for text with markup and write some text:

fd = textoutputopen('Example', true);
fprintf(fd, '=Example=\n');
fprintf(fd, 'This is a paragraph.\n\n');
fprintf(fd, 'Here is a list:\n* Alpha\n* Beta\n');

Close window:

fclose(fd);

sqcurrentlanguage

Get current language.

Syntax

(lang, code) = sqcurrentlanguage

Description

sqcurrentlanguage retrieve the current language chosen by the user for the user interface. It returns up to two output arguments: the first one if the language and the second one is the language code, as defined with beginlanguage in the SQ file.


Copyright 1998-2008, Calerga.
All rights reserved.