<<

Introduction Using LabTalk, Origin's built-in , you can create a 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 (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 . 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 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 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]. 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 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. Alternatively, place your cursor inside the Script Window and simultaneously press the CTRL and V keys on your keyboard. 5. Highlight the batch processing script (as seen below), excluding [MAIN] and press the ENTER key.

6. Navigate to a folder containing more than one ASCII data files and double-click on at least two files to select them. 7. Click OK. Upon doing so, this script will import multiple data files to an Origin worksheet, and plot them as Scatter graphs. 8. Now, in the Script Window save your script as MYFILE.OGS in your main Origin folder (within the Script Window choose File(Text):Save As...).

Congratulations! You have just created your own ! Next, we will discuss other easy and useful ways to run your new batch file.

Executing Your Batch Processing File

We've already discussed how a batch file can be executed via the Script Window using the run.section() command (run.section(myfile,main) for our example above). There are other, quicker and much easier ways you can execute your batch file. You can create a menu command, edit the Custom Routine button on an already existing toolbar, or even create your own user-defined toolbar button.

Creating your own Menu Command

If you don't know already, the term 'menu command' is what we use to refer to a submenu selection from the Origin menu bar. For instance, by selecting Open from the File menu, you are selecting a menu command. In addition to the menu commands installed with Origin, you can create your own menu commands. To learn how to create a menu command that executes your batch processing file, perform the following operations:

1. Highlight the script below:

menu -w; /* set the worksheet menu structure as active*/ menu 4; /* activate the Plot menu option */ menu -i 1 (Import and Plot Data...) {run.section(myfile,main);}; /* add a menu item called Import and Plot Data..." and run MYFILE.OGS */

2. Choose the Edit:Copy menu option from your browser (IE, Netscape, etc.). Alternatively, simultaneously press the CTRL and C keys on your keyboard. 3. In Origin, open the Script Window (Window:Script Window). 4. Within the Script Window choose File(Text):Open. 5. Choose MACROS.CNF from your Origin installation folder.

HINT: Select All Files (*.*) from the 'Files of type' drop-down list in order to view files with the .CNF extension.

6. Scroll down to the bottom of the MACROS.CNF file 7. Place your cursor at the bottom of the file below the last line of code and choose Edit:Paste. Alternatively, simultaneously press the CTRL and V keys on your keyboard. 8. Within the Script Window choose File(Text):Save. 9. Now restart Origin. Restarting Origin causes MACROS.CNF to run, placing a new menu item called 'Import and Plot Data' into the first position of the Plot menu. This new menu item is designed to make a call to the batch processing file you created above, thus executing the script within. 10. Start a new project and select the Plot menu. Upon doing so you should notice the Import and Plot submenu (or menu command). Select it and the batch processing script will execute automatically! Using the Custom Routine Button

The Standard toolbar in Origin comes with a Custom Routine button you can use to execute your own scripts with a single mouse click! It is designed to make a call to the [MAIN] section of an Origin script file called CUSTOM.OGS. So all you have to do is to copy your script into the [MAIN] section and you're ready to go! Here's what you do:

1. In the Script Window, choose File(Text):Open. 2. Choose Script (*.OGS) from the 'Files of type' drop-down list. 3. Open CUSTOM.OGS from the Origin folder. 4. When the file opens, replace the default script (seen here):

type -b $General.Userbutton;

with the script used in our batch processing example (repeated below so you don't have to look for it):

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 }

5. Save your changes by selecting File(Text):Save in the Script Window. 6. Now run your script by pressing the Custom Routine button on the Standard toolbar.

Next, learn about creating your own user-defined toolbar button.

Creating Your Own User-defined Toolbar Button

Creating a user-defined toolbar button which executes your batch processing file (or any other Origin script file) is quick and easy. Once created you can add your button to a preexisting toolbar, or create your own toolbar and add it to that. To see how it's done, perform the following steps:

1. Select View:Toolbars and then the Commands tab. 2. Select 'User Defined' from the Categories list box. 3. Select the Test button from the Buttons section.

4. Click on the Button Settings button to edit the properties of the Test button. 5. In the Button Settings dialog box that appears, press the Browse button for the File Name field and select your batch processing file (MYFILE.OGS). 6. Click the Open button and notice the path and file name of your batch file appear in the File Name field. 7. Enter MAIN in the Section field. Feel free to enter in a Tool Tip and/or Status Bar text. You may also choose to limit the type(s) of windows for which the Test button is active by disabling some (but not all) of the check boxes in the Context group. 8. Click OK when you are done. Here is an example of how it might look:

9. Now click and drag the Test button out into the Origin workspace. Origin automatically creates a toolbar and places your button onto the toolbar.

You can also click and drag the button onto an already existing Origin toolbar, whether it be floating or docked (see example below).

10. Now close the Customize Toolbar dialog box and test your new button.

Wasn't that simple? You have just created your own button and your own toolbar!

Summing Up

As you can see, working with batch processing files is a great way to automate multiple tasks in Origin. And, once you have created one, running it is both quick and easy.

This concludes my article on batch processing script files and how to run them in Origin. I hope you enjoyed it! For more information regarding LabTalk, please refer to your Origin LabTalk Manual, or contact your local technical support representative for assistance.