1#!F-adobe-helvetica-medium-r-normal--18* 2#!N 3#!CNavyBlue #!N 4 #!Radd2i Add2Invalid Module Example--Manipulate Invalid Data #!N #!EC #!N #!N The 5Data Explorer data model makes it possible to identify invalid input 6(position and connections elements) and mark the resulting output as "invalid." 7(see #!Linvdata,dxall1118 h Invalid Data #!EL ). Invalid elements (and the data associated with them) 8are ignored by Data Explorer modules. #!N #!N In the example 9given here, the Add2Invalid module processes two input data components. If 10either of the two data values is invalid, the resulting sum 11is treated as invalid. The routines that support this function check 12for matching data types, matching dependencies, missing Fields, and so on. 13#!N #!N #!F-adobe-times-bold-r-normal--18* REPEAT STEPS (1) THROUGH (5) #!EF of the 14first example (see #!Laddmodx,dxall1028 h Add Module Example--Add a __________________________________ Number to Every Data Value #!EL ), using the file name "add2invalid" instead 15of "add." Step (5) will produce files add2invalid.c, add2invalid.mdf, and add2invalid.make. 16#!N #!N #!F-adobe-times-bold-r-normal--18* (6) IMPLEMENT THE ADD2INVALID FUNCTION. #!EF #!Rimpad2i Because 17this module uses routines _______________________________________________ for handling invalid data, the necessary 18modifications of the #!F-adobe-times-bold-r-normal--18* .c #!EF file are more extensive than 19those required for the preceding examples. #!N #!N As written, the 20add2_invalid.c file passes only the data component to the lowest-level routine 21(Add2Invalid_worker); it does not pass information about the data's validity. The 22solution is to modify the doLeaf routine, rather than the worker 23routine. The doLeaf routine has access to all the components of 24an input or output Field and not to just the data 25component. #!N #!N In the routine doLeaf, starting at the comment 26"Call the user's routine. Check the return code." insert the following: 27#!CForestGreen #!N #!N #!F-adobe-courier-bold-r-normal--18* #!N /* create invalid component handles for 28each input field */ #!N inv_handle1 = DXCreateInvalidComponentHandle(in[0], NULL, #!N src_dependency); 29#!N inv_handle2 = DXCreateInvalidComponentHandle(in[1], NULL, #!N src_dependency); #!N #!N /* the 30loop that actually adds the data components. #!N * if either 31of the two input data values is invalid, then the #!N 32* output is marked invalid, and set to the value 0 33#!N */ #!N out_ptr = (float *)out_data[0]; #!N in1_ptr = (float 34*)in_data[0]; #!N in2_ptr = (float *)in_data[1]; #!N for (i=0; i<out_knt[0]; i++) 35{ #!N if (DXIsElementValid(inv_handle1, i) && #!N DXIsElementValid(inv_handle2, i)) { #!N 36*out_ptr = *in1_ptr + *in2_ptr; #!N } #!N else { #!N 37*out_ptr = 0.0; #!N DXSetElementInvalid(inv_handle1, i); #!N } #!N out_ptr++; #!N 38in1_ptr++; #!N in2_ptr++; #!N } #!N #!N /* the invalid-component-handle information 39is added to the output field */ #!N if (!DXSaveInvalidComponent((Field)out[0], inv_handle1)) 40#!N goto error; #!N DXFreeInvalidComponentHandle(inv_handle1); #!N DXFreeInvalidComponentHandle(inv_handle2); #!N #!N return OK; 41#!N #!N error: #!N return ERROR; #!EF #!N #!N #!EC #!N 42#!N #!F-adobe-times-bold-r-normal--18* (7) REMOVE THE CALL TO ADD2INVALID_WORKER: #!EF it is 43not needed. All of the data processing code has been added 44________________________________________________ to doLeaf. #!N #!N #!F-adobe-times-bold-r-normal--18* (8) INSERT THE FOLLOWING DECLARATIONS 45#!EF at the top of the routine doLeaf: ___________________________________________ #!CForestGreen #!N 46#!N #!F-adobe-courier-bold-r-normal--18* #!N InvalidComponentHandle inv_handle1, inv_handle2; #!N float *out_ptr, *in1_ptr, *in2_ptr; 47#!EF #!N #!N #!EC #!N #!N The file /usr/local/dx/samples/program_guide/add2invalid.c contains a 48completed version of this program. #!N #!N #!F-adobe-times-bold-r-normal--18* (9) TO CREATE 49A VERSION OF DATA EXPLORER THAT INCLUDES #!EF the Add2Invalid module, 50enter the command: ____________________________________________________________ #!CForestGreen #!N #!N #!F-adobe-courier-bold-r-normal--18* #!N make -f 51add2invalid.make dxexec #!EF #!N #!N #!EC #!N #!N (You have now 52created an executable that contains the Add2Invalid module.) #!N #!N #!F-adobe-times-bold-r-normal--18* 53(10) TO INVOKE THIS VERSION, ENTER: #!EF __________________________________________ #!CForestGreen #!N #!N 54 #!F-adobe-courier-bold-r-normal--18* #!N dx -edit -mdf ./add2invalid.mdf -exec ./dxexec #!EF #!N #!N 55#!EC #!N #!N This command starts Data Explorer (the #!F-adobe-times-bold-r-normal--18* add2invalid.mdf 56#!EF file tells the graphical user interface about Add2Invalid and its 57inputs and outputs). The executable dxexec invoked here is the one 58created in Step 8. #!N #!N #!F-adobe-times-bold-r-normal--18* (11) WITH THIS VERSION 59OF DATA EXPLORER #!EF you can now run any visual program 60that uses the Add2Invalid module. _____________________________________________ One such program is /usr/local/dx/samples/program_guide/add2_invalid.net 61#!N #!N #!N #!F-adobe-times-medium-i-normal--18* Next Topic #!EF #!N #!N #!Lposit,dxall1031 h Working with Positions #!EL #!N 62 #!F-adobe-times-medium-i-normal--18* #!N 63