1 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/tools_samp.fypp"
2 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/../instrumentation.fypp" 1
3 # 1 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/../subr_list.fypp" 1
12 # 726 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/../subr_list.fypp"
13 # 2 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/../instrumentation.fypp" 2
22 # 112 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/../instrumentation.fypp"
23 # 2 "/Users/miesch/JEDI/code/working_copy/public/fv3-bundle/saber/src/saber/bump/tools_samp.fypp" 2
33 use atlas_module,
only: atlas_structuredgrid
34 use fckit_mpi_module,
only: fckit_mpi_sum,fckit_mpi_status
67 subroutine samp_initialize_sampling(mpl,rng,area,n_loc,lon_loc,lat_loc,mask_loc,rh_loc,loc_to_glb,ntry,nrep,ns2_glb,sam2_glb, &
68 & fast,verbosity,n_uni,uni_to_loc,mesh_uni,tree_uni,inside_type)
75 real(kind_real),
intent(in) :: area
76 integer,
intent(in) :: n_loc
77 real(kind_real),
intent(in) :: lon_loc(n_loc)
78 real(kind_real),
intent(in) :: lat_loc(n_loc)
79 logical,
intent(in) :: mask_loc(n_loc)
80 real(kind_real),
intent(in) :: rh_loc(n_loc)
81 integer,
intent(in) :: loc_to_glb(n_loc)
82 integer,
intent(in) :: ntry
83 integer,
intent(in) :: nrep
84 integer,
intent(in) :: ns2_glb
85 integer,
intent(out) :: sam2_glb(ns2_glb)
86 logical,
intent(in),
optional :: fast
87 logical,
intent(in),
optional :: verbosity
88 integer,
intent(in),
optional :: n_uni
89 integer,
intent(in),
optional :: uni_to_loc(:)
90 type(
mesh_type),
intent(in),
optional :: mesh_uni
91 type(
tree_type),
intent(in),
optional :: tree_uni
92 character(len=*),
intent(in),
optional :: inside_type
95 integer :: n_glb,n_loc_eff,n_glb_eff,i_glb,i_loc,is2_glb,ns1_glb_eff
96 integer,
allocatable :: sam1_glb_eff(:),order(:)
97 real(kind_real),
allocatable :: hash_glb(:),hash_loc(:)
98 real(kind_real),
allocatable :: lon1_glb_eff(:),lat1_glb_eff(:),rh1_glb_eff(:)
99 real(kind_real),
allocatable :: list(:)
100 logical :: lfast,lverbosity
101 logical,
allocatable :: mask_glb(:)
112 if (
present(fast)) lfast = fast
113 if (
present(verbosity)) lverbosity = verbosity
116 call mpl%f_comm%allreduce(n_loc,n_glb,fckit_mpi_sum())
119 n_loc_eff = count(mask_loc)
120 call mpl%f_comm%allreduce(n_loc_eff,n_glb_eff,fckit_mpi_sum())
123 if (n_glb_eff==0)
then
124 call mpl%abort(
'samp_initialize_sampling',
'empty mask in initialize sampling')
125 elseif (n_glb_eff<ns2_glb)
then
126 call mpl%abort(
'samp_initialize_sampling',
'ns2_glb greater than n_glb_eff in initialize_sampling')
127 elseif (n_glb_eff==ns2_glb)
then
128 write(mpl%info,
'(a)')
' all points are used'
129 if (lverbosity)
call mpl%flush
132 allocate(hash_loc(n_loc))
134 allocate(hash_glb(n_glb))
135 allocate(mask_glb(n_glb))
136 allocate(list(ns2_glb))
137 allocate(order(ns2_glb))
139 allocate(hash_glb(0))
140 allocate(mask_glb(0))
145 hash_loc(i_loc) =
lonlathash(lon_loc(i_loc),lat_loc(i_loc))
149 call mpl%loc_to_glb(n_loc,n_glb,loc_to_glb,hash_loc,hash_glb)
150 call mpl%loc_to_glb(n_loc,n_glb,loc_to_glb,mask_loc,mask_glb)
156 if (mask_glb(i_glb))
then
158 sam2_glb(is2_glb) = i_glb
159 list(is2_glb) = hash_glb(i_glb)
164 call qsort(ns2_glb,list,order)
167 sam2_glb = sam2_glb(order)
180 if (
present(n_uni).and.
present(uni_to_loc).and.
present(mesh_uni).and.
present(tree_uni).and.
present(inside_type))
then
181 call initialize_sampling_local(mpl,area,n_loc,n_loc_eff,n_glb_eff,lon_loc,lat_loc,mask_loc,rh_loc,loc_to_glb,ns2_glb, &
182 & ns1_glb_eff,lon1_glb_eff,lat1_glb_eff,rh1_glb_eff,sam1_glb_eff,lverbosity,n_uni,uni_to_loc,mesh_uni,tree_uni,inside_type)
184 call initialize_sampling_local(mpl,area,n_loc,n_loc_eff,n_glb_eff,lon_loc,lat_loc,mask_loc,rh_loc,loc_to_glb,ns2_glb, &
185 & ns1_glb_eff,lon1_glb_eff,lat1_glb_eff,rh1_glb_eff,sam1_glb_eff,lverbosity)
191 & ntry,nrep,ns2_glb,sam2_glb,lfast,lverbosity)
194 deallocate(lon1_glb_eff)
195 deallocate(lat1_glb_eff)
196 deallocate(rh1_glb_eff)
197 deallocate(sam1_glb_eff)
202 call mpl%f_comm%broadcast(sam2_glb,mpl%rootproc-1)
213 subroutine samp_initialize_sampling_local(mpl,area,n_loc,n_loc_eff,n_glb_eff,lon_loc,lat_loc,mask_loc,rh_loc,loc_to_glb,ns2_glb, &
214 & ns1_glb_eff,lon1_glb_eff,lat1_glb_eff,rh1_glb_eff,sam1_glb_eff,verbosity,n_uni,uni_to_loc,mesh_uni,tree_uni,inside_type)
220 real(kind_real),
intent(in) :: area
221 integer,
intent(in) :: n_loc
222 integer,
intent(in) :: n_loc_eff
223 integer,
intent(in) :: n_glb_eff
224 real(kind_real),
intent(in) :: lon_loc(n_loc)
225 real(kind_real),
intent(in) :: lat_loc(n_loc)
226 logical,
intent(in) :: mask_loc(n_loc)
227 real(kind_real),
intent(in) :: rh_loc(n_loc)
228 integer,
intent(in) :: loc_to_glb(n_loc)
229 integer,
intent(in) :: ns2_glb
230 integer,
intent(out) :: ns1_glb_eff
231 real(kind_real),
allocatable,
intent(out) :: lon1_glb_eff(:)
232 real(kind_real),
allocatable,
intent(out) :: lat1_glb_eff(:)
233 real(kind_real),
allocatable,
intent(out) :: rh1_glb_eff(:)
234 integer,
allocatable,
intent(out) :: sam1_glb_eff(:)
235 logical,
intent(in),
optional :: verbosity
236 integer,
intent(in),
optional :: n_uni
237 integer,
intent(in),
optional :: uni_to_loc(:)
238 type(
mesh_type),
intent(in),
optional :: mesh_uni
239 type(
tree_type),
intent(in),
optional :: tree_uni
240 character(len=*),
intent(in),
optional :: inside_type
243 integer :: i_loc,i_loc_eff,n,ix,iy,iproc,is1_glb,ns1_loc,is1_loc,nfac,ns1_loc_tmp,nn_index(1),ns1_glb,is1_glb_eff,offset
244 integer,
allocatable :: s1_loc_to_glb(:),s1_loc_to_glb_tmp(:),sam1_loc(:),sam1_loc_tmp(:),sam1_glb(:)
245 real(kind_real) :: lonlat(2),nn_dist(1)
246 real(kind_real),
allocatable :: lon1_loc(:),lat1_loc(:),dist1_loc(:),rh1_loc(:)
247 real(kind_real),
allocatable :: lon1_loc_tmp(:),lat1_loc_tmp(:),dist1_loc_tmp(:),rh1_loc_tmp(:)
248 real(kind_real),
allocatable :: lon1_glb(:),lat1_glb(:),dist1_glb(:),rh1_glb(:)
249 logical :: lfull_grid,lverbosity,update,retry,valid
250 logical,
allocatable :: lmask(:)
251 character(len=6) :: gridid
252 type(fckit_mpi_status) :: status
253 type(atlas_structuredgrid) :: agrid
263 if (
present(verbosity)) lverbosity = verbosity
264 lfull_grid =
present(n_uni).and.
present(uni_to_loc).and.
present(mesh_uni).and.
present(tree_uni).and.
present(inside_type)
276 ns1_glb = nfac*int(real(ns2_glb,kind_real)*
four*
pi/area)
279 n = int(-4.5_kind_real+sqrt(20.25_kind_real+
quarter*real(ns1_glb,kind_real)))+1
280 write(gridid,
'(a,i5.5)')
'O',n
281 agrid = atlas_structuredgrid(gridid)
282 ns1_glb = 4*n**2+36*n
285 allocate(lon1_loc(ns1_glb))
286 allocate(lat1_loc(ns1_glb))
287 allocate(rh1_loc(ns1_glb))
288 allocate(sam1_loc(ns1_glb))
289 allocate(dist1_loc(ns1_glb))
290 allocate(s1_loc_to_glb(ns1_glb))
291 allocate(lmask(n_loc))
295 if (lverbosity)
call mpl%prog_init(ns1_glb)
306 lonlat = agrid%lonlat(ix,iy)*
deg2rad
310 if (trim(inside_type)==
'mesh_based')
then
311 call mesh_uni%inside(mpl,lonlat(1),lonlat(2),valid)
312 elseif (trim(inside_type)==
'tree_based')
then
313 call tree_uni%inside(lonlat(1),lonlat(2),valid)
318 call tree_uni%find_nearest_neighbors(lonlat(1),lonlat(2),1,nn_index,nn_dist)
319 i_loc = uni_to_loc(nn_index(1))
321 if (mpl%msv%isnot(i_loc))
then
323 if (lmask(i_loc))
then
325 lon1_loc(is1_loc) = lon_loc(i_loc)
326 lat1_loc(is1_loc) = lat_loc(i_loc)
327 rh1_loc(is1_loc) = rh_loc(i_loc)
328 sam1_loc(is1_loc) = loc_to_glb(i_loc)
329 dist1_loc(is1_loc) = nn_dist(1)
330 s1_loc_to_glb(is1_loc) = is1_glb
331 lmask(i_loc) = .false.
337 if (lverbosity)
call mpl%prog_print(is1_glb)
340 if (lverbosity)
call mpl%prog_final(.false.)
353 allocate(lon1_loc(ns1_loc))
354 allocate(lat1_loc(ns1_loc))
355 allocate(rh1_loc(ns1_loc))
356 allocate(sam1_loc(ns1_loc))
361 if (mask_loc(i_loc))
then
362 i_loc_eff = i_loc_eff+1
363 lon1_loc(i_loc_eff) = lon_loc(i_loc)
364 lat1_loc(i_loc_eff) = lat_loc(i_loc)
365 rh1_loc(i_loc_eff) = rh_loc(i_loc)
366 sam1_loc(i_loc_eff) = loc_to_glb(i_loc)
374 write(mpl%info,
'(a)')
' => '
375 if (lverbosity)
call mpl%flush(.false.)
379 allocate(lon1_glb(ns1_glb))
380 allocate(lat1_glb(ns1_glb))
381 allocate(rh1_glb(ns1_glb))
382 allocate(sam1_glb(ns1_glb))
383 if (lfull_grid)
allocate(dist1_glb(ns1_glb))
386 lon1_glb = mpl%msv%valr
387 lat1_glb = mpl%msv%valr
388 rh1_glb = mpl%msv%valr
389 sam1_glb = mpl%msv%vali
391 dist1_glb = mpl%msv%valr
398 if (iproc==mpl%rootproc)
then
400 ns1_loc_tmp = ns1_loc
403 call mpl%f_comm%receive(ns1_loc_tmp,iproc-1,mpl%tag,status)
407 allocate(lon1_loc_tmp(ns1_loc_tmp))
408 allocate(lat1_loc_tmp(ns1_loc_tmp))
409 allocate(rh1_loc_tmp(ns1_loc_tmp))
410 allocate(sam1_loc_tmp(ns1_loc_tmp))
412 allocate(dist1_loc_tmp(ns1_loc_tmp))
413 allocate(s1_loc_to_glb_tmp(ns1_loc_tmp))
416 if (iproc==mpl%rootproc)
then
418 lon1_loc_tmp = lon1_loc(1:ns1_loc)
419 lat1_loc_tmp = lat1_loc(1:ns1_loc)
420 rh1_loc_tmp = rh1_loc(1:ns1_loc)
421 sam1_loc_tmp = sam1_loc(1:ns1_loc)
423 dist1_loc_tmp = dist1_loc(1:ns1_loc)
424 s1_loc_to_glb_tmp = s1_loc_to_glb(1:ns1_loc)
428 call mpl%f_comm%receive(lon1_loc_tmp,iproc-1,mpl%tag+1,status)
429 call mpl%f_comm%receive(lat1_loc_tmp,iproc-1,mpl%tag+2,status)
430 call mpl%f_comm%receive(rh1_loc_tmp,iproc-1,mpl%tag+3,status)
431 call mpl%f_comm%receive(sam1_loc_tmp,iproc-1,mpl%tag+4,status)
433 call mpl%f_comm%receive(dist1_loc_tmp,iproc-1,mpl%tag+5,status)
434 call mpl%f_comm%receive(s1_loc_to_glb_tmp,iproc-1,mpl%tag+6,status)
440 do is1_loc=1,ns1_loc_tmp
442 is1_glb = s1_loc_to_glb_tmp(is1_loc)
445 update = mpl%msv%is(dist1_glb(is1_glb))
446 if (.not.update) update = (dist1_loc_tmp(is1_loc)<dist1_glb(is1_glb))
448 lon1_glb(is1_glb) = lon1_loc_tmp(is1_loc)
449 lat1_glb(is1_glb) = lat1_loc_tmp(is1_loc)
450 rh1_glb(is1_glb) = rh1_loc_tmp(is1_loc)
451 sam1_glb(is1_glb) = sam1_loc_tmp(is1_loc)
452 dist1_glb(is1_glb) = dist1_loc_tmp(is1_loc)
457 lon1_glb(offset+1:offset+ns1_loc_tmp) = lon1_loc_tmp
458 lat1_glb(offset+1:offset+ns1_loc_tmp) = lat1_loc_tmp
459 rh1_glb(offset+1:offset+ns1_loc_tmp) = rh1_loc_tmp
460 sam1_glb(offset+1:offset+ns1_loc_tmp) = sam1_loc_tmp
461 offset = offset+ns1_loc_tmp
465 deallocate(lon1_loc_tmp)
466 deallocate(lat1_loc_tmp)
467 deallocate(rh1_loc_tmp)
468 deallocate(sam1_loc_tmp)
470 deallocate(dist1_loc_tmp)
471 deallocate(s1_loc_to_glb_tmp)
477 ns1_glb_eff = count(mpl%msv%isnot(dist1_glb))
479 ns1_glb_eff = ns1_glb
481 retry = (ns1_glb_eff<ns2_glb)
484 call mpl%f_comm%send(ns1_loc,mpl%rootproc-1,mpl%tag)
485 call mpl%f_comm%send(lon1_loc(1:ns1_loc),mpl%rootproc-1,mpl%tag+1)
486 call mpl%f_comm%send(lat1_loc(1:ns1_loc),mpl%rootproc-1,mpl%tag+2)
487 call mpl%f_comm%send(rh1_loc(1:ns1_loc),mpl%rootproc-1,mpl%tag+3)
488 call mpl%f_comm%send(sam1_loc(1:ns1_loc),mpl%rootproc-1,mpl%tag+4)
490 call mpl%f_comm%send(dist1_loc(1:ns1_loc),mpl%rootproc-1,mpl%tag+5)
491 call mpl%f_comm%send(s1_loc_to_glb(1:ns1_loc),mpl%rootproc-1,mpl%tag+6)
498 write(mpl%info,
'(a)')
''
499 if (lverbosity)
call mpl%flush
502 call mpl%update_tag(7)
504 call mpl%update_tag(5)
508 call mpl%f_comm%broadcast(retry,mpl%rootproc-1)
511 if ((.not.lfull_grid).and.retry)
call mpl%abort(
'samp_initialize_sampling_local',
'retry activated for limited grid')
512 if ((nfac>=8).and.retry)
call mpl%abort(
'samp_initialize_sampling_local',
'retry activated for nfac>=8')
520 deallocate(dist1_loc)
521 deallocate(s1_loc_to_glb)
523 if (mpl%main.and.retry)
then
528 if (lfull_grid)
deallocate(dist1_glb)
534 allocate(lon1_glb_eff(ns1_glb_eff))
535 allocate(lat1_glb_eff(ns1_glb_eff))
536 allocate(rh1_glb_eff(ns1_glb_eff))
537 allocate(sam1_glb_eff(ns1_glb_eff))
543 if (mpl%msv%isnot(dist1_glb(is1_glb)))
then
544 is1_glb_eff = is1_glb_eff+1
545 lon1_glb_eff(is1_glb_eff) = lon1_glb(is1_glb)
546 lat1_glb_eff(is1_glb_eff) = lat1_glb(is1_glb)
547 rh1_glb_eff(is1_glb_eff) = rh1_glb(is1_glb)
548 sam1_glb_eff(is1_glb_eff) = sam1_glb(is1_glb)
552 lon1_glb_eff = lon1_glb
553 lat1_glb_eff = lat1_glb
554 rh1_glb_eff = rh1_glb
555 sam1_glb_eff = sam1_glb
563 if (lfull_grid)
deallocate(dist1_glb)
576 & ns2_glb,sam2_glb,fast,verbosity)
583 integer,
intent(in) :: ns1_glb_eff
584 real(kind_real),
intent(in) :: lon1_glb_eff(ns1_glb_eff)
585 real(kind_real),
intent(in) :: lat1_glb_eff(ns1_glb_eff)
586 real(kind_real),
intent(in) :: rh1_glb_eff(ns1_glb_eff)
587 integer,
intent(in) :: sam1_glb_eff(ns1_glb_eff)
588 integer,
intent(in) :: ntry
589 integer,
intent(in) :: nrep
590 integer,
intent(in) :: ns2_glb
591 integer,
intent(out) :: sam2_glb(ns2_glb)
592 logical,
intent(in),
optional :: fast
593 logical,
intent(in),
optional :: verbosity
596 integer :: is2_glb,js,irep,irmax,itry,ir,irval,irvalmin,irvalmax,is2_glb_min,nrep_eff,nn_index(2),is1_glb_eff,ns1_glb_val
597 integer :: order(ns1_glb_eff),sam1_glb_tmp(ns1_glb_eff)
598 integer,
allocatable :: to_valid(:),sam2_glb_tmp(:)
599 real(kind_real) :: d,distmax,distmin,nn_dist(2),cdf_norm,rr
600 real(kind_real) :: list(ns1_glb_eff),lon1_glb_tmp(ns1_glb_eff),lat1_glb_tmp(ns1_glb_eff),rh1_glb_tmp(ns1_glb_eff)
601 real(kind_real),
allocatable :: cdf(:),lon_rep(:),lat_rep(:),dist(:)
602 logical :: lfast,lverbosity
603 logical,
allocatable :: lmask(:),smask(:),rmask(:)
615 if (
present(fast)) lfast = fast
616 if (
present(verbosity)) lverbosity = verbosity
619 do is1_glb_eff=1,ns1_glb_eff
620 list(is1_glb_eff) =
lonlathash(lon1_glb_eff(is1_glb_eff),lat1_glb_eff(is1_glb_eff))
622 call qsort(ns1_glb_eff,list,order)
625 lon1_glb_tmp = lon1_glb_eff(order)
626 lat1_glb_tmp = lat1_glb_eff(order)
627 rh1_glb_tmp = rh1_glb_eff(order)
628 sam1_glb_tmp = sam1_glb_eff(order)
631 nrep_eff = min(nrep,ns1_glb_eff-ns2_glb)
632 allocate(sam2_glb_tmp(ns2_glb+nrep_eff))
633 allocate(lmask(ns1_glb_eff))
634 allocate(smask(ns1_glb_eff))
635 allocate(to_valid(ns1_glb_eff))
638 sam2_glb_tmp = mpl%msv%vali
641 to_valid = mpl%msv%vali
642 do is1_glb_eff=1,ns1_glb_eff
643 to_valid(is1_glb_eff) = is1_glb_eff
645 ns1_glb_val = ns1_glb_eff
646 if (lverbosity)
call mpl%prog_init(ns2_glb+nrep_eff)
652 allocate(cdf(ns1_glb_eff))
656 do is1_glb_eff=2,ns1_glb_eff
657 if (lmask(is1_glb_eff))
then
658 cdf(is1_glb_eff) = cdf(is1_glb_eff-1)+
one/rh1_glb_tmp(is1_glb_eff)**2
661 cdf_norm =
one/cdf(ns1_glb_eff)
664 do is2_glb=1,ns2_glb+nrep_eff
670 irvalmax = ns1_glb_val
671 do while (irvalmax-irvalmin>1)
672 irval = (irvalmin+irvalmax)/2
673 if ((
sup(cdf(irvalmin),rr).and.
sup(cdf(irval),rr)).or.(
inf(cdf(irvalmin),rr).and.
inf(cdf(irval),rr)))
then
682 sam2_glb_tmp(is2_glb) = ir
685 if (irval<ns1_glb_val)
then
686 cdf(irval:ns1_glb_val-1) = cdf(irval+1:ns1_glb_val)
687 to_valid(irval:ns1_glb_val-1) = to_valid(irval+1:ns1_glb_val)
689 ns1_glb_val = ns1_glb_val-1
692 cdf_norm =
one/cdf(ns1_glb_val)
693 cdf(1:ns1_glb_val) = cdf(1:ns1_glb_val)*cdf_norm
696 if (lverbosity)
call mpl%prog_print(is2_glb)
698 if (lverbosity)
call mpl%prog_final(.false.)
704 do is2_glb=1,ns2_glb+nrep_eff
707 call tree%alloc(mpl,ns1_glb_eff,mask=smask)
710 call tree%init(lon1_glb_tmp,lat1_glb_tmp)
722 call rng%rand(1,ns1_glb_val,irval)
733 nn_index(1) = sam2_glb_tmp(1)
734 call sphere_dist(lon1_glb_tmp(ir),lat1_glb_tmp(ir),lon1_glb_tmp(nn_index(1)),lat1_glb_tmp(nn_index(1)), &
738 call tree%find_nearest_neighbors(lon1_glb_tmp(ir),lat1_glb_tmp(ir),1,nn_index(1:1),nn_dist(1:1))
740 d = nn_dist(1)**2/(rh1_glb_tmp(ir)**2+rh1_glb_tmp(nn_index(1))**2)
743 if (
sup(d,distmax))
then
752 if (is2_glb>2)
call tree%dealloc
757 sam2_glb_tmp(is2_glb) = irmax
758 lmask(irmax) = .false.
759 smask(irmax) = .true.
762 if (irvalmax<ns1_glb_val) to_valid(irvalmax:ns1_glb_val-1) = to_valid(irvalmax+1:ns1_glb_val)
763 ns1_glb_val = ns1_glb_val-1
767 if (lverbosity)
call mpl%prog_print(is2_glb)
769 if (lverbosity)
call mpl%prog_final(.false.)
774 write(mpl%info,
'(a)')
' => '
775 if (lverbosity)
call mpl%flush(.false.)
778 allocate(rmask(ns2_glb+nrep_eff))
779 allocate(lon_rep(ns2_glb+nrep_eff))
780 allocate(lat_rep(ns2_glb+nrep_eff))
781 allocate(dist(ns2_glb+nrep_eff))
785 do is2_glb=1,ns2_glb+nrep_eff
786 lon_rep(is2_glb) = lon1_glb_tmp(sam2_glb_tmp(is2_glb))
787 lat_rep(is2_glb) = lat1_glb_tmp(sam2_glb_tmp(is2_glb))
790 if (lverbosity)
call mpl%prog_init(nrep_eff)
795 call tree%alloc(mpl,ns2_glb+nrep_eff,mask=rmask)
798 call tree%init(lon_rep,lat_rep)
801 do is2_glb=1,ns2_glb+nrep_eff
802 if (rmask(is2_glb))
then
804 call tree%find_nearest_neighbors(lon1_glb_tmp(sam2_glb_tmp(is2_glb)),lat1_glb_tmp(sam2_glb_tmp(is2_glb)), &
805 & 2,nn_index,nn_dist)
806 if (nn_index(1)==is2_glb)
then
807 dist(is2_glb) = nn_dist(2)
808 elseif (nn_index(2)==is2_glb)
then
809 dist(is2_glb) = nn_dist(1)
811 call mpl%abort(
'samp_initialize_sampling_global',
'wrong index in replacement')
813 dist(is2_glb) = dist(is2_glb)**2/(rh1_glb_tmp(sam2_glb_tmp(nn_index(1)))**2 &
814 & +rh1_glb_tmp(sam2_glb_tmp(nn_index(2)))**2)
823 is2_glb_min = mpl%msv%vali
824 do is2_glb=1,ns2_glb+nrep_eff
825 if (rmask(is2_glb))
then
826 if (
inf(dist(is2_glb),distmin))
then
827 is2_glb_min = is2_glb
828 distmin = dist(is2_glb)
832 rmask(is2_glb_min) = .false.
835 if (lverbosity)
call mpl%prog_print(irep)
837 if (lverbosity)
call mpl%prog_final
841 do is2_glb=1,ns2_glb+nrep_eff
842 if (rmask(is2_glb))
then
844 sam2_glb(js) = sam2_glb_tmp(is2_glb)
855 write(mpl%info,
'(a)')
''
856 if (lverbosity)
call mpl%flush
859 sam2_glb = sam2_glb_tmp
863 sam2_glb = sam1_glb_tmp(sam2_glb)
866 deallocate(sam2_glb_tmp)
Subroutines/functions list.
Generic ranks, dimensions and types.
Generic ranks, dimensions and types.
Subroutines/functions list.