title: Pass kind parameter to subprogram
body: <p>Is it possible in modern versions of Fortran to pass a kind parameter to a subprogram and to use this to 'cast' variables to this kind? As an example, in the following code I am trying to convert an default integer to an 16-bit integer before printing it.</p>
  
  <pre><code>program mwe
  
  ! Could use iso_fortran_env definition of int16, but I am stuck with
  ! old versions of ifort and gfortran.
  ! use, intrinsic :: iso_fortran_env, only : int16
  
  implicit none
  
  ! 16-bit (short) integer kind.
  integer, parameter :: int16 = selected_int_kind(15)
  
  call convert_print(123, int16)
  
  contains
  
    subroutine convert_print(i, ikind)
      implicit none
      integer, intent(in) :: i
      integer, intent(in) :: ikind
  
      print*, int(i, ikind)
  
    end subroutine convert_print
  
  end program mwe
  </code></pre>
  
  <p>With this example code the Intel Fortran compiler complains that </p>
  
  <blockquote>
    <p>mwe.f(24): error #6238: An integer constant expression is required in this context.   [IKIND]<br>
    ...<br>
    mwe.f(24): error #6683: A kind type parameter must be a compile-time constant   [IKIND]</p>
  </blockquote>
  
  <p>and gfortran complains</p>
  
  <blockquote>
    <p>'kind' argument of 'int' intrinsic at (1) must be a constant</p>
  </blockquote>
  
  <p>Using <code>print*, int(i, int16)</code> in place of <code>print*, int(i, ikind)</code> would of course work fine in this case. However, if <code>convert_print</code> were defined in a a module which does not define <code>int16</code> then this would be useless.</p>
  
  <p>Is there a way of passing a kind parameter as a constant to subprograms?</p>