Skip to content

Commit

Permalink
add number_of_days_in_year and maximum_time_step standard variables; …
Browse files Browse the repository at this point in the history
…add global_constant builtin model (#99)

* add number_of_days_in_year and maximum_time_step standard variables; add global_constant builtin model

* typo
  • Loading branch information
jornbr authored Nov 22, 2024
1 parent 5b14042 commit a28d33c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/standard_variable_assignments.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ self%longitude%units = 'degree_east'
self%longitude%cf_names = 'longitude'
call add(self%longitude)

self%maximum_time_step%name = 'maximum_time_step'
self%maximum_time_step%units = 's'
call add(self%maximum_time_step)

self%number_of_days_in_year%name = 'number_of_days_in_year'
self%number_of_days_in_year%units = 'd'
call add(self%number_of_days_in_year)

self%number_of_days_since_start_of_the_year%name = 'number_of_days_since_start_of_the_year'
self%number_of_days_since_start_of_the_year%units = 'd'
call add(self%number_of_days_since_start_of_the_year)
Expand Down
2 changes: 2 additions & 0 deletions include/standard_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type (type_horizontal_standard_variable) :: latitude
type (type_horizontal_standard_variable) :: longitude

! Global variables
type (type_global_standard_variable) :: maximum_time_step
type (type_global_standard_variable) :: number_of_days_in_year
type (type_global_standard_variable) :: number_of_days_since_start_of_the_year

! Universal variables
Expand Down
26 changes: 26 additions & 0 deletions src/builtin/constant.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ module fabm_builtin_constant
procedure :: initialize => bottom_constant_initialize
end type

type, extends(type_base_model), public :: type_global_constant
contains
procedure :: initialize => global_constant_initialize
end type

contains

subroutine interior_constant_initialize(self, configunit)
Expand Down Expand Up @@ -117,4 +122,25 @@ subroutine bottom_constant_initialize(self, configunit)
end if
end subroutine bottom_constant_initialize

subroutine global_constant_initialize(self, configunit)
class (type_global_constant), intent(inout), target :: self
integer, intent(in) :: configunit

real(rk) :: value
type (type_global_standard_variable) :: standard_variable

call self%register_implemented_routines()
call self%get_parameter(standard_variable%name, 'standard_name', '', 'standard name', default='')
call self%get_parameter(value, 'value', '', 'value')
if (standard_variable%name /= '') then
! Note: for Cray 8.3.7, standard_variable needs to be declared separately.
! It cannot be constructed on the fly within the function call
call self%add_scalar_variable('data', '', 'data', fill_value=value, &
output=output_none, source=source_constant, standard_variable=standard_variable)
else
call self%add_scalar_variable('data', '', 'data', fill_value=value, &
output=output_none, source=source_constant)
end if
end subroutine global_constant_initialize

end module
1 change: 1 addition & 0 deletions src/builtin/model_library.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ subroutine create(self,name,model)
case ('horizontal_constant'); allocate(type_horizontal_constant::model)
case ('bottom_constant'); allocate(type_bottom_constant::model)
case ('surface_constant'); allocate(type_surface_constant::model)
case ('global_constant'); allocate(type_global_constant::model)
case ('surface_flux'); allocate(type_constant_surface_flux::model)
case ('constant_surface_flux'); allocate(type_constant_surface_flux::model)
case ('external_surface_flux'); allocate(type_external_surface_flux::model)
Expand Down
2 changes: 1 addition & 1 deletion src/fabm_job.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ subroutine job_manager_initialize(self, variable_register, schedules, log_unit,
node => node%next
end do

! If we have unfulfilled dependneices, stop here and let the host/user deal with them.
! If we have unfulfilled dependencies, stop here and let the host/user deal with them.
if (associated(variable_register%unfulfilled_dependencies%first)) return

variable_register%read_cache%frozen = .true.
Expand Down
6 changes: 3 additions & 3 deletions src/fabm_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2037,15 +2037,15 @@ subroutine add_horizontal_variable(self, name, units, long_name, missing_value,
end subroutine add_horizontal_variable

subroutine add_scalar_variable(self, name, units, long_name, missing_value, minimum, maximum, initial_value, &
background_value, fill_value, standard_variable, presence, output, &
background_value, fill_value, standard_variable, presence, output, source, &
read_index, state_index, write_index, sms_index, background, link)
class (type_base_model),target, intent(inout) :: self
character(len=*), intent(in) :: name
character(len=*), intent(in), optional :: units, long_name
real(rk), intent(in), optional :: minimum, maximum, missing_value
real(rk), intent(in), optional :: initial_value, background_value, fill_value
class (type_base_standard_variable), intent(in), optional :: standard_variable
integer, intent(in), optional :: presence, output
integer, intent(in), optional :: presence, output, source
integer, target, optional :: read_index, state_index, write_index, sms_index
real(rk), target, optional :: background
type (type_link), pointer, optional :: link
Expand All @@ -2057,7 +2057,7 @@ subroutine add_scalar_variable(self, name, units, long_name, missing_value, mini

! Process remainder of fields and creation of link generically (i.e., irrespective of variable domain).
call add_variable(self, variable, name, units, long_name, missing_value, minimum, maximum, &
initial_value, background_value, fill_value, standard_variable, presence, output, source_unknown, &
initial_value, background_value, fill_value, standard_variable, presence, output, source, &
.false., read_index, state_index, write_index, background, link)
end subroutine add_scalar_variable

Expand Down
4 changes: 4 additions & 0 deletions util/standard_variables/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ horizontal:
global:
- name: number_of_days_since_start_of_the_year
units: d
- name: number_of_days_in_year
units: d
- name: maximum_time_step
units: s
universal:
- name: total_carbon
units: mmol m-3
Expand Down

0 comments on commit a28d33c

Please sign in to comment.