JScript Tutorial
Wolfgang Unger and Tobias Sommer
(tsommer@iup.uni-heidelberg.de)
24.06.2008
Contents
I
Introduction
4
1
What is JScript?
5
2
For whom this Tutorial is written
7
3
What is special about this Tutorial?
8
4
Tips and Tricks
9
4.1
The help menu of DOASIS . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
4.2
Structuring a JScript program by creating a JScript Project File . . . . . . .
9
4.3
Running several JScripts after each other . . . . . . . . . . . . . . . . . . . .
9
4.3.1
Creating a JScript project file . . . . . . . . . . . . . . . . . . . . . . .
9
4.3.2
Creating a batch file . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
4.4
Starting a JScript automatically after a hardware reboot . . . . . . . . . . . . 10
4.5
Avoiding inexplicable program crashes . . . . . . . . . . . . . . . . . . . . . . 10
II
The basics of JScript
11
5
First steps in JScript
12
5.1
A first example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2
A word on ”object-orientation” . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.3
A second example
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.4
The syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6
Programming in JScript
15
6.1
Data Types and Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.2
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.2.1
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.3
Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.3.1
if..else-statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.3.2
for-Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.3.3
for..in-Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.3.4
while-Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.4
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
7
Important DOASIS-namespaces and their usage
23
7.1
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.2
DoasCore.Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2.1
DoasCore.Math.SpecMath . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.2.2
DoasCore.Math.ScanGeometry, DoasCore.Math.JulianDateTime . . . 25
7.2.3
DoasCore.Math.DoasFit . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.3
DoasCore.Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.4
DoasCore.IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
1
7.5
DoasCore.Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.5.1
DoasCore.Spectra.ISpectrum . . . . . . . . . . . . . . . . . . . . . . . 29
7.5.2
DoasCore.Spectra.Specbar . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.6
DoasCore.Script
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.7
DoasCore.HMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.7.1
Progress Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.8
System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.9
System.Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.10 System.Windows.Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.11 System.IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
7.12 System.Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
III
Collection of JScript applications
34
8
Simple JScripts
35
8.1
Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2
Diplaying variables in the Output window. . . . . . . . . . . . . . . . . . . . . 35
8.3
Wait functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8.4
Display message boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
8.5
Creating a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
8.6
Creating a text file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
8.7
Get the current date and time . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
8.8
Control number of digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
8.9
Open and Save a spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
8.10 Saving spectra with the “AutoFileName”-class . . . . . . . . . . . . . . . . . 42
8.10.1 A word on AutoFileName() . . . . . . . . . . . . . . . . . . . . . . . . 43
8.11 Opening spectra with the “AutoFileName”-class . . . . . . . . . . . . . . . . 43
8.12 Modifying the properties of a spectrum
. . . . . . . . . . . . . . . . . . . . . 45
8.13 How to compare the time of different spectra . . . . . . . . . . . . . . . . . . 45
8.14 Calculate the solar zenith angle (SZA) . . . . . . . . . . . . . . . . . . . . . . 47
8.14.1 A word on the class ScanGeometry . . . . . . . . . . . . . . . . . . . . 48
8.15 Wavelength Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9
JScript Project File
49
10 JScripts communicating with hardware
51
10.1 Reading in data from a serial port (e.g. GPS data) . . . . . . . . . . . . . . . 51
10.2 Measure a spectrum with an Ocean Optics spectrograph . . . . . . . . . . . . 53
10.3 Operate two Ocean Optics spectrographs . . . . . . . . . . . . . . . . . . . . 54
10.4 Mini-MAX-DOAS (MiniDOAS) control via JScript . . . . . . . . . . . . . . . 54
11 Evaluating spectra
55
11.1 Offset and Dark Current Correction . . . . . . . . . . . . . . . . . . . . . . . 55
11.2 Offset and Dark Current Correction with a “JScript project file” . . . . . . . 56
11.2.1 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
11.2.2 The “project file“ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
11.2.3 The file variables.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
11.2.4 The file functions.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
11.2.5 The file maincorrect.js . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
11.3 Fitting with JScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
11.4 Modifying a fit scenario with JScript . . . . . . . . . . . . . . . . . . . . . . . 59
11.5 Save the residual of the fit result . . . . . . . . . . . . . . . . . . . . . . . . . 62
2