Origin Automation
An extremely flexible tool for acquiring, processing and displaying data John R. Joyce, Ph.D.
Origin 8.5.1 is a full-featured data analysis and graphing package that has been the target of previous reviews in Scientific Computing.
1,2 Here, we will take a more in-depth look at the many automation features to be found in both Origin and OriginPro. These include several different ways of automating its internal processes, ways for it to control external processes and ways for external processes to control it. In the following text, we will examine these capabilities and some of the ways in which they can be used, as well as constructing examples illustrating some of the approaches to go about doing it.
The two internal ways of programmatically automating Origin processes are through its scripting language, LabTalk, and its programming language, Origin C. According to OriginLab, the primary criteria for selecting which of these languages to use is the complexity of the task to be performed. Specifically, they recommend LabTalk for use with ‘simple operations,’ and go on to list examples such as importing data, manipulating data columns and performing data operations like smoothing, curve fitting or interpolation. While they state that LabTalk ‘provides access to most of the functionality of Origin,’ Origin C allows full access to Origin functionality. To add additional functionality and flexibility to Origin C, Origin comes bundled with a Developer Kit designed to assist in the development of complex dialog boxes, floating tools and wizards.3 Those wishing to review the most up-to-date documentation on these two programming tools can find it at OriginLab’s wiki site (http://wiki.originlab.com).
Programs for both languages can be developed in Origin’s integrated debugging environment, which is called Code Builder. Additionally, LabTalk commands also can be entered in Origin’s Command window for immediate execution. Advantages to using Code Builder include access to program break points, step-wise program execution and variable inspection.
 |
| Figure 1: The data values and settings in the Origin project file created by the JRuby demonstration program (Figure 2) when opened in Origin. |
However, the real power of Origin automation comes from the fact that Origin can serve as either a COM client or server. COM, short for Component Object Model,
4,5 was introduced by Microsoft in 1993 to simplify interprocess communication between applications. Users should note the caveat that Microsoft has redefined this term a number of times and introduced the related technologies of Object Linking and Embedding (OLE), OLE Automation,
6 ActiveX, COM+, and Distributed Component Object Model (DCOM). It currently is common to find the term COM used as an umbrella for all of the above technologies (and all of their changing definitions). Notwithstanding, the point is that, when acting as a COM client, Origin can control external applications, such as Microsoft Excel or MATLAB. Conversely, it also can function as a COM server and allow external applications, such as MS Excel, MS Word or National Instruments LabVIEW to control it. Of particular interest to me is that it allows a user to write their own application, whether for data collection, process control or just about anything, and to use Origin to process and plot this data. Support for COM automation, both client and server, is currently built into all versions of Origin, including the Student version. If you’ve taken the time to download and install the trial version of Origin, you can access the Help file documentation by clicking on the Help menu option and first clicking on the Programming drop-down menu option, followed by the Automation Server option.
The beauty of this is that the COM client program using Origin as the COM server can be very simple, requiring only a few lines of code to implement (well, if you don’t count all of the code going into the language itself and all of its associated libraries). As an example, we can put together a simple JRuby program (since I happen to have a copy of that language already loaded) and have it create a new Origin project and upload some dummy data to it. As you can see in the attached sidebar, the full program runs to less than 30 lines of code, and that’s with a rather inefficient first attempt at an implementation.
Depending on how far you want to drill down, you could write whole articles just examining the functionality of this short program. Suffice it to say that the ‘require’ statement at the start of this program is used to associate the standard Ruby library ‘win32ole,’ which implements the COM functionality. The remaining statements are basically to pass commands and data to the Origin COM server. Some of these statements are direct commands supported in the COM interface, while others are ‘simply’ passing back LabTalk commands for Origin to execute.
 |
| Figure 2 |
While extensive information on the Origin COM interface can be found both in Origin’s online help and in their wiki, it still can be somewhat cryptic, particularly if you are attempting to use it with a language for which OriginLab hasn’t written example programs. However, if you are willing to put in some time probing and experimenting with the system, I think you can work your way up to being proficient with it fairly quickly. If you are just attempting to get standard packages, such as MS Excel and Origin, to talk with each other instead of writing an external application from scratch, your learning curve shouldn’t be anywhere near as severe either.
To make this approach even more attractive, you don’t even have to set up your control program to ‘micromanage’ the data analysis and display by transmitting all of the stepwise processing commands. Due to its design, you can configure Origin projects so that, once you connect to Origin and push data up to it, Origin’s internal recalculate functions can be configured to automatically process and display the data.
There are a few caveats to keep in mind when taking advantage of Origin COM automation. Depending on the tools that you are using, it is important to remember that Origin uses zero-based arrays while other tools may start their base index at one. This is not a difficult situation to deal with, but it is a factor that you need to consider when designing your program, as working backwards to correct such a mistake can be a major headache. Depending on how the COM libraries were written for the programming language you are using, it might be important to keep in mind that Origin generally defaults to using double precision values in its COM interface, though there are plenty of examples of how you can force the system to use different values, including Byte transfers.
JRuby
In perhaps overly simplistic terms, JRuby is a version of the Ruby programming language built on the Java virtual machine and optimized to allow easy integration of both Ruby and Java program libraries and tools. It is simple to install, highly portable and very powerful. I highly recommend it to anyone involved in programming as an additional tool to add to your repertoire. At the same time, this tool lends itself well to those just learning how to program. Those wanting to learn more about JRuby should check out the JRuby Web site7 as well as the complementary references Using JRuby8 and Programming Ruby 1.9.9 As the JRuby language download is free, you have little to lose and a lot to gain! |
Another common gotcha is the use of backslashes. As with a number of programming languages, Origin uses the backslash as an escape character to modify the function of the character following it. If this character is a valid command, Origin will attempt to execute it. If the following character is not either a valid command or an opening parenthesis, then Origin will suppress it. Exactly how this is handled depends on which aspect of the system you are working with, as it can affect everything from the display of special characters to the passing of sub-directory names. There are multiple ways of dealing with this issue, ranging from the use of a double backslash (‘\\’), which is the escape command sequence to display a backslash, the ‘\v()’ command, which tells the system to ignore any contained escape codes, to the ‘verbatim’ method (e.g. ObjectName.verbatim), which tells the system to display the contents of the object, well, verbatim.
If your automation programs insert any special characters into table or graph labels, another caveat to keep in mind is that not all of the Origin help files and other online documentation has been fully updated yet. As such, you may encounter instances, as I did, where the documentation clearly states to enter the ASCII code10 for the character to be inserted, when the reality is that the code page to be used is Windows-2859111, which is much closer to what Microsoft originally referred to as the ‘ANSI code’12.* This is not an uncommon problem, and I’d advise you to be particularly careful regarding the accuracy of any character tables you download from the WWW, as many are mislabeled or even mangled merges of the two. As long as you keep this documentation discrepancy in mind, you shouldn’t encounter any major problems using these functions. Note that, in addition to accepting a decimal value, this code value can be entered using other radixes14 as well, such as hexadecimal15, just remember to include the appropriate radix flag character with the value (e.g. prefacing the value with an ‘x’ in Origin).
While not an automation tool in the same way as those that we’ve been discussing, another feature of Origin worth knowing about is its Orglab8 file library. This is a set of 8 Dynamic Link Library (DLL) files that can be used when writing your own programs to enable the reading and writing of Origin Project files. This allows you to make the output of your application available for Origin processing by those with a copy of Origin, without having to license Origin for inclusion in your program.
It also is worth reviewing the File Exchange maintained on the OriginLab Web site (www.OriginLab.com). In addition to supplementary programming tools, you also can find add-ons ranging through support for RS-232 serial ports to data recorder support for LabVIEW, expanded import and export functions, and expanded analysis support for spectroscopy, mathematics, image processing and general data exploration.
Taken together, these tools make Origin an extremely flexible platform for processing and displaying your data. So flexible, in fact, that you even can use it to control the acquisition of the data itself. If you are in the process of trying to select a data analysis and display tool, these features may well make a deciding difference.
References
1. Plotkin, S. & Tracy, S. Origin at Pittcon2011. Scientific Computing: www.scientificcomputing.com/video-Origin-at-Pittcon2011-41911.aspx
2. Wiggins-Camacho, J. & Stevenson, K.J. “OriginPro Student Version Offers Useful Enhancements.” Scientific Computing: 28, 26-27 (2011).
3. Origin’s Developer Kit. OriginLab: www.originlab.com/index.aspx?go=Products/DeveloperKit
4. Component Object Model. Wikipedia, the free encyclopedia: http://en.wikipedia.org/wiki/Component_Object_Model
5. COM: Component Object Model Technologies. Microsoft: www.microsoft.com/com/default.mspx
6. OLE Automation. Wikipedia, the free encyclopedia: http://en.wikipedia.org/wiki/OLE_Automation
7. Home — JRuby.org. JRuby: www.jruby.org
8. Nutter, C.O., Enebo, T., Sieger, N., Bini, O. & Dees, I. Using JRuby: Bringing Ruby to Java. (The Pragmatic Bookshelf: Raleigh, NC, 2011). http://pragprog.com/book/jruby/using-jruby
9. Thomas, D., Fowler, C. & Hunt, A. Programming Ruby 1.9 (3rd edition): The Pragmatic Programmers’ Guide. (The Pragmatic Bookshelf: Raleigh, NC, 2009). http://pragprog.com/book/ruby3/programming-ruby-1-9
10. Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion.
www.asciitable.com
11. ISO/IEC 8859-1 - Wikipedia. Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/ISO/IEC_8859-1
12. ANSI character sets. ASCII-Table.com: http://ascii-table.com/ansi-codes.php
13. Windows-1252 - Wikipedia. Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Windows-1252
14. Weisstein, E.W. Radix — from Wolfram MathWorld, http://mathworld.wolfram.com/Radix.html
15. Hexadecimal - Wikipedia. Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Hexadecimal
* Editor’s note: While based on what eventually became the ISO 8859-1 standard, this character set was never an ANSI standard and should be referred to as code page Windows-125213, though it is still frequently confused with the ISO 8859-1 standard, which was implemented in Windows as code page Windows-28591. The primary difference is that Windows-1252 substituted printable characters for the control characters located in the 0x80 to 0x9F range in ISO 8859-1.
John Joyce is a laboratory informatics specialist based in Richmond, VA. He may be reached at editor@ScientificComputing.com.