Skip to content

Commit

Permalink
split get_close to get_close_obs get_close_state
Browse files Browse the repository at this point in the history
The vertical conversion is difference for state vs obs.
see #404 (comment)
for note on the (no longer true) assumption in the old code that state elements
have already been vertically converted in get_state_meta data.
  • Loading branch information
hkershaw-brown committed Sep 8, 2023
1 parent d799b32 commit 17b0cfa
Showing 1 changed file with 45 additions and 33 deletions.
78 changes: 45 additions & 33 deletions models/wrf/model_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module model_mod
VERTISHEIGHT, VERTISLEVEL, VERTISPRESSURE, &
VERTISSURFACE, VERTISUNDEF, &
loc_get_close => get_close, get_location, &
query_location, is_vertical
query_location, is_vertical, vertical_localization_on

use utilities_mod, only : register_module, error_handler, &
E_ERR, E_MSG, &
Expand Down Expand Up @@ -644,19 +644,38 @@ end subroutine get_state_meta_data

!------------------------------------------------------------------
! obs have a type and qty
! observation type not taken in to account for wrf get close calulations
! observation type not taken in to account for wrf get close calculations
subroutine get_close_obs(gc, base_loc, base_type, locs, loc_qtys, loc_types, &
num_close, close_ind, dist, state_handle)

type(get_close_type), intent(in) :: gc
type(location_type), intent(inout) :: base_loc, locs(:)
integer, intent(in) :: base_type, loc_qtys(:), loc_types(:)
integer, intent(out) :: num_close, close_ind(:)
real(r8), optional, intent(out) :: dist(:)
type(ensemble_type), optional, intent(in) :: state_handle
type(get_close_type), intent(in) :: gc ! handle to a get_close structure
integer, intent(in) :: base_type ! observation TYPE
type(location_type), intent(inout) :: base_loc ! location of interest
type(location_type), intent(inout) :: locs(:) ! obs/state locations
integer, intent(in) :: loc_qtys(:) ! QTYS for obs
integer, intent(in) :: loc_types(:) ! types for obs
integer, intent(out) :: num_close ! how many are close
integer, intent(out) :: close_ind(:) ! indices into the locs array
real(r8), optional, intent(out) :: dist(:) ! distances in radians
type(ensemble_type), optional, intent(in) :: state_handle

character(len=*), parameter :: routine = 'get_close_obs'
logical :: fail

call convert_base_vertical(base_loc, fail)
if (fail) then
num_close = 0
return
endif

call loc_get_close(gc, base_loc, base_type, locs, loc_qtys, &
num_close, close_ind)

if (.not. present(dist)) return

call get_close(gc, base_loc, base_type, locs, loc_qtys, &
num_close, close_ind, dist, state_handle)
!call convert_vertical_obs()

!call calculate_distances()

end subroutine get_close_obs

Expand All @@ -673,26 +692,7 @@ subroutine get_close_state(gc, base_loc, base_type, locs, loc_qtys, loc_indx, &
real(r8), optional, intent(out) :: dist(:)
type(ensemble_type), optional, intent(in) :: state_handle

call get_close(gc, base_loc, base_type, locs, loc_qtys, &
num_close, close_ind, dist, state_handle)

end subroutine get_close_state

!------------------------------------------------------------------
subroutine get_close(gc, base_loc, base_type, locs, loc_qtys, &
num_close, close_ind, dist, ens_handle)

type(get_close_type), intent(in) :: gc ! handle to a get_close structure
integer, intent(in) :: base_type ! observation TYPE
type(location_type), intent(inout) :: base_loc ! location of interest
type(location_type), intent(inout) :: locs(:) ! obs/state locations
integer, intent(in) :: loc_qtys(:) ! QTYS for obs/state
integer, intent(out) :: num_close ! how many are close
integer, intent(out) :: close_ind(:) ! indices into the locs array
real(r8), optional, intent(out) :: dist(:) ! distances in radians
type(ensemble_type), optional, intent(in) :: ens_handle

character(len=*), parameter :: routine = 'get_close'
character(len=*), parameter :: routine = 'get_close_state'
logical :: fail

call convert_base_vertical(base_loc, fail)
Expand All @@ -706,11 +706,12 @@ subroutine get_close(gc, base_loc, base_type, locs, loc_qtys, &

if (.not. present(dist)) return

!call convert_vertical()
!call convert_vertical_state()

!call calculate_distances()

end subroutine get_close

end subroutine get_close_state


!------------------------------------------------------------------
Expand Down Expand Up @@ -1731,7 +1732,18 @@ subroutine convert_base_vertical(base_loc, fail)
type(location_type), intent(inout) :: base_loc
logical, intent(out) :: fail

fail = .true.
integer :: base_vertical_coord

if (.not. vertical_localization_on() ) then
fail = .false.
return
endif

base_vertical_coord = nint(query_location(base_loc))
if (base_vertical_coord /= vert_localization_coord) then


endif

end subroutine convert_base_vertical

Expand Down

0 comments on commit 17b0cfa

Please sign in to comment.