source: XIOS/dev/common/src/fortran/iccontext.cpp @ 1511

Last change on this file since 1511 was 300, checked in by ymipsl, 12 years ago

nouvelle version de developpement de xios

  • nouvelle interface fortran
  • recodage complet de la couche de communication
  • et bien d'autres choses...

YM

File size: 5.9 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 cxios_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      context_hdl->calendar_type.setValue(calendar_type_str);
36      context_hdl->sendAttributToServer(context_hdl->calendar_type) ;
37   }
38   
39   void cxios_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      context_hdl->sendAttributToServer(context_hdl->start_date) ; 
46   }
47   
48   void cxios_set_context_output_dir(XContextPtr context_hdl, const char * output_dir, int output_dir_size)
49   {
50      std::string output_dir_str; 
51      if (!cstr2string(output_dir, output_dir_size, output_dir_str)) return;
52
53      context_hdl->output_dir.setValue(output_dir_str);
54      context_hdl->sendAttributToServer(context_hdl->output_dir) ; 
55   }
56   
57   // ------------------------ Création des handle -----------------------------
58   
59   void cxios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len)
60   {
61      std::string id; 
62      if (!cstr2string(_id, _id_len, id)) return;
63
64      std::vector<boost::shared_ptr<xmlioserver::tree::CContext> > def_vector =
65            xmlioserver::tree::CContext::GetContextGroup()->getChildList();
66
67      for (std::size_t i = 0; i < def_vector.size(); i++)
68           {
69          if (def_vector[i]->getId().compare(id) == 0)
70          *_ret = def_vector[i].get();
71          return;
72      }
73      // Lever une execption ici
74   }
75   
76   // ------------------------ Changements de contextes ------------------------
77   
78   void cxios_context_set_current(XContextPtr context, bool withswap)
79   {
80      CTreeManager::SetCurrentContextId(context->getId());
81   }
82   
83   // ------------------------ Création de contexte ----------------------------
84   
85   void cxios_context_create(XContextPtr * context,
86                            const char  * context_id,
87                            int           context_id_size,
88                            XCalendarType calendar_type,
89                            int           year,
90                            int           month,
91                            int           day,
92                            int           hour,
93                            int           minute,
94                            int           second)
95   {
96      std::string context_id_str; 
97      if (!cstr2string(context_id, context_id_size, context_id_str)) return;
98      try
99      {
100         boost::shared_ptr<xmlioserver::tree::CContext> _context =
101            CTreeManager::CreateContext(context_id_str);
102         *context = _context.get();
103         switch(calendar_type)
104         {
105            case (D360)     :
106               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
107                  (new xmlioserver::date::CD360Calendar
108                     (year, month, day, hour, minute, second)));
109               break;
110            case (ALLLEAP)  :
111               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
112                  (new xmlioserver::date::CAllLeapCalendar
113                     (year, month, day, hour, minute, second)));
114               break;
115            case (NOLEAP)   :
116               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
117                  (new xmlioserver::date::CNoLeapCalendar
118                     (year, month, day, hour, minute, second)));
119               break;
120            case (JULIAN)   :
121               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
122                  (new xmlioserver::date::CJulianCalendar
123                     (year, month, day, hour, minute, second)));
124               break;
125            case (GREGORIAN):
126               _context->setCalendar(boost::shared_ptr<xmlioserver::date::CCalendar>
127                  (new xmlioserver::date::CGregorianCalendar
128                     (year, month, day, hour, minute, second)));
129                break;
130            default:
131               std::cerr << "Le calendrier n'est pas identifié" << std::endl;
132               exit (EXIT_FAILURE);
133         }
134      }
135      catch (xmlioserver::CException & exc)
136      {
137         std::cerr << exc.getMessage() << std::endl;
138         exit (EXIT_FAILURE);
139      }
140   }
141
142   // -------------------- Vérification des identifiants -----------------------
143
144   void cxios_context_valid_id (bool * _ret, const char * _id, int _id_len)
145   {
146      std::string id;
147      if (!cstr2string(_id, _id_len, id)) return;
148
149      std::vector<boost::shared_ptr<xmlioserver::tree::CContext> > def_vector =
150            xmlioserver::tree::CContext::GetContextGroup()->getChildList();
151
152      for (std::size_t i = 0; i < def_vector.size(); i++)
153           {
154          if (def_vector[i]->getId().compare(id) == 0)
155          *_ret = true;
156      }
157     *_ret = false;
158   }
159} // extern "C"
Note: See TracBrowser for help on using the repository browser.