33 wts_ensmean,wts_ensperts,&
34 rdiaginv_loc,nanals,neigv,getkf_inflation,denkf,getkf)
125 integer(i_kind),
intent(in) :: nobsl,nanals,neigv
126 real(r_kind),
dimension(nobsl),
intent(in ) :: rdiaginv_loc
127 real(r_kind),
dimension(nanals,nobsl),
intent(inout) :: hxens
128 real(r_single),
dimension(nanals/neigv,nobsl),
intent(in) :: hxens_orig
129 real(r_single),
dimension(nobsl),
intent(in) :: dep
130 real(r_single),
dimension(nanals),
intent(out) :: wts_ensmean
131 real(r_single),
dimension(nanals,nanals/neigv),
intent(out) :: wts_ensperts
134 real(r_kind),
allocatable,
dimension(:,:) :: work3,evecs
135 real(r_single),
allocatable,
dimension(:,:) :: swork2,pa,swork3,shxens
136 real(r_single),
allocatable,
dimension(:) :: swork1
137 real(r_kind),
allocatable,
dimension(:) :: rrloc,evals,gammapI,gamma_inv
139 integer(i_kind) :: nanal,ierr,lwork,liwork
141 integer(i_kind) isuppz(2*nanals)
142 real(r_kind) vl,vu,normfact
143 integer(i_kind),
allocatable,
dimension(:) :: iwork
144 real(r_kind),
dimension(:),
allocatable :: work1
145 logical,
intent(in) :: getkf_inflation,denkf,getkf
149 call abor1_ftn(
"neigv must be >=1 in letkf_core")
152 allocate(work3(nanals,nanals),evecs(nanals,nanals))
153 allocate(rrloc(nobsl),gammapi(nanals),evals(nanals),gamma_inv(nanals))
157 allocate(iwork(3+5*nanals),work1(1+6*nanals+2*nanals*nanals))
161 eps = epsilon(0.0_r_single)
162 where (rrloc < eps) rrloc = eps
164 normfact = sqrt(real((nanals/neigv)-1,r_kind))
169 hxens(nanal,1:nobsl) = hxens(nanal,1:nobsl) * &
170 rrloc(1:nobsl)/normfact
176 lwork =
size(work1); liwork =
size(iwork)
177 if(r_kind == kind(1.d0))
then
179 call dgemm(
'n',
't',nanals,nanals,nobsl,1.d0,hxens,nanals, &
180 hxens,nanals,0.d0,work3,nanals)
187 call dsyevd(
'V',
'L',nanals,evecs,nanals,evals,work1,lwork,iwork,liwork,ierr)
189 call sgemm(
'n',
't',nanals,nanals,nobsl,1.e0,hxens,nanals, &
190 hxens,nanals,0.e0,work3,nanals)
196 call ssyevd(
'V',
'L',nanals,evecs,nanals,evals,work1,lwork,iwork,liwork,ierr)
198 if (ierr .ne. 0) print *,
'warning: dsyev* failed, ierr=',ierr
199 deallocate(work1,iwork,work3)
200 gamma_inv = 0.0_r_kind
204 if (evals(nanal) > eps)
then
205 gamma_inv(nanal) = 1./evals(nanal)
207 evals(nanal) = 0.0_r_kind
217 allocate(shxens(nanals,nobsl))
220 shxens(nanal,1:nobsl) = hxens(nanal,1:nobsl) * rrloc(1:nobsl)
230 allocate(swork3(nanals,nanals),swork2(nanals,nanals),pa(nanals,nanals))
233 swork3(nanal,:) = evecs(nanal,:)/gammapi
234 swork2(nanal,:) = evecs(nanal,:)
240 call sgemm(
'n',
't',nanals,nanals,nanals,1.e0,swork3,nanals,swork2,&
241 nanals,0.e0,pa,nanals)
245 allocate(swork1(nanals))
248 swork1(nanal) = sum(shxens(nanal,:)*dep(:))
255 wts_ensmean(nanal) = sum(pa(nanal,:)*swork1(:))/normfact
279 gammapi = sqrt(1.0/gammapi)
283 evecs(nanal,:)*(1.-gammapi(:))*gamma_inv(:)
289 call sgemm(
'n',
't',nanals,nanals,nanals,1.e0,swork3,nanals,swork2,&
290 nanals,0.e0,pa,nanals)
292 deallocate(swork2,swork3)
298 allocate(swork2(nanals,nanals/neigv))
300 call sgemm(
'n',
't',nanals,nanals/neigv,nobsl,1.e0,&
301 shxens,nanals,hxens_orig,nanals/neigv,0.e0,swork2,nanals)
306 call sgemm(
'n',
'n',nanals,nanals/neigv,nanals,-1.e0,&
307 pa,nanals,swork2,nanals,0.e0,wts_ensperts,nanals)
308 wts_ensperts = wts_ensperts/normfact
311 deallocate(shxens,swork2,pa)
318 call abor1_ftn(
"neigv must be 1 in letkf_core if getkf=F")
326 deallocate(shxens,pa)
327 gammapi = sqrt(1.0/gammapi)
330 swork3(nanal,:) = evecs(nanal,:)*gammapi
337 call sgemm(
'n',
't',nanals,nanals,nanals,1.0,swork3,nanals,swork2,&
338 nanals,0.e0,wts_ensperts,nanals)
339 deallocate(swork3,swork2)
343 deallocate(evecs,gammapi,gamma_inv)
integer, parameter r_kind
subroutine letkf_core(nobsl, hxens, hxens_orig, dep, wts_ensmean, wts_ensperts, rdiaginv_loc, nanals, neigv, getkf_inflation, denkf, getkf)
integer, parameter r_double
integer, parameter num_bytes_for_r_single
integer, parameter i_kind
integer, parameter r_single