Silverfrost Forums

Welcome to our forums

problem regarding pointers/allocate etc.

24 Jan 2012 5:23 #9481

Dear Fortran experts!

The test program below gives unexpected results with version 6.20 (and older versions). Other compilers (gnu fortran, intel fortran) seem to work fine. For example, the outcome of g95 is:

..... zeros for N=1 and 2 3 1 1 11 3 2 1 21 3 3 1 31 3 4 1 41 3 1 2 12 3 2 2 22 3 3 2 32 3 4 2 42 3 1 3 13 3 2 3 23 3 3 3 33 3 4 3 43 4 1 1 0 4 2 1 0 4 3 1 0 4 4 1 0 4 1 2 0 4 2 2 0 4 3 2 0 4 4 2 0 4 1 3 0 4 2 3 0 4 3 3 0 4 4 3 0 .... more zeros for N=5 to 10

as expected, whereas the outcome of ftn95 v6.20 has a shift and two missing numbers:

..... zeros for N=1 and 2 3 1 1 11 3 2 1 21 3 3 1 31 3 4 1 41 3 1 2 0 3 2 2 0 3 3 2 0 3 4 2 0 3 1 3 0 3 2 3 0 3 3 3 12 3 4 3 22 4 1 1 0 4 2 1 0 4 3 1 0 4 4 1 0 4 1 2 13 4 2 2 23 4 3 2 33 4 4 2 43 4 1 3 0 4 2 3 0 4 3 3 0 4 4 3 0 .... zeros for N=5 to 10

Please help!

Regards,

Roel

C --------------------------------------------------------------------- C PROGRAM POINTER_TEST C IMPLICIT NONE

c---------------------------------------- type realarray integer,dimension(:,:),pointer :: arr END type realarray

  type(realarray), dimension(10), target :: lst_fb
  integer, dimension(:,:), pointer :: fb

c----------------------------------------

  integer i,j,ierr,N

  DO N=1,10
  ALLOCATE(lst_fb(N)%arr(4,3),stat = ierr)
  if (ierr.ne.0) then
     print *,'allocation error'
     stop
  endif
  ENDDO

  DO N=1,10
  DO J = 1, 3
  DO I = 1, 4
     lst_fb(N)%arr(i,j)=0
  ENDDO
  ENDDO
  ENDDO

  fb => lst_fb(3)%arr

  DO J = 1, 3
  DO I = 1, 4
    FB(i,j) = i*10+j
  ENDDO
  ENDDO

  DO N=1,10
  DO J = 1, 3
  DO I = 1, 4
     print*,N,i,j,lst_fb(N)%arr(i,j)
  ENDDO
  ENDDO
  ENDDO

  STOP
  END

C C ---------------------------------------------------------------------

25 Jan 2012 10:06 #9485

I have logged this as a bug in FTN95. Here is a minimal program that illustrates the bug...

      PROGRAM POINTER_TEST 
c---------------------------------------- 
      TYPE array 
      INTEGER arr(4,3) 
      END TYPE array 
      
      TYPE(array),TARGET::lst_fb(10)
       
      INTEGER,DIMENSION(:,:),POINTER::fb 
c---------------------------------------- 
      lst_fb(3)%arr(1,2)=42 
      fb => lst_fb(3)%arr 
      fb(1,2) = 12 ! fb(3,3) is changed not fb(1,2)
      print*, lst_fb(3)%arr(1,2)
      END 
27 Jan 2012 6:41 #9515

Thanks Paul! I suppose this will be fixed in the new release? I so, when is a new release scheduled?

Roel

27 Jan 2012 9:02 #9518

We will aim to have it fixed for the next release which would normally be towards the end of 2012.

6 Mar 2012 1:37 #9761

This bug has now been fixed for the next release of FTN95.

Please login to reply.