function aurinko(lat,lon)
{
time = new Date();
var y = time.getFullYear();
var m = time.getMonth()+1; //Bug!!
var d = time.getDate();
var h = time.getHours();
var min = time.getMinutes();
var s = time.getSeconds();
var tz = time.getTimezoneOffset();
if (tz != 0) tz /= 60;
var juliantime;
juliantime = dispMath.MakeJulianDate(y,m,d,h+tz,min,s);
SolarValues = dispMath.GetSZA(juliantime,lat,lon);
return(SolarValues);
}
// create empty spectra in the Specbar of DOASIS
function MakeSpec(specname)
{
newspec = dispTools.GetSpectrum(specname);
newspec.Name = specname;
newspec.MinChannel = 2;
newspec.maxchannel = 2048;
return(newspec);
}
// calculates integration time and records spectra
function TakeSpectrum(angle)
{
specPath = MFCPath;
StopCheck();
for (l=0;l
{
if (angle == AngleSeries[l])
{
measspec = straylight[l];
if (angle != currentelevation)
{
MotorMoveToPos(angle);
currentelevation = angle;
}
}
}
dispTools.CurrentSpectrum = offset0;
if (offset0.Average < 100)
specOOI.Scan(offset0,100,3);
// measure offset spectrum
window.Sleep(waitscan);
dispTools.CurrentSpectrum = measspec;
specOOI.Scan(measspec,1,t);
// measure test spectrum
window.Sleep(waitscan);
79
dispMath.Correctoffset(measspec,offset0)
// correct measspec for offset
// determine integration time
while (measspec.Max > sat)
{
StopCheck();
t = (parseInt(0.8 * t));
window.Status = "IT= "+t;
if (t < 3)
{
t = 3;
break;
}
specOOI.Scan(measspec,1,t);
window.Sleep(waitscan);
dispMath.Correctoffset(measspec,offset0)
}
specOOI.Scan(measspec,1,t);
window.Sleep(waitscan);
while (measspec.Max < (0.8*sat))
{
StopCheck();
t = (parseInt((1.2 * t)+0.5));
window.Status = "IT= "+t;
if (t > tmax)
{
t = tmax;
break;
}
// the integration time has been determined with t
// the number of scans still has to be calculated
specOOI.Scan(measspec,1,t);
window.Sleep(waitscan);
dispMath.Correctoffset(measspec,offset0)
}
// calculate the number of scans s
s = parseInt(ttotal/t);
if (s>smax)
{
s=smax;
}
if (s < 1)
{
s=smin;
}
// now s has been determined
dispIO.PathSplitting(1,specPath,100);
dispIO.AutoFileNumber( 1,CampInit,6,1);
i = dispIO.AutoFileNumberFindLastIndex() + 1;
window.Status = "Taking spectrum #" + i + "
" + s + "x" + t +"ms @ "+angle+"
◦
";
// the actual spectrum, which will be used for evaluation later is recorded now!
specOOI.Scan(measspec,s,t);
window.Sleep(waitscan);
//
StoreADCValues(measspec);
80
measspec.CalibPolynomialOrder = 2;
measspec.CalibPolynomial[0] = CalZero;
measspec.CalibPolynomial[1] = CalFirst;
measspec.CalibPolynomial[2] = CalSecond;
measspec.Site = MeasSite;
// the spectrum is now saved!!!!!!!!
dispIO.Save(measspec);
// check if the file of the spectrum exists
if (CheckFileSize(measspec.FileName))
WriteToLog(DoasLog, measspec.FileName+" looks ok - IT was " + s
+ " scans at" + t + " ms");
// modify integration for next spectrum if spectrum was over- or undersaturated
if ((measspec.Max/s) > sat)
{ t = parseInt(0.8 * t)
}
if ((measspec.Max/s) < (0.8*sat))
{
t = parseInt(1.2 * t);
}
// checks, if stored spectrum shows signal
CheckIfSpecOk(measspec);
i++;
}
function TakeOffsetDarkCurrent()
{
StopCheck();
specPath=OSDCPath;
window.Status = "Offset spectrum 1: " + sOS + " x " + tOS + " ms";
// measure offset or dark current depending on given parameters (see function below)
OSDC(offset1,100,sOS,tOS);
window.Status = "Offset spectrum 2: " + sOS + " x " + tOS + " ms";
OSDC(offset2,100,sOS,tOS);
window.Status = "Dark current spectrum 1: 1 x " + tDC + " ms";
OSDC(dark1,200,1,tDC);
window.Status = "Dark current spectrum 2: 1 x " + tDC + " ms";
OSDC(dark2,200,1,tDC);
window.Status = "Went for a nap - " + tNap/60000 + " min ... See you soon!!!";
window.Sleep(tNap);
StopCheck();
}
// measure offset or dark current
function OSDC(spec,wl,ss,tt)
{
StopCheck();
dispTools.CurrentSpectrum = spec;
specOOI.Scan(spec,ss,tt);
window.Sleep(waitscan);
StoreADCValues(spec);
spec.Wavelength1=wl;
dispIO.PathSplitting(1,specPath,100);
dispIO.AutoFileNumber( 1,CampInit,6,1);
o = dispIO.AutoFileNumberFindLastIndex() + 1;
dispIO.Save(spec);
81
if (CheckFileSize(spec.FileName))
WriteToLog(DoasLog, spec.FileName+" looks ok");
o++
StopCheck();
}
// store the values of the analog digital converter (Temperature, Voltage....)
function StoreADCValues(spec)
{
CheckIfSpecOk(spec);
ADCVal[0] = dispHMTUSB.ADC(0)/100;
//UBatt
ADCVal[1] = dispHMTUSB.ADC(1);
//USteuer
ADCVal[2] = (dispHMTUSB.ADC(2)-2048)/50;
//Tcold
ADCVal[3] = dispHMTUSB.ADC(3)/50;
//Twarm
ADCVal[4] = (dispHMTUSB.ADC(4)-2048)/50;
//Tset
ADCVal[5] = dispHMTUSB.ADC(5)/1000;
//IPelt
ADCVal[6] = dispHMTUSB.ADC(6);
WriteToLog(AdcLog, ADCVal[0] + "; " + ADCVal[1] + "; " + ADCVal[2]
+ "; " + ADCVal[3] + "; " + ADCVal[4] + "; " + ADCVal[5] + "; " + ADCVal[6]);
var RAWADC = new Array();
for (m=0;m<6;m++)
RAWADC[m] = dispHMTUSB.ADC(m);
spec.Latitude=Latitude;
spec.Longitude=Longitude;
Tcold = ADCVal[2]
spec.Temperature=Tcold;
if (Math.abs(Tcold-Tini) > 1)
{dispHMTUSB.Temperature = Tini;
WriteToLog(DoasLog, "Set Temperature " + Tini + " deg C, not Reached!
Set Temp new to ADC Controller.");
}
}
function MotorMoveToPos(angle_L)
{
var pos = parseInt(angle_L/90*MotorStep90) + MotorHorizontalPosition;
dispHMTUSB.MoveToPos(1,pos);
window.Sleep(waitmotor);
var Position = dispHMTUSB.GetMotorPosition(1);
window.Sleep(waitmotor);
if (Position == pos)
WriteToLog(DoasLog, "Motor position "+pos+" ("+angle_L+"
◦
) reached");
else
WriteToLog(DoasLog, "Motor position "+pos+" not reached. Motor responds "+Position);
}
function MotorMoveHome()
{
dispHMTUSB.MoveHome(1);
window.Sleep(waitmotor);
if (dispHMTUSB.GetMotorStatus(1)==3)
WriteToLog(DoasLog, "Home Position reached");
else
82
{
WriteToLog(DoasLog, "Home Position not reached");
return;
}
window.Sleep(waitmotor);
if (dispHMTUSB.GetMotorPosition(1)==0)
WriteToLog(DoasLog, "Home Position set to 0");
else
{
WriteToLog(DoasLog, "Home Position not 0");
return;
}
StopCheck();
}
function WriteToLog(file,message)
{
window.Status = "log> " + message;
var out=file.OpenAsTextStream(8);
out.WriteLine(UTCDate() + " ; " + message);
out.Close();
}
//returns the date e.g. as 05.06.2008 12:05:32
function UTCDate()
{
var d, s="";
var day,month,hours,min,sec;
d = new Date();
day = d.getUTCDate();
if (day.toString().length == 1) day = "0" + day;
s += day + ".";
month = d.getUTCMonth()+1;
if (month.toString().length == 1) month = "0" + month;
s += month + ".";
s += d.getUTCFullYear()+" ";
hours = d.getUTCHours();
if (hours.toString().length == 1) hours = "0" + hours;
s += hours + ":";
min = d.getUTCMinutes();
if (min.toString().length == 1) min = "0" + min;
s += min + ":";
sec = d.getUTCSeconds();
if (sec.toString().length == 1) sec = "0" + sec;
s += sec;
return(s);
}
// check if spectrum contains signal
function CheckIfSpecOk(spectrum)
{
if (spectrum.Average == 0e-20)
{
WriteToLog(DoasLog, "Average is ZERO");
83
WriteToLog(DoasLog, "No Spectrum taken, intensity is
zero due to an error! New initialisation of HMT device");
window.Sleep(1000);
InitHMT()
}
}
// check if file saved spectrum actually exists
function CheckFileSize(filespec)
{
fullname = specPath + "\\" +filespec.substr(0,6)+"00\\"+filespec;
System.Console.WriteLine(fullname);
f = dispFileSystem.GetFile(fullname);
if (f.size == 0)
WriteToLog(DoasLog, f.Name + " has " + f.size + " bytes. Restart DOASIS");
else
return(f.size);
}
// check, if stop button in Script window has been pressed
function StopCheck()
{
if (window.CheckStop())
{
WriteToLog(DoasLog, "Stopped");
return;
}
}
main();
12.6.4
Remarks:
• The motor status checked by the command
dispHMTUSB.GetMotorStatus()
can have the values:
–
0: motor stopped
–
1: motor is moving
–
2: positive end reached
–
3: negative end (homing position) reached
• The command window.sleep() is used frequently in the script. It helps to guarantee
reliable data transfer between computer and measurement instrument (see Tips and
Tricks of section 4.5).
84
Chapter 13
Literature
JScript Reference Microsoft
http://msdn.microsoft.com/en-us/library/x85xxsf4.aspx
JScript Textbooks
• Rogers, Justin (2002). Microsoft JScript .NET Programming. Indianapolis: SAMS
• Stone, M. (1996). How to Program Microsoft Jscript, Scripting Interface: Ziff Davis
• Jaworski, J. (1999). Mastering JavaScript and JScript (Mastering). London: Sybex
Inc.
Google
The best way to google for JScript commands is to type:
“msdn2 + command”
For example:
“msdn2 ToString”
returns as the first link the page:
http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx
which should hopefully be exactly what you want.
85
Index
ActiveXObject, 38, 66, 74
AND, 18
AppendResultToFile, 58
AutoFileName, 28, 42
errors related to, 45
Open, 43
Save, 43
automatic start of JScript, 10
automized measurements, 70
backslash, 27
batch file, 9
baud rate, 52
boolean, 18
break, 36
CalcSZA, 26
calculate
integration time, 30
calibration
polynomial, 48
wavelength, 48
calibration polynomial, 29
catch, 67
check box, 32, 69
ChiSquare
display, 59
class, 71
colon, 20
comments, 14
Console, 31
correct
offset and dark current, 25, 55
CorrectDarkCurrent, 55
CorrectOffset, 55
crash
avoid, 10
CurrentFileNumber, 44
data transfer, 10
data types, 15
conversion, 15
lost of, 16
date
get, 39
DateTime, 45
decimal numbers, see digits
Device, 27, 54
digits
control, 40
directory
create, 37
DoasCore, 23
IO, 28
DoasCore.Spectra, 13
DoasFit, 26, 59
DoasFitReferenceInfo, 59
driver, 74
else if, 19
equals, 20
Excel
ActiveXObject, 66
create worksheet, 65
write data into sheet, 65
exception handling, 67
factorial, 21
false, 18
FileSystemObject, 38
find peak of spectrum, 29
FindLastIndex, 43
fit, 26, 58, 69
access properties, 63
fit coefficient
display, 58
fit range, 61
fit result
show, 58
fit scenario, 26, 58
active/deactivate spectra, 59
modify, 59
number of spectra, 59
replace spectrum, 59
set fit range, 61
FitCoefficientError
display, 59
fix parameter, 62
for loop, 20
for..in-loop, 21
Forms, 32
86
functions, 21, 57
g5, 41
GetSpectrum, 25
google, 85
GPS, 51
handshake, 52
hardware
communication with, 51
Hello World, 12, 35
HMI, 31, 36
if..else, 18
import, 14
input, 32
input/output, 28
InstallerHMTActiveXControll, 74
InstallerHMTUSBDriver, 74
internet, 85
IO, 38
ISpectrum, 29, 42, 45
members, 29
JScript project file, 9, 49, 56
jsp, see JScript project file
Julian, 47
JulianDateTime, 25, 47
LAZ, see lunar azimuth angle
LimitHard, 61
link parameter, 62
lunar azimuth angle, 48
lunar zenith angle, 48
LZA, see lunar zenith angle
main function, 74
marker, 29
Math, 25
message box, 32, 37
MinChannel, 29
Mini Scripts, 13
MiniDOAS
control, 54
MiniDoas, 73
minus, 17
namespace, 12
namespaces
overview, 23
NaN, 17
notation
scientific, 41
object orientation, 12, 57
ObjectKey, 25, 45, 62
Ocean Optics, 53
control two, 54
OldUI, 36
OpenTextFile, 39
operators, 17
list of, 17
logical, 18
OR, 18
Origin, 39
parity, 52
plus, 17
port, 52
PrepareFitResultSpectrum, 58
Progress Bar, 31
Project file, 9
project files, see JScript project file
question mark, 20
ReadLine, 32
ReferencesInfo, 61
residual
save, 62
ResultSpectrum, 63
run several JScripts, 9
SaveAs, 29
SAZ, see solar azimuth angle
Scan
OceanOptics, 28, 53
ScanGeometry, 25, 47
scanning
automized, 70
Script, 30
semicolon, 12
serial port
communication with, 51
SetCoefficientDefault, 61
SetCoefficientHighLimit, 61
SetCoefficientLowLimit, 61
SetCoefficientLowMode, 61
shift
display, 59
limit parameter, 61
sleep, 36, 84
solar azimuth angle, 48
solar zenith angle, 25
calculate, 47
Specbar, 13, 29
SpecMath, 25
Spectra, 28
spectrograph
control, 53
87
control two, 54
serial number, 53
spectrum
file name, 59
measure, 53
modify, 29
name, 13
open, 41
optimize, 30
properties, 45
save, 41
Squeeze
display, 59
limit, 62
start JScript, 5
Stop button, 31
StopAllScripts, 30
stopbits, 52
String, 12
syntax, 14
System, 12, 31, 35
IO, 32
SZA, 25, see solar zenith angle
TargetSpectrum, 63
text file, 32
create, 38
textbooks, 85
Threading, 32, 36, 71
time
compare, 45
get, 39
TimeSpan, 45
true, 18
type mismatch, 17
variable
case sensitive, 14
conversion, 15
declare, 13
initialize, 17
type, 44
types, 13
variables
display, 35
vectors, 64
wait, 36, 84
while loop, 21
WriteLine, 12, 35
88
Document Outline - I Introduction
- What is JScript?
- For whom this Tutorial is written
- What is special about this Tutorial?
- Tips and Tricks
- The help menu of DOASIS
- Structuring a JScript program by creating a JScript Project File
- Running several JScripts after each other
- Starting a JScript automatically after a hardware reboot
- Avoiding inexplicable program crashes
- II The basics of JScript
- First steps in JScript
- A first example
- A word on "object-orientation"
- A second example
- The syntax
- Programming in JScript
- Data Types and Type Conversion
- Operators
- Program Flow
- if..else-statements
- for-Loops
- for..in-Loops
- while-Loops
- Functions
- Important DOASIS-namespaces and their usage
- Overview
- DoasCore.Math
- DoasCore.Math.SpecMath
- DoasCore.Math.ScanGeometry, DoasCore.Math.JulianDateTime
- DoasCore.Math.DoasFit
- DoasCore.Device
- DoasCore.IO
- DoasCore.Spectra
- DoasCore.Spectra.ISpectrum
- DoasCore.Spectra.Specbar
- DoasCore.Script
- DoasCore.HMI
- System
- System.Console
- System.Windows.Forms
- System.IO
- System.Threading
- III Collection of JScript applications
- Simple JScripts
- Hello World
- Diplaying variables in the Output window.
- Wait functions
- Display message boxes
- Creating a directory
- Creating a text file
- Get the current date and time
- Control number of digits
- Open and Save a spectrum
- Saving spectra with the ``AutoFileName''-class
- Opening spectra with the ``AutoFileName''-class
- Modifying the properties of a spectrum
- How to compare the time of different spectra
- Calculate the solar zenith angle (SZA)
- A word on the class ScanGeometry
- Wavelength Calibration
- JScript Project File
- JScripts communicating with hardware
- Reading in data from a serial port (e.g. GPS data)
- Measure a spectrum with an Ocean Optics spectrograph
- Operate two Ocean Optics spectrographs
- Mini-MAX-DOAS (MiniDOAS) control via JScript
- Evaluating spectra
- Offset and Dark Current Correction
- Offset and Dark Current Correction with a ``JScript project file''
- Preparation
- The ``project file``
- The file variables.js
- The file functions.js
- The file maincorrect.js
- Fitting with JScript
- Modifying a fit scenario with JScript
- Save the residual of the fit result
- Advanced JScripts
- Write spectrum data to an Excel-Sheet
- Exception handling
- Evaluate data with a fit scenario file
- Automatized scanning
- Threading
- Controlling Mini-MAX-DOAS (MiniDOAS) instruments with JScript
- Structure of the program
- Description of the tasks
- Prerequisites
- Remarks:
- Literature
- Index
Dostları ilə paylaş: |