Using pointers in fortran 95



Hello everybody,

I am having troubles understanding if the way I am using pointers in
the module Module_Neighbors is conform to f95 standard or not. I had
problems with this on the pgi compiler (version 5.2-4 and 6.0), which
in some partcular case returns a ierr /= 0 for the first deallocate
statement in the subroutine "Delete". Can anybody help? I enclose an
example of the way I am using the module in my code.

Thank you beforehand

Massimo


========================================================================
MODULE Module_Neighbors
IMPLICIT none
TYPE Neighbors
INTEGER :: no=0
INTEGER, DIMENSION (:), POINTER :: nb=>null()
END TYPE Neighbors
CONTAINS
SUBROUTINE Start(neigh,nmol)
IMPLICIT none
TYPE(Neighbors), DIMENSION (:), POINTER :: neigh
INTEGER :: nmol

INTEGER :: i

ALLOCATE(neigh(nmol))
DO i=1,nmol
neigh(i) % no = 0
NULLIFY(neigh(i) % nb)
END DO

END SUBROUTINE Start
SUBROUTINE Delete(neigh)
IMPLICIT none
INTEGER :: i,ierr
TYPE(Neighbors), DIMENSION (:), POINTER :: neigh

IF(ASSOCIATED(neigh)) THEN
DO i=1,SIZE(neigh)
IF(ASSOCIATED(neigh(i) % nb)) THEN
DEALLOCATE(neigh(i) % nb, STAT=ierr)
IF(ierr /= 0) THEN
WRITE(*,*) 'ierr not zero',ierr
ELSE
WRITE(*,*) 'ierr zero',ierr
END IF
NULLIFY(neigh(i) % nb)
END IF
END DO
DEALLOCATE(neigh, STAT=ierr)
NULLIFY(neigh)
END IF
END SUBROUTINE Delete
END MODULE Module_Neighbors
PROGRAM Test_Neigh
USE Module_Neighbors, ONLY: Neigh_Start=>Start, Neigh_Delete&
&=>Delete, Neighbors
IMPLICIT NONE
TYPE(Neighbors), DIMENSION (:), POINTER :: neigh1
TYPE(Neighbors), DIMENSION (:), POINTER, SAVE :: neigha
INTEGER :: i,n,j,map,p_nn,Count
PARAMETER (n=10)
INTEGER, DIMENSION(n) :: ind_a


NULLIFY(neigha)

Count=0
DO
CALL Neigh_Delete(neigha)
CALL Neigh_Start(neigha,n)
neigh1=>neigha

p_nn=0
DO i=1,n
p_nn=p_nn+1
map=i
DO j=1,map
ind_a(1:map) = j
END DO
neigh1(p_nn) % no = map
ALLOCATE(neigh1(p_nn) % nb(map))
neigh1(p_nn) % nb = ind_a(1:map)
END DO
Count=Count+1
IF(Count > 2) EXIT
END DO

END PROGRAM Test_Neigh

.



Relevant Pages

  • Re: Procedure Pointer (Components) with no explicit interface and with implicit typing
    ... in principle, I can assign to it either a function nor a subroutine, e.g. ... "7.4.2.2 Procedure pointer assignment" ... "If proc-pointer-object has an implicit interface and is explicitly ... external:: func, sub ...
    (comp.lang.fortran)
  • Re: Pointer-valued function to access inner components
    ... implicit none ... Return a F90 pointer which points to the diagonal of T. ... a copyin/copyout on array A during the procedure call. ... subroutine dirty_pointer_1d ...
    (comp.lang.fortran)
  • More gfortran and BIND(C)
    ... implicit none ... subroutine sub1bind ... end interface ... attribute or of an associated POINTER. ...
    (comp.lang.fortran)
  • Re: Merge Sorting
    ... subroutine Merge ... dimension QA ... Had to change so that implicit character(*) would work! ... end interface Mergesort ...
    (comp.lang.fortran)
  • Re: How to declare my_reshape()
    ... >to at compile time. ... mind using a subroutine instead of a function, ... implicit none ... integer, intent, allocatable, dimension(:):: z ...
    (comp.lang.fortran)