source: XIOS/trunk/src/interface/fortran/icalendar.F90 @ 545

Last change on this file since 545 was 545, checked in by rlacroix, 9 years ago

Expose the calendar operations through the Fortran interface.

  • Add arithmetic operations on the xios_duration and xios_date types:
    • xios_duration + xios_duration = xios_duration
    • xios_duration - xios_duration = xios_duration
    • scalar * xios_duration = xios_duration * scalar = xios_duration
    • - xios_duration = xios_duration
    • xios_date + xios_duration = xios_date
    • xios_date - xios_duration = xios_date
    • xios_date - xios_date = xios_duration
  • Add comparison operations on the xios_duration and xios_date types:
    • xios_duration: ==, /=
    • xios_date: ==, /=, <, <=, >, >=
  • Add a new function "xios_date_convert_to_seconds" to convert a date into the number of seconds since the time origin of the calendar
  • Define some constant durations "xios_second", "xios_minute", "xios_hour", "xios_day", "xios_month", "xios_year" et "xios_timestep" to ease the definition of new durations (for example, 10h is just 10 * xios_hour)
  • Add a new function "xios_set_calendar" so that one can manually create the calendar attached to the current context and thus use the calendar operations before calling "xios_close_context_definition". This function can accept optional parameters so that the calendar attributes (calendar_type, start_date, time_origin and timestep) can be easily overwritten. Note that you cannot define a new calendar after one was already created (either because "xios_set_calendar" or "xios_close_context_definition" was used)
  • Readd the function "xios_set_timestep" as a simplified alias of "xios_set_context_attr(context, timestep)" for the current context
File size: 2.3 KB
Line 
1#include "xios_fortran_prefix.hpp"
2MODULE ICALENDAR
3   USE, INTRINSIC :: ISO_C_BINDING
4   USE CALENDAR_INTERFACE
5   USE IDATE
6   USE IDURATION
7
8   ! enum XCalendarType
9   INTEGER(kind = C_INT), PARAMETER :: D360 = 0 , ALLLEAP = 1 , NOLEAP = 2 , JULIAN = 3 , GREGORIAN = 4
10
11   CONTAINS ! Fonctions disponibles pour les utilisateurs.
12
13   SUBROUTINE xios(set_calendar)(calendar_type, start_date, time_origin, timestep)
14      USE ICONTEXT, ONLY : txios(context), xios(get_current_context)
15      USE icontext_attr, ONLY : xios(set_context_attr_hdl)
16      USE IDATE, ONLY : txios(date)
17      USE IDURATION, ONLY : txios(duration)
18      IMPLICIT NONE
19      CHARACTER(len = *),    OPTIONAL, INTENT(IN) :: calendar_type
20      TYPE(txios(date)),     OPTIONAL, INTENT(IN) :: start_date
21      TYPE(txios(date)),     OPTIONAL, INTENT(IN) :: time_origin
22      TYPE(txios(duration)), OPTIONAL, INTENT(IN) :: timestep
23      TYPE(txios(context)) :: context
24
25      CALL xios(get_current_context)(context)
26
27      IF (PRESENT(calendar_type)) THEN
28         CALL xios(set_context_attr_hdl)(context, calendar_type=calendar_type)
29      END IF
30      IF (PRESENT(start_date)) THEN
31         CALL xios(set_context_attr_hdl)(context, start_date=start_date)
32      END IF
33      IF (PRESENT(time_origin)) THEN
34         CALL xios(set_context_attr_hdl)(context, time_origin=time_origin)
35      END IF
36      IF (PRESENT(time_origin)) THEN
37         CALL xios(set_context_attr_hdl)(context, timestep=timestep)
38      END IF
39
40      CALL cxios_create_calendar()
41   END SUBROUTINE xios(set_calendar)
42
43   SUBROUTINE xios(set_timestep)(timestep)
44      USE ICONTEXT, ONLY : txios(context), xios(get_current_context)
45      USE icontext_attr, ONLY : xios(set_context_attr_hdl)
46      USE IDURATION, ONLY : txios(duration)
47      IMPLICIT NONE
48      TYPE(txios(duration)), INTENT(IN) :: timestep
49      TYPE(txios(context)) :: context
50
51      CALL xios(get_current_context)(context)
52
53      CALL xios(set_context_attr_hdl)(context, timestep=timestep)
54   END SUBROUTINE xios(set_timestep)
55
56   SUBROUTINE xios(update_calendar)(step)
57      IMPLICIT NONE
58      INTEGER, INTENT(IN) :: step
59     
60      IF (step < 0) THEN
61         PRINT *, "L'argument 'step' ne peut être négatif"
62         STOP
63      END IF
64      CALL cxios_update_calendar(step)
65   END SUBROUTINE xios(update_calendar)
66
67END MODULE ICALENDAR
Note: See TracBrowser for help on using the repository browser.