source: XMLIO_V2/dev/dev_rv/src/iface/interface.cpp.in @ 141

Last change on this file since 141 was 141, checked in by hozdoba, 13 years ago

Mise à jour depuis un autre dépôt

File size: 9.9 KB
Line 
1#include "macro.inc"
2
3INCLUDE "../xmlioserver.hpp"
4
5INCLUDE "attribute_template_impl.hpp"
6INCLUDE "object_template_impl.hpp"
7INCLUDE "group_template_impl.hpp"
8
9#ifdef __cplusplus
10extern "C"
11{
12#endif //__cplusplus
13
14typedef xmlioserver::tree::CAxis    caxis;
15typedef xmlioserver::tree::CField   cfield;
16typedef xmlioserver::tree::CDomain  cdomain;
17typedef xmlioserver::tree::CGrid    cgrid;
18typedef xmlioserver::tree::CFile    cfile;
19typedef xmlioserver::tree::CContext ccontext;
20
21typedef xmlioserver::tree::CAxisGroup    caxisgroup;
22typedef xmlioserver::tree::CFieldGroup   cfieldgroup;
23typedef xmlioserver::tree::CDomainGroup  cdomaingroup;
24typedef xmlioserver::tree::CGridGroup    cgridgroup;
25typedef xmlioserver::tree::CFileGroup    cfilegroup;
26typedef xmlioserver::tree::CContextGroup ccontextgroup;
27
28
29typedef long int XInt, XSize; // Integer
30typedef bool     XBool;       // Logical
31typedef void   * XPtr;        // Pointeur C non typé
32typedef char   * XString;     // Pointeur C non typé
33
34typedef enum
35{
36   NOTYPE = 0,
37   DTREATMENT/* UNUSED */, DATE, CALENDAR, ECONTEXT,
38   EAXIS, EDOMAIN, EFIELD, EFILE, EGRID,
39   GAXIS, GDOMAIN, GFIELD, GFILE, GGRID
40} XDType;
41
42typedef enum
43{
44   NETCDF4 = 0
45} XFileType;
46
47typedef enum
48{ D360 = 0 , ALLLEAP, NOLEAP, JULIAN, GREGORIAN } XCalendarType ;
49
50#define DECLARE_ATTRIBUTE(type, name) \
51        DECLARE_INTERFACE(axis, type, name)
52#include "../config/axis_attribute.conf"
53
54#undef  DECLARE_ATTRIBUTE
55#define DECLARE_ATTRIBUTE(type, name) \
56        DECLARE_INTERFACE(field, type, name)
57#include "../config/field_attribute.conf"
58
59#undef  DECLARE_ATTRIBUTE
60#define DECLARE_ATTRIBUTE(type, name) \
61        DECLARE_INTERFACE(context, type, name)
62#include "../config/context_attribute.conf"
63
64#undef  DECLARE_ATTRIBUTE
65#define DECLARE_ATTRIBUTE(type, name) \
66        DECLARE_INTERFACE(domain, type, name)
67#include "../config/domain_attribute.conf"
68
69#undef  DECLARE_ATTRIBUTE
70#define DECLARE_ATTRIBUTE(type, name) \
71        DECLARE_INTERFACE(file, type, name)
72#include "../config/file_attribute.conf"
73
74#undef  DECLARE_ATTRIBUTE
75#define DECLARE_ATTRIBUTE(type, name) \
76        DECLARE_INTERFACE(grid, type, name)
77#include "../config/grid_attribute.conf"
78
79#define CASE_ELEM(elem_enum, elem_class)                                         \
80   case (E##elem_enum): ;; { ;;                                                  \
81      *_ret = (!CObjectFactory::HasObject<C##elem_class>(__id));;                \
82            ? 0 : CObjectFactory::GetObject<C##elem_class>(__id).get(); ;;       \
83      return; ;;};;                                                              \
84   case (G##elem_enum): ;; { ;;                                                  \
85      *_ret = (!CObjectFactory::HasObject<C##elem_class##Group>(__id));;         \
86            ? 0 : CObjectFactory::GetObject<C##elem_class##Group>(__id).get(); ;;\
87      return; ;;};;
88
89
90void xios_handle_create (XPtr * const _ret, XDType _dtype, const XString _id, XSize _id_len)
91{
92   MAKE_STRING(__id, _id, _id_len);
93   switch(_dtype)
94   {
95      case (ECONTEXT):
96         // Si le context n'existe pas, on retourne un handle vide/nul.
97         *_ret = (!CObjectFactory::HasObject<CContext>(__id))
98               ? 0 : CObjectFactory::GetObject<CContext>(__id).get();
99         return ;
100      CASE_ELEM(AXIS   , Axis)
101      CASE_ELEM(DOMAIN , Domain)
102      CASE_ELEM(FIELD  , Field)
103      CASE_ELEM(FILE   , File)
104      CASE_ELEM(GRID   , Grid)
105      default :
106         *_ret = 0;
107         return;
108   }
109}
110
111#undef CASE_ELEM
112
113void xios_xml_parse_file  (const XString _filename, XSize _filename_len)
114{
115   try
116   {
117      MAKE_STRING(__filename, _filename, _filename_len)
118      CTreeManager::ParseFile(__filename);
119      StdOStringStream oss;
120      oss << StdString("data/def/def_client_pre.")
121          << CMPIManager::GetCommRank(CMPIManager::GetCommWorld());
122      CTreeManager::PrintTreeToFile(oss.str());
123   }
124   catch (CException & exc)
125   {
126      std::cerr << exc.getMessage() << std::endl;
127      exit (EXIT_FAILURE);
128   }
129}
130
131void xios_xml_parse_string(const XString _xmlcontent, XSize _xmlcontent_len)
132{
133   try
134   {
135      MAKE_STRING(__xmlcontent, _xmlcontent, _xmlcontent_len)
136      CTreeManager::ParseString(__xmlcontent);
137      StdOStringStream oss;
138      oss << StdString("data/def/def_client_pre.")
139          << CMPIManager::GetCommRank(CMPIManager::GetCommWorld());
140      CTreeManager::PrintTreeToFile(oss.str());
141   }
142   catch (CException & exc)
143   {
144      std::cerr << exc.getMessage() << std::endl;
145      exit (EXIT_FAILURE);
146   }
147}
148
149void xios_context_set_current (XPtr const _ctx, bool _wswap)
150{
151   boost::shared_ptr<CContext> context = CObjectFactory::GetObject<CContext> ((CContext*)_ctx);
152   CTreeManager::SetCurrentContextId(context->getId());
153}
154
155void xios_context_create (XPtr * _ctxt, const XString _ctxt_id,
156                          XSize _ctxt_id_len, XCalendarType _calType,
157                          XInt yr, XInt mth, XInt dd,
158                          XInt hr, XInt min, XInt sec)
159{
160   try
161   {
162      MAKE_STRING(__ctxt_id, _ctxt_id, _ctxt_id_len)
163      boost::shared_ptr<CContext> context = CTreeManager::CreateContext(__ctxt_id);
164      *_ctxt = context.get();
165   }
166   catch (CException & exc)
167   {
168      std::cerr << exc.getMessage() << std::endl;
169      exit (EXIT_FAILURE);
170   }
171}
172
173#define CASE_ELEM0(elem_enum, elem_class, group_enum, group_class)                     \
174      case (group_enum) : ;;                                                           \
175      { ;;                                                                             \
176         group_class * _group = (group_class *) _parent;                               \
177         boost::shared_ptr<group_class> group = ;;                                     \
178            CObjectFactory::GetObject<group_class>(_group); ;;                         \
179         switch(_child_type) ;;                                                        \
180         { ;;                                                                          \
181            case (group_enum) : ;;                                                     \
182               if ((_child_id_len != -1) && ;;                                         \
183                   (CObjectFactory::HasObject<group_class>(__child_id))) ;;            \
184                  return; ;;                                                           \
185               *_child = CGroupFactory::CreateGroup(group, __child_id).get(); ;;       \
186               break; ;;                                                               \
187            case (elem_enum) : ;;                                                      \
188               if ((_child_id_len != -1) && ;;                                         \
189                   (CObjectFactory::HasObject<elem_class>(__child_id))) ;;             \
190                  return; ;;                                                           \
191               *_child = CGroupFactory::CreateChild(group, __child_id).get(); ;;       \
192               break; ;;                                                               \
193            default : ;;                                                               \
194               std::cerr << "[xml_tree_add] Type enfant invalide" << std::endl; ;;     \
195         }; ;;                                                                         \
196         return; ;;                                                                    \
197      }
198
199
200
201void xios_xml_tree_add(const XPtr _parent, XDType _parent_type, XPtr * _child,
202                       XDType _child_type, const XString _child_id, XSize _child_id_len)
203{
204   MAKE_STRING(__child_id, _child_id, _child_id_len);
205   try
206   {
207      switch (_parent_type)
208      {
209         case (EFILE) :
210         {
211            CFile * _file = (CFile *) _parent;
212            boost::shared_ptr<CFile> file = CObjectFactory::GetObject<CFile>(_file);
213            if (!CObjectFactory::HasObject<CFieldGroup>(file->getId()))
214               file->setVirtualFieldGroup(file->getId());
215            xios_xml_tree_add (file->getVirtualFieldGroup().get(), GFIELD,
216                              _child, EFIELD, _child_id, _child_id_len);
217            return;
218         }
219         CASE_ELEM0(EAXIS  , CAxis  , GAXIS  , CAxisGroup);
220         CASE_ELEM0(EGRID  , CGrid  , GGRID  , CGridGroup);
221         CASE_ELEM0(EDOMAIN, CDomain, GDOMAIN, CDomainGroup);
222         CASE_ELEM0(EFIELD , CField , GFIELD , CFieldGroup);
223         CASE_ELEM0(EFILE  , CFile  , GFILE  , CFileGroup);
224         default :
225            std::cerr << "[xml_tree_add] Type parent invalide" << std::endl;
226            return;
227      }
228   }
229   catch (CException & exc)
230   {
231      std::cerr << exc.getMessage() << std::endl;
232      exit (EXIT_FAILURE);
233   }
234}
235
236#undef CASE_ELEM0
237
238void xios_xml_tree_show(const XString _filename, XSize _filename_len)
239{
240   MAKE_STRING(__filename, _filename, _filename_len);
241   if (_filename_len != -1)
242      CTreeManager::PrintTreeToFile(__filename);
243   else
244      CTreeManager::PrintTreeToStream(std::clog);
245}
246
247void xios_dtreatment_start(XPtr const _context, XFileType filetype)
248{
249   try
250   {
251      StdOStringStream oss;
252      oss << StdString("data/def/def_client_next.")
253          << CMPIManager::GetCommRank(CMPIManager::GetCommWorld());
254      CTreeManager::PrintTreeToFile(oss.str());
255
256      CDataTreatment dt;
257      dt.createDataOutput<CNc4DataOutput>();
258
259      oss.str("");
260      oss << StdString("data/def/def_client_end.")
261          << CMPIManager::GetCommRank(CMPIManager::GetCommWorld());
262      CTreeManager::PrintTreeToFile(oss.str());
263   }
264   catch (CException & exc)
265   {
266      std::cerr << exc.getMessage() << std::endl;
267      exit (EXIT_FAILURE);
268   }
269}
270
271void xios_dtreatment_end(void)
272{
273
274}
275
276void xios_write_data(const XString _field_id, XSize _field_id_len, double * data_k8,
277                     XSize data_Xsize, XSize data_Ysize, XSize data_Zsize)
278{
279
280}
281
282void xios_update_calendar(int step)
283{
284
285}
286
287void xios_set_timestep(double ts_year, double ts_month, double ts_day,
288                       double ts_hour, double ts_minute, double ts_second)
289{
290
291
292}
293
294
295
296
297#ifdef __cplusplus
298}
299#endif //__cplusplus
Note: See TracBrowser for help on using the repository browser.