-
Notifications
You must be signed in to change notification settings - Fork 390
Implement lapse-rate extrapolation for vertical interpolation (extrap_type == 2) #1413
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ module init_atm_vinterp | |
| ! | ||
| ! Purpose: | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val) | ||
| real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surface_val, sealev_val, ierr) | ||
|
|
||
| implicit none | ||
|
|
||
|
|
@@ -33,10 +33,12 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf | |
| integer, intent(in), optional :: extrap | ||
| real (kind=RKIND), intent(in), optional :: surface_val | ||
| real (kind=RKIND), intent(in), optional :: sealev_val | ||
| integer, intent(out), optional :: ierr ! error code: 0 = success, 1 = invalid extrapolation type | ||
|
|
||
| integer :: k, lm, lp | ||
| real (kind=RKIND) :: wm, wp | ||
| real (kind=RKIND) :: slope | ||
| real (kind=RKIND) :: lapse_rate | ||
|
|
||
| integer :: interp_order, extrap_type | ||
| real (kind=RKIND) :: surface, sealevel | ||
|
|
@@ -66,6 +68,11 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf | |
| sealevel = 201300.0 | ||
| end if | ||
|
|
||
| ! Initialize ierr to 0 (success) | ||
| if (present(ierr)) then | ||
| ierr = 0 | ||
| end if | ||
|
|
||
| ! | ||
| ! Extrapolation required | ||
| ! | ||
|
|
@@ -75,6 +82,13 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf | |
| else if (extrap_type == 1) then | ||
| slope = (zf(2,2) - zf(2,1)) / (zf(1,2) - zf(1,1)) | ||
| vertical_interp = zf(2,1) + slope * (target_z - zf(1,1)) | ||
| else if (extrap_type == 2) then | ||
| ! Lapse-rate extrapolation: calculate lapse rate from bottom two levels | ||
| lapse_rate = (zf(2,2) - zf(2,1)) / (zf(1,2) - zf(1,1)) | ||
| vertical_interp = zf(2,1) + lapse_rate * (target_z - zf(1,1)) | ||
|
Comment on lines
+85
to
+88
|
||
| else | ||
| vertical_interp = zf(2,1) | ||
| if (present(ierr)) ierr = 1 | ||
| end if | ||
| return | ||
| end if | ||
|
|
@@ -84,6 +98,13 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf | |
| else if (extrap_type == 1) then | ||
| slope = (zf(2,nz) - zf(2,nz-1)) / (zf(1,nz) - zf(1,nz-1)) | ||
| vertical_interp = zf(2,nz) + slope * (target_z - zf(1,nz)) | ||
| else if (extrap_type == 2) then | ||
| ! Lapse-rate extrapolation: calculate lapse rate from top two levels | ||
| lapse_rate = (zf(2,nz) - zf(2,nz-1)) / (zf(1,nz) - zf(1,nz-1)) | ||
| vertical_interp = zf(2,nz) + lapse_rate * (target_z - zf(1,nz)) | ||
|
Comment on lines
+101
to
+104
|
||
| else | ||
| vertical_interp = zf(2,nz) | ||
| if (present(ierr)) ierr = 1 | ||
| end if | ||
| return | ||
| end if | ||
|
|
@@ -109,3 +130,4 @@ real (kind=RKIND) function vertical_interp(target_z, nz, zf, order, extrap, surf | |
| end function vertical_interp | ||
|
|
||
| end module init_atm_vinterp | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
extrap_type == 2(lapse-rate) at the upper boundary, this change computeslapse_ratefrom the top two levels, which makes it effectively the same asextrap_type == 1linear extrapolation. In this same function, the lower-boundary lapse-rate branch uses a fixed 0.0065 K/m (line 6926), so the upper and lower implementations are now inconsistent. Please align the two (either both fixed-lapse-rate or both gradient-derived) and ensurelinearvslapse-rateremain meaningfully different options.