Changeset 15004 for trunk/FACT++


Ignore:
Timestamp:
03/09/13 16:27:00 (12 years ago)
Author:
tbretz
Message:
Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/scripts/Observation_class.js

    r14770 r15004  
    11'use strict';
    22
    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//
    77
    8 // Constructor
    9 function Observation ( oArg ) {
     8function 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;
    1027   
    11     if (oArg['date'])
     28    switch (this.task)
    1229    {
    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.");
    2155    }
    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    
    8356}
    8457
    8558// method toString()
    8659Observation.prototype.toString = function()
    87 { 
     60{
    8861    if (this.source)
    8962        return this.task + "  " + this.source+" ["+this.start+"]" ;
    9063    else
    9164        return this.task + " ["+this.start+"]" ;
    92 
    9365}
Note: See TracChangeset for help on using the changeset viewer.