Skip to content

Commit a227a61

Browse files
committed
Enforce comment in perturbation, check that number of fields is correct. #30
1 parent 083f3bd commit a227a61

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

libforcing/src/forcing_config.F90

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ subroutine forcing_config_parse_field(self, field_jv_ptr, field_ptr, &
133133

134134
character(kind=CK, len=:), allocatable :: cname, fieldname, domain_str
135135
character(kind=CK, len=:), allocatable :: filename, perturbation_filename
136+
character(kind=CK, len=:), allocatable :: comment
136137
character(kind=CK, len=:), allocatable :: perturbation_type
137138
character(kind=CK, len=:), allocatable :: dimension_type
138139
character(kind=CK, len=:), allocatable :: perturbation_calendar
139140

140141
integer :: perturbation_constant_value
141142
logical :: found, domain_found
142-
integer :: num_perturbations
143+
integer :: num_perturbations, num_fields
143144
integer :: i, j
144145

145146
type(json_value), pointer :: perturbation_jv_ptr
@@ -302,16 +303,22 @@ subroutine forcing_config_parse_field(self, field_jv_ptr, field_ptr, &
302303
endif
303304
endif
304305

306+
num_fields = self%core%count(perturbation_jv_ptr)
305307
call self%core%get(perturbation_jv_ptr, "calendar", &
306308
perturbation_calendar, found)
309+
! Calendar is optional for dimension 'constant'
307310
if (.not. found) then
308311
call assert(field_ptr%perturbations(i)%dimension_type == &
309312
FORCING_PERTURBATION_DIMENSION_CONSTANT, &
310313
"forcing_parse_field: missing calendar type")
314+
call assert(num_fields == 4, 'forcing_parse_field: wrong number of fields'// &
315+
' in perturbation definition, should be 4.')
311316
else
312317
call assert(trim(perturbation_calendar) == 'forcing' .or. &
313318
trim(perturbation_calendar) == 'experiment', &
314319
"forcing_parse_field: invalid perturbation calendar type")
320+
call assert(num_fields == 5, 'forcing_parse_field: wrong number of fields'// &
321+
' in perturbation definition, should be 5.')
315322
if (trim(perturbation_calendar) == 'forcing') then
316323
field_ptr%perturbations(i)%calendar = &
317324
FORCING_PERTURBATION_CALENDAR_FORCING
@@ -321,6 +328,10 @@ subroutine forcing_config_parse_field(self, field_jv_ptr, field_ptr, &
321328
endif
322329
endif
323330

331+
call self%core%get(perturbation_jv_ptr, "comment", &
332+
comment, found)
333+
call assert(found, 'forcing_parse_field: perturbation missing "comment" field')
334+
324335
call field_ptr%perturbations(i)%init()
325336
if (field_ptr%separated_perturbations(i)%valid) then
326337
call field_ptr%separated_perturbations(i)%init()

libforcing/test/test_forcing_perturbations.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"type": "{{type}}",
3535
"dimension": "{{dimension}}",
3636
"value": "{{value}}",
37-
"calendar": "{{calendar}}"
37+
"calendar": "{{calendar}}",
38+
"comment": "",
3839
}""")
3940

4041

@@ -43,7 +44,8 @@
4344
"type": "{{type}}",
4445
"dimension": ["{{dimension1}}", "{{dimension2}}"],
4546
"value": ["{{value1}}", "{{value2}}"],
46-
"calendar": "{{calendar}}"
47+
"calendar": "{{calendar}}",
48+
"comment": ""
4749
}""")
4850

4951

0 commit comments

Comments
 (0)