Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions parser/yaml_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ subroutine get_value_from_key_0d(file_id, block_id, key_name, key_value, is_opti
if (err_unit .ne. 0) call mpp_error(FATAL, "Key:"//trim(key_name)//" Error converting '"//trim(buffer)//"' to r8")
type is (character(len=*))
call string_copy(key_value, buffer)
type is (logical)
if (lowercase(trim(buffer)) == "false") then
key_value = .false.
elseif (lowercase(trim(buffer)) == "true") then
key_value = .true.
else
call mpp_error(FATAL, "Key:"//trim(key_name)//" Error converting '"//trim(buffer)//"' to logical")
endif
class default
call mpp_error(FATAL, "The type of your buffer in your get_value_from_key call for key "//trim(key_name)//&
&" is not supported. Only i4, i8, r4, r8 and strings are supported.")
Expand Down
10 changes: 10 additions & 0 deletions test_fms/parser/test_yaml_parser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ program test_read_and_parse_file
integer, allocatable :: key_ids(:) !< array of key ids
character(len=20) :: key_name !< the name of the key
character(len=20) :: key_value !< the value of a key
logical :: logical_buffer !< logical buffer

call fms_init

Expand Down Expand Up @@ -117,6 +118,15 @@ program test_read_and_parse_file
call get_value_from_key(yaml_file_id1, variable_ids(1), "fill_value", r8_buffer)
if (abs(r8_buffer - real(-999.9, kind=r8_kind)) .gt. 5d-5) call mpp_error(FATAL, "fill_value was not read correctly as an r8!")

!! Try get_value_from_key using a logical buffer
logical_buffer = .true.
call get_value_from_key(yaml_file_id2, entries_ids(2), "do_data_bug", logical_buffer)
if (logical_buffer) call mpp_error(FATAL, "do_data_bug was not read correctly as a logical")

logical_buffer = .false.
call get_value_from_key(yaml_file_id2, entries_ids(2), "use_data_bug", logical_buffer)
if (.not. logical_buffer) call mpp_error(FATAL, "use_data_bug was not read correctly as a logical")

!! Try the is_optional argument on an key that does not exist
string_buffer = ""
call get_value_from_key(yaml_file_id1, variable_ids(1), "NANANANA", string_buffer, is_optional=.true.)
Expand Down
2 changes: 2 additions & 0 deletions test_fms/parser/test_yaml_parser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data_table:
lat_end : 89.8
lon_start : 3.4
lon_end : 154.4
do_data_bug : false
use_data_bug : True
_EOF

cat <<_EOF > diag_table.yaml
Expand Down