IBM Visualization Data Explorer Programmer's Reference

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


5.3 Add2Invalid Module Example--Manipulate Invalid Data

The Data Explorer data model makes it possible to identify invalid input (position and connections elements) and mark the resulting output as "invalid." (see 14.3 , "Invalid Data"). Invalid elements (and the data associated with them) are ignored by Data Explorer modules.

In the example given here, the Add2Invalid module processes two input data components. If either of the two data values is invalid, the resulting sum is treated as invalid. The routines that support this function check for matching data types, matching dependencies, missing Fields, and so on.

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 "add2invalid" instead of "add." Step (5) will produce files add2invalid.c, add2invalid.mdf, and add2invalid.make.

(6) Implement the Add2Invalid function. (Ref #1.) Because this module uses routines for handling invalid data, the necessary modifications of the .c file are more extensive than those required for the preceding examples.

As written, the add2_invalid.c file passes only the data component to the lowest-level routine (Add2Invalid_worker); it does not pass information about the data's validity. The solution is to modify the doLeaf routine, rather than the worker routine. The doLeaf routine has access to all the components of an input or output Field and not to just the data component.

In the routine doLeaf, starting at the comment "Call the user's routine. Check the return code." insert the following:

  /* create invalid component handles for each input field */
  inv_handle1 = DXCreateInvalidComponentHandle(in[0], NULL,
                                               src_dependency);
  inv_handle2 = DXCreateInvalidComponentHandle(in[1], NULL,
                                               src_dependency);
  /* the loop that actually adds the data components.
   * if either of the two input data values is invalid, then the
   * output is marked invalid, and set to the value 0
   */
  out_ptr = (float *)out_data[0];
  in1_ptr = (float *)in_data[0];
  in2_ptr = (float *)in_data[1];
  for (i=0; i<out_knt[0]; i++) {
    if (DXIsElementValid(inv_handle1, i) &&
        DXIsElementValid(inv_handle2, i)) {
      *out_ptr =  *in1_ptr + *in2_ptr;
    }
    else {
      *out_ptr = 0.0;
      DXSetElementInvalid(inv_handle1, i);
    }
    out_ptr++;
    in1_ptr++;
    in2_ptr++;
  }
  /* the invalid-component-handle information is added to the output field */
  if (!DXSaveInvalidComponent((Field)out[0], inv_handle1))
     goto error;
  DXFreeInvalidComponentHandle(inv_handle1);
  DXFreeInvalidComponentHandle(inv_handle2);
  return OK;
error:
  return ERROR;

(7) Remove the call to Add2Invalid_worker: it is not needed. All of the data processing code has been added to doLeaf.

(8) Insert the following declarations at the top of the routine doLeaf:

  InvalidComponentHandle inv_handle1, inv_handle2;
  float *out_ptr, *in1_ptr, *in2_ptr;

The file /usr/lpp/dx/samples/program_guide/add2invalid.c contains a completed version of this program.

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

make -f add2invalid.make dxexec

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

(10) To invoke this version, enter:

dx  -mdf ./add2invalid.mdf -exec ./dxexec

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

(11) With this version of Data Explorer you can now run any visual program that uses the Add2Invalid module. One such program is /usr/lpp/dx/samples/program_guide/add2_invalid.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 ]