ESMF_ConfigSetString Subroutine

private subroutine ESMF_ConfigSetString(config, value, keywordEnforcer, label, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
character(len=*), intent(in) :: value
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
character(len=*), intent(in), optional :: label
integer, intent(out), optional :: rc

Calls

proc~~esmf_configsetstring~~CallsGraph proc~esmf_configsetstring ESMF_ConfigSetString proc~esmf_configgetinit ESMF_ConfigGetInit proc~esmf_configsetstring->proc~esmf_configgetinit proc~esmf_configgetstring ESMF_ConfigGetString proc~esmf_configsetstring->proc~esmf_configgetstring proc~esmf_imerr ESMF_IMErr proc~esmf_configsetstring->proc~esmf_imerr proc~esmf_logfounderror ESMF_LogFoundError proc~esmf_configsetstring->proc~esmf_logfounderror proc~esmf_configgetstring->proc~esmf_configgetinit proc~esmf_configgetstring->proc~esmf_imerr proc~esmf_configgetstring->proc~esmf_logfounderror proc~esmf_configfindlabel ESMF_ConfigFindLabel proc~esmf_configgetstring->proc~esmf_configfindlabel proc~index_ index_ proc~esmf_configgetstring->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_configfindlabel->proc~esmf_configgetinit proc~esmf_configfindlabel->proc~esmf_imerr proc~esmf_configfindlabel->proc~esmf_logfounderror proc~esmf_configfindlabel->proc~index_ c_esmc_loggeterrormsg c_esmc_loggeterrormsg proc~esmf_logrc2msg->c_esmc_loggeterrormsg 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_utilstring2array ESMF_UtilString2Array proc~esmf_logwrite->proc~esmf_utilstring2array proc~esmf_logclose->proc~esmf_logflush proc~esmf_logflush->proc~esmf_utiliounitflush proc~esmf_utilarray2string ESMF_UtilArray2String proc~esmf_logflush->proc~esmf_utilarray2string proc~esmf_logopenfile->proc~esmf_utiliounitflush proc~esmf_utiliounitget ESMF_UtilIOUnitGet proc~esmf_logopenfile->proc~esmf_utiliounitget

Called by

proc~~esmf_configsetstring~~CalledByGraph proc~esmf_configsetstring ESMF_ConfigSetString interface~esmf_configsetattribute ESMF_ConfigSetAttribute interface~esmf_configsetattribute->proc~esmf_configsetstring proc~esmf_configsetinti4 ESMF_ConfigSetIntI4 interface~esmf_configsetattribute->proc~esmf_configsetinti4 proc~esmf_configsetinti4->interface~esmf_configsetattribute proc~f_esmf_configsetstring f_esmf_configsetstring proc~f_esmf_configsetstring->interface~esmf_configsetattribute proc~singleparset SingleParSet proc~singleparset->interface~esmf_configsetattribute program~esmf_hconfigutest ESMF_HConfigUTest program~esmf_hconfigutest->interface~esmf_configsetattribute

Source Code

      subroutine ESMF_ConfigSetString(config, value, &
        keywordEnforcer, label, rc)

! !ARGUMENTS:
      type(ESMF_Config),     intent(inout)         :: config
      character(*),          intent(in)            :: value
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      character(len=*),      intent(in),  optional :: label
      integer,               intent(out), optional :: rc

!
! !DESCRIPTION: 
!  Sets an integer {\tt value} in the {\tt config} object.
!
!   The arguments are:
!   \begin{description}
!   \item [config]
!     Already created {\tt ESMF\_Config} object.
!   \item [value]
!     String to set.
!   \item [{[label]}]
!     Identifying attribute label. 
!   \item [{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOPI -------------------------------------------------------------------
!
      integer :: localrc
      character(len=ESMF_MAXSTR) :: logmsg
      character(len=NBUF_MAX) :: curVal, newVal
      integer :: i, j, k, m, nchar, ninsert, ndelete, lenThisLine

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

      !check variables
      ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)

      ! Set config buffer at desired attribute
      if ( present (label) ) then
         call ESMF_ConfigGetString( config, curVal, label=label, rc=localrc)
      else
         call ESMF_ConfigGetString( config, curVal, rc = localrc )
      endif

      if ( localrc /= ESMF_SUCCESS ) then
        if ( localrc == ESMF_RC_NOT_FOUND ) then
          ! set config buffer at end for appending
          i = config%cptr%nbuf
        else
          if ( present( rc ) ) then
            rc = localrc
          endif
          return
        endif
      else ! attribute found
        ! set config buffer for overwriting/inserting
        i = config%cptr%value_begin
      endif

      ! for appending, create new attribute string with label and value
      if ( i .eq. config%cptr%nbuf ) then
        if ( present(label) ) then
          write(newVal, *) trim(label), BLK, value
        else
          write(newVal, *) "__MISSING__:", BLK, value
        endif
        newVal = trim(adjustl(newVal)) // EOL
        nchar = len_trim(newVal)
        j = i + nchar

        ! check if enough space left in config buffer
        if (j .ge. NBUF_MAX) then   ! room for EOB if necessary
           write(logmsg, *) ", attribute label & value require ", j-i+1, &
               " characters (including EOL & EOB), only ", NBUF_MAX-i, &
               " characters left in config buffer"
           if (ESMF_LogFoundError(ESMC_RC_LONG_STR, msg=logmsg, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
        endif
      endif

      ! overwrite, with possible insertion or deletion of extra characters
      if (i .eq. config%cptr%value_begin) then
         write(newVal, *) value
         newVal = BLK // trim(adjustl(newVal)) // EOL

         nchar = len_trim(newVal)

         j = i + nchar - 1

         !  check if we need more space to insert new characters;
         !  shift buffer down (linked-list redesign would be better!)
         lenThisLine = index(config%cptr%buffer(i:config%cptr%next_line),EOL)
         if (lenThisLine .eq. 0) lenThisLine = config%cptr%nbuf - i

         if ( nchar .gt. lenThisLine) then
            ninsert = nchar - lenThisLine

            ! check if enough space left in config buffer to extend line
            ! leave room for EOB with .ge.
            if (config%cptr%nbuf+ninsert .ge. NBUF_MAX) then
               m = index(config%cptr%buffer(1:i), EOL, back=.true.)
               if (m .lt. 1) m = 1
               write(logmsg, *) ", attribute label & value require ", j-m+1, &
                   " characters (including EOL & EOB), only ", NBUF_MAX-i, &
                   " characters left in config buffer"
               if (ESMF_LogFoundError(ESMC_RC_LONG_STR, msg=logmsg, &
                                         ESMF_CONTEXT, rcToReturn=rc)) return
            endif

            config%cptr%nbuf = config%cptr%nbuf + ninsert
            config%cptr%buffer(i+lenThisLine+ninsert:config%cptr%nbuf+ninsert) = &
               config%cptr%buffer(i+lenThisLine:config%cptr%nbuf)

         ! or if we need less space and remove characters;
         ! shift buffer up
         elseif ( nchar .lt. lenThisLine ) then
            ndelete = lenThisLine - nchar
            config%cptr%buffer(i+lenThisLine-ndelete:config%cptr%nbuf-ndelete) = &
               config%cptr%buffer(i+lenThisLine:config%cptr%nbuf)
            config%cptr%nbuf = config%cptr%nbuf - ndelete
         endif
      endif

      ! write new attribute value into config
      config%cptr%buffer(i:j) = newVal(1:nchar)
      config%cptr%next_line = j + 1
      config%cptr%next_item = config%cptr%value_begin

      ! if appended, reset EOB marker and nbuf
      if (i .eq. config%cptr%nbuf) then
        config%cptr%buffer(j+1:j+1) = EOB
        config%cptr%nbuf = j
      endif

      if( present( rc )) then
        rc = ESMF_SUCCESS
      endif

      return
    end subroutine ESMF_ConfigSetString