SOCA
soca_model.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_model_mod::soca_model
8 
9 use datetime_mod, only: datetime, c_f_datetime
10 use duration_mod, only: duration, duration_seconds, assignment(=)
11 use fckit_configuration_module, only: fckit_configuration
12 use iso_c_binding
13 
14 ! soca modules
16 use soca_geom_mod, only: soca_geom
17 use soca_model_mod, only: soca_model
18 use soca_state_mod, only: soca_state
20 
21 implicit none
22 private
23 
24 #define LISTED_TYPE soca_model
25 
26 !> Linked list interface - defines registry_t type
27 #include "oops/util/linkedList_i.f"
28 
29 !> Global registry for soca_model instances
30 type(registry_t), public :: soca_model_registry
31 
32 ! ------------------------------------------------------------------------------
33 contains
34 ! ------------------------------------------------------------------------------
35 
36 !> Linked list implementation
37 #include "oops/util/linkedList_c.f"
38 
39 ! ------------------------------------------------------------------------------
40 !> C++ interface for soca_model_mod::soca_model::setup()
41 subroutine soca_model_setup_c(c_conf, c_key_geom, c_key_model) bind (c,name='soca_model_setup_f90')
42  type(c_ptr), intent(in) :: c_conf !< pointer to object of class Config
43  integer(c_int), intent(in) :: c_key_geom !< Geometry
44  integer(c_int), intent(inout) :: c_key_model !< Key to configuration data
45 
46  type(soca_model), pointer :: model
47  type(soca_geom), pointer :: geom
48 
49  type(duration) :: dtstep
50  real(c_double), allocatable :: tocn_minmax(:), socn_minmax(:)
51  type(fckit_configuration) :: f_conf
52  character(len=:), allocatable :: str
53 
54  f_conf = fckit_configuration(c_conf)
55 
56  call soca_geom_registry%get(c_key_geom, geom)
57  call soca_model_registry%init()
58  call soca_model_registry%add(c_key_model)
59  call soca_model_registry%get(c_key_model, model)
60 
61  ! Setup time step
62  call f_conf%get_or_die("tstep", str)
63  dtstep = trim(str)
64  model%dt0 = duration_seconds(dtstep)
65 
66  ! Setup mom6 advance or identity model
67  call f_conf%get_or_die("advance_mom6", model%advance_mom6)
68 
69  ! Setup defaults for clamping values in the model
70  if ( f_conf%has("tocn_minmax") ) then
71  call f_conf%get_or_die("tocn_minmax", tocn_minmax)
72  model%tocn_minmax = tocn_minmax
73  else
74  model%tocn_minmax=(/-999., -999./)
75  endif
76  if ( f_conf%has("socn_minmax") ) then
77  call f_conf%get_or_die("socn_minmax", socn_minmax)
78  model%socn_minmax = socn_minmax
79  else
80  model%socn_minmax=(/-999., -999./)
81  endif
82 
83  ! Initialize mom6
84  call model%setup(geom)
85 
86  if (allocated(str)) deallocate(str)
87 end subroutine soca_model_setup_c
88 
89 
90 ! ------------------------------------------------------------------------------
91 !> C++ interface for soca_model_mod::soca_model::delete()
92 subroutine soca_model_delete_c(c_key_conf) bind (c,name='soca_model_delete_f90')
93  integer(c_int), intent(inout) :: c_key_conf !< Key to configuration structure
94 
95  type(soca_model), pointer :: model
96 
97  call soca_model_registry%get(c_key_conf, model)
98  call model%delete()
99  call soca_model_registry%remove(c_key_conf)
100 end subroutine soca_model_delete_c
101 
102 
103 ! ------------------------------------------------------------------------------
104 !> C++ interface for soca_model_mod::soca_model::init()
105 subroutine soca_model_init_c(c_key_model, c_key_state) &
106  & bind(c,name='soca_model_init_f90')
107  integer(c_int), intent(in) :: c_key_model !< Configuration structure
108  integer(c_int), intent(in) :: c_key_state !< Model fields
109 
110  type(soca_model), pointer :: model
111  type(soca_state),pointer :: flds
112 
113  call soca_state_registry%get(c_key_state, flds)
114  call soca_model_registry%get(c_key_model, model)
115 
116  call model%init(flds)
117 
118 end subroutine soca_model_init_c
119 
120 
121 ! ------------------------------------------------------------------------------
122 !> C++ interface for soca_model_mod::soca_model::finalize()
123 subroutine soca_model_finalize_c(c_key_model, c_key_state) &
124  bind(c,name='soca_model_finalize_f90')
125  integer(c_int), intent(in) :: c_key_model !< Configuration structure
126  integer(c_int), intent(in) :: c_key_state !< Model fields
127 
128  type(soca_model), pointer :: model
129  type(soca_state),pointer :: flds
130 
131  call soca_state_registry%get(c_key_state, flds)
132  call soca_model_registry%get(c_key_model, model)
133 
134  call model%finalize(flds)
135 end subroutine soca_model_finalize_c
136 
137 
138 ! ------------------------------------------------------------------------------
139 !> C++ interface for soca_model_mod::soca_model::propagate()
140 subroutine soca_model_propagate_c(c_key_model, c_key_state, c_key_date) bind(c,name='soca_model_propagate_f90')
141  integer(c_int), intent(in) :: c_key_model !< Config structure
142  integer(c_int), intent(in) :: c_key_state !< Model fields
143  type(c_ptr), intent(inout) :: c_key_date !< DateTime
144 
145  type(soca_model), pointer :: model
146  type(soca_state),pointer :: flds
147  type(datetime) :: fldsdate
148 
149  call soca_model_registry%get(c_key_model, model)
150  call soca_state_registry%get(c_key_state, flds)
151  call c_f_datetime(c_key_date, fldsdate)
152 
153  call model%propagate(flds, fldsdate)
154 end subroutine soca_model_propagate_c
155 
156 end module soca_model_mod_c
C++ interfaces for soca_geom_mod::soca_geom.
type(registry_t), public soca_geom_registry
Linked list interface - defines registry_t type.
Geometry module.
C++ interfaces for soca_model_mod::soca_model.
subroutine soca_model_setup_c(c_conf, c_key_geom, c_key_model)
Linked list implementation.
subroutine soca_model_finalize_c(c_key_model, c_key_state)
C++ interface for soca_model_mod::soca_model::finalize()
subroutine soca_model_delete_c(c_key_conf)
C++ interface for soca_model_mod::soca_model::delete()
subroutine soca_model_propagate_c(c_key_model, c_key_state, c_key_date)
C++ interface for soca_model_mod::soca_model::propagate()
subroutine soca_model_init_c(c_key_model, c_key_state)
C++ interface for soca_model_mod::soca_model::init()
type(registry_t), public soca_model_registry
Linked list interface - defines registry_t type.
Structure holding configuration variables for the model.
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.
Geometry data structure.
Fortran derived type to hold configuration data for the model.