Using pointers in fortran 95
- From: Massimo Marchi <Massimo.Marchi@xxxxxx>
- Date: Fri, 28 Oct 2005 11:52:16 +0200
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
.
- Follow-Ups:
- Re: Using pointers in fortran 95
- From: fj
- Re: Using pointers in fortran 95
- Prev by Date: Re: compare two dynamic string
- Next by Date: Modules in parallel programming
- Previous by thread: memory not freed up?
- Next by thread: Re: Using pointers in fortran 95
- Index(es):
Relevant Pages
|