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