24 real(kind_real),
parameter ::
cor_min = 0.5_kind_real
25 real(kind_real),
parameter ::
dscale = 10.0_kind_real
26 logical,
parameter ::
lprt = .false.
35 real(kind_real),
allocatable :: raw(:,:,:,:)
38 real(kind_real),
allocatable :: d(:,:,:,:)
39 real(kind_real),
allocatable :: coef(:,:,:)
40 real(kind_real),
allocatable :: fit(:,:,:,:)
43 real(kind_real),
allocatable :: d_filt(:,:,:,:)
44 real(kind_real),
allocatable :: coef_filt(:,:,:)
45 real(kind_real),
allocatable :: fit_filt(:,:,:,:)
48 real(kind_real),
allocatable :: d11(:,:,:)
49 real(kind_real),
allocatable :: d22(:,:,:)
50 real(kind_real),
allocatable :: d33(:,:,:)
51 real(kind_real),
allocatable :: d12(:,:,:)
52 real(kind_real),
allocatable :: h11(:,:,:)
53 real(kind_real),
allocatable :: h22(:,:,:)
54 real(kind_real),
allocatable :: h33(:,:,:)
55 real(kind_real),
allocatable :: h12(:,:,:)
56 real(kind_real),
allocatable :: dcoef(:,:,:)
57 real(kind_real),
allocatable :: dlh(:,:,:)
79 class(lct_blk_type),
intent(inout) :: lct_blk
80 type(nam_type),
intent(in) :: nam
81 type(geom_type),
intent(in) :: geom
82 type(bpar_type),
intent(in) :: bpar
83 type(samp_type),
intent(in) :: samp
84 integer,
intent(in) :: ib
88 lct_blk%nscales = nam%lct_nscales
91 allocate(lct_blk%raw(nam%nc3,bpar%nl0r(ib),samp%nc1a,geom%nl0))
92 allocate(lct_blk%D(4,lct_blk%nscales,samp%nc1a,geom%nl0))
93 allocate(lct_blk%coef(lct_blk%nscales,samp%nc1a,geom%nl0))
94 allocate(lct_blk%fit(nam%nc3,bpar%nl0r(ib),samp%nc1a,geom%nl0))
95 if (nam%diag_rhflt>0)
then 96 allocate(lct_blk%D_filt(4,lct_blk%nscales,samp%nc1a,geom%nl0))
97 allocate(lct_blk%coef_filt(lct_blk%nscales,samp%nc1a,geom%nl0))
98 allocate(lct_blk%fit_filt(nam%nc3,bpar%nl0r(ib),samp%nc1a,geom%nl0))
100 allocate(lct_blk%D11(geom%nc0a,geom%nl0,lct_blk%nscales))
101 allocate(lct_blk%D22(geom%nc0a,geom%nl0,lct_blk%nscales))
102 allocate(lct_blk%D33(geom%nc0a,geom%nl0,lct_blk%nscales))
103 allocate(lct_blk%D12(geom%nc0a,geom%nl0,lct_blk%nscales))
104 allocate(lct_blk%H11(geom%nc0a,geom%nl0,lct_blk%nscales))
105 allocate(lct_blk%H22(geom%nc0a,geom%nl0,lct_blk%nscales))
106 allocate(lct_blk%H33(geom%nc0a,geom%nl0,lct_blk%nscales))
107 allocate(lct_blk%H12(geom%nc0a,geom%nl0,lct_blk%nscales))
108 allocate(lct_blk%Dcoef(geom%nc0a,geom%nl0,lct_blk%nscales))
109 allocate(lct_blk%DLh(geom%nc0a,geom%nl0,lct_blk%nscales))
112 call msr(lct_blk%raw)
114 call msr(lct_blk%coef)
115 call msr(lct_blk%fit)
116 if (nam%diag_rhflt>0)
then 118 call msr(lct_blk%coef)
119 call msr(lct_blk%fit)
121 call msr(lct_blk%D11)
122 call msr(lct_blk%D22)
123 call msr(lct_blk%D33)
124 call msr(lct_blk%D12)
125 call msr(lct_blk%H11)
126 call msr(lct_blk%H22)
127 call msr(lct_blk%H33)
128 call msr(lct_blk%H12)
129 call msr(lct_blk%Dcoef)
130 call msr(lct_blk%DLh)
143 class(lct_blk_type),
intent(inout) :: lct_blk
146 if (
allocated(lct_blk%raw))
deallocate(lct_blk%raw)
147 if (
allocated(lct_blk%D))
deallocate(lct_blk%D)
148 if (
allocated(lct_blk%coef))
deallocate(lct_blk%coef)
149 if (
allocated(lct_blk%fit))
deallocate(lct_blk%fit)
150 if (
allocated(lct_blk%D_filt))
deallocate(lct_blk%D_filt)
151 if (
allocated(lct_blk%coef_filt))
deallocate(lct_blk%coef_filt)
152 if (
allocated(lct_blk%fit_filt))
deallocate(lct_blk%fit_filt)
153 if (
allocated(lct_blk%D11))
deallocate(lct_blk%D11)
154 if (
allocated(lct_blk%D22))
deallocate(lct_blk%D22)
155 if (
allocated(lct_blk%D33))
deallocate(lct_blk%D33)
156 if (
allocated(lct_blk%D12))
deallocate(lct_blk%D12)
157 if (
allocated(lct_blk%H11))
deallocate(lct_blk%H11)
158 if (
allocated(lct_blk%H22))
deallocate(lct_blk%H22)
159 if (
allocated(lct_blk%H33))
deallocate(lct_blk%H33)
160 if (
allocated(lct_blk%H12))
deallocate(lct_blk%H12)
161 if (
allocated(lct_blk%Dcoef))
deallocate(lct_blk%Dcoef)
162 if (
allocated(lct_blk%DLh))
deallocate(lct_blk%DLh)
175 class(lct_blk_type),
intent(inout) :: lct_blk
176 type(nam_type),
intent(in) :: nam
177 type(geom_type),
intent(in) :: geom
178 type(bpar_type),
intent(in) :: bpar
179 type(samp_type),
intent(in) :: samp
180 type(mom_blk_type),
intent(in) :: mom_blk
183 integer :: jsub,il0,jl0r,jl0,jc3,ic1a,ic1
184 real(kind_real) :: den
185 real(kind_real),
allocatable :: norm(:,:,:,:)
188 associate(ib=>lct_blk%ib)
191 allocate(norm(nam%nc3,bpar%nl0r(ib),samp%nc1a,geom%nl0))
198 do jsub=1,mom_blk%nsub
200 do jl0r=1,bpar%nl0r(ib)
201 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
204 ic1 = samp%c1a_to_c1(ic1a)
205 if (samp%c1l0_log(ic1,il0))
then 206 den = mom_blk%m2_1(ic1a,jc3,il0,jsub)*mom_blk%m2_2(ic1a,jc3,jl0,jsub)
208 lct_blk%raw(jc3,jl0r,ic1a,il0) = lct_blk%raw(jc3,jl0r,ic1a,il0)+mom_blk%m11(ic1a,jc3,jl0r,il0,jsub)/sqrt(den)
209 norm(jc3,jl0r,ic1a,il0) = norm(jc3,jl0r,ic1a,il0)+1.0
220 do jl0r=1,bpar%nl0r(ib)
223 ic1 = samp%c1a_to_c1(ic1a)
224 if (samp%c1l0_log(ic1,il0))
then 225 if (norm(jc3,jl0r,ic1a,il0)>0.0) lct_blk%raw(jc3,jl0r,ic1a,il0) = lct_blk%raw(jc3,jl0r,ic1a,il0) &
226 & /norm(jc3,jl0r,ic1a,il0)
247 class(lct_blk_type),
intent(inout) :: lct_blk
248 type(mpl_type),
intent(inout) :: mpl
249 type(nam_type),
intent(in) :: nam
250 type(geom_type),
intent(in) :: geom
251 type(bpar_type),
intent(in) :: bpar
252 type(samp_type),
intent(in) :: samp
255 integer :: il0,jl0r,jl0,ic1a,ic1,ic0,jc3,jc0,iscales,icomp
256 real(kind_real) :: distsq,Dhbar,Dvbar,diag_rescale
257 real(kind_real),
allocatable :: Dh(:),Dv(:),dx(:,:),dy(:,:),dz(:,:)
259 logical,
allocatable :: dmask(:,:)
260 type(minim_type) :: minim
263 associate(ib=>lct_blk%ib)
266 allocate(dh(nam%nc3))
267 allocate(dv(bpar%nl0r(ib)))
268 allocate(dx(nam%nc3,bpar%nl0r(ib)))
269 allocate(dy(nam%nc3,bpar%nl0r(ib)))
270 allocate(dz(nam%nc3,bpar%nl0r(ib)))
271 allocate(dmask(nam%nc3,bpar%nl0r(ib)))
272 minim%nx = lct_blk%nscales*4
273 if (lct_blk%nscales>1) minim%nx = minim%nx+lct_blk%nscales-1
274 minim%ny = nam%nc3*bpar%nl0r(ib)
275 allocate(minim%x(minim%nx))
276 allocate(minim%guess(minim%nx))
277 allocate(minim%binf(minim%nx))
278 allocate(minim%bsup(minim%nx))
279 allocate(minim%obs(minim%ny))
280 allocate(minim%dx(nam%nc3,bpar%nl0r(ib)))
281 allocate(minim%dy(nam%nc3,bpar%nl0r(ib)))
282 allocate(minim%dz(nam%nc3,bpar%nl0r(ib)))
283 allocate(minim%dmask(nam%nc3,bpar%nl0r(ib)))
286 write(mpl%info,
'(a13,a,i3,a)',advance=
'no')
'',
'Level ',nam%levs(il0),
':' 290 call mpl%prog_init(samp%nc1a)
294 ic1 = samp%c1a_to_c1(ic1a)
296 if (samp%c1l0_log(ic1,il0))
then 298 ic0 = samp%c1_to_c0(ic1)
299 do jl0r=1,bpar%nl0r(ib)
300 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
302 dmask(jc3,jl0r) = samp%c1l0_log(ic1,il0).and.samp%c1c3l0_log(ic1,jc3,jl0)
303 if (dmask(jc3,jl0r))
then 304 jc0 = samp%c1c3_to_c0(ic1,jc3)
305 call geom%compute_deltas(ic0,il0,jc0,jl0,dx(jc3,jl0r),dy(jc3,jl0r),dz(jc3,jl0r))
312 do jl0r=1,bpar%nl0r(ib)
313 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
316 if (dmask(jc3,jl0r))
then 317 distsq = dx(jc3,jl0r)**2+dy(jc3,jl0r)**2
318 if ((lct_blk%raw(jc3,jl0r,ic1a,il0)>
cor_min).and.(lct_blk%raw(jc3,jl0r,ic1a,il0)<1.0).and.(distsq>0.0)) &
319 & dh(jc3) = -distsq/(2.0*log(lct_blk%raw(jc3,jl0r,ic1a,il0)))
325 if (count(isnotmsr(dh))>0) dhbar = sum(dh,mask=isnotmsr(dh))/
real(count(isnotmsr(Dh)),kind_real)
330 do jl0r=1,bpar%nl0r(ib)
331 if (dmask(jc3,jl0r))
then 332 distsq = dz(jc3,jl0r)**2
333 if ((lct_blk%raw(jc3,jl0r,ic1a,il0)>
cor_min).and.(lct_blk%raw(jc3,jl0r,ic1a,il0)<1.0).and.(distsq>0.0)) &
334 & dv(jl0r) = -distsq/(2.0*log(lct_blk%raw(jc3,jl0r,ic1a,il0)))
337 if (bpar%nl0r(ib)>1)
then 338 if (count(isnotmsr(dv))>0) dvbar = sum(dv,mask=isnotmsr(dv))/
real(count(isnotmsr(Dv)),kind_real)
343 if (isnotmsr(dhbar).and.(isnotmsr(dvbar)))
then 345 do iscales=1,lct_blk%nscales
346 minim%guess((iscales-1)*4+1:(iscales-1)*4+3) = (/dhbar,dhbar,dvbar/)*
dscale**(iscales-1)
347 if (lct_blk%nscales==1)
then 348 minim%binf((iscales-1)*4+1:(iscales-1)*4+3) = (/1.0/
dscale,1.0/
dscale,1.0/
dscale/)*minim%guess(1:3)
349 minim%bsup((iscales-1)*4+1:(iscales-1)*4+3) = (/
dscale,
dscale,
dscale/)*minim%guess(1:3)
351 minim%binf((iscales-1)*4+1:(iscales-1)*4+3) = (/1.0/sqrt(
dscale),1.0/sqrt(
dscale),1.0/sqrt(
dscale)/) &
352 & *minim%guess(1:3)*
dscale**(iscales-1)
353 minim%bsup((iscales-1)*4+1:(iscales-1)*4+3) = (/sqrt(
dscale),sqrt(
dscale),sqrt(
dscale)/)*minim%guess(1:3) &
356 minim%guess((iscales-1)*4+4) = 0.0
357 minim%binf((iscales-1)*4+4) = -1.0
358 minim%bsup((iscales-1)*4+4) = 1.0
360 do iscales=1,lct_blk%nscales-1
361 minim%guess(lct_blk%nscales*4+1) = 1.0/
real(lct_blk%nscales,kind_real)
362 minim%binf(lct_blk%nscales*4+1) = 0.1
363 minim%bsup(lct_blk%nscales*4+1) = 1.0
367 minim%obs = pack(lct_blk%raw(:,:,ic1a,il0),.true.)
368 minim%cost_function =
'fit_lct' 369 minim%algo = trim(nam%minim_algo)
371 minim%nl0 = bpar%nl0r(ib)
376 minim%nscales = lct_blk%nscales
379 call minim%compute(mpl,
lprt)
382 do iscales=1,lct_blk%nscales
384 lct_blk%D(icomp,iscales,ic1a,il0) = minim%x((iscales-1)*4+icomp)
387 if (lct_blk%nscales>1)
then 388 lct_blk%coef(1:lct_blk%nscales-1,ic1a,il0) = minim%x(lct_blk%nscales*4+1:lct_blk%nscales*4+lct_blk%nscales-1)
389 lct_blk%coef(lct_blk%nscales,ic1a,il0) = 1.0-sum(lct_blk%coef(1:lct_blk%nscales-1,ic1a,il0))
391 lct_blk%coef(1,ic1a,il0) = 1.0
395 if (bpar%nl0r(ib)==1) lct_blk%D(3,:,ic1a,il0) = 0.0
399 do iscales=1,lct_blk%nscales
401 call check_cond(lct_blk%D(1,iscales,ic1a,il0),lct_blk%D(2,iscales,ic1a,il0),lct_blk%D(4,iscales,ic1a,il0),valid)
402 if (bpar%nl0r(ib)>1) valid = valid.and.(lct_blk%D(3,iscales,ic1a,il0)>0.0)
403 valid = valid.and.(lct_blk%coef(iscales,ic1a,il0)>0.0)
404 if (lct_blk%nscales>1) valid = valid.and.(lct_blk%coef(iscales,ic1a,il0)<1.0)
408 do iscales=1,lct_blk%nscales
409 if (nam%lct_diag(iscales))
then 411 diag_rescale = sqrt(1.0-lct_blk%D(4,iscales,ic1a,il0)**2)
412 lct_blk%D(1,iscales,ic1a,il0) = lct_blk%D(1,iscales,ic1a,il0)*diag_rescale
413 lct_blk%D(2,iscales,ic1a,il0) = lct_blk%D(2,iscales,ic1a,il0)*diag_rescale
414 lct_blk%D(4,iscales,ic1a,il0) = 0.0
419 call fit_lct(mpl,nam%nc3,bpar%nl0r(ib),dx,dy,dz,dmask,lct_blk%nscales, &
420 & lct_blk%D(:,:,ic1a,il0),lct_blk%coef(:,ic1a,il0),lct_blk%fit(:,:,ic1a,il0))
423 call msr(lct_blk%D(:,:,ic1a,il0))
424 call msr(lct_blk%coef(:,ic1a,il0))
425 call msr(lct_blk%fit(:,:,ic1a,il0))
429 call msr(lct_blk%D(:,:,ic1a,il0))
430 call msr(lct_blk%coef(:,ic1a,il0))
431 call msr(lct_blk%fit(:,:,ic1a,il0))
436 call mpl%prog_print(ic1a)
438 write(mpl%info,
'(a)')
'100%' subroutine lct_blk_alloc(lct_blk, nam, geom, bpar, samp, ib)
subroutine lct_blk_correlation(lct_blk, nam, geom, bpar, samp, mom_blk)
subroutine lct_blk_fitting(lct_blk, mpl, nam, geom, bpar, samp)
subroutine lct_blk_dealloc(lct_blk)
real(kind_real), parameter cor_min
real(kind_real), parameter dscale
integer, parameter, public kind_real