Fortran Coder

查看: 10362|回复: 3
打印 上一主题 下一主题

[求助] 关于Access Violation的问题

[复制链接]

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
跳转到指定楼层
楼主
发表于 2016-10-4 09:39:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
碰到一个莫名其妙的bug,该程序已经跑起来过,语法上应该没问题。
结果我用的时候,一开始跑,程序就那么挂在那里,不输出也不停止也不报错。检查输出,发现结果输出到一半就没动静了。然后为了debug,在代码输出的地方添了write(*,'(4i5)')  iyear,imon,iday,itim来看跑到哪里了。结果跑到停的那个位置就报错了,说Access Violation。关键是用/traceback看是哪里出错,结果竟然就是write(*,'(4i5)')  iyear,imon,iday,itim这里。
我已经检查了输入数据,没出现数据连在一起造成输入错误的情况。输入数据检查了一遍,没发现什么异常。根据以前的经验我怀疑是数组上下界哪里有问题,但是初步检查了一边没有越界的情况。还请各位指点一下出现这个问题可能的原因,小弟不胜感激。
以下是代码:

[Fortran] 纯文本查看 复制代码
!-----------------------------------------------------------------------
!
!            Convert HS-BSWONE result format program.
!
!-----------------------------------------------------------------------
      integer,parameter :: idmx=100    
      integer,parameter :: ndmx=10   
!-----------------------------------------------------------------------
      integer :: ihon,isho,ndall,iend,iendtm,kkk1,kkk2,kkk3
      integer :: iyear,imon,iday,itim,iyear0,iday0,itim0
      integer :: ie(0:ndmx),ishi(ndmx)
      real(8) :: zb(idmx),zs(idmx),v(idmx),dm(idmx),us(idmx),use(idmx),qq(idmx)
      real(8) :: tqb(idmx),tqs(idmx),tqw(idmx),tqbsw(idmx),silt2(idmx),dck(idmx),tqw_all(idmx,idmx),dtqw
      real(8) :: tqbik(idmx,ndmx),tqbswsba(idmx,ndmx),tdw(idmx)
      real(8) :: tqbsub(2),tqssub(2),tqwsub(2),tqbswsbas(idmx),tqbiks(idmx)
      real(8) :: tqbik0(idmx,ndmx),tqw0(idmx)
      real(8) :: ss1tmp,ss2tmp
      character(len=500) date
!-----------------------------------------------------------------------


      ihon=0


      ie(0) = 0      !(not change.)
      ie(1) = 66    


      isho=0

      ndall = 10


      iend = 900000    

      open(1,file ='1D-hyd.dat',status='old')
!      open(2,file='sed-side.dat')
      open(3,file='sed-bsw.dat',status='old')
      open(4,file='sed-k.dat')
!      open(5,file='Silt2.dat')

      open(32,file='out/11.csv')

      open(100,file='out/22.csv',status='unknown')
      open(101,file='out/33.csv',status='unknown')
      open(102,file='out/44.csv',status='unknown')
      open(103,file='out/55.csv',status='unknown')
      open(104,file='out/66.csv',status='unknown')
      open(105,file='out/77.csv',status='unknown')
      open(106,file='out/88.csv',status='unknown')
      open(107,file='out/99.csv',status='unknown')
      open(108,file='out/111.csv',status='unknown')
      open(109,file='out/222.csv',status='unknown')
      open(110,file='out/333.csv',status='unknown')
      open(111,file='out/444.csv',status='unknown')
      open(112,file='out/555.csv',status='unknown')
      open(113,file='out/666.csv',status='unknown')
      open(114,file='out/777.csv',status='unknown')

      iendtmp=0
      kkk0=0
      kkk1=0
      kkk2=0
      kkk3=0

      do i=1,iend        !time loop start


        if(i > 1) tqbik0(1:idmx,1:ndmx)=tqbik(1:idmx,1:ndmx)
!ori        if(i > 1) tqw0(1:idmx)=tqw(1:idmx)
        if(i > 1) tqw0(1:idmx)=tqw_all(i-1,1:idmx)
        if(i > 1) iyear0=iyear
        if(i > 1) iday0=iday
        if(i > 1) itim0=itim

       do j=1,ihon+1
        read(1,*,IOSTAT=instat)   ! skip a line.
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 1***"
        read(1,'(1x,4i5)',IOSTAT=instat) iyear,imon,iday,itim
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 1***"

        if(itim0 == 23 .and. itim == 24 .and. iday > iday0) iday=iday0

        read(1,*,IOSTAT=instat)   ! skip a line.
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 1***"
        do k=ie(j-1)+1,ie(j)
          read(1,'(10x,3f10.0,30x,f10.0,10x,3f10.0)',IOSTAT=instat) qq(k),zb(k),zs(k),v(k),dm(k),use(k),us(k)
!          write(*,'(I3,1000f10.3)')K, qq(k),zb(k),zs(k),v(k),dm(k),use(k),us(k)
          if(instat<0)exit
          if(instat>0)stop "*** Input Error! 2***"
        enddo  !for k
       enddo   !for j
       if(instat<0)exit
       if(instat>0)stop "*** Input Error! 3***"


       dtqw=1.d0
       do j=1,ihon+1
        read(3,*,IOSTAT=instat)
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 3***"
        read(3,'(1x,4i5)') ky,km,kd,kt
!        write(*,*) ky,km,kd,kt,"here"
        read(3,*,IOSTAT=instat)

        if(km.eq.12.and.kd.eq.31.and.kt.eq.24) then
         kkk2=kkk2+1
         write(32,'(1x,5(i5,","))') ky,km,kd,kt,kkk2
        end if

        do k=ie(j-1)+1,ie(j)
         read(3,'(45x,3f10.0,30x,f10.0)',IOSTAT=instat) tqb(k),tqs(k),tqw(k),tdw(k)
!         write(*,'(I3,4f10.3)')K, tqb(k),tqs(k),tqw(k),tdw(k)
!ori         tqbsw(k)=tqb(k)+tqs(k)+tqw(k)
         if(instat<0)exit
         if(instat>0)stop "*** Input Error! 4***"
        enddo    !for k

        do k=ie(j),ie(j-1)+1,-1
         if(k.eq.ie(j)) then
         else if (k.eq.ie(j-1)+1) then
          tqw(k)=tqw(k+1)-tdw(k)
         else
          tqw(k)=tqw(k+1)-tdw(k) 
         end if
         tqb(k)=dmax1(0.d0,tqb(k))
         tqs(k)=dmax1(0.d0,tqs(k))
         tqw(k)=dmax1(0.d0,tqw(k))
         tqbsw(k)=tqb(k)+tqs(k)+tqw(k)
         if(i==1) tqw0(k)=tqw(k)
         tqw_all(i,k)=tqw(k)

        enddo    !for k


        do k=ie(j-1)+1,ie(j)
         if(km.eq.12.and.kd.eq.31.and.kt.eq.24) then
          write(32,'(3(f10.3,","))',IOSTAT=instat) tqb(k),tqs(k),tqw(k)
         end if
        enddo    !for k
!====special:end
       enddo     !for j

        itmp=i
        tqwtmp=tqw(k)
        do ii=i,1,-1
         if(tqw_all(ii,1) > tqwtmp) then
          itmp=ii
         end if
         tqwtmp=tqw_all(itmp,1)
        end do

        if(itmp < i) then
         dtqw=tqw(1)/tqwtmp
         do ii=itmp,1,-1 
          do k=1,ie(ihon+1)-1
           tqw_all(ii,k)=tqw_all(ii,k)*dtqw
          end do
         end do
        end if

       do k=1,3
        read(4,*,IOSTAT=instat)
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 7***"
       enddo
       do k=1,ie(ihon+1)
        if(i.lt.iend) read(4,'(10x,50f10.0)',IOSTAT=instat) (tqbik(k,l),l=1,ndall)
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 8***"
        if(i.eq.iend) read(4,'(10x,50f10.0)',IOSTAT=instat) (tqbik(k,l),l=1,ndall)
        if(instat<0)exit
        if(instat>0)stop "*** Input Error! 9***"
        do l=1,ndall
         tqbik(k,l)=dmax1(0.d0,tqbik(k,l))
         tqbiks(k)=tqbiks(k)+tqbik(k,l)
        enddo
       enddo

       do k=1,ie(ihon+1)
        uscm=us(k)*100.d0
        dck1=(uscm**2.d0)/80.9d0
        dck2=(uscm**(22.d0/31.d0))/134.6d0
        dck3=(uscm**2.d0)/55.d0
        dck4=(uscm**(32.d0/11.d0))/8.41d0
        dck5=(uscm**2.d0)/226.d0
        if(dck1 >= 0.3030d0) dck(k)=dck1
        if(dck2 < 0.3030d0 .and. dck2 >= 0.1180d0) dck(k)=dck2
        if(dck3 < 0.1180d0 .and. dck3 >= 0.0565d0) dck(k)=dck3
        if(dck4 < 0.0565d0 .and. dck4 >= 0.0065d0) dck(k)=dck4
        if(dck5 > 0.d0 .and. dck5 < 0.0065d0) dck(k)=dck5
       end do

       write(*,'(4i5)')  iyear,imon,iday,itim
       write(100,'(4(i5,","),1000(f10.2,","))')  iyear,imon,iday,itim,(zb(k),k=1,ie(ihon+1))
       write(101,'(4(i5,","),1000(f10.2,","))')  iyear,imon,iday,itim,(zs(k),k=1,ie(ihon+1))
       write(102,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(v(k)*100,k=1,ie(ihon+1))
       write(103,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(dm(k),k=1,ie(ihon+1))
       write(104,'(4(i5,","),1000(f10.4,","))')  iyear,imon,iday,itim,(use(k),k=1,ie(ihon+1))
       write(105,'(4(i5,","),1000(f10.4,","))')  iyear,imon,iday,itim,(us(k),k=1,ie(ihon+1))
       write(106,'(4(i5,","),1000(f10.2,","))')  iyear,imon,iday,itim,(qq(k),k=1,ie(ihon+1))
       write(113,'(4(i5,","),1000(f10.4,","))')  iyear,imon,iday,itim,(dck(k)*10.d0,k=1,ie(ihon+1))

       write(108,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(tqb(k),k=1,ie(ihon+1))
       write(109,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(tqs(k),k=1,ie(ihon+1))
       write(110,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(tqw(k),k=1,ie(ihon+1))
       write(111,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(tqbsw(k),k=1,ie(ihon+1))
       write(112,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,((tqbik(k,l),k=1,ie(ihon+1)),l=1,ndall)

       iendtmp=iendtmp+1
      enddo              !time loop end
      write(*,'(a,i10)') '< 総時間ステップ数 >=',iendtmp
      iend=iendtmp

      close(1)
      close(2)
      close(3)
!sisen      close(32)
      close(33)
      close(4)
      close(5)
      close(100)
      close(101)
      close(102)
      close(103)
      close(104)
      close(105)
      close(106)
!silt2      close(107)
      close(108)
      close(109)
      close(110)
      close(111)
      close(112)
      close(113)

      do i=1,iend 
       write(114,'(4(i5,","),1000(f10.3,","))')  iyear,imon,iday,itim,(tqw_all(i,k),k=1,ie(ihon+1))
      enddo

      close(114)

      stop
      end


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
沙发
 楼主| 发表于 2016-10-4 10:16:54 | 只看该作者
查了一下ifort的用法,用/check:bounds 来追踪错误,果然是数组越界了。

2033

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1641 元
贡献
709 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

板凳
发表于 2016-10-4 19:20:53 | 只看该作者
ifort for linux 默认情况下很多检查都是关闭的。所以我建议准备一组常规的调试选项。

60

帖子

17

主题

0

精华

专家

F 币
454 元
贡献
266 点
地板
 楼主| 发表于 2016-10-7 09:41:29 | 只看该作者
fcode 发表于 2016-10-4 19:20
ifort for linux 默认情况下很多检查都是关闭的。所以我建议准备一组常规的调试选项。 ...

确实如此。不仅仅是linux,windows下也是这样的。

有时候程序是能跑,而且结果还是对的。如果不调试的话根本不知道有错误发生了。

受教了~~~
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-12-25 21:19

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表