da_ll_to_xy.inc

References to this file elsewhere.
1 subroutine da_ll_to_xy (info, loc, xp, &
2                         outside, outside_all)
3 
4    !-----------------------------------------------------------------------
5    ! Purpose: TBD
6    !-----------------------------------------------------------------------
7 
8    ! This routine converts (lat, lon) into (x,y) coordinates
9 
10    implicit none
11 
12    type(info_type),       intent(in)    :: info
13    type(model_loc_type),  intent(inout) :: loc
14    type(xpose_type),      intent(in)    :: xp           !Domain decomposition vars.
15    logical      ,         intent(out)   :: outside      !wrt local domain
16    logical, optional,     intent(out)   :: outside_all  !wrt all domains
17 
18    outside = .false.
19    loc % x   = -1.0
20    loc % y   = -1.0
21    
22    ! get the (x, y) coordinates
23 
24    if (fg_format == fg_format_wrf) then
25       call da_latlon_to_ij(map_info, info%lat, info%lon, loc%x, loc%y)
26    else if (fg_format == fg_format_kma_global) then
27       call da_global_ll_to_xy (info%lat, info%lon, loc%x, loc%y)
28    else
29       call da_llxy (info%lat, info%lon, loc%x, loc%y)
30    end if
31 
32    call da_togrid (loc%x, xp%its-2, xp%ite+2, loc%i, loc%dx, loc%dxm)!
33 
34    call da_togrid (loc%y, xp%jts-2, xp%jte+2, loc%j, loc%dy, loc%dym)
35 
36    ! refactor to remove this ugly duplication later
37    if (present(outside_all)) then
38       outside_all = .false.
39       ! Do not check for global options 
40       if (.not. global) then 
41          if ((int(loc%x) < xp%ids) .or. (int(loc%x) >= xp%ide) .or. &
42             (int(loc%y) < xp%jds) .or. (int(loc%y) >= xp%jde)) then
43             outside_all = .true. 
44             outside = .true. 
45             return
46          end if
47          if (def_sub_domain) then
48             if (x_start_sub_domain > loc%x .or. y_start_sub_domain > loc%y .or. &
49                 x_end_sub_domain   < loc%x .or. y_end_sub_domain   < loc%y) then
50                outside_all = .true.
51             outside = .true. 
52             return
53             end if
54          end if
55       end if
56    end if
57 
58    if (fg_format == fg_format_kma_global) then
59       if ((loc%j < xp%jts-1) .or. (loc%j > xp%jte)) then
60          outside = .true.
61          return
62       end if
63 
64       if (loc%j == xp%jde) then
65          loc%j = loc%j - 1
66          loc%dy  = 1.0
67          loc%dym = 0.0
68       end if
69 
70       return
71    end if
72 
73    ! Check for edge of domain:
74 
75    if ((loc%i < xp%ids) .or. (loc%i >= xp%ide) .or. &
76       (loc%j < xp%jds) .or. (loc%j >= xp%jde)) then
77       outside     = .true. 
78       return
79    end if
80 
81    ! JRB hack
82    if ((loc%i < xp%its-1) .or. (loc%i > xp%ite) .or. &
83       (loc%j < xp%jts-1) .or. (loc%j > xp%jte)) then
84    ! if ((loc%i < xp%its-1) .or. (loc%i >= xp%ite) .or. &
85    !     (loc%j < xp%jts-1) .or. (loc%j >= xp%jte)) then
86       outside = .true.
87       return
88 
89       if (def_sub_domain) then
90          if (x_start_sub_domain > loc%x .or. y_start_sub_domain > loc%y .or. &
91              x_end_sub_domain   < loc%x .or. y_end_sub_domain   < loc%y) then
92              outside = .true.
93          end if
94       end if
95    end if
96 
97 end subroutine da_ll_to_xy
98 
99