Jscript Tutorial Wolfgang Unger and Tobias Sommer



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

6.3.3

for..in-Loops

import System;

var weekday = ["monday", "tuesday", "wednesday", "thursday"];

var j;

for (j in weekday) Console.WriteLine(weekday[j]);



6.3.4

while-Loops

The while-loops are similar to the for-loops, but the header of the while loop has no section

for initializing and no section for incrementation, but just the section for a comparison,

the while-condition. This of course only makes sense if the while-condition changes during

sweeping the while-loop. Here is an example:

import System;

var steps = 10;

while (steps >= 1)

{

if (steps > 1) Console.WriteLine(" There are" + steps + " to do.");



else Console.WriteLine("Now there is only one more step");

steps--;


}

6.4


Functions

In JScript it is possible to declare classes functions. A function is a piece of code that

is encapsulated and can be executed by calling the command under which the function is

defined. This has the advantage that code which is used in several places of the script has

only to be written once. For the declaration of classes see section 12.5.

Here is an example that calculates the factorial n! of the number n.

21



import System;

function factorial(n)

{

var i;


var f=1;

for (i=1;i<=n;i++) f=f*i;

return f;

}

Console.WriteLine(factorial(8));



The types of the parameters and the return parameter are not specified in the declaration

of the function (contrary to C/C++/C#). If your function shall not return anything, just

omit the return line. If your function takes no parameters, leave the brackets empty, but do

not forget the empty brackets ().

22



Chapter 7

Important DOASIS-namespaces

and their usage

7.1


Overview

All the DOASIS functionality is entailed in the DoasCore. There are six namespaces of inter-

est, which need to be imported in order do use its classes (i.e. objects and methods). These

are DoasCore.Math, DoasCore.Device, DoasCore.IO, DoasCore.Spectra, DoasCore.Script

and DoasCore.HMI. (compare Fig. 7.2).

We will also discuss some namespaces and classes that are offered by the .NET frame-

work, such as the System.Console that we already know from making outputs, the Sys-

tem.Windows.Forms which is useful to design forms like message boxes or dialogs (e.g. to

enter paramters), and the System.IO namespace that is used for file handling (compare Fig.

7.1). A complete list of all namespaces can be found here:

http://msdn2.microsoft.com/de-de/library/ms306608(vs.80).aspx

System


Windows

IO

Threading



Forms

Sp2File


Figure 7.1: The System namespaces and its classes (incomplete - only most common classes

listed)


23


DoasCore

Math


Device

IO

Spectra



Script

HMI


DoasFit

SpecMath


Scattering

ScanGeometry

JulianDateTime

Acton


OceanOptics

Spectrograph

ISpectograph

Sp2File


MFCFile

SpectrumFile

AutoFileName

Specbar


Spectrum

ISpectrum

Script

ProgressBar



UserInterfaceWriter

UserInterfaceReader

Figure 7.2: The Doasis namespaces and its classes (incomplete - only most common classes

listed)


24


7.2

DoasCore.Math

In this namespace you will find all kinds of mathematical operations provided by Doasis.

The classes that you can make use of are:

• DoasCore.Math.SpecMath: basic mathematical methods

• DoasCore.Math.DoasFit: fitting methods

• DoasCore.Math.Scattering: Ring and Raman spectrum calculation

• DoasCore.Math.ScanGeometry: SZA (solar zenith angle) support

• DoasCore.Math.JulianDateTime: Represents a date/time using the Julian date time.

7.2.1


DoasCore.Math.SpecMath

The first step in the evaluation of a recorded spectrum is to correct it: Offset and Dark

current have to be subtracted. This can be done at once to a great number of spectra by

using a JScript. Here, we are just interested in the method that is used to do the correction,

so for simplicity we suppose that the spectrum that shall be corrected and the offset- and

dark current-spectrum are loaded into the specbar.

import DoasCore.Spectra;

import DoasCore.Math;

var Offset:

ISpectrum = Specbar.GetSpectrum("Offset");

var Dunkel :

ISpectrum = Specbar.GetSpectrum("Dunkelstrom");

var Meas :

ISpectrum = Specbar.CurrentSpectrum;

SpecMath.CorrectOffset(Meas,Offset);

SpecMath.CorrectDarkCurrent(Meas,Dunkel);

In this example, ”Offset” and ”Dunkelstrom” are the object keys of the spectra by which

they can be identified. The methods CorrectOffset and CorrrectDarkCurrent are member

of the SpecMath class. To see more examples, read the glossary of the Doasis Tutorial.

7.2.2


DoasCore.Math.ScanGeometry, DoasCore.Math.JulianDateTime

Here is an example that calculates the SZA from the time (given in Julian date time) the

longitude, and the latitude:

25



function CalcSZA(Spectr)

{

var Julian = new JulianDateTime();



Julian = new JulianDateTime(Spectr.StartDateAndTime);

var S = new ScanGeometry();

S.Latitude = latitude;

S.Longitude = longitude;

S.JulianDate = Julian;

if (S.CalculateSZA()) return(S.SZA);

}

7.2.3


DoasCore.Math.DoasFit

With the class DoasCore.Math.DoasFit one is able to construct fit-scenarios and start fit

procedures. Here is an example of how to do fit-scenarios (how to evaluate data with fit

scenarios in JScript is shown in section 12.3).

26



Yüklə 0,62 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   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ə