source: XIOS/trunk/src/interface/c_attr/iccalendar_wrapper_attr.cpp @ 549

Last change on this file since 549 was 549, checked in by rlacroix, 6 years ago

Revised calendar functionalities:

  • the calendar is now configured from a specific calendar child node of the context in the XML configuration file. Example: <calendar type="Gregorian" start_date="2012-03-01 15:00:00" time_origin="2012-02-29 15:00:00" timestep="1h" />
  • the calendar type should now be configured when defining the start time and/or the time origin.
  • the start time and the time origin are now optional, 0000-01-01 00:00:00 will be used by default. It is also possible to define them partially. For example, 2015 and 2014-12 are valid dates corresponding respectively to 2015-01-01 00:00:00 and 2014-12-01 00:00:00.
  • an optional duration offset can be added to the start date and time origin. For example, it's possible to define the date 2015-01-12 12:00:00 as 2015-01-11 + 36h or 2015-01-11 12:00:00 + 1d. The duration format is the same as the time step. Being that the date is optional, it is possible to only use a duration (for example + 42s is the same as 0000-01-01 00:00:00 + 42s). An error will be raised if a duration based on the time step is used before the time step was configured. For example, the following would cause an error: <calendar type="Gregorian" start_date="+ 1ts" /> but <calendar type="Gregorian" start_date="+ 1ts" timestep="0.5h" /> would not.
  • new Fortran interface to define the calendar:
    • xios_define_calendar(type[, timestep, start_date, time_origin]) will create a calendar when none had previously been defined. Only the type argument is mandatory, the rest is optional. Calendar operations on dates and durations are possible as soon as the calendar is created (either using this procedure or directly from the XML configuration file).
    • the following getter and setter procedures are available: xios_set_timestep, xios_set_start_date, xios_set_time_origin, xios_get_calendar_type, xios_get_timestep, xios_get_start_date, xios_get_time_origin.
  • new Fortran interface to interact with the calendar: xios_update_calendar, xios_get_current_date, xios_get_year_length_in_seconds, xios_get_day_length_in_seconds.
  • new Fortran interface for date conversion: xios_date_get_second_of_year, xios_date_get_day_of_year, xios_date_get_fraction_of_year, xios_date_get_second_of_day, xios_date_get_fraction_of_day.
  • two new placeholders are available to format the file name when splitting the output (split_freq_format attribute):
    • %S the number of seconds since the time origin
    • %D the integral number of days since the time origin
File size: 5.1 KB
Line 
1/* ************************************************************************** *
2 *               Interface auto generated - do not modify                   *
3 * ************************************************************************** */
4
5#include <boost/multi_array.hpp>
6#include <boost/shared_ptr.hpp>
7#include "xmlioserver.hpp"
8#include "attribute_template.hpp"
9#include "object_template.hpp"
10#include "group_template.hpp"
11#include "icutil.hpp"
12#include "icdate.hpp"
13#include "timer.hpp"
14#include "node_type.hpp"
15
16extern "C"
17{
18  typedef xios::CCalendarWrapper*  calendar_wrapper_Ptr;
19 
20  void cxios_set_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * start_date, int start_date_size)
21  {
22    std::string start_date_str;
23    if(!cstr2string(start_date, start_date_size, start_date_str)) return;
24     CTimer::get("XIOS").resume();
25    calendar_wrapper_hdl->start_date.setValue(start_date_str);
26     CTimer::get("XIOS").suspend();
27  }
28 
29  void cxios_get_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, char * start_date, int start_date_size)
30  {
31     CTimer::get("XIOS").resume();
32    if(!string_copy(calendar_wrapper_hdl->start_date.getInheritedValue(),start_date , start_date_size))
33      ERROR("void cxios_get_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, char * start_date, int start_date_size)", <<"Input string is to short");
34     CTimer::get("XIOS").suspend();
35  }
36 
37  bool cxios_is_defined_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl )
38  {
39     CTimer::get("XIOS").resume();
40    return calendar_wrapper_hdl->start_date.hasInheritedValue();
41     CTimer::get("XIOS").suspend();
42  }
43 
44 
45 
46  void cxios_set_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * time_origin, int time_origin_size)
47  {
48    std::string time_origin_str;
49    if(!cstr2string(time_origin, time_origin_size, time_origin_str)) return;
50     CTimer::get("XIOS").resume();
51    calendar_wrapper_hdl->time_origin.setValue(time_origin_str);
52     CTimer::get("XIOS").suspend();
53  }
54 
55  void cxios_get_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl, char * time_origin, int time_origin_size)
56  {
57     CTimer::get("XIOS").resume();
58    if(!string_copy(calendar_wrapper_hdl->time_origin.getInheritedValue(),time_origin , time_origin_size))
59      ERROR("void cxios_get_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl, char * time_origin, int time_origin_size)", <<"Input string is to short");
60     CTimer::get("XIOS").suspend();
61  }
62 
63  bool cxios_is_defined_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl )
64  {
65     CTimer::get("XIOS").resume();
66    return calendar_wrapper_hdl->time_origin.hasInheritedValue();
67     CTimer::get("XIOS").suspend();
68  }
69 
70 
71 
72  void cxios_set_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl, cxios_duration timestep_c)
73  {
74    CTimer::get("XIOS").resume();
75    calendar_wrapper_hdl->timestep.allocate();
76    CDuration& timestep = calendar_wrapper_hdl->timestep.get();
77    timestep.year = timestep_c.year;
78    timestep.month = timestep_c.month;
79    timestep.day = timestep_c.day;
80    timestep.hour = timestep_c.hour;
81    timestep.minute = timestep_c.minute;
82    timestep.second = timestep_c.second;
83    timestep.timestep = timestep_c.timestep;
84    CTimer::get("XIOS").suspend();
85  }
86 
87  void cxios_get_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl, cxios_duration* timestep_c)
88  {
89    CTimer::get("XIOS").resume();
90    CDuration timestep = calendar_wrapper_hdl->timestep.getInheritedValue();
91    timestep_c->year = timestep.year;
92    timestep_c->month = timestep.month;
93    timestep_c->day = timestep.day;
94    timestep_c->hour = timestep.hour;
95    timestep_c->minute = timestep.minute;
96    timestep_c->second = timestep.second;
97    timestep_c->timestep = timestep.timestep;
98    CTimer::get("XIOS").suspend();
99  }
100 
101  bool cxios_is_defined_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl )
102  {
103     CTimer::get("XIOS").resume();
104    return calendar_wrapper_hdl->timestep.hasInheritedValue();
105     CTimer::get("XIOS").suspend();
106  }
107 
108 
109 
110  void cxios_set_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * type, int type_size)
111  {
112    std::string type_str;
113    if(!cstr2string(type, type_size, type_str)) return;
114     CTimer::get("XIOS").resume();
115    calendar_wrapper_hdl->type.fromString(type_str);
116     CTimer::get("XIOS").suspend();
117  }
118 
119  void cxios_get_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, char * type, int type_size)
120  {
121     CTimer::get("XIOS").resume();
122    if(!string_copy(calendar_wrapper_hdl->type.getInheritedStringValue(),type , type_size))
123      ERROR("void cxios_get_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, char * type, int type_size)", <<"Input string is to short");
124     CTimer::get("XIOS").suspend();
125  }
126 
127  bool cxios_is_defined_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl )
128  {
129     CTimer::get("XIOS").resume();
130    return calendar_wrapper_hdl->type.hasInheritedValue();
131     CTimer::get("XIOS").suspend();
132  }
133 
134 
135 
136 
137}
Note: See TracBrowser for help on using the repository browser.