Skip to content

Commit 2356728

Browse files
authored
Merge pull request #80 from billsacks/water_tracers_is_wtracer
Add shr_wtracers_is_wtracer_field The main motivation of adding this is that it helps me break a dependency of CMEPS on CESM_share, which I'll illustrate in ESCOMP/CMEPS#620. But this also feels like it will lead to more self-documenting code, since `shr_wtracers_is_wtracer_field` is more clear than calling `shr_string_withoutSuffix` directly.
2 parents 6c43c7e + d762295 commit 2356728

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/water_isotopes/shr_wtracers_mod.F90

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module shr_wtracers_mod
2020
use shr_log_mod , only : shr_log_error
2121
use shr_log_mod , only : s_logunit=>shr_log_Unit
2222
use shr_string_mod , only : shr_string_listGetAllNames, shr_string_toUpper
23+
use shr_string_mod , only : shr_string_withoutSuffix
2324
use shr_sys_mod , only : shr_sys_abort
2425
use nuopc_shr_methods , only : chkerr
2526
use NUOPC , only : NUOPC_CompAttributeGet
@@ -35,6 +36,7 @@ module shr_wtracers_mod
3536

3637
public :: shr_wtracers_init ! initialize water tracer information
3738
public :: shr_wtracers_finalize ! finalize water tracer information
39+
public :: shr_wtracers_is_wtracer_field ! return true if the given field name is a water tracer field
3840
public :: shr_wtracers_present ! return true if there are water tracers in this simulation
3941
public :: shr_wtracers_get_num_tracers ! get number of water tracers in this simulation
4042
public :: shr_wtracers_get_name ! get the name of a given tracer
@@ -354,6 +356,38 @@ subroutine shr_wtracers_check_tracer_num(tracer_num, subname)
354356
end if
355357
end subroutine shr_wtracers_check_tracer_num
356358

359+
!-----------------------------------------------------------------------
360+
function shr_wtracers_is_wtracer_field(fieldname)
361+
!
362+
! !DESCRIPTION:
363+
! Return true if the given field name is a water tracer field
364+
!
365+
! Note that, unlike most other routines in this module, this function works even if
366+
! the data in this module has not been initialized (i.e., even if shr_wtracers_init
367+
! has not been called): it works simply based on naming conventions.
368+
!
369+
! !ARGUMENTS
370+
character(len=*), intent(in) :: fieldname
371+
logical :: shr_wtracers_is_wtracer_field ! function result
372+
!
373+
! !LOCAL VARIABLES:
374+
integer :: localrc
375+
logical :: is_tracer
376+
377+
character(len=*), parameter :: subname='shr_wtracers_is_wtracer_field'
378+
!-----------------------------------------------------------------------
379+
380+
call shr_string_withoutSuffix( &
381+
in_str = fieldname, &
382+
suffix = WTRACERS_SUFFIX, &
383+
has_suffix = is_tracer, &
384+
rc = localrc)
385+
if (localrc /= 0) then
386+
call shr_sys_abort(subname//": ERROR in shr_string_withoutSuffix")
387+
end if
388+
shr_wtracers_is_wtracer_field = is_tracer
389+
end function shr_wtracers_is_wtracer_field
390+
357391
!-----------------------------------------------------------------------
358392
function shr_wtracers_present()
359393
!

0 commit comments

Comments
 (0)