source: XIOS/trunk/src/interface/fortran/idate.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
  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 5.8 KB
Line 
1#include "xios_fortran_prefix.hpp"
2MODULE IDATE
3   USE, INTRINSIC :: ISO_C_BINDING
4   USE DATE_INTERFACE
5
6   INTERFACE OPERATOR(+)
7      MODULE PROCEDURE xios(date_add_duration)
8   END INTERFACE
9
10   INTERFACE OPERATOR(-)
11      MODULE PROCEDURE xios(date_sub_duration)
12      MODULE PROCEDURE xios(date_sub)
13   END INTERFACE
14
15   INTERFACE OPERATOR(==)
16      MODULE PROCEDURE xios(date_eq)
17   END INTERFACE
18
19   INTERFACE OPERATOR(/=)
20      MODULE PROCEDURE xios(date_neq)
21   END INTERFACE
22
23   INTERFACE OPERATOR(<)
24      MODULE PROCEDURE xios(date_lt)
25   END INTERFACE
26
27   INTERFACE OPERATOR(<=)
28      MODULE PROCEDURE xios(date_le)
29   END INTERFACE
30
31   INTERFACE OPERATOR(>)
32      MODULE PROCEDURE xios(date_gt)
33   END INTERFACE
34
35   INTERFACE OPERATOR(>=)
36      MODULE PROCEDURE xios(date_ge)
37   END INTERFACE
38
39   INTERFACE ASSIGNMENT(=)
40      MODULE PROCEDURE xios(date_assign_duration)
41   END INTERFACE
42
43   CONTAINS ! Fonctions disponibles pour les utilisateurs.
44
45   FUNCTION xios(date_convert_to_seconds)(date) RESULT(res)
46      USE DATE_INTERFACE, only : txios(date)
47      IMPLICIT NONE
48      TYPE(txios(date)), INTENT(IN) :: date
49      INTEGER(kind = C_LONG_LONG) :: res
50
51      res = cxios_date_convert_to_seconds(date)
52   END FUNCTION xios(date_convert_to_seconds)
53
54   ! Addition: date + duration = date
55
56   FUNCTION xios(date_add_duration)(date, dur) RESULT(res)
57      USE DATE_INTERFACE, only : txios(date)
58      USE IDURATION, only : txios(duration)
59      IMPLICIT NONE
60      TYPE(txios(date)), INTENT(IN) :: date
61      TYPE(txios(duration)), INTENT(IN) :: dur
62      TYPE(txios(date)) :: res
63
64      res = cxios_date_add_duration(date, dur)
65   END FUNCTION xios(date_add_duration)
66
67   ! Subtraction: date - duration = date
68
69   FUNCTION xios(date_sub_duration)(date, dur) RESULT(res)
70      USE DATE_INTERFACE, only : txios(date)
71      USE IDURATION, only : txios(duration)
72      IMPLICIT NONE
73      TYPE(txios(date)), INTENT(IN) :: date
74      TYPE(txios(duration)), INTENT(IN) :: dur
75      TYPE(txios(date)) :: res
76
77      res = cxios_date_sub_duration(date, dur)
78   END FUNCTION xios(date_sub_duration)
79
80   ! Subtraction: date - date = duration
81
82   FUNCTION xios(date_sub)(date1, date2) RESULT(res)
83      USE DATE_INTERFACE, only : txios(date)
84      USE IDURATION, only : txios(duration)
85      IMPLICIT NONE
86      TYPE(txios(date)), INTENT(IN) :: date1, date2
87      TYPE(txios(duration)) :: res
88
89      res = cxios_date_sub(date1, date2)
90   END FUNCTION xios(date_sub)
91
92   FUNCTION xios(date_eq)(date1, date2) RESULT(res)
93      USE DATE_INTERFACE, only : txios(date)
94      IMPLICIT NONE
95      TYPE(txios(date)), INTENT(IN) :: date1, date2
96      LOGICAL :: res
97
98      res = cxios_date_eq(date1, date2)
99   END FUNCTION xios(date_eq)
100
101   FUNCTION xios(date_neq)(date1, date2) RESULT(res)
102      USE DATE_INTERFACE, only : txios(date)
103      IMPLICIT NONE
104      TYPE(txios(date)), INTENT(IN) :: date1, date2
105      LOGICAL :: res
106
107      res = cxios_date_neq(date1, date2)
108   END FUNCTION xios(date_neq)
109
110   FUNCTION xios(date_lt)(date1, date2) RESULT(res)
111      USE DATE_INTERFACE, only : txios(date)
112      IMPLICIT NONE
113      TYPE(txios(date)), INTENT(IN) :: date1, date2
114      LOGICAL :: res
115
116      res = cxios_date_lt(date1, date2)
117   END FUNCTION xios(date_lt)
118
119   FUNCTION xios(date_le)(date1, date2) RESULT(res)
120      USE DATE_INTERFACE, only : txios(date)
121      IMPLICIT NONE
122      TYPE(txios(date)), INTENT(IN) :: date1, date2
123      LOGICAL :: res
124
125      res = cxios_date_le(date1, date2)
126   END FUNCTION xios(date_le)
127
128   FUNCTION xios(date_gt)(date1, date2) RESULT(res)
129      USE DATE_INTERFACE, only : txios(date)
130      IMPLICIT NONE
131      TYPE(txios(date)), INTENT(IN) :: date1, date2
132      LOGICAL :: res
133
134      res = cxios_date_gt(date1, date2)
135   END FUNCTION xios(date_gt)
136
137   FUNCTION xios(date_ge)(date1, date2) RESULT(res)
138      USE DATE_INTERFACE, only : txios(date)
139      IMPLICIT NONE
140      TYPE(txios(date)), INTENT(IN) :: date1, date2
141      LOGICAL :: res
142
143      res = cxios_date_ge(date1, date2)
144   END FUNCTION xios(date_ge)
145
146   SUBROUTINE xios(date_assign_duration)(date, dur)
147      USE DATE_INTERFACE, only : txios(date)
148      USE IDURATION, only : txios(duration)
149      IMPLICIT NONE
150      TYPE(txios(date)), INTENT(OUT) :: date
151      TYPE(txios(duration)), INTENT(IN) :: dur
152
153      date = txios(date)(0, 1, 1, 0, 0, 0) + dur
154   END SUBROUTINE xios(date_assign_duration)
155
156   FUNCTION xios(date_get_second_of_year)(date) RESULT(res)
157      USE DATE_INTERFACE, only : txios(date)
158      IMPLICIT NONE
159      TYPE(txios(date)), INTENT(OUT) :: date
160      INTEGER(kind = C_INT) :: res
161
162      res = cxios_date_get_second_of_year(date)
163   END FUNCTION xios(date_get_second_of_year)
164
165   FUNCTION xios(date_get_day_of_year)(date) RESULT(res)
166      USE DATE_INTERFACE, only : txios(date)
167      IMPLICIT NONE
168      TYPE(txios(date)), INTENT(OUT) :: date
169      REAL(kind = C_DOUBLE) :: res
170
171      res = cxios_date_get_day_of_year(date)
172   END FUNCTION xios(date_get_day_of_year)
173
174   FUNCTION xios(date_get_fraction_of_year)(date) RESULT(res)
175      USE DATE_INTERFACE, only : txios(date)
176      IMPLICIT NONE
177      TYPE(txios(date)), INTENT(OUT) :: date
178      REAL(kind = C_DOUBLE) :: res
179
180      res = cxios_date_get_fraction_of_year(date)
181   END FUNCTION xios(date_get_fraction_of_year)
182
183   FUNCTION xios(date_get_second_of_day)(date) RESULT(res)
184      USE DATE_INTERFACE, only : txios(date)
185      IMPLICIT NONE
186      TYPE(txios(date)), INTENT(OUT) :: date
187      INTEGER(kind = C_INT) :: res
188
189      res = cxios_date_get_second_of_day(date)
190   END FUNCTION xios(date_get_second_of_day)
191
192   FUNCTION xios(date_get_fraction_of_day)(date) RESULT(res)
193      USE DATE_INTERFACE, only : txios(date)
194      IMPLICIT NONE
195      TYPE(txios(date)), INTENT(OUT) :: date
196      REAL(kind = C_DOUBLE) :: res
197
198      res = cxios_date_get_fraction_of_day(date)
199   END FUNCTION xios(date_get_fraction_of_day)
200
201END MODULE IDATE
Note: See TracBrowser for help on using the repository browser.