0

I have to classify millions of numbered triangles into different squares (suppose there are 1000 squares) by some method, but I don't know how many triangles that belong to some square before judgement. So I need 1000 linked lists so that I can store the number of relevant triangles in any length.

But it seems that I can't decalre a 1000-element head array to create 1000 linked lists in Fortran (Intel Visual Fortran 2011), and there is an error:

LoopLinkedList.for(34): error #7121: A ptr dummy may only be argument associated with a ptr, and this array element or section does not inherit the POINTER attr from its parent array. [CURRENT]

Here is code of my testing program:

   module global
       type node
         integer i
          type(node) ,pointer ::next
       end type node
   end module global 


   program  LinkedList
   use global

   integer k
    interface 
    subroutine insertItem(pos,item)
     use global
     implicit none 
     type(node) ,pointer ::pos,item
    end subroutine insertItem
    end interface 

   type(node), pointer::item,head(:),current(:)


   allocate(head(1000))
   allocate(current(1000))
    head(1) = node(1,head(1))
   current(1)=head(1)


    do k  =2,10
    allocate(item)
    !allocate(current%next) 
    item%i = k
    call insertItem(current(1),item)
   current(1) =item
    end do



    k =current(1)%i
    do while(.true.) 
      write(*,*) current(1)%i
     if(.not.associated(current(1)%next)) exit
      current(1) =current(1)%next
      if(current(1)%i.eq.k)exit
    end do

    deallocate(head)
    deallocate(current)
   end program LinkedList



    subroutine insertItem(pos,item)
     use global
     implicit none 

     type(node) ,pointer ::item,pos

     if(associated(pos%next)) then
     item%next =>pos%next
     pos%next=>item
     end if

  end subroutine insertItem
12
  • Intel Fortran usually indicates which line is offending. You should include the complete error message and the command which has generated it. Commented Feb 25, 2016 at 12:28
  • At least item in the subroutine should be target and not pointer but there will be probably more errors. Commented Feb 25, 2016 at 12:31
  • 1>G:\VS\files\LoopLinkedList\LoopLinkedList\LoopLinkedList.for(34): error #7121: A ptr dummy may only be argument associated with a ptr, and this array element or section does not inherit the POINTER attr from its parent array. [CURRENT]@VladimirF Commented Feb 25, 2016 at 12:31
  • 1
    There is a pointer array, but there is no array of pointers. You can create an array of a derived type with a pointer component instead. Commented Feb 25, 2016 at 12:41
  • 1
    Pointer array is NOT array of pointers! Commented Feb 25, 2016 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.