AM在FORTRAN中编写代码以读取STARCD格式的网格文件(has.cel,.vrt和.bnd)我试图使用计数器和指针数组来计算顶点数和文件数因此,以后很容易定义单元的邻居。你能不能看看代码并纠正我,我得到一个错误无效的数组参考形式(1)。
ivrt(icell(i)%cell(2)%icounter(1)=ivrt(icell(i)%cell(2)%icounter(1)+1
1
此处显示了与icounter的所有行的错误。为了给出你正在做什么的概述,我刚刚声明了我使用的类型和变量,我正在读取三个文件.vrt(nov).cel(noc)和.bnd(bnd)并定义数据结构.vrt有4列,.cel有5列。
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)
答案 0 :(得分:1)
缺少两个括号......您的意思是:
ivrt( icell(i)%cell(2)%icounter(1) ) = ivrt( icell(i)%cell(2)%icounter(1)+1 )
^ ^
或:
ivrt( icell(i)%cell(2)%icounter(1) ) = ivrt( icell(i)%cell(2)%icounter(1) ) + 1
^ ^
在整个代码中,该错误会重复多次!
答案 1 :(得分:0)
与Alexander Vogt一样,我同意缺少括号。但是,还有另一个问题。
在类型cel
的定义中,组件cell
是一个整数数组:
type :: cel
integer, allocatable, dimension(:) :: cell, ishape, reffwd
end type
type(cel), allocatable, dimension(:) :: icell
所以不能有参考icell(i)%cell(2)%...
或许,cel
的宣言应该是
type :: cel
type(node), allocatable, dimension(:) :: cell
! Also components ishape, reffwd of some type.
end type
end type
然后另外修改括号。