Octawrap
A octave wrapper





Why Octawrap

Sometime ago I wanted to run some matlab scripts in octave. Most of them were defining an user interface, making wide use of commands like uicontrol and uimenu, not available in Octave.

After some research I found tk-octave, but though this tool allows similar graphic interfaces, the language is far away from the one of matlab. What I wanted was a tool able to translate the matlab language to the tk language of wish.

Finally I came out with this project, wich is currently about to reach its first beta. The idea is to have an upper layer that runs over its control wish and octave and gives an interface to the user. The user commands will be passed directly to octave or translated to tk and passed to wish, according to the meaning of the command.

In order to accomplish this, Octawrap performs a very simple parsing of the commands, just looking for some patterns in the instruction for identify wich kind of instruction it is.

Current Status

Currently Octawrap is able to display only labels and buttons, but being this two widgets the most widely used in programs, it would be able to run some simple scripts if required. Octawrap is also able to assign a callback to the buttons and potentially to any widget, just uploading the callback code into wish, programming wish to return this code on event, and launching a thread that will parse it and run it, just as if it were another user input


Octawrap has currently no direct support for running scripts, nor from the outside (putting #!/bin/octawrap in the header) nor from the inside (loading the script from the command line). The second one is planned to be available soon, as soon as the emulation of the widgets is complete. The first one probably will not be done, at least not shortly, due that this program is intended for creating user interfaces, and this kind of behaviour is more likely to be used in the second way.

Future plans

Currently I am putting all my effort in making a working widgets collection at least usable. When this is done, I will release the first beta version. I want to have compatibility at least for all the unix-like systems. Therefore the first weeks I expect to be working in portings and compability issues.

The support for the scripts will be the next step, and I plan to introduce it for the version 1.2. I will not add it until having a complete working 1.0 version. Other issues could be support for connect to wish and octave through a network and to use wish also for plotting, deflecting to wish also the calls to the plot command. In this way, octave will never receive this kind of commands and octawrap will have to take care of the plotting procedure, and probably this will involve to have a cache with the variables to plot. The advantages of this improvement will be to have interactive plotings, like those of matlab, in wich we can know where the mouse is.

Its internals

This intends to be an introduction for reading the code, in case you are interested in modify it for your own purposes. This description will deal with the first alpha version, in which the idea is much more clear than in the others. It is also available at sourceforge.

The basic behaviour of this version (and all the following) is to fork to a process that will execute octave, and, on request, to do the same with wish, launching a new wish for every "figure" request. The communication from the user to octave/wish is achieved using pipes. The main program creates two pipes for speaking to and from Octave (and redirects the standard input and output of Octave in such a way that it will notice nothing), and it keeps at the same time the two handlers for its standards input and output.

Two additional threads (in fact, processes) are launch with the purpose of copying the user input on the octave input, and the octave output to the console. This functions cannot be made directly because is required to do a parsing for detecting the commands that are directed to wish.

The command figure allow us to launch wish instances (and therefore the figure command embedded in octave, that calls gnuplot, will never be used). For every instance of wish that we launch we will do the same process (we will launch two threads, one for copying user commands to this wish and other for do the same backwards)

The rest of the code are only technical details, like editing routines, or the functions that parse the matlab commands and translate them onto wish commands. I think that the only difficult part is the one here stated about the different spawned processes.

Finally, if you do any customization that you think can be usefull for others, do not forget to make it publicy available!!! Octawrap is under BSD license and this allows you to release your modifications under the license you want, even a commercial one.


you can download the last version from here

enjoy it!

Juan Garcia de Arboleya.






SourceForge.net Logo