UFO
ufo_backgrounderroridentity_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2021 Met Office UK
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
7 
8 use iso_c_binding, only: c_ptr
9 use oops_variables_mod, only: oops_variables
11 
12 contains
13 
14 !> For each obs diagnostic called <var>_background_error, where <var> belongs to the set of variable
15 !> names @p obsvars, fill this diagnostic with estimates of the background error of variable <var>
16 !> at observation locations.
17 subroutine ufo_backgrounderroridentity_fillobsdiags(geovals, nlocs, obsvars, obsdiags)
18  use kinds, only: kind_real
20  use ufo_vars_mod, only: maxvarlen
21  implicit none
22 
23  type(ufo_geovals), intent(in) :: geovals
24  integer, intent(in) :: nlocs
25  type(oops_variables), intent(in) :: obsvars
26  type(ufo_geovals), intent(inout) :: obsdiags
27 
28  type(ufo_geoval), pointer :: background_error
29  integer :: ivar
30  character(len=MAXVARLEN) :: varstr
31  integer :: lenvarstr
32 
33  character(len=*), parameter :: suffix = "_background_error"
34 
35  do ivar = 1, obsdiags%nvar
36  varstr = obsdiags%variables(ivar)
37  lenvarstr = len_trim(varstr)
38 
39  ! We need to fill this diagnostic if:
40  ! (a) its name is long enough to be of the form `<var>_background_error`;
41  if (lenvarstr <= len(suffix)) cycle
42  ! (b) its name actually *is* of the form `<var>_background_error`;
43  if (varstr(lenvarstr - len(suffix)+1:lenvarstr) /= suffix) cycle
44  ! (c) <var> belongs to the list obsvars.
45  if (.not. obsvars%has(varstr(:lenvarstr - len(suffix)))) cycle
46 
47  ! All tests passed -- fill the diagnostic.
48 
49  ! Get the background error geoval.
50  call ufo_geovals_get_var(geovals, varstr, background_error)
51 
52  ! Allocate the background error diagnostic.
53  if (allocated(obsdiags%geovals(ivar)%vals)) deallocate(obsdiags%geovals(ivar)%vals)
54  obsdiags%geovals(ivar)%nval = 1
55  allocate(obsdiags%geovals(ivar)%vals(obsdiags%geovals(ivar)%nval, nlocs))
56 
57  ! Copy the geoval to the diagnostic.
58  obsdiags%geovals(ivar)%vals(1, 1:nlocs) = background_error%vals(1, 1:nlocs)
59  enddo
61 
subroutine ufo_backgrounderroridentity_fillobsdiags(geovals, nlocs, obsvars, obsdiags)
For each obs diagnostic called _background_error, where belongs to the set of variable names obsvars...
subroutine, public ufo_geovals_get_var(self, varname, geoval)
integer, parameter, public maxvarlen
type to hold interpolated field for one variable, one observation
type to hold interpolated fields required by the obs operators