source: XIOS/trunk/src/interface/fortran/icalendar.F90 @ 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: 7.9 KB
Line 
1#include "xios_fortran_prefix.hpp"
2MODULE ICALENDAR
3   USE, INTRINSIC :: ISO_C_BINDING
4   USE CALENDAR_INTERFACE
5   USE ICALENDAR_WRAPPER
6   USE IDATE
7   USE IDURATION
8
9   ! enum XCalendarType
10   INTEGER(kind = C_INT), PARAMETER :: D360 = 0 , ALLLEAP = 1 , NOLEAP = 2 , JULIAN = 3 , GREGORIAN = 4
11
12   INTERFACE xios(set_start_date)
13      MODULE PROCEDURE xios(set_start_date_date), xios(set_start_date_dur)
14   END INTERFACE xios(set_start_date)
15
16   INTERFACE xios(set_time_origin)
17      MODULE PROCEDURE xios(set_time_origin_date), xios(set_time_origin_dur)
18   END INTERFACE xios(set_time_origin)
19
20   CONTAINS ! Fonctions disponibles pour les utilisateurs.
21
22   SUBROUTINE xios(define_calendar)(type, timestep, start_date, time_origin)
23      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
24      USE icalendar_wrapper_attr, ONLY : xios(set_calendar_wrapper_attr_hdl)
25      USE IDURATION, ONLY : txios(duration)
26      USE IDATE, ONLY : txios(date)
27      IMPLICIT NONE
28      CHARACTER(len = *),              INTENT(IN) :: type
29      TYPE(txios(duration)), OPTIONAL, INTENT(IN) :: timestep
30      TYPE(txios(date)),     OPTIONAL, INTENT(IN) :: start_date
31      TYPE(txios(date)),     OPTIONAL, INTENT(IN) :: time_origin
32      TYPE(txios(calendar_wrapper)) :: calendar_wrapper
33
34      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
35
36      CALL xios(set_calendar_wrapper_attr_hdl)(calendar_wrapper, type=type)
37      IF (PRESENT(timestep)) THEN
38         CALL xios(set_calendar_wrapper_attr_hdl)(calendar_wrapper, timestep=timestep)
39      END IF
40
41      CALL xios(create_calendar)(calendar_wrapper)
42
43      IF (PRESENT(start_date)) THEN
44         CALL xios(set_start_date_hdl)(calendar_wrapper, start_date=start_date)
45      END IF
46      IF (PRESENT(time_origin)) THEN
47         CALL xios(set_time_origin_hdl)(calendar_wrapper, time_origin=time_origin)
48      END IF
49   END SUBROUTINE xios(define_calendar)
50
51   SUBROUTINE xios(get_calendar_type)(calendar_type)
52      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
53      USE icalendar_wrapper_attr, ONLY : xios(get_calendar_wrapper_attr_hdl)
54      IMPLICIT NONE
55      CHARACTER(len = *), INTENT(OUT) :: calendar_type
56      TYPE(txios(calendar_wrapper))   :: calendar_wrapper
57
58      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
59
60      CALL xios(get_calendar_wrapper_attr_hdl)(calendar_wrapper, type=calendar_type)
61   END SUBROUTINE xios(get_calendar_type)
62
63   SUBROUTINE xios(set_timestep)(timestep)
64      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
65      USE icalendar_wrapper_attr, ONLY : xios(set_calendar_wrapper_attr_hdl)
66      USE IDURATION, ONLY : txios(duration)
67      IMPLICIT NONE
68      TYPE(txios(duration)), INTENT(IN) :: timestep
69      TYPE(txios(calendar_wrapper))     :: calendar_wrapper
70
71      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
72
73      CALL xios(set_calendar_wrapper_attr_hdl)(calendar_wrapper, timestep=timestep)
74
75      CALL xios(update_calendar_timestep)(calendar_wrapper)
76   END SUBROUTINE xios(set_timestep)
77
78   SUBROUTINE xios(get_timestep)(timestep)
79      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
80      USE icalendar_wrapper_attr, ONLY : xios(get_calendar_wrapper_attr_hdl)
81      USE IDURATION, ONLY : txios(duration)
82      IMPLICIT NONE
83      TYPE(txios(duration)), INTENT(OUT) :: timestep
84      TYPE(txios(calendar_wrapper))      :: calendar_wrapper
85
86      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
87
88      CALL xios(get_calendar_wrapper_attr_hdl)(calendar_wrapper, timestep=timestep)
89   END SUBROUTINE xios(get_timestep)
90
91   SUBROUTINE xios(set_start_date_date)(start_date)
92      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
93      USE IDATE, ONLY : txios(date)
94      IMPLICIT NONE
95      TYPE(txios(date)), INTENT(IN) :: start_date
96      TYPE(txios(calendar_wrapper)) :: calendar_wrapper
97
98      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
99
100      CALL xios(set_start_date_hdl)(calendar_wrapper, start_date)
101   END SUBROUTINE xios(set_start_date_date)
102
103   SUBROUTINE xios(set_start_date_dur)(start_date)
104      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
105      USE IDURATION, ONLY : txios(duration)
106      USE IDATE, ONLY : txios(date)
107      IMPLICIT NONE
108      TYPE(txios(duration)), INTENT(IN) :: start_date
109      TYPE(txios(calendar_wrapper))     :: calendar_wrapper
110      TYPE(txios(date))                 :: start_date_date
111
112      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
113
114      start_date_date = start_date
115      CALL xios(set_start_date_hdl)(calendar_wrapper, start_date_date)
116   END SUBROUTINE xios(set_start_date_dur)
117
118   SUBROUTINE xios(get_start_date)(start_date)
119      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
120      USE IDATE, ONLY : txios(date)
121      IMPLICIT NONE
122      TYPE(txios(date)), INTENT(OUT) :: start_date
123      TYPE(txios(calendar_wrapper))  :: calendar_wrapper
124
125      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
126
127      CALL xios(get_start_date_hdl)(calendar_wrapper, start_date)
128   END SUBROUTINE xios(get_start_date)
129
130   SUBROUTINE xios(set_time_origin_date)(time_origin)
131      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
132      USE IDATE, ONLY : txios(date)
133      IMPLICIT NONE
134      TYPE(txios(date)), INTENT(IN) :: time_origin
135      TYPE(txios(calendar_wrapper)) :: calendar_wrapper
136
137      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
138
139      CALL xios(set_time_origin_hdl)(calendar_wrapper, time_origin)
140   END SUBROUTINE xios(set_time_origin_date)
141
142   SUBROUTINE xios(set_time_origin_dur)(time_origin)
143      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
144      USE IDURATION, ONLY : txios(duration)
145      USE IDATE, ONLY : txios(date)
146      IMPLICIT NONE
147      TYPE(txios(duration)), INTENT(IN) :: time_origin
148      TYPE(txios(calendar_wrapper))     :: calendar_wrapper
149      TYPE(txios(date))                 :: time_origin_date
150
151      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
152
153      time_origin_date = time_origin
154      CALL xios(set_time_origin_hdl)(calendar_wrapper, time_origin_date)
155   END SUBROUTINE xios(set_time_origin_dur)
156
157   SUBROUTINE xios(get_time_origin)(time_origin)
158      USE ICALENDAR_WRAPPER, ONLY : txios(calendar_wrapper), xios(get_default_calendar_wrapper_handle)
159      USE IDATE, ONLY : txios(date)
160      IMPLICIT NONE
161      TYPE(txios(date)), INTENT(OUT) :: time_origin
162      TYPE(txios(calendar_wrapper))  :: calendar_wrapper
163
164      CALL xios(get_default_calendar_wrapper_handle)(calendar_wrapper)
165
166      CALL xios(get_time_origin_hdl)(calendar_wrapper, time_origin)
167   END SUBROUTINE xios(get_time_origin)
168
169   SUBROUTINE xios(update_calendar)(step)
170      IMPLICIT NONE
171      INTEGER, INTENT(IN) :: step
172
173      IF (step < 0) THEN
174         PRINT *, "L'argument 'step' ne peut être négatif"
175         STOP
176      END IF
177      CALL cxios_update_calendar(step)
178   END SUBROUTINE xios(update_calendar)
179
180   SUBROUTINE xios(get_current_date)(current_date)
181      USE IDATE, ONLY : txios(date)
182      IMPLICIT NONE
183      TYPE(txios(date)), INTENT(OUT) :: current_date
184
185      CALL cxios_get_current_date(current_date)
186   END SUBROUTINE xios(get_current_date)
187
188   FUNCTION xios(get_year_length_in_seconds)(year) RESULT(res)
189      IMPLICIT NONE
190      INTEGER(kind = C_INT), INTENT(IN) :: year
191      INTEGER(kind = C_INT) :: res
192
193      res = cxios_get_year_length_in_seconds(year)
194   END FUNCTION xios(get_year_length_in_seconds)
195
196   FUNCTION xios(get_day_length_in_seconds)() RESULT(res)
197      IMPLICIT NONE
198      INTEGER(kind = C_INT) :: res
199
200      res = cxios_get_day_length_in_seconds()
201   END FUNCTION xios(get_day_length_in_seconds)
202
203END MODULE ICALENDAR
Note: See TracBrowser for help on using the repository browser.