Jscript Tutorial Wolfgang Unger and Tobias Sommer



Yüklə 0,62 Mb.
Pdf görüntüsü
səhifə18/21
tarix07.11.2018
ölçüsü0,62 Mb.
#78679
1   ...   13   14   15   16   17   18   19   20   21

var afnFile = new AutoFileName();

afnFile.BasePath = "C:\\scanTest";

afnFile.Prefix = "a";

afnFile.Suffix = ".std";

afnFile.FilesPerFolder = 100,

afnFile.NumberOfDigits = 5;

// look for the first existing file

afnFile.FindFirstIndex();

// create the spectrum object that will receive the scanned data

var specEval = Specbar.GetSpectrum("Eval");

// open the fit scenario

// in this case we need to define the complete namespace hierarchie,

// since another Math namespace exists in the System-library, too!

var fit = DoasCore.Math.DoasFit.Open("c:\\scanTest\\EvaluateExample.fs");

// repeat until the stop button was pressed and a file could be loaded

while(!Script.StopAllScripts && afnFile.Open(specEval))

{

// set the target spectrum for fitting



fit.TargetSpectrum = specEval;

// run the fit

if(fit.DoFit())

{

System.Console.WriteLine("Fit successful for spectrum " + specEval.FileName);



fit.AppendResultToFile("C:\\scanTest\\EvaluateResult.txt");

}

else



System.Console.WriteLine("Fit failed for spectrum " + specEval.FileName);

}

System.Console.WriteLine("Evaluate stopped.");



12.4

Automatized scanning

This example shows how to do an automated scanning for measurement spectra and save

them using successive file names. As well suggested by Stefan Kraus.

/* ScanExample.js

This example script gives an example about how to scan using the default spectrograph

and saves the measured spectra one after another using the AutoFileName scheme.

Author: Stefan Kraus

Version: 1.0 @ 10/28/2003 */

import System;

// use the System library of the .NET framework

import DoasCore;

// use the DoasCore library

import DoasCore.Device;

// use the Device namespace

import DoasCore.IO;

// use the Input-/Output namespace

70



import DoasCore.Script;

// use the Script namespace

import DoasCore.Spectra;

// use the Spectra namespace

// create the spectrograph device object

var spectrograph = new Spectrograph();

// create the AutoFileName object to store the files

var afnFile = new AutoFileName();

afnFile.BasePath = "C:\\scanTest";

afnFile.Prefix = "a";

afnFile.Suffix = ".std";

afnFile.FilesPerFolder = 100,

afnFile.NumberOfDigits = 5;

// look for the last existing file and set the file counter to the successor

afnFile.FindLastIndex();

// create the spectrum object that will receive the scanned data

var specScan = Specbar.GetSpectrum("Scan");

// repeat until the stop button was pressed

while(!Script.StopAllScripts)

{

// show some info in the Output window



System.Console.WriteLine("Scanning spectrum " +

afnFile.CurrentFileNumber.ToString() + "...");

// scan using a fixed number of scans and exposure time

spectrograph.Scan(specScan, 10, 1000);

afnFile.Save(specScan);

System.Console.WriteLine("Saved spectrum " +

afnFile.CurrentFileNumber.ToString() + "!");

}

System.Console.WriteLine("Scanning stopped.");



12.5

Threading

This example shows how to create multiple thread that run at once. Each thread can be

supplied with a different information. Also the usage of classes and object is shown.

// first include the default namespaces

import System;

import DoasCore;

import DoasCore.Spectra;

import DoasCore.Math;

// use the threading namespace of the .NET framework

import System.Threading;

// Create a class that represent the thread including any additional

// data required to start the thread. In our case the thread has

// one additional data elements: The internal variable ’objectInfoForThread’.

71



// The content of ’objectInfoForThread’ is set when the object is created.

// The example function that actually runs in a separate thread can access this

// additional information.

class ThreadTest

{

// an internal variable used to store the additional



// information for the thread

private var objectInfoForThread;

// This variable will store the thread object. Using this object

// we can control the thread (Start, Stop, Pause, ...)

private var threadWorker : Thread;

// this is the constructor of the object.

// whenever you create an object of this type with the

// new-operator this function will be called. In our case

// the contrutor requires one parameter. The data supplied

// here will be used by the thread.

function ThreadTest(info)

{

// store the additional information in the internal variable



objectInfoForThread = info;

// create the thread object. As soon as the thread is started

// is will run the function ’RunWorker’ in a separate thread.

// See .NET documentation System.Threading.Thread

// ’RunWorker’ is of the type ’ThreadStart’. This has to

// declared, since the ’Thread’ object has several constructors.

threadWorker = new Thread(ThreadStart(RunWorker));

}

// this function actually starts the thread that was created



// in the constructor

function StartThread()

{

threadWorker.Start();



}

// This function waits until the thread function terminates.

function WaitThreadFinished()

{

threadWorker.Join();



}

// This is the function that will run in a separarte thread as soon as the

// ’StartThread’ function is called. The thread will run until this function

// exits or you terminate the thread using the ’threadWorker’ object.

function RunWorker()

{

// just do something inside the thread



var i : int = 0;

while(i < 100)

{

// print the additional information supplied



72


Yüklə 0,62 Mb.

Dostları ilə paylaş:
1   ...   13   14   15   16   17   18   19   20   21




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

    Ana səhifə