General Information about Script-Based Control in SpectraLab


Basics

Besides traditional "pick and click" control via GUI (Graphical User Interface), SpectraLab may be controlled through textual commands utilizing its scripting language. Script-based control provides powerful means for automated data processing. It also allows the user to define new "words" (commands) that can be added to the SpectraLab vocabulary permanently (i.e., saved between the sessions), thus providing the user an opportunity to tailor the software for various specific applications.

In order to allow versatile script-based control of the program, the user interface of SpectraLab was written in Forth (Win32Forth), an extensible interactive stack-based language, which allows the user to write and execute custom pieces of code "on the fly".  The scripting language can be used in two ways:

The commands (scripts) should be written according to the general rules of the Forth programming with the use of either basic words of Win32Forth or SpecrtraLab-specific words described in "Basic Glossary of SpectraLab" and "Screen Output of Textual and Numeric Data in SpectraLab" pages.

The use of Command Line

Although the Command-Line scripts should follow the general rules described in the following pages of this Help, there are several limitations and exceptions from the Forth standards for the scripts entered for immediate execution::

Adding new words to the SpectraLab dictionary and the use of the STARTUP.F file

In order to use the same script multiple times, the user can define it as a new word in the SpectraLab dictionary. It can be done either in the Command Line or by including its definitions in the STARTUP.F file. While the new words defined through the Command Line can be used only in the ongoing session and are lost upon closing the program, the definitions found in STARTUP.F become an integral part of SpectraLab and are preserved between the sessions. According to the general rules of Forth, the definitions should start with a double-point (":") followed by a space and a name of the new script (which will be used to invoke its execution from the command line). The definition should end with a semicolon (";") preceded by a space (or form a separate line in STARTUP.F). The names of new definitions (new words) can contain any letters, numbers, and special symbols (no spaces, however) and can be of any length. They are not case-sensitive. In order to prevent re-defining already existing words, the user is recommended to start the new names with such special characters as a percent sign (%), tilde (~), or underline (_). When defining new words, either in the Command Line or in the STARTUP.F file, the user should strictly follow the syntax of Forth - the limitations and exceptions described above for the immediately-executable scripts are not applicable. Some examples of valid definitions of new SpectraLab words may be found in the STARTUP.F file supplied with the package. It should be noted, however, that any errors in the STARTUP.F file (misspelled words, missing ";" at the end of definitions, etc.) will prevent SpectraLab from loading with the appearance of "Exception occurred in program"  error notice. Debugging of complex scripts can be done with the use of installed Win32Forth package and SpectraLab source files available from the author upon request.