2.4.2.4 Using Origin C Functions

Besides define LabTalk function, you can also define an Origin C function (see Creating and Using Origin C Code for details) which returns a single value, and call the function from command window. For example,

  1. Open Code Builder by menu View: Code Builder.
  2. In Code Builder, create a new *.c file by menu File: New. In the New File dialog, give a file name, MyFuncs for example, and click OK.
  3. Start a new line at the end of this new file, and add the following code.
  4. double MyFunc (double x)
    {
        return sin(x) + cos(x);
    }
  5. Click menu item Build: Build to compile and link the file.
  6. If no error, the function defined above is now available in LabTalk. Run the following script in the Command Window.
  7. newbook;  // create a new workbook
    col(A) = data(1, 32);  // fill row number
    col(B) = MyFunc(col(A));  // call the Origin C function, result is put to column B