diff --git a/code/src/hd_ctl.inc b/code/src/hd_ctl.inc index 476f9654bee21c3fb89857e8cfe6c5b06b1f8d78..b0a637fdd94124c7fd85baac9f00a2a7fe2ac919 100644 --- a/code/src/hd_ctl.inc +++ b/code/src/hd_ctl.inc @@ -29,9 +29,12 @@ ! nstep INTEGER Number of time steps within the run if date_start & date_end are not provided ! delta_time REAL(dp) Model time step length in seconds ! 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 time of the run, 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) +! irest_regular INTEGER Switch for regular writing of restart files (0=none, 1=annual) ! ! ufakru REAL(dp) unit factor for runoff and drainage input data ! runoff_file CHARACTER file with input runoff data @@ -65,7 +68,7 @@ NAMELIST /HD_CTL/ & OUT_EXPNAME, OUT_DATAPATH, YEAR1, MONTH1, DATE_START, DATE_END, NSTEP, DELTA_TIME, & - TIME_START, TIME_END, DATE_REST, TIME_REST, & + TIME_START, TIME_END, DATE_REST, TIME_REST, IREST_REGULAR, & UFAKRU, RUNOFF_FILE, DRAINAGE_FILE, FORCING_FREQ, IOUT, & COUPLING_TYPE, LCOUPLING_ATM, LCOUPLING_OCE, ICPL_SINKS, ICPL_MASK_TOHD, & COUPLING_FILE, LCOUPLING_OUT, IFORM_INPUT, LTRANSPORT, IBC_TYPE, DN_BCPARA, LBC_WRITE diff --git a/code/src/hd_driver.f90 b/code/src/hd_driver.f90 index 16e55947ff1e23257cd2e317a259473e4d4657dd..19aeb851aeec4800c102d09331cc918c18c8a62b 100644 --- a/code/src/hd_driver.f90 +++ b/code/src/hd_driver.f90 @@ -81,7 +81,7 @@ PROGRAM hd_driver USE mo_time_control, ONLY: l_trigfiles, dt_start, init_manager, delta_time, & init_times, ec_manager_init, time_reset, & no_steps, time_set, current_date, & - write_date, day_difference, calc_nstep + write_date, day_difference, calc_nstep, update_regular_restart USE mo_exception, ONLY: finish, message, message_text !OSBJSB USE mo_jsbach_interface, ONLY: get_dates USE mo_control, ONLY: nlon, ngl, nproca, nprocb, nprocio @@ -124,6 +124,7 @@ PROGRAM hd_driver CHARACTER(LEN=10) :: date_start, date_end, date_rest CHARACTER(LEN=8) :: time_start, time_end, time_rest INTEGER :: nstep_rest ! Number of time steps until a dedicated writing of restart file + INTEGER :: irest_regular ! Switch for regular writing of restart files (0=none, 1=annual, 2=monthly) INTEGER :: forcing_freq INTEGER :: iout LOGICAL :: lcoupling_out ! Write output for coupling_type 2 (no/yes) @@ -591,7 +592,8 @@ CONTAINS ! time_start Start time of the run, format HHMMSS or HH:MM:SS (Def.: none) ! time_end End time of the run, HHMMSS or HH:MM:SS (Def.: none) ! date_rest Date of the first restart file writing, format YYYYMMDD or YYYY-MM-DD (Def.: none) - ! time_rest Time of the first restart file writing, format HHMMSS or HH:MM:SS (Def.: none) + ! time_rest Time of the first restart file writing, format HHMMSS or HH:MM:SS (Def.: none) + ! irest_regular Switch for regular writing of restart files (0=none, 1=annual) ! ! runoff_file file with input runoff data ! drainage_file file with input drainage data @@ -622,6 +624,7 @@ CONTAINS INTEGER :: read_status, inml, iunit, ndays INTEGER :: coupling_type + INTEGER :: month_next INCLUDE 'hd_ctl.inc' @@ -639,6 +642,7 @@ CONTAINS time_end = '' date_rest = '' time_rest = '' + irest_regular = 0 ufakru = 1._dp runoff_file = "runoff.nc" drainage_file = "drainage.nc" @@ -700,6 +704,7 @@ CONTAINS ELSE WRITE (message_text,*) 'No. of time steps taken from namelist (Def.: 365): ', nstep CALL message('config_hd', message_text) + day1 = 0 ; hour1 = 0 ; minute1 = 0 ; second1 = 0 ENDIF ! Check whether the writing of a restart file at a speficied point in time is requested. @@ -723,6 +728,40 @@ CONTAINS ENDIF ENDIF + ! Check whether the regular writing of a restart file is requested. + + IF (irest_regular.GT.0) THEN + IF (LEN_TRIM(date_rest).GT.0) THEN + WRITE (message_text,*) 'A dedicated and regular restart file writings are both set -> Inconsistent -> Please correct!' + CALL finish ('config_hd', message_text) + ENDIF + SELECT CASE(irest_regular) + CASE(1) ! Annual + date_rest = 'yyyy-01-01' + WRITE(date_rest(1:4), '(I4.4)') year1+1 + CASE(2) ! monthly + month_next = month1 + 1 + IF (month_next.EQ.13) THEN + date_rest = 'yyyy-01-01' + WRITE(date_rest(1:4), '(I4.4)') year1+1 + ELSE + date_rest = 'yyyy-mm-01' + WRITE(date_rest(1:4), '(I4.4)') year1 + WRITE(date_rest(6:7), '(I2.2)') month_next + ENDIF + CASE default + WRITE (message_text,*) 'irest_regular = ', irest_regular, ' is not defined -> Program terminated' + CALL finish ('config_hd', message_text) + END SELECT + + IF (LEN_TRIM(date_start).LE.0) THEN + date_start = 'yyyy-mm-01' + WRITE(date_start(1:4), '(I4.4)') year1 + WRITE(date_start(6:7), '(I2.2)') month1 + ENDIF + CALL calc_nstep(date_start, '00:00:00', date_rest, '00:00:00', nstep_rest) + ENDIF + ! Check coupling information CALL set_coupling_type(coupling_type) diff --git a/code/src/mo_hydrology.f90 b/code/src/mo_hydrology.f90 index 4e88b880f250b7c7ab2e31082127e6a1f94948ff..0c70610f4ab8ff8ed0f4784712eb92496cf4c817 100644 --- a/code/src/mo_hydrology.f90 +++ b/code/src/mo_hydrology.f90 @@ -610,8 +610,8 @@ CONTAINS ! finfl = Inflow data array for each gridbox for time step nstep ! - CHARACTER(LEN=*), OPTIONAL :: date_rest ! Date of dedicated restart file writing - CHARACTER(LEN=*), OPTIONAL :: time_rest ! Time of dedicated restart file writing + CHARACTER(LEN=*), OPTIONAL, INTENT(in) :: date_rest ! Date of dedicated restart file writing + CHARACTER(LEN=*), OPTIONAL, INTENT(in) :: time_rest ! Time of dedicated restart file writing TYPE (FILE_INFO) :: restartfile diff --git a/code/src/mo_time_control.f90 b/code/src/mo_time_control.f90 index 7e8e4071b2f620c6a93dabf64f1191bc79a45e1c..963bc49dde09951b269ef5cc8081aa1769403b04 100644 --- a/code/src/mo_time_control.f90 +++ b/code/src/mo_time_control.f90 @@ -403,6 +403,8 @@ MODULE mo_time_control PUBLIC :: day_difference ! Calculate the difference in days for two ISO dates PUBLIC :: calc_nstep ! Calculate the number of time steps between two ISO dates & times + PUBLIC :: update_regular_restart ! Updates the time step number nstep_rest + ! when the next regular restart file shall be written CONTAINS !+ @@ -2421,6 +2423,55 @@ CONTAINS END SUBROUTINE ctime2hms + !***************************************************************************** + SUBROUTINE update_regular_restart(irest_regular, nstep_rest, date_rest) + !***************************************************************************** + + ! Updates the time step number nstep_rest when the next regular restart file shall be written + ! if irest_regular ist set > 0. + + INTEGER, INTENT(in) :: irest_regular ! Switch for regular writing of restart files + ! (0=none, 1=annual, 2=monthly) + INTEGER, INTENT(inout) :: nstep_rest ! Number of time steps until next writing of restart file + CHARACTER(LEN=*), INTENT(inout) :: date_rest ! Date of next regular restart file writing + + INTEGER :: ymd, year_rest, month_rest, day_rest, month_next, ndum + INTEGER :: zero = 0 + TYPE(time_days) :: date1 + TYPE(time_native) :: date_nat + CHARACTER(LEN=10) :: date_old + + date_old = date_rest + CALL cdate2ymd(date_rest, ymd) + + ! Determine day, month and year of previous restart date + CALL inp_convert_date (ymd, zero, date1) + CALL TC_convert(date1, date_nat) + CALL TC_get (date_nat, year_rest, month_rest, day_rest) + + SELECT CASE(irest_regular) + CASE(1) ! Annual + WRITE(date_rest(1:4), '(I4.4)') year_rest+1 + CASE(2) ! monthly + month_next = month_rest + 1 + IF (month_next.EQ.13) THEN + date_rest = 'yyyy-01-01' + WRITE(date_rest(1:4), '(I4.4)') year_rest+1 + ELSE + date_rest = 'yyyy-mm-01' + WRITE(date_rest(1:4), '(I4.4)') year_rest + WRITE(date_rest(6:7), '(I2.2)') month_next + ENDIF + CASE default + WRITE (message_text,*) 'irest_regular = ', irest_regular, ' is not defined -> Program terminated' + CALL finish ('update_regular_restart', message_text) + END SELECT + + CALL calc_nstep(date_old, '00:00:00', date_rest, '00:00:00', ndum) + nstep_rest = nstep_rest + ndum + + END SUBROUTINE update_regular_restart + !+ ! ------------------------------------------------------------------------------ !