29 integer,
parameter ::
nsc = 50
31 real(kind_real),
parameter ::
maxfactor = 2.0_kind_real
37 character(len=1024) :: name
40 real(kind_real),
allocatable :: raw(:,:,:)
41 real(kind_real),
allocatable :: raw_coef_ens(:)
42 real(kind_real) :: raw_coef_sta
43 real(kind_real),
allocatable :: fit(:,:,:)
44 real(kind_real),
allocatable :: fit_rh(:)
45 real(kind_real),
allocatable :: fit_rv(:)
46 real(kind_real),
allocatable :: fit_rv_rfac(:)
47 real(kind_real),
allocatable :: fit_rv_coef(:)
48 real(kind_real),
allocatable :: distv(:,:)
69 subroutine diag_blk_alloc(diag_blk,nam,geom,bpar,samp,ic2a,ib,prefix,double_fit)
74 class(diag_blk_type),
intent(inout) :: diag_blk
75 type(nam_type),
intent(in) :: nam
76 type(geom_type),
intent(in) :: geom
77 type(bpar_type),
intent(in) :: bpar
78 type(samp_type),
intent(in) :: samp
79 integer,
intent(in) :: ic2a
80 integer,
intent(in) :: ib
81 character(len=*),
intent(in) :: prefix
82 logical,
intent(in) :: double_fit
85 integer :: ic0,ic2,il0,jl0
86 real(kind_real) :: vunit(geom%nl0)
91 diag_blk%name = trim(prefix)//
'_'//trim(bpar%blockname(ib))
92 diag_blk%double_fit = double_fit
95 allocate(diag_blk%raw_coef_ens(geom%nl0))
96 if ((ic2a==0).or.nam%local_diag)
allocate(diag_blk%raw(nam%nc3,bpar%nl0r(ib),geom%nl0))
99 call msr(diag_blk%raw_coef_ens)
100 if ((ic2a==0).or.nam%local_diag)
then 101 call msr(diag_blk%raw)
102 call msr(diag_blk%raw_coef_sta)
105 if (((ic2a==0).or.nam%local_diag).and.(trim(nam%minim_algo)/=
'none'))
then 107 allocate(diag_blk%fit(nam%nc3,bpar%nl0r(ib),geom%nl0))
108 allocate(diag_blk%fit_rh(geom%nl0))
109 allocate(diag_blk%fit_rv(geom%nl0))
110 if (diag_blk%double_fit)
then 111 allocate(diag_blk%fit_rv_rfac(geom%nl0))
112 allocate(diag_blk%fit_rv_coef(geom%nl0))
114 allocate(diag_blk%distv(geom%nl0,geom%nl0))
117 call msr(diag_blk%fit)
118 call msr(diag_blk%fit_rh)
119 call msr(diag_blk%fit_rv)
120 if (diag_blk%double_fit)
then 121 call msr(diag_blk%fit_rv_rfac)
122 call msr(diag_blk%fit_rv_coef)
124 call msr(diag_blk%distv)
128 vunit = geom%vunitavg
130 ic2 = samp%c2a_to_c2(ic2a)
131 ic0 = samp%c2_to_c0(ic2)
132 vunit = geom%vunit(ic0,:)
138 diag_blk%distv(jl0,il0) = abs(vunit(il0)-vunit(jl0))
154 class(diag_blk_type),
intent(inout) :: diag_blk
157 if (
allocated(diag_blk%raw))
deallocate(diag_blk%raw)
158 if (
allocated(diag_blk%raw_coef_ens))
deallocate(diag_blk%raw_coef_ens)
159 if (
allocated(diag_blk%fit))
deallocate(diag_blk%fit)
160 if (
allocated(diag_blk%fit_rh))
deallocate(diag_blk%fit_rh)
161 if (
allocated(diag_blk%fit_rv))
deallocate(diag_blk%fit_rv)
162 if (
allocated(diag_blk%fit_rv_rfac))
deallocate(diag_blk%fit_rv_rfac)
163 if (
allocated(diag_blk%fit_rv_coef))
deallocate(diag_blk%fit_rv_coef)
164 if (
allocated(diag_blk%distv))
deallocate(diag_blk%distv)
177 class(diag_blk_type),
intent(inout) :: diag_blk
178 type(mpl_type),
intent(in) :: mpl
179 type(nam_type),
intent(in) :: nam
180 type(geom_type),
intent(in) :: geom
181 type(bpar_type),
intent(in) :: bpar
182 character(len=*),
intent(in) :: filename
185 integer :: info,ncid,one_id,nc3_id,nl0r_id,nl0_1_id,nl0_2_id,disth_id,vunit_id
186 integer :: raw_id,raw_zs_id,raw_coef_ens_id,raw_coef_sta_id,l0rl0_to_l0_id
187 integer :: fit_id,fit_zs_id,fit_rh_id,fit_rv_id,fit_rv_rfac_id,fit_rv_coef_id
188 integer :: il0,jl0r,jl0
189 character(len=1024) :: subr =
'diag_blk_write' 192 associate(ib=>diag_blk%ib,ic2a=>diag_blk%ic2a)
195 info = nf90_create(trim(nam%datadir)//
'/'//trim(filename),or(nf90_noclobber,nf90_64bit_offset),ncid)
196 if (info==nf90_noerr)
then 198 call nam%ncwrite(mpl,ncid)
201 call mpl%ncerr(subr,nf90_open(trim(nam%datadir)//
'/'//trim(filename),nf90_write,ncid))
204 call mpl%ncerr(subr,nf90_redef(ncid))
208 info = nf90_inq_dimid(ncid,
'one',one_id)
209 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_dim(ncid,
'one',1,one_id))
210 info = nf90_inq_dimid(ncid,
'nc3',nc3_id)
211 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_dim(ncid,
'nc3',nam%nc3,nc3_id))
212 info = nf90_inq_dimid(ncid,
'nl0r',nl0r_id)
213 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_dim(ncid,
'nl0r',bpar%nl0rmax,nl0r_id))
214 info = nf90_inq_dimid(ncid,
'nl0_1',nl0_1_id)
215 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_dim(ncid,
'nl0_1',geom%nl0,nl0_1_id))
216 if (bpar%nl0rmax/=geom%nl0)
then 217 info = nf90_inq_dimid(ncid,
'nl0_2',nl0_2_id)
218 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_dim(ncid,
'nl0_2',geom%nl0,nl0_2_id))
220 info = nf90_inq_varid(ncid,
'disth',disth_id)
221 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_var(ncid,
'disth',
ncfloat,(/nc3_id/),disth_id))
222 info = nf90_inq_varid(ncid,
'vunit',vunit_id)
223 if (info/=nf90_noerr)
call mpl%ncerr(subr,nf90_def_var(ncid,
'vunit',
ncfloat,(/nl0_1_id/),vunit_id))
224 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_raw_coef_ens',raw_coef_ens_id)
225 if (info/=nf90_noerr)
then 226 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_raw_coef_ens',
ncfloat,(/nl0_1_id/),raw_coef_ens_id))
227 call mpl%ncerr(subr,nf90_put_att(ncid,raw_coef_ens_id,
'_FillValue',
msvalr))
229 if ((ic2a==0).or.nam%local_diag)
then 230 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_raw',raw_id)
231 if (info/=nf90_noerr)
then 232 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_raw',
ncfloat,(/nc3_id,nl0r_id,nl0_1_id/),raw_id))
233 call mpl%ncerr(subr,nf90_put_att(ncid,raw_id,
'_FillValue',
msvalr))
235 if (bpar%nl0rmax/=geom%nl0)
then 236 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_raw_zs',raw_zs_id)
237 if (info/=nf90_noerr)
then 238 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_raw_zs',
ncfloat,(/nl0_2_id,nl0_1_id/),raw_zs_id))
239 call mpl%ncerr(subr,nf90_put_att(ncid,raw_zs_id,
'_FillValue',
msvalr))
242 if (
isnotmsr(diag_blk%raw_coef_sta))
then 243 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_raw_coef_sta',raw_coef_sta_id)
244 if (info/=nf90_noerr)
then 245 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_raw_coef_sta',
ncfloat,(/one_id/),raw_coef_sta_id))
246 call mpl%ncerr(subr,nf90_put_att(ncid,raw_coef_sta_id,
'_FillValue',
msvalr))
249 if ((trim(nam%minim_algo)/=
'none').and.(
isanynotmsr(diag_blk%fit)))
then 250 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit',fit_id)
251 if (info/=nf90_noerr)
then 252 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit',
ncfloat,(/nc3_id,nl0r_id,nl0_1_id/),fit_id))
253 call mpl%ncerr(subr,nf90_put_att(ncid,fit_id,
'_FillValue',
msvalr))
255 if (bpar%nl0rmax/=geom%nl0)
then 256 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit_zs',fit_zs_id)
257 if (info/=nf90_noerr)
then 258 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit_zs',
ncfloat,(/nl0_2_id,nl0_1_id/),fit_zs_id))
259 call mpl%ncerr(subr,nf90_put_att(ncid,fit_zs_id,
'_FillValue',
msvalr))
262 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit_rh',fit_rh_id)
263 if (info/=nf90_noerr)
then 264 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit_rh',
ncfloat,(/nl0_1_id/),fit_rh_id))
265 call mpl%ncerr(subr,nf90_put_att(ncid,fit_rh_id,
'_FillValue',
msvalr))
267 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit_rv',fit_rv_id)
268 if (info/=nf90_noerr)
then 269 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit_rv',
ncfloat,(/nl0_1_id/),fit_rv_id))
270 call mpl%ncerr(subr,nf90_put_att(ncid,fit_rv_id,
'_FillValue',
msvalr))
272 if (diag_blk%double_fit)
then 273 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit_rv_rfac',fit_rv_rfac_id)
274 if (info/=nf90_noerr)
then 275 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit_rv_rfac',
ncfloat,(/nl0_1_id/),fit_rv_rfac_id))
276 call mpl%ncerr(subr,nf90_put_att(ncid,fit_rv_rfac_id,
'_FillValue',
msvalr))
278 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_fit_rv_coef',fit_rv_coef_id)
279 if (info/=nf90_noerr)
then 280 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_fit_rv_coef',
ncfloat,(/nl0_1_id/),fit_rv_coef_id))
281 call mpl%ncerr(subr,nf90_put_att(ncid,fit_rv_coef_id,
'_FillValue',
msvalr))
285 info = nf90_inq_varid(ncid,trim(diag_blk%name)//
'_l0rl0_to_l0',l0rl0_to_l0_id)
286 if (info/=nf90_noerr)
then 287 call mpl%ncerr(subr,nf90_def_var(ncid,trim(diag_blk%name)//
'_l0rl0_to_l0',nf90_int,(/nl0r_id,nl0_1_id/),l0rl0_to_l0_id))
288 call mpl%ncerr(subr,nf90_put_att(ncid,l0rl0_to_l0_id,
'_FillValue',
msvali))
293 call mpl%ncerr(subr,nf90_enddef(ncid))
296 call mpl%ncerr(subr,nf90_put_var(ncid,disth_id,geom%disth(1:nam%nc3)))
297 call mpl%ncerr(subr,nf90_put_var(ncid,vunit_id,sum(geom%vunit,mask=geom%mask_c0,dim=1)/
real(geom%nc0_mask,kind_real)))
298 call mpl%ncerr(subr,nf90_put_var(ncid,raw_coef_ens_id,diag_blk%raw_coef_ens))
299 if ((ic2a==0).or.nam%local_diag)
then 300 call mpl%ncerr(subr,nf90_put_var(ncid,raw_id,diag_blk%raw))
301 if (bpar%nl0rmax/=geom%nl0)
then 303 do jl0r=1,bpar%nl0rmax
304 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
305 call mpl%ncerr(subr,nf90_put_var(ncid,raw_zs_id,diag_blk%raw(1,jl0r,il0),(/jl0,il0/)))
309 if (
isnotmsr(diag_blk%raw_coef_sta))
call mpl%ncerr(subr,nf90_put_var(ncid,raw_coef_sta_id,diag_blk%raw_coef_sta))
310 if ((trim(nam%minim_algo)/=
'none').and.(
isanynotmsr(diag_blk%fit)))
then 311 call mpl%ncerr(subr,nf90_put_var(ncid,fit_id,diag_blk%fit))
312 if (bpar%nl0rmax/=geom%nl0)
then 314 do jl0r=1,bpar%nl0rmax
315 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
316 call mpl%ncerr(subr,nf90_put_var(ncid,fit_zs_id,diag_blk%fit(1,jl0r,il0),(/jl0,il0/)))
320 call mpl%ncerr(subr,nf90_put_var(ncid,fit_rh_id,diag_blk%fit_rh))
321 call mpl%ncerr(subr,nf90_put_var(ncid,fit_rv_id,diag_blk%fit_rv))
322 if (diag_blk%double_fit)
then 323 call mpl%ncerr(subr,nf90_put_var(ncid,fit_rv_rfac_id,diag_blk%fit_rv_rfac))
324 call mpl%ncerr(subr,nf90_put_var(ncid,fit_rv_coef_id,diag_blk%fit_rv_coef))
327 call mpl%ncerr(subr,nf90_put_var(ncid,l0rl0_to_l0_id,bpar%l0rl0b_to_l0(:,:,ib)))
331 call mpl%ncerr(subr,nf90_close(ncid))
347 class(diag_blk_type),
intent(inout) :: diag_blk
348 type(geom_type),
intent(in) :: geom
349 type(bpar_type),
intent(in) :: bpar
350 logical,
intent(in),
optional :: remove_max
353 integer :: il0,jl0r,jl0,jc3
354 logical :: lremove_max
357 associate(ib=>diag_blk%ib)
361 jl0r = bpar%il0rz(il0,ib)
362 if (isnotmsr(diag_blk%raw(1,jl0r,il0))) diag_blk%raw_coef_ens(il0) = diag_blk%raw(1,jl0r,il0)
367 do jl0r=1,bpar%nl0r(ib)
368 jl0 = bpar%l0rl0b_to_l0(jl0r,il0,ib)
369 do jc3=1,bpar%nc3(ib)
370 if (isnotmsr(diag_blk%raw(jc3,jl0r,il0)).and.isnotmsr(diag_blk%raw_coef_ens(il0)) &
371 & .and.isnotmsr(diag_blk%raw_coef_ens(jl0))) &
372 & diag_blk%raw(jc3,jl0r,il0) = diag_blk%raw(jc3,jl0r,il0)/sqrt(diag_blk%raw_coef_ens(il0)*diag_blk%raw_coef_ens(jl0))
378 if (
present(remove_max))
then 379 lremove_max = remove_max
381 lremove_max = .false.
383 if (lremove_max)
then 386 do jl0r=1,bpar%nl0r(ib)
387 do jc3=1,bpar%nc3(ib)
388 if (sup(diag_blk%raw(jc3,jl0r,il0),
maxfactor))
call msr(diag_blk%raw(jc3,jl0r,il0))
409 class(diag_blk_type),
intent(inout) :: diag_blk
410 type(mpl_type),
intent(in) :: mpl
411 type(nam_type),
intent(in) :: nam
412 type(geom_type),
intent(in) :: geom
413 type(bpar_type),
intent(in) :: bpar
414 type(samp_type),
intent(in) :: samp
417 integer :: ic2,ic0,il0,jl0r,offset,isc
418 real(kind_real) :: alpha,alpha_opt,mse,mse_opt
419 real(kind_real) :: vunit(geom%nl0),fit_rh(geom%nl0),fit_rv(geom%nl0)
420 real(kind_real),
allocatable :: rawv(:),distv(:),fit(:,:,:)
421 type(minim_type) :: minim
424 associate(ic2a=>diag_blk%ic2a,ib=>diag_blk%ib)
427 if (trim(nam%minim_algo)==
'none')
call mpl%abort(
'cannot compute fit if minim_algo = none')
430 allocate(rawv(bpar%nl0r(ib)))
431 allocate(distv(bpar%nl0r(ib)))
432 allocate(fit(nam%nc3,bpar%nl0r(ib),geom%nl0))
435 call msr(diag_blk%fit_rh)
436 call msr(diag_blk%fit_rv)
437 call msr(diag_blk%fit)
441 vunit = geom%vunitavg
443 ic2 = samp%c2a_to_c2(ic2a)
444 ic0 = samp%c2_to_c0(ic2)
445 vunit = geom%vunit(ic0,:)
451 jl0r = bpar%il0rz(il0,ib)
454 call fast_fit(mpl,nam%nc3,1,geom%disth,diag_blk%raw(:,jl0r,il0),diag_blk%fit_rh(il0))
457 rawv = diag_blk%raw(1,:,il0)
458 distv = diag_blk%distv(bpar%l0rl0b_to_l0(:,il0,ib),il0)
459 call fast_fit(mpl,bpar%nl0r(ib),jl0r,distv,rawv,diag_blk%fit_rv(il0))
462 if (any(isnotmsr(diag_blk%fit_rh)).and.any(isnotmsr(diag_blk%fit_rv)))
then 464 call ver_fill(mpl,geom%nl0,vunit,diag_blk%fit_rh)
465 call ver_fill(mpl,geom%nl0,vunit,diag_blk%fit_rv)
468 if (nam%lhomh) diag_blk%fit_rh = sum(diag_blk%fit_rh,mask=isnotmsr(diag_blk%fit_rh)) &
469 & /
real(count(isnotmsr(diag_blk%fit_rh)),kind_real)
470 if (nam%lhomv) diag_blk%fit_rv = sum(diag_blk%fit_rv,mask=isnotmsr(diag_blk%fit_rv)) &
471 & /
real(count(isnotmsr(diag_blk%fit_rv)),kind_real)
474 if (diag_blk%double_fit)
then 475 diag_blk%fit_rv_rfac = 0.3
476 diag_blk%fit_rv_coef = 0.1
480 if (all(isnotmsr(diag_blk%fit_rh)).and.all(isnotmsr(diag_blk%fit_rv)))
then 485 alpha = 0.5+
real(isc-1,kind_real)/
real(nsc-1,kind_real)*(2.0-0.5)
488 fit_rh = alpha*diag_blk%fit_rh
489 fit_rv = alpha*diag_blk%fit_rv
492 if (diag_blk%double_fit)
then 493 call fit_diag_dble(mpl,nam%nc3,bpar%nl0r(ib),geom%nl0,bpar%l0rl0b_to_l0(:,:,ib),geom%disth,diag_blk%distv, &
494 & fit_rh,fit_rv,diag_blk%fit_rv_rfac,diag_blk%fit_rv_coef,fit)
496 call fit_diag(mpl,nam%nc3,bpar%nl0r(ib),geom%nl0,bpar%l0rl0b_to_l0(:,:,ib),geom%disth,diag_blk%distv,fit_rh,fit_rv,fit)
500 mse = sum((fit-diag_blk%raw)**2,mask=isnotmsr(diag_blk%raw))
501 if (mse<mse_opt)
then 506 diag_blk%fit_rh = alpha_opt*diag_blk%fit_rh
507 diag_blk%fit_rv = alpha_opt*diag_blk%fit_rv
510 write(mpl%info,
'(a)')
'' 511 write(mpl%info,
'(a13,a,f6.1,a)')
'',
'Scaling optimization, cost function decrease:',abs(mse_opt-mse)/mse*100.0,
'%' 516 select case (trim(nam%minim_algo))
521 minim%nx = minim%nx+1
523 minim%nx = minim%nx+geom%nl0
526 minim%nx = minim%nx+1
527 if (diag_blk%double_fit) minim%nx = minim%nx+2
529 minim%nx = minim%nx+geom%nl0
530 if (diag_blk%double_fit) minim%nx = minim%nx+2*geom%nl0
532 minim%ny = nam%nc3*bpar%nl0r(ib)*geom%nl0
533 allocate(minim%x(minim%nx))
534 allocate(minim%guess(minim%nx))
535 allocate(minim%binf(minim%nx))
536 allocate(minim%bsup(minim%nx))
537 allocate(minim%obs(minim%ny))
538 allocate(minim%l0rl0_to_l0(bpar%nl0r(ib),geom%nl0))
539 allocate(minim%disth(nam%nc3))
540 allocate(minim%distv(geom%nl0,geom%nl0))
545 minim%guess(offset+1) = diag_blk%fit_rh(1)
546 minim%binf(offset+1) = 0.5*minim%guess(offset+1)
547 minim%bsup(offset+1) = 1.5*minim%guess(offset+1)
550 minim%guess(offset+1:offset+geom%nl0) = diag_blk%fit_rh
551 minim%binf(offset+1:offset+geom%nl0) = 0.5*minim%guess(offset+1:offset+geom%nl0)
552 minim%bsup(offset+1:offset+geom%nl0) = 1.5*minim%guess(offset+1:offset+geom%nl0)
553 offset = offset+geom%nl0
556 minim%guess(offset+1) = diag_blk%fit_rv(1)
557 minim%binf(offset+1) = 0.5*minim%guess(offset+1)
558 minim%bsup(offset+1) = 1.5*minim%guess(offset+1)
560 if (diag_blk%double_fit)
then 561 minim%guess(offset+1) = diag_blk%fit_rv_rfac(1)
562 minim%binf(offset+1) = 0.0
563 minim%bsup(offset+1) = 1.0
565 minim%guess(offset+1) = diag_blk%fit_rv_coef(1)
566 minim%binf(offset+1) = 0.0
567 minim%bsup(offset+1) = 1.0
571 minim%guess(offset+1:offset+geom%nl0) = diag_blk%fit_rv
572 minim%binf(offset+1:offset+geom%nl0) = 0.5*minim%guess(offset+1:offset+geom%nl0)
573 minim%bsup(offset+1:offset+geom%nl0) = 1.5*minim%guess(offset+1:offset+geom%nl0)
574 offset = offset+geom%nl0
575 if (diag_blk%double_fit)
then 576 minim%guess(offset+1:offset+geom%nl0) = diag_blk%fit_rv_rfac
577 minim%binf(offset+1:offset+geom%nl0) = 0.0
578 minim%bsup(offset+1:offset+geom%nl0) = 1.0
579 offset = offset+geom%nl0
580 minim%guess(offset+1:offset+geom%nl0) = diag_blk%fit_rv_coef
581 minim%binf(offset+1:offset+geom%nl0) = 0.0
582 minim%bsup(offset+1:offset+geom%nl0) = 1.0
583 offset = offset+geom%nl0
586 minim%obs = pack(diag_blk%raw,mask=.true.)
587 if (diag_blk%double_fit)
then 588 minim%cost_function =
'fit_diag_dble' 590 minim%cost_function =
'fit_diag' 592 minim%algo = nam%minim_algo
594 minim%nl0r = bpar%nl0r(ib)
596 minim%lhomh = nam%lhomh
597 minim%lhomv = nam%lhomv
598 minim%l0rl0_to_l0 = bpar%l0rl0b_to_l0(:,:,ib)
599 minim%disth = geom%disth
600 minim%distv = diag_blk%distv
603 call minim%compute(mpl,
lprt)
606 minim%x =
max(minim%binf,
min(minim%x,minim%bsup))
611 diag_blk%fit_rh = minim%x(offset+1)
614 diag_blk%fit_rh = minim%x(offset+1:offset+geom%nl0)
615 offset = offset+geom%nl0
618 diag_blk%fit_rv = minim%x(offset+1)
620 if (diag_blk%double_fit)
then 621 diag_blk%fit_rv_rfac = minim%x(offset+1)
623 diag_blk%fit_rv_coef = minim%x(offset+1)
627 diag_blk%fit_rv = minim%x(offset+1:offset+geom%nl0)
628 offset = offset+geom%nl0
629 if (diag_blk%double_fit)
then 630 diag_blk%fit_rv_rfac = minim%x(offset+1:offset+geom%nl0)
631 offset = offset+geom%nl0
632 diag_blk%fit_rv_coef = minim%x(offset+1:offset+geom%nl0)
633 offset = offset+geom%nl0
653 class(diag_blk_type),
intent(inout) :: diag_blk
654 type(geom_type),
intent(in) :: geom
655 type(bpar_type),
intent(in) :: bpar
656 type(avg_blk_type),
intent(in) :: avg_blk
659 integer :: il0,jl0r,jc3
662 associate(ib=>diag_blk%ib)
667 do jl0r=1,bpar%nl0r(ib)
668 do jc3=1,bpar%nc3(ib)
669 if (isnotmsr(avg_blk%m11asysq(jc3,jl0r,il0)).and.isnotmsr(avg_blk%m11sq(jc3,jl0r,il0))) &
670 & diag_blk%raw(jc3,jl0r,il0) = avg_blk%m11asysq(jc3,jl0r,il0)/avg_blk%m11sq(jc3,jl0r,il0)
689 class(diag_blk_type),
intent(inout) :: diag_blk
690 type(geom_type),
intent(in) :: geom
691 type(bpar_type),
intent(in) :: bpar
692 type(avg_blk_type),
intent(in) :: avg_blk
693 type(avg_blk_type),
intent(in) :: avg_sta_blk
696 integer :: il0,jl0r,jc3
697 real(kind_real) :: wgt,num,den
700 associate(ib=>diag_blk%ib)
706 do jl0r=1,bpar%nl0r(ib)
707 do jc3=1,bpar%nc3(ib)
708 if (isnotmsr(avg_blk%m11asysq(jc3,jl0r,il0)).and.isnotmsr(avg_blk%m11sq(jc3,jl0r,il0)) &
709 & .and.isnotmsr(avg_sta_blk%m11sta(jc3,jl0r,il0)).and.isnotmsr(avg_sta_blk%stasq(jc3,jl0r,il0)))
then 711 num = num+wgt*(1.0-avg_blk%m11asysq(jc3,jl0r,il0)/avg_blk%m11sq(jc3,jl0r,il0)) &
712 & *avg_sta_blk%m11sta(jc3,jl0r,il0)
713 den = den+wgt*(avg_sta_blk%stasq(jc3,jl0r,il0)-avg_sta_blk%m11sta(jc3,jl0r,il0)**2 &
714 & /avg_blk%m11sq(jc3,jl0r,il0))
719 if ((num>0.0).and.(den>0.0))
then 720 diag_blk%raw_coef_sta = num/den
722 do jl0r=1,bpar%nl0r(ib)
723 do jc3=1,bpar%nc3(ib)
724 if (isnotmsr(avg_blk%m11asysq(jc3,jl0r,il0)).and.isnotmsr(diag_blk%raw_coef_sta) &
725 & .and.isnotmsr(avg_sta_blk%m11sta(jc3,jl0r,il0)).and.isnotmsr(avg_blk%m11sq(jc3,jl0r,il0)))
then 727 diag_blk%raw(jc3,jl0r,il0) = (avg_blk%m11asysq(jc3,jl0r,il0)-diag_blk%raw_coef_sta &
728 & *avg_sta_blk%m11sta(jc3,jl0r,il0))/avg_blk%m11sq(jc3,jl0r,il0)
731 if (diag_blk%raw(jc3,jl0r,il0)<0.0)
call msr(diag_blk%raw(jc3,jl0r,il0))
737 call msr(diag_blk%raw_coef_sta)
738 call msr(diag_blk%raw)
750 subroutine diag_blk_dualens(diag_blk,geom,bpar,avg_blk,avg_lr_blk,diag_lr_blk)
755 class(diag_blk_type),
intent(inout) :: diag_blk
756 type(geom_type),
intent(in) :: geom
757 type(bpar_type),
intent(in) :: bpar
758 type(avg_blk_type),
intent(in) :: avg_blk
759 type(avg_blk_type),
intent(in) :: avg_lr_blk
760 type(diag_blk_type),
intent(inout) :: diag_lr_blk
763 integer :: il0,jl0r,jc3
764 real(kind_real),
allocatable :: num(:),num_lr(:),den(:)
767 associate(ib=>diag_blk%ib)
770 allocate(num(bpar%nc3(ib)))
771 allocate(num_lr(bpar%nc3(ib)))
772 allocate(den(bpar%nc3(ib)))
776 do jl0r=1,bpar%nl0r(ib)
777 do jc3=1,bpar%nc3(ib)
778 if (isnotmsr(avg_blk%m11asysq(jc3,jl0r,il0)).and.isnotmsr(avg_blk%m11sq(jc3,jl0r,il0)) &
779 & .and.isnotmsr(avg_lr_blk%m11lrm11asy(jc3,jl0r,il0)).and.isnotmsr(avg_lr_blk%m11lrm11(jc3,jl0r,il0)) &
780 & .and.isnotmsr(avg_lr_blk%m11sq(jc3,jl0r,il0)).and.isnotmsr(avg_lr_blk%m11lrm11asy(jc3,jl0r,il0)))
then 781 num(jc3) = avg_blk%m11asysq(jc3,jl0r,il0)*avg_lr_blk%m11sq(jc3,jl0r,il0) &
782 & -avg_lr_blk%m11lrm11asy(jc3,jl0r,il0)*avg_lr_blk%m11lrm11(jc3,jl0r,il0)
783 num_lr(jc3) = avg_lr_blk%m11lrm11asy(jc3,jl0r,il0)*avg_blk%m11sq(jc3,jl0r,il0) &
784 & -avg_blk%m11asysq(jc3,jl0r,il0)*avg_lr_blk%m11lrm11(jc3,jl0r,il0)
785 den(jc3) = avg_blk%m11sq(jc3,jl0r,il0)*avg_lr_blk%m11sq(jc3,jl0r,il0)-avg_lr_blk%m11lrm11(jc3,jl0r,il0)**2
786 if ((num(jc3)>0.0).and.(den(jc3)>0.0))
then 787 diag_blk%raw(jc3,jl0r,il0) = num(jc3)/den(jc3)
788 diag_lr_blk%raw(jc3,jl0r,il0) = num_lr(jc3)/den(jc3)
real(kind_real), parameter maxfactor
subroutine diag_blk_localization(diag_blk, geom, bpar, avg_blk)
subroutine diag_blk_alloc(diag_blk, nam, geom, bpar, samp, ic2a, ib, prefix, double_fit)
subroutine diag_blk_dealloc(diag_blk)
subroutine diag_blk_write(diag_blk, mpl, nam, geom, bpar, filename)
subroutine diag_blk_normalization(diag_blk, geom, bpar, remove_max)
subroutine diag_blk_hybridization(diag_blk, geom, bpar, avg_blk, avg_sta_blk)
subroutine diag_blk_dualens(diag_blk, geom, bpar, avg_blk, avg_lr_blk, diag_lr_blk)
integer, parameter, public kind_real
subroutine diag_blk_fitting(diag_blk, mpl, nam, geom, bpar, samp)