Ignore:
Timestamp:
02/10/15 14:23:02 (9 years ago)
Author:
rlacroix
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/interface/c_attr/iccalendar_wrapper_attr.cpp

    r549 r550  
    1818  typedef xios::CCalendarWrapper*  calendar_wrapper_Ptr; 
    1919   
     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   
    20129  void cxios_set_calendar_wrapper_start_date(calendar_wrapper_Ptr calendar_wrapper_hdl, const char * start_date, int start_date_size) 
    21130  { 
     
    134243   
    135244   
     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   
    136266   
    137267} 
Note: See TracChangeset for help on using the changeset viewer.