12 Advanced JScripts
65
12.1 Write spectrum data to an Excel-Sheet . . . . . . . . . . . . . . . . . . . . . . 65
12.1.1 A word on ActiveXObjects . . . . . . . . . . . . . . . . . . . . . . . . 66
12.2 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
12.3 Evaluate data with a fit scenario file . . . . . . . . . . . . . . . . . . . . . . . 69
12.4 Automatized scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
12.5 Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
12.6 Controlling Mini-MAX-DOAS (MiniDOAS) instruments with JScript . . . . . 73
12.6.1 Structure of the program . . . . . . . . . . . . . . . . . . . . . . . . . 73
12.6.2 Description of the tasks . . . . . . . . . . . . . . . . . . . . . . . . . . 74
12.6.3 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
12.6.4 Remarks: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
13 Literature
85
Index
86
3
Chapter 1
What is JScript?
JScript is a script language which can be used within an application. In DOASIS, this makes
possible to automatize measuring and evaluating data. For example, let’s say you want to
record a huge number of spectra, and you want to adjust the parameters (e.g. the angle)
after each measurement. Since you don’t want to start a new measurement every 5 minutes,
you can use a script which tells DOASIS what measurements to make.
A script language is a programming language, but you are not able to write executable
programs with them. Instead, the scripts are started from the program for which the script
was written. Scripts are not compiled, but interpreted. That means, the script is not at
once translated to machine language and then executed, but read and executed line by line.
Resources that your script makes use of (namespaces, objects) are precompiled.
In DOASIS, everything that you need concerning scripts can be found in the Console-
Window. More precisely, there are four tabs: the Output-, the Script-, the Mini Scrips- and
the Quick Script-Tab.
A script can be started from the Script-Tab in the Console-Window (by specifying the file
in which the script is stored) or by entering a script in the Mini-Script-Tab. The output
that is generated by the Script can be viewed in the Output-Tab.
5
Figure 1.1: The main application window of the graphical user interface part DoasUI.
6
Chapter 2
For whom this Tutorial is
written
If you are fairly good at programming and you know Java or JavaScript, this is not for you.
In fact, JScript could also be called the ”Mircosoft JavaScript”. There quite a lot similarities,
although Microsoft emphasizes that the technology behind JScript is very different from the
JavaScript by Netscape.
But if you are a poor programmer, or even never learned programming, but still want to
use all the great possibilities of DOASIS-JScript without bothering too much on aspects of
programming in general, then this is written for you! Here you will learn just what you need
to write JScripts in DOASIS.
Maybe you have experience with other script languages like VBA (”Visual Basic for Ap-
plications”). But this will be little help, since JScript has a different syntax, orientated at
C/C++. I would recommend to read this anyhow, since there is a lot DOASIS-specific to
learn about.
7
Chapter 3
What is special about this
Tutorial?
The Tutorial is split into two parts. In part II, the basic features of JScript and its use
in DOASIS are explained. This is more a general overview and interesting for people, who
have non or only very little programming experience. If you already have a general idea
about programming it is recommended to skip Part II and continue directly with Part III.
Part III consists of a selection of practical source code examples, which have been or are
still in use by different working groups which use DOASIS for measurement and evaluation
purposes. The code examples are explained in a way which can be easily understood and
the important commands are commented out.
The code examples can be ”copy-pasted” directly from your pdf-Reader program (e.g.
Adobe Acrobat Reader) to a text editor, then saved with the suffix ”.js” and opened within
DOASIS in the sheet ”Script” of the ”Console window”. If the programs are very short,
than it might be more convenient to ”copy-paste” them directly into the ”Mini Scripts”
sheet of the console window and press ”Start”. (See as well 5.3)
To get fast access to the commands you are looking for, take advantage of the Index,
that will guide you to the requested sections.
8
Chapter 4
Tips and Tricks
4.1
The help menu of DOASIS
The Programming Documentation in the Help menu of DOASIS provides information on all
the JScript commands that access the DOASIS source code. Each button or property that
can be activated or set in DOASIS can be accessed through JScript as well. This is due
to the object orientated programming of DOASIS (with C#, similar to C++). Just press
“Help” in the main menu of DOASIS, then “Programming Documentation” and then e.g.
under “Search” the command, about which you want to get more information.
4.2
Structuring a JScript program by creating a JScript
Project File
A lot of programming work can be saved if, from the beginning, the program is structured
in a way, that methods and variables are defined “generally” in a separate file, so that
new programs can refer to them as well. It is strongly recommended to establish so called
“JScript-projects”. In section 9, more information is provided.
4.3
Running several JScripts after each other
If several JScripts should be executed automatically directly after each other two possibilities
are presented in the following.
4.3.1
Creating a JScript project file
By creating a JScript project file, the individual JScripts can listed after each other and will
be executed successively. See section 9.
4.3.2
Creating a batch file
The advantage of creating a batch file is that the script runs much faster compared to when
the script is started within DOASIS. This is because the grafical user interface (GUI) of
DOASIS is not used and therefore does not consume calculation time.
Open the text editor and write:
C:\Programme\DOASIS\DoasConsole.exe
C:\scripttest\jscript1.js
>>
C:\logfile1.txt
Save this file for example under C:\startscript.bat. By double clicking on the batch file
9
Dostları ilə paylaş: |