Origin is a powerful scientific spreadsheet program capable of sophisticated data analysis and presentation-quality graphics. It is packed with all sorts of features. However, here, we will focus on Origin C. I recommend that you purchase Origin Pro. The full version is pricey, but the student version (which is fully functional) is only $50. It is a steel at $50, and the academic/corporate versions are still well worth the money.
The description here is for Origin 8.0 and will be updated should a newer version be significantly different.
The beauty of Origin C is that one can define custom functions that are complied (so they run super fast) and become part of Origin, so these functions can be used as simply as sines, cosines, and exponentials. Furthermore, Origin C has built-in functions for opening graph sheets, worksheets and dialogue boxes. If that's not cool enough, the full NAG C Libraries (from Numerical Algorithms Group) are included, so you can count on having having lots of power at your fingertips.
Unfortunately, many people feel it a daunting task to build their own personal custom library. On this web page, I will give step-by-step instructions of how to get started. You will, of course, have to learn C programming on your own. Even if you know just a tiny bit of C, you will be able to do lots of stuff using OriginC.
I am not a sophisticated programmer and chose to use C++ - quite by random. I am embarrassed to say that I thought the "++" meant that it's much better than just plain old C! Luckily, I made a good choice because C++ is an object-oriented language, and it turns out that I like to program that way.
When I write code, I write small modules that can be easily combined to deliver powerful functionality. Rather than reading and writing data to files, I use the Origin Worksheet as my IO device. I just fill a worksheet column with values, use them as input to calculations, then write the results onto another column or columns. This is very convenient since Origin makes pretty plots, so the results of calculations can be immediately plotted. Alternatively, one can use the custom functions for data fitting.
I will assume that the reader has no experience with Origin, other than having generic knowledge of how to use a spreadsheet. First, we will discuss how to customize the GUI (Graphical User Interface), and then we will discuss how to load and compile functions, make a library of functions, and then how to build this library into Origin so that your custom functions are available for future use.
My description is a bit long-winded, so here goes!
Customizing the GUI
First we will start by configuring the Graphical User Interface (GUI). Open Origin, then:
1. Select "View" then 2. Select "Toolbars." Click here to for a screen shot of what you should see after you have selected "Toolbars." Note that your Origin window will look different depending on how you configure the GUI. 3. In the "Customize Toolbar" window, 4. check all of the boxes. 5. Then select "Close."
All kinds of toolbars will appear all over the place. You should move them around to optimize the size of your workspace. After you have used Origin for a while, you will undoubtedly want to change the placement of the toolbars to suit your needs. The important thing for now is that you will have one-click access to everything.
Download C Code
Create a directory where you will keep your C Library of custom functions. For this tutorial, we will call it: C:\MyPath\C-Code\. Then, open the following two sample files and save them into your directory and make sure that the filenames are exactly as shown below:
factorial2.cpp is a C++ file that calculates double factorials.
MyLibrary.h defines your library of functions.
Warning! There is a bug in Origin 8.0 SR5 and SR6; and in Origin 8.1 SR0 that prevents the procedure below from working. Select "Help" and "About Origin" to check which Service release you have. It appears in the last three digits at the top of the window and will look something like: OriginPro 22.214.171.1248 SR6. As of this writing, Originlab is working on a fix. Be sure to update Origin with the newest Service release once its available. Do do so, select "Check for Updates" in the "Help" menu.
Load and Compile Your Function
Click on the Code Builder icon, which looks like a gear (see screen shot above). Then select "File"and "Open" and navigate to the directory that contains your C++ files.
1. Make sure that "All Files (*.*) is selected as the "Files of type:". This will allow you to see both the .cpp and .h files. 2. Holding down the shift key, left click on each of the files until they are all highlighted 3. Check the "Add to Workspace" box. (see screen shot). This will add all the programs to the workspace, which is required for compiling. If a program is not in the workspace, it will not compile. (Click here to see a screen shot up to this point.) 4. Then select "Open."
Select the "Build" button, and all of your functions will be compiled. (see screen shot.) Close the code builder window. You are now ready to use your custom functions.
Using Your Custom Functions
1. In the worksheet, enter integers in columns A and B with A>B. 2. Right click on column C and select "Set Column Values..." 3. Then enter the formula: "factorial2(Col(A),Col(B))" Note that if you select "F(x)" the function "factorial(d,d)" appears in the list. Then select "apply." When you are done, the screen should appear as shown in the screen shot.
Directory for your C Code
I strongly suggest that you place your Origin C++ code (i.e. the .cpp files) and your header file (the .h file) in one of your own directories. While in Code Builder, make sure that you chose the "Save As" option and pick the directory that you have previously created for your code. Also, make sure that you select "Save Workspace" and save your .OCW in that same place. The advantage of choosing a directory separate from other Origin files is that it is easier to find, and, if you ever need to reload Origin, your work will not get lost.
After you exit Origin and restart it, your libraries need to be recompiled. To learn how to do so automatically, click more.