Skip to content

Commit f33b7a0

Browse files
authored
Add core construtor from json/yaml string (#142)
* add core construtor from json/yaml string * revert changes to config_t
1 parent 6de782d commit f33b7a0

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

src/core.F90

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,57 @@ module tuvx_core
8686
end type core_t
8787

8888
interface core_t
89-
module procedure constructor
89+
module procedure constructor_file_path, constructor_config
9090
end interface core_t
9191

9292
contains
9393

9494
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9595

96-
function constructor( config, grids, profiles, radiators ) result( new_core )
97-
! Constructor of TUV-x core objects
96+
function constructor_file_path( config_file_path, grids, profiles, &
97+
radiators ) result( new_core )
98+
! Constructor of TUV-x core objects from a configuration file
99+
100+
use musica_string, only : string_t
101+
102+
type(string_t), intent(in) :: config_file_path ! Path to TUV-x configuration file
103+
class(grid_warehouse_t), optional, intent(in) :: grids ! Set of grids to include in the configuration
104+
class(profile_warehouse_t), optional, intent(in) :: profiles ! Set of profiles to include in the configuration
105+
class(radiator_warehouse_t), optional, intent(in) :: radiators ! Set of radiators to include in the configuration
106+
class(core_t), pointer :: new_core
107+
108+
type(config_t) :: config
109+
110+
call config%from_file( config_file_path%to_char() )
111+
new_core => constructor_config( config, grids, profiles, radiators )
112+
113+
end function constructor_file_path
114+
115+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
116+
117+
function constructor_config( config, grids, profiles, radiators ) &
118+
result( new_core )
119+
! Constructor of TUV-x core objects from a configuration object
98120

99121
use musica_assert, only : assert_msg
100122
use musica_string, only : string_t
101123
use tuvx_diagnostic_util, only : diagout
102124
use tuvx_profile, only : profile_t
103125
use tuvx_radiator_warehouse, only : radiator_warehouse_t
104126

105-
type(string_t), intent(in) :: config ! Full TUV-x configuration data
106-
class(grid_warehouse_t), optional, intent(in) :: grids ! Set of grids to include in the configuration
107-
class(profile_warehouse_t), optional, intent(in) :: profiles ! Set of profiles to include in the configuration
108-
class(radiator_warehouse_t), optional, intent(in) :: radiators ! Set of radiators to include in the configuration
109-
class(core_t), pointer :: new_core
127+
type(config_t), intent(inout) :: config ! Full TUV-x configuration data
128+
class(grid_warehouse_t), optional, intent(in) :: grids ! Set of grids to include in the configuration
129+
class(profile_warehouse_t), optional, intent(in) :: profiles ! Set of profiles to include in the configuration
130+
class(radiator_warehouse_t), optional, intent(in) :: radiators ! Set of radiators to include in the configuration
131+
class(core_t), pointer :: new_core
110132

111133
! Local variables
112134
character(len=*), parameter :: Iam = 'Photolysis core constructor: '
113135
logical :: found
114-
type(config_t) :: core_config, child_config
136+
type(config_t) :: child_config
115137
class(profile_t), pointer :: aprofile
116138
type(string_t) :: required_keys(4), optional_keys(3)
117139

118-
call core_config%from_file( config%to_char() )
119-
120140
! Check json configuration file for basic structure, integrity
121141
required_keys(1) = "radiative transfer"
122142
required_keys(2) = "grids"
@@ -126,22 +146,22 @@ function constructor( config, grids, profiles, radiators ) result( new_core )
126146
optional_keys(2) = "dose rates"
127147
optional_keys(3) = "enable diagnostics"
128148
call assert_msg( 255400232, &
129-
core_config%validate( required_keys, optional_keys ), &
149+
config%validate( required_keys, optional_keys ), &
130150
"Bad configuration data format for tuv-x core." )
131151

132152
! Instantiate photolysis core
133153
allocate( new_core )
134154

135-
call core_config%get( 'enable diagnostics', new_core%enable_diagnostics_, &
155+
call config%get( 'enable diagnostics', new_core%enable_diagnostics_, &
136156
Iam, default=.false. )
137157

138158
! Instantiate and initialize grid warehouse
139-
call core_config%get( "grids", child_config, Iam )
159+
call config%get( "grids", child_config, Iam )
140160
new_core%grid_warehouse_ => grid_warehouse_t( child_config )
141161
if( present( grids ) ) call new_core%grid_warehouse_%add( grids )
142162

143163
! Instantiate and initialize profile warehouse
144-
call core_config%get( "profiles", child_config, Iam )
164+
call config%get( "profiles", child_config, Iam )
145165
new_core%profile_warehouse_ => &
146166
profile_warehouse_t( child_config, new_core%grid_warehouse_ )
147167
if( present( profiles ) ) call new_core%profile_warehouse_%add( profiles )
@@ -166,16 +186,15 @@ function constructor( config, grids, profiles, radiators ) result( new_core )
166186
end if
167187

168188
! Set up radiative transfer calculator
169-
call core_config%get( "radiative transfer", child_config, Iam )
189+
call config%get( "radiative transfer", child_config, Iam )
170190
new_core%radiative_transfer_ => &
171191
radiative_transfer_t( child_config, &
172192
new_core%grid_warehouse_, &
173193
new_core%profile_warehouse_, &
174194
radiators )
175195

176196
! photolysis rate constants
177-
call core_config%get( "photolysis", child_config, Iam, &
178-
found = found )
197+
call config%get( "photolysis", child_config, Iam, found = found )
179198
if( found ) then
180199
new_core%photolysis_rates_ => &
181200
photolysis_rates_t( child_config, &
@@ -187,7 +206,7 @@ function constructor( config, grids, profiles, radiators ) result( new_core )
187206
end if
188207

189208
! dose rates
190-
call core_config%get( "dose rates", child_config, Iam, found = found )
209+
call config%get( "dose rates", child_config, Iam, found = found )
191210
if( found ) then
192211
new_core%dose_rates_ => &
193212
dose_rates_t( child_config, new_core%grid_warehouse_, &
@@ -199,13 +218,13 @@ function constructor( config, grids, profiles, radiators ) result( new_core )
199218
spherical_geometry_t( new_core%grid_warehouse_ )
200219

201220
! instantiate and initialize lyman alpha, srb type
202-
call core_config%get( "O2 absorption", child_config, Iam )
221+
call config%get( "O2 absorption", child_config, Iam )
203222
new_core%la_sr_bands_ => la_sr_bands_t( child_config, &
204223
new_core%grid_warehouse_, &
205224
new_core%profile_warehouse_ )
206225

207226

208-
end function constructor
227+
end function constructor_config
209228

210229
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
211230

0 commit comments

Comments
 (0)