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 | INCLUDE "calendar_type.hpp" |
---|
10 | |
---|
11 | #ifdef __cplusplus |
---|
12 | extern "C" |
---|
13 | { |
---|
14 | #endif //__cplusplus |
---|
15 | |
---|
16 | typedef xmlioserver::tree::CAxis caxis; |
---|
17 | typedef xmlioserver::tree::CField cfield; |
---|
18 | typedef xmlioserver::tree::CDomain cdomain; |
---|
19 | typedef xmlioserver::tree::CGrid cgrid; |
---|
20 | typedef xmlioserver::tree::CFile cfile; |
---|
21 | typedef xmlioserver::tree::CContext ccontext; |
---|
22 | |
---|
23 | typedef xmlioserver::tree::CAxisGroup caxisgroup; |
---|
24 | typedef xmlioserver::tree::CFieldGroup cfieldgroup; |
---|
25 | typedef xmlioserver::tree::CDomainGroup cdomaingroup; |
---|
26 | typedef xmlioserver::tree::CGridGroup cgridgroup; |
---|
27 | typedef xmlioserver::tree::CFileGroup cfilegroup; |
---|
28 | typedef xmlioserver::tree::CContextGroup ccontextgroup; |
---|
29 | |
---|
30 | |
---|
31 | typedef long int XInt, XSize; // Integer |
---|
32 | typedef bool XBool; // Logical |
---|
33 | typedef void * XPtr; // Pointeur C non typé |
---|
34 | typedef char * XString; // Pointeur C non typé |
---|
35 | |
---|
36 | typedef enum |
---|
37 | { |
---|
38 | NOTYPE = 0, |
---|
39 | DTREATMENT/* UNUSED */, DATE, CALENDAR, ECONTEXT, |
---|
40 | EAXIS, EDOMAIN, EFIELD, EFILE, EGRID, |
---|
41 | GAXIS, GDOMAIN, GFIELD, GFILE, GGRID |
---|
42 | } XDType; |
---|
43 | |
---|
44 | typedef enum |
---|
45 | { |
---|
46 | NETCDF4 = 0 |
---|
47 | } XFileType; |
---|
48 | |
---|
49 | typedef enum |
---|
50 | { D360 = 0 , ALLLEAP, NOLEAP, JULIAN, GREGORIAN } XCalendarType ; |
---|
51 | |
---|
52 | //------------------------------------------------------------------- |
---|
53 | |
---|
54 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
55 | DECLARE_INTERFACE(axis, type, name) |
---|
56 | #include "../config/axis_attribute.conf" |
---|
57 | |
---|
58 | #undef DECLARE_ATTRIBUTE |
---|
59 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
60 | DECLARE_INTERFACE(field, type, name) |
---|
61 | #include "../config/field_attribute.conf" |
---|
62 | |
---|
63 | #undef DECLARE_ATTRIBUTE |
---|
64 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
65 | DECLARE_INTERFACE(context, type, name) |
---|
66 | #include "../config/context_attribute.conf" |
---|
67 | |
---|
68 | #undef DECLARE_ATTRIBUTE |
---|
69 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
70 | DECLARE_INTERFACE(domain, type, name) |
---|
71 | #include "../config/domain_attribute.conf" |
---|
72 | |
---|
73 | #undef DECLARE_ATTRIBUTE |
---|
74 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
75 | DECLARE_INTERFACE(file, type, name) |
---|
76 | #include "../config/file_attribute.conf" |
---|
77 | |
---|
78 | #undef DECLARE_ATTRIBUTE |
---|
79 | #define DECLARE_ATTRIBUTE(type, name) \ |
---|
80 | DECLARE_INTERFACE(grid, type, name) |
---|
81 | #include "../config/grid_attribute.conf" |
---|
82 | |
---|
83 | //------------------------------------------------------------------- |
---|
84 | |
---|
85 | #define CASE_ELEM(elem_enum, elem_class) \ |
---|
86 | case (E##elem_enum): ;; { ;; \ |
---|
87 | *_ret = (!CObjectFactory::HasObject<C##elem_class>(__id));; \ |
---|
88 | ? 0 : CObjectFactory::GetObject<C##elem_class>(__id).get(); ;; \ |
---|
89 | return; ;;};; \ |
---|
90 | case (G##elem_enum): ;; { ;; \ |
---|
91 | *_ret = (!CObjectFactory::HasObject<C##elem_class##Group>(__id));; \ |
---|
92 | ? 0 : CObjectFactory::GetObject<C##elem_class##Group>(__id).get(); ;;\ |
---|
93 | return; ;;};; |
---|
94 | |
---|
95 | //------------------------------------------------------------------- |
---|
96 | |
---|
97 | void xios_handle_create (XPtr * const _ret, XDType _dtype, const XString _id, XSize _id_len) |
---|
98 | { |
---|
99 | MAKE_STRING(__id, _id, _id_len); |
---|
100 | switch(_dtype) |
---|
101 | { |
---|
102 | case (ECONTEXT): |
---|
103 | // Si le context n'existe pas, on retourne un handle vide/nul. |
---|
104 | *_ret = (!CObjectFactory::HasObject<CContext>(__id)) |
---|
105 | ? 0 : CObjectFactory::GetObject<CContext>(__id).get(); |
---|
106 | return ; |
---|
107 | CASE_ELEM(AXIS , Axis) |
---|
108 | CASE_ELEM(DOMAIN , Domain) |
---|
109 | CASE_ELEM(FIELD , Field) |
---|
110 | CASE_ELEM(FILE , File) |
---|
111 | CASE_ELEM(GRID , Grid) |
---|
112 | default : |
---|
113 | *_ret = 0; |
---|
114 | return; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | #undef CASE_ELEM |
---|
119 | |
---|
120 | //------------------------------------------------------------------- |
---|
121 | |
---|
122 | void xios_xml_parse_file (const XString _filename, XSize _filename_len) |
---|
123 | { |
---|
124 | try |
---|
125 | { |
---|
126 | MAKE_STRING(__filename, _filename, _filename_len) |
---|
127 | CTreeManager::ParseFile(__filename); |
---|
128 | //~ StdOStringStream oss; |
---|
129 | //~ oss << StdString("data/def/def_client_pre.") |
---|
130 | //~ << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
131 | //~ CTreeManager::PrintTreeToFile(oss.str()); |
---|
132 | } |
---|
133 | catch (CException & exc) |
---|
134 | { |
---|
135 | std::cerr << exc.getMessage() << std::endl; |
---|
136 | exit (EXIT_FAILURE); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | //------------------------------------------------------------------- |
---|
141 | |
---|
142 | void xios_xml_parse_string(const XString _xmlcontent, XSize _xmlcontent_len) |
---|
143 | { |
---|
144 | try |
---|
145 | { |
---|
146 | MAKE_STRING(__xmlcontent, _xmlcontent, _xmlcontent_len) |
---|
147 | CTreeManager::ParseString(__xmlcontent); |
---|
148 | //~ StdOStringStream oss; |
---|
149 | //~ oss << StdString("data/def/def_client_pre.") |
---|
150 | //~ << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
151 | //~ CTreeManager::PrintTreeToFile(oss.str()); |
---|
152 | } |
---|
153 | catch (CException & exc) |
---|
154 | { |
---|
155 | std::cerr << exc.getMessage() << std::endl; |
---|
156 | exit (EXIT_FAILURE); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | //------------------------------------------------------------------- |
---|
161 | |
---|
162 | void xios_context_set_current (XPtr const _ctx, bool _wswap) |
---|
163 | { |
---|
164 | boost::shared_ptr<CContext> context = CObjectFactory::GetObject<CContext> ((CContext*)_ctx); |
---|
165 | CTreeManager::SetCurrentContextId(context->getId()); |
---|
166 | } |
---|
167 | |
---|
168 | //------------------------------------------------------------------- |
---|
169 | |
---|
170 | void xios_context_create (XPtr * _ctxt, const XString _ctxt_id, |
---|
171 | XSize _ctxt_id_len, XCalendarType _calType, |
---|
172 | XInt yr, XInt mth, XInt dd, |
---|
173 | XInt hr, XInt min, XInt sec) |
---|
174 | { |
---|
175 | try |
---|
176 | { |
---|
177 | MAKE_STRING(__ctxt_id, _ctxt_id, _ctxt_id_len) |
---|
178 | boost::shared_ptr<CContext> context = CTreeManager::CreateContext(__ctxt_id); |
---|
179 | *_ctxt = context.get(); |
---|
180 | switch(_calType) |
---|
181 | { |
---|
182 | case (D360) : |
---|
183 | context->setCalendar(boost::shared_ptr<date::CCalendar> |
---|
184 | (new date::CD360Calendar(yr, mth, dd, hr, min, sec))); |
---|
185 | break; |
---|
186 | case (ALLLEAP) : |
---|
187 | context->setCalendar(boost::shared_ptr<date::CCalendar> |
---|
188 | (new date::CAllLeapCalendar(yr, mth, dd, hr, min, sec))); |
---|
189 | break; |
---|
190 | case (NOLEAP) : |
---|
191 | context->setCalendar(boost::shared_ptr<date::CCalendar> |
---|
192 | (new date::CNoLeapCalendar(yr, mth, dd, hr, min, sec))); |
---|
193 | break; |
---|
194 | case (JULIAN) : |
---|
195 | context->setCalendar(boost::shared_ptr<date::CCalendar> |
---|
196 | (new date::CJulianCalendar(yr, mth, dd, hr, min, sec))); |
---|
197 | break; |
---|
198 | case (GREGORIAN): |
---|
199 | context->setCalendar(boost::shared_ptr<date::CCalendar> |
---|
200 | (new date::CGregorianCalendar(yr, mth, dd, hr, min, sec))); |
---|
201 | break; |
---|
202 | default: |
---|
203 | std::cerr << "Le calendrier n'est pas identifié" << std::endl; |
---|
204 | exit (EXIT_FAILURE); |
---|
205 | } |
---|
206 | } |
---|
207 | catch (CException & exc) |
---|
208 | { |
---|
209 | std::cerr << exc.getMessage() << std::endl; |
---|
210 | exit (EXIT_FAILURE); |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | //------------------------------------------------------------------- |
---|
215 | |
---|
216 | #define CASE_ELEM0(elem_enum, elem_class, group_enum, group_class) \ |
---|
217 | case (group_enum) : ;; \ |
---|
218 | { ;; \ |
---|
219 | group_class * _group = (group_class *) _parent; \ |
---|
220 | boost::shared_ptr<group_class> group = ;; \ |
---|
221 | CObjectFactory::GetObject<group_class>(_group); ;; \ |
---|
222 | switch(_child_type) ;; \ |
---|
223 | { ;; \ |
---|
224 | case (group_enum) : ;; \ |
---|
225 | if ((_child_id_len != -1) && ;; \ |
---|
226 | (CObjectFactory::HasObject<group_class>(__child_id))) ;; \ |
---|
227 | return; ;; \ |
---|
228 | *_child = CGroupFactory::CreateGroup(group, __child_id).get(); ;; \ |
---|
229 | break; ;; \ |
---|
230 | case (elem_enum) : ;; \ |
---|
231 | if ((_child_id_len != -1) && ;; \ |
---|
232 | (CObjectFactory::HasObject<elem_class>(__child_id))) ;; \ |
---|
233 | return; ;; \ |
---|
234 | *_child = CGroupFactory::CreateChild(group, __child_id).get(); ;; \ |
---|
235 | break; ;; \ |
---|
236 | default : ;; \ |
---|
237 | std::cerr << "[xml_tree_add] Type enfant invalide" << std::endl; ;; \ |
---|
238 | }; ;; \ |
---|
239 | return; ;; \ |
---|
240 | } |
---|
241 | |
---|
242 | //------------------------------------------------------------------- |
---|
243 | |
---|
244 | void xios_xml_tree_add(const XPtr _parent, XDType _parent_type, XPtr * _child, |
---|
245 | XDType _child_type, const XString _child_id, XSize _child_id_len) |
---|
246 | { |
---|
247 | MAKE_STRING(__child_id, _child_id, _child_id_len); |
---|
248 | try |
---|
249 | { |
---|
250 | switch (_parent_type) |
---|
251 | { |
---|
252 | case (EFILE) : |
---|
253 | { |
---|
254 | CFile * _file = (CFile *) _parent; |
---|
255 | boost::shared_ptr<CFile> file = CObjectFactory::GetObject<CFile>(_file); |
---|
256 | if (!CObjectFactory::HasObject<CFieldGroup>(file->getId())) |
---|
257 | file->setVirtualFieldGroup(file->getId()); |
---|
258 | xios_xml_tree_add (file->getVirtualFieldGroup().get(), GFIELD, |
---|
259 | _child, EFIELD, _child_id, _child_id_len); |
---|
260 | return; |
---|
261 | } |
---|
262 | CASE_ELEM0(EAXIS , CAxis , GAXIS , CAxisGroup); |
---|
263 | CASE_ELEM0(EGRID , CGrid , GGRID , CGridGroup); |
---|
264 | CASE_ELEM0(EDOMAIN, CDomain, GDOMAIN, CDomainGroup); |
---|
265 | CASE_ELEM0(EFIELD , CField , GFIELD , CFieldGroup); |
---|
266 | CASE_ELEM0(EFILE , CFile , GFILE , CFileGroup); |
---|
267 | default : |
---|
268 | std::cerr << "[xml_tree_add] Type parent invalide" << std::endl; |
---|
269 | return; |
---|
270 | } |
---|
271 | } |
---|
272 | catch (CException & exc) |
---|
273 | { |
---|
274 | std::cerr << exc.getMessage() << std::endl; |
---|
275 | exit (EXIT_FAILURE); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | #undef CASE_ELEM0 |
---|
280 | |
---|
281 | //------------------------------------------------------------------- |
---|
282 | |
---|
283 | void xios_xml_tree_show(const XString _filename, XSize _filename_len) |
---|
284 | { |
---|
285 | MAKE_STRING(__filename, _filename, _filename_len); |
---|
286 | if (_filename_len != -1) |
---|
287 | CTreeManager::PrintTreeToFile(__filename); |
---|
288 | else |
---|
289 | CTreeManager::PrintTreeToStream(std::clog); |
---|
290 | } |
---|
291 | |
---|
292 | //------------------------------------------------------------------- |
---|
293 | |
---|
294 | void xios_dtreatment_start |
---|
295 | (XPtr const _context, XFileType filetype, MPIComm comm_client_server) |
---|
296 | { |
---|
297 | try |
---|
298 | { |
---|
299 | CContext * __context = (CContext *) _context; |
---|
300 | boost::shared_ptr<CContext> context = |
---|
301 | CObjectFactory::GetObject<CContext>(__context); |
---|
302 | StdOStringStream oss; |
---|
303 | //~ oss << StdString("data/def/def_client_next.") |
---|
304 | //~ << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
305 | //~ CTreeManager::PrintTreeToFile(oss.str()); |
---|
306 | //~ oss.str(""); |
---|
307 | |
---|
308 | boost::shared_ptr<CDataTreatment> dt(new CDataTreatment (context)); |
---|
309 | context->setDataTreatment(dt); |
---|
310 | |
---|
311 | oss << StdString("data/def/def_client_end.") |
---|
312 | << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
313 | CTreeManager::PrintTreeToFile(oss.str()); |
---|
314 | |
---|
315 | if ((comm_client_server != -1)) |
---|
316 | { |
---|
317 | MPIRequest request = 0; |
---|
318 | StdOStringStream ostrs; |
---|
319 | if (CMPIManager::GetCommRank(comm_client_server) == 1) |
---|
320 | { |
---|
321 | CTreeManager::ToBinary(ostrs); |
---|
322 | CLinearBuffer lbuffer(ostrs.str().size()+13); |
---|
323 | lbuffer.appendString(ostrs.str()); |
---|
324 | CMPIManager::SendLinearBuffer(comm_client_server, 0, lbuffer, request); |
---|
325 | CMPIManager::Wait(request); // Pas encore en mode RPC |
---|
326 | } |
---|
327 | else |
---|
328 | { |
---|
329 | CTreeManager::DomainsToBinary(ostrs); |
---|
330 | CLinearBuffer lbuffer(ostrs.str().size()+13); |
---|
331 | lbuffer.appendString(ostrs.str()); |
---|
332 | CMPIManager::SendLinearBuffer(comm_client_server, 0, lbuffer, request); |
---|
333 | CMPIManager::Wait(request); // Pas encore en mode RPC |
---|
334 | } |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | dt->createDataOutput<CNc4DataOutput>(); |
---|
339 | } |
---|
340 | } |
---|
341 | catch (CException & exc) |
---|
342 | { |
---|
343 | std::cerr << exc.getMessage() << std::endl; |
---|
344 | exit (EXIT_FAILURE); |
---|
345 | } |
---|
346 | } |
---|
347 | |
---|
348 | //------------------------------------------------------------------- |
---|
349 | |
---|
350 | void xios_dtreatment_end(void) |
---|
351 | { |
---|
352 | |
---|
353 | } |
---|
354 | |
---|
355 | //------------------------------------------------------------------- |
---|
356 | |
---|
357 | void xios_write_data(const XString _field_id, XSize _field_id_len, double * data_k8, |
---|
358 | XSize data_Xsize, XSize data_Ysize, XSize data_Zsize) |
---|
359 | { |
---|
360 | |
---|
361 | } |
---|
362 | |
---|
363 | //------------------------------------------------------------------- |
---|
364 | |
---|
365 | void xios_update_calendar(int step) |
---|
366 | { |
---|
367 | try |
---|
368 | { |
---|
369 | } |
---|
370 | catch (CException & exc) |
---|
371 | { |
---|
372 | std::cerr << exc.getMessage() << std::endl; |
---|
373 | exit (EXIT_FAILURE); |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | //------------------------------------------------------------------- |
---|
378 | |
---|
379 | void xios_set_timestep(double ts_year, double ts_month , double ts_day, |
---|
380 | double ts_hour, double ts_minute, double ts_second) |
---|
381 | { |
---|
382 | try |
---|
383 | { |
---|
384 | } |
---|
385 | catch (CException & exc) |
---|
386 | { |
---|
387 | std::cerr << exc.getMessage() << std::endl; |
---|
388 | exit (EXIT_FAILURE); |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | //------------------------------------------------------------------- |
---|
393 | |
---|
394 | #ifdef __cplusplus |
---|
395 | } |
---|
396 | #endif //__cplusplus |
---|