source: XIOS/dev/common/src/data_treatment.hpp @ 1512

Last change on this file since 1512 was 300, checked in by ymipsl, 12 years ago

nouvelle version de developpement de xios

  • nouvelle interface fortran
  • recodage complet de la couche de communication
  • et bien d'autres choses...

YM

File size: 6.2 KB
Line 
1#ifndef __XMLIO_CDataTreatment__
2#define __XMLIO_CDataTreatment__
3
4/// xmlioserver headers ///
5#include "xmlioserver_spl.hpp"
6#include "node_type.hpp"
7#include "mpi_manager.hpp"
8#include "data_output.hpp"
9#include "duration.hpp"
10#include "client.hpp"
11#include "xios_manager.hpp"
12#include <mpi.h>
13
14namespace xmlioserver
15{
16   namespace data
17   {
18      /// ////////////////////// Déclarations ////////////////////// ///
19      class CDataTreatment
20      {
21         public :
22
23            /// Construteurs ///
24            CDataTreatment
25               (boost::shared_ptr<CContext> _ctxt =
26                  CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()));
27
28            CDataTreatment(const CDataTreatment & data_treatment);       // Not implemented yet.
29            CDataTreatment(const CDataTreatment * const data_treatment); // Not implemented yet.
30
31            /// Accesseurs ///
32            const boost::shared_ptr<CContext> getCurrentContext(void) const;
33            const std::vector<boost::shared_ptr<CFile> > & getEnabledFiles  (void) const;
34
35            /// Ecriture et mise à jour du calendrier ///
36            void write_data(const StdString & fieldId,
37                            const StdString & fileId,
38                            const std::deque<ARRAY(double, 1)> & data);
39
40            template <StdSize N>
41               void write_data(const StdString & fieldId, const ARRAY(double, N) & data);
42
43            template <StdSize N>
44               void write_data(const StdString & fieldId, const ARRAY(float, N) & data);
45
46            void update_calendar(int step);
47            void set_timestep(const date::CDuration & duration);
48            void finalize(void) ;
49           
50            /// Création des sorties ///
51            template <class T> void createDataOutput(MPI_Comm comm_server = CXIOSManager::Comm_Server);
52
53           
54            /// Destructeur ///
55            ~CDataTreatment(void);
56
57         private :
58
59            /// Traitements ///
60            void doTreatment(void);
61            void closeAllFile(void ) ;
62
63            void findAllEnabledFields(void);
64            void solveAllGridRef(void);
65            void solveAllOperation(void);
66            void solveAllInheritance(void) const;
67            void findEnabledFiles(void);
68
69            /// Propriétés privées ///
70            boost::shared_ptr<CContext> currentContext;
71            std::vector<boost::shared_ptr<CFile> > enabledFiles;
72     
73      }; // CDataTreatment
74
75      //----------------------------------------------------------------
76
77      template <class T>
78         void CDataTreatment::createDataOutput(MPI_Comm comm_server )
79      {
80         std::vector<boost::shared_ptr<CFile> >::const_iterator
81            it = this->enabledFiles.begin(), end = this->enabledFiles.end();
82         
83         for (; it != end; it++)
84         {
85            CXIOSManager::Comm_Server = comm_server;
86            boost::shared_ptr<CFile> file = *it;
87            StdString filename = (!file->name.isEmpty())
88                               ?   file->name.getValue() : file->getId();
89            StdOStringStream oss;
90            if (!CObjectFactory::GetObject<CContext>
91                (CObjectFactory::GetCurrentContextId())->output_dir.isEmpty())
92                oss << CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId())->output_dir.getValue();
93            oss << filename;
94            if (!file->name_suffix.isEmpty())
95                oss << file->name_suffix.getValue();
96
97            bool multifile=true ;
98            if (!file->type.isEmpty())
99            {
100              StdString str=file->type.getValue() ; 
101              if (str.compare("one_file")==0) multifile=false ;
102              else if (str.compare("multi_file")==0) multifile=true ;
103              else ERROR("void CDataTreatment::createDataOutput(MPI_Comm comm_server)",
104                         "incorrect file <type> attribut : must be <multi_file> or <one_file>, "
105                        <<"having : <"<<str<<">") ;
106            } 
107            if (multifile) 
108            {
109              if (comm::CMPIManager::GetCommSize(comm_server) > 1)
110                       oss << "_" << comm::CMPIManager::GetCommRank(comm_server);
111            }
112            oss << ".nc";
113
114            boost::shared_ptr<io::CDataOutput> dout(new T(oss.str(), false,comm_server,multifile));
115//            file->initializeDataOutput(dout);
116         }
117      }
118
119      template <StdSize N>
120         void CDataTreatment::write_data
121            (const StdString & fieldId, const ARRAY(float, N) & data)
122      {
123         typedef typename boost::multi_array<double, N>::size_type sizetp;
124         std::vector<sizetp> shape;
125         const sizetp * shapearr = data->shape();
126
127         shape.assign(shapearr, shapearr + N);
128         ARRAY(double, N) datad(new CArray<double, N>(shape));
129         for (StdSize i = 0; i < datad->num_elements(); i++)
130          datad->data()[i] = data->data()[i];
131
132         this->write_data(fieldId, datad);
133      }
134
135      template <StdSize N>
136         void CDataTreatment::write_data
137            (const StdString & fieldId, const ARRAY(double, N) & data)
138      {
139         const date::CDate & currDate =
140                this->currentContext->getCalendar()->getCurrentDate();
141         const date::CDuration & timestep = 
142               this->currentContext->getCalendar()->getTimeStep();
143         const std::vector<boost::shared_ptr<CField> > & refField=
144               CObjectFactory::GetObject<CField>(fieldId)->getAllReference();
145         std::vector<boost::shared_ptr<CField> >::const_iterator
146               it = refField.begin(), end = refField.end();
147         for (; it != end; it++)
148         {
149            boost::shared_ptr<CField> field = *it;
150            boost::shared_ptr<CFile>  file  = field->getRelFile();
151            if (field->updateData(data))
152            {
153               if (CXIOSManager::GetStatus() == CXIOSManager::LOC_CLIENT)
154               { 
155                   boost::shared_ptr<comm::CClient> client = comm::CClient::GetClient();
156                   client->sendData(field->getId(), file->getId(), field->getData());
157               }
158               else
159               {
160                  file->getDataOutput()->writeFieldData(field);
161               }
162            }
163         }
164
165      }
166
167   } // namespace data
168
169} // namespace xmlioserver
170
171#endif // __XMLIO_CDataTreatment__
Note: See TracBrowser for help on using the repository browser.