UFO
MetOfficeBMatrixStatic.interface.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! (C) Crown Copyright 2021 Met Office
3 !
4 ! This software is licensed under the terms of the Apache Licence Version 2.0
5 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 !-------------------------------------------------------------------------------
7 
9 
10 use fckit_configuration_module, only: fckit_configuration
11 use iso_c_binding
12 use kinds
13 use oops_variables_mod
15 use ufo_vars_mod
16 
17 implicit none
18 
19 private
20 
21 #define LISTED_TYPE ufo_metoffice_bmatrixstatic
22 
23 !> Linked list interface - defines registry_t type
24 #include "oops/util/linkedList_i.f"
25 
26 !> Global registry
28 
29 contains
30 
31 !> Linked list implementation
32 #include "oops/util/linkedList_c.f"
33 
34 !-------------------------------------------------------------------------------
35 subroutine ufo_metoffice_bmatrixstatic_setup_c(c_self, c_conf, &
36  nbands, nelements) &
37  bind(c, name='ufo_metoffice_bmatrixstatic_setup_f90')
38 
39 implicit none
40 integer(c_int), intent(inout) :: c_self
41 type(c_ptr), value, intent(in) :: c_conf
42 integer(c_size_t), intent(inout) :: nbands ! number of latitude bands in B-matrix file
43 integer(c_size_t), intent(inout) :: nelements ! number of elements per B-matrix dimension
44 
45 type(ufo_metoffice_bmatrixstatic), pointer :: self
46 type(fckit_configuration) :: f_conf
47 character(len=:), allocatable :: str
48 character(len=:), allocatable :: str_array(:)
49 logical :: qtotal_flag
50 character(len=200) :: filepath
51 integer :: varsize
52 character(len=200), allocatable :: background_fields(:)
53 
54 ! Interface and setup
55 call ufo_metoffice_bmatrixstatic_registry % setup(c_self, self)
56 
57 ! Get filepath from configuration
58 f_conf = fckit_configuration(c_conf)
59 call f_conf % get_or_die("BMatrix", str)
60 filepath = str
61 
62 ! Get variables from configuration
63 varsize = f_conf % get_size("background fields")
64 allocate(background_fields(varsize))
65 call f_conf % get_or_die("background fields", str_array)
66 background_fields(1:varsize) = str_array
67 
68 ! Get qtotal from configuration
69 call f_conf % get_or_die("qtotal", qtotal_flag)
70 
71 ! Call Fortran
72 call self % setup(background_fields, trim(filepath), qtotal_flag)
73 
74 ! B-matrix has dimensions (nelements, nelements, nbands)
75 nbands = self % nbands
76 nelements = size(self % store, 1)
77 
79 
80 !-------------------------------------------------------------------------------
82  bind(c, name='ufo_metoffice_bmatrixstatic_delete_f90')
83 
84 implicit none
85 integer(c_int), intent(inout) :: c_self
86 
87 ! Interface and setup
88 type(ufo_metoffice_bmatrixstatic), pointer :: self
89 call ufo_metoffice_bmatrixstatic_registry % get(c_self, self)
90 
91 ! Delete
92 call self % delete()
93 call ufo_metoffice_bmatrixstatic_registry % delete(c_self, self)
94 
96 
97 !-------------------------------------------------------------------------------
98 ! Extract elements of B-matrix given its dimensions
99 subroutine ufo_metoffice_bmatrixstatic_getelements_c(c_self, nelements, nbands, south, north, &
100  bmatrix_store) bind(C, name='ufo_metoffice_bmatrixstatic_getelements_f90')
101 
102 implicit none
103 integer(c_int), intent(inout) :: c_self
104 integer(c_size_t), intent(in) :: nelements
105 integer(c_size_t), intent(in) :: nbands
106 real(c_float), intent(inout) :: south(nbands)
107 real(c_float), intent(inout) :: north(nbands)
108 real(c_float), intent(inout) :: bmatrix_store(nelements,nelements,nbands)
109 
110 type(ufo_metoffice_bmatrixstatic), pointer :: self
111 call ufo_metoffice_bmatrixstatic_registry % get(c_self, self)
112 
113 south = self % south(1:nbands)
114 north = self % north(1:nbands)
115 bmatrix_store = real(self % store, kind=kind_single)
116 
118 
119 !-------------------------------------------------------------------------------
120 
subroutine ufo_metoffice_bmatrixstatic_setup_c(c_self, c_conf, nbands, nelements)
Linked list implementation.
type(registry_t) ufo_metoffice_bmatrixstatic_registry
Linked list interface - defines registry_t type.
subroutine ufo_metoffice_bmatrixstatic_getelements_c(c_self, nelements, nbands, south, north, bmatrix_store)
Fortran module containing the full b-matrix data type and methods for the 1D-Var.