module constituents use shr_kind_mod, only: r8 => shr_kind_r8 use physconst, only: r_universal use module_cam_support, only: masterproc,endrun,iulog,pcnst implicit none private save public cnst_add public cnst_num_avail public cnst_get_ind public cnst_get_type_byind public cnst_get_type_byname public cnst_read_iv public cnst_chk_dim public cnst_cam_outfld character(len=16), public :: cnst_name(pcnst) character(len=128),public :: cnst_longname(pcnst) logical, public :: readtrace = .true. real(r8), public :: cnst_cp (pcnst) real(r8), public :: cnst_cv (pcnst) real(r8), public :: cnst_mw (pcnst) character*3, public :: cnst_type(pcnst) real(r8), public :: cnst_rgas(pcnst) real(r8), public :: qmin (pcnst) real(r8), public :: qmincg (pcnst) logical, public :: cnst_fixed_ubc(pcnst) = .false. character(len=16), public :: apcnst (pcnst) character(len=16), public :: bpcnst (pcnst) character(len=16), public :: hadvnam (pcnst) character(len=16), public :: vadvnam (pcnst) character(len=16), public :: dcconnam (pcnst) character(len=16), public :: fixcnam (pcnst) character(len=16), public :: tendnam (pcnst) character(len=16), public :: ptendnam (pcnst) character(len=16), public :: dmetendnam(pcnst) character(len=16), public :: sflxnam (pcnst) character(len=16), public :: tottnam (pcnst) integer :: padv = 0 logical :: read_init_vals(pcnst) logical :: cam_outfld_(pcnst) CONTAINS subroutine cnst_add (name, mwc, cpc, qminc, & ind, longname, readiv, mixtype, cam_outfld, fixed_ubc) character(len=*), intent(in) :: & name real(r8),intent(in) :: mwc real(r8),intent(in) :: cpc real(r8),intent(in) :: qminc integer, intent(out) :: ind character(len=*), intent(in), optional :: & longname logical, intent(in), optional :: & readiv character(len=*), intent(in), optional :: & mixtype logical, intent(in), optional :: & cam_outfld logical, intent(in), optional :: & fixed_ubc padv = padv+1 ind = padv if (padv > pcnst) then write(iulog,*) 'CNST_ADD: advected tracer index greater than pcnst = ', pcnst call endrun end if cnst_name(ind) = name if ( present(longname) )then cnst_longname(ind) = longname else cnst_longname(ind) = name end if if ( present(readiv) ) then read_init_vals(ind) = readiv else read_init_vals(ind) = readtrace end if if ( present(mixtype) )then cnst_type(ind) = mixtype else cnst_type(ind) = 'wet' end if if ( present(cam_outfld) ) then cam_outfld_(ind) = cam_outfld else cam_outfld_(ind) = .true. end if if ( present(fixed_ubc) ) then cnst_fixed_ubc(ind) = fixed_ubc else cnst_fixed_ubc(ind) = .false. end if cnst_cp (ind) = cpc cnst_mw (ind) = mwc qmin (ind) = qminc qmincg (ind) = qminc if (ind == 1) qmincg = 0._r8 cnst_rgas(ind) = r_universal * mwc cnst_cv (ind) = cpc - cnst_rgas(ind) return end subroutine cnst_add function cnst_num_avail() integer cnst_num_avail cnst_num_avail = pcnst - padv end function cnst_num_avail subroutine cnst_get_ind (name, ind, abort) character(len=*), intent(in) :: name integer, intent(out) :: ind logical, optional, intent(in) :: abort integer :: m logical :: abort_on_error do m = 1, pcnst if (name == cnst_name(m)) then ind = m return end if end do abort_on_error = .true. if ( present(abort) ) abort_on_error = abort if ( abort_on_error ) then write(iulog,*) 'CNST_GET_IND, name:', name, ' not found in list:', cnst_name(:) call wrf_message(iulog) call endrun('CNST_GET_IND: name not found') end if ind = -1 end subroutine cnst_get_ind character*3 function cnst_get_type_byind (ind) integer, intent(in) :: ind integer :: m if (ind.le.pcnst) then cnst_get_type_byind = cnst_type(ind) else write(iulog,*) 'CNST_GET_TYPE_BYIND, ind:', ind call endrun endif end function cnst_get_type_byind character*3 function cnst_get_type_byname (name) character(len=*), intent(in) :: name integer :: m do m = 1, pcnst if (name == cnst_name(m)) then cnst_get_type_byname = cnst_type(m) return end if end do write(iulog,*) 'CNST_GET_TYPE_BYNAME, name:', name, ' not found in list:', cnst_name(:) call endrun end function cnst_get_type_byname function cnst_read_iv(m) integer, intent(in) :: m logical :: cnst_read_iv cnst_read_iv = read_init_vals(m) end function cnst_read_iv subroutine cnst_chk_dim integer i,m if (padv /= pcnst) then write(iulog,*)'CNST_CHK_DIM: number of advected tracer ',padv, ' not equal to pcnst = ',pcnst call endrun () endif if (masterproc) then write(iulog,*) 'Advected constituent list:' do i = 1, pcnst write(iulog,'(i4,2x,a8,2x,a128,2x,a3)') i, cnst_name(i), cnst_longname(i), cnst_type(i) end do end if do m=1,pcnst apcnst (m) = trim(cnst_name(m)) bpcnst (m) = trim(cnst_name(m)) hadvnam (m) = 'HA' vadvnam (m) = 'VA' fixcnam (m) = 'DF' tendnam (m) = 'TE' ptendnam (m) = 'PTE' dmetendnam(m) = 'DME' tottnam (m) = 'TA' sflxnam(m) = 'SF' end do end subroutine cnst_chk_dim function cnst_cam_outfld(m) integer, intent(in) :: m logical :: cnst_cam_outfld cnst_cam_outfld = cam_outfld_(m) end function cnst_cam_outfld end module constituents