UFO
ufo_roobserror_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017-2018 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 !> Fortran module to implement RO observational error
7 
9 use fckit_configuration_module, only: fckit_configuration
10 use kinds
12 use obsspace_mod
13 use oops_variables_mod
14 use missing_values_mod
16 use fckit_log_module, only : fckit_log
17 
18 implicit none
20 public :: ufo_roobserror_prior
21 public :: max_string
22 private
23 
24 ! ------------------------------------------------------------------------------
26  character(len=max_string) :: variable
27  character(len=max_string) :: errmodel
28  type(oops_variables), public :: obsvar
29  type(c_ptr) :: obsdb
30 end type ufo_roobserror
31 
32 ! ------------------------------------------------------------------------------
33 contains
34 ! ------------------------------------------------------------------------------
35 
36 subroutine ufo_roobserror_create(self, obspace, f_conf)
37 use iso_c_binding
38 use oops_variables_mod
39 implicit none
40 type(ufo_roobserror), intent(inout) :: self
41 type(c_ptr), value, intent(in) :: obspace
42 type(fckit_configuration), intent(in) :: f_conf
43 character(len=:), allocatable :: str
44 
45 self%errmodel = "NBAM"
46 if (f_conf%has("errmodel")) then
47  call f_conf%get_or_die("errmodel",str)
48  self%errmodel = str
49 end if
50 self%obsdb = obspace
51 
52 end subroutine ufo_roobserror_create
53 
54 ! ------------------------------------------------------------------------------
55 
56 subroutine ufo_roobserror_delete(self)
57 implicit none
58 type(ufo_roobserror), intent(inout) :: self
59 end subroutine ufo_roobserror_delete
60 
61 ! ------------------------------------------------------------------------------
62 
63 subroutine ufo_roobserror_prior(self)
64 use fckit_log_module, only : fckit_log
65 implicit none
66 type(ufo_roobserror), intent(in) :: self
67 integer :: nobs
68 real(kind_real), allocatable :: obsz(:), obslat(:)
69 real(kind_real), allocatable :: obsimph(:),obsimpp(:),obsgeoid(:),obslocr(:)
70 real(kind_real), allocatable :: obsvalue(:)
71 real(kind_real), allocatable :: obserr(:)
72 integer(c_int), allocatable :: obssaid(:)
73 integer(c_int), allocatable :: qcflags(:)
74 real(kind_real) :: missing
75 character(max_string) :: err_msg
76 
77 missing = missing_value(missing)
78 nobs = obsspace_get_nlocs(self%obsdb)
79 allocate(qcflags(nobs))
80 allocate(obserr(nobs))
81 qcflags(:) = 0
82 
83 ! read QC flags
84 call obsspace_get_db(self%obsdb, "FortranQC", trim(self%variable),qcflags )
85 
86 !-------------------------------
87 select case (trim(self%variable))
88 
89 !-------------------------------
90 case ("bending_angle")
91 
92  allocate(obsimpp(nobs))
93  allocate(obsgeoid(nobs))
94  allocate(obslocr(nobs))
95  allocate(obsimph(nobs))
96  call obsspace_get_db(self%obsdb, "MetaData", "impact_parameter", obsimpp)
97  call obsspace_get_db(self%obsdb, "MetaData", "geoid_height_above_reference_ellipsoid",obsgeoid)
98  call obsspace_get_db(self%obsdb, "MetaData", "earth_radius_of_curvature", obslocr)
99  obsimph(:) = obsimpp(:) - obsgeoid(:) - obslocr(:)
100 
101  select case (trim(self%errmodel))
102  case ("NBAM")
103  allocate(obssaid(nobs))
104  allocate(obslat(nobs))
105  call obsspace_get_db(self%obsdb, "MetaData", "occulting_sat_id", obssaid)
106  call obsspace_get_db(self%obsdb, "MetaData", "latitude", obslat)
107  call bending_angle_obserr_nbam(obslat, obsimph, obssaid, nobs, obserr, qcflags, missing)
108  write(err_msg,*) "ufo_roobserror_mod: setting up bending_angle obs error with NBAM method"
109  call fckit_log%info(err_msg)
110  deallocate(obssaid)
111  deallocate(obslat)
112  ! update obs error
113  call obsspace_put_db(self%obsdb, "FortranERR", trim(self%variable), obserr)
114 
115  case ("ECMWF")
116  allocate(obsvalue(nobs))
117  call obsspace_get_db(self%obsdb, "ObsValue", "bending_angle", obsvalue)
118  call bending_angle_obserr_ecmwf(obsimph, obsvalue, nobs, obserr, qcflags, missing)
119  write(err_msg,*) "ufo_roobserror_mod: setting up bending_angle obs error with ECMWF method"
120  call fckit_log%info(err_msg)
121  deallocate(obsvalue)
122  ! update obs error
123  call obsspace_put_db(self%obsdb, "FortranERR", trim(self%variable), obserr)
124  case ("NRL")
125  allocate(obsvalue(nobs))
126  allocate(obslat(nobs))
127  call obsspace_get_db(self%obsdb, "ObsValue", "bending_angle", obsvalue)
128  call obsspace_get_db(self%obsdb, "MetaData", "latitude", obslat)
129  call bending_angle_obserr_nrl(obslat, obsimph, obsvalue, nobs, obserr, qcflags, missing)
130  write(err_msg,*) "ufo_roobserror_mod: setting up bending_angle obs error with NRL method"
131  call fckit_log%info(err_msg)
132  deallocate(obsvalue)
133  deallocate(obslat)
134  ! update obs error
135  call obsspace_put_db(self%obsdb, "FortranERR", trim(self%variable), obserr)
136 
137  case default
138  write(err_msg,*) "ufo_roobserror_mod: bending_angle error model must be NBAM, ECMWF, or NRL"
139  call fckit_log%info(err_msg)
140  call fckit_log%info(err_msg)
141  end select
142  deallocate(obsimpp)
143  deallocate(obsgeoid)
144  deallocate(obslocr)
145  deallocate(obsimph)
146 
147 !-------------------------------
148 case ("refractivity")
149 
150  select case (trim(self%errmodel))
151 
152  case ("NBAM")
153 
154  allocate(obsz(nobs))
155  allocate(obslat(nobs))
156  call obsspace_get_db(self%obsdb, "MetaData", "altitude", obsz)
157  call obsspace_get_db(self%obsdb, "MetaData", "latitude", obslat)
158  call refractivity_obserr_nbam(obslat, obsz, nobs, obserr, qcflags, missing)
159  write(err_msg,*) "ufo_roobserror_mod: setting up refractivity obs error with NBAM method"
160  call fckit_log%info(err_msg)
161  deallocate(obsz)
162  deallocate(obslat)
163  ! up date obs error
164  call obsspace_put_db(self%obsdb, "FortranERR", trim(self%variable), obserr)
165 
166  case ("ECMWF")
167  write(err_msg,*) "ufo_roobserror_mod: ECMWF refractivity error model is not available now"
168  call fckit_log%info(err_msg)
169 
170  case default
171  write(err_msg,*) "ufo_roobserror_mod: only NBAM refractivity model is available now"
172  call fckit_log%info(err_msg)
173  end select
174 
175 case default
176  call abor1_ftn("ufo_roobserror_prior: variable has to be bending_angle or refractivity")
177 end select
178 
179 deallocate(qcflags)
180 deallocate(obserr)
181 
182 end subroutine ufo_roobserror_prior
183 
184 end module ufo_roobserror_mod
ufo_avgkernel_mod::max_string
integer, parameter max_string
Definition: ufo_avgkernel_mod.F90:17
ufo_roobserror_mod::ufo_roobserror_prior
subroutine, public ufo_roobserror_prior(self)
Definition: ufo_roobserror_mod.F90:64
ufo_gnssro_bndnbam_tlad_mod::missing
real(c_double) missing
Definition: ufo_gnssro_bndnbam_tlad_mod.F90:23
gnssro_mod_obserror::refractivity_obserr_nbam
subroutine refractivity_obserr_nbam(obsLat, obsZ, nobs, obsErr, QCflags, missing)
Definition: gnssro_mod_obserror.F90:137
gnssro_mod_obserror
Definition: gnssro_mod_obserror.F90:2
ufo_geovals_mod
Definition: ufo_geovals_mod.F90:7
ufo_roobserror_mod::ufo_roobserror_create
subroutine, public ufo_roobserror_create(self, obspace, f_conf)
Definition: ufo_roobserror_mod.F90:37
gnssro_mod_obserror::bending_angle_obserr_nbam
subroutine bending_angle_obserr_nbam(obsLat, obsImpH, obsSaid, nobs, obsErr, QCflags, missing)
Definition: gnssro_mod_obserror.F90:77
ufo_roobserror_mod::ufo_roobserror
Definition: ufo_roobserror_mod.F90:25
ufo_roobserror_mod::ufo_roobserror_delete
subroutine, public ufo_roobserror_delete(self)
Definition: ufo_roobserror_mod.F90:57
ufo_roobserror_mod
Fortran module to implement RO observational error.
Definition: ufo_roobserror_mod.F90:8
gnssro_mod_obserror::bending_angle_obserr_nrl
subroutine bending_angle_obserr_nrl(obsLat, obsImpH, obsValue, nobs, obsErr, QCflags, missing)
Definition: gnssro_mod_obserror.F90:42
gnssro_mod_obserror::bending_angle_obserr_ecmwf
subroutine bending_angle_obserr_ecmwf(obsImpH, obsValue, nobs, obsErr, QCflags, missing)
Definition: gnssro_mod_obserror.F90:10