source: XMLIO_V2/dev/dev_rv/src/xmlio/fortran/iccontext.cpp @ 270

Last change on this file since 270 was 270, checked in by hozdoba, 13 years ago

Début nouvelle interface fortran

File size: 5.1 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5#include <boost/multi_array.hpp>
6#include <boost/shared_ptr.hpp>
7
8#include "xmlioserver.hpp"
9
10#include "attribute_template_impl.hpp"
11#include "object_template_impl.hpp"
12#include "group_template_impl.hpp"
13
14#include "calendar_type.hpp"
15
16#include "icutil.hpp"
17
18extern "C"
19{
20// /////////////////////////////// Définitions ////////////////////////////// //
21
22   // ----------------------- Redéfinition de types ----------------------------
23
24   typedef enum { D360 = 0 , ALLLEAP, NOLEAP, JULIAN, GREGORIAN } XCalendarType ;
25
26   typedef xmlioserver::tree::CContext * XContextPtr;
27
28   // ------------------------- Attributs des contextes ------------------------
29   
30   
31   void xios_set_context_calendar_type(XContextPtr context_hdl, const char * calendar_type, int calendar_type_size)
32   {
33      std::string calendar_type_str; 
34      if (!cstr2string(calendar_type, calendar_type_size, calendar_type_str)) return;
35
36      context_hdl->calendar_type.setValue(calendar_type_str);
37   }
38   
39   void xios_set_context_start_date(XContextPtr context_hdl, const char * start_date, int start_date_size)
40   {
41      std::string start_date_str; 
42      if (!cstr2string(start_date, start_date_size, start_date_str)) return;
43
44      context_hdl->start_date.setValue(start_date_str);
45   }
46   
47   void xios_set_context_output_dir(XContextPtr context_hdl, const char * output_dir, int output_dir_size)
48   {
49      std::string output_dir_str; 
50      if (!cstr2string(output_dir, output_dir_size, output_dir_str)) return;
51
52      context_hdl->output_dir.setValue(output_dir_str);
53   }
54   
55   // ------------------------ Création des handle -----------------------------
56   
57   void xios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len)
58   {
59      std::string id; 
60      if (!cstr2string(_id, _id_len, id)) return;
61
62      std::vector<boost::shared_ptr<xmlioserver::tree::CContext> > def_vector =
63            xmlioserver::tree::CContext::GetContextGroup()->getChildList();
64
65      for (std::size_t i = 0; i < def_vector.size(); i++)
66           {
67          if (def_vector[i]->getId().compare(id) == 0)
68          *_ret = def_vector[i].get();
69          return;
70      }
71      // Lever une execption ici
72   }
73   
74   // ------------------------ Changements de contextes ------------------------
75   
76   void xios_context_set_current(XContextPtr context, bool withswap)
77   {
78      CTreeManager::SetCurrentContextId(context->getId());
79   }
80   
81   // ------------------------ Création de contexte ----------------------------
82   
83   void xios_context_create(XContextPtr * context,
84                            const char  * context_id,
85                            int           context_id_size,
86                            XCalendarType calendar_type,
87                            int           year,
88                            int           month,
89                            int           day,
90                            int           hour,
91                            int           minute,
92                            int           second)
93   {
94      std::string context_id_str; 
95      if (!cstr2string(context_id, context_id_size, context_id_str)) return;
96      try
97      {
98         boost::shared_ptr<xmlioserver::tree::CContext> _context =
99            CTreeManager::CreateContext(context_id_str);
100         *context = _context.get();
101         switch(calendar_type)
102         {
103            case (D360)     :
104               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
105                  (new xmlioserver::date::CD360Calendar
106                     (year, month, day, hour, minute, second)));
107               break;
108            case (ALLLEAP)  :
109               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
110                  (new xmlioserver::date::CAllLeapCalendar
111                     (year, month, day, hour, minute, second)));
112               break;
113            case (NOLEAP)   :
114               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
115                  (new xmlioserver::date::CNoLeapCalendar
116                     (year, month, day, hour, minute, second)));
117               break;
118            case (JULIAN)   :
119               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
120                  (new xmlioserver::date::CJulianCalendar
121                     (year, month, day, hour, minute, second)));
122               break;
123            case (GREGORIAN):
124               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
125                  (new xmlioserver::date::CGregorianCalendar
126                     (year, month, day, hour, minute, second)));
127                break;
128            default:
129               std::cerr << "Le calendrier n'est pas identifié" << std::endl;
130               exit (EXIT_FAILURE);
131         }
132      }
133      catch (xmlioserver::CException & exc)
134      {
135         std::cerr << exc.getMessage() << std::endl;
136         exit (EXIT_FAILURE);
137      }
138   }
139   
140} // extern "C"
Note: See TracBrowser for help on using the repository browser.