sfc_climo_gen  1.10.0
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 ('soil_color') ! soil color
75  default_value = float(4)
76  case ('vegetation_type') ! vegetation type
77  default_value = float(3)
78  case default
79  print*,'- FATAL ERROR IN ROUTINE SEARCH. UNIDENTIFIED FIELD : ', field
80  call mpi_abort(mpi_comm_world, 77, ierr)
81  end select
82 
83 !-----------------------------------------------------------------------
84 ! Perform search and replace.
85 !-----------------------------------------------------------------------
86 
87  allocate (field_save(idim,jdim))
88  field_save = field
89 
90  j_loop : do j = 1, jdim
91  i_loop : do i = 1, idim
92 
93  if (mask(i,j) == 1 .and. field_save(i,j) < -9999.0) then
94 
95  krad_loop : do krad = 1, 100
96 
97  istart = i - krad
98  iend = i + krad
99  jstart = j - krad
100  jend = j + krad
101 
102  jj_loop : do jj = jstart, jend
103  ii_loop : do ii = istart, iend
104 
105 !-----------------------------------------------------------------------
106 ! Search only along outer square.
107 !-----------------------------------------------------------------------
108 
109  if ((jj == jstart) .or. (jj == jend) .or. &
110  (ii == istart) .or. (ii == iend)) then
111 
112  if (jj < 1 .or. jj > jdim) cycle jj_loop
113  if (ii < 1 .or. ii > idim) cycle ii_loop
114 
115  if (mask(ii,jj) == 1 .and. field_save(ii,jj) > -9999.0) then
116  field(i,j) = field_save(ii,jj)
117 ! write(6,100) tile,i,j,ii,jj,field(i,j)
118  cycle i_loop
119  endif
120 
121  endif
122 
123  enddo ii_loop
124  enddo jj_loop
125 
126  enddo krad_loop
127 
128  field(i,j) = default_value ! Search failed. Use default value.
129 
130  write(6,101) tile,i,j,field(i,j)
131 
132  endif
133  enddo i_loop
134  enddo j_loop
135 
136  deallocate(field_save)
137 
138  100 format(1x,"- MISSING POINT TILE: ",i2," I/J: ",i5,i5," SET TO VALUE AT: ",i5,i5,". NEW VALUE IS: ",f8.3)
139  101 format(1x,"- MISSING POINT TILE: ",i2," I/J: ",i5,i5," SET TO DEFAULT VALUE OF: ",f8.3)
140 
141  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:24