2014-10-01 21 views
-5
program height_sand 
     implicit none 
    integer tmax, nmax 
    real zmax, maxx 
    parameter (nmax=200000) 
    real x1(nmax),y1(nmax),z1(nmax),teta 
     !real d, zmax, xmax 
    integer t,ntot 
    integer i, j, id, tip(nmax) 
    open(unit=1,file='vmdfile.xyz') 
    open(unit=3,file='height.dat') 
    ntot=3000 
     tmax=51 
     maxx=0 
     zmax=0 

     do t=1,tmax 
      read(1,*) 
      read(1,*) 


     do i=1,ntot 
     read(1,*)tip(id),x1(id),y1(id),z1(id) 

      if (z1(id).gt.zmax) then 
      zmax=z1(id) 

     end if 

     if (x1(id).gt.maxx) then 
      maxx=x1(id) 
     end if 

      end do 

      teta=zmax/maxx 
      write(3,*)t,zmax,teta 
    end do 


     !110 format(I8, f15.6) 
    END 
+2

編譯所有警告和調試信息('gfortran -g-Wall')。使用調試器('gdb')。如果可能的話,切換到最新版本的Fortran(至少Fortran 2003) – 2014-10-01 07:10:45

+0

這不是一個簡單的例子,因爲沒有輸入文件,我們不能重現問題。 – Peter 2014-10-01 07:38:56

+2

編譯運行時間下標檢查。用gfortran,'-fcheck = all'或'-fcheck = bounds'。這會導致編譯器查找由高性能標記標識的問題。 – 2014-10-01 15:57:34

回答

1

此行

  read(1,*)tip(id),x1(id),y1(id),z1(id) 

可能是您報告錯誤的根源。在執行時id還沒有被賦予一個值。如果你認爲它會被自動設置爲0,那麼(a)你認爲是錯誤的,並且(b)tip(0)無論如何都是無效的數組元素引用,因爲Fortran索引從1開始(除非你專門將它們設置爲另一個起始值,顯示的代碼不)。

由於循環控制變量(tmaxntot)不在循環內部使用,我強烈懷疑您向我們展示了一個半熟的代碼。

相關問題