title: Defining and invoking a constructor in Fortran
body: <p>I can't figure out how I define a simple constructor for a class. What I want to do is allocate an array in <code>mytype</code> and later populate it in the main program.</p>
  
  <p>What I have is this:</p>
  
  <pre><code>module types
      implicit none
  
      type mytype
          real, allocatable :: someArray(:)
      end type mytype
  
      interface
          module procedure :: init
      end interface
  
  contains
      subroutine init(this)
          class(mytype), intent(inout) :: this
          allocate( this%someArray(5) )
      end subroutine init
  end module types
  
  program test
    use types
    implicit none
  
    type(mytype) :: array
  
    call array%init
    do i=1, 5
      array%someArray(i) = real(i)
      print *, array%someArray(i)
    end do
  end program test
  </code></pre>
  
  <p>When I compile I get the error</p>
  
  <blockquote>
    <p>Error: MODULE PROCEDURE at (1) must be in a generic module interface</p>
  </blockquote>
  
  <p>What does that mean? How can I define a <em>generic module interface</em>?</p>
  
  <p>Thanks!</p>