import System;
import DoasCore.Spectra;
// IO stands for input/output operations
// AutoFileName is a class of the DoasCore.IO namespace
import DoasCore.IO;
// create the AutoFileName object and store it in the varible afn
var afn :
AutoFileName = new AutoFileName();
// specify the path where the spectra should be stored in, the path should
// exist already, it is not created by the script
afn.BasePath = "c:
\\scripttest";
// Prefix defines the symbols before the digits
afn.Prefix = "S";
// Suffix defines the symbols after the digits, usually related to the file type
afn.Suffix = ".sp2";
// Number of Digits to be used
afn.NumberOfDigits = 7;
// Number of files to be stored in one folder
afn.FilesPerFolder = 100;
// store current spectrum in the variable Spec
var Spec:
ISpectrum = Specbar.CurrentSpectrum;
// see comment below
afn.FindLastIndex();
// save spectrum with the new index number
afn.Save(Spec);
8.10.1
A word on AutoFileName()
• In this class many things are done intrinsically. Here are some examples:
–
The method “FindLastIndex” looks for the last already existing index number
and then sets the property “CurrentFileNumber” one higher.
–
The property “CurrentFileNumber” of the “AutoFileName”-class was not used
directly in the example above, but the meaning is quite simple. See example 8.11
–
The method “Save” saves a Spectrum and then increases the “CurrentFileNum-
ber” counter by one.
• More Information concerning the “AutoFileName”-class can be found in the Program-
ming Documentation in the Help menu of DOASIS
8.11
Opening spectra with the “AutoFileName”-class
In the following example the property “CurrentFileNumber” of the “AutoFileName”-class
will be used to open a specific spectrum. When data has been collected for a very long pe-
riod of time, several thousand spectra can easily accumulate. Opening specific spectra out
of this huge amount can be quite annoying and tiring. Therefore a script is presented here,
43
that opens a single spectrum. The spectrum number is asked for in the Output window.
The demanded spectrum will be opened and some details of the spectrum like “Current-
FileNumber”, “ExposureTime” and “AzimuthAngle” are displayed in the Output window.
The spectra have to be stored in the folder C:\scripttest\S0000000. The spectra themselves
must have names like S0000000.sp2, S0000001.sp2, S0000002,.... This is the same structure
as how they are stored, when automatic measurements are taken.
import System;
import DoasCore.Spectra;
import DoasCore.IO;
var SpectrumNumber;
var Spec:
ISpectrum;
// see section 8.10.1 for "AutoFileName"-class
var afn :
AutoFileName = new AutoFileName();
afn.BasePath = "C:
\\scripttest\\";
afn.Prefix = "S";
afn.Suffix = ".sp2";
afn.NumberOfDigits = 7;
afn.FilesPerFolder = 100;
// ask for the spectrum number in the Output window
Console.WriteLine("Open spectrum with the number:");
// store the number that is typed in the variable "SpectrumNumber"
SpectrumNumber = Console.ReadLine();
// add a new empty spectrum sheet to the "Specbar"
// the name of the spectrum is the spectrum number, that was specified before
Spec = Specbar.GetSpectrum(SpectrumNumber);
// the property "CurrentFileNumber" of the "AutoFileName" class
// is set to "SpectrumNumber"
afn.CurrentFileNumber = SpectrumNumber;
// open the spectrum with the demanded spectrum number into the empty
// Spectrum "Spec"
afn.Open(Spec);
// display some properties of the opened spectrum in the Output window
Console.WriteLine(
" Spectrum:
"+SpectrumNumber+
" ExposureTime:
"+Spec.ExposureTime+
" AzimuthAngle:
"+Spec.AzimuthAngle);
Remarks
• Referring to the line
var Spec:
ISpectrum;
:
It would be enough as well to write
var Spec
;
only. In JScript, the type of the variable doesn’t have to be declared most of the
times. But sometimes, it is useful to declare the type of the variable explicitly. See
8.14, where the variable “time” has to be of the type “System.DateTime”.
44
• If the script doesn’t open any spectrum when calling the line
afn.Open()
;
the problem often is a mistake in the declaration of the “AutoFileName” properties
(e.g. “BasePath”,“ Prefix”,...) and it is worth checking those very carefully.
In order to proof, if the problem is actually caused by the “afn.Open()” method, dis-
play the return value of this method in the Output window. The following command
can be placed in the script:
Console.WriteLine(afn.Open(Spec))
;
“True” is displayed if the file could be opened and “false” if not.
8.12
Modifying the properties of a spectrum
The following script displays the “ObjectKey” (see Fig. 8.1) of the active spectrum sheet
in the Output window, changes it to “Nice spectrum” and displays the new ObjectKey in
the Output window. Other properties can be changed similarly.
import System;
import DoasCore.Spectra;
// The spectrum in the active spectrum sheet is stored in the variable "MeasSpec"
var MeasSpec = Specbar.CurrentSpectrum;
// Display the old object key
Console.WriteLine("Old object key:
"+MeasSpec.ObjectKey);
// Change the object key
MeasSpec.ObjectKey = "Nice spectrum";
// Display the new object key
Console.WriteLine("New object key:
"+MeasSpec.ObjectKey);
Remarks
Other spectrum properties like StartDate, StartTime, ExposureTime, NumScans etc. can
be accessed in the same way. For a list of all spectrum properties search for “ISpectrum” in
the Programming Documentation of DOASIS (Help - Programming Documentation).
8.13
How to compare the time of different spectra
It is possible to compare the date and time of spectra. This can be helpful e.g. when
selecting a reference spectrum as close to the measurement spectrum as possible. To com-
pare the spectrum start times the function “TimeSpan.Compare” is used. To compare the
“StartTimeAndDate” the function “DateTime.Compare” is used. Both are provided by the
“System” namespace. In the example script, the “AutoFileName” structure of section 8.11
is used.
45
Dostları ilə paylaş: |