Newer
Older
! Created by Andrey Debolskiy on 18.10.2024.
module config_utils
use config_parser
use ISO_C_BINDING, only: C_NULL_CHAR
use parkinds, only: rf=>kind_rf, im=>kind_im
implicit none
integer, public, save:: is_config_initialized = 0
public init_config, get_fluid_params, get_grid_params
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
contains
subroutine init_config(fname,status, ierr)
implicit none
character(len = *), intent(in) ::fname
integer,intent(out):: status, ierr
call c_config_run(trim(fname)//C_NULL_CHAR, status)
if (status == 0) then
write(*, *) ' FAILURE! > unable to parse configuration file: ', trim(fname)
return
end if
is_config_initialized = 1
end subroutine init_config
subroutine get_fluid_params(fluid_params, status, ierr)
use phys_fluid, only: fluidParamsDataType
type(fluidParamsDataType), intent(inout):: fluid_params
integer,intent(out):: status, ierr
ierr = 0
if( is_config_initialized /= 0 ) then
! Fluid params
call c_config_is_varname("fluid.tref"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_float("fluid.tref"//C_NULL_CHAR, fluid_params%tref, status)
if (status == 0) then
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("fluid.pref"//C_NULL_CHAR, status)
if ((status /= 0)) then
!< mandatory in user dataset
call c_config_get_float("fluid.pref"//C_NULL_CHAR, fluid_params%pref, status)
if (status == 0) then
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("fluid.beta"//C_NULL_CHAR, status)
if ((status /= 0)) then
!< mandatory in user dataset
call c_config_get_float("fluid.beta"//C_NULL_CHAR, fluid_params%beta, status)
if (status == 0) then
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("fluid.g"//C_NULL_CHAR, status)
if ((status /= 0)) then
!< mandatory in user dataset
call c_config_get_float("fluid.g"//C_NULL_CHAR, fluid_params%g, status)
if (status == 0) then
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("fluid.kappa"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_float("fluid.kappa"//C_NULL_CHAR, fluid_params%kappa, status)
if (status == 0) then
ierr = 1 ! signal ERROR
return
end if
end if
end if
end subroutine get_fluid_params
subroutine get_grid_params(grid, status, ierr)
use pbl_grid, only: pblgridDataType, &
grid_inmcm21_tag, grid_inmcm73_tag, &
grid_streached_tag, grid_uniform_tag, &
set_pbl_grid_uniform
implicit none
type(pblgridDataType), intent(inout):: grid
integer,intent(out):: status, ierr
character(len=50) :: tag
character, allocatable :: config_field(:)
real(kind=rf):: h_bot, h_top
integer(kind=im):: nz
ierr = 0
if( is_config_initialized /= 0 ) then
! grid type
call c_config_is_varname("grid.type"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_string("grid.type"//C_NULL_CHAR, config_field, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: grid.type '
ierr = 1 ! signal ERROR
return
end if
end if
if (trim(tag) == trim(grid_uniform_tag)) then
call c_config_is_varname("grid.nz"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_int("grid.nz"//C_NULL_CHAR, nz, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: grid.nz '
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("grid.h_bot"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_float("grid.h_bot"//C_NULL_CHAR, h_bot, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: grid.h_bot '
ierr = 1 ! signal ERROR
return
end if
end if
call c_config_is_varname("grid.h_top"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_float("grid.h_top"//C_NULL_CHAR, h_top, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: grid.h_top '
ierr = 1 ! signal ERROR
return
end if
end if
call set_pbl_grid_uniform(grid, h_bot, h_top, nz)
end if
else
status = 0
ierr = 2
end if
end subroutine get_grid_params
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
subroutine get_closure_params(turb, status, ierr)
use pbl_turb_data, only: turbBLDataType, &
pbl_fom_tag, pbl_kl_tag, &
pbl_fom_louis_tag, pbl_fom_esau_tag, &
pbl_fom_efb_tag
use sfx_common, only: char_array2str
implicit none
type(turbBLDataType), intent(inout):: turb
integer,intent(out):: status, ierr
character(len=50) :: tag, tag_stabf
character, allocatable :: config_field(:)
ierr = 0
if( is_config_initialized /= 0 ) then
! closure type
call c_config_is_varname("closure.type"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_string("closure.type"//C_NULL_CHAR, config_field, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: grid.type '
ierr = 1 ! signal ERROR
return
end if
end if
tag = char_array2str(config_field)
if (trim(tag) == trim(pbl_fom_tag)) then
turb%cl_type = 1
call c_config_is_varname("closure.name"//C_NULL_CHAR, status)
if ((status /= 0)) then
call c_config_get_string("closure.name"//C_NULL_CHAR, config_field, status)
if (status == 0) then
write(*, *) ' FAILURE! > could not set: closure.name '
ierr = 1 ! signal ERROR
return
else
tag_stabf = char_array2str(config_field)
if (trim(tag_stabf) == trim(pbl_fom_louis_tag)) then
turb%sf_type = 1
elseif (trim(tag_stabf) == trim(pbl_fom_esau_tag)) then
turb%sf_type = 2
elseif (trim(tag_stabf) == trim(pbl_fom_efb_tag)) then
turb%sf_type = 3
else
status = 1
ierr = 1
write(*, *) ' FAILURE! > could not find eligable: closure.name '
write(*,*) tag_stabf, pbl_fom_louis_tag
return
end if
end if
end if
else
turb%cl_type = 2 ! KL - type
endif
end if
end subroutine get_closure_params
!> @brief character array to string conversion
function char_array2str(char_array) result(str)
! ----------------------------------------------------------------------------
implicit none
character, intent(in) :: char_array(:)
character(len=:), allocatable :: str
integer :: i
! ----------------------------------------------------------------------------
str = ""
do i = 1, size(char_array)
str = str(:) // char_array(i)
end do
end function
end module config_utils