Origin C provides many global functions for performing a variety of tasks. These functions fall into twenty-six categories:
Please refer to the Global Functions section for a complete list of functions with examples.
Origin C supports user-defined functions. A user-defined function lets you create functions that accept your choice of arguments and return type, and operate on those arguments to achieve a specific purpose.
Define the function and call it in one block:
double my_function(double dData) { dData += 10; return dData; } // Usage double d = 3.3; d = my_function(d); out_double("d == ", d); // 13.3
Use a reference parameter to modify the caller’s variable without returning a value.
void add_offset(double& x, double offset) { x += offset; // modifies 'x' in the caller } // Usage double v = 5; add_offset(v, 2.5); out_double("v == ", v); // 7.5
Origin C supports function overloading and default parameter values.
// Two overloads for scale(): vector<double> and vector<int> void scale(vector<double>& v, double factor = 1.0) { int n = v.GetSize(); for (int i = 0; i < n; i++) v[i] *= factor; } void scale(vector<int>& v, double factor = 1.0) { int n = v.GetSize(); for (int i = 0; i < n; i++) v[i] = (int)(v[i] * factor); } // Usage vector<double> a = {1.0, 2.0, 3.0}; scale(a, 2.0); // -> {2, 4, 6} vector<int> b = {1, 2, 3}; scale(b); // default factor 1.0 (no change)
Keep the input read-only and return a scaled copy.
vector<double> scale(const vector<double>& v, double factor) { vector<double> out = v; // copy input int n = out.GetSize(); for (int i = 0; i < n; i++) out[i] *= factor; return out; } // Usage vector<double> c = {2.5, 4.0}; vector<double> d2 = scale(c, 0.5); // c unchanged, d2 = {1.25, 2.0}
You can call eligible Origin C functions from LabTalk (parameters/return types must meet certain criteria).
// Example function callable from LabTalk: double add_then_scale(double x, double y, double factor) { return (x + y) * factor; }
// In the Script Window or LabTalk Console: double r; r = add_then_scale(2.5, 3.5, 10); // calls the Origin C function r=; // outputs 60
For details on which signatures are callable from script and how to keep functions available, see |