Changeset 794 for XIOS/trunk


Ignore:
Timestamp:
11/19/15 16:55:17 (8 years ago)
Author:
rlacroix
Message:

Fortran interface: Add functions to convert date and duration to string.

Location:
XIOS/trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/interface/c/icdate.cpp

    r591 r794  
    4141                                   date_c.hour, date_c.minute, date_c.second); 
    4242    return date; 
     43  } 
     44 
     45  void cxios_date_convert_to_string(cxios_date date_c, char* str, int str_size) 
     46  { 
     47    xios::CDate date = xios::CDate(getCalendar("void cxios_date_convert_to_string(cxios_date date_c, char* str, int str_size)"), 
     48                                   date_c.year, date_c.month, date_c.day, 
     49                                   date_c.hour, date_c.minute, date_c.second); 
     50 
     51    if (!string_copy(date.toString(), str, str_size)) 
     52      ERROR("void cxios_date_convert_to_string(cxios_date date_c, char* str, int str_size)", << "Input string is too short"); 
    4353  } 
    4454 
  • XIOS/trunk/src/interface/c/icduration.cpp

    r545 r794  
     1#include "icutil.hpp" 
    12#include "icdate.hpp" 
    23#include "calendar_util.hpp" 
     
    45extern "C" 
    56{ 
     7  void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size) 
     8  { 
     9    xios::CDuration dur = { dur_c.year, dur_c.month, dur_c.day, 
     10                            dur_c.hour, dur_c.minute, dur_c.second, 
     11                            dur_c.timestep }; 
     12 
     13    if (!string_copy(dur.toString(), str, str_size)) 
     14      ERROR("void cxios_duration_convert_to_string(cxios_duration dur_c, char* str, int str_size)", << "Input string is too short"); 
     15  } 
     16 
    617  cxios_duration cxios_duration_add(cxios_duration dur1_c, cxios_duration dur2_c) 
    718  { 
  • XIOS/trunk/src/interface/fortran/date_interface.F90

    r576 r794  
    1818         TYPE(txios(date)), VALUE :: date 
    1919      END FUNCTION cxios_date_convert_to_seconds 
     20 
     21      SUBROUTINE cxios_date_convert_to_string(date, str, str_size) BIND(C) 
     22         USE ISO_C_BINDING 
     23         IMPORT :: txios(date) 
     24         TYPE(txios(date)), VALUE :: date 
     25         CHARACTER(kind = C_CHAR), DIMENSION(*) :: str 
     26         INTEGER(kind = C_INT), VALUE :: str_size 
     27      END SUBROUTINE cxios_date_convert_to_string 
    2028 
    2129      TYPE(txios(date)) FUNCTION cxios_date_add_duration(date, dur) BIND(C) 
  • XIOS/trunk/src/interface/fortran/duration_interface.F90

    r545 r794  
    99      
    1010   INTERFACE ! Ne pas appeler directement/Interface FORTRAN 2003 <-> C99 
     11 
     12      SUBROUTINE cxios_duration_convert_to_string(dur, str, str_size) BIND(C) 
     13         USE ISO_C_BINDING 
     14         IMPORT :: txios(duration) 
     15         TYPE(txios(duration)), VALUE :: dur 
     16         CHARACTER(kind = C_CHAR), DIMENSION(*) :: str 
     17         INTEGER(kind = C_INT), VALUE :: str_size 
     18      END SUBROUTINE cxios_duration_convert_to_string 
    1119 
    1220      TYPE(txios(duration)) FUNCTION cxios_duration_add(dur1, dur2) BIND(C) 
  • XIOS/trunk/src/interface/fortran/idate.F90

    r558 r794  
    4343   CONTAINS ! Fonctions disponibles pour les utilisateurs. 
    4444 
     45   ! Conversion functions 
     46 
    4547   FUNCTION xios(date_convert_to_seconds)(date) RESULT(res) 
    4648      USE DATE_INTERFACE, only : txios(date) 
     
    5254   END FUNCTION xios(date_convert_to_seconds) 
    5355 
     56   SUBROUTINE xios(date_convert_to_string)(date, str) 
     57      USE DATE_INTERFACE, only : txios(date) 
     58      IMPLICIT NONE 
     59      TYPE(txios(date)), INTENT(IN) :: date 
     60      CHARACTER(len = *), INTENT(OUT) :: str 
     61 
     62      CALL cxios_date_convert_to_string(date, str, len(str)) 
     63   END SUBROUTINE xios(date_convert_to_string) 
     64 
    5465   ! Addition: date + duration = date 
    5566 
  • XIOS/trunk/src/interface/fortran/iduration.F90

    r545 r794  
    4949 
    5050   CONTAINS 
     51 
     52   ! Conversion function 
     53 
     54   SUBROUTINE xios(duration_convert_to_string)(dur, str) 
     55      USE DURATION_INTERFACE, only : txios(duration) 
     56      IMPLICIT NONE 
     57      TYPE(txios(duration)), INTENT(IN) :: dur 
     58      CHARACTER(len = *), INTENT(OUT) :: str 
     59 
     60      CALL cxios_duration_convert_to_string(dur, str, len(str)) 
     61   END SUBROUTINE xios(duration_convert_to_string) 
    5162 
    5263   ! Addition 
  • XIOS/trunk/src/interface/fortran/ixios.F90

    r788 r794  
    2323USE iduration, ONLY: txios(duration),                                                                            & 
    2424                     xios(year), xios(month), xios(day), xios(hour), xios(minute), xios(second), xios(timestep), & 
     25                     xios(duration_convert_to_string),                                                           & 
    2526                     xios(duration_add), xios(duration_sub), xios(duration_mult), xios(duration_neg),            & 
    2627                     xios(duration_eq), xios(duration_neq),                                                      & 
     
    2829 
    2930USE idate, ONLY : txios(date),                                                                                & 
    30                   xios(date_convert_to_seconds),                                                              & 
     31                  xios(date_convert_to_seconds), xios(date_convert_to_string),                                & 
    3132                  xios(date_add_duration), xios(date_sub_duration), xios(date_sub),                           & 
    3233                  xios(date_eq), xios(date_neq), xios(date_lt), xios(date_le), xios(date_gt), xios(date_ge),  & 
  • XIOS/trunk/src/test/test_client.f90

    r723 r794  
    1212  INTEGER :: comm 
    1313  TYPE(xios_duration) :: dtime 
     14  CHARACTER(len=20) :: dtime_str 
    1415  TYPE(xios_date) :: date 
     16  CHARACTER(len=20) :: date_str 
    1517  CHARACTER(len=15) :: calendar_type 
    1618  TYPE(xios_context) :: ctx_hdl 
     
    98100  PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year) 
    99101  PRINT *, "--> day length = ", xios_get_day_length_in_seconds() 
    100   PRINT *, "time_origin = ", date 
     102  CALL xios_date_convert_to_string(date, date_str) 
     103  PRINT *, "time_origin = ", date_str 
    101104  PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date) 
    102105  PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date) 
     
    106109  dtime%timestep = 1 
    107110  dtime = 0.5 * dtime 
    108   PRINT *, "duration = ", dtime 
     111  CALL xios_duration_convert_to_string(dtime, dtime_str) 
     112  PRINT *, "duration = ", dtime_str 
    109113  date = date + 3 * (dtime + dtime) 
    110   PRINT *, "date = time_origin + 3 * (duration + duration) = ", date 
     114  CALL xios_date_convert_to_string(date, date_str) 
     115  PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str 
    111116  PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date) 
    112117  PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour) 
Note: See TracChangeset for help on using the changeset viewer.