-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement constituent index lookup routines
ccpp_constituent_index: Lookup index constituent by name ccpp_constituent_indices: Lookup indices of consitutents by name Add tests of this functionality into advection_test Minor code cleanup Update DDThost test for new CCPP source file
- Loading branch information
Steve Goldhaber
committed
Jan 6, 2025
1 parent
fca3a9e
commit 949afbc
Showing
23 changed files
with
464 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
module ccpp_scheme_utils | ||
|
||
! Module of utilities available to CCPP schemes | ||
|
||
use ccpp_constituent_prop_mod, only: ccpp_model_constituents_t, int_unassigned | ||
|
||
implicit none | ||
private | ||
|
||
!! Public interfaces | ||
public :: ccpp_initialize_constituent_ptr ! Used by framework to initialize | ||
public :: ccpp_constituent_index ! Lookup index constituent by name | ||
public :: ccpp_constituent_indices ! Lookup indices of consitutents by name | ||
|
||
!! Private module variables & interfaces | ||
|
||
! initialized set to .true. once hash table pointer is initialized | ||
logical :: initialized = .false. | ||
type(ccpp_model_constituents_t), pointer :: constituent_obj => NULL() | ||
|
||
private :: uninitialized | ||
|
||
contains | ||
|
||
subroutine uninitialized(caller, errcode, errmsg) | ||
! Dummy arguments | ||
character(len=*), intent(in) :: caller | ||
integer, optional, intent(out) :: errcode | ||
character(len=*), optional, intent(out) :: errmsg | ||
|
||
if (.not. initialized) then | ||
if (present(errcode)) then | ||
errcode = 1 | ||
end if | ||
if (present(errmsg)) then | ||
errmsg = trim(caller)//' FAILED, module not initialized' | ||
end if | ||
end if | ||
end subroutine uninitialized | ||
|
||
subroutine ccpp_initialize_constituent_ptr(const_obj) | ||
! Dummy arguments | ||
type(ccpp_model_constituents_t), pointer, intent(in) :: const_obj | ||
|
||
if (.not. initialized) then | ||
constituent_obj => const_obj | ||
initialized = .true. | ||
end if | ||
end subroutine ccpp_initialize_constituent_ptr | ||
|
||
subroutine ccpp_constituent_index(standard_name, const_index, errcode, errmsg) | ||
! Dummy arguments | ||
character(len=*), intent(in) :: standard_name | ||
integer, intent(out) :: const_index | ||
integer, optional, intent(out) :: errcode | ||
character(len=*), optional, intent(out) :: errmsg | ||
|
||
! Local variable | ||
character(len=*), parameter :: subname = 'ccpp_constituent_index' | ||
|
||
if (initialized) then | ||
call constituent_obj%const_index(const_index, standard_name, & | ||
errcode, errmsg) | ||
else | ||
const_index = int_unassigned | ||
call uninitialized(subname) | ||
end if | ||
end subroutine ccpp_constituent_index | ||
|
||
subroutine ccpp_constituent_indices(standard_names, const_inds, errcode, errmsg) | ||
! Dummy arguments | ||
character(len=*), intent(in) :: standard_names(:) | ||
integer, intent(out) :: const_inds(:) | ||
integer, optional, intent(out) :: errcode | ||
character(len=*), optional, intent(out) :: errmsg | ||
|
||
! Local variables | ||
integer :: indx | ||
character(len=*), parameter :: subname = 'ccpp_constituent_indices' | ||
|
||
const_inds = int_unassigned | ||
if (initialized) then | ||
if (size(const_inds) < size(standard_names)) then | ||
errcode = 1 | ||
errmsg = subname//': const_inds too small' | ||
else | ||
do indx = 1, size(standard_names) | ||
! For each std name in <standard_names>, find the const. index | ||
call constituent_obj%const_index(const_inds(indx), & | ||
standard_names(indx), errcode, errmsg) | ||
if (errcode /= 0) then | ||
exit | ||
end if | ||
end do | ||
end if | ||
else | ||
call uninitialized(subname) | ||
end if | ||
end subroutine ccpp_constituent_indices | ||
|
||
end module ccpp_scheme_utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
cld_liq.meta | ||
cld_ice.meta | ||
apply_constituent_tendencies.meta | ||
const_indices.meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
! Test collection of constituent indices | ||
! | ||
|
||
MODULE const_indices | ||
|
||
USE ccpp_kinds, ONLY: kind_phys | ||
|
||
IMPLICIT NONE | ||
PRIVATE | ||
|
||
PUBLIC :: const_indices_init | ||
PUBLIC :: const_indices_run | ||
|
||
CONTAINS | ||
|
||
!> \section arg_table_const_indices_run Argument Table | ||
!! \htmlinclude arg_table_const_indices_run.html | ||
!! | ||
subroutine const_indices_run(const_std_name, num_consts, test_stdname_array, & | ||
const_index, const_inds, errmsg, errflg) | ||
use ccpp_scheme_utils, only: ccpp_constituent_index, ccpp_constituent_indices | ||
|
||
character(len=*), intent(in) :: const_std_name | ||
integer, intent(in) :: num_consts | ||
character(len=*), intent(in) :: test_stdname_array(:) | ||
integer, intent(out) :: const_index | ||
integer, intent(out) :: const_inds(:) | ||
character(len=512), intent(out) :: errmsg | ||
integer, intent(out) :: errflg | ||
!---------------------------------------------------------------- | ||
|
||
integer :: indx | ||
|
||
errmsg = '' | ||
errflg = 0 | ||
|
||
! Find the constituent index for <const_std_name> | ||
call ccpp_constituent_index(const_std_name, const_index, errflg, errmsg) | ||
if (errflg == 0) then | ||
call ccpp_constituent_indices(test_stdname_array, const_inds, errflg, errmsg) | ||
end if | ||
|
||
end subroutine const_indices_run | ||
|
||
!> \section arg_table_const_indices_init Argument Table | ||
!! \htmlinclude arg_table_const_indices_init.html | ||
!! | ||
subroutine const_indices_init(const_std_name, num_consts, test_stdname_array, & | ||
const_index, const_inds, errmsg, errflg) | ||
use ccpp_scheme_utils, only: ccpp_constituent_index, ccpp_constituent_indices | ||
|
||
character(len=*), intent(in) :: const_std_name | ||
integer, intent(in) :: num_consts | ||
character(len=*), intent(in) :: test_stdname_array(:) | ||
integer, intent(out) :: const_index | ||
integer, intent(out) :: const_inds(:) | ||
character(len=512), intent(out) :: errmsg | ||
integer, intent(out) :: errflg | ||
!---------------------------------------------------------------- | ||
|
||
integer :: indx | ||
|
||
errmsg = '' | ||
errflg = 0 | ||
|
||
! Find the constituent index for <const_std_name> | ||
call ccpp_constituent_index(const_std_name, const_index, errflg, errmsg) | ||
if (errflg == 0) then | ||
call ccpp_constituent_indices(test_stdname_array, const_inds, errflg, errmsg) | ||
end if | ||
|
||
end subroutine const_indices_init | ||
|
||
!! @} | ||
!! @} | ||
|
||
END MODULE const_indices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# const_indices just returns some constituent indices as a test | ||
[ccpp-table-properties] | ||
name = const_indices | ||
type = scheme | ||
[ccpp-arg-table] | ||
name = const_indices_run | ||
type = scheme | ||
[ const_std_name ] | ||
standard_name = test_banana_name | ||
type = character | kind = len=* | ||
units = 1 | ||
dimensions = () | ||
protected = true | ||
intent = in | ||
[ num_consts ] | ||
standard_name = banana_array_dim | ||
long_name = Size of test_banana_name_array | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = in | ||
[ test_stdname_array ] | ||
standard_name = test_banana_name_array | ||
type = character | kind = len=* | ||
units = count | ||
dimensions = (banana_array_dim) | ||
intent = in | ||
[ const_index ] | ||
standard_name = test_banana_constituent_index | ||
long_name = Constituent index | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = out | ||
[ const_inds ] | ||
standard_name = test_banana_constituent_indices | ||
long_name = Array of constituent indices | ||
units = 1 | ||
dimensions = (banana_array_dim) | ||
type = integer | ||
intent = out | ||
[ errmsg ] | ||
standard_name = ccpp_error_message | ||
long_name = Error message for error handling in CCPP | ||
units = none | ||
dimensions = () | ||
type = character | ||
kind = len=512 | ||
intent = out | ||
[ errflg ] | ||
standard_name = ccpp_error_code | ||
long_name = Error flag for error handling in CCPP | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = out | ||
[ccpp-arg-table] | ||
name = const_indices_init | ||
type = scheme | ||
[ const_std_name ] | ||
standard_name = test_banana_name | ||
type = character | kind = len=* | ||
units = 1 | ||
dimensions = () | ||
protected = true | ||
intent = in | ||
[ num_consts ] | ||
standard_name = banana_array_dim | ||
long_name = Size of test_banana_name_array | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = in | ||
[ test_stdname_array ] | ||
standard_name = test_banana_name_array | ||
type = character | kind = len=* | ||
units = count | ||
dimensions = (banana_array_dim) | ||
intent = in | ||
[ const_index ] | ||
standard_name = test_banana_constituent_index | ||
long_name = Constituent index | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = out | ||
[ const_inds ] | ||
standard_name = test_banana_constituent_indices | ||
long_name = Array of constituent indices | ||
units = 1 | ||
dimensions = (banana_array_dim) | ||
type = integer | ||
intent = out | ||
[ errmsg ] | ||
standard_name = ccpp_error_message | ||
long_name = Error message for error handling in CCPP | ||
units = none | ||
dimensions = () | ||
type = character | ||
kind = len=512 | ||
intent = out | ||
[ errflg ] | ||
standard_name = ccpp_error_code | ||
long_name = Error flag for error handling in CCPP | ||
units = 1 | ||
dimensions = () | ||
type = integer | ||
intent = out |
Oops, something went wrong.