source: XIOS/trunk/src/interface/c/icdata.cpp @ 342

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

suppress ym related element

YM

  • Property svn:eol-style set to native
File size: 7.7 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5#include <boost/multi_array.hpp>
6#include <boost/shared_ptr.hpp>
7#include <string>
8#include <iostream>
9
10
11#include "xmlioserver.hpp"
12#include "oasis_cinterface.hpp"
13
14#include "attribute_template_impl.hpp"
15#include "object_template_impl.hpp"
16#include "group_template_impl.hpp"
17
18#include "icutil.hpp"
19#include "cxios.hpp"
20#include "client.hpp"
21#include "field.hpp"
22#include "field_impl.hpp"
23#include <mpi.h>
24
25extern "C"
26{
27// /////////////////////////////// Définitions ////////////////////////////// //
28
29   // ----------------------- Redéfinition de types ----------------------------
30   
31   typedef enum { NETCDF4 = 0 } XFileType;
32   
33   typedef xios::tree::CContext * XContextPtr;
34
35   // -------------------- Traitement des données ------------------------------
36   void cxios_init_server(void)
37   {
38     CXios::initServerSide();     
39   }
40
41   void cxios_init_client(const char * client_id , int len_client_id, MPI_Fint* f_local_comm, MPI_Fint* f_return_comm )
42   {
43      std::string str; 
44      MPI_Comm local_comm ;
45      MPI_Comm return_comm ;
46     
47      if (!cstr2string(client_id, len_client_id, str)) return;
48     
49      int initialized ;
50      MPI_Initialized(&initialized) ;
51      if (initialized) local_comm=MPI_Comm_f2c(*f_local_comm) ;
52      else local_comm=MPI_COMM_NULL ;
53      CXios::initClientSide(str,local_comm,return_comm);
54      *f_return_comm=MPI_Comm_c2f(return_comm) ;
55   }
56
57   void cxios_context_initialize(const char * context_id , int len_context_id, MPI_Fint* f_comm)
58   {
59     std::string str; 
60     MPI_Comm comm ;
61     
62     if (!cstr2string(context_id, len_context_id, str)) return;
63     comm=MPI_Comm_f2c(*f_comm) ;
64     CClient::registerContext(str,comm) ;
65   }
66 
67    void cxios_context_close_definition()
68   {
69     boost::shared_ptr<CContext> context =
70            CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
71     context->closeDefinition() ;
72   } 
73
74   void cxios_context_finalize()
75   {
76     boost::shared_ptr<CContext> context =
77            CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
78     context->finalize() ;
79   }
80   
81   void cxios_finalize()
82   {
83     CXios::clientFinalize() ;
84   }
85
86 
87   
88   // ---------------------- Ecriture des données ------------------------------
89   
90   void cxios_write_data_k81(const char * fieldid, int fieldid_size, double * data_k8, int data_Xsize)
91   {
92      std::string fieldid_str;
93      boost::shared_ptr<CContext> context =
94      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
95      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return; 
96     
97//      boost::const_multi_array_ref<double, 1> array_(data_k8,
98//          boost::extents [data_Xsize],
99//          boost::fortran_storage_order());
100      ARRAY(double, 1) data(new CArray<double, 1>(boost::extents [data_Xsize]));
101      std::copy(data_k8, &(data_k8[data->num_elements()]), data->data());
102     
103//      dtreat->write_data(fieldid_str, data);
104      CField::get(fieldid_str)->setData(data) ;
105   }
106   
107   void cxios_write_data_k82(const char * fieldid, int fieldid_size, double * data_k8, int data_Xsize, int data_Ysize)
108   {
109      std::string fieldid_str;
110      boost::shared_ptr<CContext> context =
111      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
112      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;
113     
114//      boost::const_multi_array_ref<double, 2> array_(data_k8,
115//          boost::extents [data_Xsize][data_Ysize],
116//          boost::fortran_storage_order());
117      ARRAY(double, 2) data(new CArray<double, 2>(boost::extents [data_Xsize][data_Ysize]));
118      std::copy(data_k8, &(data_k8[data->num_elements()]), data->data());
119//      dtreat->write_data(fieldid_str, data);
120      CField::get(fieldid_str)->setData(data) ;
121   }
122   
123   void cxios_write_data_k83(const char * fieldid, int fieldid_size, double * data_k8, int data_Xsize, int data_Ysize, int data_Zsize)
124   {
125      std::string fieldid_str;
126      boost::shared_ptr<CContext> context =
127      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
128      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return; 
129     
130//      boost::const_multi_array_ref<double, 3> array_(data_k8,
131//          boost::extents [data_Xsize][data_Ysize][data_Zsize],
132//          boost::fortran_storage_order());
133      ARRAY(double, 3) data(new CArray<double, 3>(boost::extents [data_Xsize][data_Ysize][data_Zsize]));
134      std::copy(data_k8, &(data_k8[data->num_elements()]), data->data());
135//      dtreat->write_data(fieldid_str, data);
136      CField::get(fieldid_str)->setData(data) ;
137
138   }
139   
140   void cxios_write_data_k41(const char * fieldid, int fieldid_size, float * data_k4, int data_Xsize)
141   {
142      std::string fieldid_str;
143      boost::shared_ptr<CContext> context =
144      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
145      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return; 
146     
147//      boost::const_multi_array_ref<float, 1> array_(data_k4,
148//          boost::extents [data_Xsize],
149//          boost::fortran_storage_order());
150//      ARRAY(float, 1) data(new CArray<float, 1>(boost::extents [data_Xsize]));
151//      std::copy(data_k4, &(data_k4[data->num_elements()]), data->data());
152//      dtreat->write_data(fieldid_str, data);
153      ARRAY(double, 1) data(new CArray<double, 1>(boost::extents [data_Xsize]));
154      double* ptr_data=data->data() ; 
155      for(int i=0;i<data->num_elements();i++) ptr_data[i]=data_k4[i];
156      CField::get(fieldid_str)->setData(data) ;
157   }
158   
159   void cxios_write_data_k42(const char * fieldid, int fieldid_size, float * data_k4, int data_Xsize, int data_Ysize)
160   {
161      std::string fieldid_str;
162      boost::shared_ptr<CContext> context =
163      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
164      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return; 
165     
166//      boost::const_multi_array_ref<float, 2> array_(data_k4,
167//          boost::extents [data_Xsize][data_Ysize],
168//          boost::fortran_storage_order());
169//      ARRAY(float, 2) data(new CArray<float, 2>(boost::extents [data_Xsize][data_Ysize]));
170//      std::copy(data_k4, &(data_k4[data->num_elements()]), data->data());
171//      dtreat->write_data(fieldid_str, data);
172      ARRAY(double, 2) data(new CArray<double, 2>(boost::extents [data_Xsize][data_Ysize]));
173      double* ptr_data=data->data() ; 
174      for(int i=0;i<data->num_elements();i++) ptr_data[i]=data_k4[i];
175      CField::get(fieldid_str)->setData(data) ;
176   }
177   
178   void cxios_write_data_k43(const char * fieldid, int fieldid_size, float * data_k4, int data_Xsize, int data_Ysize, int data_Zsize)
179   {
180      std::string fieldid_str;
181      boost::shared_ptr<CContext> context =
182      CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId());
183      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return; 
184     
185//      boost::const_multi_array_ref<float, 3> array_(data_k4,
186//          boost::extents [data_Xsize][data_Ysize][data_Zsize],
187//          boost::fortran_storage_order());
188//      ARRAY(float, 3) data(new CArray<float, 3>(boost::extents [data_Xsize][data_Ysize][data_Zsize]));
189//      std::copy(data_k4, &(data_k4[data->num_elements()]), data->data());
190//      dtreat->write_data(fieldid_str, data);
191      ARRAY(double, 3) data(new CArray<double, 3>(boost::extents [data_Xsize][data_Ysize][data_Zsize]));
192      double* ptr_data=data->data() ; 
193      for(int i=0;i<data->num_elements();i++) ptr_data[i]=data_k4[i];
194      CField::get(fieldid_str)->setData(data) ;
195    } 
196
197} // extern "C"
Note: See TracBrowser for help on using the repository browser.