Construct_EquationParser Function

private function Construct_EquationParser(equation, indepVars) result(parser)

Arguments

TypeIntentOptionalAttributesName
character :: equation
character :: indepVars(:)

Return Value type(EquationParser)


Contents


Source Code

  function Construct_EquationParser(equation,indepVars) result(parser)
    type(EquationParser) :: parser
    character(*)         :: equation
    character(*)         :: indepVars(:)
    ! Local
    integer :: i
    character(:),allocatable   :: errorMsg
    logical                     :: equationIsClean,tokenized,success
    integer                     :: nIndepVars

    call InitializeFunctions()

    nIndepVars = size(indepVars)
    allocate(parser%indepVars(1:nIndepVars))
    parser%nIndepVars = nIndepVars
    do i = 1,nIndepVars
      parser%indepVars(i)%value = trim(indepVars(i))
    enddo

    parser%equation = trim(equation)
    if(allocated(parser%inFixFormula)) deallocate(parser%inFixFormula)
    allocate(character(len(parser%equation)+maxFunctionLength+1) :: parser%inFixFormula)
    parser%variableName = '#noname'

    call parser%CleanEquation(equationIsClean)

    if(equationIsClean) then
      call parser%Tokenize(tokenized,errorMsg)
      if(tokenized) then
        call parser%ConvertToPostFix()
      else
        if(allocated(errorMsg)) print*,trim(errorMsg)
        success = .false.
      endif
    endif

  endfunction Construct_EquationParser