merge_config Subroutine

public recursive subroutine merge_config(merged_hconfig, input_hconfig, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_HConfig), intent(inout) :: merged_hconfig
type(ESMF_HConfig), intent(in) :: input_hconfig
integer, intent(out), optional :: rc

Calls

proc~~merge_config~~CallsGraph proc~merge_config merge_config proc~merge_config->proc~merge_config ESMF_HConfigAdd ESMF_HConfigAdd proc~merge_config->ESMF_HConfigAdd ESMF_HConfigAsStringMapKey ESMF_HConfigAsStringMapKey proc~merge_config->ESMF_HConfigAsStringMapKey ESMF_HConfigCreate ESMF_HConfigCreate proc~merge_config->ESMF_HConfigCreate ESMF_HConfigCreateAtMapVal ESMF_HConfigCreateAtMapVal proc~merge_config->ESMF_HConfigCreateAtMapVal ESMF_HConfigDestroy ESMF_HConfigDestroy proc~merge_config->ESMF_HConfigDestroy ESMF_HConfigIterLoop ESMF_HConfigIterLoop proc~merge_config->ESMF_HConfigIterLoop ESMF_HConfigSet ESMF_HConfigSet proc~merge_config->ESMF_HConfigSet esmf_hconfigasstringseq esmf_hconfigasstringseq proc~merge_config->esmf_hconfigasstringseq esmf_hconfigcreateat esmf_hconfigcreateat proc~merge_config->esmf_hconfigcreateat esmf_hconfigisdefined esmf_hconfigisdefined proc~merge_config->esmf_hconfigisdefined esmf_hconfigissequence esmf_hconfigissequence proc~merge_config->esmf_hconfigissequence esmf_hconfigiterbegin esmf_hconfigiterbegin proc~merge_config->esmf_hconfigiterbegin esmf_hconfigiterend esmf_hconfigiterend proc~merge_config->esmf_hconfigiterend interface~mapl_assert MAPL_Assert proc~merge_config->interface~mapl_assert proc~mapl_return MAPL_Return proc~merge_config->proc~mapl_return proc~mapl_verify MAPL_Verify proc~merge_config->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Called by

proc~~merge_config~~CalledByGraph proc~merge_config merge_config proc~merge_config->proc~merge_config proc~setservices~13 setServices proc~setservices~13->proc~merge_config proc~test_merge_hconfig test_merge_hconfig proc~test_merge_hconfig->proc~merge_config proc~setservices~14 setServices proc~setservices~14->proc~setservices~13

Source Code

   recursive subroutine merge_config(merged_hconfig, input_hconfig, rc)
      type(ESMF_HConfig), intent(inout) :: merged_hconfig
      type(ESMF_HConfig), intent(in) :: input_hconfig
      integer, intent(out), optional :: rc

      integer :: status

      character(len=:), allocatable :: sub_configs(:)
      type(ESMF_HConfig) :: sub_config
      integer :: i
      logical :: is_sequence
    
      if (ESMF_HConfigIsDefined(input_hconfig, keyString=SUBCONFIG_KEY)) then
         is_sequence = ESMF_HConfigIsSequence(input_hconfig, keyString=SUBCONFIG_KEY, _RC)
         _ASSERT(is_sequence, "subconfig list in extdata not a sequence")
         sub_configs = ESMF_HConfigAsStringSeq(input_hconfig, ESMF_MAXPATHLEN, keyString=SUBCONFIG_KEY, _RC) 
         do i=1,size(sub_configs)
            sub_config = ESMF_HConfigCreate(filename=trim(sub_configs(i)), _RC)
            call merge_config(merged_hconfig, sub_config, _RC)
            call ESMF_HConfigDestroy(sub_config, _RC)
         enddo
      end if
      call merge_map(merged_hconfig, input_hconfig, COLLECTIONS_KEY, _RC)
      call merge_map(merged_hconfig, input_hconfig, SAMPLINGS_KEY, _RC)
      call merge_map(merged_hconfig, input_hconfig, EXPORTS_KEY, _RC)
      call merge_map(merged_hconfig, input_hconfig, DERIVED_KEY, _RC)

      _RETURN(_SUCCESS)

      contains

      subroutine merge_map(hconfig_to, hconfig_from, key, rc)
         type(ESMF_HConfig), intent(inout) :: hconfig_to
         type(ESMF_HConfig), intent(in) :: hconfig_from
         character(len=*), intent(in) :: key
         integer, optional, intent(out) :: rc

         integer :: status
         type(ESMF_HConfig) :: hconfig_temp, hconfig_exist, hconfig_accum, iter_val
         type(ESMF_HConfigIter) :: iter, iter_begin,iter_end
         character(len=:), allocatable :: iter_key

         if (ESMF_HConfigIsDefined(hconfig_from, keyString=key)) then
            hconfig_temp = ESMF_HConfigCreateAt(hconfig_from, keyString=key, _RC)
         else
            _RETURN(_SUCCESS)
         end if

         if (ESMF_HConfigIsDefined(hconfig_to, keyString=key)) then
            hconfig_accum = ESMF_HConfigCreate(_RC)

            iter_begin = ESMF_HConfigIterBegin(hconfig_temp)
            iter_end = ESMF_HConfigIterEnd(hconfig_temp)
            iter = iter_begin
            do while (ESMF_HConfigIterLoop(iter, iter_begin, iter_end, rc=status))
               _VERIFY(status)
               iter_key = ESMF_HConfigAsStringMapKey(iter, _RC)
               iter_val = ESMF_HConfigCreateAtMapVal(iter, _RC)
               call ESMF_HConfigAdd(hconfig_accum, iter_val, addKeyString=iter_key, _RC)
            enddo

            hconfig_exist = ESMF_HConfigCreateAt(hconfig_to, keyString=key, _RC)
            iter_begin = ESMF_HConfigIterBegin(hconfig_exist)
            iter_end = ESMF_HConfigIterEnd(hconfig_exist)
            iter = iter_begin
            do while (ESMF_HConfigIterLoop(iter, iter_begin, iter_end, rc=status))
               _VERIFY(status)
               iter_key = ESMF_HConfigAsStringMapKey(iter, _RC)
               iter_val = ESMF_HConfigCreateAtMapVal(iter, _RC)
               call ESMF_HConfigAdd(hconfig_accum, iter_val, addKeyString=iter_key, _RC)
            enddo
            call ESMF_HConfigSet(hconfig_to, hconfig_accum, keyString=key, _RC)

         else
            call ESMF_HConfigAdd(hconfig_to, hconfig_temp, addKeyString=key, _RC)
         end if
         _RETURN(_SUCCESS)

      end subroutine
   end subroutine merge_config