Skip to content

Commit fc4f4e0

Browse files
committed
Need to find forcing files using file templates and dates. COSIMA/access-om2#242
1 parent 467e3e2 commit fc4f4e0

File tree

3 files changed

+67
-444
lines changed

3 files changed

+67
-444
lines changed

libforcing/src/forcing_config.F90

+42-36
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ module forcing_config_mod
3535
procedure, pass(self), public :: init => forcing_config_init
3636
procedure, pass(self), public :: deinit => forcing_config_deinit
3737
procedure, pass(self), public :: parse => forcing_config_parse
38-
procedure, pass(self), private :: parse_field => forcing_config_parse_field
38+
procedure, pass(self), private :: parse_input => forcing_config_parse_input
39+
procedure, pass(self), private :: parse_permutations => &
40+
forcing_config_parse_permutations
3941
endtype forcing_config
4042

4143
contains
@@ -71,11 +73,11 @@ subroutine forcing_config_init(self, config, loggerin, num_fields)
7173
endsubroutine forcing_config_init
7274

7375

74-
!> Parse forcing file into a dictionary.
75-
subroutine forcing_config_parse(self, fields, start_date, &
76+
!> Parse forcing file
77+
subroutine forcing_config_parse(self, forcing_fields, start_date, &
7678
num_land_fields, min_dt, calendar)
7779
class(forcing_config), intent(inout) :: self
78-
type(forcing_field), dimension(:), intent(inout) :: fields
80+
type(forcing_field), dimension(:), intent(inout) :: forcing_fields
7981
type(datetime), intent(in) :: start_date
8082
integer, intent(out) :: min_dt, num_land_fields
8183
character(len=9), intent(out) :: calendar
@@ -88,8 +90,8 @@ subroutine forcing_config_parse(self, fields, start_date, &
8890
type(json_value), pointer :: root, inputs
8991
logical :: found, is_land_field
9092

91-
call assert(size(fields) == self%num_inputs, &
92-
"Insufficient number of fields allocated.")
93+
call assert(size(forcing_fields) == self%num_inputs, &
94+
"Insufficient number of forcing_fields allocated.")
9395

9496
call self%json%get(root)
9597
call self%core%get_child(root, "inputs", inputs, found)
@@ -104,7 +106,7 @@ subroutine forcing_config_parse(self, fields, start_date, &
104106
do i=1, self%num_inputs
105107
call self%core%get_child(inputs, i, input_jv_ptr, found)
106108
call assert(found, "No inputs found in forcing config.")
107-
call self%parse_input(input_jv_ptr, fields(i), start_date, &
109+
call self%parse_input(input_jv_ptr, forcing_fields(i), start_date, &
108110
product_name, dt, calendar_str, is_land_field)
109111
if (dt < min_dt) then
110112
min_dt = dt
@@ -122,7 +124,7 @@ subroutine forcing_config_parse(self, fields, start_date, &
122124

123125
endsubroutine forcing_config_parse
124126

125-
127+
!> Parse a single forcing input. This corresponds to a single coupling field.
126128
subroutine forcing_config_parse_input(self, input_jv_ptr, field_ptr, &
127129
start_date, product_name, dt, forcing_calendar, &
128130
is_land_field)
@@ -136,34 +138,20 @@ subroutine forcing_config_parse_input(self, input_jv_ptr, field_ptr, &
136138
character(len=9), intent(out) :: forcing_calendar
137139
logical, intent(out) :: is_land_field
138140

139-
character(kind=CK, len=:), allocatable :: cname, fieldname, domain_str
140-
character(kind=CK, len=:), allocatable :: filename, perturbation_filename
141-
character(kind=CK, len=:), allocatable :: comment
142-
character(kind=CK, len=:), allocatable :: perturbation_type
143-
character(kind=CK, len=:), allocatable :: dimension_type
144-
character(kind=CK, len=:), allocatable :: perturbation_calendar
145-
141+
character(kind=CK, len=:), allocatable :: cname, realm_str
142+
character(kind=CK, len=:), allocatable :: filename, fieldname
146143
character(len=256), dimension(:), allocatable :: fieldname_list, filename_list
147-
148-
integer :: num_fieldnames, num_filenames
149-
integer :: perturbation_constant_value
150-
logical :: found, domain_found
151-
integer :: num_perturbations, num_fields
144+
integer :: num_input_fields
145+
logical :: found
152146
integer :: i, j
153147

154-
type(json_value), pointer :: input_field_jv_list,
155-
type(json_value), pointer :: fieldname_jv_list, filename_jv_list
156-
type(json_value), pointer :: fieldname_jv_ptr, filename_jv_ptr
157-
type(json_value), pointer :: perturbation_jv_ptr
158-
type(json_value), pointer :: dimension_jv_ptr, value_jv_ptr
159-
type(json_value), pointer :: perturbation_list, dimension_list
160-
type(json_value), pointer :: value_list
148+
type(json_value), pointer :: input_field_jv_list, input_field_jv_ptr
161149

162150
call self%core%get(input_jv_ptr, "coupling_field_name", cname, found)
163151
call assert(found, "Entry 'coupling_field_name' not found in forcing config.")
164152

165-
call self%core%get(input_jv_ptr, "realm", realm_str, realm_found)
166-
if (realm_found) then
153+
call self%core%get(input_jv_ptr, "realm", realm_str, found)
154+
if (found) then
167155
call assert(realm_str == "land" .or. realm_str == "atmosphere", &
168156
"forcing_parse_field: invalid domain value.")
169157
else
@@ -176,6 +164,7 @@ subroutine forcing_config_parse_input(self, input_jv_ptr, field_ptr, &
176164
endif
177165

178166
! Each coupling field can have multiple input fields associated with it.
167+
! The YATM code can combine these as it sees fit.
179168
call self%core%get_child(input_jv_ptr, "input_fields", &
180169
input_field_jv_list, found)
181170
num_input_fields = self%core%count(input_field_jv_list)
@@ -185,26 +174,44 @@ subroutine forcing_config_parse_input(self, input_jv_ptr, field_ptr, &
185174

186175
call self%core%get(input_field_jv_ptr, "filename", filename, found)
187176
call assert(found, "Expected to find filename entry.")
188-
filedame_list(i) = trim(filename)
177+
filename_list(i) = trim(filename)
189178

190179
call self%core%get(input_field_jv_ptr, "fieldname", fieldname, found)
191180
call assert(found, "Expected to find fieldname entry.")
192181
fieldname_list(i) = trim(fieldname)
193182

194-
self%parse_permutations()
195-
183+
! Each input field can have a number of permutations.
184+
call self%parse_permutations(input_field_jv_ptr, field_ptr, fieldname)
196185
enddo
197186

198187
call field_ptr%init(fieldname_list, filename_list, cname, realm_str, start_date, &
199188
product_name, self%logger, dt, forcing_calendar)
200189

190+
end subroutine forcing_config_parse_input
201191

202192

203-
end subroutine forcing_config_parse_field
193+
subroutine forcing_config_parse_permutations(self, field_jv_ptr, field_ptr, fieldname)
204194

195+
class(forcing_config), intent(inout) :: self
196+
type(json_value), pointer :: field_jv_ptr
197+
type(forcing_field) :: field_ptr
198+
character(len=*) :: fieldname
199+
200+
integer :: perturbation_constant_value
201+
logical :: found
202+
integer :: num_perturbations, num_fields
203+
integer :: i, j
205204

206-
subroutine forcing_config_parse_permutations(self)
205+
type(json_value), pointer :: perturbation_jv_ptr
206+
type(json_value), pointer :: dimension_jv_ptr, value_jv_ptr
207+
type(json_value), pointer :: perturbation_list, dimension_list
208+
type(json_value), pointer :: value_list
207209

210+
character(kind=CK, len=:), allocatable :: filename, perturbation_filename
211+
character(kind=CK, len=:), allocatable :: comment
212+
character(kind=CK, len=:), allocatable :: perturbation_type
213+
character(kind=CK, len=:), allocatable :: dimension_type
214+
character(kind=CK, len=:), allocatable :: perturbation_calendar
208215

209216
call self%core%get_child(field_jv_ptr, "perturbations", perturbation_list, found)
210217
if (.not. found) then
@@ -371,8 +378,7 @@ subroutine forcing_config_parse_permutations(self)
371378
endif
372379
enddo
373380

374-
375-
end subroutine forcing_config_parse_permutations(self)
381+
end subroutine forcing_config_parse_permutations
376382

377383

378384
subroutine forcing_config_deinit(self)

0 commit comments

Comments
 (0)