Skip to content

Commit

Permalink
feat: update and refactor fm_yaml_mod for new field_table format (#…
Browse files Browse the repository at this point in the history
…1547)

Co-authored-by: Eric Stofferahn <[email protected]>
Co-authored-by: Uriel Ramirez <[email protected]>
Co-authored-by: Jesse Lentz <[email protected]>
  • Loading branch information
4 people authored Jul 26, 2024
1 parent 116408f commit 94d66ee
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 488 deletions.
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
end subroutine read_field_table_yaml

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

0 comments on commit 94d66ee

Please sign in to comment.