Jscript Tutorial Wolfgang Unger and Tobias Sommer



Yüklə 0,62 Mb.
Pdf görüntüsü
səhifə12/21
tarix07.11.2018
ölçüsü0,62 Mb.
#78679
1   ...   8   9   10   11   12   13   14   15   ...   21

Figure 8.1: The property window of the spectrum.

import System;

import DoasCore.Spectra;

import DoasCore.IO;

// add two new empty spectrum sheets to the "Specbar"

var Spectrum1 = Specbar.GetSpectrum("Spectrum1");

var Spectrum2 = Specbar.GetSpectrum("Spectrum2");

// use the same "AutoFileName" structure as in example 8.11

var afn :

AutoFileName = new AutoFileName();

afn.BasePath = "C:

\\scripttest\\";

afn.Prefix = "S";

afn.Suffix = ".sp2";

afn.NumberOfDigits = 7;

afn.FilesPerFolder = 100;

// the method "FindFirstIndex()" returns the number of the first existing file

afn.CurrentFileNumber = afn.FindFirstIndex();

// open the first spectrum and increase the "CurrentFileNumber" by one

afn.Open(Spectrum1);

// open the next spectrum

afn.Open(Spectrum2);

// display the date and time, when the spectra were recorded

Console.WriteLine("Spectrum1:

"+Spectrum1.StartDateAndTime);

Console.WriteLine("Spectrum2:

"+Spectrum2.StartDateAndTime);

// check which spectrum has been recorded first

if (DateTime.Compare(Spectrum1.StartDateAndTime, Spectrum2.StartDateAndTime) > 0)

Console.WriteLine("Spectrum1 was recorded later than Spectrum2.")

else if (DateTime.Compare(Spectrum1.StartDateAndTime, Spectrum2.StartDateAndTime) == 0)

Console.WriteLine("Spectrum1 was recorded at the same time as Spectrum2.")

else

Console.WriteLine("Spectrum1 was recorded before Spectrum2.")



46


The output can look like this:

Spectrum1: Sun Jul 1 11:31:10 UTC+1 2007

Spectrum2: Sun Jul 1 11:31:12 UTC+1 2007

Spectrum1 was recorded before Spectrum2.

8.14

Calculate the solar zenith angle (SZA)



In order to calculate the solar zenith angle, we need latitude, longitude and time. In this

example, latitude and longitude are defined in the code and time is read out of the spectrum,

that is active when the script is executed.

import System;

import DoasCore.Spectra;

import DoasCore.Math;

// store the active spectrum in the variable Spec

var Spec:

ISpectrum = Specbar.CurrentSpectrum;

// StartDateAndTime provides the time the spectrum was recorded

var time = Spec.StartDateAndTime;

var SZA;


// calculate julian date and store it in the var Julian

var Julian = new JulianDateTime(System.DateTime(time));

// create ScanGeometry class for SZA calculation

var S = new ScanGeometry();

// feed it with lat, long, and time

S.Latitude = 49.4167;

S.Longitude = 8.7;

S.JulianDate = Julian;

// calculate SZA

S.CalculateSZA();

// store it in the var SZA

SZA = S.SZA;

// displays the SZA on the screen

System.Console.WriteLine("SZA="+SZA);

Remarks

• When “JulianDateTime” is called, it has to be made clear, that the argument time is



of the type “System.DateTime”, because another type would call a different routine.

In this case, “StartDateAndTime” of the spectrum is stored in the variable “time”,

then “time” is specified to be of the type “System.DateTime” and then delivered to

the class “JulianDateTime”, that afterwards returns the julian date.

47



8.14.1

A word on the class ScanGeometry

• This class offers calculations of solar and lunar zenith angle (sza, lza) and solar and

lunar azimuth angle (saz, laz).

• It is provided by the DoasCore.Math namespace

• You can find the whole functionality of the class, if you search for ScanGeometry in

the Help menu of the Programming Documentation of DOASIS

8.15


Wavelength Calibration

Just open a spectrum and run the script. You will see that wavelength information will

be added or modified in your spectrum. Therefore a polynom of order 2 is used and the

coefficients are defined in the script. Mathematically it looks like this:

λ

= c


0

+ c


1

· x + c


2

· x


2

λ

is the wavelength, c



i

are the coefficients and x is the channel.

import DoasCore.Spectra;

var Spec :

ISpectrum = Specbar.CurrentSpectrum;

Spec.CalibPolynomialOrder = 2;

Spec.CalibPolynomial[0]= 297.51431;

Spec.CalibPolynomial[1]= 0.12086;

Spec.CalibPolynomial[2]= -9.60429e-6;

48



Chapter 9

JScript Project File

Using JScript Project Files (jsp-files) to structure JScripts is very recommendable as it saves

a lot of work. Variables and functions are declared once in a separate JScript file and can be

used later on by simply calling these files in the JScript Project before the “main” JScript,

in which the actual task is defined.

A typical project file would look like this:

// for path descriptions use always two backslashs!!

C:

\\scripttest\\generally\\variables.js



C:

\\scripttest\\generally\\functions.js

C:

\\scripttest\\evaluate\\mainevaluate.js



This project script can be saved as C:\scripttest\evaluate\evaluate.jsp. Be aware, that the

suffix of a project file is .jsp and not .js.

The idea:

In C:\scripttest\generally\variables.js, all variables are declared.

In C:\scripttest\generally\functions.js, all methods, that are used frequently are defined

here.


In C:\scripttest\evaluate\mainevaluate.js, the actual main routine is defined.

All three JScript files are executed after each other, as if the content was just written in one

script. The advantage is that for the next program, a similar project file can be written.

Here an example:

C:

\\scripttest\\generally\\variables.js



C:

\\scripttest\\generally\\functions.js

C:

\\scripttest\\correct\\maincorrect.js



The project script could be saved as: C:\scripttest\correct\correct.jsp.

Only the “main-function” has changed and the definitions of the variables and functions can

still be used. Therefore, the main routine will be shorter, it will be less work to write and

it provides better overview. Within DOASIS, instead of opening a script file with the suffix

.js, the project file (suffix .jsp) can be opened and executed.

49



Yüklə 0,62 Mb.

Dostları ilə paylaş:
1   ...   8   9   10   11   12   13   14   15   ...   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ə