title: Passing strings for execution in Fortran subroutines
body: <p>In the following subroutine I would like to pass a string variables named <code>str</code>. If it is <code>'poly'</code>, <code>'gaus'</code>, <code>'slat'</code>, then it has a predefined action (<code>fval =</code><i> see code below </i>). I would like to have the user specify a function to use and pass that as a string variable.</p>
  
  <p>That is ... </p>
  
  <p>If <code>str = '3*cos(i*t)'</code>, then i would like to have <code>fval</code> be equal to <code>3*cos(i*t)</code>. How can I get Fortran to interpret the string entered as a command to be executed by Fortran?</p>
  
  <pre><code>subroutine f(fval, i, t, str)
  implicit none
  integer, parameter :: ikind = selected_int_kind(8)
  integer, parameter :: dbl = selected_real_kind(15,307)
  
  integer(kind = ikind) :: i
  real(kind = dbl) :: fval, t
  character str*100
  
  if(str .eq. 'poly') then
      fval = t**i
  elseif(str .eq. 'slat') then
      fval = exp(-i*t)
  elseif(str .eq. 'gaus') then
      fval = exp(-i*t*t)
  else
      fval = ???
  endif
  
  end subroutine
  </code></pre>