source: XMLIO_V2/dev/common/src/xmlio/node/field.hpp @ 286

Last change on this file since 286 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: 6.6 KB
Line 
1#ifndef __XMLIO_CField__
2#define __XMLIO_CField__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "group_factory.hpp"
7#include "functor.hpp"
8#include "functor_type.hpp"
9#include "duration.hpp"
10#include "date.hpp"
11#include "declare_group.hpp"
12#include "calendar_util.hpp"
13
14namespace xmlioserver {
15namespace tree {
16   
17   /// ////////////////////// Déclarations ////////////////////// ///
18
19   class CFieldGroup;
20   class CFieldAttributes;
21   class CField;
22
23   class CFile;
24   class CGrid;
25
26   ///--------------------------------------------------------------
27
28   // Declare/Define CFieldAttribute
29   BEGIN_DECLARE_ATTRIBUTE_MAP(CField)
30#  include "field_attribute.conf"
31   END_DECLARE_ATTRIBUTE_MAP(CField)
32
33   ///--------------------------------------------------------------
34   class CField
35      : public CObjectTemplate<CField>
36      , public CFieldAttributes
37   {
38         /// friend ///
39         friend class CFile;
40
41         /// typedef ///
42         typedef CObjectTemplate<CField>   SuperClass;
43         typedef CFieldAttributes SuperClassAttribute;
44
45      public :
46
47         typedef CFieldAttributes RelAttributes;
48         typedef CFieldGroup      RelGroup;
49
50         /// Constructeurs ///
51         CField(void);
52         explicit CField(const StdString & id);
53         CField(const CField & field);       // Not implemented yet.
54         CField(const CField * const field); // Not implemented yet.
55
56         /// Accesseurs ///
57               boost::shared_ptr<CField> getDirectFieldReference(void) const;
58         const boost::shared_ptr<CField> getBaseFieldReference(void)   const;
59         const std::vector<boost::shared_ptr<CField> > & getAllReference(void) const;
60
61         boost::shared_ptr<CGrid> getRelGrid(void) const ;
62         boost::shared_ptr<CFile> getRelFile(void) const ;
63
64      public :
65
66         StdSize getNStep(void) const;
67
68         const date::CDuration & getFreqOperation(void) const;
69         const date::CDuration & getFreqWrite(void) const;
70
71         boost::shared_ptr<date::CDate> getLastWriteDate(void) const;
72         boost::shared_ptr<date::CDate> getLastOperationDate(void) const;
73
74         boost::shared_ptr<func::CFunctor> getFieldOperation(void) const;
75         
76         ARRAY(double, 1) getData(void) const;
77
78         const StdString & getBaseFieldId(void) const;
79
80         /// Mutateur ///
81         void setRelFile(const boost::shared_ptr<CFile> _file);
82         void incrementNStep(void);
83
84         template <StdSize N>
85            inline bool updateData
86               (const date::CDate      & currDate,
87                const date::CDuration  & timestep,
88                const ARRAY(double, N)   data);
89
90         bool updateDataServer
91               (const date::CDate & currDate,
92                const std::deque<ARRAY(double, 1)> storedClient);
93
94      public :
95
96         /// Test ///
97         bool hasDirectFieldReference(void) const;
98
99         /// Traitements ///
100         void solveRefInheritance(void);
101         void solveGridReference(void);
102         void solveOperation(void);
103
104         virtual void fromBinary(StdIStream & is);
105
106         /// Destructeur ///
107         virtual ~CField(void);
108
109         /// Accesseurs statiques ///
110         static StdString GetName(void);
111         static StdString GetDefName(void);
112         
113         static ENodeType GetType(void);
114
115      private :
116
117         /// Propriétés privées ///
118         
119         std::vector<boost::shared_ptr<CField> > refObject;
120         boost::shared_ptr<CField> baseRefObject;
121         boost::shared_ptr<CGrid>  grid ;
122         boost::shared_ptr<CFile>  file;
123
124         date::CDuration freq_operation, freq_write;
125
126         StdSize nstep;
127         boost::shared_ptr<date::CDate>    last_Write, last_operation;
128         boost::shared_ptr<func::CFunctor> foperation;
129         
130         ARRAY(double, 1) data;
131
132   }; // class CField
133
134   ///--------------------------------------------------------------
135
136   // Declare/Define CFieldGroup and CFieldDefinition
137   DECLARE_GROUP(CField);
138
139   } // namespace tree
140
141   ///-----------------------------------------------------------------
142
143   template <>
144      void CGroupTemplate<CField, CFieldGroup, CFieldAttributes>::solveRefInheritance(void);
145
146   ///-----------------------------------------------------------------
147} // namespace xmlioserver
148
149#include "grid.hpp"
150
151namespace xmlioserver {
152namespace tree {
153
154   template <StdSize N>
155      bool CField::updateData(const date::CDate & currDate, const date::CDuration & timestep, const ARRAY(double, N) _data)
156   {       
157      const date::CDate opeDate      = *last_operation + freq_operation;
158      const date::CDate writeDate    = *last_Write     + freq_write;       
159
160//      std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
161//      std::cout << "Champ : "     << this->getBaseFieldId() << std::endl;
162//      std::cout << "CurrDate : "  << currDate  << std::endl;
163//      std::cout << "opeDate : "   << opeDate   << " = " << *last_operation << " + " << freq_operation << std::endl;
164//      std::cout       << "writeDate : " << writeDate << " = " << *last_Write     << " + " << freq_write     << std::endl;
165//      std::cout << "(opeDate <= currDate)   = " << std::boolalpha << (opeDate <= currDate)   << std::endl;
166//      std::cout       << "(writeDate <= currDate) = " << std::boolalpha << (writeDate <= currDate) << std::endl;   
167   
168      std::cout << ">> " << currDate <<  " : Envoi de données " << this->getBaseFieldId() << std::endl;
169      std::cout << ">> next operation "  << opeDate<<std::endl;
170      if (opeDate <= currDate)
171      {
172         //std::cout << "> " << currDate << ": Operation du champs" << this->getBaseFieldId() << std::endl;
173         if (this->data->num_elements() != this->grid->storeIndex[0]->num_elements())
174         {
175            this->data->resize(boost::extents[this->grid->storeIndex[0] ->num_elements()]);
176         }
177           
178         ARRAY_CREATE(input, double, 1, [this->data->num_elements()]);
179         this->grid->inputField(_data, input);         
180         (*this->foperation)(input);
181         
182         *last_operation = currDate;
183         std::cout << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
184      }
185     
186      if (writeDate < (currDate + freq_operation))
187      {
188         this->foperation->final();
189         this->incrementNStep();
190         *last_Write = writeDate;
191         std::cout << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
192         return (true);       
193      }
194//      std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
195      return (false);
196   };
197
198} // namespace tree
199} // namespace xmlioserver
200
201#endif // __XMLIO_CField__
Note: See TracBrowser for help on using the repository browser.