UFO
ufo_rttovonedvarcheck_utils_mod.f90
Go to the documentation of this file.
1 ! (C) copyright 2020 Met Office
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 !> Fortran module containing main type, setup and utilities for the
7 !! main rttovonedvarcheck object
8 
10 
11 use fckit_configuration_module, only: fckit_configuration
12 use iso_c_binding
13 use kinds
15 
16 implicit none
17 private
18 
20 
21 !===============================================================================
22 ! type definitions
23 !===============================================================================
24 
25 !---------------
26 ! 1. 1DVar type
27 !---------------
28 
29 type, public :: ufo_rttovonedvarcheck
30  character(len=max_string) :: qcname !< name of the filter
31  character(len=max_string) :: b_matrix_path !< path to the b-matrix file
32  character(len=max_string) :: r_matrix_path !< path to the r-matrix file
33  character(len=max_string) :: forward_mod_name !< forward model name (only RTTOV at the moment)
34  character(len=max_string), allocatable :: retrieval_variables(:) !< list of variables which form the 1D-var retrieval vector
35  type(c_ptr) :: obsdb !< pointer to the observation space
36  integer(c_int) :: onedvarflag !< flag uased by the qc manager for a 1D-var check
37  integer(c_int) :: passflag !< flag uased by the qc manager to flag good data
38  integer :: nlevels ! number 1D-Var model levels
39  integer :: nmvars !< number of variables being used in the retrieval
40  integer :: nchans !< maximum number of channels (channels can be removed by previous qc checks)
41  integer(c_int), allocatable :: channels(:) !< integer list of channels
42  integer :: startob !< starting ob number for testing
43  integer :: finishob !< finishing ob number for testing
44  logical :: qtotal !< flag to enable total humidity retrievals
45  logical :: useqtsplitrain !< flag to choose whether to split rain in qsplit routine
46  logical :: rttov_mwscattswitch !< flag to switch on RTTOV-scatt
47  logical :: rttov_usetotalice !< flag for use of total ice in RTTOV MW scatt
48  logical :: usemlminimization !< flag to turn on marquardt-levenberg minimizer
49  logical :: usejforconvergence !< flag to Use J for convergence
50  logical :: userhwaterforqc !< flag to use water in relative humidity check
51  logical :: store1dvarlwp !< Output the LWP if the profile converges
52  logical :: usecoldsurfacecheck !< flag to use cold water check to adjust starting surface parameters
53  logical :: fulldiagnostics !< flag to turn on full diagnostics
54  logical :: pcemiss !< flag gets turned off in emissivity eigen vector file is present
55  integer :: max1dvariterations !< maximum number of iterations
56  integer :: jconvergenceoption !< integer to select convergence option
57  integer :: iternumforlwpcheck !< choose which iteration to start checking LWP
58  integer :: maxmliterations !< maximum number of iterations for internal Marquardt-Levenberg loop
59  real(kind_real) :: retrievederrorfactor !< check retrieved BTs all within factor * stdev of obs
60  real(kind_real) :: convergencefactor !< 1d-var convergence if using change in profile
61  real(kind_real) :: cost_convergencefactor !< 1d-var convergence if using % change in cost
62  real(kind_real) :: emisslanddefault !< default emissivity value to use over land
63  real(kind_real) :: emissseaicedefault !< default emissivity value to use over sea ice
64  character(len=max_string) :: emiseigvecpath !< path to eigen vector file for IR PC emissivity
65  character(len=max_string) :: emisatlas !< path to the emissivity atlas for IR PC emissivity
66 end type ufo_rttovonedvarcheck
67 
68 contains
69 
70 !------------------------------------------------------------------------------
71 !> Setup the defaults for the main rttovonedvarcheck object and read in the
72 !! contents of the yaml file.
73 !!
74 !! \author Met Office
75 !!
76 !! \date 09/06/2020: Created
77 !!
78 subroutine ufo_rttovonedvarcheck_setup(self, f_conf, channels)
79 
80 implicit none
81 
82 ! subroutine arguments
83 type(ufo_rttovonedvarcheck), intent(inout) :: self
84 type(fckit_configuration), intent(in) :: f_conf !< yaml file contents
85 integer(c_int), intent(in) :: channels(:)
86 
87 ! local variables
88 character(len=max_string) :: tmp
89 character(len=:), allocatable :: str
90 character(len=:), allocatable :: str_array(:)
91 
92 ! Setup core paths and names
93 self % qcname = "rttovonedvarcheck"
94 call f_conf % get_or_die("BMatrix",str)
95 self % b_matrix_path = str
96 call f_conf % get_or_die("RMatrix",str)
97 self % r_matrix_path = str
98 call f_conf % get_or_die("ModName",str)
99 self % forward_mod_name = str
100 call f_conf % get_or_die("nlevels",self % nlevels)
101 
102 ! Variables for profile (x,xb)
103 self % nmvars = f_conf % get_size("retrieval variables")
104 allocate(self % retrieval_variables(self % nmvars))
105 call f_conf % get_or_die("retrieval variables", str_array)
106 self % retrieval_variables(1:self % nmvars) = str_array
107 
108 ! Satellite channels
109 self % nchans = size(channels)
110 allocate(self % channels(self % nchans))
111 self % channels(:) = channels(:)
112 
113 ! Flag for total humidity
114 call f_conf % get_or_die("qtotal", self % qtotal)
115 
116 ! Flag to choose whether to split rain in qsplit routine
117 call f_conf % get_or_die("UseQtSplitRain", self % UseQtsplitRain)
118 
119 ! Flag for RTTOV MW scatt
120 call f_conf % get_or_die("RTTOVMWScattSwitch", self % RTTOV_mwscattSwitch)
121 
122 ! Flag for use of total ice in RTTOV MW scatt
123 call f_conf % get_or_die("RTTOVUseTotalIce", self % RTTOV_usetotalice)
124 
125 ! Flag to turn on marquardt-levenberg minimiser
126 call f_conf % get_or_die("UseMLMinimization", self % UseMLMinimization)
127 
128 ! Flag to Use J for convergence
129 call f_conf % get_or_die("UseJforConvergence", self % UseJforConvergence)
130 
131 ! Flag to use water in relative humidity check
132 call f_conf % get_or_die("UseRHwaterForQC", self % UseRHwaterForQC)
133 
134 ! Flag to use cold water check to adjust starting surface parameters
135 call f_conf % get_or_die("UseColdSurfaceCheck", self % UseColdSurfaceCheck)
136 
137 ! Flag to output the LWP if the profile converges
138 call f_conf % get_or_die("Store1DVarLWP", self % Store1DVarLWP)
139 
140 ! Flag to turn on full diagnostics
141 call f_conf % get_or_die("FullDiagnostics", self % FullDiagnostics)
142 
143 ! maximum number of iterations allowed
144 call f_conf % get_or_die("Max1DVarIterations", self % Max1DVarIterations)
145 
146 ! integer to select convergence option
147 ! 1= percentage change in cost tested between iterations
148 ! otherwise = absolute change in cost tested between iterations
149 call f_conf % get_or_die("JConvergenceOption", self % JConvergenceOption)
150 
151 ! Choose which iteration to start checking the liquid water path
152 call f_conf % get_or_die("IterNumForLWPCheck", self % IterNumForLWPCheck)
153 
154 ! Check the retrieved brightness temperatures are within a factor * error of the
155 ! observed and bias corrected BTs. If this value is less than 0.0 this check is
156 ! not performed
157 call f_conf % get_or_die("RetrievedErrorFactor", self % RetrievedErrorFactor)
158 
159 ! Convergence factor used when the absolute difference in the profile is used
160 ! to determine convergence.
161 call f_conf % get_or_die("ConvergenceFactor", self % ConvergenceFactor)
162 
163 ! Cost threshold for convergence check when cost function value is used for convergence
164 call f_conf % get_or_die("CostConvergenceFactor", self % Cost_ConvergenceFactor)
165 
166 ! Maximum number of iterations for internal Marquardt-Levenberg loop
167 call f_conf % get_or_die("MaxMLIterations", self % MaxMLIterations)
168 
169 ! Starting observation number for loop - used for testing
170 call f_conf % get_or_die("StartOb", self % StartOb)
171 
172 ! Finishing observation number for loop - used for testing
173 call f_conf % get_or_die("FinishOb", self % FinishOb)
174 
175 ! Default emissivity value to use over land
176 call f_conf % get_or_die("EmissLandDefault", self % EmissLandDefault)
177 
178 ! Default emissivity value to use over seaice
179 call f_conf % get_or_die("EmissSeaIceDefault", self % EmissSeaIceDefault)
180 
181 ! Default eigen value path is blank but needs to be present if using PC emiss
182 call f_conf % get_or_die("EmisEigVecPath",str)
183 self % EmisEigVecPath = str
184 self % pcemiss = .false.
185 if (len(trim(self % EmisEigVecPath)) > 4) then
186  self % pcemiss = .true.
187 end if
188 
189 ! Default emis atlas path is blank
190 call f_conf % get_or_die("EmisAtlas",str)
191 self % EmisAtlas = str
192 
193 ! Print self
194 if (self % FullDiagnostics) then
195  call ufo_rttovonedvarcheck_print(self)
196 end if
197 
198 end subroutine ufo_rttovonedvarcheck_setup
199 
200 !------------------------------------------------------------------------------
201 !> Print contents of rttovonedvarcheck object
202 !!
203 !! \author Met Office
204 !!
205 !! \date 03/08/2020: Created
206 !!
208 
209 implicit none
210 
211 type(ufo_rttovonedvarcheck), intent(in) :: self
212 
213 integer :: ii
214 
215 write(*,*) "qcname = ", trim(self % qcname)
216 write(*,*) "b_matrix_path = ", trim(self % b_matrix_path)
217 write(*,*) "r_matrix_path = ", trim(self % r_matrix_path)
218 write(*,*) "forward_mod_name = ", trim(self % forward_mod_name)
219 write(*,*) "retrieval_variables = "
220 do ii = 1, self % nmvars
221  write(*,*) trim(self % retrieval_variables(ii))," "
222 end do
223 write(*,*) "nlevels = ",self % nlevels
224 write(*,*) "nmvars = ",self % nmvars
225 write(*,*) "nchans = ",self % nchans
226 write(*,*) "channels(:) = ",self % channels(:)
227 write(*,*) "qtotal = ",self % qtotal
228 write(*,*) "RTTOV_mwscattSwitch = ",self % RTTOV_mwscattSwitch
229 write(*,*) "RTTOV_usetotalice = ",self % RTTOV_usetotalice
230 write(*,*) "UseMLMinimization = ",self % UseMLMinimization
231 write(*,*) "UseJforConvergence = ",self % UseJforConvergence
232 write(*,*) "UseRHwaterForQC = ", self % UseRHwaterForQC
233 write(*,*) "UseColdSurfaceCheck = ", self % UseColdSurfaceCheck
234 write(*,*) "UseQtsplitRain = ",self % UseQtsplitRain
235 write(*,*) "FullDiagnostics = ",self % FullDiagnostics
236 write(*,*) "Max1DVarIterations = ",self % Max1DVarIterations
237 write(*,*) "JConvergenceOption = ",self % JConvergenceOption
238 write(*,*) "IterNumForLWPCheck = ",self % IterNumForLWPCheck
239 write(*,*) "ConvergenceFactor = ",self % ConvergenceFactor
240 write(*,*) "CostConvergenceFactor = ",self % Cost_ConvergenceFactor
241 write(*,*) "MaxMLIterations = ",self % MaxMLIterations
242 write(*,*) "EmissLandDefault = ",self % EmissLandDefault
243 write(*,*) "EmissSeaIceDefault = ",self % EmissSeaIceDefault
244 write(*,*) "Use PC for Emissivity = ", self % pcemiss
245 write(*,*) "EmisEigVecPath = ",self % EmisEigVecPath
246 write(*,*) "EmisAtlas = ",self % EmisAtlas
247 
248 end subroutine ufo_rttovonedvarcheck_print
249 
250 ! ------------------------------------------------------------------------------
251 
Fortran module constants used throughout the rttovonedvarcheck filter.
Fortran module containing main type, setup and utilities for the main rttovonedvarcheck object.
subroutine ufo_rttovonedvarcheck_print(self)
Print contents of rttovonedvarcheck object.
subroutine, public ufo_rttovonedvarcheck_setup(self, f_conf, channels)
Setup the defaults for the main rttovonedvarcheck object and read in the contents of the yaml file.