FindStr Subroutine

private subroutine FindStr(Key, Str, DefMsg, Proposal)

Find parameter string containing keyword "Key" in list of strings starting with "FirstString" and return string "Str" without keyword. If keyword is not found in list of strings, return default values "Proposal" (error if not given). Ini file was read in before and is stored as list of character strings starting with "FirstString".

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: Key

Search for this keyword in ini file

character(len=*), intent(out) :: Str

Parameter string without keyword

character(len=8), intent(inout) :: DefMsg

Default message = keyword not found, return default parameters (if available)

character(len=*), intent(in), optional :: Proposal

Default values as character string (as in ini file)


Calls

proc~~findstr~~CallsGraph proc~findstr FindStr interface~deletestring DeleteString proc~findstr->interface~deletestring interface~lowcase LowCase proc~findstr->interface~lowcase proc~remove_blanks remove_blanks proc~findstr->proc~remove_blanks proc~replace replace proc~findstr->proc~replace interface~deletestring->interface~deletestring interface~lowcase->interface~lowcase

Source Code

SUBROUTINE FindStr(Key,Str,DefMsg,Proposal)
! MODULES
IMPLICIT NONE
!-----------------------------------------------------------------------------------------------------------------------------------
! INPUT VARIABLES
CHARACTER(LEN=*),INTENT(IN)          :: Key         !! Search for this keyword in ini file
CHARACTER(LEN=8),INTENT(INOUT)       :: DefMsg      !! Default message = keyword not found, return default parameters (if available)
CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: Proposal    !! Default values as character string (as in ini file)
!-----------------------------------------------------------------------------------------------------------------------------------
! OUTPUT VARIABLES
CHARACTER(LEN=*),INTENT(OUT)         :: Str         !! Parameter string without keyword
!-----------------------------------------------------------------------------------------------------------------------------------
! LOCAL VARIABLES
CHARACTER(LEN=LEN(Key))              :: TmpKey
TYPE(tString),POINTER                :: Str1
LOGICAL                              :: Found
!===================================================================================================================================
DefMsg='*CUSTOM'
! Convert to lower case
CALL LowCase(Key,TmpKey)
TmpKey=remove_blanks(TmpKey)
Found=.FALSE.
Str1=>FirstString
DO WHILE(.NOT.Found)
  IF (.NOT.ASSOCIATED(Str1)) THEN
    IF (.NOT.PRESENT(Proposal)) THEN
      CALL abort(__STAMP__, &
           "missing necessary parameter '"//TRIM(TmpKey)//"'", &
           TypeInfo="MissingParameterError")
    ELSE ! Return default value
!      CALL LowCase(TRIM(Proposal),Str)
      IF(LEN_TRIM(Proposal).LE.LEN(Str))THEN
        Str=TRIM(Proposal)
      ELSE
        CALL abort(__STAMP__,&
          'parameter readin: proposal string of parameter '//TRIM(Key)//' does not fit into output string!')
      END IF


      IF (Str(1:1).NE.'@') THEN
        DefMsg='DEFAULT'
      END IF
      RETURN
    END IF ! (.NOT.PRESENT(Proposal))
  END IF ! (.NOT.ASSOCIATED(Str1))

  IF (INDEX(Str1%Str,TRIM(TmpKey)//'=').EQ.1) THEN
    Found=.TRUE.
    Str1%Str=replace(Str1%Str,TRIM(TmpKey)//'=',"")
    IF(LEN_TRIM(Str1%str).LE.LEN(Str))THEN
      Str=TRIM(Str1%Str)
    ELSE
      CALL abort(__STAMP__,&
        'parameter readin: string of parameter '//TRIM(Key)//' does not fit into output string!')
    END IF
    ! Remove string from list
    CALL DeleteString(Str1)
  ELSE
    ! Next string in list
    Str1=>Str1%NextStr
  END IF

END DO
END SUBROUTINE FindStr