Ignore:
Timestamp:
01/26/15 14:39:26 (9 years ago)
Author:
rlacroix
Message:

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

Legend:

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

    r537 r549  
    1717{ 
    1818  typedef xios::CContext*  context_Ptr; 
    19    
    20   void cxios_set_context_calendar_type(context_Ptr context_hdl, const char * calendar_type, int calendar_type_size) 
    21   { 
    22     std::string calendar_type_str; 
    23     if(!cstr2string(calendar_type, calendar_type_size, calendar_type_str)) return; 
    24      CTimer::get("XIOS").resume(); 
    25     context_hdl->calendar_type.fromString(calendar_type_str); 
    26      CTimer::get("XIOS").suspend(); 
    27   } 
    28    
    29   void cxios_get_context_calendar_type(context_Ptr context_hdl, char * calendar_type, int calendar_type_size) 
    30   { 
    31      CTimer::get("XIOS").resume(); 
    32     if(!string_copy(context_hdl->calendar_type.getInheritedStringValue(),calendar_type , calendar_type_size)) 
    33       ERROR("void cxios_get_context_calendar_type(context_Ptr context_hdl, char * calendar_type, int calendar_type_size)", <<"Input string is to short"); 
    34      CTimer::get("XIOS").suspend(); 
    35   } 
    36    
    37   bool cxios_is_defined_context_calendar_type(context_Ptr context_hdl ) 
    38   { 
    39      CTimer::get("XIOS").resume(); 
    40     return context_hdl->calendar_type.hasInheritedValue(); 
    41      CTimer::get("XIOS").suspend(); 
    42   } 
    43    
    44    
    4519   
    4620  void cxios_set_context_output_dir(context_Ptr context_hdl, const char * output_dir, int output_dir_size) 
     
    7044   
    7145   
    72   void cxios_set_context_start_date(context_Ptr context_hdl, cxios_date start_date_c) 
    73   { 
    74     CTimer::get("XIOS").resume(); 
    75     context_hdl->start_date.allocate(); 
    76     CDate& start_date = context_hdl->start_date.get(); 
    77     start_date.setDate(start_date_c.year, 
    78                            start_date_c.month, 
    79                            start_date_c.day, 
    80                            start_date_c.hour, 
    81                            start_date_c.minute, 
    82                            start_date_c.second); 
    83     if (start_date.hasRelCalendar()) 
    84       start_date.checkDate(); 
    85     CTimer::get("XIOS").suspend(); 
    86   } 
    87    
    88   void cxios_get_context_start_date(context_Ptr context_hdl, cxios_date* start_date_c) 
    89   { 
    90     CTimer::get("XIOS").resume(); 
    91     CDate start_date = context_hdl->start_date.getInheritedValue(); 
    92     start_date_c->year = start_date.getYear(); 
    93     start_date_c->month = start_date.getMonth(); 
    94     start_date_c->day = start_date.getDay(); 
    95     start_date_c->hour = start_date.getHour(); 
    96     start_date_c->minute = start_date.getMinute(); 
    97     start_date_c->second = start_date.getSecond(); 
    98     CTimer::get("XIOS").suspend(); 
    99   } 
    100    
    101   bool cxios_is_defined_context_start_date(context_Ptr context_hdl ) 
    102   { 
    103      CTimer::get("XIOS").resume(); 
    104     return context_hdl->start_date.hasInheritedValue(); 
    105      CTimer::get("XIOS").suspend(); 
    106   } 
    107    
    108    
    109    
    110   void cxios_set_context_time_origin(context_Ptr context_hdl, cxios_date time_origin_c) 
    111   { 
    112     CTimer::get("XIOS").resume(); 
    113     context_hdl->time_origin.allocate(); 
    114     CDate& time_origin = context_hdl->time_origin.get(); 
    115     time_origin.setDate(time_origin_c.year, 
    116                            time_origin_c.month, 
    117                            time_origin_c.day, 
    118                            time_origin_c.hour, 
    119                            time_origin_c.minute, 
    120                            time_origin_c.second); 
    121     if (time_origin.hasRelCalendar()) 
    122       time_origin.checkDate(); 
    123     CTimer::get("XIOS").suspend(); 
    124   } 
    125    
    126   void cxios_get_context_time_origin(context_Ptr context_hdl, cxios_date* time_origin_c) 
    127   { 
    128     CTimer::get("XIOS").resume(); 
    129     CDate time_origin = context_hdl->time_origin.getInheritedValue(); 
    130     time_origin_c->year = time_origin.getYear(); 
    131     time_origin_c->month = time_origin.getMonth(); 
    132     time_origin_c->day = time_origin.getDay(); 
    133     time_origin_c->hour = time_origin.getHour(); 
    134     time_origin_c->minute = time_origin.getMinute(); 
    135     time_origin_c->second = time_origin.getSecond(); 
    136     CTimer::get("XIOS").suspend(); 
    137   } 
    138    
    139   bool cxios_is_defined_context_time_origin(context_Ptr context_hdl ) 
    140   { 
    141      CTimer::get("XIOS").resume(); 
    142     return context_hdl->time_origin.hasInheritedValue(); 
    143      CTimer::get("XIOS").suspend(); 
    144   } 
    145    
    146    
    147    
    148   void cxios_set_context_timestep(context_Ptr context_hdl, cxios_duration timestep_c) 
    149   { 
    150     CTimer::get("XIOS").resume(); 
    151     context_hdl->timestep.allocate(); 
    152     CDuration& timestep = context_hdl->timestep.get(); 
    153     timestep.year = timestep_c.year; 
    154     timestep.month = timestep_c.month; 
    155     timestep.day = timestep_c.day; 
    156     timestep.hour = timestep_c.hour; 
    157     timestep.minute = timestep_c.minute; 
    158     timestep.second = timestep_c.second; 
    159     timestep.timestep = timestep_c.timestep; 
    160     CTimer::get("XIOS").suspend(); 
    161   } 
    162    
    163   void cxios_get_context_timestep(context_Ptr context_hdl, cxios_duration* timestep_c) 
    164   { 
    165     CTimer::get("XIOS").resume(); 
    166     CDuration timestep = context_hdl->timestep.getInheritedValue(); 
    167     timestep_c->year = timestep.year; 
    168     timestep_c->month = timestep.month; 
    169     timestep_c->day = timestep.day; 
    170     timestep_c->hour = timestep.hour; 
    171     timestep_c->minute = timestep.minute; 
    172     timestep_c->second = timestep.second; 
    173     timestep_c->timestep = timestep.timestep; 
    174     CTimer::get("XIOS").suspend(); 
    175   } 
    176    
    177   bool cxios_is_defined_context_timestep(context_Ptr context_hdl ) 
    178   { 
    179      CTimer::get("XIOS").resume(); 
    180     return context_hdl->timestep.hasInheritedValue(); 
    181      CTimer::get("XIOS").suspend(); 
    182   } 
    183    
    184    
    185    
    18646   
    18747} 
Note: See TracChangeset for help on using the changeset viewer.