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

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

Add a new user defined calendar type.

A new calendar type "user_defined" is now available. This allows the users to create a custom calendar that we can configured to be suitable for planets other than the Earth.

An user defined calendar is always defined by two mandatory attributes:

  • day_length: the duration of a day, in seconds
  • and either:
    • month_length: an array containing the duration of each month, in days (the number of elements in the array is the number of months in a year)
    • or year_length: the duration of a year, in seconds (in that case, the calendar does not have months).

If the calendar has months (i.e. month_length attribute is set) and only in that case, it is possible to define leap years in order to compensate for the duration of an astronomical year not being a multiple of the day length. The leap years are defined by two mandatory attributes:

  • leap_year_month: the month to which the extra day will be added in case of leap year, expressed as an integer number in the range [1, numberOfMonths]
  • and leap_year_drift: the fraction of a day representing the yearly drift between the calendar year and the astronomical year, expressed as a real number in the range [0, 1).

Optionally, one can define the leap_year_drift_offset attribute to set the original drift at the beginning of the time origin's year, again expressed as a real number in the range [0, 1). If leap_year_drift_offset + leap_year_drift is greater or equal to 1, then the first year will be a leap year.

For example, the following configuration creates a Gregorian-like calendar:

<calendar type="user_defined" start_date="2012-03-01 15:00:00" time_origin="2012-02-28 15:00:00 + 1d" day_length="86400" month_lengths="(1, 12) [31 28 31 30 31 30 31 31 30 31 30 31]" leap_year_month="2" leap_year_drift="0.25" leap_year_drift_offset="0.75" />

Note that dates attributes must be written differently in the configuration file when using an user defined calendar without months:

  • if the year length is greater than the day length, the input format is year-day hh:min:sec instead of year-month-day hh:min:sec
  • if the day length is greater or equal to the year length, the input format is year hh:min:sec.

In all cases, it is still possible to use the date + duration notation to build a date (with both the date and duration parts being optional).

The Fortran interface has been updated accordingly so that xios_define_calendar can accept the new attributes necessary to define custom calendars.

File size: 9.6 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_day_length(calendar_wrapper_Ptr calendar_wrapper_hdl, int day_length)
21  {
22     CTimer::get("XIOS").resume();
23    calendar_wrapper_hdl->day_length.setValue(day_length);
24     CTimer::get("XIOS").suspend();
25  }
26 
27  void cxios_get_calendar_wrapper_day_length(calendar_wrapper_Ptr calendar_wrapper_hdl, int* day_length)
28  {
29    *day_length = calendar_wrapper_hdl->day_length.getInheritedValue();
30  }
31 
32  bool cxios_is_defined_calendar_wrapper_day_length(calendar_wrapper_Ptr calendar_wrapper_hdl )
33  {
34     CTimer::get("XIOS").resume();
35    return calendar_wrapper_hdl->day_length.hasInheritedValue();
36     CTimer::get("XIOS").suspend();
37  }
38 
39 
40 
41  void cxios_set_calendar_wrapper_leap_year_drift(calendar_wrapper_Ptr calendar_wrapper_hdl, double leap_year_drift)
42  {
43     CTimer::get("XIOS").resume();
44    calendar_wrapper_hdl->leap_year_drift.setValue(leap_year_drift);
45     CTimer::get("XIOS").suspend();
46  }
47 
48  void cxios_get_calendar_wrapper_leap_year_drift(calendar_wrapper_Ptr calendar_wrapper_hdl, double* leap_year_drift)
49  {
50    *leap_year_drift = calendar_wrapper_hdl->leap_year_drift.getInheritedValue();
51  }
52 
53  bool cxios_is_defined_calendar_wrapper_leap_year_drift(calendar_wrapper_Ptr calendar_wrapper_hdl )
54  {
55     CTimer::get("XIOS").resume();
56    return calendar_wrapper_hdl->leap_year_drift.hasInheritedValue();
57     CTimer::get("XIOS").suspend();
58  }
59 
60 
61 
62  void cxios_set_calendar_wrapper_leap_year_drift_offset(calendar_wrapper_Ptr calendar_wrapper_hdl, double leap_year_drift_offset)
63  {
64     CTimer::get("XIOS").resume();
65    calendar_wrapper_hdl->leap_year_drift_offset.setValue(leap_year_drift_offset);
66     CTimer::get("XIOS").suspend();
67  }
68 
69  void cxios_get_calendar_wrapper_leap_year_drift_offset(calendar_wrapper_Ptr calendar_wrapper_hdl, double* leap_year_drift_offset)
70  {
71    *leap_year_drift_offset = calendar_wrapper_hdl->leap_year_drift_offset.getInheritedValue();
72  }
73 
74  bool cxios_is_defined_calendar_wrapper_leap_year_drift_offset(calendar_wrapper_Ptr calendar_wrapper_hdl )
75  {
76     CTimer::get("XIOS").resume();
77    return calendar_wrapper_hdl->leap_year_drift_offset.hasInheritedValue();
78     CTimer::get("XIOS").suspend();
79  }
80 
81 
82 
83  void cxios_set_calendar_wrapper_leap_year_month(calendar_wrapper_Ptr calendar_wrapper_hdl, int leap_year_month)
84  {
85     CTimer::get("XIOS").resume();
86    calendar_wrapper_hdl->leap_year_month.setValue(leap_year_month);
87     CTimer::get("XIOS").suspend();
88  }
89 
90  void cxios_get_calendar_wrapper_leap_year_month(calendar_wrapper_Ptr calendar_wrapper_hdl, int* leap_year_month)
91  {
92    *leap_year_month = calendar_wrapper_hdl->leap_year_month.getInheritedValue();
93  }
94 
95  bool cxios_is_defined_calendar_wrapper_leap_year_month(calendar_wrapper_Ptr calendar_wrapper_hdl )
96  {
97     CTimer::get("XIOS").resume();
98    return calendar_wrapper_hdl->leap_year_month.hasInheritedValue();
99     CTimer::get("XIOS").suspend();
100  }
101 
102 
103 
104  void cxios_set_calendar_wrapper_month_lengths(calendar_wrapper_Ptr calendar_wrapper_hdl, int* month_lengths, int extent1)
105  {
106    CTimer::get("XIOS").resume();
107    CArray<int,1> tmp(month_lengths,shape(extent1),neverDeleteData) ;
108    calendar_wrapper_hdl->month_lengths.reference(tmp.copy());
109     CTimer::get("XIOS").suspend();
110  }
111 
112  void cxios_get_calendar_wrapper_month_lengths(calendar_wrapper_Ptr calendar_wrapper_hdl, int* month_lengths, int extent1)
113  {
114    CTimer::get("XIOS").resume();
115    CArray<int,1> tmp(month_lengths,shape(extent1),neverDeleteData) ;
116    tmp=calendar_wrapper_hdl->month_lengths.getInheritedValue() ;
117     CTimer::get("XIOS").suspend();
118  }
119 
120  bool cxios_is_defined_calendar_wrapper_month_lengths(calendar_wrapper_Ptr calendar_wrapper_hdl )
121  {
122     CTimer::get("XIOS").resume();
123    return calendar_wrapper_hdl->month_lengths.hasInheritedValue();
124     CTimer::get("XIOS").suspend();
125  }
126 
127 
128 
129  void cxios_set_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * start_date, int start_date_size)
130  {
131    std::string start_date_str;
132    if(!cstr2string(start_date, start_date_size, start_date_str)) return;
133     CTimer::get("XIOS").resume();
134    calendar_wrapper_hdl->start_date.setValue(start_date_str);
135     CTimer::get("XIOS").suspend();
136  }
137 
138  void cxios_get_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, char * start_date, int start_date_size)
139  {
140     CTimer::get("XIOS").resume();
141    if(!string_copy(calendar_wrapper_hdl->start_date.getInheritedValue(),start_date , start_date_size))
142      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");
143     CTimer::get("XIOS").suspend();
144  }
145 
146  bool cxios_is_defined_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl )
147  {
148     CTimer::get("XIOS").resume();
149    return calendar_wrapper_hdl->start_date.hasInheritedValue();
150     CTimer::get("XIOS").suspend();
151  }
152 
153 
154 
155  void cxios_set_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * time_origin, int time_origin_size)
156  {
157    std::string time_origin_str;
158    if(!cstr2string(time_origin, time_origin_size, time_origin_str)) return;
159     CTimer::get("XIOS").resume();
160    calendar_wrapper_hdl->time_origin.setValue(time_origin_str);
161     CTimer::get("XIOS").suspend();
162  }
163 
164  void cxios_get_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl, char * time_origin, int time_origin_size)
165  {
166     CTimer::get("XIOS").resume();
167    if(!string_copy(calendar_wrapper_hdl->time_origin.getInheritedValue(),time_origin , time_origin_size))
168      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");
169     CTimer::get("XIOS").suspend();
170  }
171 
172  bool cxios_is_defined_calendar_wrapper_time_origin(calendar_wrapper_Ptr calendar_wrapper_hdl )
173  {
174     CTimer::get("XIOS").resume();
175    return calendar_wrapper_hdl->time_origin.hasInheritedValue();
176     CTimer::get("XIOS").suspend();
177  }
178 
179 
180 
181  void cxios_set_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl, cxios_duration timestep_c)
182  {
183    CTimer::get("XIOS").resume();
184    calendar_wrapper_hdl->timestep.allocate();
185    CDuration& timestep = calendar_wrapper_hdl->timestep.get();
186    timestep.year = timestep_c.year;
187    timestep.month = timestep_c.month;
188    timestep.day = timestep_c.day;
189    timestep.hour = timestep_c.hour;
190    timestep.minute = timestep_c.minute;
191    timestep.second = timestep_c.second;
192    timestep.timestep = timestep_c.timestep;
193    CTimer::get("XIOS").suspend();
194  }
195 
196  void cxios_get_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl, cxios_duration* timestep_c)
197  {
198    CTimer::get("XIOS").resume();
199    CDuration timestep = calendar_wrapper_hdl->timestep.getInheritedValue();
200    timestep_c->year = timestep.year;
201    timestep_c->month = timestep.month;
202    timestep_c->day = timestep.day;
203    timestep_c->hour = timestep.hour;
204    timestep_c->minute = timestep.minute;
205    timestep_c->second = timestep.second;
206    timestep_c->timestep = timestep.timestep;
207    CTimer::get("XIOS").suspend();
208  }
209 
210  bool cxios_is_defined_calendar_wrapper_timestep(calendar_wrapper_Ptr calendar_wrapper_hdl )
211  {
212     CTimer::get("XIOS").resume();
213    return calendar_wrapper_hdl->timestep.hasInheritedValue();
214     CTimer::get("XIOS").suspend();
215  }
216 
217 
218 
219  void cxios_set_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * type, int type_size)
220  {
221    std::string type_str;
222    if(!cstr2string(type, type_size, type_str)) return;
223     CTimer::get("XIOS").resume();
224    calendar_wrapper_hdl->type.fromString(type_str);
225     CTimer::get("XIOS").suspend();
226  }
227 
228  void cxios_get_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, char * type, int type_size)
229  {
230     CTimer::get("XIOS").resume();
231    if(!string_copy(calendar_wrapper_hdl->type.getInheritedStringValue(),type , type_size))
232      ERROR("void cxios_get_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl, char * type, int type_size)", <<"Input string is to short");
233     CTimer::get("XIOS").suspend();
234  }
235 
236  bool cxios_is_defined_calendar_wrapper_type(calendar_wrapper_Ptr calendar_wrapper_hdl )
237  {
238     CTimer::get("XIOS").resume();
239    return calendar_wrapper_hdl->type.hasInheritedValue();
240     CTimer::get("XIOS").suspend();
241  }
242 
243 
244 
245  void cxios_set_calendar_wrapper_year_length(calendar_wrapper_Ptr calendar_wrapper_hdl, int year_length)
246  {
247     CTimer::get("XIOS").resume();
248    calendar_wrapper_hdl->year_length.setValue(year_length);
249     CTimer::get("XIOS").suspend();
250  }
251 
252  void cxios_get_calendar_wrapper_year_length(calendar_wrapper_Ptr calendar_wrapper_hdl, int* year_length)
253  {
254    *year_length = calendar_wrapper_hdl->year_length.getInheritedValue();
255  }
256 
257  bool cxios_is_defined_calendar_wrapper_year_length(calendar_wrapper_Ptr calendar_wrapper_hdl )
258  {
259     CTimer::get("XIOS").resume();
260    return calendar_wrapper_hdl->year_length.hasInheritedValue();
261     CTimer::get("XIOS").suspend();
262  }
263 
264 
265 
266 
267}
Note: See TracBrowser for help on using the repository browser.