replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Bug using intent(inout) on subobject of type
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 

Bug using intent(inout) on subobject of type

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



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Jun 14, 2014 12:15 pm    Post subject: Bug using intent(inout) on subobject of type Reply with quote

In the following, the init_list subroutine makes a call to the reset subroutine passing the list subobject of the list_container.

The reset subroutine has the intent(inout) for the list. In this version of the code, it just sets the elements of the list to 1, 2, 3, 4. (In another version it shuffles the list; this isn't important, but shows why intent(inout) is required).

The program should print out the elements as 1, 2, 3, 4 but doesn't, showing that the call to reset doesn't work.

If I change the intent for list to intent(out) it works, but I can't use this if I change reset to do a shuffle.

I am still using 7.00 here.

Code:

module xxx

   implicit none
   
   type list_container_t
      integer :: n
      integer :: list(20)
   end type list_container_t
   
contains

   subroutine init_list(list_container, n)
      integer, intent(in) :: n
      type(list_container_t), intent(out) :: list_container
      integer :: i
      list_container%n = n
      do i=1, n
         list_container%list(i) = n-i+1
      end do
      call reset(list_container%list, n)
   end subroutine init_list
   
   subroutine reset(list, n)
      integer, intent(in) :: n
      integer, intent(inout) :: list(:)
      integer :: i
      do i=1, n
         list(i) = i
      end do
   end subroutine reset

end module xxx

program test

   use xxx
   
   implicit none

   integer :: i
   type(list_container_t) :: list_container
   
   call init_list(list_container, 4)
   
   print *, 'Should print 1 to 4 but doesn''t'
   do i=1, 4
      print *, list_container%list(i)
   end do
   
end program test


This is the shuffle version of reset, which replaces the above in my real code.

Code:

   ! In place Fisher-Yates/Knuth shuffle
   subroutine reset(list, n)
      integer, intent(in) :: n
      integer, intent(inout) :: list(:)
      integer :: i, j, k
      real :: u
      do i=1, n-1
         call random_number(u)
         j = i + floor((n-i+1)*u)
         k = list(i)
         list(i) = list(j)
         list(j) = k
      end do
   end subroutine reset

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Jun 17, 2014 6:59 am    Post subject: Reply with quote

Thanks David. I have logged this for investigation.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Fri Jan 16, 2015 9:56 am    Post subject: Reply with quote

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Jan 17, 2015 2:41 pm    Post subject: Reply with quote

Thanks a lot Paul.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
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