This topic describes how to write an Origin C function so that it can be listed in the Function menu of Set Column Values dialog.
For general information on how to add your own OC functions to Origin, please refer to this topic: Calling OC Functions from LabTalk.
For the OC function to be accessible from the Set Column Values dialog, the following additional conditions should be met:
Once the function is compiled, it will be available in the Function menu drop-down of the Set Column Values dialog.
The following is an example of a string function:
string AddSomethingToStr(string str) { str += " test"; return str; }
Once compiled, this function could then be used in the Set Column Values dialog like below:
Col(B) = AddSomethingToStr(Col(A))$;
The following is an example of a function that returns an integer:
int CopyNumeric(int nn) { return nn; }
The function can then be accessed from Set Column Values dialog to copy numeric data from one column to another such as:
Col(B) = CopyNumeric(Col(A));
Add one of the following #pragma directive to your OC source file to disable, allow, or limit access to your OC functions from LabTalk
Since the default Origin behavior is to allow calling OC functions from LabTalk, #pragma labtalk(1) is not really needed in your OC code. Note that #pragma labtalk(...) affects all functions in that file until another #pragma labtalk(...). Therefore, if you don't want to put some C functions in the Function menu, you can put #pragma labtalk(0) before the function, and you can put #pragma labtalk(1) again to resume putting the functions in the Function menu. By using this method, you can control and manage the function names in the Function menu.
In order for your OC functions to appear in the Function menu under an appropriate category, you should add a pragma statement such as below:
The function(s) will then appear in the Function menu of Set Column Values like below, where the example here represents a function that accepts and returns a string:
Date and Time : FunctionName(str)$
If no category is specified for your OC function, the function will be shown under the User Origin C category.
Selecting a built-in function from the Function menu displays a "smart-hint" with basic function information (prototype, what is returned, etc.). You can add such hints to your Origin C functions (Tutorial, below) by inserting comments between /*$$$ and $$$*/, as shown:
|
The following procedure is a tutorial to add a user-defined function in the Function menu of the Set Values dialog. You can also find the sample codes in internal.c in the \OriginC\System\ subfolder in your Origin program directory.
Steps:
#pragma labtalk(1,Math) double add2num(double a, double b) { return a + b; }
|
Note: The "pragma" line before the function definition is for placing the function in the Math category in Function menu. |
| Note: See the more information on compiling in: "Four Methods of Building the Code Builder Workspace" and "Loading and Compiling Origin C Function". |
add2num(col(1),col(2))
|
Note: Although this function "add2num" has two (double) scalar arguments, and returns a scalar value, when you run this function in Set Values dialog with two columns (i.e., vectors) as its arguments, the results are filled in the target column because Set Values dialog applies the formula to each element (indexed by i implicitly) automatically. |