Skip to content

Commit

Permalink
Add ccpp_const_utils implementing ccpp_const_get_index to avoid circu…
Browse files Browse the repository at this point in the history
…lar dependencies.
  • Loading branch information
jimmielin committed Oct 16, 2024
1 parent bc1f643 commit fbea5c8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions to_be_ccppized/ccpp_const_utils.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
! ccpp_const_utils contains utility functions that use
! the ccpp constituents property pointer.
! this code was separated out to remove circular dependencies.
module ccpp_const_utils
implicit none
private

public :: ccpp_const_get_idx

contains

subroutine ccpp_const_get_idx(constituent_props, name, cindex, errmsg, errflg)
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t

! Input arguments
type(ccpp_constituent_prop_ptr_t), pointer, intent(in) :: constituent_props(:)
character(len=*), intent(in) :: name ! constituent name

! Output arguments
integer, intent(out) :: cindex ! global constituent index
character(len=512), intent(out) :: errmsg ! error message
integer, intent(out) :: errflg ! error flag

! Local variables
integer :: t_cindex
character(len=256) :: t_const_name

errmsg = ''
errflg = 0

cindex = -1

! This convoluted loop is brought to you in exchange for avoiding a
! circular dependency on cam_ccpp_cap::cam_const_get_index.
const_props_loop: do t_cindex = lbound(constituent_props, 1), ubound(constituent_props, 1)
call constituent_props(t_cindex)%standard_name(t_const_name, errflg, errmsg)
if (errflg /= 0) then
! Abort subroutine and return with error.
return
end if

if (trim(t_const_name) == trim(name)) then
cindex = t_cindex
exit const_props_loop
end if
enddo const_props_loop

end subroutine ccpp_const_get_idx

end module ccpp_const_utils

0 comments on commit fbea5c8

Please sign in to comment.