Skip to content

Commit 5d2658f

Browse files
authored
validate seconds_per_time_unit (#157)
* check for valid values of seconds_per_time_unit * clean up initialize_global
1 parent c76c348 commit 5d2658f

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/builtin/time_filter.F90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,11 @@ subroutine horizontal_temporal_maximum_initialize(self, configunit)
211211
subroutine interior_temporal_mean_set_data(self, store, seconds_per_time_unit)
212212
class (type_interior_temporal_mean), intent(inout) :: self
213213
type (type_store), target :: store
214-
real(rke), intent(in) :: seconds_per_time_unit
214+
real(rke), optional, intent(in) :: seconds_per_time_unit
215215

216216
integer :: ibin
217217

218+
if (.not. present(seconds_per_time_unit)) call self%fatal_error('interior_temporal_mean_set_data', 'host did not provide time information.')
218219
self%source%icatalog = self%source%link%target%catalog_index
219220
self%window = self%window / seconds_per_time_unit
220221
do ibin = 1, size(self%history)
@@ -344,10 +345,11 @@ subroutine interior_temporal_mean_update(self, catalog _POSTARG_LOCATION_RANGE_,
344345
subroutine horizontal_temporal_mean_set_data(self, store, seconds_per_time_unit)
345346
class (type_horizontal_temporal_mean), intent(inout) :: self
346347
type (type_store), target :: store
347-
real(rke), intent(in) :: seconds_per_time_unit
348+
real(rke), optional, intent(in) :: seconds_per_time_unit
348349

349350
integer :: ibin
350351

352+
if (.not. present(seconds_per_time_unit)) call self%fatal_error('horizontal_temporal_mean_set_data', 'host did not provide time information.')
351353
self%source%icatalog = self%source%link%target%catalog_index
352354
self%window = self%window / seconds_per_time_unit
353355
do ibin = 1, size(self%history)
@@ -477,10 +479,11 @@ end subroutine horizontal_temporal_mean_update
477479
subroutine horizontal_temporal_maximum_set_data(self, store, seconds_per_time_unit)
478480
class (type_horizontal_temporal_maximum), intent(inout) :: self
479481
type (type_store), target :: store
480-
real(rke), intent(in) :: seconds_per_time_unit
482+
real(rke), optional, intent(in) :: seconds_per_time_unit
481483

482484
integer :: ibin
483485

486+
if (.not. present(seconds_per_time_unit)) call self%fatal_error('horizontal_temporal_maximum_set_data', 'host did not provide time information.')
484487
self%source%icatalog = self%source%link%target%catalog_index
485488
self%window = self%window / seconds_per_time_unit
486489
do ibin = 1, size(self%history)

src/fabm.F90

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,10 @@ subroutine set_domain(self _POSTARG_LOCATION_, seconds_per_time_unit)
683683
self%domain%horizontal_shape(:) = (/_HORIZONTAL_LOCATION_/)
684684
#endif
685685

686-
if (present(seconds_per_time_unit)) self%seconds_per_time_unit = seconds_per_time_unit
686+
if (present(seconds_per_time_unit)) then
687+
if (seconds_per_time_unit <= 0.0_rke) call fatal_error('set_domain', 'seconds_per_time_unit must be positive if provided.')
688+
self%seconds_per_time_unit = seconds_per_time_unit
689+
end if
687690
end subroutine set_domain
688691

689692
#if _FABM_DIMENSION_COUNT_>0
@@ -905,7 +908,11 @@ subroutine start(self)
905908
call cache_create(self%domain, self%cache_fill_values, self%cache_hz)
906909
call cache_create(self%domain, self%cache_fill_values, self%cache_vert)
907910

908-
call initialize_global(self%root)
911+
if (self%seconds_per_time_unit == 0.0_rke) then
912+
call initialize_global(self%root)
913+
else
914+
call initialize_global(self%root, self%seconds_per_time_unit)
915+
end if
909916

910917
! For diagnostics that are not needed, set their write index to 0 (rubbish bin)
911918
if (self%log) then
@@ -998,20 +1005,21 @@ subroutine flag_variables_with_data(variable_list, data_sources)
9981005
end do
9991006
end subroutine
10001007

1001-
recursive subroutine initialize_global(model)
1008+
recursive subroutine initialize_global(model, seconds_per_time_unit)
10021009
class (type_base_model), intent(inout) :: model
1010+
real(rke), optional, intent(in) :: seconds_per_time_unit
10031011

10041012
type (type_model_list_node), pointer :: child
10051013

10061014
select type (model)
10071015
class is (type_global_model)
1008-
call model%set_data(self%store, self%seconds_per_time_unit)
1016+
call model%set_data(self%store, seconds_per_time_unit)
10091017
end select
10101018

10111019
! Process children
10121020
child => model%children%first
10131021
do while (associated(child))
1014-
call initialize_global(child%model)
1022+
call initialize_global(child%model, seconds_per_time_unit)
10151023
child => child%next
10161024
end do
10171025
end subroutine

src/fabm_global_types.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ module fabm_global_types
113113
subroutine set_data(self, store, seconds_per_time_unit)
114114
class (type_global_model), intent(inout) :: self
115115
type (type_store), target :: store
116-
real(rke), intent(in) :: seconds_per_time_unit
116+
real(rke), optional, intent(in) :: seconds_per_time_unit
117117
end subroutine
118118

119119
subroutine update(self, catalog _POSTARG_LOCATION_RANGE_, time)

0 commit comments

Comments
 (0)