Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran错误:位于(1)的意外语句函数语句_Fortran_Gfortran - Fatal编程技术网

Fortran错误:位于(1)的意外语句函数语句

Fortran错误:位于(1)的意外语句函数语句,fortran,gfortran,Fortran,Gfortran,我正在做一个fortran代码,在一个细胞模型中找到带有硬球的径向分布函数(RDF)。 它还没有完成,现在我有一个错误。我正在实现直方图。这是我的密码 implicit double precision (a-h,o-z) parameter(npart=3000) dimension x(0:npart),y(0:npart),z(0:npart) c n=Number of particules c rcel=Radius of the cell c r

我正在做一个fortran代码,在一个细胞模型中找到带有硬球的径向分布函数(RDF)。 它还没有完成,现在我有一个错误。我正在实现直方图。这是我的密码

      implicit double precision (a-h,o-z)
      parameter(npart=3000)
      dimension x(0:npart),y(0:npart),z(0:npart)

c n=Number of particules
c rcel=Radius of the cell
c rpart=Radius of the particules

      pi=3.1415927
      write(*,*)'n,rcel,rpart,dr?'
      read(*,*)n,rcel,rpart,dr
      write(*,*)'nstep,dp'
      read(*,*)nstep,dp
      rpart2=(2*rpart) 

      nfatmax=rcel/dr ! Number of bins
      vtotal=(4/3)*pi*rcel*rcel*rcel
      dentotal=n/vtotal
      write(*,*)'Density of particles, volume and bins = '
      write(*,*)dentotal,vtotal,nfatmax

      x(0)=0
      y(0)=0
      z(0)=0

      write(*,'(a,/)')'Generating start configurations'      
      counter1=0
      counter2=0
      counter3=0

      k=0
      do i=1,n

   21 xx=rcel*(ran()-0.5)*2
      yy=rcel*(ran()-0.5)*2
      zz=rcel*(ran()-0.5)*2

      rr=xx**2+yy**2+zz**2
      dist=sqrt(rr)

      if(dist.gt.(rcel-rpart2))then  !Avoid particles outside the cell
      counter1=counter1+1
      go to 21
      end if

      if(dist.lt.rpart2)then    ! Avoid overlap with central particle
      counter2=counter2+1
      go to 21
      end if   

      if(i.ge.1)then
        do j=1,i-1,1
           sep2=(x(i)-x(j))**2+(y(i)-y(j))**2+(z(i)-z(j))**2
           sep=sqrt(sep2)
           if(sep.lt.rpart2)then
           counter3=counter3+1
           go to 21
           end if
        end do
      end if

      k=k+1
      x(k)=xx
      y(k)=yy
      z(k)=zz
      end do

      write(*,*)'Starting config'
      write(*,'(3f8.3)')(x(i),y(i),z(i),i=1,n)  

      counterA=counter1+counter2+counter3
      write(*,*)'Rejection = '
      write(*,*)counterA

c     Monte Carlo loop
      counter4=0
      counter5=0
      counter6=0

      do i = 1,nfatmax
         h(i) = 0       !!!! Error here!!!!!!
      end do
      nobs = 0
      naccept = 0 

      do i=1,nstep
        do j=1,n
         nobs = nobs + 1
         xil=x(j)+dp*(ran()-0.5)
         yil=y(j)+dp*(ran()-0.5)
         zil=z(j)+dp*(ran()-0.5)

         r2=(xil**2)+(yil**2)+(zil**2)
         r=sqrt(r2)

         if(r.gt.(rcel-rpart2))then
           counter4=counter4+1
           go to 444    ! Avoid particles outside the cell
         end if

         if(r.lt.rpart2)then
           counter5=counter5+1
           go to 444    ! Avoid overlap with central particle
         end if 

         do ii=1,j-1
           dist2=(x(ii)-xil)**2+(y(ii)-yil)**2+(z(ii)-zil)**2
           dist=sqrt(dist2)
           if(dist.lt.rpart2)then
             counter6=counter6+1
             go to 444               ! Avoid overlap wit particles
           end if
         end do

c        Accepted configuration 
         x(j)=xil
         y(j)=yil
         z(j)=zil
         naccept = naccept + 1

c        Rejected configuration
 444     continue

         do jj=1,n
           dist2=(x(jj))**2+(y(jj))**2+(z(jj))**2
           dist=sqrt(dist2)
           k=(dist/dr)+1
           h(k) = h(k)+1    !!!!!!!! Error here!!!!!!!!!
         end do
        enddo
      end do

      write(*,*)'Final config'
      write(*,'(3f8.3)')(x(j),y(j),z(j),j=1,n)

      counterB=counter4+counter5+counter6
      write(*,*)'Rejection ='
      write(*,*)counterB
      stop
      end

我看到你在标注
x
y
z
的尺寸,但我没有看到
h
的尺寸


在尝试将值放入数组之前,您可能希望先创建数组。

我看到您对
x
y
z
进行了尺寸标注,但我没有看到
h
的此类beastie


在尝试将值放入数组之前,可能需要先创建数组。

在代码中,
h
未声明

我假设它应该是一个长度为nfatmax的数组:

dimension h(nfatmax)

正如High Performance Mark的评论中所述,您可以通过在代码中使用
隐式无
..

来发现此错误,
h
未声明

我假设它应该是一个长度为nfatmax的数组:

dimension h(nfatmax)

正如High Performance Mark的评论中所述,您可以通过使用
隐式无

发现此错误,因为标记表明您正在使用gfortran,我建议在开发时使用以下编译器选项:
-O2-fimplicit none-Wall-Wline截断-Wcharacter截断-Wsurprising-Waliasing-Wimplicit接口-Wunused参数-fcheck=all-std=f2008-pedantic-fbacktrace
。其中一些具有运行时成本(例如,
-fcheck=all
),通常会在编译生产可执行文件时删除
-fimplicit none
将应用
隐式none
,即使您在源代码中忘记了它。由于标记指示您正在使用gfortran,我建议在开发时使用以下编译器选项:
-O2-fimplicit none-Wall-Wline截断-Wcharacter截断-Wsurprising-Waliasing-Wimplicit接口-Wunused参数-fcheck=all-std=f2008-pedantic-fbacktrace
。其中一些具有运行时成本(例如,
-fcheck=all
),通常会在编译生产可执行文件时删除
-fimplicit none
将应用
隐式none
,即使您在源代码中忘记了它。