ESMF_ConfigParseAttributes Subroutine

private subroutine ESMF_ConfigParseAttributes(config, unique, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
logical, intent(in), optional :: unique
integer, intent(out), optional :: rc

Calls

proc~~esmf_configparseattributes~~CallsGraph proc~esmf_configparseattributes ESMF_ConfigParseAttributes proc~esmf_configgetinit ESMF_ConfigGetInit proc~esmf_configparseattributes->proc~esmf_configgetinit proc~esmf_imerr ESMF_IMErr proc~esmf_configparseattributes->proc~esmf_imerr proc~esmf_logfounderror ESMF_LogFoundError proc~esmf_configparseattributes->proc~esmf_logfounderror proc~esmf_logseterror ESMF_LogSetError proc~esmf_configparseattributes->proc~esmf_logseterror proc~esmf_utilarray2string ESMF_UtilArray2String proc~esmf_configparseattributes->proc~esmf_utilarray2string proc~esmf_utilstring2array ESMF_UtilString2Array proc~esmf_configparseattributes->proc~esmf_utilstring2array proc~index_ index_ proc~esmf_configparseattributes->proc~index_ proc~esmf_imerr->proc~esmf_logfounderror proc~esmf_initcheckdeep ESMF_InitCheckDeep proc~esmf_imerr->proc~esmf_initcheckdeep esmf_breakpoint esmf_breakpoint proc~esmf_logfounderror->esmf_breakpoint proc~esmf_logrc2msg ESMF_LogRc2Msg proc~esmf_logfounderror->proc~esmf_logrc2msg proc~esmf_logwrite ESMF_LogWrite proc~esmf_logfounderror->proc~esmf_logwrite proc~esmf_logseterror->esmf_breakpoint proc~esmf_logseterror->proc~esmf_logrc2msg proc~esmf_logseterror->proc~esmf_logwrite c_esmc_loggeterrormsg c_esmc_loggeterrormsg proc~esmf_logrc2msg->c_esmc_loggeterrormsg proc~esmf_logwrite->proc~esmf_utilstring2array c_esmc_vmwtime c_esmc_vmwtime proc~esmf_logwrite->c_esmc_vmwtime proc~esmf_logclose ESMF_LogClose proc~esmf_logwrite->proc~esmf_logclose proc~esmf_logflush ESMF_LogFlush proc~esmf_logwrite->proc~esmf_logflush proc~esmf_logopenfile ESMF_LogOpenFile proc~esmf_logwrite->proc~esmf_logopenfile proc~esmf_utiliounitflush ESMF_UtilIOUnitFlush proc~esmf_logwrite->proc~esmf_utiliounitflush proc~esmf_logclose->proc~esmf_logflush proc~esmf_logflush->proc~esmf_utilarray2string proc~esmf_logflush->proc~esmf_utiliounitflush proc~esmf_logopenfile->proc~esmf_utiliounitflush proc~esmf_utiliounitget ESMF_UtilIOUnitGet proc~esmf_logopenfile->proc~esmf_utiliounitget

Called by

proc~~esmf_configparseattributes~~CalledByGraph proc~esmf_configparseattributes ESMF_ConfigParseAttributes proc~esmf_configcreatefromsection ESMF_ConfigCreateFromSection proc~esmf_configcreatefromsection->proc~esmf_configparseattributes proc~esmf_configloadfile ESMF_ConfigLoadFile proc~esmf_configloadfile->proc~esmf_configparseattributes interface~esmf_configcreate ESMF_ConfigCreate interface~esmf_configcreate->proc~esmf_configcreatefromsection proc~complianceinitialize ComplianceInitialize proc~complianceinitialize->proc~esmf_configloadfile proc~esmf_compconstruct ESMF_CompConstruct proc~esmf_compconstruct->proc~esmf_configloadfile proc~esmf_compset ESMF_CompSet proc~esmf_compset->proc~esmf_configloadfile proc~esmf_frameworkinternalinit ESMF_FrameworkInternalInit proc~esmf_frameworkinternalinit->proc~esmf_configloadfile proc~f_esmf_configloadfile f_esmf_configloadfile proc~f_esmf_configloadfile->proc~esmf_configloadfile proc~initialization Initialization proc~initialization->proc~esmf_configloadfile proc~read_descriptor_files read_descriptor_files proc~read_descriptor_files->proc~esmf_configloadfile proc~read_dist_specification read_dist_specification proc~read_dist_specification->proc~esmf_configloadfile proc~read_grid_specification read_grid_specification proc~read_grid_specification->proc~esmf_configloadfile proc~read_redistribution_grid read_redistribution_grid proc~read_redistribution_grid->proc~esmf_configloadfile proc~read_regridding_grid read_regridding_grid proc~read_regridding_grid->proc~esmf_configloadfile proc~read_testharness_config Read_TestHarness_Config proc~read_testharness_config->proc~esmf_configloadfile program~esmf_appdriver ESMF_AppDriver program~esmf_appdriver->proc~esmf_configloadfile program~esmf_configoverviewex ESMF_ConfigOverviewEx program~esmf_configoverviewex->proc~esmf_configloadfile program~esmf_hconfigex ESMF_HConfigEx program~esmf_hconfigex->proc~esmf_configloadfile program~esmf_hconfigutest ESMF_HConfigUTest program~esmf_hconfigutest->proc~esmf_configloadfile

Source Code

    subroutine ESMF_ConfigParseAttributes( config, unique, rc )


      implicit none

      type(ESMF_Config), intent(inout) :: config    ! ESMF Configuration
      logical, intent(in), optional :: unique    ! if unique is present & true, 
                                                 !  uniqueness of labels
                                                 !  is checked and error
                                                 !  code is set
      integer, intent(out), optional :: rc       ! Error return code
!
! !DESCRIPTION: Parse all attribute labels in given config object and place
!               into attributes table to track user retrieval
!
!EOPI -------------------------------------------------------------------
      integer :: i, j, k, a, b, localrc
      character(len=LSZ) :: this_label, label
      character(len=ESMF_MAXSTR) :: logmsg
      logical :: duplicate

      ! Initialize return code; assume routine not implemented
      if ( present (rc) ) then
        rc = ESMF_RC_NOT_IMPL
      endif
      localrc = ESMF_RC_NOT_IMPL

      !check variables
      ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)

      ! initialize this config's attributes table "used" flags to "not used"
      do a = 1, NATT_MAX
        config%cptr%attr_used(a)%used = .false.
      enddo

      i = 1  ! start of buffer
      a = 1  ! first slot in attributes table
      do while ( i .lt. config%cptr%nbuf )

        ! get next line from buffer
        j = index_(config%cptr%buffer(i:config%cptr%nbuf), EOL)
        if (j .eq. 0) then
          j = config%cptr%nbuf - 1
        else
          j = i + j - 1
        endif
        this_label = config%cptr%buffer(i:j)

        ! look for label in this_label; non-blank characters followed by a colon
        if (this_label(1:2) .ne. '::' ) then  ! skip end-of-table mark
          k = index_(this_label, ':') - 1     ! label sans colon
          if (k .ge. 1) then  ! non-blank match
            ! found a label, trim it, 
            label = trim(adjustl(this_label(1:k)))

            ! ... check it for uniqueness if requested,
            duplicate = .false.
            if ( present( unique ) ) then
              if (unique) then
                !  TODO:  pre-sort and use binary search, or use hash function
                do b = 1, a-1
                  if (label == ESMF_UtilArray2String (config%cptr%attr_used(b)%label)) then
                    duplicate = .true.
                    logmsg = "Duplicate label '" // trim(label) // &
                                  "' found in attributes file"
                    call ESMF_LogSetError(rcToCheck=ESMF_RC_DUP_NAME, msg=logmsg, &
                                             ESMF_CONTEXT, rcToReturn=rc)
                    localrc = ESMF_RC_DUP_NAME
                  endif
                enddo
              endif
            endif

            ! ... and place it into attributes table
            if (.not.duplicate) then
               if ( a <= NATT_MAX ) then
                  allocate (config%cptr%attr_used(a)%label(len_trim (label)))
                  config%cptr%attr_used(a)%label = ESMF_UtilString2Array (trim (label))
               else
                  if (ESMF_LogFoundError(ESMF_RC_INTNRL_LIST,    &
                       msg="attribute out-of-range; increase NATT_MAX", &
                       ESMF_CONTEXT, rcToReturn=rc)) return
               endif
               a = a + 1
            endif
          endif
        endif

        ! set index to beginning of next line
        i = j + 1

      enddo

      ! remember number of labels found
      config%cptr%nattr = a-1

      if (present(rc)) then
        if (localrc == ESMF_RC_DUP_NAME) then
          rc = localrc
        else
          rc = ESMF_SUCCESS
        end if
      end if
      return

    end subroutine ESMF_ConfigParseAttributes