SOCA
soca_bkgerr_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017-2021 UCAR
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 
6 !> variable transform: background error
8 
9 use datetime_mod, only: datetime
10 use fckit_configuration_module, only: fckit_configuration
11 use kinds, only: kind_real
12 
13 ! soca modules
16 use soca_geom_mod, only: soca_geom
18 use soca_state_mod, only: soca_state
19 
20 implicit none
21 private
22 
23 
24 !> Variable transform for background error
25 type, public :: soca_bkgerr
26  type(soca_fields) :: std_bkgerr
27 
28  ! private members
29  type(soca_bkgerr_bounds_type) , private :: bounds !< Bounds for bkgerr
30  type(soca_geom), pointer, private :: geom !< geometry
31 
32 contains
33 
34  !> \copybrief soca_bkgerr_setup \see soca_bkgerr_setup
35  procedure :: setup => soca_bkgerr_setup
36 
37  !> \copybrief soca_bkgerr_mult \see soca_bkgerr_mult
38  procedure :: mult => soca_bkgerr_mult
39 end type soca_bkgerr
40 
41 
42 ! ------------------------------------------------------------------------------
43 contains
44 ! ------------------------------------------------------------------------------
45 
46 
47 ! ------------------------------------------------------------------------------
48 !> Setup the static background error
49 !!
50 !! \note the precomputed standard devations in std_bkgerr are only used
51 !! for tocn, socn, and ssh.
52 !! \relates soca_bkgerr_mod::soca_bkgerr
53 subroutine soca_bkgerr_setup(self, f_conf, bkg, geom)
54  class(soca_bkgerr), intent(inout) :: self
55  type(fckit_configuration), intent(in) :: f_conf !< configuration
56  type(soca_state), target, intent(in) :: bkg !< background
57  type(soca_geom), target, intent(in) :: geom !< geometry
58 
59  type(soca_field), pointer :: field, field_bkg
60  real(kind=kind_real) :: std
61  integer :: i
62  type(datetime) :: vdate
63  character(len=800) :: fname = 'soca_bkgerrsoca.nc'
64 
65  self%geom => geom
66 
67  ! Allocate memory for bkgerror
68  call self%std_bkgerr%copy(bkg)
69  !call create_copy(self%std_bkgerr, bkg)
70 
71  ! Read variance
72  ! Precomputed from an ensemble of (K^-1 dx)
73  call self%std_bkgerr%read(f_conf, vdate)
74 
75  ! Convert to standard deviation
76  do i=1,size(self%std_bkgerr%fields)
77  field => self%std_bkgerr%fields(i)
78  select case(field%name)
79  case ("tocn", "socn", "ssh")
80  field%val = sqrt(field%val)
81  end select
82  end do
83 
84  ! Get bounds from configuration
85  call self%bounds%read(f_conf)
86 
87  ! Get constand background error for sst and sss
88  if ( f_conf%has("fixed_std_sst") ) then
89  call f_conf%get_or_die("fixed_std_sst", std)
90  call self%std_bkgerr%get("tocn", field)
91  field%val(:,:,1) = std
92  end if
93  if ( f_conf%has("fixed_std_sss") ) then
94  call f_conf%get_or_die("fixed_std_sss", std)
95  call self%std_bkgerr%get("socn", field)
96  field%val(:,:,1) = std
97  end if
98 
99  ! Invent background error for ocnsfc and ocn_bgc fields:
100  ! set it to 10% or 20% of the background for now ...
101  ! TODO: Read background error for ocnsfc and ocn_bgc from
102  ! files
103  do i=1,size(self%std_bkgerr%fields)
104  field => self%std_bkgerr%fields(i)
105  select case(field%name)
106  case ('sw','lw','lhf','shf','us')
107  call bkg%get(field%name, field_bkg)
108  field%val = abs(field_bkg%val) * 0.1_kind_real
109  case ('chl','biop')
110  call bkg%get(field%name, field_bkg)
111  field%val = abs(field_bkg%val) * 0.2_kind_real
112  end select
113  end do
114 
115  ! Apply config bounds to background error
116  call self%bounds%apply(self%std_bkgerr)
117 
118  ! Save filtered background error
119  call self%std_bkgerr%write_file(fname)
120 
121 end subroutine soca_bkgerr_setup
122 
123 
124 ! ------------------------------------------------------------------------------
125 !> Apply background error: dxm = D dxa
126 !!
127 !! \relates soca_bkgerr_mod::soca_bkgerr
128 subroutine soca_bkgerr_mult(self, dxa, dxm)
129  class(soca_bkgerr), intent(in) :: self
130  type(soca_increment), intent(in) :: dxa !< input increment
131  type(soca_increment), intent(inout) :: dxm !< output increment
132 
133  type(soca_field), pointer :: field_m, field_a, field_e
134 
135  integer :: isc, iec, jsc, jec, i, j, n
136 
137  ! make sure fields are correct shape
138  call dxa%check_congruent(dxm)
139  call dxa%check_subset(self%std_bkgerr)
140 
141  ! Indices for compute domain (no halo)
142  isc=self%geom%isc; iec=self%geom%iec
143  jsc=self%geom%jsc; jec=self%geom%jec
144 
145  ! multiply
146  do n=1,size(dxa%fields)
147  field_a => dxa%fields(n)
148  call self%std_bkgerr%get(field_a%name, field_e)
149  call dxm%get(field_a%name, field_m)
150  do i = isc, iec
151  do j = jsc, jec
152  field_m%val(i,j,:) = field_e%val(i,j,:) * field_a%val(i,j,:)
153  end do
154  end do
155  end do
156 end subroutine soca_bkgerr_mult
157 
158 ! ------------------------------------------------------------------------------
159 
160 end module soca_bkgerr_mod
variable transform: background error
bakground error bounds
Handle fields for the model.
Geometry module.
Increment fields.
State fields.
Variable transform for background error.
Holds all data and metadata related to a single field variable.
A collection of soca_field types representing a collective state or increment.
Geometry data structure.