Skip to content

Commit 88ae401

Browse files
committed
Merge branch 'init_atmosphere/consolidate_vertical_interp' into develop (PR #1429)
This merge consolidates the multiple definitions of function vertical_interp, found in modules mpas_init_atm_cases and init_atm_vinterp in the init_atmosphere core and introduces one uniform definition in the init_atm_vinterp module. * init_atmosphere/consolidate_vertical_interp: Consolidating multiple definitions of vertical_interp into init_atm_vinterp
2 parents 08eae14 + 0e77221 commit 88ae401

2 files changed

Lines changed: 16 additions & 99 deletions

File tree

src/core_init_atmosphere/mpas_init_atm_cases.F

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module init_atm_cases
1616
use atm_advection
1717
use mpas_RBF_interpolation
1818
use mpas_vector_reconstruction
19+
use init_atm_vinterp, only: vertical_interp
1920
use mpas_timer
2021
use mpas_init_atm_static
2122
use mpas_init_atm_surface
@@ -7595,101 +7596,6 @@ integer function nearest_edge(target_lat, target_lon, &
75957596
end function nearest_edge
75967597

75977598

7598-
real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val, ierr)
7599-
7600-
implicit none
7601-
7602-
real (kind=RKIND), intent(in) :: target_z
7603-
integer, intent(in) :: nz
7604-
real (kind=RKIND), dimension(2,nz), intent(in) :: zf ! zf(1,:) is column of vertical coordinate values, zf(2,:) is column of field values
7605-
integer, intent(in), optional :: order
7606-
integer, intent(in), optional :: extrap ! can take values 0 = constant, 1 = linear (default), 2 = lapse-rate
7607-
real (kind=RKIND), intent(in), optional :: surface_val
7608-
real (kind=RKIND), intent(in), optional :: sealev_val
7609-
integer, intent(out), optional :: ierr
7610-
7611-
integer :: k, lm, lp
7612-
real (kind=RKIND) :: wm, wp
7613-
real (kind=RKIND) :: slope
7614-
7615-
integer :: interp_order, extrap_type
7616-
real (kind=RKIND) :: surface, sealevel
7617-
7618-
if (present(ierr)) ierr = 0
7619-
7620-
if (present(order)) then
7621-
interp_order = order
7622-
else
7623-
interp_order = 2
7624-
end if
7625-
7626-
if (present(extrap)) then
7627-
extrap_type = extrap
7628-
else
7629-
extrap_type = 1
7630-
end if
7631-
7632-
if (present(surface_val)) then
7633-
surface = surface_val
7634-
else
7635-
surface = 200100.0
7636-
end if
7637-
7638-
if (present(sealev_val)) then
7639-
sealevel = sealev_val
7640-
else
7641-
sealevel = 201300.0
7642-
end if
7643-
7644-
!
7645-
! Extrapolation required
7646-
!
7647-
if (target_z < zf(1,1)) then
7648-
if (extrap_type == 0) then
7649-
vertical_interp = zf(2,1)
7650-
else if (extrap_type == 1) then
7651-
slope = (zf(2,2) - zf(2,1)) / (zf(1,2) - zf(1,1))
7652-
vertical_interp = zf(2,1) + slope * (target_z - zf(1,1))
7653-
else if (extrap_type == 2) then
7654-
vertical_interp = zf(2,1) - (target_z - zf(1,1))*0.0065
7655-
end if
7656-
return
7657-
end if
7658-
if (target_z >= zf(1,nz)) then
7659-
if (extrap_type == 0) then
7660-
vertical_interp = zf(2,nz)
7661-
else if (extrap_type == 1) then
7662-
slope = (zf(2,nz) - zf(2,nz-1)) / (zf(1,nz) - zf(1,nz-1))
7663-
vertical_interp = zf(2,nz) + slope * (target_z - zf(1,nz))
7664-
else if (extrap_type == 2) then
7665-
call mpas_log_write('extrap_type == 2 not implemented for target_z >= zf(1,nz)', messageType=MPAS_LOG_ERR)
7666-
if (present(ierr)) ierr = 1
7667-
return
7668-
end if
7669-
return
7670-
end if
7671-
7672-
7673-
!
7674-
! No extrapolation required
7675-
!
7676-
do k=1,nz-1
7677-
if (target_z >= zf(1,k) .and. target_z < zf(1,k+1)) then
7678-
lm = k
7679-
lp = k+1
7680-
wm = (zf(1,k+1) - target_z) / (zf(1,k+1) - zf(1,k))
7681-
wp = (target_z - zf(1,k)) / (zf(1,k+1) - zf(1,k))
7682-
exit
7683-
end if
7684-
end do
7685-
7686-
vertical_interp = wm*zf(2,lm) + wp*zf(2,lp)
7687-
7688-
return
7689-
7690-
end function vertical_interp
7691-
7692-
76937599
!----------------------------------------------------------------------------------------------------------
76947600

76957601
real (kind=RKIND) function env_qv( temperature, pressure, rh_max )

src/core_init_atmosphere/mpas_init_atm_vinterp.F

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,31 @@ module init_atm_vinterp
2222
!
2323
! Purpose:
2424
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25-
real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val)
25+
real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val, ierr)
26+
27+
use mpas_log, only : mpas_log_write
28+
use mpas_derived_types, only : MPAS_LOG_ERR
2629

2730
implicit none
2831

2932
real (kind=RKIND), intent(in) :: target_z
3033
integer, intent(in) :: nz
3134
real (kind=RKIND), dimension(2,nz), intent(in) :: zf ! zf(1,:) is column of vertical coordinate values, zf(2,:) is column of field values
3235
integer, intent(in), optional :: order
33-
integer, intent(in), optional :: extrap
36+
integer, intent(in), optional :: extrap ! can take values 0 = constant, 1 = linear (default), 2 = lapse-rate
3437
real (kind=RKIND), intent(in), optional :: surface_val
3538
real (kind=RKIND), intent(in), optional :: sealev_val
36-
39+
integer, intent(out), optional :: ierr
40+
3741
integer :: k, lm, lp
3842
real (kind=RKIND) :: wm, wp
3943
real (kind=RKIND) :: slope
4044

4145
integer :: interp_order, extrap_type
4246
real (kind=RKIND) :: surface, sealevel
4347

44-
48+
if (present(ierr)) ierr = 0
49+
4550
if (present(order)) then
4651
interp_order = order
4752
else
@@ -75,6 +80,8 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf
7580
else if (extrap_type == 1) then
7681
slope = (zf(2,2) - zf(2,1)) / (zf(1,2) - zf(1,1))
7782
vertical_interp = zf(2,1) + slope * (target_z - zf(1,1))
83+
else if (extrap_type == 2) then
84+
vertical_interp = zf(2,1) - (target_z - zf(1,1))*0.0065
7885
end if
7986
return
8087
end if
@@ -84,6 +91,10 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf
8491
else if (extrap_type == 1) then
8592
slope = (zf(2,nz) - zf(2,nz-1)) / (zf(1,nz) - zf(1,nz-1))
8693
vertical_interp = zf(2,nz) + slope * (target_z - zf(1,nz))
94+
else if (extrap_type == 2) then
95+
call mpas_log_write('extrap_type == 2 not implemented for target_z >= zf(1,nz)', messageType=MPAS_LOG_ERR)
96+
if (present(ierr)) ierr = 1
97+
return
8798
end if
8899
return
89100
end if

0 commit comments

Comments
 (0)