source: XIOS/branchs/xios-1.0-alpha1/src/calendar.cpp @ 302

Last change on this file since 302 was 286, checked in by ymipsl, 13 years ago

reprise en main de la version de H. Ozdoba. Correction de différentes erreurs de conception et bug.
Version NEMO operationnel en client/server, interoperabilita avec OASIS, reconstition de fichiers via netcdf4/HDF5

YM

File size: 4.3 KB
Line 
1#include "calendar.hpp"
2#include "duration.hpp"
3#include "date.hpp"
4#include "calendar_util.hpp"
5
6namespace xmlioserver
7{
8   namespace date
9   {
10      /// ////////////////////// Définitions ////////////////////// ///
11      CCalendar::CCalendar(void)
12         : CObject()
13         , initDate(*this)
14         , currentDate(initDate)
15      { /* Ne rien faire de plus */ }
16
17      CCalendar::CCalendar(const StdString & id,
18                           int yr, int mth, int d  ,
19                           int hr, int min, int sec)
20               : CObject(id)
21               , initDate(*this, yr, mth, d, hr, min, sec)
22               , currentDate(initDate)
23      { /* Ne rien faire de plus */ }
24
25      CCalendar::CCalendar(const StdString & id, const StdString & dateStr)
26               : CObject(id)
27               , initDate(CDate::FromString(dateStr, *this))
28               , currentDate(initDate)
29      { /* Ne rien faire de plus */ }
30
31      CCalendar::~CCalendar(void)
32      { /* Ne rien faire de plus */ }
33
34      ///---------------------------------------------------------------
35
36      StdString CCalendar::toString(void) const
37      {
38         StdOStringStream oss;
39         oss <<   "[type: "   << this->getId()
40             << ", start: "   << this->initDate
41             << ", current: " << this->currentDate << "]";
42         return (oss.str());
43      }
44
45      void CCalendar::fromString(const StdString & str)
46      { ERROR("CCalendar::fromString(str)",
47               << "[ str = " << str << "] Not implemented yet !"); }
48
49      //-----------------------------------------------------------------
50
51      void CCalendar::setTimeStep(const CDuration & duration)
52      { this->timestep = duration; }
53
54      CDate & CCalendar::update(int step)
55      { 
56         std::cout << "step : " << step <<" timestep "<<this->timestep << std::endl;
57//         std::cout << "date before : " << this->getCurrentDate() <<" date after "<<this->getInitDate() + step * this->timestep << std::endl;
58         return (this->getCurrentDate() = this->getInitDate() + step * this->timestep);
59      }
60
61      //-----------------------------------------------------------------
62
63      const CDuration & CCalendar::getTimeStep(void) const { return (this->timestep); }
64      const CDate & CCalendar::getInitDate(void) const     { return (this->initDate); }
65      CDate & CCalendar::getCurrentDate(void)              { return (this->currentDate); }
66
67      //-----------------------------------------------------------------
68
69      int CCalendar::getMonthLength(const CDate & date) const
70      { // Retourne la durée du mois en jour.
71         static const int NoLeapMonthLength[] =
72            {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
73         return (NoLeapMonthLength[date.getMonth()-1]);
74      }
75
76      StdString CCalendar::getType(void) const { return (StdString(this->getId())); }
77
78      int CCalendar::getYearTotalLength(const CDate & date) const { return (365 * 86400); }
79
80      int CCalendar::getYearLength  (void) const { return (12); }
81      int CCalendar::getDayLength   (void) const { return (24); }
82      int CCalendar::getHourLength  (void) const { return (60); }
83      int CCalendar::getMinuteLength(void) const { return (60); }
84
85      int CCalendar::getNbSecond(const CDate & date) const
86      { // Retourne le nombre de secondes écoulées depuis le début de l'année.
87         CDate _d0(date); int  nbday = 0;
88
89         for(_d0.setMonth(1); _d0.getMonth() < date.getMonth(); _d0.setMonth(_d0.getMonth()+1))
90            nbday += getMonthLength(_d0);
91         return ((((nbday + date.getDay()) * getDayLength() + date.getHour()) * getHourLength()
92                     + date.getMinute()) * getMinuteLength() + date.getSecond());
93      }
94
95      StdString CCalendar::getMonthName(int month_id) const
96      {
97         static const StdString Monthname_str[] =
98            { "january", "february", "march"    , "april"  , "may"     , "june"    ,
99              "july"   , "august"  , "september", "october", "november", "december" };
100         return(Monthname_str[month_id-1]);
101      }
102
103      const StdString CCalendar::getMonthShortName(int month_id) const
104      { StdString value = this->getMonthName(month_id); value.resize(3); return (value); }
105
106      ///----------------------------------------------------------------
107
108   } // namespace date
109} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.