Jscript Tutorial Wolfgang Unger and Tobias Sommer



Yüklə 0,62 Mb.
Pdf görüntüsü
səhifə8/21
tarix07.11.2018
ölçüsü0,62 Mb.
#78679
1   ...   4   5   6   7   8   9   10   11   ...   21

The Spectrum-class also contains methods to open and save (used above) the spectrum

directly without the need to use the DoasCore.IO.SpectrumFile class.

7.6

DoasCore.Script



The DoasCore.Script-namespaces helps to handle scripts. Especially important is the prop-

erty StopScript and StopAllScripts, which signalize when a script was stopped by the user,

and the methods SuspendScript() and ResumeScript(). They are illustrated in the script be-

low, which optimizes the exposure time according to the counts given by the range between

MinCount and MaxCount.

import System;

import DoasCore;

import DoasCore.Spectra;

import DoasCore.Math;

import DoasCore.Device;

import DoasCore.IO;

import DoasCore.Script;

var MiniDoas :

OceanOptics = new OceanOptics();

var OptSpec :

ISpectrum = Specbar.GetSpectrum("Optimize");

OptSpec.MinChannel = 1400;

OptSpec.MaxChannel = 2047;

var ETime =10;

var MaxCounts = 4000;

var MinCounts = 3500;

while(!Script.StopAllScripts)

{

MiniDoas.Scan(OptSpec,1,ETime);



var Faktor :

Double = OptSpec.Max/MaxCounts;

//******************* too few counts ***********************

while( (OptSpec.Max< MinCounts || OptSpec.Max > MaxCounts)

&& !Script.StopAllScripts)

{

ETime = parseInt(ETime/Faktor);



if (ETime > 60000)

{

ETime = 60000;



}

Console.WriteLine("Exposure Time = " +ETime );

Console.WriteLine("Maximimum = " + OptSpec.Max);

MiniDoas.Scan(OptSpec,1,ETime);

Faktor = OptSpec.Max/MaxCounts;

}

Console.WriteLine("Optimization finished.



Exposure Time = " + ETime);

Console.WriteLine("Maximum :

" + OptSpec.Max);

}

Warning:



This script will be repeated until it is stopped by the user by

pressing the ”Stop” button in the ”Script” sheet of the ”console” window.

30



7.7

DoasCore.HMI

The DoasCore.HMI namespaces (Human Machine Interface) can be used to simplify the

interaction between your JScript and the user. The most common used classes are:

• DoasCore.HMI.UserInterfaceWriter: Basic text output to the user

• DoasCore.HMI.UserInterfaceReader: basic text input from the user

• DoasCore.HMI.ProgressBar: Display the progress of your algorithm in the statusbar.

7.7.1


Progress Bar

The progress bar can be used to display the progress of the calculation. Here is an example:

import System;

import DoasCore;

import DoasCore.HMI;

var Bar :

DoasCore.HMI.ProgressBar = new DoasCore.HMI.ProgressBar();

Bar.Value = 0;

Bar.Minimum = 0;

Bar.Maximum = 100;

Bar.Caption = "Bar";

Bar.Text = "Advance";

var i;

for (i=0;i<100;i++)



{

doCalculation();

Bar.Value++;

}

The function doCalculation() is not defined here, but can be considered a calculation that



has to be done a couple of times.

7.8


System

The System namespace and all its subnamespaces are provided by the .NET Framework.

All its classes are also available in programing C++ or C# in the Visual .NET Framework.

Since they are not part of Doasis, I will just give a few examples and refer you to the very

extensive guide to the .NET framework on the web (see last chapter for addresses).

7.9


System.Console

We already used the WriteLine() method a lot. But there is more functionality of the

System.Console namespace.

You can also input data from the console:

31



import System;

Console.WriteLine("Please enter your Name");

var a=System.Console.ReadLine();

Console.WriteLine("Hello " + a + "!

You have a nice name.");

Due to the concept of untyped variables, you can use the same command to read integers

or real numbers.

7.10


System.Windows.Forms

The most important and easiest form is the message box:

import System.Windows.Forms;

MessageBox.Show("This is a message box");

But there are plenty of other opportunities to design very personal forms including buttons

and check boxes and much more.

7.11

System.IO



The System.IO namespace contains classes that provide all kinds of input and output rou-

tines, such as serialization (which helps storing data of instants of classes). As an example

we will consider the TextWriter class, which can be helpful to save evaluation data of spectra

in plain text to files:

using System;

using System.IO;

var filename = "MyFile.txt";

StreamWriter sr = File.CreateText(filename);

sr.WriteLine ("I am the text in this file.");

sr.Close();

7.12

System.Threading



In the System.Threading namespace, the class thread allows to start more than one threads

to execute a portion of your program. A thread is a sequence of instructions. Multiple

threads allow parallel computing, comparable to multitasking of programs. For example

32



you could create two threads, one to measure data, another to do simple math like offset

corrections, etc. on all recorded spectra. A sample script about threading is explained in

section 12.5

33



Part III

Collection of JScript

applications

34



Yüklə 0,62 Mb.

Dostları ilə paylaş:
1   ...   4   5   6   7   8   9   10   11   ...   21




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə