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

Last change on this file since 14970 was 14770, checked in by neise, 12 years ago
renamed utc member to 'start', since it's used by this name in Main.js. Also adapted Observation.toString() to the new task/source structure.
File size: 2.5 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.start = 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 break;
77 default:
78 throw new Error(" the task of this observation:"+this.task+
79 "is not implemented. use one of: DATA, STARTUP, SHUTDOWN, RATESCAN.");
80 }
81
82
83}
84
85// method toString()
86Observation.prototype.toString = function()
87{
88 if (this.source)
89 return this.task + " " + this.source+" ["+this.start+"]" ;
90 else
91 return this.task + " ["+this.start+"]" ;
92
93}
Note: See TracBrowser for help on using the repository browser.