here is my code
module vector_class
implicit none
! Type definition
type,public :: vector
private
real, dimension(:), POINTER :: v
logical :: v_allocated = .false.
contains
procedure,public :: set_vector=>set_vector_sub
procedure,public :: get_vector=>get_vector_sub
! procedure,public :: clear_vector=>clear_vector_sub
FINAL :: clear_vector
end type vector
private :: set_vector_sub,get_vector_sub,clear_vector_sub
contains
subroutine set_vector_sub(this,array)
implicit none
class(vector) :: this
real,dimension(:),intent(in) :: array
integer istat
if(this%v_allocated) then
deallocate(this%v,stat=istat)
endif
allocate(this%v(size(array,1)),stat=istat)
this%v = array
this%v_allocated = .true.
end subroutine set_vector_sub
subroutine get_vector_sub(this, array)
implicit none
class(vector) :: this
real,dimension(:),intent(out) :: array
integer array_length
integer data_length
integer istat
if(this%v_allocated) then
array_length = size(array,1)
data_length = size(this%v,1)
if(array_length > data_length) then
array(1:data_length) = this%v
array(data_length+1:array_length) = 0
else if(array_length == data_length) then
array = this%v
else
array = this%v(1:array_length)
endif
else
array = 0
endif
end subroutine get_vector_sub
subroutine clear_vector_sub(self)
implicit none
class(vector) :: self
integer istat
write(*,*) 'in finalizer .....'
if(self%v_allocated) then
deallocate(self%v,stat=istat)
endif
end subroutine clear_vector_sub
end module vector_class
program test_vector
use vector_class
implicit none
type(vector) :: aa
end program test_vector
following is compiler error :
vectorclass.f90(13): error #8338: A final subroutine name must be the name of a module procedure with exactly one dummy argument. [CLEAR_VECTOR]
FINAL :: clear_vector
------------^
compilation aborted for vectorclass.f90 (code 1)
i not kown why is IT error ?