source: XIOS/trunk/src/interface/c/icxml_tree.cpp @ 835

Last change on this file since 835 was 835, checked in by mhnguyen, 8 years ago

Exposing some functions to Fortran interface

+) Allow add axis and domain into grid with Fortran interface
+) Remove some redundant code

Test
+) On Curie
+) test_client passes

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
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
24extern "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   void cxios_xml_tree_add_axistogrid
313      (XGridPtr parent_, XAxisPtr * child_, const char * child_id, int child_id_size)
314   {
315      std::string child_id_str;
316      CTimer::get("XIOS").resume() ;
317      if (cstr2string(child_id, child_id_size, child_id_str))
318      {
319         *child_ = parent_->addAxis(child_id_str);
320      }
321      else
322      {
323         *child_ = parent_->addAxis();
324      }
325      CTimer::get("XIOS").suspend() ;
326   }
327
328   void cxios_xml_tree_add_domaintogrid
329      (XGridPtr parent_, XDomainPtr * child_, const char * child_id, int child_id_size)
330   {
331      std::string child_id_str;
332      CTimer::get("XIOS").resume() ;
333      if (cstr2string(child_id, child_id_size, child_id_str))
334      {
335         *child_ = parent_->addDomain(child_id_str);
336      }
337      else
338      {
339         *child_ = parent_->addDomain();
340      }
341      CTimer::get("XIOS").suspend() ;
342   }
343
344   // ----------------------- Affichage de l'arborescence ----------------------
345
346//   void cxios_xml_tree_show   (const char * filename, int filename_size)
347//   {
348//      std::string filename_str;
349//      try
350//      {
351//         if (cstr2string(filename, filename_size, filename_str))
352//            xios::CTreeManager::PrintTreeToFile(filename_str);
353//         else
354//            xios::CTreeManager::PrintTreeToStream(std::clog);
355//      }
356//      catch (xios::CException & exc)
357//      {
358//         std::cerr << exc.getMessage() << std::endl;
359//         exit (EXIT_FAILURE);
360//      }
361//  }
362
363
364   // ----------------------- Parsing de document xml --------------------------
365
366//   void cxios_xml_parse_file  (const char * filename  , int filename_size)//
367//   {
368//      std::string filename_str;
369//      if (!cstr2string(filename, filename_size, filename_str)) return;
370//
371//      try
372//      {
373//         xios::CTreeManager::ParseFile(filename_str);
374//      }
375//      catch (xios::CException & exc)
376//      {
377//         std::cerr << exc.getMessage() << std::endl;
378//         exit (EXIT_FAILURE);
379//      }
380//   }
381
382//   void cxios_xml_parse_string(const char * xmlcontent, int xmlcontent_size)
383//   {
384//      std::string xmlcontent_str;
385//      if (!cstr2string(xmlcontent, xmlcontent_size, xmlcontent_str)) return;
386//
387//      try
388//      {
389//         xios::CTreeManager::ParseString(xmlcontent_str);
390//      }
391//      catch (xios::CException & exc)
392//      {
393//         std::cerr << exc.getMessage() << std::endl;
394//         exit (EXIT_FAILURE);
395//      }
396//   }
397
398
399
400} // extern "C"
Note: See TracBrowser for help on using the repository browser.