From 1919444f916004a19c21cdd5fe0da47e6167cd89 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Thu, 16 Jan 2025 16:31:14 +0100
Subject: [PATCH] Rewrite simulate_iau so it does not need mtime_hl

---
 examples/CMakeLists.txt   |  2 +-
 examples/Makefile.am      |  4 ++--
 examples/simulate_iau.f90 | 35 +++++++++++++++++++----------------
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 84021b0a..d0269a41 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -13,6 +13,7 @@ set(examples_Fortran
     iconoce
     output_control
     repetitor
+    simulate_iau
     tas
     test_cf_timeaxis
     test_dace
@@ -27,7 +28,6 @@ if(MTIME_ENABLE_FORTRAN_HL)
     # cmake-format: sort
     example_hl
     iconoce_hl
-    simulate_iau
   )
 endif()
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
index e9ed814f..4bb90418 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -15,6 +15,7 @@ noinst_PROGRAMS =     \
     output_control    \
     recurrence        \
     repetitor         \
+    simulate_iau      \
     tas               \
     test_cf_timeaxis  \
     test_dace         \
@@ -24,8 +25,7 @@ noinst_PROGRAMS =     \
 if ENABLE_FORTRAN_HL
 noinst_PROGRAMS += \
     example_hl \
-    iconoce_hl \
-    simulate_iau
+    iconoce_hl
 endif ENABLE_FORTRAN_HL
 endif ENABLE_EXAMPLES
 
diff --git a/examples/simulate_iau.f90 b/examples/simulate_iau.f90
index 8e910f01..6f801d49 100644
--- a/examples/simulate_iau.f90
+++ b/examples/simulate_iau.f90
@@ -4,15 +4,12 @@
 !!
 PROGRAM simulate_iau
 
-#ifndef __NVCOMPILER
-
-  USE mtime, ONLY: setCalendar, proleptic_gregorian
-  USE mtime_hl
+  USE mtime
 
   IMPLICIT NONE
 
-  TYPE(t_datetime)  :: start_date, stop_date, current_date, previous_date
-  TYPE(t_timedelta) :: time_step, iau_time_shift
+  TYPE(datetime) :: start_date, stop_date, current_date, previous_date
+  TYPE(timedelta), POINTER :: time_step, iau_time_shift
 
   LOGICAL, PARAMETER :: iterate_iau = .TRUE.
   INTEGER :: iau_iter
@@ -21,19 +18,21 @@ PROGRAM simulate_iau
 
   INTEGER :: jstep, jstep0, jstep_shift
 
+  CHARACTER(len=max_datetime_str_len) :: dstring
+
   WRITE (0, *) "Start execution, set calendar ..."
 
   CALL setCalendar(proleptic_gregorian)
 
   WRITE (0, *) "Assign values ..."
 
-  start_date = t_datetime("2016-01-01T00:00:00")
-  stop_date = t_datetime("2016-01-02T00:00:00")
+  start_date = newDatetime("2016-01-01T00:00:00")
+  stop_date = newDatetime("2016-01-02T00:00:00")
 
-  time_step = t_timedelta("PT15M")
+  time_step => newTimedelta("PT15M")
   dtime = 900.0
 
-  iau_time_shift = t_timedelta("-PT1H30M")
+  iau_time_shift => newTimedelta("-PT1H30M")
   dt_shift = -5400.0
 
   WRITE (0, *) "Prepare time loop ..."
@@ -41,8 +40,10 @@ PROGRAM simulate_iau
   current_date = start_date
   current_date = current_date + iau_time_shift
 
-  WRITE (0, *) '           start date ', start_date%toString()
-  WRITE (0, *) '   shifted start date ', current_date%toString()
+  CALL datetimeToString(start_date, dstring)
+  WRITE (0, *) '           start date ', dstring
+  CALL datetimeToString(current_date, dstring)
+  WRITE (0, *) '   shifted start date ', dstring
 
   iau_iter = MERGE(1, 0, iterate_iau)
 
@@ -63,13 +64,14 @@ PROGRAM simulate_iau
 
     current_date = current_date + time_step
 
-    WRITE (0, *) "   Time loop ", current_date%toString(), jstep
+    CALL datetimeToString(current_date, dstring)
+    WRITE (0, *) "   Time loop ", dstring, jstep
 
-    IF ((current_date%getDay() /= previous_date%getDay()) .AND. .NOT. (jstep == 0 .AND. iau_iter == 1)) THEN
+    IF ((current_date%date%day /= previous_date%date%day) .AND. .NOT. (jstep == 0 .AND. iau_iter == 1)) THEN
       previous_date = current_date
     END IF
 
-    WRITE (0, *) '   --- integrate nh input: ', current_date%toString(), jstep - jstep_shift, iau_iter
+    WRITE (0, *) '   --- integrate nh input: ', dstring, jstep - jstep_shift, iau_iter
 
     IF (current_date >= stop_date) THEN
       EXIT time_loop
@@ -85,6 +87,7 @@ PROGRAM simulate_iau
 
   END DO time_loop
 
-#endif
+  CALL deallocateTimeDelta(time_step)
+  CALL deallocateTimeDelta(iau_time_shift)
 
 END PROGRAM simulate_iau
-- 
GitLab