From 8ed26e337134af4d4183e8208514c08d0a16bbd0 Mon Sep 17 00:00:00 2001
From: Florian Prill <florian.prill@dwd.de>
Date: Mon, 24 Jun 2019 12:35:00 +0000
Subject: [PATCH] [develop]  fixed interface.

---
 include/mtime_eventHandling.h |  7 ----
 src/libmtime_hl.f90           |  1 +
 src/mtime_t_datetime.inc      | 60 +++++++++++++++++++++++------------
 src/mtime_t_timedelta.inc     |  4 +--
 4 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/include/mtime_eventHandling.h b/include/mtime_eventHandling.h
index 393922df..ccd99f09 100644
--- a/include/mtime_eventHandling.h
+++ b/include/mtime_eventHandling.h
@@ -161,13 +161,6 @@ getTriggerNextEventAtDateTimeRaw(struct _datetime* eventLastDateTime,
 				 struct _datetime* current_dt,
 				 struct _datetime* dt_return);
 
-struct _datetime*
-getTriggerNextEventAtDateTime(struct _datetime* eventLastDateTime,
-			      bool nextEventIsFirst,
-			      struct _datetime* triggerNextEventDateTime,
-			      struct _timedelta* eventInterval, 
-			      struct _datetime* current_dt);
-
 struct _datetime*
 getTriggerNextEventAtDateTime(struct _event* e, struct _datetime* dt_current, struct _datetime* dt_return);
 
diff --git a/src/libmtime_hl.f90 b/src/libmtime_hl.f90
index 4eb857c2..a0ead829 100644
--- a/src/libmtime_hl.f90
+++ b/src/libmtime_hl.f90
@@ -59,6 +59,7 @@ MODULE mtime_hl
   ! TODO: simply repeat the implementation of "divisionquotienttimespan" in order to disentangle the mtime_hl and the mtime Fortran modules.
   !
   PUBLIC :: divisionquotienttimespan
+  PUBLIC :: MAX_DATETIME_STR_LEN, MAX_TIMEDELTA_STR_LEN
   PUBLIC :: no_of_sec_in_a_day
 
 
diff --git a/src/mtime_t_datetime.inc b/src/mtime_t_datetime.inc
index 49e1e8d6..60b20a31 100644
--- a/src/mtime_t_datetime.inc
+++ b/src/mtime_t_datetime.inc
@@ -52,7 +52,7 @@
     integer :: i
 
     string = ""
-    
+
     c_pointer = this%get_c_pointer()
     CALL handle_errno(.not. c_associated(c_pointer), 0 * 100 + 2, __FILE__, __LINE__)
     dummy_ptr = my_datetimetostring(c_pointer, string)
@@ -83,7 +83,7 @@
       if (string(i:i) == c_null_char) exit char_loop
     end do char_loop
     string(i:len(string)) = ' '
-    
+
     CALL my_deallocatedatetime(c_pointer)
   END FUNCTION t_datetime_to_posix_string
 
@@ -114,7 +114,7 @@
     call c_f_pointer(c_pointer1, dt_tmp)
     dt_td_sum%dt = dt_tmp
     CALL my_deallocatedatetime(c_pointer1)
-    CALL my_deallocatedatetime(c_pointer2)    
+    CALL my_deallocatedatetime(c_pointer2)
   END FUNCTION t_datetime_add_timedelta
 
   ! Subtraction of time interval to datetime object.
@@ -133,7 +133,7 @@
     ELSE
       td_tmp%td%sign = "+"
     ENDIF
-    
+
     c_pointer1 = this%get_c_pointer()
     c_pointer2 = td_tmp%get_c_pointer()
 
@@ -142,7 +142,7 @@
     call c_f_pointer(c_pointer1, dt_tmp)
     dt_td_sum%dt = dt_tmp
     CALL my_deallocatedatetime(c_pointer1)
-    CALL my_deallocatedatetime(c_pointer2)    
+    CALL my_deallocatedatetime(c_pointer2)
   END FUNCTION t_datetime_sub_timedelta
 
   ! Subtraction of two dates.
@@ -158,7 +158,7 @@
 
   ! Overloaded operator: test for equivalence.
   !
-  LOGICAL FUNCTION t_datetime_equal(this, dt) result(eq)
+  LOGICAL FUNCTION t_datetime_equal(this, dt)  result(eq)
     CLASS (t_datetime),  INTENT(in), target :: this
     CLASS (t_datetime),  INTENT(in), target :: dt
     integer(c_int) :: ret
@@ -167,13 +167,19 @@
       eq = .true.
     else
       eq = .false.
-    endif    
+    endif
   END FUNCTION t_datetime_equal
 
-  LOGICAL FUNCTION t_datetime_not_equal(this, dt)
-    CLASS (t_datetime),  INTENT(in) :: this
-    CLASS (t_datetime),  INTENT(in) :: dt
-    t_datetime_not_equal = .not. (this%dt == dt%dt)
+  LOGICAL FUNCTION t_datetime_not_equal(this, dt)  result(ne)
+    CLASS (t_datetime),  INTENT(in), target :: this
+    CLASS (t_datetime),  INTENT(in), target :: dt
+    integer(c_int) :: ret
+    ret = my_comparedatetime(c_loc(this%dt), c_loc(dt%dt))
+    if (ret /= 0) then
+      ne = .true.
+    else
+      ne = .false.
+    endif
   END FUNCTION t_datetime_not_equal
 
   LOGICAL FUNCTION t_datetime_less_than(this, dt)  result(lt)
@@ -185,7 +191,7 @@
       lt = .true.
     else
       lt = .false.
-    endif    
+    endif
   END FUNCTION t_datetime_less_than
 
   LOGICAL FUNCTION t_datetime_greater_than(this, dt)  result(gt)
@@ -197,19 +203,31 @@
       gt = .true.
     else
       gt = .false.
-    endif    
+    endif
   END FUNCTION t_datetime_greater_than
 
-  LOGICAL FUNCTION t_datetime_less_or_equal(this, dt)
-    CLASS (t_datetime),  INTENT(in) :: this
-    CLASS (t_datetime),  INTENT(in) :: dt
-    t_datetime_less_or_equal = .not. (this > dt)
+  LOGICAL FUNCTION t_datetime_less_or_equal(this, dt) result(le)
+    CLASS (t_datetime),  INTENT(in), target :: this
+    CLASS (t_datetime),  INTENT(in), target :: dt
+    integer(c_int) :: ret
+    ret = my_comparedatetime(c_loc(this%dt), c_loc(dt%dt))
+    if ((ret == 0) .or. (ret == -1)) then
+      le = .true.
+    else
+      le = .false.
+    endif
   END FUNCTION t_datetime_less_or_equal
 
-  LOGICAL FUNCTION t_datetime_greater_or_equal(this, dt)
-    CLASS (t_datetime),  INTENT(in) :: this
-    CLASS (t_datetime),  INTENT(in) :: dt
-    t_datetime_greater_or_equal = .not. (this < dt)
+  LOGICAL FUNCTION t_datetime_greater_or_equal(this, dt) result(ge)
+    CLASS (t_datetime),  INTENT(in), target :: this
+    CLASS (t_datetime),  INTENT(in), target :: dt
+    integer(c_int) :: ret
+    ret = my_comparedatetime(c_loc(this%dt), c_loc(dt%dt))
+    if ((ret == 0) .or. (ret == 1)) then
+      ge = .true.
+    else
+      ge = .false.
+    endif
   END FUNCTION t_datetime_greater_or_equal
 
   FUNCTION t_datetime_daysInEntireMonth(this)
diff --git a/src/mtime_t_timedelta.inc b/src/mtime_t_timedelta.inc
index f1f1ec4c..9a0e7e85 100644
--- a/src/mtime_t_timedelta.inc
+++ b/src/mtime_t_timedelta.inc
@@ -305,7 +305,7 @@
     TYPE(t_datetime) :: a,b
     TYPE(t_datetime) :: res
 
-    IF (a > b) THEN
+    IF (a%dt > b%dt) THEN
       res = b
     ELSE
       res = a
@@ -316,7 +316,7 @@
     TYPE(t_datetime) :: a,b
     TYPE(t_datetime) :: res
 
-    IF (a > b) THEN
+    IF (a%dt > b%dt) THEN
       res = a
     ELSE
       res = b
-- 
GitLab