Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constituent bugfixes #608

Merged
merged 10 commits into from
Nov 5, 2024
39 changes: 31 additions & 8 deletions src/ccpp_constituent_prop_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ subroutine copyConstituent(outConst, inConst)
outConst%molar_mass_val = inConst%molar_mass_val
outConst%thermo_active = inConst%thermo_active
outConst%water_species = inConst%water_species
outConst%var_units = inConst%var_units
end subroutine copyConstituent

!#######################################################################
Expand Down Expand Up @@ -371,7 +372,8 @@ end function ccp_is_instantiated
!#######################################################################

subroutine ccp_instantiate(this, std_name, long_name, units, vertical_dim, &
advected, default_value, min_value, molar_mass, errcode, errmsg)
advected, default_value, min_value, molar_mass, water_species, &
mixing_ratio_type, errcode, errmsg)
! Initialize all fields in <this>

! Dummy arguments
Expand All @@ -384,6 +386,8 @@ subroutine ccp_instantiate(this, std_name, long_name, units, vertical_dim, &
real(kind_phys), optional, intent(in) :: default_value
real(kind_phys), optional, intent(in) :: min_value
real(kind_phys), optional, intent(in) :: molar_mass
logical, optional, intent(in) :: water_species
character(len=*), optional, intent(in) :: mixing_ratio_type
integer, intent(out) :: errcode
character(len=*), intent(out) :: errmsg

Expand Down Expand Up @@ -414,6 +418,9 @@ subroutine ccp_instantiate(this, std_name, long_name, units, vertical_dim, &
if (present(molar_mass)) then
this%molar_mass_val = molar_mass
end if
if (present(water_species)) then
this%water_species = water_species
end if
end if
if (errcode == 0) then
if (index(this%var_std_name, "volume_mixing_ratio") > 0) then
Expand All @@ -426,14 +433,29 @@ subroutine ccp_instantiate(this, std_name, long_name, units, vertical_dim, &
end if
if (errcode == 0) then
! Determine if this mixing ratio is dry, moist, or "wet".
if (index(this%var_std_name, "wrt_moist_air") > 0) then
this%const_water = moist_mixing_ratio
else if (this%var_std_name == "specific_humidity") then
this%const_water = moist_mixing_ratio
else if (this%var_std_name == "wrt_total_mass") then
this%const_water = wet_mixing_ratio
! If a type was provided, use that (if it's valid)
if (present(mixing_ratio_type)) then
if (trim(mixing_ratio_type) == 'wet') then
this%const_water = wet_mixing_ratio
else if (trim(mixing_ratio_type) == 'moist') then
this%const_water = moist_mixing_ratio
else if (trim(mixing_ratio_type) == 'dry') then
this%const_water = dry_mixing_ratio
else
errcode = 1
write(errmsg, *) 'ccp_instantiate: invalid mixing ratio type. ', &
'Must be one of: "wet", "moist", or "dry". Got: "', &
trim(mixing_ratio_type), '"'
end if
else
this%const_water = dry_mixing_ratio
! Otherwise, parse it from the standard name
if (index(this%var_std_name, "wrt_moist_air_and_condensed_water") > 0) then
this%const_water = wet_mixing_ratio
else if (index(this%var_std_name, "wrt_moist_air") > 0) then
this%const_water = moist_mixing_ratio
else
this%const_water = dry_mixing_ratio
end if
end if
end if
if (errcode /= 0) then
Expand Down Expand Up @@ -740,6 +762,7 @@ subroutine ccp_is_equivalent(this, oconst, equiv, errcode, errmsg)
equiv = (trim(this%var_std_name) == trim(oconst%var_std_name)) .and. &
(trim(this%var_long_name) == trim(oconst%var_long_name)) .and. &
(trim(this%vert_dim) == trim(oconst%vert_dim)) .and. &
(trim(this%var_units) == trim(oconst%var_units)) .and. &
(this%advected .eqv. oconst%advected) .and. &
(this%const_default_value == oconst%const_default_value) .and. &
(this%min_val == oconst%min_val) .and. &
Expand Down
Loading