forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

allocateable array of integers / Ref through Null Pointer

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Tue Apr 01, 2008 7:07 pm    Post subject: allocateable array of integers / Ref through Null Pointer Reply with quote

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(Smile,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!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
brucebowler
Guest





PostPosted: Tue Apr 01, 2008 7:52 pm    Post subject: Re: allocateable array of integers / Ref through Null Pointe Reply with quote

MattMcD wrote:
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


What's the value of mxI and what does condition look like? In other words, is k getting incremented as expected?[/code]
Back to top
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Wed Apr 02, 2008 9:29 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Wed Apr 02, 2008 9:47 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Wed Apr 02, 2008 9:54 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Wed Apr 02, 2008 9:56 am    Post subject: Reply with quote

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

regards John
Back to top
View user's profile Send private message
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Wed Apr 02, 2008 10:57 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Wed Apr 02, 2008 11:02 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
MattMcD



Joined: 06 Sep 2007
Posts: 19
Location: Cambridge,UK

PostPosted: Tue Apr 08, 2008 12:32 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Tue Apr 08, 2008 12:58 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group