Changeset 15004
- Timestamp:
- 03/09/13 16:27:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Observation_class.js
r14770 r15004 1 1 'use strict'; 2 2 3 / * **************4 * this file contains just the implementation of the 5 *Observation class (I know there are no classes in javascript...)6 */3 // 4 // this file contains just the implementation of the 5 // Observation class (I know there are no classes in javascript...) 6 // 7 7 8 // Constructor 9 function Observation ( oArg ) { 8 function Observation(obj) 9 { 10 if (typof(obj)!='object') 11 throw new Error("Observation object can only be constructed using an object."); 12 13 if (!obj.date) 14 throw new Error("Observation object must have a 'date' parameter"); 15 16 // FIXME: Check transisiton from summer- and winter-time!! 17 var utc = new Date(obj.date); 18 if (isNaN(utc.valueOf())) 19 throw new Error(obj.date+' is not a valid Date String.'+ 20 ' Try something like "2013-01-08 23:05 UTC" .'); 21 22 this.start = utc; 23 this.task = obj.task ? oArg.task.toUpperCase() : "DATA"; 24 this.source = obj.source; 25 this.ra = obj.ra; 26 this.dec = obj.dec; 10 27 11 if (oArg['date'])28 switch (this.task) 12 29 { 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 30 case 'DATA': 31 if (this.source == undefined) 32 throw new Error("Observation must have either 'source' or 'task' " + 33 "if 'task' == 'data' it must have also have 'source' "); 34 break; 35 36 case 'STARTUP': 37 if (this.source != undefined) 38 console.out("warning. Observation with task='startup' also has source defined"); 39 break; 40 41 case 'SHUTDOWN': 42 if (this.source != undefined) 43 console.out("warning. Observation with task='shutdown' also has source defined"); 44 break; 45 46 case 'RATESCAN': 47 if (this.source == undefined && (this.ra == undefined || this.dec == undefined)) 48 throw new Error("Observation must have either 'source' or 'ra' & 'dec' " + 49 "if 'task' == 'ratescan'"); 50 break; 51 52 default: 53 throw new Error(" the task of this observation:"+this.task+ 54 "is not implemented. use one of: DATA, STARTUP, SHUTDOWN, RATESCAN."); 21 55 } 22 else23 {24 throw new Error("Observation object must have a 'date' parameter");25 }26 27 if (oArg['task'])28 this.task = oArg.task.toUpperCase()29 else30 this.task = 'DATA'31 32 if (oArg['source'])33 this.source = oArg.source34 else35 this.source = undefined36 37 if (oArg['ra'])38 this.ra = oArg.ra39 else40 this.ra = undefined41 42 if (oArg['dec'])43 this.dec = oArg.dec44 else45 this.dec = undefined46 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 56 } 84 57 85 58 // method toString() 86 59 Observation.prototype.toString = function() 87 { 60 { 88 61 if (this.source) 89 62 return this.task + " " + this.source+" ["+this.start+"]" ; 90 63 else 91 64 return this.task + " ["+this.start+"]" ; 92 93 65 }
Note:
See TracChangeset
for help on using the changeset viewer.