Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and refactor fm_yaml_mod for new field_table format #1547

Merged
merged 13 commits into from
Jul 26, 2024
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
71 changes: 34 additions & 37 deletions field_manager/field_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ subroutine read_field_table_yaml(nfields, table_name)
character(len=fm_string_len) :: tbl_name !< field_table yaml file
character(len=fm_string_len) :: method_control !< field_table yaml file
integer :: h, i, j, k, l, m !< dummy integer buffer
type (fmTable_t) :: my_table !< the field table
type (fmTable_t) :: my_table !< the field table
integer :: model !< model assocaited with the current field
character(len=fm_path_name_len) :: list_name !< field_manager list name
character(len=fm_string_len) :: subparamvalue !< subparam value to be used when defining new name
Expand All @@ -614,14 +614,12 @@ subroutine read_field_table_yaml(nfields, table_name)
return
endif

! Construct my_table object
call build_fmTable(my_table, trim(tbl_name))

! Define my_table object and read in number of fields
my_table = fmTable_t(trim(tbl_name))
call my_table%get_blocks
call my_table%create_children
do h=1,my_table%nchildren
do i=1,my_table%children(h)%nchildren
do j=1,my_table%children(h)%children(i)%nchildren
do h=1,size(my_table%types)
do i=1,size(my_table%types(h)%models)
do j=1,size(my_table%types(h)%models(i)%variables)
num_fields = num_fields + 1
end do
end do
Expand All @@ -630,9 +628,9 @@ subroutine read_field_table_yaml(nfields, table_name)
allocate(fields(num_fields))

current_field = 0
do h=1,my_table%nchildren
do i=1,my_table%children(h)%nchildren
select case (my_table%children(h)%children(i)%name)
do h=1,size(my_table%types)
do i=1,size(my_table%types(h)%models)
select case (my_table%types(h)%models(i)%name)
case ('coupler_mod')
model = MODEL_COUPLER
case ('atmos_mod')
Expand All @@ -645,58 +643,58 @@ subroutine read_field_table_yaml(nfields, table_name)
model = MODEL_ICE
case default
call mpp_error(FATAL, trim(error_header)//'The model name is unrecognised : &
&'//trim(my_table%children(h)%children(i)%name))
&'//trim(my_table%types(h)%models(i)%name))
end select
do j=1,my_table%children(h)%children(i)%nchildren
do j=1,size(my_table%types(h)%models(i)%variables)
current_field = current_field + 1
list_name = list_sep//lowercase(trim(my_table%children(h)%children(i)%name))//list_sep//&
lowercase(trim(my_table%children(h)%name))//list_sep//&
lowercase(trim(my_table%children(h)%children(i)%children(j)%name))
list_name = list_sep//lowercase(trim(my_table%types(h)%models(i)%name))//list_sep//&
lowercase(trim(my_table%types(h)%name))//list_sep//&
lowercase(trim(my_table%types(h)%models(i)%variables(j)%name))
index_list_name = fm_new_list(list_name, create = .true.)
if ( index_list_name == NO_FIELD ) &
call mpp_error(FATAL, trim(error_header)//'Could not set field list for '//trim(list_name))
fm_success = fm_change_list(list_name)
fields(current_field)%model = model
fields(current_field)%field_name = lowercase(trim(my_table%children(h)%children(i)%children(j)%name))
fields(current_field)%field_type = lowercase(trim(my_table%children(h)%name))
fields(current_field)%num_methods = size(my_table%children(h)%children(i)%children(j)%key_ids)
fields(current_field)%field_name = lowercase(trim(my_table%types(h)%models(i)%variables(j)%name))
fields(current_field)%field_type = lowercase(trim(my_table%types(h)%name))
fields(current_field)%num_methods = size(my_table%types(h)%models(i)%variables(j)%keys)
allocate(fields(current_field)%methods(fields(current_field)%num_methods))
if(fields(current_field)%num_methods.gt.0) then
if (my_table%children(h)%children(i)%children(j)%nchildren .gt. 0) subparams = .true.
do k=1,size(my_table%children(h)%children(i)%children(j)%keys)
subparams = (size(my_table%types(h)%models(i)%variables(j)%attributes) .gt. 0)
do k=1,size(my_table%types(h)%models(i)%variables(j)%keys)
fields(current_field)%methods(k)%method_type = &
lowercase(trim(my_table%children(h)%children(i)%children(j)%keys(k)))
lowercase(trim(my_table%types(h)%models(i)%variables(j)%keys(k)))
fields(current_field)%methods(k)%method_name = &
lowercase(trim(my_table%children(h)%children(i)%children(j)%values(k)))
lowercase(trim(my_table%types(h)%models(i)%variables(j)%values(k)))
if (.not.subparams) then
call new_name_yaml(list_name, my_table%children(h)%children(i)%children(j)%keys(k),&
my_table%children(h)%children(i)%children(j)%values(k) )
call new_name(list_name, my_table%types(h)%models(i)%variables(j)%keys(k),&
my_table%types(h)%models(i)%variables(j)%values(k) )
else
subparamindex=-1
do l=1,my_table%children(h)%children(i)%children(j)%nchildren
if(lowercase(trim(my_table%children(h)%children(i)%children(j)%children(l)%paramname)).eq.&
do l=1,size(my_table%types(h)%models(i)%variables(j)%attributes)
if(lowercase(trim(my_table%types(h)%models(i)%variables(j)%attributes(l)%paramname)).eq.&
lowercase(trim(fields(current_field)%methods(k)%method_type))) then
subparamindex = l
exit
end if
end do
if (subparamindex.eq.-1) then
call new_name_yaml(list_name, my_table%children(h)%children(i)%children(j)%keys(k),&
my_table%children(h)%children(i)%children(j)%values(k) )
call new_name(list_name, my_table%types(h)%models(i)%variables(j)%keys(k),&
my_table%types(h)%models(i)%variables(j)%values(k) )
else
do m=1,size(my_table%children(h)%children(i)%children(j)%children(subparamindex)%keys)
do m=1,size(my_table%types(h)%models(i)%variables(j)%attributes(subparamindex)%keys)
method_control = " "
subparamvalue = " "
if (trim(my_table%children(h)%children(i)%children(j)%values(k)).eq.'fm_yaml_null') then
if (trim(my_table%types(h)%models(i)%variables(j)%values(k)).eq.'fm_yaml_null') then
fm_yaml_null = ''
else
fm_yaml_null = trim(my_table%children(h)%children(i)%children(j)%values(k))//'/'
fm_yaml_null = trim(my_table%types(h)%models(i)%variables(j)%values(k))//'/'
end if
method_control = trim(my_table%children(h)%children(i)%children(j)%keys(k))//"/"//&
method_control = trim(my_table%types(h)%models(i)%variables(j)%keys(k))//"/"//&
&trim(fm_yaml_null)//&
&trim(my_table%children(h)%children(i)%children(j)%children(subparamindex)%keys(m))
subparamvalue = trim(my_table%children(h)%children(i)%children(j)%children(subparamindex)%values(m))
call new_name_yaml(list_name, method_control, subparamvalue)
&trim(my_table%types(h)%models(i)%variables(j)%attributes(subparamindex)%keys(m))
subparamvalue = trim(my_table%types(h)%models(i)%variables(j)%attributes(subparamindex)%values(m))
call new_name(list_name, method_control, subparamvalue)
end do
end if
end if
Expand All @@ -707,7 +705,6 @@ subroutine read_field_table_yaml(nfields, table_name)
end do

if (present(nfields)) nfields = num_fields
call my_table%destruct
rem1776 marked this conversation as resolved.
Show resolved Hide resolved
end subroutine read_field_table_yaml

!> @brief Subroutine to add new values to list parameters.
Expand Down
Loading
Loading