00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 subroutine psmile_srch_nneigh_gauss2_real (grid_id, nn_srch, &
00011 arrays, search_mode, nref_3d, &
00012 sin_values_lon, cos_values_lon, &
00013 sin_values_lat, cos_values_lat, &
00014 grid_valid_shape, &
00015 z_coords, coords_shape, &
00016 neighbors_3d, nloc, num_neigh, &
00017 sin_search, cos_search, z_search, &
00018 dist_real, dim1, extra_search, jbeg, jend, &
00019 mask_array, mask_shape, mask_available, &
00020 tol, ierror)
00021
00022
00023
00024 use PRISM_constants
00025
00026 use PSMILe
00027
00028 implicit none
00029
00030
00031
00032 Integer, Intent (In) :: grid_id
00033
00034
00035
00036
00037 Type (Extra_search_nn), Intent (In) :: nn_srch
00038
00039
00040
00041 Type (Extra_search_real) :: arrays
00042
00043
00044
00045 Integer :: nref_3d
00046
00047
00048
00049 Integer, Intent (In) :: search_mode
00050
00051
00052
00053
00054
00055
00056 Integer, Intent (In) :: grid_valid_shape (2, ndim_3d)
00057
00058
00059
00060 Real, Intent (In) :: sin_values_lon (grid_valid_shape(1,1):
00061 grid_valid_shape(2,1))
00062 Real, Intent (In) :: sin_values_lat (grid_valid_shape(1,1):
00063 grid_valid_shape(2,1))
00064
00065
00066
00067 Real, Intent (In) :: cos_values_lon (grid_valid_shape(1,1):
00068 grid_valid_shape(2,1))
00069 Real, Intent (In) :: cos_values_lat (grid_valid_shape(1,1):
00070 grid_valid_shape(2,1))
00071
00072
00073
00074 Integer, Intent (In) :: coords_shape (2, ndim_3d)
00075
00076
00077
00078 Real, Intent (In) :: z_coords(coords_shape(1,3):
00079 coords_shape(2,3))
00080
00081
00082 Integer, Intent (In) :: nloc
00083
00084
00085
00086
00087 Integer, Intent (In) :: num_neigh
00088
00089
00090
00091
00092
00093 Integer, Intent (In) :: jbeg, jend
00094
00095
00096
00097 Real, Intent (In) :: sin_search (jbeg:jend, 2)
00098
00099
00100
00101
00102 Real, Intent (In) :: cos_search (jbeg:jend, 2)
00103
00104
00105
00106
00107 Real, Intent (In) :: z_search (jbeg:jend)
00108
00109
00110
00111
00112 Integer, Intent (In) :: dim1 (2)
00113
00114
00115
00116 Type (Extra_search_info), Intent(InOut) :: extra_search
00117
00118
00119
00120
00121 Integer, Intent (In) :: mask_shape (2, ndim_3d)
00122
00123
00124
00125 Logical, Intent (In) :: mask_array (mask_shape (1,1):
00126 mask_shape (2,1),
00127 mask_shape (1,2):
00128 mask_shape (2,2),
00129 mask_shape (1,3):
00130 mask_shape (2,3))
00131
00132
00133 Logical, Intent (In) :: mask_available
00134
00135
00136
00137
00138
00139 Real, Intent (In) :: tol
00140
00141
00142
00143
00144
00145 Real, Intent (InOut) :: dist_real (dim1(1):dim1(2), num_neigh)
00146
00147
00148
00149 Integer, Intent (Out) :: neighbors_3d (ndim_3d, nloc, num_neigh)
00150
00151
00152
00153
00154
00155
00156 Integer, Intent (Out) :: ierror
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 Real, Parameter :: real_earth = 6400000.0
00167
00168 Real, Parameter :: acosp1 = 1.0
00169 Real, Parameter :: acosm1 = -1.0
00170
00171 Integer, Parameter :: lon = 1
00172 Integer, Parameter :: lat = 2
00173
00174
00175
00176 Real :: dist ( (grid_valid_shape(2,1)-grid_valid_shape(1,1)+1) )
00177
00178 Real :: val, fac
00179
00180 Integer, Pointer :: indices (:)
00181
00182 Integer :: leni
00183 Integer :: i, n
00184 Integer :: ii, kk
00185 Integer :: ind, jind
00186 Integer :: iloc(1)
00187 #ifdef DEBUGX
00188 Integer :: m1, m2, m3, m4
00189 #endif
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 #ifdef VERBOSE
00209 print 9990, trim(ch_id)
00210
00211 call psmile_flushstd
00212 #endif /* VERBOSE */
00213
00214 ierror = 0
00215 indices => extra_search%indices
00216
00217
00218
00219
00220
00221
00222
00223 leni = grid_valid_shape(2,1) - grid_valid_shape(1,1) + 1
00224
00225 do jind = jbeg, jend
00226
00227
00228
00229 fac = real_earth + z_search (jind)
00230
00231 do i = grid_valid_shape(1,1), grid_valid_shape(2,1)
00232
00233 val = sin_values_lat(i) * sin_search(jind, lat) &
00234 + cos_values_lat(i) * cos_search(jind, lat) &
00235 * (cos_values_lon(i) * cos_search(jind, lon) &
00236 + sin_values_lon(i) * sin_search(jind, lon))
00237
00238 val = min (acosp1, val)
00239 val = max (acosm1, val)
00240
00241 if ( mask_available ) then
00242 if ( mask_array(i,1,1) ) then
00243 dist ( i-grid_valid_shape(1,1) + 1) = fac * acos (val)
00244 else
00245 dist ( i-grid_valid_shape(1,1) + 1) = huge(fac)
00246 endif
00247 else
00248 dist ( i-grid_valid_shape(1,1) + 1) = fac * acos (val)
00249 endif
00250
00251 enddo
00252
00253
00254
00255 kk = 1
00256
00257 ind = indices(jind)
00258
00259 do n = 1, num_neigh
00260
00261 iloc(:) = minloc(dist)
00262
00263 #ifdef MINLOCFIX
00264 if (iloc(1) == 0) iloc(1) = 1
00265 #endif /* MINLOCFIX */
00266 ii = iloc(1)
00267
00268 neighbors_3d (1, ind, n) = ii
00269 neighbors_3d (2, ind, n) = 1
00270 neighbors_3d (3, ind, n) = kk
00271
00272 #ifdef DEBUGX
00273 print *, ' Latitude '
00274 print *, asin(sin_search(jind, lat)) / real_deg2rad
00275 print *, ' => ', asin(sin_values_lat(ii)) / real_deg2rad
00276 print *, ' Longitude '
00277 print *, acos(cos_search(jind, lon)) / real_deg2rad, &
00278 asin(sin_search(jind, lon)) / real_deg2rad
00279 print *, ' => ', acos(cos_values_lon(ii)) / real_deg2rad , &
00280 asin(sin_values_lon(ii)) / real_deg2rad
00281 print *, ' found neighbour ', ind, neighbors_3d (1, ind, n)
00282
00283 m1 = 1
00284 m3 = 0
00285 do m2 = grid_valid_shape(1,1), neighbors_3d (1, ind, n)
00286 m4 = Grids(grid_id)%partition(m1,1)
00287 m3 = m3 + 1
00288 if ( m3 == Grids(grid_id)%extent(m1,1) ) then
00289 m1 = m1 + 1
00290 m3 = 0
00291 endif
00292 enddo
00293 print *, ' global index for found neighbour ', ind, m4+m3
00294 #endif
00295 if (associated(extra_search%dist_real)) &
00296 extra_search%dist_real(jind,n) = dist(iloc(1))
00297
00298 enddo
00299
00300 end do
00301
00302
00303
00304
00305
00306 #ifdef VERBOSE
00307 print 9980, trim(ch_id), ierror
00308
00309 call psmile_flushstd
00310 #endif /* VERBOSE */
00311
00312
00313
00314 9990 format (1x, a, ': psmile_srch_nneigh_gauss2_real')
00315 9980 format (1x, a, ': psmile_srch_nneigh_gauss2_real: eof, ierror =', i3)
00316
00317 end subroutine PSMILe_srch_nneigh_gauss2_real