Silverfrost Forums

Welcome to our forums

allocateable array of integers / Ref through Null Pointer

1 Apr 2008 6:07 #2969

I'm having an issue with the latest ftn95 5.2.1 which goes along the lines of 'Error: Reference through NULL Fortran POINTER'

Module Mod_Name

integer,dimension(:),allocatable,save :: array1

Contains Subroutine Sub_Name integer :: k,i,stat k = 0 do i = 1,mxI if (condition(i)) k = k +1 end do allocate (array1(k),STAT = stat) do i = 1,k array1(i) = some value !!!!!!!!!!!! end do

...something else...

End Subroutine Sub_Name End Module Mod_Name

Which errors at the !!!!!! marked line

in the debugger right clicking on array1 yields 'no pointer'

the stat value for on allocation is 2 (but I can't find a table to tell me what these stat values mean and I'm sure non-zero means it didn't work!)

Thanks!

2 Apr 2008 8:29 #2970

well it turns out that k = 8 in this case incremented as expected, I hope that an array of 8 integers is less than the heap size!

the code I posted was an over simplification, its in a read file routine so its actually:

do read(unit=rdunit,fmt='(1x,i4)',iostat = stat) iin1 if (iin1 == 0) exit if (InputGroup(iin1,inpgrp1) then k = k + 1 else exit with error message end if end do

allocate (array1(k),STAT = stat) do i = 1,k array1(i) = some value !!!!!!!!!!!! end do

InputGroup is a 2D logical array that runs over all inputs and input groups and is true if iin1 is in the group referenced by the second variable

with the debugger the program functions as expected untill the allocate array1 statement is executed

2 Apr 2008 8:47 #2971

Can you post some working code that fails in this way, that is code that compiles and fails with the NULL prointer. Alternatively I can give you an email address to send the code to.

2 Apr 2008 8:54 #2972

can I get an email address, its not in a simple program at all! Don't think the boss would be very happy with me posting big chunks of real code up!

2 Apr 2008 8:56 #2973

You could test if K<=0 or array1 is already allocated before the allocate statement. Report the value of K before allocating.

regards John

2 Apr 2008 9:57 #2975

John,

use of

if (.not.allocated(array1)) allocate(array1(k)) else deallocate(array1) allocate(array1(k)) end if

was tested and didn't help

I haven't put in explicit check on k in the code, but have using the debugger verified that the value of k before execution is the integer 8

2 Apr 2008 10:02 #2976

using the vars table before execution of the allocate statement reports that

array1 = integer * 4 (-2139062144:16843008)

which as far as my knowledge goes indicates that it is an array the size of the heap of 4 byte integers and I thought that allocate would then change the bounds to those specifies and reduce the size of the heap by the requisite amount...

8 Apr 2008 11:32 #3006

Using Nullify(array1) instead of deallocate(array1) seemed to do the trick

If allocatable and pointer are synonymous then should deallocate be synonymous (or incorporate) nullify?

No idea why it happened in this one particular instance!

8 Apr 2008 11:58 #3011

I have not followed the detail of this conversation but you will probably need to nullify if there is a call to deallocate before the first call to allocate.

Please login to reply.