source: XIOS/trunk/src/interface/fortran/icalendar_wrapper.F90 @ 549

Last change on this file since 549 was 549, checked in by rlacroix, 9 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: 3.0 KB
Line 
1#include "xios_fortran_prefix.hpp"
2
3MODULE ICALENDAR_WRAPPER
4   USE, INTRINSIC :: ISO_C_BINDING
5   USE CALENDAR_WRAPPER_INTERFACE
6   USE IDATE
7   USE IDURATION
8
9   TYPE txios(calendar_wrapper)
10      INTEGER(kind = C_INTPTR_T) :: daddr
11   END TYPE txios(calendar_wrapper)
12
13   CONTAINS ! Fonctions disponibles pour les utilisateurs.
14
15   SUBROUTINE xios(get_calendar_wrapper_handle)(idt, ret)
16      IMPLICIT NONE
17      CHARACTER(len = *),            INTENT(IN)  :: idt
18      TYPE(txios(calendar_wrapper)), INTENT(OUT) :: ret
19
20      CALL cxios_calendar_wrapper_handle_create(ret%daddr, idt, len(idt))
21   END SUBROUTINE xios(get_calendar_wrapper_handle)
22
23   SUBROUTINE xios(get_default_calendar_wrapper_handle)(ret)
24      IMPLICIT NONE
25      TYPE(txios(calendar_wrapper)), INTENT(OUT) :: ret
26
27      CALL cxios_get_current_calendar_wrapper(ret%daddr)
28   END SUBROUTINE xios(get_default_calendar_wrapper_handle)
29
30   LOGICAL FUNCTION xios(is_valid_calendar_wrapper)(idt)
31      IMPLICIT NONE
32      CHARACTER(len  = *), INTENT(IN) :: idt
33      LOGICAL  (kind = 1)             :: val
34
35      CALL cxios_calendar_wrapper_valid_id(val, idt, len(idt));
36      xios(is_valid_calendar_wrapper) = val
37   END FUNCTION  xios(is_valid_calendar_wrapper)
38
39   SUBROUTINE xios(create_calendar)(hdl)
40      IMPLICIT NONE
41      TYPE(txios(calendar_wrapper)), INTENT(IN) :: hdl
42
43      CALL cxios_create_calendar(hdl%daddr)
44   END SUBROUTINE xios(create_calendar)
45
46   SUBROUTINE xios(update_calendar_timestep)(hdl)
47      IMPLICIT NONE
48      TYPE(txios(calendar_wrapper)), INTENT(IN) :: hdl
49
50      CALL cxios_update_calendar_timestep(hdl%daddr)
51   END SUBROUTINE xios(update_calendar_timestep)
52
53   SUBROUTINE xios(set_start_date_hdl)(hdl, start_date)
54      USE IDATE
55      IMPLICIT NONE
56      TYPE(txios(calendar_wrapper)), INTENT(IN) :: hdl
57      TYPE(txios(date)),             INTENT(IN) :: start_date
58
59      CALL cxios_set_calendar_wrapper_date_start_date(hdl%daddr, start_date)
60   END SUBROUTINE xios(set_start_date_hdl)
61
62   SUBROUTINE xios(get_start_date_hdl)(hdl, start_date)
63      USE IDATE
64      IMPLICIT NONE
65      TYPE(txios(calendar_wrapper)), INTENT(IN)  :: hdl
66      TYPE(txios(date)),             INTENT(OUT) :: start_date
67
68      CALL cxios_get_calendar_wrapper_date_start_date(hdl%daddr, start_date)
69   END SUBROUTINE xios(get_start_date_hdl)
70
71   SUBROUTINE xios(set_time_origin_hdl)(hdl, time_origin)
72      USE IDATE
73      IMPLICIT NONE
74      TYPE(txios(calendar_wrapper)), INTENT(IN) :: hdl
75      TYPE(txios(date)),             INTENT(IN) :: time_origin
76
77      CALL cxios_set_calendar_wrapper_date_time_origin(hdl%daddr, time_origin)
78   END SUBROUTINE xios(set_time_origin_hdl)
79
80   SUBROUTINE xios(get_time_origin_hdl)(hdl, time_origin)
81      USE IDATE
82      IMPLICIT NONE
83      TYPE(txios(calendar_wrapper)), INTENT(IN)  :: hdl
84      TYPE(txios(date)),             INTENT(OUT) :: time_origin
85
86      CALL cxios_get_calendar_wrapper_date_time_origin(hdl%daddr, time_origin)
87   END SUBROUTINE xios(get_time_origin_hdl)
88
89END MODULE ICALENDAR_WRAPPER
Note: See TracBrowser for help on using the repository browser.