# IBM Visualization Data Explorer Programmer's Reference

[ Bottom of Page | Previous Page | Next Page | Table of Contents | Partial Table of Contents | Index ]

## 5.2 Add2 Module Example--Add Two Data Fields

This module adds together the data components of two input Fields. Thus, one of its functions is to ensure that the hierarchies of the two input Objects match one-to-one.

The Add2 module takes two inputs: `field1` and `field2`. Each is of type `field` and has no default value.

The Add2 module has one output, `result`, of type `field`.

Repeat Steps (1) through (5) of the first example (see 5.1 , "Add Module Example--Add a Number to Every Data Value"), using the file name "add2" instead of "add." Step (5) will produce files `add2.c`, `add2.mdf`, and `add2.make`.

(6) Implement the Add2 function. Use an editor to add the following lines after "User's code goes here," near the end of the `add2.c` file:

       int i;
       /* first check that the lengths of the data buffers match */
       if (field1_knt != field2_knt) {
          DXSetError(ERROR_INVALID_DATA,"data components do not match");
          return 0;
       }
       for (i=0; i < field1_knt; i++)
          result_data[i] = field1_data[i] + field2_data[i];
       return 1;
    }

The file `/usr/share/dx/samples/program_guide/add2.c` contains a completed version of this program.

(7) To create a version of Data Explorer that includes the Add2 module, enter the command:

    make -f add2.make dxexec

(You have now created an executable that contains the Add2 module.)

(8) To invoke this version, enter:

    dx  -mdf ./add2.mdf -exec ./dxexec

This command starts Data Explorer (the `add2.mdf` file tells the graphical user interface about Add2 and its inputs and outputs). The executable dxexec invoked here is the one created in Step 6.

(9) With this version of Data Explorer you can now run any visual program that uses the Add2 module. One such program is `/usr/share/dx/samples/program_guide/add2.net`

[ Top of Page | Previous Page | Next Page | Table of Contents | Partial Table of Contents | Index ]
[Data Explorer Documentation | QuickStart Guide | User's Guide | User's Reference | Programmer's Reference | Installation and Configuration Guide ]

[Data Explorer Home Page]

[IBM Home Page | Order | Search | Contact IBM | Legal ]