Introduction What Is a Batch Processing File?
Total Page:16
File Type:pdf, Size:1020Kb
Introduction Using LabTalk, Origin's built-in programming language, you can create a batch processing file to automate your application and thus speed up your work. This article: · defines the term "batch processing file", · shows you how simple it is to create and run one, and · shows you how to integrate it into Origin's graphical user interface (GUI). What Is a Batch Processing File? A batch processing file is a form of Origin script file that acquires and processes multiple data files (most often without user intervention) and reports the results to the user. Batch processing files are created, ran, and integrated into Origin's GUI in exactly the same way as all Origin script files. In order to learn more about them, you should first learn more about Origin script files as a whole =>. What is an Origin script file? How is it used? An Origin script file is an ASCII text file which consists of a series of one or more LabTalk statements, often divided into sections. When called, the LabTalk statements contained in an Origin script file (or section of it) are sent to Origin's LabTalk interpreter, whereupon a series of actions are automatically carried out in Origin. An Origin script file can be run from the Script Window, from a menu option, or from a toolbar button. In fact, many of the menu commands and toolbar buttons in Origin execute Origin script files (or sections of them) 'behind the scenes.' Viewing these Origin script files that are executed behind the scenes is a good way to learn more about LabTalk programming and syntax. You can even use all or part of the script file to build your own script. As an example, consider the Window:Duplicate menu command. Selecting it automatically duplicates the active window. How does it do this? To find out how this menu command works, first perform the following procedure (developed for LabTalk script debugging purposes): Open a new project in Origin. The default worksheet Data1 will appear. Open the Script Window (choose Window:Script Window). Then, while holding down both the CTRL and SHIFT keys, simultaneously choose the Window:Duplicate menu command. The following is reported to the Script Window: Menu id=33051 run.section(Standard,Duplicate) The first line reported displays the menu ID reserved for the Window:Duplicate menu command and the second line displays the run.section( ) object method behind the Window:Duplicate menu command. Both the menu ID and object method can be used to automatically execute the Window:Duplicate operation (as you will see later). However, only the run.section( ) object method provides the means to view the actual script that runs behind the scenes. The run.section( ) object method The run.section(fileName,sectionName) object method is designed to make a call to a specific section of a specific Origin script file. It expects a file name as the first argument and a section name as the second argument, separated by a comma ( , ). The fileName argument indicates the name of the Origin script file and the path in which it resides. The sectionName argument indicates the section of code that gets executed within the Origin script file. If a path is not specified the file is assumed to be located in the Origin folder and if a file extension is not specified the default extension (.OGS) is assumed. In our example (run.section(standard,duplicate)), a call is made to the Duplicate section of a file called Standard. Since the path and extension are not reported (as seen in the debugging step you performed earlier), the file called Standard possesses the .OGS extension and is assumed to be located in the Origin folder. Now that you know the file name (STANDARD.OGS) and section name (Duplicate) associated with the Window:Duplicate menu command, you have all the information you need to view the actual script that runs. The actual script Activate the Script Window and choose File(Text):Open. Locate STANDARD.OGS in the main Origin folder and double-click on it (or single-click on it and press the Open button) to open the file. Finally, scroll down to the section called [Duplicate]. At this point you should see the following LabTalk script: [duplicate] #Creates a duplicate of the active window win -d; The first line of this script is a comment line which is ignored by the LabTalk interpreter. The second line of script uses the 'window' command with the -d option. Note: In most cases the script present in a section like the one above will be much more complex. Now that you know exactly what script runs when selecting Window:Duplicate, try executing it without the use of Origin's GUI. Executing the script There are three ways you can execute the script contained in the [Duplicate] section. You can execute the actual script we just located, place the menu ID into a 'domenu' statement, or execute the run.section() object method (both of which were listed by the debugging procedure you performed earlier). · To execute the script contained in the [Duplicate] section, do the following: In the Script Window choose File(Text):New to clear it. Enter: win -d and press the ENTER key on your keyboard. · To use the menu ID in a 'domenu' statement, place your cursor underneath the win -d statement you just executed in the Script Window, enter the following command: domenu 33051 and press the ENTER key on your keyboard. A duplicate worksheet will appear. The domenu command can be used in conjunction with any menu ID. However, please remember that menu IDs may change among versions of Origin. · To use the run.section method, place your cursor underneath the domenu 33051 statement you just executed in the Script Window, enter the following statement: run.section(standard,duplicate) and press the ENTER key on your keyboard. As with the win -d and domenu 33051 statements, your active window will duplicate. Pretty nifty, huh? HINT: When you use the run.section() command instead of the menu ID command you do not need to worry about compatibility among Origin versions. Now that you are familiar with Origin script files and some of the techniques to run them, you should be ready to run a batch processing file. Continue to the next page to try running one which comes with the Origin installation =>. Running a Batch Processing File A typical Origin installation includes a batch processing file called BATCH.OGS in the Buttons subfolder of your Origin installation folder. When called, BATCH.OGS imports multiple ASCII files into separate worksheets, graphs the data, performs a linear fit on each dataset, and reports the intercept and slope for each dataset to the Results Log. To run it from the Script Window, perform the following operations: 1. Let's start a new Origin project. Select File:New:Project from the Origin menu bar. Alternatively, click the New Project button on the Origin Standard toolbar. 2. If your Script Window still contains those lines of script we entered earlier, choose File(Text):New to clear it. 3. Place your cursor in the Script Window, enter the following line of script: run.section(buttons\batch,main) and press the ENTER key on your keyboard. Alternatively, highlight the line of script and press the ENTER key. As you learned earlier, doing so begins execution of the [MAIN] section of BATCH.OGS. 4. In the Import Multiple ASCII dialog box that appears, navigate to the Tutorial subfolder of the Origin installation folder. 5. In the file list, double-click on the files called GROUP.DAT and START.DAT to add them to the 'Files to Open' list. Or, single-click on an individual file and click the Add File button to add each one to the list. 6. Click OK and BATCH.OGS will continue to execute. Click on the link below to view a sample AVI file. Note: The link will open a new browser window. To close this new window either click on the X button in the top right corner or double-click on the window icon in the top left corner. Batch.AVI (647KB) This is how easy it is to automate your work! Now try creating your own batch processing script. Creating Your Own Batch Processing File The process of importing and plotting multiple data files is one of the more common batch processes. It is also an easy one to automate. What follows is a step-by-step procedure which describes how to execute this process through script in the Script Window and then implement it in a batch processing file. If you have any questions or comments about the script itself, please consult your Origin User's and LabTalk Manuals. 1. Let's start a new Origin project. Choose File:New:Project from the Origin menu bar. 2. Clear the Script Window by choosing File(Text):New. 3. Highlight the batch processing script below (beginning with [MAIN] and ending with } ) with your cursor and choose the Edit:Copy menu option located at the top of your browser. Alternatively, highlight the script and simultaneously press the CTRL and C keys on your keyboard. [MAIN] getfile -m *.dat; // get multiple ASCII *.dat data files for(i=1;i<=count;i+=1) { getfile -g i; // get file name into %A win -t data; // bring up a new worksheet open -w %A; // import the data worksheet -s 0 0; // entire worksheet is highlighted worksheet -p 201; // data is plotted in a scatter graph } 4. Within the Script Window choose Edit:Paste.