SOCA
soca_omb_stats_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 !> surface background error used by soca_bkgerrgodas_mod
8 
9 use fckit_mpi_module, only: fckit_mpi_comm
10 use kinds, only: kind_real
11 use netcdf
13 
14 implicit none
15 private
16 
17 
18 !> domain indices used by soca_omb_stats
19 type, public :: soca_domain_indices ! TODO: Move elsewhere!
20  integer :: is, ie, js, je ! Compute domain indices
21  integer :: isl, iel, jsl, jel ! Local compute domain indices
22 end type soca_domain_indices
23 
24 
25 !> interpolate surface background error file to grid
26 !!
27 !! Used by soca_bkgerrgodas_mod::soca_bkgerrgodas_config
28 type, public :: soca_omb_stats
29  integer :: nlocs
30  real(kind=kind_real), allocatable :: lon(:)
31  real(kind=kind_real), allocatable :: lat(:)
32  real(kind=kind_real), allocatable :: bgerr(:)
33  real(kind=kind_real), allocatable :: bgerr_model(:,:)
34  type(soca_domain_indices) :: domain
35  contains
36 
37  !> \copybrief soca_omb_stats_init \see soca_omb_stats_init
38  procedure :: init => soca_omb_stats_init
39 
40  !> \copybrief soca_omb_stats_bin \see soca_omb_stats_bin
41  procedure :: bin => soca_omb_stats_bin
42 
43  !> \copybrief soca_omb_stats_exit \see soca_omb_stats_exit
44  procedure :: exit => soca_omb_stats_exit
45 end type soca_omb_stats
46 
47 
48 contains
49 
50 ! ------------------------------------------------------------------------------
51 !> constructor
52 !!
53 !! \relates soca_omb_stats_mod::soca_omb_stats
54 subroutine soca_omb_stats_init(self, domain)
55  class(soca_omb_stats), intent(inout) :: self
56  type(soca_domain_indices), intent(in) :: domain
57 
58  integer(kind=4) :: ncid
59  integer(kind=4) :: dimid
60  integer(kind=4) :: varid
61  type(fckit_mpi_comm) :: f_comm
62  integer :: myrank, root=0
63 
64  ! Setup Communicator
65  f_comm = fckit_mpi_comm()
66  myrank = f_comm%rank()
67 
68  if (myrank.eq.root) then
69 
70  call nc_check(nf90_open('godas_sst_bgerr.nc', nf90_nowrite,ncid))
71 
72  ! Get the size of the horizontal grid
73  call nc_check(nf90_inq_dimid(ncid, 'nlocs', dimid))
74  call nc_check(nf90_inquire_dimension(ncid, dimid, len = self%nlocs))
75 
76  allocate(self%lon(self%nlocs), self%lat(self%nlocs), self%bgerr(self%nlocs))
77 
78  ! Get longitude
79  call nc_check(nf90_inq_varid(ncid,'longitude',varid))
80  call nc_check(nf90_get_var(ncid,varid,self%lon))
81 
82  ! Get latitude
83  call nc_check(nf90_inq_varid(ncid,'latitude',varid))
84  call nc_check(nf90_get_var(ncid,varid,self%lat))
85 
86  ! Get omb stats
87  call nc_check(nf90_inq_varid(ncid,'sst_bgerr',varid))
88  call nc_check(nf90_get_var(ncid,varid,self%bgerr))
89 
90  ! Close netcdf file
91  call nc_check(nf90_close(ncid))
92  end if
93 
94  ! Broadcast to all workers
95  call f_comm%broadcast(self%nlocs, root)
96  if (myrank.ne.root) then
97  allocate(self%lon(self%nlocs), self%lat(self%nlocs), self%bgerr(self%nlocs))
98  end if
99  call f_comm%broadcast(self%lon, root)
100  call f_comm%broadcast(self%lat, root)
101  call f_comm%broadcast(self%bgerr, root)
102  call f_comm%barrier()
103 
104  ! Rotate longitude
105  where (self%lon>180.0_kind_real)
106  self%lon=self%lon-360.0_kind_real
107  end where
108 
109  ! Compute domain info
110  self%domain = domain
111 
112 end subroutine soca_omb_stats_init
113 
114 
115 ! ------------------------------------------------------------------------------
116 !> remap background error to grid
117 !!
118 !! \relates soca_omb_stats_mod::soca_omb_stats
119 subroutine soca_omb_stats_bin(self, lon, lat)
120  class(soca_omb_stats), intent(inout) :: self
121  real(kind=kind_real), intent(in) :: lon(:,:)
122  real(kind=kind_real), intent(in) :: lat(:,:)
123 
124  integer :: is, ie, js, je
125  integer :: isl, iel, jsl, jel
126 
127  ! Short cuts to global indices
128  is = self%domain%is
129  ie = self%domain%ie
130  js = self%domain%js
131  je = self%domain%je
132 
133  ! Short cuts to local indices
134  isl = self%domain%isl
135  iel = self%domain%iel
136  jsl = self%domain%jsl
137  jel = self%domain%jel
138 
139  allocate(self%bgerr_model(is:ie,js:je))
140  self%bgerr_model = 0.0_kind_real
141  call soca_remap_idw(self%lon, self%lat, self%bgerr,&
142  lon(isl:iel,jsl:jel), lat(isl:iel,jsl:jel), &
143  self%bgerr_model(is:ie,js:je))
144 
145 end subroutine soca_omb_stats_bin
146 
147 
148 ! ------------------------------------------------------------------------------
149 !> Destructor
150 !!
151 !! \relates soca_omb_stats_mod::soca_omb_stats
152 subroutine soca_omb_stats_exit(self)
153  class(soca_omb_stats), intent(inout) :: self
154 
155  deallocate(self%lon, self%lat, self%bgerr, self%bgerr_model)
156 
157 end subroutine soca_omb_stats_exit
158 
159 end module soca_omb_stats_mod
surface background error used by soca_bkgerrgodas_mod
various utility functions
Definition: soca_utils.F90:7
subroutine, public nc_check(status)
wrapper for netcdf calls
Definition: soca_utils.F90:157
subroutine, public soca_remap_idw(lon_src, lat_src, data_src, lon_dst, lat_dst, data_dst)
inverse distance weighted remaping (modified Shepard's method)
Definition: soca_utils.F90:189
domain indices used by soca_omb_stats
interpolate surface background error file to grid