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 | |
---|
8 | #include "xios.hpp" |
---|
9 | |
---|
10 | #include "attribute_template.hpp" |
---|
11 | #include "object_template.hpp" |
---|
12 | #include "group_template.hpp" |
---|
13 | |
---|
14 | #include "icutil.hpp" |
---|
15 | #include "timer.hpp" |
---|
16 | #include "context.hpp" |
---|
17 | #include "grid.hpp" |
---|
18 | #include "file.hpp" |
---|
19 | #include "field.hpp" |
---|
20 | #include "axis.hpp" |
---|
21 | #include "domain.hpp" |
---|
22 | #include "variable.hpp" |
---|
23 | |
---|
24 | extern "C" |
---|
25 | { |
---|
26 | // /////////////////////////////// Définitions ////////////////////////////// // |
---|
27 | |
---|
28 | // ----------------------- Redéfinition de types ---------------------------- |
---|
29 | |
---|
30 | typedef xios::CContext * XContextPtr; |
---|
31 | |
---|
32 | typedef xios::CGrid * XGridPtr; |
---|
33 | typedef xios::CGridGroup * XGridGroupPtr; |
---|
34 | |
---|
35 | typedef xios::CFile * XFilePtr; |
---|
36 | typedef xios::CFileGroup * XFileGroupPtr; |
---|
37 | |
---|
38 | typedef xios::CField * XFieldPtr; |
---|
39 | typedef xios::CFieldGroup * XFieldGroupPtr; |
---|
40 | |
---|
41 | typedef xios::CDomain * XDomainPtr; |
---|
42 | typedef xios::CDomainGroup * XDomainGroupPtr; |
---|
43 | |
---|
44 | typedef xios::CAxis * XAxisPtr; |
---|
45 | typedef xios::CAxisGroup * XAxisGroupPtr; |
---|
46 | |
---|
47 | typedef xios::CVariable * XVariablePtr; |
---|
48 | typedef xios::CVariableGroup * XVariableGroupPtr; |
---|
49 | |
---|
50 | // ----------------------- Ajout d'enfant à un parent ----------------------- |
---|
51 | |
---|
52 | void cxios_xml_tree_add_field |
---|
53 | (XFieldGroupPtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
54 | { |
---|
55 | std::string child_id_str; |
---|
56 | CTimer::get("XIOS").resume() ; |
---|
57 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
58 | { |
---|
59 | *child_ = parent_->createChild(child_id_str) ; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | *child_ = parent_->createChild() ; |
---|
64 | } |
---|
65 | CTimer::get("XIOS").suspend() ; |
---|
66 | } |
---|
67 | |
---|
68 | void cxios_xml_tree_add_grid |
---|
69 | (XGridGroupPtr parent_, XGridPtr * child_, const char * child_id, int child_id_size) |
---|
70 | { |
---|
71 | std::string child_id_str; |
---|
72 | CTimer::get("XIOS").resume() ; |
---|
73 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
74 | { |
---|
75 | *child_ = parent_->createChild(child_id_str) ; |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | *child_ = parent_->createChild() ; |
---|
80 | } |
---|
81 | CTimer::get("XIOS").suspend() ; |
---|
82 | } |
---|
83 | |
---|
84 | void cxios_xml_tree_add_file |
---|
85 | (XFileGroupPtr parent_, XFilePtr * child_, const char * child_id, int child_id_size) |
---|
86 | { |
---|
87 | std::string child_id_str; |
---|
88 | CTimer::get("XIOS").resume() ; |
---|
89 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
90 | { |
---|
91 | *child_ = parent_->createChild(child_id_str) ; |
---|
92 | } |
---|
93 | else |
---|
94 | { |
---|
95 | *child_ = parent_->createChild() ; |
---|
96 | } |
---|
97 | CTimer::get("XIOS").suspend() ; |
---|
98 | } |
---|
99 | |
---|
100 | void cxios_xml_tree_add_axis |
---|
101 | (XAxisGroupPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size) |
---|
102 | { |
---|
103 | std::string child_id_str; |
---|
104 | CTimer::get("XIOS").resume() ; |
---|
105 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
106 | { |
---|
107 | *child_ = parent_->createChild(child_id_str) ; |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | *child_ = parent_->createChild() ; |
---|
112 | } |
---|
113 | CTimer::get("XIOS").suspend() ; |
---|
114 | } |
---|
115 | |
---|
116 | void cxios_xml_tree_add_domain |
---|
117 | (XDomainGroupPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size) |
---|
118 | { |
---|
119 | std::string child_id_str; |
---|
120 | CTimer::get("XIOS").resume() ; |
---|
121 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
122 | { |
---|
123 | *child_ = parent_->createChild(child_id_str) ; |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | *child_ = parent_->createChild() ; |
---|
128 | } |
---|
129 | CTimer::get("XIOS").suspend() ; |
---|
130 | } |
---|
131 | |
---|
132 | void cxios_xml_tree_add_fieldtofile |
---|
133 | (XFilePtr parent_, XFieldPtr * child_, const char * child_id, int child_id_size) |
---|
134 | { |
---|
135 | std::string child_id_str; |
---|
136 | CTimer::get("XIOS").resume() ; |
---|
137 | |
---|
138 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
139 | { |
---|
140 | *child_ = parent_->addField(child_id_str); |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | *child_ = parent_->addField(); |
---|
145 | } |
---|
146 | CTimer::get("XIOS").suspend() ; |
---|
147 | } |
---|
148 | |
---|
149 | void cxios_xml_tree_add_variabletofile |
---|
150 | (XFilePtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
151 | { |
---|
152 | std::string child_id_str; |
---|
153 | CTimer::get("XIOS").resume() ; |
---|
154 | |
---|
155 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
156 | { |
---|
157 | *child_ = parent_->addVariable(child_id_str); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | *child_ = parent_->addVariable(); |
---|
162 | } |
---|
163 | CTimer::get("XIOS").suspend() ; |
---|
164 | } |
---|
165 | |
---|
166 | void cxios_xml_tree_add_variabletofield |
---|
167 | (XFieldPtr parent_, XVariablePtr * child_, const char * child_id, int child_id_size) |
---|
168 | { |
---|
169 | std::string child_id_str; |
---|
170 | CTimer::get("XIOS").resume() ; |
---|
171 | |
---|
172 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
173 | { |
---|
174 | *child_ = parent_->addVariable(child_id_str); |
---|
175 | } |
---|
176 | else |
---|
177 | { |
---|
178 | *child_ = parent_->addVariable(); |
---|
179 | } |
---|
180 | CTimer::get("XIOS").suspend() ; |
---|
181 | } |
---|
182 | // ----------------------- Ajout de groupe à un parent ---------------------- |
---|
183 | |
---|
184 | void cxios_xml_tree_add_fieldgroup |
---|
185 | (XFieldGroupPtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
186 | { |
---|
187 | std::string child_id_str; |
---|
188 | CTimer::get("XIOS").resume() ; |
---|
189 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
190 | { |
---|
191 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | *child_ = parent_->createChildGroup() ; |
---|
196 | } |
---|
197 | CTimer::get("XIOS").suspend() ; |
---|
198 | } |
---|
199 | |
---|
200 | void cxios_xml_tree_add_gridgroup |
---|
201 | (XGridGroupPtr parent_, XGridGroupPtr * child_, const char * child_id, int child_id_size) |
---|
202 | { |
---|
203 | std::string child_id_str; |
---|
204 | CTimer::get("XIOS").resume() ; |
---|
205 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
206 | { |
---|
207 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
208 | } |
---|
209 | else |
---|
210 | { |
---|
211 | *child_ = parent_->createChildGroup() ; |
---|
212 | } |
---|
213 | CTimer::get("XIOS").suspend() ; |
---|
214 | } |
---|
215 | |
---|
216 | void cxios_xml_tree_add_filegroup |
---|
217 | (XFileGroupPtr parent_, XFileGroupPtr * child_, const char * child_id, int child_id_size) |
---|
218 | { |
---|
219 | std::string child_id_str; |
---|
220 | CTimer::get("XIOS").resume() ; |
---|
221 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
222 | { |
---|
223 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | *child_ = parent_->createChildGroup() ; |
---|
228 | } |
---|
229 | CTimer::get("XIOS").suspend() ; |
---|
230 | } |
---|
231 | |
---|
232 | void cxios_xml_tree_add_axisgroup |
---|
233 | (XAxisGroupPtr parent_, XAxisGroupPtr * child_, const char * child_id, int child_id_size) |
---|
234 | { |
---|
235 | std::string child_id_str; |
---|
236 | CTimer::get("XIOS").resume() ; |
---|
237 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
238 | { |
---|
239 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | *child_ = parent_->createChildGroup() ; |
---|
244 | } |
---|
245 | CTimer::get("XIOS").suspend() ; |
---|
246 | } |
---|
247 | |
---|
248 | void cxios_xml_tree_add_domaingroup |
---|
249 | (XDomainGroupPtr parent_, XDomainGroupPtr * child_, const char * child_id, int child_id_size) |
---|
250 | { |
---|
251 | std::string child_id_str; |
---|
252 | CTimer::get("XIOS").resume() ; |
---|
253 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
254 | { |
---|
255 | *child_ = parent_->createChildGroup(child_id_str) ; |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | *child_ = parent_->createChildGroup() ; |
---|
260 | } |
---|
261 | CTimer::get("XIOS").suspend() ; |
---|
262 | } |
---|
263 | |
---|
264 | void cxios_xml_tree_add_fieldgrouptofile |
---|
265 | (XFilePtr parent_, XFieldGroupPtr * child_, const char * child_id, int child_id_size) |
---|
266 | { |
---|
267 | std::string child_id_str; |
---|
268 | CTimer::get("XIOS").resume() ; |
---|
269 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
270 | { |
---|
271 | *child_ = parent_->addFieldGroup(child_id_str); |
---|
272 | } |
---|
273 | else |
---|
274 | { |
---|
275 | *child_ = parent_->addFieldGroup(); |
---|
276 | } |
---|
277 | CTimer::get("XIOS").suspend() ; |
---|
278 | } |
---|
279 | |
---|
280 | void cxios_xml_tree_add_variablegrouptofile |
---|
281 | (XFilePtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
282 | { |
---|
283 | std::string child_id_str; |
---|
284 | CTimer::get("XIOS").resume() ; |
---|
285 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
286 | { |
---|
287 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
288 | } |
---|
289 | else |
---|
290 | { |
---|
291 | *child_ = parent_->addVariableGroup(); |
---|
292 | } |
---|
293 | CTimer::get("XIOS").suspend() ; |
---|
294 | } |
---|
295 | |
---|
296 | void cxios_xml_tree_add_variablegrouptofield |
---|
297 | (XFieldPtr parent_, XVariableGroupPtr * child_, const char * child_id, int child_id_size) |
---|
298 | { |
---|
299 | std::string child_id_str; |
---|
300 | CTimer::get("XIOS").resume() ; |
---|
301 | if (cstr2string(child_id, child_id_size, child_id_str)) |
---|
302 | { |
---|
303 | *child_ = parent_->addVariableGroup(child_id_str); |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | *child_ = parent_->addVariableGroup(); |
---|
308 | } |
---|
309 | CTimer::get("XIOS").suspend() ; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | // ----------------------- Affichage de l'arborescence ---------------------- |
---|
314 | |
---|
315 | // void cxios_xml_tree_show (const char * filename, int filename_size) |
---|
316 | // { |
---|
317 | // std::string filename_str; |
---|
318 | // try |
---|
319 | // { |
---|
320 | // if (cstr2string(filename, filename_size, filename_str)) |
---|
321 | // xios::CTreeManager::PrintTreeToFile(filename_str); |
---|
322 | // else |
---|
323 | // xios::CTreeManager::PrintTreeToStream(std::clog); |
---|
324 | // } |
---|
325 | // catch (xios::CException & exc) |
---|
326 | // { |
---|
327 | // std::cerr << exc.getMessage() << std::endl; |
---|
328 | // exit (EXIT_FAILURE); |
---|
329 | // } |
---|
330 | // } |
---|
331 | |
---|
332 | |
---|
333 | // ----------------------- Parsing de document xml -------------------------- |
---|
334 | |
---|
335 | // void cxios_xml_parse_file (const char * filename , int filename_size)// |
---|
336 | // { |
---|
337 | // std::string filename_str; |
---|
338 | // if (!cstr2string(filename, filename_size, filename_str)) return; |
---|
339 | // |
---|
340 | // try |
---|
341 | // { |
---|
342 | // xios::CTreeManager::ParseFile(filename_str); |
---|
343 | // } |
---|
344 | // catch (xios::CException & exc) |
---|
345 | // { |
---|
346 | // std::cerr << exc.getMessage() << std::endl; |
---|
347 | // exit (EXIT_FAILURE); |
---|
348 | // } |
---|
349 | // } |
---|
350 | |
---|
351 | // void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size) |
---|
352 | // { |
---|
353 | // std::string xmlcontent_str; |
---|
354 | // if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return; |
---|
355 | // |
---|
356 | // try |
---|
357 | // { |
---|
358 | // xios::CTreeManager::ParseString(xmlcontent_str); |
---|
359 | // } |
---|
360 | // catch (xios::CException & exc) |
---|
361 | // { |
---|
362 | // std::cerr << exc.getMessage() << std::endl; |
---|
363 | // exit (EXIT_FAILURE); |
---|
364 | // } |
---|
365 | // } |
---|
366 | |
---|
367 | |
---|
368 | |
---|
369 | } // extern "C" |
---|