Calling the Wrapper Module from the Main Program

Once you have written a wrapper module to encapsulate access to a C function, you can call the function by simply calling the wrapper module.

IML Studio is distributed with a sample program that calls the wrapper module for the example C function My_C_Function. The sample program is called Demo_My_C_Function.sx and is stored in the subdirectory

<IMLStudio>\Programs\Samples\User Extensions

where <IMLStudio> is the directory in which you installed IML Studio. The program defines a wrapper module called My_C_Function and then uses the following statements to call the wrapper module twice:

/* Example 1: Type in your own data */
x = { 1, 2, 3, 4, 5, 6 };
v = My_C_Function( 3.0, x );
print v "is a scalar multiple of" x;

/* Example 2: Get data from a data set (Baseball)
   Potential variables are
      NO_ATBAT, NO_HITS, NO_HOME, NO_RUNS, NO_RBI, NO_BB,... */
declare DataObject dobj;
dobj = DataObject.CreateFromFile( "baseball" );
dobj.GetVarData( "NO_HITS", x );
v = My_C_Function( 2.0, x );
/* Print out some of the altered data */
print "A little data on hitting" (x[1:10]);
print "Twice the number of hits" (v[1:10]);

This code shows two ways to obtain data to send to the C function. The first example sends in a column vector and prints the result of multiplying the vector by three. The second example retrieves data from a SAS data set and multiplies one of the variables by two.