1 | #include "macro.inc" |
---|
2 | |
---|
3 | INCLUDE "../xmlioserver.hpp" |
---|
4 | |
---|
5 | INCLUDE "attribute_template_impl.hpp" |
---|
6 | INCLUDE "object_template_impl.hpp" |
---|
7 | INCLUDE "group_template_impl.hpp" |
---|
8 | |
---|
9 | #ifdef __cplusplus |
---|
10 | extern "C" |
---|
11 | { |
---|
12 | #endif //__cplusplus |
---|
13 | |
---|
14 | typedef xmlioserver::tree::CAxis caxis; |
---|
15 | typedef xmlioserver::tree::CField cfield; |
---|
16 | typedef xmlioserver::tree::CDomain cdomain; |
---|
17 | typedef xmlioserver::tree::CGrid cgrid; |
---|
18 | typedef xmlioserver::tree::CFile cfile; |
---|
19 | typedef xmlioserver::tree::CContext ccontext; |
---|
20 | |
---|
21 | typedef xmlioserver::tree::CAxisGroup caxisgroup; |
---|
22 | typedef xmlioserver::tree::CFieldGroup cfieldgroup; |
---|
23 | typedef xmlioserver::tree::CDomainGroup cdomaingroup; |
---|
24 | typedef xmlioserver::tree::CGridGroup cgridgroup; |
---|
25 | typedef xmlioserver::tree::CFileGroup cfilegroup; |
---|
26 | typedef xmlioserver::tree::CContextGroup ccontextgroup; |
---|
27 | |
---|
28 | |
---|
29 | typedef long int XInt, XSize; // Integer |
---|
30 | typedef bool XBool; // Logical |
---|
31 | typedef void * XPtr; // Pointeur C non typé |
---|
32 | typedef char * XString; // Pointeur C non typé |
---|
33 | |
---|
34 | typedef 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 | |
---|
42 | typedef enum |
---|
43 | { |
---|
44 | NETCDF4 = 0 |
---|
45 | } XFileType; |
---|
46 | |
---|
47 | typedef 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 | |
---|
90 | void 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 | |
---|
113 | void 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 | |
---|
131 | void 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 | |
---|
149 | void 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 | |
---|
155 | void 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 | |
---|
201 | void 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 | |
---|
238 | void 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 | |
---|
247 | void xios_dtreatment_start(XPtr const _context, XFileType filetype, MPIComm comm_client_server) |
---|
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 | //~ oss.str(""); |
---|
256 | |
---|
257 | CDataTreatment dt; |
---|
258 | oss << StdString("data/def/def_client_end.") |
---|
259 | << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
260 | CTreeManager::PrintTreeToFile(oss.str()); |
---|
261 | |
---|
262 | if ((comm_client_server != -1)) |
---|
263 | { |
---|
264 | MPIRequest request = 0; |
---|
265 | StdOStringStream ostrs; |
---|
266 | if (CMPIManager::GetCommRank(comm_client_server) == 1) |
---|
267 | { |
---|
268 | CTreeManager::ToBinary(ostrs); |
---|
269 | CLinearBuffer lbuffer(ostrs.str().size()+13); |
---|
270 | lbuffer.appendString(ostrs.str()); |
---|
271 | CMPIManager::SendLinearBuffer(comm_client_server, 0, lbuffer, request); |
---|
272 | CMPIManager::Wait(request); // Pas encore en mode RPC |
---|
273 | } |
---|
274 | else |
---|
275 | { |
---|
276 | CTreeManager::DomainsToBinary(ostrs); |
---|
277 | CLinearBuffer lbuffer(ostrs.str().size()+13); |
---|
278 | lbuffer.appendString(ostrs.str()); |
---|
279 | CMPIManager::SendLinearBuffer(comm_client_server, 0, lbuffer, request); |
---|
280 | CMPIManager::Wait(request); // Pas encore en mode RPC |
---|
281 | } |
---|
282 | } |
---|
283 | else |
---|
284 | { |
---|
285 | dt.createDataOutput<CNc4DataOutput>(); |
---|
286 | } |
---|
287 | } |
---|
288 | catch (CException & exc) |
---|
289 | { |
---|
290 | std::cerr << exc.getMessage() << std::endl; |
---|
291 | exit (EXIT_FAILURE); |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | void xios_dtreatment_end(void) |
---|
296 | { |
---|
297 | |
---|
298 | } |
---|
299 | |
---|
300 | void xios_write_data(const XString _field_id, XSize _field_id_len, double * data_k8, |
---|
301 | XSize data_Xsize, XSize data_Ysize, XSize data_Zsize) |
---|
302 | { |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | void xios_update_calendar(int step) |
---|
307 | { |
---|
308 | |
---|
309 | } |
---|
310 | |
---|
311 | void xios_set_timestep(double ts_year, double ts_month, double ts_day, |
---|
312 | double ts_hour, double ts_minute, double ts_second) |
---|
313 | { |
---|
314 | |
---|
315 | |
---|
316 | } |
---|
317 | |
---|
318 | |
---|
319 | |
---|
320 | |
---|
321 | #ifdef __cplusplus |
---|
322 | } |
---|
323 | #endif //__cplusplus |
---|