source: trunk/FACT++/scripts/Observation_class.js@ 14767

Last change on this file since 14767 was 14765, checked in by neise, 12 years ago
introduced new class to generate the schedule - called Observation. Now the list of observations can be filled with Ratescans loocking on source-names as well as ratescans looking at specific ra-dec-coordinates.
File size: 2.2 KB
Line 
1'use strict';
2
3/* **************
4 * this file contains just the implementation of the
5 * Observation class (I know there are no classes in javascript...)
6 */
7
8// Constructor
9function Observation ( oArg ) {
10
11 if (oArg['date'])
12 {
13 // FIXME: Check transisiton from summer- and winter-time!!
14 var utc = new Date(oArg.date);
15 if (isNaN(utc.valueOf()))
16 {
17 throw new Error(startDateString+' is not a valid Date String.'+
18 ' Try something like "2013-01-08 23:05 UTC" .');
19 }
20 this.utc = utc
21 }
22 else
23 {
24 throw new Error("Observation object must have a 'date' parameter");
25 }
26
27 if (oArg['task'])
28 this.task = oArg.task.toUpperCase()
29 else
30 this.task = 'DATA'
31
32 if (oArg['source'])
33 this.source = oArg.source
34 else
35 this.source = undefined
36
37 if (oArg['ra'])
38 this.ra = oArg.ra
39 else
40 this.ra = undefined
41
42 if (oArg['dec'])
43 this.dec = oArg.dec
44 else
45 this.dec = undefined
46
47
48
49 switch( this.task)
50 {
51 case 'DATA':
52 if (this.source == undefined)
53 throw new Error(
54 "Observation must have either 'source' or 'task' " +
55 "if 'task' == 'data' it must have also have 'source' ");
56 break;
57 case 'STARTUP':
58 if ( this.source != undefined)
59 {
60 console.out("warning. Observation with task='startup' also has source defined");
61 }
62 break;
63 case 'SHUTDOWN':
64 if ( this.source != undefined)
65 {
66 console.out("warning. Observation with task='shutdown' also has source defined");
67 }
68 break;
69 case 'RATESCAN':
70 if ( this.source == undefined && (this.ra == undefined || this.dec == undefined) )
71 {
72 throw new Error(
73 "Observation must have either 'source' or 'ra' & 'dec' " +
74 "if 'task' == 'ratescan'");
75 }
76 }
77
78
79}
80
81// method toString()
82Observation.prototype.toString = function()
83{
84 return this.source+" ["+this.utc+"]" ;
85}
Note: See TracBrowser for help on using the repository browser.