user3816496
user3816496

Reputation: 1

Invalid form of array reference in fortran

AM writing a code in FORTRAN to read a mesh file in STARCD format(has.cel, .vrt and .bnd) am trying to use a counter and a pointer array, to count the number of vertices and the cells the file has so that it would be easy to define the neighbours of the cells later. Can you please take a look at the code and correct me out please and i get an error Invalid form of array reference at (1).

ivrt(icell(i)%cell(2)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1

               1

The error is shown here for all the lines with the icounter. To give u the outline of what is being done, i have just declared the types i have used and the variables, am reading the three files .vrt(nov) .cel(noc) and .bnd(bnd) and defining the datastructure where .vrt has 4 columns, .cel has 5 columns.

program reader
implicit none

type::node
real,allocatable,dimension(:)::point1,icounter,vrt
end type 

type::elemtype
integer,allocatable,dimension(:)::quad,refback
integer,allocatable,dimension(:)::tri
end type 

type::cel
integer,allocatable,dimension(:)::cell,ishape,reffwd
end type 

type::boundnode
integer,allocatable,dimension(:)::bnode
end type 

type::boundarycell
integer,allocatable,dimension(:)::bcell
end type 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

type(node),allocatable,dimension(:)::ivrt 
type(elemtype),allocatable,dimension(:)::iquad
type(elemtype),allocatable,dimension(:)::itri 
type(cel),allocatable,dimension(:)::icell 
type(boundnode),allocatable,dimension(:)::ibnode 
type(boundarycell),allocatable,dimension(:)::ibcell 

integer::nov,noc,bnd,nbnd,i,j,k,count1,count2,numquad,flag,numtri
integer::usercell,tcell,cindex
integer::celltype,n,m

integer,allocatable,dimension(:,:)::qedg1,qedg2,qedg3,qedg4
integer,allocatable,dimension(:,:)::tedg1,tedg2,tedg3,tedg4
integer,allocatable,dimension(:)::ctype
integer,allocatable,dimension(:)::quadvert 
integer,allocatable,dimension(:)::trivert 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CALL SYSTEM("wc  STAR.vrt > NO_V")
OPEN (UNIT=10,FILE='NO_V',STATUS="OLD",ACTION="READ")
READ (10,"(i6)")nov
close(10)

print *, nov

CALL SYSTEM("wc  STAR.cel > NO_C")
OPEN (UNIT=10,FILE='NO_C',STATUS="OLD",ACTION="READ")
READ (10,"(i6)")noc
close(10)

print *, noc 

CALL SYSTEM("wc  STAR.bnd > NO_B")
OPEN (UNIT=10,FILE='NO_B',STATUS="OLD",ACTION="READ")
READ (10,"(i6)")nbnd
close(10)

print *, nbnd

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

allocate(ivrt(nov))
do i=1,nov
  allocate(ivrt(i)%vrt(1:4))
  allocate(ivrt(i)%icounter(1))
end do

allocate(icell(noc))
do i=1,noc
  allocate(ivrt(i)%icounter(1)) 
  allocate(icell(i)%cell(1:5))
  allocate(icell(i)%ishape(1))
  allocate(icell(i)%reffwd(1))
end do

allocate(ibnode(nbnd))
do i=1,bnd
  allocate(ibnode(i)%bnode(1:3))
end do

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

open(unit=10,file="STAR.vrt",status="old",action="read")
do i = 1,nov
  read(10,*)ivrt(i)%vrt(1), ivrt(i)%vrt(2), ivrt(i)%vrt(3), ivrt(i)%vrt(4) 
  !print *, ivrt(i)%vrt(1), ivrt(i)%vrt(2), ivrt(i)%vrt(3), ivrt(i)%vrt(4)
end do
close (10)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

open(unit=10,file="STAR.cel",status="old",action="read")
do i=1,noc
  read(10,*)icell(i)%cell(1),icell(i)%cell(2),icell(i)%cell(3),icell(i)%cell(4),icell(i)%cell(5)
  ivrt(icell(i)%cell(2)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
  ivrt(icell(i)%cell(3)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
  ivrt(icell(i)%cell(4)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
    if (icell(i)%cell(4).ne.icell(i)%cell(5))then
    ivrt(icell(i)%cell(5)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
    end if
end do
close(10)

do i=1,nov
  allocate(ivrt(i)%point1(ivrt(i)%icounter(1)))
end do

ivrt(:)%icounter(:)=0

open(unit=10,file="STAR.cel",status="old",action="read")
do i=1,noc
  read(10,*)icell(i)%cell(1),icell(i)%cell(2),icell(i)%cell(3),icell(i)%cell(4),icell(i)%cell(5)
  ivrt(icell(i)%cell(2)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
  ivrt(icell(i)%cell(3)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
  ivrt(icell(i)%cell(4)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1

  ivrt(icell(i)%cell(2))%point1(ivrt(icell(i)%cell(2))%icounter(1))=i
  ivrt(icell(i)%cell(3))%point1(ivrt(icell(i)%cell(2))%icounter(1))=i
  ivrt(icell(i)%cell(4))%point1(ivrt(icell(i)%cell(2))%icounter(1))=i
    if (icell(i)%cell(4).ne.icell(i)%cell(5))then
    ivrt(icell(i)%cell(5))%point1(ivrt(icell(i)%cell(2))%icounter(1))=i
    ivrt(icell(i)%cell(5))%icounter(1)=ivrt(icell(i)%cell(2))%icounter(1)+1
    end if
end do
close(10)

Upvotes: 0

Views: 1531

Answers (2)

francescalus
francescalus

Reputation: 32451

Like Alexander Vogt I agree that there are brackets missing. However, there is another problem.

In the defintion of the type cel the component cell is an integer array:

type :: cel
  integer, allocatable, dimension(:) :: cell, ishape, reffwd
end type
type(cel), allocatable, dimension(:) :: icell

so one cannot have a reference icell(i)%cell(2)%...

Perhaps, then, the declaration of cel should be

type :: cel
  type(node), allocatable, dimension(:) :: cell
  ! Also components ishape, reffwd of some type.
end type

end type

And then the bracket corrections additionally.

Upvotes: 0

Alexander Vogt
Alexander Vogt

Reputation: 18118

There are two brackets missing... Do you mean:

ivrt( icell(i)%cell(2)%icounter(1) ) = ivrt( icell(i)%cell(2)%icounter(1)+1 )
                                   ^                                        ^

or:

ivrt( icell(i)%cell(2)%icounter(1) ) = ivrt( icell(i)%cell(2)%icounter(1) ) + 1
                                   ^                                      ^

That error is repeated several times throughout your code!

Upvotes: 1

Related Questions