sfc_climo_gen  1.4.0
 All Data Structures Files Functions Variables
search.f90
Go to the documentation of this file.
1 
5 
23  subroutine search (field, mask, idim, jdim, tile, field_name)
24 
25  use mpi
26  use esmf
27 
28  implicit none
29 
30  character(len=*) :: field_name
31 
32  integer, intent(in) :: idim, jdim, tile
33  integer(esmf_kind_i4), intent(in) :: mask(idim,jdim)
34 
35  real(esmf_kind_r4), intent(inout) :: field(idim,jdim)
36 
37  integer :: i, j, krad, ii, jj
38  integer :: istart, iend
39  integer :: jstart, jend
40  integer :: ierr
41 
42  real :: default_value
43  real(esmf_kind_r4), allocatable :: field_save(:,:)
44 
45 !-----------------------------------------------------------------------
46 ! Set default value.
47 !-----------------------------------------------------------------------
48 
49  select case (field_name)
50  case ('substrate_temperature') ! soil substrate_temperature
51  default_value = 280.0
52  case ('vegetation_greenness') ! vegetation greenness
53  default_value = 0.5
54  case ('maximum_snow_albedo') ! maximum snow albedo
55  default_value = 0.5
56  case ('leaf_area_index') ! leaf area index
57  default_value = 1.0
58  case ('visible_black_sky_albedo') ! visible black sky albedo
59  default_value = 0.1
60  case ('visible_white_sky_albedo') ! visible white sky albedo
61  default_value = 0.1
62  case ('near_IR_black_sky_albedo') ! near IR black sky albedo
63  default_value = 0.2
64  case ('near_IR_white_sky_albedo') ! near IR white sky albedo
65  default_value = 0.2
66  case ('facsf') ! facsf
67  default_value = 0.5
68  case ('facwf') ! facwf
69  default_value = 0.5
70  case ('slope_type') ! slope type
71  default_value = float(1)
72  case ('soil_type') ! soil type
73  default_value = float(2)
74  case ('vegetation_type') ! vegetation type
75  default_value = float(3)
76  case default
77  print*,'- FATAL ERROR IN ROUTINE SEARCH. UNIDENTIFIED FIELD : ', field
78  call mpi_abort(mpi_comm_world, 77, ierr)
79  end select
80 
81 !-----------------------------------------------------------------------
82 ! Perform search and replace.
83 !-----------------------------------------------------------------------
84 
85  allocate (field_save(idim,jdim))
86  field_save = field
87 
88  j_loop : do j = 1, jdim
89  i_loop : do i = 1, idim
90 
91  if (mask(i,j) == 1 .and. field_save(i,j) < -9999.0) then
92 
93  krad_loop : do krad = 1, 100
94 
95  istart = i - krad
96  iend = i + krad
97  jstart = j - krad
98  jend = j + krad
99 
100  jj_loop : do jj = jstart, jend
101  ii_loop : do ii = istart, iend
102 
103 !-----------------------------------------------------------------------
104 ! Search only along outer square.
105 !-----------------------------------------------------------------------
106 
107  if ((jj == jstart) .or. (jj == jend) .or. &
108  (ii == istart) .or. (ii == iend)) then
109 
110  if (jj < 1 .or. jj > jdim) cycle jj_loop
111  if (ii < 1 .or. ii > idim) cycle ii_loop
112 
113  if (mask(ii,jj) == 1 .and. field_save(ii,jj) > -9999.0) then
114  field(i,j) = field_save(ii,jj)
115 ! write(6,100) tile,i,j,ii,jj,field(i,j)
116  cycle i_loop
117  endif
118 
119  endif
120 
121  enddo ii_loop
122  enddo jj_loop
123 
124  enddo krad_loop
125 
126  field(i,j) = default_value ! Search failed. Use default value.
127 
128  write(6,101) tile,i,j,field(i,j)
129 
130  endif
131  enddo i_loop
132  enddo j_loop
133 
134  deallocate(field_save)
135 
136  100 format(1x,"- MISSING POINT TILE: ",i2," I/J: ",i5,i5," SET TO VALUE AT: ",i5,i5,". NEW VALUE IS: ",f8.3)
137  101 format(1x,"- MISSING POINT TILE: ",i2," I/J: ",i5,i5," SET TO DEFAULT VALUE OF: ",f8.3)
138 
139  end subroutine search
subroutine search(field, mask, idim, jdim, tile, field_name)
Replace undefined values on the model grid with a valid value at a nearby neighbor.
Definition: search.f90:23