CleanEquation Subroutine

private subroutine CleanEquation(parser, equationCleaned)

Arguments

TypeIntentOptionalAttributesName
class(EquationParser), intent(inout) :: parser
logical, intent(out) :: equationCleaned

Contents

Source Code


Source Code

  subroutine CleanEquation(parser,equationCleaned)
    class(EquationParser),intent(inout)    :: parser
    logical,intent(out)                    :: equationCleaned
    ! Local
    integer :: nChar,equalSignLoc,j,i,n
    character(:),allocatable :: infixformula

    equationCleaned = .false.

    equalSignLoc = index(parser%equation,'=')
    if(equalSignLoc /= 0) then
      parser%variableName = parser%equation(1:equalSignLoc-1)
    endif

    !Replace ** for ^
    parser%equation = ReplaceStr(parser%equation,'**','^')
    nChar = len_trim(parser%equation)

    ! Grab the formula to the right of the equal sign and left adjust the formula
    inFixFormula = parser%equation(equalSignLoc+1:)
    ! Remove any spaces
    j = 1
    n = len(inFixFormula)
    do i = 1,n
      if(inFixFormula(i:i) /= ' ') then
        parser%inFixFormula(j:j) = inFixFormula(i:i)
        j = j+1
      endif
    enddo

    parser%inFixFormula(j:) = ' '
    equationCleaned = .true.

  endsubroutine CleanEquation