From 8bff4e4dbd39ee72388d88555450b0a478207b34 Mon Sep 17 00:00:00 2001
From: Stefan Hagemann <stefan.hagemann@hereon.de>
Date: Thu, 13 Feb 2025 10:36:17 +0100
Subject: [PATCH] Add time steering related warnings and documentation

---
 code/src/hd_driver.f90    | 13 +++++++++++++
 docu/namelist_settings.md |  2 ++
 docu/readme_hd_model.md   | 13 +++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/code/src/hd_driver.f90 b/code/src/hd_driver.f90
index 0f62ac6..16e5594 100644
--- a/code/src/hd_driver.f90
+++ b/code/src/hd_driver.f90
@@ -670,6 +670,15 @@ CONTAINS
 
     ! Check Run period and calculate number of time steps if start and end date are provided
 
+    IF (LEN_TRIM(time_start).GT.0 .AND. LEN_TRIM(date_start).LE.0) THEN
+      WRITE (message_text,*) 'time_start is set but date_start is not --> Unclean setting --> Please correct!'
+      CALL finish ('config_hd', message_text)
+    ENDIF
+    IF (LEN_TRIM(time_end).GT.0 .AND. LEN_TRIM(date_end).LE.0) THEN
+      WRITE (message_text,*) 'time_end is set but date_end is not --> Unclean setting --> Please correct!'
+      CALL finish ('config_hd', message_text)
+    ENDIF
+
     IF (LEN_TRIM(date_start).GT.0 .AND. LEN_TRIM(date_end).GT.0) THEN
       IF (LEN_TRIM(time_start).GT.0 .AND. LEN_TRIM(time_end).GT.0) THEN
         CALL calc_nstep(date_start, time_start, date_end, time_end, nstep, year1, month1, day1, hour1, minute1, second1)
@@ -702,11 +711,15 @@ CONTAINS
           CALL calc_nstep(date_start, time_start, date_rest, time_rest, nstep_rest)
         ELSE   ! If time_start not set, midnight (0 am) is assumed.
           CALL calc_nstep(date_start, '00:00:00', date_rest, time_rest, nstep_rest)
+          WRITE (message_text,*) 'time_start is not set --> Assuming start at midnight (0 am)'
+          CALL message('config_hd', message_text)
         ENDIF
         nstep_rest = nstep_rest - 1      ! time_rest is exact time, not begin time of a timestep.
       ELSE     ! It is assumed that restart file shall be written after date_rest is calculated.
         CALL calc_nstep(date_start, '00:00:00', date_rest, '00:00:00', nstep_rest)
         nstep_rest = nstep_rest + NINT(86400._dp / delta_time)    ! --> add no. of timesteps of one day.
+        WRITE (message_text,*) 'time_rest is not set --> Restart will be written after date_rest is calculated'
+        CALL message('config_hd', message_text)
       ENDIF
     ENDIF
 
diff --git a/docu/namelist_settings.md b/docu/namelist_settings.md
index 2e76a52..b884cf7 100644
--- a/docu/namelist_settings.md
+++ b/docu/namelist_settings.md
@@ -33,7 +33,9 @@ Time Control
      nstep          INTEGER     number of time steps within the run (Def. 365) if date_start & date_end are not provided
      delta_time     REAL(dp)    model time step length in seconds, Default: 86400.
      time_start     CHARACTER   Start time of the run, format HHMMSS or HH:MM:SS (Def.: none)
+                                If you set time_start, you must also set date_start.
      time_end       CHARACTER   End of the run: Begin time of final time step, HHMMSS or HH:MM:SS (Def.: none)
+                                If you set time_end, you must also set date_end.
      date_rest      CHARACTER   Date of the first restart file writing, format YYYYMMDD or YYYY-MM-DD (Def.: none)
      time_rest      CHARACTER   Time of the first restart file writing, format HHMMSS or HH:MM:SS (Def.: none)
 
diff --git a/docu/readme_hd_model.md b/docu/readme_hd_model.md
index 2150a93..fea7c62 100644
--- a/docu/readme_hd_model.md
+++ b/docu/readme_hd_model.md
@@ -28,6 +28,7 @@ This readme file comprises a checklist to perform standalone model runs with the
 1.4. Adapt run script settings in *run_hdmodel.ksh*
 1.5. Choose from where you start a new model run
 1.6. Adapt run script settings in subscript *hd_run_settings.ksh*
+1.7. Alternative and more detailed settings of the simulation period
 2. Coupling the HD model
 3. Necessary preparations for a new regional HD 5 min. domain
 3.1. Preparation of 5 Min. subdomain from the global 5 min. HD parameter
@@ -161,6 +162,8 @@ file
    c. Set first (YYYY) and last (YEND) year of your simulation.
       - The first year "YYYY=" of the whole simulation should be kept on its initial value
         even if you add more years later by increasing the last year YEND. 
+      - Alternatively, you may steer the simulation by specifying date_start and date_end. 
+        Section 1.7 provides some details on more elaborate settings of the simulation period.
 
    d. Select forcing "IFORCE=" and HD Model resolution "HDRES="
 
@@ -197,6 +200,7 @@ file
         |   2   | monthly, not fully explored              |
         |   3   | annual with 30-day months                |
         |   4   | as 1 but final year with nday_final days |
+        |   5   | Detailled steering by settings in *./scr/hd_subdaily_settings.ksh* |
 
       - Set Variable nday_final if IWORK=4, e.g. nday_final=212 (Jan-July)
 
@@ -237,6 +241,15 @@ file
       - On a slurm system, (e.g. Levante at DKRZ) use:
         `sbatch run_hdmodel.ksh`
 
+7. Alternative and more detailed settings of the simulation period
+         
+   * Instead of specifying the last year (YEND) in *./scr/hd_run_settings.ksh* or the number of time steps (nstep) in *namelist.hd*, you may steer the simulation by specifying date_start and date_end of your simulation.   
+         
+   * You may use a more detailed steering of the simulation period by setting start (time_start) and end (time_end) times of your simulation. Note that if time_start or time_end are set, you must also set date_start and date_end, respectively. If time_start is not specified, it is set to 0 am. If time_end is not specified, the simulation will end after the final time step of date_end.
+         
+   * In addition to writing a restart file in the end of the simulation period, an additional restart file may be written at a specified date (date_rest) and time (time_rest). If time_rest is not provided, the restart file will be written in the end of day date_rest. 
+         
+   * When using *./scr/hd_run_settings.ksh*, you may set IWORK=5 and specify such detailed settings in *./scr/hd_subdaily_settings.ksh*
         
 ## 2. Coupling the HD model
 
-- 
GitLab