next up previous contents index
Next: MegaWave2 Macros Up: Introduction Previous: What you will find   Contents   Index


The MegaWave2 philosophy: basic principles

The aim of MegaWave2 is to make the coding of signal and image-oriented algorithms easier. An algorithm is implemented as a function (or a set of functions) written in C language; such a function (or set of functions) is called a module.

The programmer does not write a complete program: what a module becomes is the matter of the MegaWave2 compiler. This compiler adds input/output code to generate a run-time command: the module's command. The module can then be called under the shell as Unix commands (and in a compatible mode with the MegaWave1 software). But the MegaWave2 compiler can also add interface to a window-oriented interpreter (XMegaWave2); the module is then included in the interpreter as a new function. The MegaWave2 compiler does even more; see Section 1.9 page [*] for details.

What does a module's source looks like ? you can refer to Section 3 for a first example of a module. In short, the source of a module is a file (its name is the module name followed by the .c extension) which contains pure C instructions. It begins with a header put into comments (/* ... */), so the C compiler ignores it (see Section 4 for a description of the header). But the MegaWave2 preprocessor decodes this header. Informations are defined about the module, so are the author's name, the version number, etc. More important are the informations about the usage, that is, about the input/output objects (or input/output variables) of the module. This usage may say that a given variable (for example a float) is an optional input with default value 1.0, and that another variable (for example an image with gray levels stored as float numbers) is an output.

After the header comes the regular C body, where functions are defined. One function must always be present, it is the main function of the module and it must have the same name as the module. When we refer to input/output objects of the module, we think about the parameters of this main function. Only the main function is global (i.e. can be accessed from other modules), all other functions are local.

In the module's skeleton below, the main function is module and the input/output objects are obj1,obj2,...:

/*------------------ MegaWave2 Module ----------------*/
/* mwcommand
.
. [header, including usage of obj1,obj2,...]
.
*/
/*----------------------------------------------------*/

internal_function(a1,a2,....)
.
. [definition of this function]
.

module(obj1,obj2,....)
{
  .
  .
  internal_function(b1,b2,...);
  .
  .
}

A module can access to the main function of any other module, following these rules:

A module belongs to a group. A group puts together all modules dealing about the same subject. For example, you can imagine a group fourier where all the algorithms about the Fourier transform are put. But you may want to distinguish between Fourier applied on one-dimensional signals and Fourier applied on images. So you can define subgroups of the group fourier, as for example signal and image: you get two groups named fourier/signal and fourier/image.

How are the groups defined ? You define a group by creating a directory corresponding to the name of the group into the existing directory $MEGAWAVE2/src (or $MY_MEGAWAVE2/src). In our former example you must create $MEGAWAVE2/src/fourier/signal and
$MEGAWAVE2/src/fourier/image. The source of the modules (with .c extension) has to be put into those directories. With MegaWave2 versions 1.x, in addition you had to specify in the header of each module the name of the group (see Section 4): group={"fourier/signal"} for all modules in the directory $MEGAWAVE2/src/fourier/signal and group={"fourier/image"} for all modules in the directory $MEGAWAVE2/src/fourier/image. This is no longer required in MegaWave2 versions 2.x.

What is the meaning of the input/output objects ? First, they are variables of C type. All scalar types are allowed, such as char, int, long, float, ... More sophisticated types are available. They are called MegaWave2 memory (or internal) types, and they are always pointers to a structure. The structure defines the object to be processed by the module. For example, the memory type Cimage represents monochrome images with gray levels of (unsigned) Char values. The memory type Curve represents a discrete curve in the plane, etc. See the Volume two ``MegaWave2 System Library'' for a description of all available MegaWave2 memory types.

How do these objects live outside a module ? They are C variables until the process finishes : a module which calls another module just gives the objects as parameters of the function; into the XMegaWave2 interpreter, all commands reside in memory and therefore objects remain C variables until they are removed. When the process finishes (e.g. at the end of a module's command), the output objects have to be saved on disk as a file. The same problem occurs when a process begins: input objects have to be read from files. The format of the file depends on the memory type, we call it the MegaWave2 file (or external) type. Whereas there is only one memory type associated to an object, a memory type may be represented on disk with many different file types. This is because MegaWave2 recognizes several standard file formats, especially for the images. Also see Volume two for a description of all available MegaWave2 file types.


next up previous contents index
Next: MegaWave2 Macros Up: Introduction Previous: What you will find   Contents   Index
mw 2004-05-05