source: XIOS/trunk/src/interface/c/iccontext.cpp @ 587

Last change on this file since 587 was 545, checked in by rlacroix, 9 years ago

Expose the calendar operations through the Fortran interface.

  • Add arithmetic operations on the xios_duration and xios_date types:
    • xios_duration + xios_duration = xios_duration
    • xios_duration - xios_duration = xios_duration
    • scalar * xios_duration = xios_duration * scalar = xios_duration
    • - xios_duration = xios_duration
    • xios_date + xios_duration = xios_date
    • xios_date - xios_duration = xios_date
    • xios_date - xios_date = xios_duration
  • Add comparison operations on the xios_duration and xios_date types:
    • xios_duration: ==, /=
    • xios_date: ==, /=, <, <=, >, >=
  • Add a new function "xios_date_convert_to_seconds" to convert a date into the number of seconds since the time origin of the calendar
  • Define some constant durations "xios_second", "xios_minute", "xios_hour", "xios_day", "xios_month", "xios_year" et "xios_timestep" to ease the definition of new durations (for example, 10h is just 10 * xios_hour)
  • Add a new function "xios_set_calendar" so that one can manually create the calendar attached to the current context and thus use the calendar operations before calling "xios_close_context_definition". This function can accept optional parameters so that the calendar attributes (calendar_type, start_date, time_origin and timestep) can be easily overwritten. Note that you cannot define a new calendar after one was already created (either because "xios_set_calendar" or "xios_close_context_definition" was used)
  • Readd the function "xios_set_timestep" as a simplified alias of "xios_set_context_attr(context, timestep)" for the current context
  • 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: 2.7 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 "xmlioserver.hpp"
9
10#include "attribute_template.hpp"
11#include "object_template.hpp"
12#include "group_template.hpp"
13
14#include "calendar_type.hpp"
15
16#include "icutil.hpp"
17#include "timer.hpp"
18#include "context.hpp"
19
20extern "C"
21{
22// /////////////////////////////// Définitions ////////////////////////////// //
23
24   // ----------------------- Redéfinition de types ----------------------------
25
26   typedef enum { D360 = 0 , ALLLEAP, NOLEAP, JULIAN, GREGORIAN } XCalendarType ;
27
28   typedef xios::CContext * XContextPtr;
29
30   // ------------------------ Création des handle -----------------------------
31
32   void cxios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len)
33   {
34      std::string id;
35      if (!cstr2string(_id, _id_len, id)) return;
36      CTimer::get("XIOS").resume() ;
37
38      std::vector<xios::CContext*> def_vector =
39            xios::CContext::getRoot()->getChildList();
40
41      for (std::size_t i = 0; i < def_vector.size(); i++)
42      {
43          if (def_vector[i]->getId().compare(id) == 0)
44          {
45            *_ret = def_vector[i];
46             CTimer::get("XIOS").suspend() ;
47            return;
48          }
49      }
50       CTimer::get("XIOS").suspend() ;
51       ERROR("void cxios_context_handle_create (XContextPtr * _ret, const char * _id, int _id_len)",
52             << "Context "<<id<<"  unknown");
53      // Lever une exeception ici
54   }
55
56   // ------------------------ Changements de contextes ------------------------
57
58   void cxios_context_get_current(XContextPtr* context)
59   {
60      CTimer::get("XIOS").resume();
61      *context = CContext::getCurrent();
62      CTimer::get("XIOS").suspend();
63   }
64
65   void cxios_context_set_current(XContextPtr context, bool withswap)
66   {
67      CTimer::get("XIOS").resume() ;
68      CContext::setCurrent(context->getId());
69      CTimer::get("XIOS").suspend() ;
70   }
71
72   // -------------------- Vérification des identifiants -----------------------
73
74   void cxios_context_valid_id (bool * _ret, const char * _id, int _id_len)
75   {
76      std::string id;
77      if (!cstr2string(_id, _id_len, id)) return;
78
79      CTimer::get("XIOS").resume();
80      std::vector<xios::CContext*> def_vector =
81            xios::CContext::getRoot()->getChildList();
82
83      *_ret = false;
84      for (std::size_t i = 0; i < def_vector.size(); i++)
85      {
86        if (def_vector[i]->getId().compare(id) == 0)
87        {
88          *_ret = true;
89          break;
90        }
91      }
92      CTimer::get("XIOS").suspend();
93   }
94} // extern "C"
Note: See TracBrowser for help on using the repository browser.