FV3 Bundle
type_bump.F90
Go to the documentation of this file.
1 !----------------------------------------------------------------------
2 ! Module: type_bump
3 ! Purpose: BUMP derived type
4 ! Author: Benjamin Menetrier
5 ! Licensing: this code is distributed under the CeCILL-C license
6 ! Copyright © 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT
7 !----------------------------------------------------------------------
8 module type_bump
9 
10 use netcdf
11 use tools_const, only: req,deg2rad
12 use tools_func, only: sphere_dist
13 use tools_kinds,only: kind_real
14 use type_bpar, only: bpar_type
15 use type_cmat, only: cmat_type
16 use type_cv, only: cv_type
17 use type_ens, only: ens_type
18 use type_geom, only: geom_type
19 use type_hdiag, only: hdiag_type
20 use type_io, only: io_type
21 use type_lct, only: lct_type
22 use type_mpl, only: mpl_type
23 use type_nam, only: nam_type
24 use type_nicas, only: nicas_type
25 use type_obsop, only: obsop_type
26 use type_rng, only: rng_type
27 use type_vbal, only: vbal_type
28 
29 implicit none
30 
31 ! BUMP derived type
33  type(bpar_type) :: bpar
34  type(cmat_type) :: cmat
35  type(ens_type) :: ens1
36  type(ens_type) :: ens1u
37  type(ens_type) :: ens2
38  type(geom_type) :: geom
39  type(hdiag_type) :: hdiag
40  type(io_type) :: io
41  type(lct_type) :: lct
42  type(mpl_type) :: mpl
43  type(nam_type) :: nam
44  type(nicas_type) :: nicas
45  type(obsop_type) :: obsop
46  type(rng_type) :: rng
47  type(vbal_type) :: vbal
48  logical :: close_listing
49 contains
50  procedure :: setup_online => bump_setup_online
51  procedure :: setup_generic => bump_setup_generic
52  procedure :: run_drivers => bump_run_drivers
53  procedure :: add_member => bump_add_member
54  procedure :: apply_vbal => bump_apply_vbal
55  procedure :: apply_vbal_inv => bump_apply_vbal_inv
56  procedure :: apply_vbal_ad => bump_apply_vbal_ad
57  procedure :: apply_vbal_inv_ad => bump_apply_vbal_inv_ad
58  procedure :: apply_nicas => bump_apply_nicas
59  procedure :: get_cv_size => bump_get_cv_size
60  procedure :: apply_nicas_sqrt => bump_apply_nicas_sqrt
61  procedure :: apply_nicas_sqrt_ad => bump_apply_nicas_sqrt_ad
62  procedure :: apply_obsop => bump_apply_obsop
63  procedure :: apply_obsop_ad => bump_apply_obsop_ad
64  procedure :: get_parameter => bump_get_parameter
65  procedure :: copy_to_field => bump_copy_to_field
66  procedure :: set_parameter => bump_set_parameter
67  procedure :: copy_from_field => bump_copy_from_field
68  procedure :: dealloc => bump_dealloc
69 end type bump_type
70 
71 private
72 public :: bump_type
73 
74 contains
75 
76 !----------------------------------------------------------------------
77 ! Subroutine: bump_setup_online
78 ! Purpose: online setup
79 !----------------------------------------------------------------------
80 subroutine bump_setup_online(bump,nmga,nl0,nv,nts,lon,lat,area,vunit,lmask,ens1_ne,ens1_nsub,ens2_ne,ens2_nsub, &
81  & nobs,lonobs,latobs,namelname,lunit)
82 
83 implicit none
84 
85 ! Passed variables
86 class(bump_type),intent(inout) :: bump ! BUMP
87 integer,intent(in) :: nmga ! Halo A size
88 integer,intent(in) :: nl0 ! Number of levels in subset Sl0
89 integer,intent(in) :: nv ! Number of variables
90 integer,intent(in) :: nts ! Number of time slots
91 real(kind_real),intent(in) :: lon(nmga) ! Longitude (in degrees: -180 to 180)
92 real(kind_real),intent(in) :: lat(nmga) ! Latitude (in degrees: -90 to 90)
93 real(kind_real),intent(in) :: area(nmga) ! Area (in m^2)
94 real(kind_real),intent(in) :: vunit(nmga,nl0) ! Vertical unit
95 logical,intent(in) :: lmask(nmga,nl0) ! Mask
96 integer,intent(in),optional :: ens1_ne ! Ensemble 1 size
97 integer,intent(in),optional :: ens1_nsub ! Ensemble 1 number of sub-ensembles
98 integer,intent(in),optional :: ens2_ne ! Ensemble 2 size
99 integer,intent(in),optional :: ens2_nsub ! Ensemble 2 size of sub-ensembles
100 integer,intent(in),optional :: nobs ! Number of observations
101 real(kind_real),intent(in),optional :: lonobs(:) ! Observations longitude (in degrees: -180 to 180)
102 real(kind_real),intent(in),optional :: latobs(:) ! Observations latitude (in degrees: -90 to 90)
103 character(len=*),intent(in),optional :: namelname ! Namelist name
104 integer,intent(in),optional :: lunit ! Listing unit
105 
106 ! Local variables
107 integer :: lens1_ne,lens1_nsub,lens2_ne,lens2_nsub
108 
109 ! Initialize MPL
110 call bump%mpl%init
111 
112 if (present(namelname)) then
113  ! Read and broadcast namelist
114  call bump%nam%read(bump%mpl,namelname)
115  call bump%nam%bcast(bump%mpl)
116 end if
117 
118 ! Set internal namelist parameters
119 lens1_ne = 0
120 lens1_nsub = 1
121 lens2_ne = 0
122 lens2_nsub = 1
123 if (present(ens1_ne)) lens1_ne = ens1_ne
124 if (present(ens1_nsub)) lens1_nsub = ens1_nsub
125 if (present(ens2_ne)) lens2_ne = ens2_ne
126 if (present(ens2_ne)) lens2_nsub = ens2_nsub
127 call bump%nam%setup_internal(nl0,nv,nts,lens1_ne,lens1_nsub,lens2_ne,lens2_nsub)
128 
129 ! Initialize listing
130 if (present(lunit)) then
131  call bump%mpl%init_listing(bump%nam%prefix,bump%nam%model,bump%nam%colorlog,bump%nam%logpres,lunit)
132  bump%close_listing = .false.
133 else
134  call bump%mpl%init_listing(bump%nam%prefix,bump%nam%model,bump%nam%colorlog,bump%nam%logpres)
135  bump%close_listing = (trim(bump%nam%model)=='online').and.(.not.present(nobs))
136 end if
137 
138 ! Generic setup
139 call bump%setup_generic
140 
141 ! Initialize geometry
142 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
143 write(bump%mpl%info,'(a)') '--- Initialize geometry'
144 call flush(bump%mpl%info)
145 call bump%geom%setup_online(bump%mpl,bump%rng,bump%nam,nmga,nl0,lon,lat,area,vunit,lmask)
146 call bump%geom%init(bump%mpl,bump%rng,bump%nam)
147 
148 if (bump%nam%grid_output) then
149  ! Initialize fields regridding
150  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
151  write(bump%mpl%info,'(a)') '--- Initialize fields regridding'
152  call flush(bump%mpl%info)
153  call bump%io%grid_init(bump%mpl,bump%rng,bump%nam,bump%geom)
154 end if
155 
156 ! Initialize block parameters
157 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
158 write(bump%mpl%info,'(a)') '--- Initialize block parameters'
159 call bump%bpar%alloc(bump%nam,bump%geom)
160 
161 ! Initialize ensemble 1
162 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
163 write(bump%mpl%info,'(a)') '--- Initialize ensemble 1'
164 call bump%ens1%alloc(bump%nam,bump%geom,bump%nam%ens1_ne,bump%nam%ens1_nsub)
165 
166 ! Initialize ensemble 2
167 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
168 write(bump%mpl%info,'(a)') '--- Initialize ensemble 2'
169 call bump%ens2%alloc(bump%nam,bump%geom,bump%nam%ens2_ne,bump%nam%ens2_nsub)
170 
171 if (present(nobs)) then
172  ! Check arguments consistency
173  if ((.not.present(lonobs)).or.(.not.present(latobs))) call bump%mpl%abort('lonobs and latobs are missing')
174 
175  ! Check sizes consistency
176  if (size(lonobs)/=nobs) call bump%mpl%abort('wrong size for lonobs')
177  if (size(latobs)/=nobs) call bump%mpl%abort('wrong size for latobs')
178 
179  ! Initialize observations locations
180  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
181  write(bump%mpl%info,'(a)') '--- Initialize observations locations'
182  call flush(bump%mpl%info)
183  call bump%obsop%from(nobs,lonobs,latobs)
184 end if
185 
186 if ((bump%nam%ens1_ne>0).or.(bump%nam%ens2_ne>0)) then
187  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
188  write(bump%mpl%info,'(a)') '--- Add members to BUMP ensembles'
189 end if
190 
191 end subroutine bump_setup_online
192 
193 !----------------------------------------------------------------------
194 ! Subroutine: bump_setup_generic
195 ! Purpose: generic setup
196 !----------------------------------------------------------------------
197 subroutine bump_setup_generic(bump)
199 implicit none
200 
201 ! Passed variables
202 class(bump_type),intent(inout) :: bump ! BUMP
203 
204 ! Header
205 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
206 write(bump%mpl%info,'(a)') '--- You are running BUMP ------------------------------------------'
207 write(bump%mpl%info,'(a)') '--- Author: Benjamin Menetrier ------------------------------------'
208 write(bump%mpl%info,'(a)') '--- Copyright © 2015-... UCAR, CERFACS, METEO-FRANCE and IRIT -----'
209 call flush(bump%mpl%info)
210 
211 ! Check namelist parameters
212 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
213 write(bump%mpl%info,'(a)') '--- Check namelist parameters'
214 call flush(bump%mpl%info)
215 call bump%nam%check(bump%mpl)
216 
217 ! Write parallel setup
218 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
219 write(bump%mpl%info,'(a,i3,a,i2,a)') '--- Parallelization with ',bump%mpl%nproc,' MPI tasks and ', &
220  & bump%mpl%nthread,' OpenMP threads'
221 call flush(bump%mpl%info)
222 
223 ! Initialize random number generator
224 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
225 write(bump%mpl%info,'(a)') '--- Initialize random number generator'
226 call flush(bump%mpl%info)
227 call bump%rng%init(bump%mpl,bump%nam)
228 
229 ! Initialize allocation flags
230 bump%cmat%allocated = .false.
231 bump%lct%allocated = .false.
232 bump%nicas%allocated = .false.
233 
234 end subroutine bump_setup_generic
235 
236 !----------------------------------------------------------------------
237 ! Subroutine: bump_run_drivers
238 ! Purpose: run drivers
239 !----------------------------------------------------------------------
240 subroutine bump_run_drivers(bump)
242 implicit none
243 
244 ! Passed variables
245 class(bump_type),intent(inout) :: bump ! BUMP
246 
247 ! Reset seed
248 if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
249 
250 ! Finalize ensemble 1
251 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
252 write(bump%mpl%info,'(a)') '--- Finalize ensemble 1'
253 call flush(bump%mpl%info)
254 call bump%ens1%remove_mean
255 
256 ! Finalize ensemble 2
257 write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
258 write(bump%mpl%info,'(a)') '--- Finalize ensemble 2'
259 call flush(bump%mpl%info)
260 call bump%ens2%remove_mean
261 
262 if (bump%nam%new_vbal) then
263  ! Reseed random number generator
264  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
265 
266  ! Run vertical balance driver
267  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
268  write(bump%mpl%info,'(a)') '--- Run vertical balance driver'
269  call flush(bump%mpl%info)
270  call bump%vbal%run_vbal(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%io,bump%ens1,bump%ens1u)
271 elseif (bump%nam%load_vbal) then
272  ! Read vertical balance
273  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
274  write(bump%mpl%info,'(a)') '--- Read vertical balance'
275  call flush(bump%mpl%info)
276  call bump%vbal%read(bump%mpl,bump%nam,bump%geom,bump%bpar)
277 end if
278 
279 if (bump%nam%check_vbal) then
280  ! Reseed random number generator
281  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
282 
283  ! Run vertical balance tests driver
284  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
285  write(bump%mpl%info,'(a)') '--- Run vertical balance tests driver'
286  call flush(bump%mpl%info)
287  call bump%vbal%run_vbal_tests(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar)
288 end if
289 
290 if (bump%nam%new_hdiag) then
291  ! Reseed random number generator
292  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
293 
294  ! Run HDIAG driver
295  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
296  write(bump%mpl%info,'(a)') '--- Run HDIAG driver'
297  call flush(bump%mpl%info)
298  if ((trim(bump%nam%method)=='hyb-rnd').or.(trim(bump%nam%method)=='dual-ens')) then
299  call bump%hdiag%run_hdiag(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%io,bump%ens1,bump%ens2)
300  else
301  call bump%hdiag%run_hdiag(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%io,bump%ens1)
302  end if
303 
304  ! Copy HDIAG into C matrix
305  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
306  write(bump%mpl%info,'(a)') '--- Copy HDIAG into C matrix'
307  call flush(bump%mpl%info)
308  call bump%cmat%from_hdiag(bump%mpl,bump%nam,bump%geom,bump%bpar,bump%hdiag)
309 end if
310 
311 if (bump%nam%new_lct) then
312  ! Reseed random number generator
313  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
314 
315  ! Run LCT driver
316  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
317  write(bump%mpl%info,'(a)') '--- Run LCT driver'
318  call flush(bump%mpl%info)
319  call bump%lct%run_lct(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%io,bump%ens1)
320 
321  ! Copy LCT into C matrix
322  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
323  write(bump%mpl%info,'(a)') '--- Copy LCT into C matrix'
324  call flush(bump%mpl%info)
325  call bump%cmat%from_lct(bump%mpl,bump%nam,bump%geom,bump%bpar,bump%lct)
326 end if
327 
328 if (bump%nam%load_cmat) then
329  ! Read C matrix
330  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
331  write(bump%mpl%info,'(a)') '--- Read C matrix'
332  call flush(bump%mpl%info)
333  call bump%cmat%read(bump%mpl,bump%nam,bump%geom,bump%bpar,bump%io)
334 else
335  if (bump%nam%forced_radii) then
336  ! Copy namelist support radii into C matrix
337  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
338  write(bump%mpl%info,'(a)') '--- Copy namelist support radii into C matrix'
339  call flush(bump%mpl%info)
340  call bump%cmat%from_nam(bump%mpl,bump%nam,bump%geom,bump%bpar)
341  end if
342 end if
343 
344 if (allocated(bump%cmat%blk)) then
345  ! Get C matrix from OOPS
346  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
347  write(bump%mpl%info,'(a)') '--- Get C matrix from OOPS'
348  call bump%cmat%from_oops(bump%mpl,bump%geom,bump%bpar)
349 
350  ! Setup C matrix sampling
351  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
352  write(bump%mpl%info,'(a)') '--- Setup C matrix sampling'
353  call bump%cmat%setup_sampling(bump%nam,bump%geom,bump%bpar)
354 
355  ! Write C matrix
356  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
357  write(bump%mpl%info,'(a)') '--- Write C matrix'
358  call flush(bump%mpl%info)
359  call bump%cmat%write(bump%mpl,bump%nam,bump%geom,bump%bpar,bump%io)
360 end if
361 
362 if (bump%nam%new_nicas) then
363  ! Reseed random number generator
364  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
365 
366  ! Run NICAS driver
367  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
368  write(bump%mpl%info,'(a)') '--- Run NICAS driver'
369  call flush(bump%mpl%info)
370  call bump%nicas%run_nicas(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%cmat)
371 elseif (bump%nam%load_nicas) then
372  ! Read NICAS parameters
373  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
374  write(bump%mpl%info,'(a)') '--- Read NICAS parameters'
375  call flush(bump%mpl%info)
376  call bump%nicas%read(bump%mpl,bump%nam,bump%geom,bump%bpar)
377 end if
378 
379 if (bump%nam%check_adjoints.or.bump%nam%check_pos_def.or.bump%nam%check_sqrt.or.bump%nam%check_dirac.or. &
380  & bump%nam%check_randomization.or.bump%nam%check_consistency.or.bump%nam%check_optimality) then
381  ! Reseed random number generator
382  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
383 
384  ! Run NICAS tests driver
385  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
386  write(bump%mpl%info,'(a)') '--- Run NICAS tests driver'
387  call flush(bump%mpl%info)
388  call bump%nicas%run_nicas_tests(bump%mpl,bump%rng,bump%nam,bump%geom,bump%bpar,bump%io,bump%cmat,bump%ens1)
389 end if
390 
391 if (bump%nam%new_obsop) then
392  ! Reseed random number generator
393  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
394 
395  ! Run observation operator driver
396  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
397  write(bump%mpl%info,'(a)') '--- Run observation operator driver'
398  call flush(bump%mpl%info)
399  call bump%obsop%run_obsop(bump%mpl,bump%rng,bump%nam,bump%geom)
400 elseif (bump%nam%load_obsop) then
401  ! Read observation operator
402  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
403  write(bump%mpl%info,'(a)') '--- Read observation operator'
404  call flush(bump%mpl%info)
405  call bump%obsop%read(bump%mpl,bump%nam)
406 end if
407 
408 if (bump%nam%check_obsop) then
409  ! Reseed random number generator
410  if (bump%nam%default_seed) call bump%rng%reseed(bump%mpl)
411 
412  ! Run observation operator tests driver
413  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
414  write(bump%mpl%info,'(a)') '--- Run observation operator tests driver'
415  call flush(bump%mpl%info)
416  call bump%obsop%run_obsop_tests(bump%mpl,bump%rng,bump%geom)
417 end if
418 
419 if (bump%close_listing) then
420  ! Close listings
421  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
422  write(bump%mpl%info,'(a)') '--- Close listings'
423  write(bump%mpl%info,'(a)') '-------------------------------------------------------------------'
424  call flush(bump%mpl%info)
425  close(unit=bump%mpl%info)
426  call flush(bump%mpl%test)
427  close(unit=bump%mpl%test)
428 end if
429 
430 end subroutine bump_run_drivers
431 
432 !----------------------------------------------------------------------
433 ! Subroutine: bump_add_member
434 ! Purpose: add member into bump%ens[1,2]
435 !----------------------------------------------------------------------
436 subroutine bump_add_member(bump,fld_mga,ie,iens)
438 implicit none
439 
440 ! Passed variables
441 class(bump_type),intent(inout) :: bump ! BUMP
442 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
443 integer,intent(in) :: ie ! Member index
444 integer,intent(in) :: iens ! Ensemble number
445 
446 ! Local variables
447 integer :: its,iv,nnonzero,nzero,nmask
448 real(kind_real) :: norm,fld_c0a(bump%geom%nc0a,bump%geom%nl0)
449 
450 ! Add member
451 write(bump%mpl%info,'(a7,a,i3,a,i1)') '','Member ',ie,' added to ensemble ',iens
452 do its=1,bump%nam%nts
453  do iv=1,bump%nam%nv
454  ! Model grid to subset Sc0
455  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a)
456 
457  ! Copy to ensemble structure
458  if (iens==1) then
459  bump%ens1%fld(:,:,iv,its,ie) = fld_c0a
460  elseif (iens==2) then
461  bump%ens2%fld(:,:,iv,its,ie) = fld_c0a
462  else
463  call bump%mpl%abort('wrong ensemble number')
464  end if
465 
466  ! Print norm
467  norm = sum(fld_c0a**2,mask=bump%geom%mask_c0a)
468  write(bump%mpl%info,'(a10,a,i2,a,i2,a,e9.2)') '','Local norm for variable ',iv,' and timeslot ',its,': ',norm
469  nnonzero = count((abs(fld_c0a)>0.0).and.bump%geom%mask_c0a)
470  nzero = count((.not.(abs(fld_c0a)>0.0)).and.bump%geom%mask_c0a)
471  nmask = count(.not.bump%geom%mask_c0a)
472  write(bump%mpl%info,'(a10,a,i8,a,i8,a,i8,a,i8)') '','Total / non-zero / zero / masked points: ',bump%geom%nc0a,' / ', &
473  & nnonzero,' / ',nzero,' / ',nmask
474  end do
475 end do
476 
477 end subroutine bump_add_member
478 
479 !----------------------------------------------------------------------
480 ! Subroutine: bump_apply_vbal
481 ! Purpose: vertical balance application
482 !----------------------------------------------------------------------
483 subroutine bump_apply_vbal(bump,fld_mga)
485 implicit none
486 
487 ! Passed variables
488 class(bump_type),intent(in) :: bump ! BUMP
489 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
490 
491 ! Local variable
492 integer :: its,iv
493 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv)
494 
495 do its=1,bump%nam%nts
496  if (bump%geom%nc0==bump%geom%nmg) then
497  ! Apply vertical balance
498  call bump%vbal%apply(bump%nam,bump%geom,bump%bpar,fld_mga(:,:,:,its))
499  else
500  ! Model grid to subset Sc0
501  do iv=1,bump%nam%nv
502  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv))
503  end do
504 
505  ! Apply vertical balance
506  call bump%vbal%apply(bump%nam,bump%geom,bump%bpar,fld_c0a)
507 
508  ! Subset Sc0 to model grid
509  do iv=1,bump%nam%nv
510  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv),fld_mga(:,:,iv,its))
511  end do
512  end if
513 end do
514 
515 end subroutine bump_apply_vbal
516 
517 !----------------------------------------------------------------------
518 ! Subroutine: bump_apply_vbal_inv
519 ! Purpose: vertical balance application, inverse
520 !----------------------------------------------------------------------
521 subroutine bump_apply_vbal_inv(bump,fld_mga)
523 implicit none
524 
525 ! Passed variables
526 class(bump_type),intent(in) :: bump ! BUMP
527 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
528 
529 ! Local variable
530 integer :: its,iv
531 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv)
532 
533 do its=1,bump%nam%nts
534  if (bump%geom%nc0==bump%geom%nmg) then
535  ! Apply vertical balance, inverse
536  call bump%vbal%apply_inv(bump%nam,bump%geom,bump%bpar,fld_mga(:,:,:,its))
537  else
538  ! Model grid to subset Sc0
539  do iv=1,bump%nam%nv
540  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv))
541  end do
542 
543  ! Apply vertical balance, inverse
544  call bump%vbal%apply_inv(bump%nam,bump%geom,bump%bpar,fld_c0a)
545 
546  ! Subset Sc0 to model grid
547  do iv=1,bump%nam%nv
548  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv),fld_mga(:,:,iv,its))
549  end do
550  end if
551 end do
552 
553 end subroutine bump_apply_vbal_inv
554 
555 !----------------------------------------------------------------------
556 ! Subroutine: bump_apply_vbal_ad
557 ! Purpose: vertical balance application, adjoint
558 !----------------------------------------------------------------------
559 subroutine bump_apply_vbal_ad(bump,fld_mga)
561 implicit none
562 
563 ! Passed variables
564 class(bump_type),intent(in) :: bump ! BUMP
565 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
566 
567 ! Local variable
568 integer :: its,iv
569 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv)
570 
571 do its=1,bump%nam%nts
572  if (bump%geom%nc0==bump%geom%nmg) then
573  ! Apply vertical balance, adjoint
574  call bump%vbal%apply_ad(bump%nam,bump%geom,bump%bpar,fld_mga(:,:,:,its))
575  else
576  ! Model grid to subset Sc0
577  do iv=1,bump%nam%nv
578  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv))
579  end do
580 
581  ! Apply vertical balance, adjoint
582  call bump%vbal%apply_ad(bump%nam,bump%geom,bump%bpar,fld_c0a)
583 
584  ! Subset Sc0 to model grid
585  do iv=1,bump%nam%nv
586  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv),fld_mga(:,:,iv,its))
587  end do
588  end if
589 end do
590 
591 end subroutine bump_apply_vbal_ad
592 
593 !----------------------------------------------------------------------
594 ! Subroutine: bump_apply_vbal_inv_ad
595 ! Purpose: vertical balance application, inverse adjoint
596 !----------------------------------------------------------------------
597 subroutine bump_apply_vbal_inv_ad(bump,fld_mga)
599 implicit none
600 
601 ! Passed variables
602 class(bump_type),intent(in) :: bump ! BUMP
603 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
604 
605 ! Local variable
606 integer :: its,iv
607 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv)
608 
609 do its=1,bump%nam%nts
610  if (bump%geom%nc0==bump%geom%nmg) then
611  ! Apply vertical balance, inverse adjoint
612  call bump%vbal%apply_inv_ad(bump%nam,bump%geom,bump%bpar,fld_mga(:,:,:,its))
613  else
614  ! Model grid to subset Sc0
615  do iv=1,bump%nam%nv
616  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv))
617  end do
618 
619  ! Apply vertical balance, inverse adjoint
620  call bump%vbal%apply_inv_ad(bump%nam,bump%geom,bump%bpar,fld_c0a)
621 
622  ! Subset Sc0 to model grid
623  do iv=1,bump%nam%nv
624  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv),fld_mga(:,:,iv,its))
625  end do
626  end if
627 end do
628 
629 end subroutine bump_apply_vbal_inv_ad
630 
631 !----------------------------------------------------------------------
632 ! Subroutine: bump_apply_nicas
633 ! Purpose: NICAS application
634 !----------------------------------------------------------------------
635 subroutine bump_apply_nicas(bump,fld_mga)
637 implicit none
638 
639 ! Passed variables
640 class(bump_type),intent(in) :: bump ! BUMP
641 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
642 
643 ! Local variable
644 integer :: its,iv
645 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv,bump%nam%nts)
646 
647 if (bump%geom%nc0==bump%geom%nmg) then
648  ! Apply NICAS
649  if (bump%nam%lsqrt) then
650  call bump%nicas%apply_from_sqrt(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_mga)
651  else
652  call bump%nicas%apply(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_mga)
653  end if
654 else
655  ! Model grid to subset Sc0
656  do its=1,bump%nam%nts
657  do iv=1,bump%nam%nv
658  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv,its))
659  end do
660  end do
661 
662  ! Apply NICAS
663  if (bump%nam%lsqrt) then
664  call bump%nicas%apply_from_sqrt(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_c0a)
665  else
666  call bump%nicas%apply(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_c0a)
667  end if
668 
669  ! Subset Sc0 to model grid
670  do its=1,bump%nam%nts
671  do iv=1,bump%nam%nv
672  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv,its),fld_mga(:,:,iv,its))
673  end do
674  end do
675 end if
676 
677 end subroutine bump_apply_nicas
678 
679 !----------------------------------------------------------------------
680 ! Subroutine: bump_get_cv_size
681 ! Purpose: get control variable size
682 !----------------------------------------------------------------------
683 subroutine bump_get_cv_size(bump,n)
685 implicit none
686 
687 ! Passed variables
688 class(bump_type),intent(in) :: bump ! BUMP
689 integer,intent(out) :: n ! Control variable size
690 
691 ! Local variables
692 type(cv_type) :: cv
693 
694 ! Allocate control variable
695 call bump%nicas%alloc_cv(bump%bpar,cv,getsizeonly=.true.)
696 
697 ! Copy size
698 n = cv%n
699 
700 end subroutine bump_get_cv_size
701 
702 !----------------------------------------------------------------------
703 ! Subroutine: bump_apply_nicas_sqrt
704 ! Purpose: NICAS square-root application
705 !----------------------------------------------------------------------
706 subroutine bump_apply_nicas_sqrt(bump,pcv,fld_mga)
708 implicit none
709 
710 ! Passed variables
711 class(bump_type),intent(in) :: bump ! BUMP
712 real(kind_real),intent(in) :: pcv(:) ! Packed control variable
713 real(kind_real),intent(inout) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
714 
715 ! Local variable
716 integer :: its,iv
717 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv,bump%nam%nts)
718 type(cv_type) :: cv
719 
720 ! Allocation
721 call bump%nicas%alloc_cv(bump%bpar,cv)
722 
723 ! Check dimension
724 if (size(pcv)==cv%n) then
725  ! Unpack control variable
726  call cv%unpack(pcv)
727 else
728  call bump%mpl%abort('wrong control variable size in bump_apply_nicas_sqrt')
729 end if
730 
731 if (bump%geom%nc0==bump%geom%nmg) then
732  ! Apply NICAS square-root
733  call bump%nicas%apply_sqrt(bump%mpl,bump%nam,bump%geom,bump%bpar,cv,fld_mga)
734 else
735  ! Apply NICAS square-root
736  call bump%nicas%apply_sqrt(bump%mpl,bump%nam,bump%geom,bump%bpar,cv,fld_c0a)
737 
738  ! Subset Sc0 to model grid
739  do its=1,bump%nam%nts
740  do iv=1,bump%nam%nv
741  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a(:,:,iv,its),fld_mga(:,:,iv,its))
742  end do
743  end do
744 end if
745 
746 end subroutine bump_apply_nicas_sqrt
747 
748 !----------------------------------------------------------------------
749 ! Subroutine: bump_apply_nicas_sqrt_ad
750 ! Purpose: NICAS square-root adjoint application
751 !----------------------------------------------------------------------
752 subroutine bump_apply_nicas_sqrt_ad(bump,fld_mga,pcv)
754 implicit none
755 
756 ! Passed variables
757 class(bump_type),intent(in) :: bump ! BUMP
758 real(kind_real),intent(in) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
759 real(kind_real),intent(inout) :: pcv(:) ! Packed control variable
760 
761 ! Local variables
762 integer :: its,iv
763 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0,bump%nam%nv,bump%nam%nts)
764 type(cv_type) :: cv
765 
766 if (bump%geom%nc0==bump%geom%nmg) then
767  ! Apply NICAS square-root adjoint
768  call bump%nicas%apply_sqrt_ad(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_mga,cv)
769 else
770  ! Model grid to subset Sc0
771  do its=1,bump%nam%nts
772  do iv=1,bump%nam%nv
773  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga(:,:,iv,its),fld_c0a(:,:,iv,its))
774  end do
775  end do
776 
777  ! Apply NICAS square-root adjoint
778  call bump%nicas%apply_sqrt_ad(bump%mpl,bump%nam,bump%geom,bump%bpar,fld_c0a,cv)
779 end if
780 
781 ! Check dimension
782 if (size(pcv)==cv%n) then
783  ! Pack control variable
784  call cv%pack(pcv)
785 else
786  call bump%mpl%abort('wrong control variable size in bump_apply_nicas_sqrt_ad')
787 end if
788 
789 end subroutine bump_apply_nicas_sqrt_ad
790 
791 !----------------------------------------------------------------------
792 ! Subroutine: bump_apply_obsop
793 ! Purpose: observation operator application
794 !----------------------------------------------------------------------
795 subroutine bump_apply_obsop(bump,fld_mga,obs)
797 implicit none
798 
799 ! Passed variables
800 class(bump_type),intent(in) :: bump ! BUMP
801 real(kind_real),intent(in) :: fld_mga(bump%geom%nmga,bump%geom%nl0) ! Field
802 real(kind_real),intent(out) :: obs(bump%obsop%nobsa,bump%geom%nl0) ! Observations columns
803 
804 ! Local variables
805 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0)
806 
807 if (bump%geom%nc0==bump%geom%nmg) then
808  ! Apply observation operator
809  call bump%obsop%apply(bump%mpl,bump%geom,fld_mga,obs)
810 else
811  ! Model grid to subset Sc0
812  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,fld_c0a)
813 
814  ! Apply observation operator
815  call bump%obsop%apply(bump%mpl,bump%geom,fld_c0a,obs)
816 end if
817 
818 end subroutine bump_apply_obsop
819 
820 !----------------------------------------------------------------------
821 ! Subroutine: bump_apply_obsop_ad
822 ! Purpose: observation operator adjoint application
823 !----------------------------------------------------------------------
824 subroutine bump_apply_obsop_ad(bump,obs,fld_mga)
826 implicit none
827 
828 ! Passed variables
829 class(bump_type),intent(in) :: bump ! BUMP
830 real(kind_real),intent(in) :: obs(bump%obsop%nobsa,bump%geom%nl0) ! Observations columns
831 real(kind_real),intent(out) :: fld_mga(bump%geom%nmga,bump%geom%nl0) ! Field
832 
833 ! Local variables
834 real(kind_real) :: fld_c0a(bump%geom%nc0a,bump%geom%nl0)
835 
836 if (bump%geom%nc0==bump%geom%nmg) then
837  ! Apply observation operator adjoint
838  call bump%obsop%apply_ad(bump%mpl,bump%geom,obs,fld_mga)
839 else
840  ! Apply observation operator adjoint
841  call bump%obsop%apply_ad(bump%mpl,bump%geom,obs,fld_c0a)
842 
843  ! Subset Sc0 to model grid
844  call bump%geom%copy_c0a_to_mga(bump%mpl,fld_c0a,fld_mga)
845 end if
846 
847 end subroutine bump_apply_obsop_ad
848 
849 !----------------------------------------------------------------------
850 ! Subroutine: bump_get_parameter
851 ! Purpose: get a parameter
852 !----------------------------------------------------------------------
853 subroutine bump_get_parameter(bump,param,fld_mga)
855 implicit none
856 
857 ! Passed variables
858 class(bump_type),intent(in) :: bump ! BUMP
859 character(len=*),intent(in) :: param ! Parameter
860 real(kind_real),intent(out) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
861 
862 ! Local variables
863 integer :: ib,iv,jv,its,jts
864 
865 select case (trim(param))
866 case ('var','cor_rh','cor_rv','cor_rv_rfac','cor_rv_coef','loc_coef','loc_rh','loc_rv','hyb_coef')
867  select case (trim(bump%nam%strategy))
868  case ('specific_univariate','specific_multivariate')
869  do ib=1,bump%bpar%nb
870  ! Get indices
871  iv = bump%bpar%b_to_v1(ib)
872  jv = bump%bpar%b_to_v2(ib)
873  its = bump%bpar%b_to_ts1(ib)
874  jts = bump%bpar%b_to_ts2(ib)
875 
876  ! Copy to field
877  if ((iv==jv).and.(its==jts)) call bump%copy_to_field(param,ib,fld_mga(:,:,iv,its))
878  end do
879  case ('common','common_univariate','common_weighted')
880  ! Set common index
881  ib = bump%bpar%nbe
882 
883  do its=1,bump%nam%nts
884  do iv=1,bump%nam%nv
885  ! Copy to field
886  call bump%copy_to_field(param,ib,fld_mga(:,:,iv,its))
887  end do
888  end do
889  end select
890 case default
891  do ib=1,bump%bpar%nb
892  ! Get indices
893  iv = bump%bpar%b_to_v1(ib)
894  jv = bump%bpar%b_to_v2(ib)
895  its = bump%bpar%b_to_ts1(ib)
896  jts = bump%bpar%b_to_ts2(ib)
897 
898  ! Copy to field
899  if ((iv==jv).and.(its==jts)) call bump%copy_to_field(param,ib,fld_mga(:,:,iv,its))
900  end do
901 end select
902 
903 end subroutine bump_get_parameter
904 
905 !----------------------------------------------------------------------
906 ! Subroutine: bump_copy_to_field
907 ! Purpose: copy to field
908 !----------------------------------------------------------------------
909 subroutine bump_copy_to_field(bump,param,ib,fld_mga)
911 implicit none
912 
913 ! Passed variables
914 class(bump_type),intent(in) :: bump ! BUMP
915 character(len=*),intent(in) :: param ! Parameter
916 integer,intent(in) :: ib ! Block index
917 real(kind_real),intent(out) :: fld_mga(bump%geom%nmga,bump%geom%nl0) ! Field
918 
919 ! Local variables
920 integer :: iscales,ie,iv,its
921 
922 ! Select parameter
923 select case (trim(param))
924 case ('var')
925  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%coef_ens,fld_mga)
926 case ('cor_rh')
927  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rh,fld_mga)
928  fld_mga = fld_mga*req
929 case ('cor_rv')
930  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rv,fld_mga)
931 case ('cor_rv_rfac')
932  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rv_rfac,fld_mga)
933 case ('cor_rv_coef')
934  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rv_coef,fld_mga)
935 case ('loc_coef')
936  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%coef_ens,fld_mga)
937 case ('loc_rh')
938  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rh,fld_mga)
939  fld_mga = fld_mga*req
940 case ('loc_rv')
941  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%rv,fld_mga)
942 case ('hyb_coef')
943  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%cmat%blk(ib)%coef_sta,fld_mga)
944 case default
945  select case (param(1:4))
946  case ('D11_')
947  read(param(5:5),'(i1)') iscales
948  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%D11(:,:,iscales),fld_mga)
949  fld_mga = fld_mga*req**2
950  case ('D22_')
951  read(param(5:5),'(i1)') iscales
952  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%D22(:,:,iscales),fld_mga)
953  fld_mga = fld_mga*req**2
954  case ('D33_')
955  read(param(5:5),'(i1)') iscales
956  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%D33(:,:,iscales),fld_mga)
957  case ('D12_')
958  read(param(5:5),'(i1)') iscales
959  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%D12(:,:,iscales),fld_mga)
960  fld_mga = fld_mga*req**2
961  case ('Dcoe')
962  read(param(7:7),'(i1)') iscales
963  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%Dcoef(:,:,iscales),fld_mga)
964  case ('DLh_')
965  read(param(5:5),'(i1)') iscales
966  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%lct%blk(ib)%DLh(:,:,iscales),fld_mga)
967  fld_mga = fld_mga*req
968  case default
969  if (param(1:6)=='ens1u_') then
970  read(param(7:10),'(i4.4)') ie
971  iv = bump%bpar%b_to_v1(ib)
972  its = bump%bpar%b_to_ts1(ib)
973  call bump%geom%copy_c0a_to_mga(bump%mpl,bump%ens1u%fld(:,:,iv,its,ie),fld_mga)
974  else
975  call bump%mpl%abort('parameter '//trim(param)//' not yet implemented in get_parameter')
976  end if
977  end select
978 end select
979 
980 end subroutine bump_copy_to_field
981 
982 !----------------------------------------------------------------------
983 ! Subroutine: bump_set_parameter
984 ! Purpose: set a parameter
985 !----------------------------------------------------------------------
986 subroutine bump_set_parameter(bump,param,fld_mga)
988 implicit none
989 
990 ! Passed variables
991 class(bump_type),intent(inout) :: bump ! BUMP
992 character(len=*),intent(in) :: param ! Parameter
993 real(kind_real),intent(in) :: fld_mga(bump%geom%nmga,bump%geom%nl0,bump%nam%nv,bump%nam%nts) ! Field
994 
995 ! Local variables
996 integer :: ib,iv,jv,its,jts
997 
998 select case (trim(param))
999 case ('var','cor_rh','cor_rv','cor_rv_rfac','cor_rv_coef','loc_coef','loc_rh','loc_rv','hyb_coef')
1000  select case (trim(bump%nam%strategy))
1001  case ('specific_univariate','specific_multivariate')
1002  do ib=1,bump%bpar%nb
1003  ! Get indices
1004  iv = bump%bpar%b_to_v1(ib)
1005  jv = bump%bpar%b_to_v2(ib)
1006  its = bump%bpar%b_to_ts1(ib)
1007  jts = bump%bpar%b_to_ts2(ib)
1008 
1009  ! Copy to field
1010  if ((iv==jv).and.(its==jts)) call bump%copy_from_field(param,ib,fld_mga(:,:,iv,its))
1011  end do
1012  case ('common','common_univariate','common_weighted')
1013  ! Set common index
1014  ib = bump%bpar%nbe
1015 
1016  do its=1,bump%nam%nts
1017  do iv=1,bump%nam%nv
1018  ! Copy to field
1019  call bump%copy_from_field(param,ib,fld_mga(:,:,iv,its))
1020  end do
1021  end do
1022  end select
1023 case default
1024  do ib=1,bump%bpar%nb
1025  ! Get indices
1026  iv = bump%bpar%b_to_v1(ib)
1027  jv = bump%bpar%b_to_v2(ib)
1028  its = bump%bpar%b_to_ts1(ib)
1029  jts = bump%bpar%b_to_ts2(ib)
1030 
1031  ! Copy to field
1032  if ((iv==jv).and.(its==jts)) call bump%copy_from_field(param,ib,fld_mga(:,:,iv,its))
1033  end do
1034 end select
1035 
1036 end subroutine bump_set_parameter
1037 
1038 !----------------------------------------------------------------------
1039 ! Subroutine: bump_copy_from_field
1040 ! Purpose: copy from field
1041 !----------------------------------------------------------------------
1042 subroutine bump_copy_from_field(bump,param,ib,fld_mga)
1044 implicit none
1045 
1046 ! Passed variables
1047 class(bump_type),intent(inout) :: bump ! BUMP
1048 character(len=*),intent(in) :: param ! Parameter
1049 integer,intent(in) :: ib ! Block index
1050 real(kind_real),intent(in) :: fld_mga(bump%geom%nmga,bump%geom%nl0) ! Field
1051 
1052 ! Allocation
1053 if (.not.allocated(bump%cmat%blk)) allocate(bump%cmat%blk(bump%bpar%nbe))
1054 
1055 ! Select parameter
1056 select case (trim(param))
1057 case ('var')
1058  if (.not.allocated(bump%cmat%blk(ib)%oops_coef_ens)) allocate(bump%cmat%blk(ib)%oops_coef_ens(bump%geom%nc0a,bump%geom%nl0))
1059  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_coef_ens)
1060 case ('cor_rh')
1061  if (.not.allocated(bump%cmat%blk(ib)%oops_rh)) allocate(bump%cmat%blk(ib)%oops_rh(bump%geom%nc0a,bump%geom%nl0))
1062  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rh)
1063  bump%cmat%blk(ib)%oops_rh = bump%cmat%blk(ib)%oops_rh/req
1064 case ('cor_rv')
1065  if (.not.allocated(bump%cmat%blk(ib)%oops_rv)) allocate(bump%cmat%blk(ib)%oops_rv(bump%geom%nc0a,bump%geom%nl0))
1066  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rv)
1067 case ('cor_rv_rfac')
1068  if (.not.allocated(bump%cmat%blk(ib)%oops_rv_rfac)) allocate(bump%cmat%blk(ib)%oops_rv_rfac(bump%geom%nc0a,bump%geom%nl0))
1069  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rv_rfac)
1070 case ('cor_rv_coef')
1071  if (.not.allocated(bump%cmat%blk(ib)%oops_rv_coef)) allocate(bump%cmat%blk(ib)%oops_rv_coef(bump%geom%nc0a,bump%geom%nl0))
1072  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rv_coef)
1073 case ('loc_coef')
1074  if (.not.allocated(bump%cmat%blk(ib)%oops_coef_ens)) allocate(bump%cmat%blk(ib)%oops_coef_ens(bump%geom%nc0a,bump%geom%nl0))
1075  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_coef_ens)
1076 case ('loc_rh')
1077  if (.not.allocated(bump%cmat%blk(ib)%oops_rh)) allocate(bump%cmat%blk(ib)%oops_rh(bump%geom%nc0a,bump%geom%nl0))
1078  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rh)
1079  bump%cmat%blk(ib)%oops_rh = bump%cmat%blk(ib)%oops_rh/req
1080 case ('loc_rv')
1081  if (.not.allocated(bump%cmat%blk(ib)%oops_rv)) allocate(bump%cmat%blk(ib)%oops_rv(bump%geom%nc0a,bump%geom%nl0))
1082  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_rv)
1083 case ('hyb_coef')
1084  if (.not.allocated(bump%cmat%blk(ib)%oops_coef_sta)) allocate(bump%cmat%blk(ib)%oops_coef_sta(bump%geom%nc0a,bump%geom%nl0))
1085  call bump%geom%copy_mga_to_c0a(bump%mpl,fld_mga,bump%cmat%blk(ib)%oops_coef_sta)
1086 case default
1087  call bump%mpl%abort('parameter '//trim(param)//' not yet implemented in set_parameter')
1088 end select
1089 
1090 end subroutine bump_copy_from_field
1091 
1092 !----------------------------------------------------------------------
1093 ! Subroutine: bump_dealloc
1094 ! Purpose: deallocation of BUMP fields
1095 !----------------------------------------------------------------------
1096 subroutine bump_dealloc(bump)
1098 implicit none
1099 
1100 ! Passed variables
1101 class(bump_type),intent(inout) :: bump ! BUMP
1102 
1103 ! Release memory
1104 call bump%cmat%dealloc(bump%bpar)
1105 call bump%ens1%dealloc
1106 call bump%ens1u%dealloc
1107 call bump%ens2%dealloc
1108 call bump%io%dealloc
1109 call bump%lct%dealloc(bump%bpar)
1110 call bump%nicas%dealloc(bump%nam,bump%geom,bump%bpar)
1111 call bump%obsop%dealloc
1112 call bump%vbal%dealloc(bump%nam)
1113 
1114 ! Final memory release (because objects required for previous memory releases)
1115 call bump%bpar%dealloc
1116 call bump%geom%dealloc
1117 
1118 end subroutine bump_dealloc
1119 
1120 end module type_bump
subroutine bump_setup_generic(bump)
Definition: type_bump.F90:198
subroutine bump_run_drivers(bump)
Definition: type_bump.F90:241
subroutine bump_apply_vbal_ad(bump, fld_mga)
Definition: type_bump.F90:560
subroutine bump_dealloc(bump)
Definition: type_bump.F90:1097
subroutine bump_copy_to_field(bump, param, ib, fld_mga)
Definition: type_bump.F90:910
subroutine bump_set_parameter(bump, param, fld_mga)
Definition: type_bump.F90:987
subroutine bump_apply_obsop_ad(bump, obs, fld_mga)
Definition: type_bump.F90:825
subroutine bump_apply_vbal(bump, fld_mga)
Definition: type_bump.F90:484
subroutine, public sphere_dist(lon_i, lat_i, lon_f, lat_f, dist)
Definition: tools_func.F90:67
subroutine bump_copy_from_field(bump, param, ib, fld_mga)
Definition: type_bump.F90:1043
subroutine bump_apply_nicas(bump, fld_mga)
Definition: type_bump.F90:636
real(kind_real), parameter, public deg2rad
Definition: tools_const.F90:16
real(kind=kind_real), parameter req
Earth radius at equator (m)
subroutine bump_apply_nicas_sqrt_ad(bump, fld_mga, pcv)
Definition: type_bump.F90:753
subroutine bump_add_member(bump, fld_mga, ie, iens)
Definition: type_bump.F90:437
subroutine bump_apply_vbal_inv(bump, fld_mga)
Definition: type_bump.F90:522
subroutine bump_setup_online(bump, nmga, nl0, nv, nts, lon, lat, area, vunit, lmask, ens1_ne, ens1_nsub, ens2_ne, ens2_nsub, nobs, lonobs, latobs, namelname, lunit)
Definition: type_bump.F90:82
integer, parameter, public kind_real
subroutine bump_apply_obsop(bump, fld_mga, obs)
Definition: type_bump.F90:796
subroutine bump_apply_nicas_sqrt(bump, pcv, fld_mga)
Definition: type_bump.F90:707
subroutine bump_get_parameter(bump, param, fld_mga)
Definition: type_bump.F90:854
subroutine bump_apply_vbal_inv_ad(bump, fld_mga)
Definition: type_bump.F90:598
subroutine bump_get_cv_size(bump, n)
Definition: type_bump.F90:684