10 use fckit_mpi_module,
only: fckit_mpi_sum,fckit_mpi_status
34 integer,
parameter ::
irmax = 10000
35 real(kind_real),
parameter ::
lcoast = 1000.0e3_kind_real/
req 36 real(kind_real),
parameter ::
rcoast = 0.2_kind_real
41 real(kind_real),
allocatable :: rh_c0(:,:)
42 logical,
allocatable :: mask_c0(:,:)
43 logical,
allocatable :: mask_hor_c0(:)
44 integer,
allocatable :: nc0_mask(:)
45 integer,
allocatable :: c1_to_c0(:)
46 logical,
allocatable :: c1l0_log(:,:)
47 integer,
allocatable :: c1c3_to_c0(:,:)
48 logical,
allocatable :: c1c3l0_log(:,:,:)
49 integer,
allocatable :: c2_to_c1(:)
50 integer,
allocatable :: c2_to_c0(:)
53 logical,
allocatable :: vbal_mask(:,:)
54 logical,
allocatable :: local_mask(:,:)
55 logical,
allocatable :: displ_mask(:,:)
56 integer,
allocatable :: nn_c2_index(:,:,:)
57 real(kind_real),
allocatable :: nn_c2_dist(:,:,:)
58 integer,
allocatable :: nn_ldwv_index(:)
64 real(kind_real),
allocatable :: displ_lon(:,:,:)
65 real(kind_real),
allocatable :: displ_lat(:,:,:)
79 logical,
allocatable :: lcheck_c0a(:)
80 logical,
allocatable :: lcheck_c0c(:)
81 logical,
allocatable :: lcheck_c0d(:)
82 logical,
allocatable :: lcheck_c1a(:)
83 logical,
allocatable :: lcheck_c2a(:)
84 logical,
allocatable :: lcheck_c2b(:)
85 logical,
allocatable :: lcheck_c2f(:)
86 logical,
allocatable :: lcheck_h(:,:)
87 logical,
allocatable :: lcheck_d(:,:,:)
88 integer,
allocatable :: c0c_to_c0(:)
89 integer,
allocatable :: c0_to_c0c(:)
90 integer,
allocatable :: c0a_to_c0c(:)
91 integer,
allocatable :: c0d_to_c0(:)
92 integer,
allocatable :: c0_to_c0d(:)
93 integer,
allocatable :: c0a_to_c0d(:)
94 integer,
allocatable :: c1a_to_c1(:)
95 integer,
allocatable :: c1_to_c1a(:)
96 integer,
allocatable :: c2a_to_c2(:)
97 integer,
allocatable :: c2_to_c2a(:)
98 integer,
allocatable :: c2b_to_c2(:)
99 integer,
allocatable :: c2_to_c2b(:)
100 integer,
allocatable :: c2a_to_c2b(:)
101 integer,
allocatable :: c2f_to_c2(:)
102 integer,
allocatable :: c2_to_c2f(:)
103 integer,
allocatable :: c2a_to_c2f(:)
104 integer,
allocatable :: c2_to_proc(:)
105 integer,
allocatable :: proc_to_nc2a(:)
144 class(samp_type),
intent(inout) :: samp
145 type(nam_type),
intent(in) :: nam
146 type(geom_type),
intent(in) :: geom
149 allocate(samp%rh_c0(geom%nc0,geom%nl0))
150 allocate(samp%mask_c0(geom%nc0,geom%nl0))
151 allocate(samp%mask_hor_c0(geom%nc0))
152 allocate(samp%nc0_mask(geom%nl0))
153 allocate(samp%c1_to_c0(nam%nc1))
154 allocate(samp%c1l0_log(nam%nc1,geom%nl0))
155 allocate(samp%c1c3_to_c0(nam%nc1,nam%nc3))
156 allocate(samp%c1c3l0_log(nam%nc1,nam%nc3,geom%nl0))
157 if (nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag)))
then 158 allocate(samp%c2_to_c1(nam%nc2))
159 allocate(samp%c2_to_c0(nam%nc2))
160 allocate(samp%nn_c2_index(nam%nc2,nam%nc2,geom%nl0i))
161 allocate(samp%nn_c2_dist(nam%nc2,nam%nc2,geom%nl0i))
162 allocate(samp%hfull(geom%nl0i))
164 if (nam%new_vbal)
allocate(samp%vbal_mask(nam%nc1,nam%nc2))
165 if (nam%local_diag)
allocate(samp%local_mask(nam%nc1,nam%nc2))
166 if (nam%displ_diag)
then 167 allocate(samp%displ_mask(nam%nc1,nam%nc2))
168 allocate(samp%displ_lon(geom%nc0a,geom%nl0,nam%nts))
169 allocate(samp%displ_lat(geom%nc0a,geom%nl0,nam%nts))
174 samp%mask_c0 = .false.
175 samp%mask_hor_c0 = .false.
176 call msi(samp%nc0_mask)
177 call msi(samp%c1_to_c0)
178 samp%c1l0_log = .false.
179 call msi(samp%c1c3_to_c0)
180 samp%c1c3l0_log = .false.
181 if (nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag)))
then 182 call msi(samp%c2_to_c1)
183 call msi(samp%c2_to_c0)
184 call msi(samp%nn_c2_index)
185 call msr(samp%nn_c2_dist)
187 if (nam%new_vbal) samp%vbal_mask = .false.
188 if (nam%local_diag) samp%local_mask = .false.
189 if (nam%displ_diag)
then 190 samp%displ_mask = .false.
191 call msr(samp%displ_lon)
192 call msr(samp%displ_lat)
206 class(samp_type),
intent(inout) :: samp
207 type(geom_type),
intent(in) :: geom
213 if (
allocated(samp%rh_c0))
deallocate(samp%rh_c0)
214 if (
allocated(samp%mask_c0))
deallocate(samp%mask_c0)
215 if (
allocated(samp%mask_hor_c0))
deallocate(samp%mask_hor_c0)
216 if (
allocated(samp%nc0_mask))
deallocate(samp%nc0_mask)
217 if (
allocated(samp%c1_to_c0))
deallocate(samp%c1_to_c0)
218 if (
allocated(samp%c1l0_log))
deallocate(samp%c1l0_log)
219 if (
allocated(samp%c1c3_to_c0))
deallocate(samp%c1c3_to_c0)
220 if (
allocated(samp%c1c3l0_log))
deallocate(samp%c1c3l0_log)
221 if (
allocated(samp%c2_to_c1))
deallocate(samp%c2_to_c1)
222 if (
allocated(samp%c2_to_c0))
deallocate(samp%c2_to_c0)
223 if (
allocated(samp%c2a_to_c2))
deallocate(samp%c2a_to_c2)
224 if (
allocated(samp%c2_to_c2a))
deallocate(samp%c2_to_c2a)
225 if (
allocated(samp%vbal_mask))
deallocate(samp%vbal_mask)
226 if (
allocated(samp%local_mask))
deallocate(samp%local_mask)
227 if (
allocated(samp%displ_mask))
deallocate(samp%displ_mask)
228 if (
allocated(samp%nn_c2_index))
deallocate(samp%nn_c2_index)
229 if (
allocated(samp%nn_c2_dist))
deallocate(samp%nn_c2_dist)
230 if (
allocated(samp%hfull))
then 232 call samp%hfull(il0)%dealloc
234 deallocate(samp%hfull)
236 if (
allocated(samp%h))
then 238 call samp%h(il0)%dealloc
242 if (
allocated(samp%nn_ldwv_index))
deallocate(samp%nn_ldwv_index)
243 if (
allocated(samp%displ_lon))
deallocate(samp%displ_lon)
244 if (
allocated(samp%displ_lat))
deallocate(samp%displ_lat)
252 subroutine samp_read(samp,mpl,nam,geom,bpar,ios)
257 class(samp_type),
intent(inout) :: samp
258 type(mpl_type),
intent(in) :: mpl
259 type(nam_type),
intent(inout) :: nam
260 type(geom_type),
intent(in) :: geom
261 type(bpar_type),
intent(in) :: bpar
262 integer,
intent(out) :: ios
265 integer :: il0,il0i,ic1,jc3,ic2
266 integer :: nl0_test,nl0r_test,nc_test,nc1_test,nc2_test,nc2_1_test,nc2_2_test
267 integer :: info,ncid,nl0_id,nc3_id,nc1_id,nc2_id,nc2_1_id,nc2_2_id
268 integer :: c1_to_c0_id,c1l0_log_id,c1c3_to_c0_id,c1c3l0_log_id
269 integer :: c2_to_c1_id,c2_to_c0_id,vbal_mask_id,local_mask_id,displ_mask_id,nn_c2_index_id,nn_c2_dist_id
270 integer :: c1l0_logint(nam%nc1,geom%nl0),c1c3l0_logint(nam%nc1,nam%nc3,geom%nl0)
271 integer,
allocatable :: vbal_maskint(:,:),local_maskint(:,:),displ_maskint(:,:)
272 character(len=3) :: il0ichar
273 character(len=1024) :: subr =
'samp_read' 279 info = nf90_open(trim(nam%datadir)//
'/'//trim(nam%prefix)//
'_sampling.nc',nf90_nowrite,ncid)
280 if (info/=nf90_noerr)
then 281 call mpl%warning(
'cannot find sampling to read, recomputing sampling')
282 nam%sam_write = .true.
288 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nl0',nl0_id))
289 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nl0_id,len=nl0_test))
290 call mpl%ncerr(subr,nf90_get_att(ncid,nf90_global,
'nl0r',nl0r_test))
291 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nc3',nc3_id))
292 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc3_id,len=nc_test))
293 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nc1',nc1_id))
294 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc1_id,len=nc1_test))
295 if (nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag)
then 296 info = nf90_inq_dimid(ncid,
'nc2',nc2_id)
297 if (info==nf90_noerr)
then 298 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc2_id,len=nc2_test))
300 call mpl%warning(
'cannot find nc2 when reading sampling, recomputing sampling')
301 nam%sam_write = .true.
305 if ((geom%nl0/=nl0_test).or.(bpar%nl0rmax/=nl0r_test).or.(nam%nc3/=nc_test).or.(nam%nc1/=nc1_test))
then 306 call mpl%warning(
'wrong dimension when reading sampling, recomputing sampling')
307 nam%sam_write = .true.
308 call mpl%ncerr(subr,nf90_close(ncid))
312 if (nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag)
then 313 if (nam%nc2/=nc2_test)
then 314 call mpl%warning(
'wrong dimension when reading sampling, recomputing sampling')
315 nam%sam_write = .true.
320 write(mpl%info,
'(a7,a)')
'',
'Read sampling' 324 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c1_to_c0',c1_to_c0_id))
325 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c1l0_log',c1l0_log_id))
326 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c1c3_to_c0',c1c3_to_c0_id))
327 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c1c3l0_log',c1c3l0_log_id))
328 if ((ios==0).and.(nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag))
then 329 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c2_to_c1',c2_to_c1_id))
330 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'c2_to_c0',c2_to_c0_id))
334 call mpl%ncerr(subr,nf90_get_var(ncid,c1_to_c0_id,samp%c1_to_c0))
335 call mpl%ncerr(subr,nf90_get_var(ncid,c1l0_log_id,c1l0_logint))
338 if (c1l0_logint(ic1,il0)==0)
then 339 samp%c1l0_log(ic1,il0) = .false.
340 else if (c1l0_logint(ic1,il0)==1)
then 341 samp%c1l0_log(ic1,il0) = .true.
345 call mpl%ncerr(subr,nf90_get_var(ncid,c1c3_to_c0_id,samp%c1c3_to_c0))
346 call mpl%ncerr(subr,nf90_get_var(ncid,c1c3l0_log_id,c1c3l0_logint))
350 if (c1c3l0_logint(ic1,jc3,il0)==0)
then 351 samp%c1c3l0_log(ic1,jc3,il0) = .false.
352 else if (c1c3l0_logint(ic1,jc3,il0)==1)
then 353 samp%c1c3l0_log(ic1,jc3,il0) = .true.
358 if ((ios==0).and.(nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag))
then 359 call mpl%ncerr(subr,nf90_get_var(ncid,c2_to_c1_id,samp%c2_to_c1))
360 call mpl%ncerr(subr,nf90_get_var(ncid,c2_to_c0_id,samp%c2_to_c0))
364 call mpl%ncerr(subr,nf90_close(ncid))
368 if ((ios==0).and.(nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag))))
then 370 write(il0ichar,
'(i3.3)') il0i
371 info = nf90_open(trim(nam%datadir)//
'/'//trim(nam%prefix)//
'_sampling_'//il0ichar//
'.nc',nf90_nowrite,ncid)
372 if (info/=nf90_noerr)
then 373 call mpl%warning(
'cannot find nearest neighbors and interpolation data to read, recomputing sampling')
374 nam%sam_write = .true.
380 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nc1',nc1_id))
381 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc1_id,len=nc1_test))
382 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nc2_1',nc2_1_id))
383 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc2_1_id,len=nc2_1_test))
384 call mpl%ncerr(subr,nf90_inq_dimid(ncid,
'nc2_2',nc2_2_id))
385 call mpl%ncerr(subr,nf90_inquire_dimension(ncid,nc2_2_id,len=nc2_2_test))
386 if ((nam%nc1/=nc1_test).or.(nam%nc2/=nc2_1_test).or.(nam%nc2/=nc2_2_test))
then 387 call mpl%warning(
'wrong dimension when reading sampling, recomputing sampling')
388 nam%sam_write = .true.
391 info = nf90_inq_varid(ncid,
'nn_c2_index',nn_c2_index_id)
392 if (info==nf90_noerr)
then 393 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'nn_c2_dist',nn_c2_dist_id))
394 call mpl%ncerr(subr,nf90_get_var(ncid,nn_c2_index_id,samp%nn_c2_index(:,:,il0i)))
395 call mpl%ncerr(subr,nf90_get_var(ncid,nn_c2_dist_id,samp%nn_c2_dist(:,:,il0i)))
397 call mpl%warning(
'cannot find nc2 nearest neighbors data to read, recomputing sampling')
398 nam%sam_write = .true.
401 write(samp%hfull(il0i)%prefix,
'(a,i3.3)')
'hfull_',il0i
402 call samp%hfull(il0i)%read(mpl,ncid)
405 if ((ios==0).and.nam%new_vbal)
then 407 allocate(vbal_maskint(nam%nc1,nam%nc2))
409 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'vbal_mask',vbal_mask_id))
410 call mpl%ncerr(subr,nf90_get_var(ncid,vbal_mask_id,vbal_maskint))
413 if (vbal_maskint(ic1,ic2)==1)
then 414 samp%vbal_mask(ic1,ic2) = .true.
415 elseif (vbal_maskint(ic1,ic2)==0)
then 416 samp%vbal_mask(ic1,ic2) = .false.
418 call mpl%abort(
'wrong vbal_mask')
424 deallocate(vbal_maskint)
427 if ((ios==0).and.nam%local_diag)
then 429 allocate(local_maskint(nam%nc1,nam%nc2))
431 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'local_mask',local_mask_id))
432 call mpl%ncerr(subr,nf90_get_var(ncid,local_mask_id,local_maskint))
435 if (local_maskint(ic1,ic2)==1)
then 436 samp%local_mask(ic1,ic2) = .true.
437 elseif (local_maskint(ic1,ic2)==0)
then 438 samp%local_mask(ic1,ic2) = .false.
440 call mpl%abort(
'wrong local_mask')
446 deallocate(local_maskint)
449 if ((ios==0).and.nam%displ_diag)
then 451 allocate(displ_maskint(nam%nc1,nam%nc2))
453 call mpl%ncerr(subr,nf90_inq_varid(ncid,
'displ_mask',displ_mask_id))
454 call mpl%ncerr(subr,nf90_get_var(ncid,displ_mask_id,displ_maskint))
457 if (displ_maskint(ic1,ic2)==1)
then 458 samp%displ_mask(ic1,ic2) = .true.
459 elseif (displ_maskint(ic1,ic2)==0)
then 460 samp%displ_mask(ic1,ic2) = .false.
462 call mpl%abort(
'wrong displ_mask')
468 deallocate(displ_maskint)
471 if ((ios==0).and.(nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag))
then 473 call mpl%ncerr(subr,nf90_close(ncid))
488 class(samp_type),
intent(in) :: samp
489 type(mpl_type),
intent(in) :: mpl
490 type(nam_type),
intent(in) :: nam
491 type(geom_type),
intent(in) :: geom
492 type(bpar_type),
intent(in) :: bpar
495 integer :: il0,il0i,ic1,jc3,ic2
496 integer :: ncid,nl0_id,nc1_id,nc2_id,nc2_1_id,nc2_2_id,nc3_id
497 integer :: lat_id,lon_id,smax_id,c1_to_c0_id,c1l0_log_id,c1c3_to_c0_id,c1c3l0_log_id
498 integer :: c2_to_c1_id,c2_to_c0_id,vbal_mask_id,local_mask_id,displ_mask_id,nn_c2_index_id,nn_c2_dist_id
499 integer :: c1l0_logint(nam%nc1,geom%nl0),c1c3l0_logint(nam%nc1,nam%nc3,geom%nl0)
500 integer,
allocatable :: vbal_maskint(:,:),local_maskint(:,:),displ_maskint(:,:)
501 real(kind_real) :: lon(nam%nc1,nam%nc3,geom%nl0),lat(nam%nc1,nam%nc3,geom%nl0)
502 character(len=3) :: il0ichar
503 character(len=1024) :: subr =
'samp_write' 506 if (.not.mpl%main)
call mpl%abort(
'only I/O proc should enter '//trim(subr))
509 write(mpl%info,
'(a7,a)')
'',
'Write sampling' 511 call mpl%ncerr(subr,nf90_create(trim(nam%datadir)//
'/'//trim(nam%prefix)//
'_sampling.nc',or(nf90_clobber,nf90_64bit_offset),ncid))
514 call nam%ncwrite(mpl,ncid)
517 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nl0',geom%nl0,nl0_id))
518 call mpl%ncerr(subr,nf90_put_att(ncid,nf90_global,
'nl0r',bpar%nl0rmax))
519 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc3',nam%nc3,nc3_id))
520 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc1',nam%nc1,nc1_id))
521 if (nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag))) &
522 &
call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc2',nam%nc2,nc2_id))
525 call mpl%ncerr(subr,nf90_def_var(ncid,
'lat',
ncfloat,(/nc1_id,nc3_id,nl0_id/),lat_id))
526 call mpl%ncerr(subr,nf90_put_att(ncid,lat_id,
'_FillValue',
msvalr))
527 call mpl%ncerr(subr,nf90_def_var(ncid,
'lon',
ncfloat,(/nc1_id,nc3_id,nl0_id/),lon_id))
528 call mpl%ncerr(subr,nf90_put_att(ncid,lon_id,
'_FillValue',
msvalr))
529 call mpl%ncerr(subr,nf90_def_var(ncid,
'smax',
ncfloat,(/nc3_id,nl0_id/),smax_id))
530 call mpl%ncerr(subr,nf90_put_att(ncid,smax_id,
'_FillValue',
msvalr))
531 call mpl%ncerr(subr,nf90_def_var(ncid,
'c1_to_c0',nf90_int,(/nc1_id/),c1_to_c0_id))
532 call mpl%ncerr(subr,nf90_put_att(ncid,c1_to_c0_id,
'_FillValue',
msvali))
533 call mpl%ncerr(subr,nf90_def_var(ncid,
'c1l0_log',nf90_int,(/nc1_id,nl0_id/),c1l0_log_id))
534 call mpl%ncerr(subr,nf90_put_att(ncid,c1l0_log_id,
'_FillValue',
msvali))
535 call mpl%ncerr(subr,nf90_def_var(ncid,
'c1c3_to_c0',nf90_int,(/nc1_id,nc3_id/),c1c3_to_c0_id))
536 call mpl%ncerr(subr,nf90_put_att(ncid,c1c3_to_c0_id,
'_FillValue',
msvali))
537 call mpl%ncerr(subr,nf90_def_var(ncid,
'c1c3l0_log',nf90_int,(/nc1_id,nc3_id,nl0_id/),c1c3l0_log_id))
538 call mpl%ncerr(subr,nf90_put_att(ncid,c1c3l0_log_id,
'_FillValue',
msvali))
539 if (nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag)
then 540 call mpl%ncerr(subr,nf90_def_var(ncid,
'c2_to_c1',nf90_int,(/nc2_id/),c2_to_c1_id))
541 call mpl%ncerr(subr,nf90_put_att(ncid,c2_to_c1_id,
'_FillValue',
msvali))
542 call mpl%ncerr(subr,nf90_def_var(ncid,
'c2_to_c0',nf90_int,(/nc2_id/),c2_to_c0_id))
543 call mpl%ncerr(subr,nf90_put_att(ncid,c2_to_c0_id,
'_FillValue',
msvali))
547 call mpl%ncerr(subr,nf90_enddef(ncid))
555 if (samp%c1c3l0_log(ic1,jc3,il0))
then 556 lon(ic1,jc3,il0) = geom%lon(samp%c1c3_to_c0(ic1,jc3))*
rad2deg 557 lat(ic1,jc3,il0) = geom%lat(samp%c1c3_to_c0(ic1,jc3))*
rad2deg 558 c1c3l0_logint(ic1,jc3,il0) = 1
560 c1c3l0_logint(ic1,jc3,il0) = 0
565 if (samp%c1l0_log(ic1,il0))
then 566 c1l0_logint(ic1,il0) = 1
568 c1l0_logint(ic1,il0) = 0
574 call mpl%ncerr(subr,nf90_put_var(ncid,lon_id,lon))
575 call mpl%ncerr(subr,nf90_put_var(ncid,lat_id,lat))
576 call mpl%ncerr(subr,nf90_put_var(ncid,smax_id,
real(count(samp%c1c3l0_log,dim=1),kind_real)))
577 call mpl%ncerr(subr,nf90_put_var(ncid,c1_to_c0_id,samp%c1_to_c0))
578 call mpl%ncerr(subr,nf90_put_var(ncid,c1l0_log_id,c1l0_logint))
579 call mpl%ncerr(subr,nf90_put_var(ncid,c1c3_to_c0_id,samp%c1c3_to_c0))
580 call mpl%ncerr(subr,nf90_put_var(ncid,c1c3l0_log_id,c1c3l0_logint))
581 if (nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag)
then 582 call mpl%ncerr(subr,nf90_put_var(ncid,c2_to_c1_id,samp%c2_to_c1))
583 call mpl%ncerr(subr,nf90_put_var(ncid,c2_to_c0_id,samp%c2_to_c0))
587 call mpl%ncerr(subr,nf90_close(ncid))
591 if (nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag)))
then 593 write(il0ichar,
'(i3.3)') il0i
594 call mpl%ncerr(subr,nf90_create(trim(nam%datadir)//
'/'//trim(nam%prefix)//
'_sampling_'//il0ichar//
'.nc', &
595 & or(nf90_clobber,nf90_64bit_offset),ncid))
598 call nam%ncwrite(mpl,ncid)
601 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc1',nam%nc1,nc1_id))
602 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc2_1',nam%nc2,nc2_1_id))
603 call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc2_2',nam%nc2,nc2_2_id))
606 call mpl%ncerr(subr,nf90_def_var(ncid,
'nn_c2_index',nf90_int,(/nc2_1_id,nc2_2_id/),nn_c2_index_id))
607 call mpl%ncerr(subr,nf90_put_att(ncid,nn_c2_index_id,
'_FillValue',
msvali))
608 call mpl%ncerr(subr,nf90_def_var(ncid,
'nn_c2_dist',
ncfloat,(/nc2_1_id,nc2_2_id/),nn_c2_dist_id))
609 call mpl%ncerr(subr,nf90_put_att(ncid,nn_c2_dist_id,
'_FillValue',
msvalr))
612 call mpl%ncerr(subr,nf90_enddef(ncid))
615 call mpl%ncerr(subr,nf90_put_var(ncid,nn_c2_index_id,samp%nn_c2_index(:,:,il0i)))
616 call mpl%ncerr(subr,nf90_put_var(ncid,nn_c2_dist_id,samp%nn_c2_dist(:,:,il0i)))
617 call samp%hfull(il0i)%write(mpl,ncid)
620 if (nam%new_vbal)
then 622 allocate(vbal_maskint(nam%nc1,nam%nc2))
625 call mpl%ncerr(subr,nf90_redef(ncid))
628 call mpl%ncerr(subr,nf90_def_var(ncid,
'vbal_mask',nf90_int,(/nc1_id,nc2_1_id/),vbal_mask_id))
629 call mpl%ncerr(subr,nf90_put_att(ncid,vbal_mask_id,
'_FillValue',
msvali))
634 if (samp%vbal_mask(ic1,ic2))
then 635 vbal_maskint(ic1,ic2) = 1
637 vbal_maskint(ic1,ic2) = 0
643 call mpl%ncerr(subr,nf90_enddef(ncid))
646 call mpl%ncerr(subr,nf90_put_var(ncid,vbal_mask_id,vbal_maskint))
649 deallocate(vbal_maskint)
652 if (nam%local_diag)
then 654 allocate(local_maskint(nam%nc1,nam%nc2))
657 call mpl%ncerr(subr,nf90_redef(ncid))
660 call mpl%ncerr(subr,nf90_def_var(ncid,
'local_mask',nf90_int,(/nc1_id,nc2_1_id/),local_mask_id))
661 call mpl%ncerr(subr,nf90_put_att(ncid,local_mask_id,
'_FillValue',
msvali))
666 if (samp%local_mask(ic1,ic2))
then 667 local_maskint(ic1,ic2) = 1
669 local_maskint(ic1,ic2) = 0
675 call mpl%ncerr(subr,nf90_enddef(ncid))
678 call mpl%ncerr(subr,nf90_put_var(ncid,local_mask_id,local_maskint))
681 deallocate(local_maskint)
684 if (nam%displ_diag)
then 686 allocate(displ_maskint(nam%nc1,nam%nc2))
689 call mpl%ncerr(subr,nf90_redef(ncid))
692 call mpl%ncerr(subr,nf90_def_var(ncid,
'displ_mask',nf90_int,(/nc1_id,nc2_1_id/),displ_mask_id))
693 call mpl%ncerr(subr,nf90_put_att(ncid,displ_mask_id,
'_FillValue',
msvali))
698 if (samp%displ_mask(ic1,ic2))
then 699 displ_maskint(ic1,ic2) = 1
701 displ_maskint(ic1,ic2) = 0
707 call mpl%ncerr(subr,nf90_enddef(ncid))
710 call mpl%ncerr(subr,nf90_put_var(ncid,displ_mask_id,displ_maskint))
713 deallocate(displ_maskint)
716 if (nam%new_lct.or.nam%var_diag.or.nam%local_diag.or.nam%displ_diag)
then 718 call mpl%ncerr(subr,nf90_close(ncid))
733 class(samp_type),
intent(inout) :: samp
734 type(mpl_type),
intent(inout) :: mpl
735 type(rng_type),
intent(inout) :: rng
736 type(nam_type),
intent(inout) :: nam
737 type(geom_type),
intent(in) :: geom
738 type(bpar_type),
intent(in) :: bpar
739 type(io_type),
intent(in) :: io
740 type(ens_type),
intent(in) :: ens
743 integer :: ios,ic0,il0,ic1,ic2,ildw,jc3,il0i,jc1,kc1
744 integer,
allocatable :: vbot(:),vtop(:),nn_c1_index(:)
745 real(kind_real) :: lon_c1(nam%nc1),lat_c1(nam%nc1)
746 real(kind_real) :: lon_c2(nam%nc2),lat_c2(nam%nc2)
747 real(kind_real) :: rh_c0a(geom%nc0a,geom%nl0),nn_dist(1)
748 real(kind_real),
allocatable :: rh_c1(:),nn_c1_dist(:)
749 logical :: mask_c1(nam%nc1),mask_c2(nam%nc2)
750 character(len=1024) :: filename
751 type(kdtree_type) :: kdtree
752 type(linop_type) :: hbase
755 if (nam%nc1>maxval(geom%nc0_mask))
then 756 call mpl%warning(
'nc1 is too large for then mask, reset nc1 to the largest possible value')
757 nam%nc1 = maxval(geom%nc0_mask)
761 call samp%alloc(nam,geom)
765 if (nam%sam_read)
call samp%read(mpl,nam,geom,bpar,ios)
768 call samp%compute_mask(mpl,nam,geom,ens)
771 call samp%compute_sampling_zs(mpl,rng,nam,geom)
773 if (nam%new_lct)
then 775 call samp%compute_sampling_lct(mpl,nam,geom)
776 elseif (nam%new_vbal.or.nam%new_hdiag)
then 778 call samp%compute_sampling_ps(mpl,rng,nam,geom)
782 call samp%compute_sampling_mask(mpl,nam,geom)
785 if (nam%new_vbal.or.nam%new_lct.or.(nam%new_hdiag.and.(nam%var_diag.or.nam%local_diag.or.nam%displ_diag)))
then 786 if ((ios==1).or.(ios==2))
then 788 write(mpl%info,
'(a7,a)',advance=
'no')
'',
'Define subsampling:' 790 allocate(rh_c1(nam%nc1))
791 lon_c1 = geom%lon(samp%c1_to_c0)
792 lat_c1 = geom%lat(samp%c1_to_c0)
793 mask_c1 = any(samp%c1l0_log(:,:),dim=2)
795 call rng%initialize_sampling(mpl,nam%nc1,lon_c1,lat_c1,mask_c1,rh_c1,nam%ntry,nam%nrep,nam%nc2,samp%c2_to_c1)
796 samp%c2_to_c0 = samp%c1_to_c0(samp%c2_to_c1)
800 if ((ios==1).or.(ios==2).or.(ios==3).or.(ios==4))
then 802 write(mpl%info,
'(a7,a)')
'',
'Find nearest neighbors' 805 if ((il0==1).or.(geom%nl0i>1))
then 806 write(mpl%info,
'(a10,a,i3)')
'',
'Level ',nam%levs(il0)
808 lon_c2 = geom%lon(samp%c2_to_c0)
809 lat_c2 = geom%lat(samp%c2_to_c0)
811 call kdtree%create(mpl,nam%nc2,lon_c2,lat_c2,mask=mask_c2)
813 ic1 = samp%c2_to_c1(ic2)
814 ic0 = samp%c2_to_c0(ic2)
815 call kdtree%find_nearest_neighbors(geom%lon(ic0),geom%lat(ic0),nam%nc2,samp%nn_c2_index(:,ic2,il0), &
816 & samp%nn_c2_dist(:,ic2,il0))
824 write(mpl%info,
'(a7,a)')
'',
'Compute sampling mesh' 826 lon_c2 = geom%lon(samp%c2_to_c0)
827 lat_c2 = geom%lat(samp%c2_to_c0)
828 call samp%mesh%create(mpl,rng,nam%nc2,lon_c2,lat_c2)
831 write(mpl%info,
'(a7,a)')
'',
'Compute triangles list ' 833 call samp%mesh%trlist
836 write(mpl%info,
'(a7,a)')
'',
'Find boundary nodes' 838 call samp%mesh%bnodes
841 write(mpl%info,
'(a7,a)')
'',
'Find boundary arcs' 845 if ((ios==1).or.(ios==2).or.(ios==3))
then 846 if (nam%new_vbal.or.nam%local_diag.or.nam%displ_diag)
then 848 allocate(nn_c1_index(nam%nc1))
849 allocate(nn_c1_dist(nam%nc1))
852 write(mpl%info,
'(a7,a)')
'',
'Compute local masks' 854 lon_c1 = geom%lon(samp%c1_to_c0)
855 lat_c1 = geom%lat(samp%c1_to_c0)
856 mask_c1 = any(samp%c1l0_log,dim=2)
857 call kdtree%create(mpl,nam%nc1,lon_c1,lat_c1,mask=mask_c1)
860 ic1 = samp%c2_to_c1(ic2)
861 ic0 = samp%c2_to_c0(ic2)
864 call kdtree%find_nearest_neighbors(geom%lon(ic0),geom%lat(ic0),nam%nc1,nn_c1_index,nn_c1_dist)
866 kc1 = nn_c1_index(jc1)
867 if (nam%new_vbal) samp%vbal_mask(kc1,ic2) = (jc1==1) &
868 & .or.(nn_c1_dist(jc1)<nam%vbal_rad)
869 if (nam%local_diag) samp%local_mask(kc1,ic2) = (jc1==1) &
870 & .or.(nn_c1_dist(jc1)<nam%local_rad)
871 if (nam%displ_diag) samp%displ_mask(kc1,ic2) = (jc1==1) &
872 & .or.(nn_c1_dist(jc1)<
min(nam%displ_rad,samp%mesh%bdist(ic2)))
878 deallocate(nn_c1_index)
879 deallocate(nn_c1_dist)
883 allocate(vbot(nam%nc2))
884 allocate(vtop(nam%nc2))
891 write(mpl%info,
'(a7,a)')
'',
'Compute grid interpolation' 894 write(samp%hfull(il0i)%prefix,
'(a,i3.3)')
'hfull_',il0i
895 call samp%hfull(il0i)%interp(mpl,rng,geom,il0i,nam%nc2,samp%c2_to_c0,nam%mask_check,vbot,vtop,nam%diag_interp,hbase)
905 if (nam%sam_write)
then 906 if (mpl%main)
call samp%write(mpl,nam,geom,bpar)
909 if (trim(nam%draw_type)==
'random_coast')
then 910 call mpl%glb_to_loc(geom%nl0,geom%nc0,geom%c0_to_proc,geom%c0_to_c0a,samp%rh_c0,geom%nc0a,rh_c0a)
911 filename = trim(nam%prefix)//
'_sampling_rh_c0' 912 call io%fld_write(mpl,nam,geom,filename,
'rh_c0',rh_c0a)
917 if (nam%local_diag.and.(nam%nldwv>0))
then 918 write(mpl%info,
'(a7,a)')
'',
'Compute nearest neighbors for local diagnostics output' 920 allocate(samp%nn_ldwv_index(nam%nldwv))
921 call kdtree%create(mpl,nam%nc2,geom%lon(samp%c2_to_c0),geom%lat(samp%c2_to_c0),mask=samp%c1l0_log(samp%c2_to_c1,1))
923 call kdtree%find_nearest_neighbors(nam%lon_ldwv(ildw),nam%lat_ldwv(ildw),1,samp%nn_ldwv_index(ildw:ildw),nn_dist)
929 write(mpl%info,
'(a7,a)')
'',
'Sampling efficiency (%):' 931 write(mpl%info,
'(a10,a,i3,a)',advance=
'no')
'',
'Level ',nam%levs(il0),
' ~> ' 933 if (count(samp%c1c3l0_log(:,jc3,il0))>=nam%nc1/2)
then 935 write(mpl%info,
'(a,i3,a)',advance=
'no') trim(mpl%green), &
936 & int(100.0*
real(count(samp%c1c3l0_log(:,jc3,il0)),kind_real)/
real(nam%nc1,kind_real)),trim(mpl%black)
939 write(mpl%info,
'(a,i3,a)',advance=
'no') trim(mpl%peach), &
940 & int(100.0*
real(count(samp%c1c3l0_log(:,jc3,il0)),kind_real)/
real(nam%nc1,kind_real)),trim(mpl%black)
942 if (jc3<nam%nc3)
write(mpl%info,
'(a)',advance=
'no')
'-' 944 write(mpl%info,
'(a)')
' ' 959 class(samp_type),
intent(inout) :: samp
960 type(mpl_type),
intent(inout) :: mpl
961 type(nam_type),
intent(in) :: nam
962 type(geom_type),
intent(in) :: geom
963 type(ens_type),
intent(in) :: ens
966 integer :: ic0a,il0,iv,its,ie,isub,ie_sub
967 real(kind_real),
allocatable :: var(:,:,:,:)
968 logical :: valid,mask_c0a(geom%nc0a,geom%nl0)
971 mask_c0a = geom%mask_c0a
974 select case (trim(nam%mask_type))
977 allocate(var(geom%nc0a,geom%nl0,nam%nv,nam%nts))
982 var = var +ens%fld(:,:,:,:,ie)**2
984 var = var/
real(ens%ne-ens%nsub,kind_real)
989 mask_c0a = mask_c0a.and.(var(:,:,iv,its)>nam%mask_th**2)
1000 do ie_sub=1,ens%ne/ens%nsub
1001 ie = ie_sub+(isub-1)*ens%ne/ens%nsub
1002 valid = valid.and.(ens%mean(ic0a,il0,iv,its,isub)+ens%fld(ic0a,il0,iv,its,ie)>nam%mask_th)
1005 mask_c0a(ic0a,il0) = mask_c0a(ic0a,il0).and.valid
1013 call mpl%loc_to_glb(geom%nl0,geom%nc0a,mask_c0a,geom%nc0,geom%c0_to_proc,geom%c0_to_c0a,.true.,samp%mask_c0)
1016 samp%mask_hor_c0 = any(samp%mask_c0,dim=2)
1017 samp%nc0_mask = count(samp%mask_c0,dim=1)
1020 select case (trim(nam%mask_type))
1021 case (
'stddev',
'all_members',
'any_member')
1022 write(mpl%info,
'(a7,a)')
'',
'Number of points excluded from HDIAG sampling:' 1024 write(mpl%info,
'(a10,a,i3,a,i8,a,i8)')
'',
'Level',nam%levs(il0),
': ',count(geom%mask_c0(:,il0))-count(samp%mask_c0(:,il0)), &
1025 &
' of ',count(geom%mask_c0(:,il0))
1040 class(samp_type),
intent(inout) :: samp
1041 type(mpl_type),
intent(inout) :: mpl
1042 type(rng_type),
intent(inout) :: rng
1043 type(nam_type),
intent(in) :: nam
1044 type(geom_type),
intent(in) :: geom
1047 integer :: ic0,ic1,il0
1048 integer :: nn_index(1)
1049 real(kind_real) :: nn_dist(1)
1050 type(kdtree_type) :: kdtree
1053 if (nam%nc1<maxval(samp%nc0_mask))
then 1054 write(mpl%info,
'(a7,a)',advance=
'no')
'',
'Compute horizontal subset C1: ' 1055 call flush(mpl%info)
1056 select case (trim(nam%draw_type))
1057 case (
'random_uniform')
1060 if (samp%mask_hor_c0(ic0)) samp%rh_c0(ic0,1) = 1.0
1062 case (
'random_coast')
1065 if (samp%mask_hor_c0(ic0)) samp%rh_c0(ic0,1) = 0.0
1068 call kdtree%create(mpl,geom%nc0,geom%lon,geom%lat,mask=.not.samp%mask_c0(:,il0))
1070 if (samp%mask_c0(ic0,il0))
then 1071 call kdtree%find_nearest_neighbors(geom%lon(ic0),geom%lat(ic0),1,nn_index,nn_dist)
1072 samp%rh_c0(ic0,1) = samp%rh_c0(ic0,1)+exp(-nn_dist(1)/
lcoast)
1074 samp%rh_c0(ic0,1) = samp%rh_c0(ic0,1)+1.0
1079 samp%rh_c0(:,1) =
rcoast+(1.0-
rcoast)*(1.0-samp%rh_c0(:,1)/
real(geom%nl0,kind_real))
1083 call rng%initialize_sampling(mpl,geom%nc0,geom%lon,geom%lat,samp%mask_hor_c0,samp%rh_c0(:,1),nam%ntry,nam%nrep, &
1084 & nam%nc1,samp%c1_to_c0)
1088 if (samp%mask_hor_c0(ic0))
then 1090 samp%c1_to_c0(ic1) = ic0
1106 class(samp_type),
intent(inout) :: samp
1107 type(mpl_type),
intent(inout) :: mpl
1108 type(rng_type),
intent(inout) :: rng
1109 type(nam_type),
intent(in) :: nam
1110 type(geom_type),
intent(in) :: geom
1113 integer :: irmaxloc,jc3,ic1,ir,ic0,jc0,i,nvc0,ivc0,icinf,icsup,ictest
1114 integer,
allocatable :: vic0(:)
1115 real(kind_real) :: d
1116 real(kind_real),
allocatable :: x(:),y(:),z(:),v1(:),v2(:),va(:),vp(:),t(:)
1120 samp%c1c3_to_c0(:,1) = samp%c1_to_c0
1123 write(mpl%info,
'(a7,a)',advance=
'no')
'',
'Compute positive separation sampling: ' 1124 call flush(mpl%info)
1128 if (jc3/=1)
call msi(samp%c1c3_to_c0(:,jc3))
1132 nvc0 = count(samp%mask_hor_c0)
1133 allocate(vic0(nvc0))
1136 if (samp%mask_hor_c0(ic0))
then 1143 call mpl%prog_init(nam%nc3*nam%nc1)
1146 do while ((.not.all(
isnotmsi(samp%c1c3_to_c0))).and.(nvc0>1).and.(ir<=irmaxloc))
1148 if (mpl%main)
call rng%rand_integer(1,nvc0,i)
1149 call mpl%f_comm%broadcast(i,mpl%ioproc-1)
1166 if (
isnotmsi(samp%c1_to_c0(ic1)))
then 1168 ic0 = samp%c1_to_c0(ic1)
1169 call sphere_dist(geom%lon(ic0),geom%lat(ic0),geom%lon(jc0),geom%lat(jc0),d)
1172 if ((d>0.0).and.(d<(
real(nam%nc3,kind_real)-0.5)*nam%dc)) then
1177 do while (.not.found)
1179 ictest = (icsup+icinf)/2
1182 if (d<(
real(ictest,kind_real)-0.5)*nam%dc) icsup = ictest
1183 if (d>(
real(ictest,kind_real)-0.5)*nam%dc) icinf = ictest
1186 if (icsup==icinf+1)
then 1187 if (abs((
real(icinf,kind_real)-0.5)*nam%dc-d)<abs((
real(icsup,kind_real)-0.5)*nam%dc-d)) then
1197 if ((jc3/=1).and.(
ismsi(samp%c1c3_to_c0(ic1,jc3)))) samp%c1c3_to_c0(ic1,jc3) = jc0
1214 vic0(i) = vic0(nvc0)
1218 mpl%done = pack(
isnotmsi(samp%c1c3_to_c0),mask=.true.)
1221 write(mpl%info,
'(a)')
'100%' 1222 call flush(mpl%info)
1239 class(samp_type),
intent(inout) :: samp
1240 type(mpl_type),
intent(inout) :: mpl
1241 type(nam_type),
intent(in) :: nam
1242 type(geom_type),
intent(in) :: geom
1245 integer :: i,il0,ic1,ic0,jc0,ibnd,ic3
1246 integer :: nn_index(nam%nc3)
1247 integer :: iproc,ic1_s(mpl%nproc),ic1_e(mpl%nproc),nc1_loc(mpl%nproc),ic1_loc
1248 integer,
allocatable :: sbufi(:),rbufi(:)
1249 real(kind_real) :: nn_dist(nam%nc3)
1250 real(kind_real),
allocatable :: x(:),y(:),z(:),v1(:),v2(:),va(:),vp(:),t(:)
1251 logical,
allocatable :: sbufl(:),rbufl(:)
1252 type(fckit_mpi_status) :: status
1254 write(mpl%info,
'(a7,a)',advance=
'no')
'',
'Compute LCT sampling: ' 1255 call flush(mpl%info)
1258 call mpl%split(nam%nc1,ic1_s,ic1_e,nc1_loc)
1261 call mpl%prog_init(nc1_loc(mpl%myproc))
1263 do ic1_loc=1,nc1_loc(mpl%myproc)
1265 ic1 = ic1_s(mpl%myproc)+ic1_loc-1
1268 if (
isnotmsi(samp%c1_to_c0(ic1)))
then 1270 call geom%kdtree%find_nearest_neighbors(geom%lon(samp%c1_to_c0(ic1)),geom%lat(samp%c1_to_c0(ic1)), &
1271 & nam%nc3,nn_index,nn_dist)
1276 samp%c1c3_to_c0(ic1,ic3) = nn_index(ic3)
1278 samp%c1c3l0_log(ic1,ic3,il0) = samp%mask_c0(jc0,il0)
1282 if (nam%mask_check)
then 1298 ic0 = samp%c1_to_c0(ic1)
1299 jc0 = samp%c1c3_to_c0(ic1,ic3)
1302 call trans(2,geom%lat((/ic0,jc0/)),geom%lon((/ic0,jc0/)),x,y,z)
1305 v1 = (/x(1),y(1),z(1)/)
1306 v2 = (/x(2),y(2),z(2)/)
1310 do ibnd=1,geom%nbnd(il0)
1312 v1 = (/x(1),y(1),z(1)/)
1314 v1 = (/x(2),y(2),z(2)/)
1316 v1 = (/geom%xbnd(1,ibnd,il0),geom%ybnd(1,ibnd,il0),geom%zbnd(1,ibnd,il0)/)
1318 v1 = (/geom%xbnd(2,ibnd,il0),geom%ybnd(2,ibnd,il0),geom%zbnd(2,ibnd,il0)/)
1322 if (all(t>0).or.(all(t<0)))
then 1323 samp%c1c3l0_log(ic1,ic3,il0) = .false.
1344 call mpl%prog_print(ic1_loc)
1346 write(mpl%info,
'(a)')
'100%' 1347 call flush(mpl%info)
1350 write(mpl%info,
'(a7,a)')
'',
'Communication' 1351 call flush(mpl%info)
1353 do iproc=1,mpl%nproc
1354 if (iproc/=mpl%ioproc)
then 1356 allocate(rbufi(nc1_loc(iproc)*nam%nc3))
1357 allocate(rbufl(nc1_loc(iproc)*nam%nc3*geom%nl0))
1360 call mpl%f_comm%receive(rbufi,iproc-1,mpl%tag,status)
1361 call mpl%f_comm%receive(rbufl,iproc-1,mpl%tag+1,status)
1366 do ic1_loc=1,nc1_loc(iproc)
1368 ic1 = ic1_s(iproc)+ic1_loc-1
1369 samp%c1c3_to_c0(ic1,ic3) = rbufi(i)
1375 do ic1_loc=1,nc1_loc(iproc)
1377 ic1 = ic1_s(iproc)+ic1_loc-1
1378 samp%c1c3l0_log(ic1,ic3,il0) = rbufl(i)
1390 allocate(sbufi(nc1_loc(mpl%myproc)*nam%nc3))
1391 allocate(sbufl(nc1_loc(mpl%myproc)*nam%nc3*geom%nl0))
1396 do ic1_loc=1,nc1_loc(mpl%myproc)
1398 ic1 = ic1_s(mpl%myproc)+ic1_loc-1
1399 sbufi(i) = samp%c1c3_to_c0(ic1,ic3)
1405 do ic1_loc=1,nc1_loc(mpl%myproc)
1407 ic1 = ic1_s(mpl%myproc)+ic1_loc-1
1408 sbufl(i) = samp%c1c3l0_log(ic1,ic3,il0)
1414 call mpl%f_comm%send(sbufi,mpl%ioproc-1,mpl%tag)
1415 call mpl%f_comm%send(sbufl,mpl%ioproc-1,mpl%tag+1)
1421 call mpl%update_tag(2)
1422 call mpl%f_comm%broadcast(samp%c1c3_to_c0,mpl%ioproc-1)
1423 call mpl%f_comm%broadcast(samp%c1c3l0_log,mpl%ioproc-1)
1436 class(samp_type),
intent(inout) :: samp
1437 type(mpl_type),
intent(inout) :: mpl
1438 type(nam_type),
intent(in) :: nam
1439 type(geom_type),
intent(in) :: geom
1442 integer :: il0,jc3,ic1,ic0,jc0,i
1447 samp%c1l0_log(:,il0) = samp%mask_c0(samp%c1_to_c0,il0)
1451 if (nam%mask_check)
then 1452 write(mpl%info,
'(a7,a)',advance=
'no')
'',
'Check mask boundaries: ' 1453 call mpl%prog_init(geom%nl0*nam%nc3*nam%nc1)
1460 ic0 = samp%c1c3_to_c0(ic1,jc3)
1461 jc0 = samp%c1c3_to_c0(ic1,1)
1468 valid = samp%mask_c0(ic0,il0).and.samp%mask_c0(jc0,il0)
1471 if (nam%mask_check)
then 1472 if (valid)
call geom%check_arc(il0,geom%lon(ic0),geom%lat(ic0),geom%lon(jc0),geom%lat(jc0),valid)
1474 call mpl%prog_print(i)
1477 samp%c1c3l0_log(ic1,jc3,il0) = valid
1481 if (nam%mask_check)
then 1482 write(mpl%info,
'(a)')
'100%' 1483 call flush(mpl%info)
1497 class(samp_type),
intent(inout) :: samp
1498 type(mpl_type),
intent(in) :: mpl
1499 type(nam_type),
intent(in) :: nam
1500 type(geom_type),
intent(in) :: geom
1503 integer :: ic0a,ic0,ic1a,ic1
1506 allocate(samp%lcheck_c0a(geom%nc0))
1507 allocate(samp%lcheck_c1a(nam%nc1))
1512 samp%lcheck_c0a = .false.
1513 samp%lcheck_c1a = .false.
1515 ic0 = geom%c0a_to_c0(ic0a)
1516 if (geom%c0_to_proc(ic0)==mpl%myproc) samp%lcheck_c0a(ic0) = .true.
1519 ic0 = samp%c1_to_c0(ic1)
1520 if (geom%c0_to_proc(ic0)==mpl%myproc) samp%lcheck_c1a(ic1) = .true.
1524 samp%nc1a = count(samp%lcheck_c1a)
1529 allocate(samp%c1a_to_c1(samp%nc1a))
1530 allocate(samp%c1_to_c1a(nam%nc1))
1533 if (samp%lcheck_c1a(ic1))
then 1535 samp%c1a_to_c1(ic1a) = ic1
1536 samp%c1_to_c1a(ic1) = ic1a
1541 write(mpl%info,
'(a7,a,i4)')
'',
'Parameters for processor #',mpl%myproc
1542 write(mpl%info,
'(a10,a,i8)')
'',
'nc0 = ',geom%nc0
1543 write(mpl%info,
'(a10,a,i8)')
'',
'nc0a = ',geom%nc0a
1544 write(mpl%info,
'(a10,a,i8)')
'',
'nl0 = ',geom%nl0
1545 write(mpl%info,
'(a10,a,i8)')
'',
'nc1 = ',nam%nc1
1546 write(mpl%info,
'(a10,a,i8)')
'',
'nc1a = ',samp%nc1a
1547 call flush(mpl%info)
1560 class(samp_type),
intent(inout) :: samp
1561 type(mpl_type),
intent(inout) :: mpl
1562 type(nam_type),
intent(in) :: nam
1563 type(geom_type),
intent(in) :: geom
1566 integer :: iproc,ic0,ic2a,ic2b,ic2,jc2,i_s,i_s_loc,h_n_s_max,il0i,h_n_s_max_loc
1567 integer,
allocatable :: interph_lg(:,:)
1572 h_n_s_max =
max(h_n_s_max,samp%hfull(il0i)%n_s)
1574 allocate(samp%c2_to_proc(nam%nc2))
1575 allocate(samp%proc_to_nc2a(mpl%nproc))
1576 allocate(samp%h(geom%nl0i))
1577 allocate(samp%lcheck_c2a(nam%nc2))
1578 allocate(samp%lcheck_c2b(nam%nc2))
1579 allocate(samp%lcheck_h(h_n_s_max,geom%nl0i))
1584 samp%lcheck_c2a = .false.
1586 ic0 = samp%c2_to_c0(ic2)
1587 if (geom%c0_to_proc(ic0)==mpl%myproc) samp%lcheck_c2a(ic2) = .true.
1591 samp%lcheck_h = .false.
1592 samp%lcheck_c2b = .false.
1594 do i_s=1,samp%hfull(il0i)%n_s
1595 ic0 = samp%hfull(il0i)%row(i_s)
1596 iproc = geom%c0_to_proc(ic0)
1597 if (iproc==mpl%myproc)
then 1598 jc2 = samp%hfull(il0i)%col(i_s)
1599 samp%lcheck_h(i_s,il0i) = .true.
1600 samp%lcheck_c2b(jc2) = .true.
1606 samp%nc2a = count(samp%lcheck_c2a)
1608 samp%h(il0i)%n_s = count(samp%lcheck_h(:,il0i))
1610 samp%nc2b = count(samp%lcheck_c2b)
1615 allocate(samp%c2a_to_c2(samp%nc2a))
1616 allocate(samp%c2_to_c2a(nam%nc2))
1619 if (samp%lcheck_c2a(ic2))
then 1621 samp%c2a_to_c2(ic2a) = ic2
1624 call mpl%glb_to_loc_index(samp%nc2a,samp%c2a_to_c2,nam%nc2,samp%c2_to_c2a)
1627 allocate(samp%c2b_to_c2(samp%nc2b))
1628 allocate(samp%c2_to_c2b(nam%nc2))
1631 if (samp%lcheck_c2b(ic2))
then 1633 samp%c2b_to_c2(ic2b) = ic2
1634 samp%c2_to_c2b(ic2) = ic2b
1639 allocate(samp%c2a_to_c2b(samp%nc2a))
1641 ic2 = samp%c2a_to_c2(ic2a)
1642 ic2b = samp%c2_to_c2b(ic2)
1643 samp%c2a_to_c2b(ic2a) = ic2b
1649 h_n_s_max_loc =
max(h_n_s_max_loc,samp%h(il0i)%n_s)
1651 allocate(interph_lg(h_n_s_max_loc,geom%nl0i))
1654 do i_s=1,samp%hfull(il0i)%n_s
1655 if (samp%lcheck_h(i_s,il0i))
then 1657 interph_lg(i_s_loc,il0i) = i_s
1666 write(samp%h(il0i)%prefix,
'(a,i3.3)')
'h_',il0i
1667 samp%h(il0i)%n_src = samp%nc2b
1668 samp%h(il0i)%n_dst = geom%nc0a
1669 call samp%h(il0i)%alloc
1670 do i_s_loc=1,samp%h(il0i)%n_s
1671 i_s = interph_lg(i_s_loc,il0i)
1672 samp%h(il0i)%row(i_s_loc) = geom%c0_to_c0a(samp%hfull(il0i)%row(i_s))
1673 samp%h(il0i)%col(i_s_loc) = samp%c2_to_c2b(samp%hfull(il0i)%col(i_s))
1674 samp%h(il0i)%S(i_s_loc) = samp%hfull(il0i)%S(i_s)
1676 call samp%h(il0i)%reorder(mpl)
1681 ic0 = samp%c2_to_c0(ic2)
1682 samp%c2_to_proc(ic2) = geom%c0_to_proc(ic0)
1684 do iproc=1,mpl%nproc
1685 samp%proc_to_nc2a(iproc) = count(samp%c2_to_proc==iproc)
1689 call samp%com_AB%setup(mpl,
'com_AB',nam%nc2,samp%nc2a,samp%nc2b,samp%c2b_to_c2,samp%c2a_to_c2b,samp%c2_to_proc, &
1693 write(mpl%info,
'(a7,a,i4)')
'',
'Parameters for processor #',mpl%myproc
1694 write(mpl%info,
'(a10,a,i8)')
'',
'nc2 = ',nam%nc2
1695 write(mpl%info,
'(a10,a,i8)')
'',
'nc2a = ',samp%nc2a
1696 write(mpl%info,
'(a10,a,i8)')
'',
'nc2b = ',samp%nc2b
1698 write(mpl%info,
'(a10,a,i3,a,i8)')
'',
'h(',il0i,
')%n_s = ',samp%h(il0i)%n_s
1700 call flush(mpl%info)
1713 class(samp_type),
intent(inout) :: samp
1714 type(mpl_type),
intent(inout) :: mpl
1715 type(nam_type),
intent(in) :: nam
1716 type(geom_type),
intent(in) :: geom
1719 integer :: ic0,ic0a,ic0d,ic1,ic2,ic2a,jc0,jc1
1722 allocate(samp%lcheck_c0d(geom%nc0))
1727 samp%lcheck_c0d = samp%lcheck_c0a
1729 ic2 = samp%c2a_to_c2(ic2a)
1730 ic1 = samp%c2_to_c1(ic2)
1732 if (samp%displ_mask(jc1,ic2))
then 1733 jc0 = samp%c1_to_c0(jc1)
1734 samp%lcheck_c0d(jc0) = .true.
1738 samp%nc0d = count(samp%lcheck_c0d)
1743 allocate(samp%c0d_to_c0(samp%nc0d))
1744 allocate(samp%c0_to_c0d(geom%nc0))
1745 call msi(samp%c0_to_c0d)
1748 if (samp%lcheck_c0d(ic0))
then 1750 samp%c0d_to_c0(ic0d) = ic0
1751 samp%c0_to_c0d(ic0) = ic0d
1756 allocate(samp%c0a_to_c0d(geom%nc0a))
1758 ic0 = geom%c0a_to_c0(ic0a)
1759 ic0d = samp%c0_to_c0d(ic0)
1760 samp%c0a_to_c0d(ic0a) = ic0d
1764 call samp%com_AD%setup(mpl,
'com_AD',geom%nc0,geom%nc0a,samp%nc0d,samp%c0d_to_c0,samp%c0a_to_c0d,geom%c0_to_proc,geom%c0_to_c0a)
1767 write(mpl%info,
'(a7,a,i4)')
'',
'Parameters for processor #',mpl%myproc
1768 write(mpl%info,
'(a10,a,i8)')
'',
'nc0d = ',samp%nc0d
1769 call flush(mpl%info)
1782 class(samp_type),
intent(inout) :: samp
1783 type(mpl_type),
intent(inout) :: mpl
1784 type(nam_type),
intent(in) :: nam
1785 type(geom_type),
intent(in) :: geom
1788 integer :: jc3,ic0,ic0a,ic0c,ic1,ic1a,its,il0,d_n_s_max,d_n_s_max_loc,i_s,i_s_loc
1789 integer,
allocatable :: interpd_lg(:,:,:)
1790 real(kind_real),
allocatable :: displ_lon(:,:),displ_lat(:,:),lon_c1(:),lat_c1(:)
1791 type(linop_type),
allocatable :: dfull(:,:)
1793 if (nam%displ_diag)
then 1795 allocate(dfull(geom%nl0,nam%nts))
1796 allocate(displ_lon(geom%nc0,geom%nl0))
1797 allocate(displ_lat(geom%nc0,geom%nl0))
1798 allocate(lon_c1(nam%nc1))
1799 allocate(lat_c1(nam%nc1))
1804 call mpl%loc_to_glb(geom%nl0,geom%nc0a,samp%displ_lon(:,:,its),geom%nc0,geom%c0_to_proc,geom%c0_to_c0a,.true.,displ_lon)
1805 call mpl%loc_to_glb(geom%nl0,geom%nc0a,samp%displ_lat(:,:,its),geom%nc0,geom%c0_to_proc,geom%c0_to_c0a,.true.,displ_lat)
1810 ic0 = samp%c1_to_c0(ic1)
1811 lon_c1(ic1) = displ_lon(ic0,il0)
1812 lat_c1(ic1) = displ_lat(ic0,il0)
1816 call dfull(il0,its)%interp(mpl,geom%mesh,geom%kdtree,geom%nc0,geom%mask_c0(:,il0),nam%nc1,lon_c1,lat_c1, &
1817 & samp%c1l0_log(:,il0),nam%diag_interp)
1823 if (nam%displ_diag)
then 1827 d_n_s_max =
max(d_n_s_max,dfull(il0,its)%n_s)
1830 allocate(samp%lcheck_d(d_n_s_max,geom%nl0,nam%nts))
1831 allocate(samp%d(geom%nl0,nam%nts))
1833 allocate(samp%lcheck_c0c(geom%nc0))
1836 samp%lcheck_c0c = samp%lcheck_c0a
1839 ic1 = samp%c1a_to_c1(ic1a)
1840 if (any(samp%c1c3l0_log(ic1,jc3,:)))
then 1841 ic0 = samp%c1c3_to_c0(ic1,jc3)
1842 samp%lcheck_c0c(ic0) = .true.
1846 if (nam%displ_diag)
then 1847 samp%lcheck_d = .false.
1850 do i_s=1,dfull(il0,its)%n_s
1851 ic0 = dfull(il0,its)%col(i_s)
1852 ic1 = dfull(il0,its)%row(i_s)
1853 if (samp%lcheck_c1a(ic1))
then 1854 samp%lcheck_c0c(ic0) = .true.
1855 samp%lcheck_d(i_s,il0,its) = .true.
1861 samp%nc0c = count(samp%lcheck_c0c)
1862 if (nam%displ_diag)
then 1865 samp%d(il0,its)%n_s = count(samp%lcheck_d(:,il0,its))
1873 allocate(samp%c0c_to_c0(samp%nc0c))
1874 allocate(samp%c0_to_c0c(geom%nc0))
1875 call msi(samp%c0_to_c0c)
1878 if (samp%lcheck_c0c(ic0))
then 1880 samp%c0c_to_c0(ic0c) = ic0
1881 samp%c0_to_c0c(ic0) = ic0c
1886 allocate(samp%c0a_to_c0c(geom%nc0a))
1888 ic0 = geom%c0a_to_c0(ic0a)
1889 ic0c = samp%c0_to_c0c(ic0)
1890 samp%c0a_to_c0c(ic0a) = ic0c
1893 if (nam%displ_diag)
then 1898 d_n_s_max_loc =
max(d_n_s_max_loc,samp%d(il0,its)%n_s)
1901 allocate(interpd_lg(d_n_s_max_loc,geom%nl0,nam%nts))
1905 do i_s=1,dfull(il0,its)%n_s
1906 if (samp%lcheck_d(i_s,il0,its))
then 1908 interpd_lg(i_s_loc,il0,its) = i_s
1917 write(samp%d(il0,its)%prefix,
'(a,i3.3,a,i2.2)')
'd_',il0,
'_',its
1918 samp%d(il0,its)%n_src = samp%nc0c
1919 samp%d(il0,its)%n_dst = samp%nc1a
1920 call samp%d(il0,its)%alloc
1921 do i_s_loc=1,samp%d(il0,its)%n_s
1922 i_s = interpd_lg(i_s_loc,il0,its)
1923 samp%d(il0,its)%row(i_s_loc) = samp%c1_to_c1a(dfull(il0,its)%row(i_s))
1924 samp%d(il0,its)%col(i_s_loc) = samp%c0_to_c0c(dfull(il0,its)%col(i_s))
1925 samp%d(il0,its)%S(i_s_loc) = dfull(il0,its)%S(i_s)
1927 call samp%d(il0,its)%reorder(mpl)
1933 call samp%com_AC%setup(mpl,
'com_AC',geom%nc0,geom%nc0a,samp%nc0c,samp%c0c_to_c0,samp%c0a_to_c0c,geom%c0_to_proc,geom%c0_to_c0a)
1936 write(mpl%info,
'(a7,a,i4)')
'',
'Parameters for processor #',mpl%myproc
1937 write(mpl%info,
'(a10,a,i8)')
'',
'nc0c = ',samp%nc0c
1938 call flush(mpl%info)
1951 class(samp_type),
intent(inout) :: samp
1952 type(mpl_type),
intent(inout) :: mpl
1953 type(nam_type),
intent(in) :: nam
1954 type(geom_type),
intent(in) :: geom
1957 integer :: ic2,ic1,jc2,ic2a,ic2f,il0,kc2
1960 allocate(samp%lcheck_c2f(nam%nc2))
1966 samp%lcheck_c2f = samp%lcheck_c2a
1968 ic2 = samp%c2a_to_c2(ic2a)
1969 ic1 = samp%c2_to_c1(ic2)
1971 do while (samp%nn_c2_dist(jc2,ic2,
min(il0,geom%nl0i))<nam%diag_rhflt)
1972 kc2 = samp%nn_c2_index(jc2,ic2,
min(il0,geom%nl0i))
1973 samp%lcheck_c2f(kc2) = .true.
1975 if (jc2>nam%nc2)
exit 1979 samp%nc2f = count(samp%lcheck_c2f)
1984 allocate(samp%c2f_to_c2(samp%nc2f))
1985 allocate(samp%c2_to_c2f(nam%nc2))
1986 call msi(samp%c2_to_c2f)
1989 if (samp%lcheck_c2f(ic2))
then 1991 samp%c2f_to_c2(ic2f) = ic2
1992 samp%c2_to_c2f(ic2) = ic2f
1997 allocate(samp%c2a_to_c2f(samp%nc2a))
1999 ic2 = samp%c2a_to_c2(ic2a)
2000 ic2f = samp%c2_to_c2f(ic2)
2001 samp%c2a_to_c2f(ic2a) = ic2f
2005 call samp%com_AF%setup(mpl,
'com_AF',nam%nc2,samp%nc2a,samp%nc2f,samp%c2f_to_c2,samp%c2a_to_c2f,samp%c2_to_proc, &
2009 write(mpl%info,
'(a7,a,i4)')
'',
'Parameters for processor #',mpl%myproc
2010 write(mpl%info,
'(a10,a,i8)')
'',
'nc2f = ',samp%nc2f
2011 call flush(mpl%info)
2024 class(samp_type),
intent(in) :: samp
2025 type(mpl_type),
intent(inout) :: mpl
2026 type(nam_type),
intent(in) :: nam
2027 type(geom_type),
intent(in) :: geom
2028 integer,
intent(in) :: il0
2029 character(len=*),
intent(in) :: filter_type
2030 real(kind_real),
intent(in) :: rflt
2031 real(kind_real),
intent(inout) :: diag(samp%nc2a)
2034 integer :: ic2a,ic2,ic1,jc2,nc2eff,kc2,kc2_glb
2035 integer,
allocatable :: order(:)
2036 real(kind_real) :: distnorm,norm,wgt
2037 real(kind_real),
allocatable :: diag_glb(:),diag_eff(:),diag_eff_dist(:)
2041 nam_rad = .not.(abs(rflt-nam%diag_rhflt)>0.0)
2046 allocate(diag_glb(samp%nc2f))
2049 call samp%com_AF%ext(mpl,diag,diag_glb)
2052 allocate(diag_glb(nam%nc2))
2055 call mpl%loc_to_glb(samp%nc2a,diag,nam%nc2,samp%c2_to_proc,samp%c2_to_c2a,.true.,diag_glb)
2061 ic2 = samp%c2a_to_c2(ic2a)
2062 ic1 = samp%c2_to_c1(ic2)
2065 allocate(diag_eff(nam%nc2))
2066 allocate(diag_eff_dist(nam%nc2))
2071 do while (samp%nn_c2_dist(jc2,ic2,
min(il0,geom%nl0i))<rflt)
2073 kc2 = samp%nn_c2_index(jc2,ic2,
min(il0,geom%nl0i))
2075 kc2_glb = samp%c2_to_c2f(kc2)
2079 if (
isnotmsr(diag_glb(kc2_glb)))
then 2081 diag_eff(nc2eff) = diag_glb(kc2_glb)
2082 diag_eff_dist(nc2eff) = samp%nn_c2_dist(jc2,ic2,
min(il0,geom%nl0i))
2085 if (jc2>nam%nc2)
exit 2090 select case (trim(filter_type))
2093 diag(ic2a) = sum(diag_eff(1:nc2eff))/
real(nc2eff,kind_real)
2099 distnorm = diag_eff_dist(jc2)/rflt
2100 wgt =
gc99(mpl,distnorm)
2101 diag(ic2a) = diag(ic2a)+wgt*diag_eff(jc2)
2104 if (norm>0.0) diag(ic2a) = diag(ic2a)/norm
2107 allocate(order(nc2eff))
2108 call qsort(nc2eff,diag_eff(1:nc2eff),order)
2109 if (mod(nc2eff,2)==0)
then 2110 diag(ic2a) = 0.5*(diag_eff(nc2eff/2)+diag_eff(nc2eff/2+1))
2112 diag(ic2a) = diag_eff((nc2eff+1)/2)
2117 call mpl%abort(
'wrong filter type')
2120 call msr(diag(ic2a))
2124 deallocate(diag_eff)
2125 deallocate(diag_eff_dist)
2141 class(samp_type),
intent(in) :: samp
2142 type(mpl_type),
intent(inout) :: mpl
2143 type(nam_type),
intent(in) :: nam
2144 type(geom_type),
intent(in) :: geom
2145 integer,
intent(in) :: il0
2146 real(kind_real),
intent(inout) :: diag(samp%nc2a)
2149 integer :: nmsr,nmsr_tot,ic2,jc2,kc2
2150 real(kind_real),
allocatable :: diag_glb(:)
2153 if (samp%nc2a>0)
then 2154 nmsr = count(
ismsr(diag))
2158 call mpl%f_comm%allreduce(nmsr,nmsr_tot,fckit_mpi_sum())
2160 if (nmsr_tot>0)
then 2162 allocate(diag_glb(nam%nc2))
2165 call mpl%loc_to_glb(samp%nc2a,diag,nam%nc2,samp%c2_to_proc,samp%c2_to_c2a,.false.,diag_glb)
2170 do while (
ismsr(diag_glb(ic2)))
2171 kc2 = samp%nn_c2_index(jc2,ic2,
min(il0,geom%nl0i))
2172 if (
isnotmsr(diag_glb(kc2))) diag_glb(ic2) = diag_glb(kc2)
2174 if (jc2>nam%nc2)
exit 2180 call mpl%glb_to_loc(nam%nc2,samp%c2_to_proc,samp%c2_to_c2a,diag_glb,samp%nc2a,diag)
2183 deallocate(diag_glb)
real(kind_real), parameter lcoast
subroutine samp_dealloc(samp, geom)
subroutine samp_diag_filter(samp, mpl, nam, geom, il0, filter_type, rflt, diag)
subroutine samp_read(samp, mpl, nam, geom, bpar, ios)
subroutine samp_compute_mpi_a(samp, mpl, nam, geom)
subroutine samp_compute_sampling_mask(samp, mpl, nam, geom)
subroutine samp_alloc(samp, nam, geom)
real(kind_real), parameter rcoast
subroutine samp_write(samp, mpl, nam, geom, bpar)
real(kind=kind_real), parameter req
Earth radius at equator (m)
subroutine samp_compute_mpi_f(samp, mpl, nam, geom)
subroutine samp_compute_mpi_d(samp, mpl, nam, geom)
subroutine samp_diag_fill(samp, mpl, nam, geom, il0, diag)
subroutine samp_compute_mask(samp, mpl, nam, geom, ens)
subroutine samp_compute_sampling_zs(samp, mpl, rng, nam, geom)
subroutine samp_setup_sampling(samp, mpl, rng, nam, geom, bpar, io, ens)
integer, parameter, public kind_real
subroutine samp_compute_sampling_lct(samp, mpl, nam, geom)
subroutine samp_compute_sampling_ps(samp, mpl, rng, nam, geom)
subroutine samp_compute_mpi_ab(samp, mpl, nam, geom)
subroutine samp_compute_mpi_c(samp, mpl, nam, geom)
real(fp), parameter, public pi