SOCA
soca_covariance.interface.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 !> C++ interfaces for soca_covariance_mod::soca_cov
8 
9 use fckit_configuration_module, only: fckit_configuration
10 use iso_c_binding
11 use oops_variables_mod, only: oops_variables
12 
13 ! soca modules
16 use soca_geom_mod, only : soca_geom
19 use soca_state_mod, only : soca_state
21 
22 implicit none
23 private
24 
25 #define LISTED_TYPE soca_cov
26 
27 !> Linked list interface - defines registry_t type
28 #include "oops/util/linkedList_i.f"
29 
30 !> Global registry for soca_cov
31 type(registry_t), public :: soca_cov_registry
32 
33 ! ------------------------------------------------------------------------------
34 contains
35 ! ------------------------------------------------------------------------------
36 !> Linked list implementation
37 #include "oops/util/linkedList_c.f"
38 ! ------------------------------------------------------------------------------
39 
40 
41 ! ------------------------------------------------------------------------------
42 !> C++ interface for soca_covariance_mod::soca_cov::setup()
43 !!
44 !! Setup for the SOCA model's background error covariance matrix
45 subroutine soca_b_setup_c(c_key_self, c_conf, c_key_geom, c_key_bkg, c_vars) &
46  & bind(c,name='soca_b_setup_f90')
47  integer(c_int), intent(inout) :: c_key_self !< The background covariance structure
48  type(c_ptr), intent(in) :: c_conf !< The configuration
49  integer(c_int), intent(in) :: c_key_geom !< Geometry
50  integer(c_int), intent(in) :: c_key_bkg !< Background
51  type(c_ptr),value, intent(in) :: c_vars !< List of variables
52 
53  type(soca_cov), pointer :: self
54  type(soca_geom), pointer :: geom
55  type(soca_state), pointer :: bkg
56  type(oops_variables) :: vars
57 
58  call soca_geom_registry%get(c_key_geom, geom)
59  call soca_cov_registry%init()
60  call soca_cov_registry%add(c_key_self)
61  call soca_cov_registry%get(c_key_self, self)
62  call soca_state_registry%get(c_key_bkg,bkg)
63  vars = oops_variables(c_vars)
64  call self%setup(fckit_configuration(c_conf), geom, bkg, vars)
65 
66 end subroutine soca_b_setup_c
67 
68 
69 ! ------------------------------------------------------------------------------
70 !> C++ interface for soca_covariance_mod::soca_cov::delete()
71 !!
72 !! Delete for the SOCA model's background error covariance matrix
73 subroutine soca_b_delete_c(c_key_self) bind (c,name='soca_b_delete_f90')
74  integer(c_int), intent(inout) :: c_key_self !< The background covariance structure
75 
76  type(soca_cov), pointer :: self
77 
78  call soca_cov_registry%get(c_key_self,self)
79  call self%delete()
80  call soca_cov_registry%remove(c_key_self)
81 
82 end subroutine soca_b_delete_c
83 
84 
85 ! ------------------------------------------------------------------------------
86 !> C++ interface for soca_covariance_mod::soca_cov::mult()
87 subroutine soca_b_mult_c(c_key_self, c_key_in, c_key_out) bind(c,name='soca_b_mult_f90')
88  integer(c_int), intent(inout) :: c_key_self !< The background covariance structure
89  integer(c_int), intent(in) :: c_key_in !< " to Increment in
90  integer(c_int), intent(in) :: c_key_out !< " to Increment out
91 
92  type(soca_cov), pointer :: self
93  type(soca_increment), pointer :: xin
94  type(soca_increment), pointer :: xout
95 
96  call soca_cov_registry%get(c_key_self, self)
97  call soca_increment_registry%get(c_key_in, xin)
98  call soca_increment_registry%get(c_key_out, xout)
99 
100  call xout%copy(xin) !< xout = xin
101  call self%mult(xout) !< xout = C.xout
102 
103 end subroutine soca_b_mult_c
104 
105 
106 ! ------------------------------------------------------------------------------
107 !> C++ interface for soca_covariance_mod::soca_cov::sqrt_c_mult()
108 !!
109 !! Generate randomized C^1/2 x increment
110 subroutine soca_b_randomize_c(c_key_self, c_key_out) bind(c,name='soca_b_randomize_f90')
111  integer(c_int), intent(in) :: c_key_self !< covar config structure
112  integer(c_int), intent(in) :: c_key_out !< Randomized increment
113 
114  type(soca_cov), pointer :: self
115  type(soca_increment), pointer :: xout
116 
117  call soca_cov_registry%get(c_key_self, self)
118  call soca_increment_registry%get(c_key_out, xout)
119 
120  ! Randomize increment
121  call self%sqrt_C_mult(xout) !< xout = C^1/2.xout
122 
123 end subroutine soca_b_randomize_c
124 
125 end module soca_covariance_mod_c
C++ interfaces for soca_covariance_mod::soca_cov.
subroutine soca_b_setup_c(c_key_self, c_conf, c_key_geom, c_key_bkg, c_vars)
Linked list implementation.
subroutine soca_b_delete_c(c_key_self)
C++ interface for soca_covariance_mod::soca_cov::delete()
subroutine soca_b_mult_c(c_key_self, c_key_in, c_key_out)
C++ interface for soca_covariance_mod::soca_cov::mult()
subroutine soca_b_randomize_c(c_key_self, c_key_out)
C++ interface for soca_covariance_mod::soca_cov::sqrt_c_mult()
type(registry_t), public soca_cov_registry
Linked list interface - defines registry_t type.
Structure holding configuration variables for the 3d error covariance matrices of the SOCA analysis.
C++ interfaces for soca_geom_mod::soca_geom.
type(registry_t), public soca_geom_registry
Linked list interface - defines registry_t type.
Geometry module.
Increment fields.
registry for soca_increment_mod::soca_increment instances for use in Fortran/C++ interface of soca_in...
type(registry_t), public soca_increment_registry
Linked list interface - defines registry_t type.
State fields.
registry for soca_state_mod::soca_state instances for use in Fortran/C++ interfaces of soca_state_mod...
type(registry_t), public soca_state_registry
Linked list interface - defines registry_t type.
SOCA background/model covariance.
Geometry data structure.