FV3 Bundle
gnssro_mod_grids.F90
Go to the documentation of this file.
2 
3 use kinds, only: kind_real
4 use gnssro_mod_constants, only: one
5 
6 public :: get_coordinate_value
7 
8 private
9 
10 contains
11 
12 subroutine get_coordinate_value(fin, fout, x, nx, flag)
13 !
14 ! Get grid coordinates from monotonically increasing or decreasing points
15 ! adapted GSI subprogram: grdcrd1
16 !
17  integer, intent(in) :: nx !number of reference grid point
18  real(kind_real), intent(in) :: x(nx) !grid values
19  real(kind_real), intent(in) :: fin !input point
20  character(10), intent(in) :: flag !"increasing" or "decreasing"
21  real(kind_real), intent(out) :: fout !input point
22  integer :: ix, isrchf
23 
24 ! Treat "normal" case in which nx>1
25  if(nx>1) then
26  if (flag == "increasing") then
27 
28  if(fin<=x(1)) then
29  ix=1
30  else
31  call searcharray(nx-1,x,fin,flag,isrchf)
32  ix=isrchf-1
33  end if
34  if(ix==nx) ix=ix-1
35 
36  else if (flag=="decreasing") then
37 
38  if(fin>=x(1)) then
39  ix=1
40  else
41  call searcharray(nx-1,x,fin,flag,isrchf)
42  ix=isrchf-1
43  end if
44  end if
45  fout=float(ix)+(fin-x(ix))/(x(ix+1)-x(ix))
46 
47 ! Treat special case of nx=1
48  elseif (nx==1) then
49  fout = one
50  endif
51 
52  return
53 end subroutine get_coordinate_value
54 
55 
56 subroutine searcharray(nx,x,y,flag,isrchf)
57  integer, intent(in) :: nx !number of input points
58  character(10), intent(in) :: flag !"increasing" or "decreasing"
59  real(kind_real),intent(in) :: y !target values
60  real(kind_real),intent(in) :: x(nx) !grid value
61  integer, intent(out) :: isrchf !array index of input grid value near target value
62  integer :: k
63 
64  if(flag=="increasing") then
65  do k=1,nx
66  if(y<=x(k)) then
67  isrchf=k
68  return
69  end if
70  end do
71  else
72  do k=1,nx
73  if(y>=x(k)) then
74  isrchf=k
75  return
76  end if
77  end do
78  end if
79 
80  isrchf=nx+1
81  if(nx<=0) isrchf=0
82 
83  return
84 end subroutine searcharray
85 
86 end module gnssro_mod_grids
subroutine searcharray(nx, x, y, flag, isrchf)
subroutine, public get_coordinate_value(fin, fout, x, nx, flag)
real(fp), parameter, public one
integer, parameter, public kind_real