source: trunk/yao/src/YAOObjects/Trajectory.hpp @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 5.6 KB
Line 
1//! \file    Trajectory.hpp
2//! \brief   Declaration and implementation of the Trajectory class, which
3//!          handles model (time) trajectories.
4//! \version 2007/10/01 (yyyy/mm/dd)
5//! \author  Luigi Nardi <luiginardi(at)gmail.com>
6//
7// This file is part of YAO, a framework for variational assimilation in
8// numerical models.
9// Copyright (c) 2001-onwards LOCEAN. All rights reserved.
10//
11// This program may be redistributed and/or modified under the terms of the GNU
12// General Public License as published by the Free Software Foundation, either
13// version 2 of the license, or (at your option) any later version.
14//
15// This program is provided AS IS and WITHOUT ANY WARRANTY, including any
16// implied warranty of DESIGN, MERCHANTABILITY or FITNESS FOR A PARTICULAR
17// PURPOSE.
18
19
20#ifndef YAO_TRAJECTORY_HPP_INCLUDED
21#define YAO_TRAJECTORY_HPP_INCLUDED
22
23//#include "../help/Enforcer.hpp"
24#include "Object.hpp"
25
26namespace yao{
27
28  //! Trajectory class, handles model (time) trajectories.
29  class Trajectory: public Object{
30
31    public:
32
33      typedef char Type; //!< Supported types: any alphabetical letter is admitted.
34
35      /**
36       * Default constructor.
37       * @param aName is the name of the trajectory.
38       * @param aBoot is the number of boot steps (so-called uptime), is the initialization time.
39       * @param aSize is the total number of steps (so-called nbsteptime).
40       * @param aStep is the time step (so-called dtime).
41       * @param anOffset is the Time offset (so-called offtime).
42       * @param aType is a label for the trajectory.
43       */
44      Trajectory(const std::string& aName="", int aBoot=0, int aSize=1, double aStep=1, double anOffset=0, char aType='M');
45
46      /**
47       * Get the boot number of the trajectory.
48       * @return the boot number.
49       */
50      int getBoot() const { return theBoot; }
51
52      /**
53       * Get the size number of the trajectory.
54       * @return the size number.
55       */
56      int getSize() const { return theSize; }
57
58      /**
59       * Get the step number of the trajectory.
60       * @return the step number.
61       */
62      double getStep() const { return theStep; }
63
64      /**
65       * Get the offset number of the trajectory.
66       * @return the offset number.
67       */
68      double getOffset() const { return theOffset; }
69
70      /**
71       * Get the type label of the trajectory.
72       * @return the character label.
73       */
74      char getType() const { return theType; }
75
76      /**
77       * Set the trajectory counter of the directive order.
78       * true the Trajectory has been already inserted in the header of the directive order spaceintraj, false otherwise.
79       * With "in the header" we mean the first line of the directive order: order spaceintraj traj_name....
80       * This is in opposite with the body of the directive that is the rest of the directive.
81       * With this header example traj_name will be marked to true.
82       * We can find trajectories only in the header of one spaceintraj directive. This counter allows to perform this control.
83       * Note that for the space is different because we have to check the space in the header of modinspace and the space in the body of spaceintraj.
84       * @param flag true if we want to enable this option, false otherwise.
85       */
86      void setCounterOrder(bool flag){ counterOrder = flag; }
87
88      /**
89       * Check if the trajectory has been already inserted in an header of the directive spaceintraj.
90       * @return true the object has been already inserted in the directive, false otherwise.
91       */
92      bool isCounterOrder(){ return counterOrder; }
93
94      //! The number of information stored in this class.
95      static int getPropertyCount() { return 6; }
96
97      //! Get the name of the property: "trajectory", "boot", "size", "step", "offset", "type".
98      static std::string getPropertyName(int anIndex){
99        ENFORCE(anIndex >= 0 && anIndex < Trajectory::getPropertyCount());
100        static const char* propertyName[] = { "trajectory", "boot", "size", "step", "offset", "type" };
101
102        return propertyName[anIndex];
103      }
104
105      //! Get the information in function of an integer that identifies it.
106      std::string getProperty(int anIndex) const;
107   
108    private:
109
110      int theBoot;        //!< Number of boot steps (so-called uptime).
111      int theSize;        //!< Total number of steps (so-called nbsteptime).
112      double theStep;     //!< Time step (so-called dtime).
113      double theOffset;   //!< Time offset (so-called offtime).
114      Type theType;       //!< Type/label.
115      bool counterOrder;  //!< A counter to control that the directive order spaceintraj include at least one time this object.
116  };
117
118  inline
119    Trajectory::Trajectory(const std::string& aName, int aBoot, int aSize, double aStep, double anOffset, char aType):
120      Object(aName), theBoot(aBoot), theSize(aSize), theStep(aStep), theOffset(anOffset), theType(aType), counterOrder(false){
121        ENFORCE(theOffset >= 0.0);
122        ENFORCE(theBoot >= 0);
123        ENFORCE(theStep > 0);
124        ENFORCE(theSize > 0);
125        ENFORCE(theBoot < theSize);
126        ENFORCE((theType >= 'a' && theType <= 'z') || (theType >= 'A' && theType <= 'Z'));
127      }
128
129  inline
130    std::string Trajectory::getProperty(int anIndex) const{
131      std::string property = Object::getProperty(anIndex);
132      switch (anIndex){
133        case 1:
134          property = stream_cast<std::string>(theBoot);
135          break;
136        case 2:
137          property = stream_cast<std::string>(theSize);
138          break;
139        case 3:
140          property = stream_cast<std::string>(theStep);
141          break;
142        case 4:
143          property = stream_cast<std::string>(theOffset);
144          break;
145        case 5:
146          property = stream_cast<std::string>(theType);
147      }
148
149      return property;
150    }
151
152} // Namespace yao.
153#endif // !YAO_TRAJECTORY_HPP_INCLUDED.
154
Note: See TracBrowser for help on using the repository browser.