Fortran Coder

查看: 9513|回复: 1
打印 上一主题 下一主题

[文件读写] 语法错误读取不了数据,求助

[复制链接]

1

帖子

1

主题

0

精华

新人

F 币
17 元
贡献
5 点
跳转到指定楼层
楼主
发表于 2018-4-20 22:23:31 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
[Fortran] 纯文本查看 复制代码
program main 
 implicit none
        integer i,j,k,l,m,n
        Integer,Parameter :: Nxm   = 224, Nxp  = 1057, Nx = Nxm + Nxp
        Integer,Parameter :: Ny    = 161
        Integer,Parameter :: Nz    = 161
        Real*8              U(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              V(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              W(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              P(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              T(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dudx(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dudy(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dudz(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dvdx(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dvdy(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dvdz(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dwdx(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dwdy(-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8              dwdz(-2:Nx+2,-2:Ny+2,-2:Nz+2)

        Real*8              dd  (3,3,-2:Nx+2,-2:Ny+2,-2:Nz+2)
        Real*8             Omega(3,  -2:Nx+2,-2:Ny+2,-2:Nz+2)
        integer(kind=4)               :: u_file
        integer(kind=4)               :: v_file
        integer(kind=4)               :: w_file
        Real*8              Levi(1:3,1:3,1:3) 
        Real*8,Parameter :: pi  = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825d0
        Real*8,Parameter :: Ldelta = 2.0d0 * pi
        Real*8,Parameter :: Lx  = 14.4* Ldelta
        Real*8,Parameter :: Ly  = 1.0d0 * Ldelta
        Real*8,Parameter :: Lz  = 1.0d0 * Ldelta
        Real*8,Parameter :: Lxm = 1.2 * Ldelta
        Real*8,Parameter :: Lxp = Lx - Lxm
        Real*8,Parameter :: dy = Ly / ( 161.0d0 - 1.0d0 )
        Real*8,Parameter :: dz = Lz / ( 161.0d0 - 1.0d0 )
        Real*8              dx (-1:Nx)
        Real*8              c1_dx (0:Nx)
        Real*8              c1_dx2(0:Nx)
        Real*8              x(0:Nx)
        Real*8              y(0:Ny)
        Real*8              z(0:Nz)

        Real*8              dxm(0:Nx)
        Real*8              dxhm(0:Nx)
        Real*8              c1_dxm(0:Nx)
        Real*8              c1_dxhm(0:Nx)
        Real*8              dxp(0:Nx)
        Real*8              dxhp(0:Nx)
        Real*8              c1_dxp(0:Nx)
        Real*8              c1_dxhp(0:Nx)

        Real*8              dxm_dxp(Nx-1)
        Real*8              c1_dxhpxm(Nx-1)
        Real*8              dxp_dxm(Nx-1)
        Real*8              c1_dxhmxp(Nx-1)
        Real*8,Parameter :: alp_x1  = 0.9d0
        Real*8,Parameter :: alp_x2  = 0.2d0
        Real*8,Parameter :: alpha_x  = ( Lxp / (1057.0d0 - 1.0d0) ) - ( alp_x1 * Lxm / 224.0d0 )
        Real*8,Parameter :: c1_4       = 1.0d0 /   4.0d0
        Real*8              x_alf, x_Nxm
        Real*8,Parameter :: c1_dz      = 1.0d0 /   dz
        Real*8,Parameter :: c1_dy      = 1.0d0 /   dy
        integer             iter, Count, rl ,Nt
        real*8              time
 
       
        Open(40, File = 'fgg0126Ob_ityp_UVWPT_bu', Form = 'unFormatted', Status = 'unknown')
        read(40) Nt, time
        read(40) U
        read(40) V
        read(40) W
        read(40) P
        read(40) T

        Close(40)
        
        write(*,*) Nt

        x(0) = 0.0d0

         Do i = 1, Nxm, 1
          Select Case(i)
          Case(            : Nxm  /4 )
          x(i) = x(i-1) + ( (alp_x2 / Dble( Nxm/4 )) * Dble(i) + ( 1.0d0 - alp_x2 ) )  &
                        * ( alpha_x * ( dcos(2.0d0 * pi * (Dble(i - 1) )/Dble(Nxm) ) ) **2 + (Lxp/Dble(Nxp -1) - alpha_x) )
          Case( Nxm/4   +1 : Nxm*3/4 )
          x(i) = x(i-1) + ( alpha_x * ( dcos(2.0d0 * pi * (Dble(Nxm/4) )/Dble(Nxm) ) ) **2 + (Lxp/Dble(Nxp -1) - alpha_x) )
          Case( Nxm*3/4 +1 : Nxm     )
          x(i) = x(i-1) + ( alpha_x * ( dcos(2.0d0 * pi * (Dble(i - 1) )/Dble(Nxm) ) ) **2 + (Lxp/Dble(Nxp -1) - alpha_x) )
          End Select   
        End Do

        x_alf = 2.0d0
        x_Nxm = x(Nxm)


        Do i = Nxm, Nx, 1
          x (i) = (i - Dble(Nxm)) * ( Lxp / Dble(Nxp -1) ) + Lxm
        End Do

        dx(0) = x(0) - ( 2.0d0 * x(0) - x(1) )
        Do i = 1, Nx, 1
          dx(i) = x(i) - x(i-1)  
        End Do

        !$OMP PARALLEL DO PRIVATE(i) SHARED(dxm,dxp,c1_dx,c1_dx2)
        Do i = 0, Nx, 1
          dxm(i)    = 0.5d0 * dx(i)
          dxp(i)    = 0.5d0 * dx(i)
          c1_dx (i) = 1.0d0 /  dx(i)
          c1_dx2(i) = 1.0d0 / (dx(i  ) * dx(i))
        End Do
        !$OMP End PARALLEL DO

        !$OMP PARALLEL DO PRIVATE(i) SHARED(dxhm,dxhp)
        Do i = 1, Nx-1, 1
          dxhm(i)     = ( dx(i-1) + dx(i  ) ) * 0.5d0
          dxhp(i)     = ( dx(i  ) + dx(i+1) ) * 0.5d0
        End Do
        !$OMP End PARALLEL DO

        !$OMP PARALLEL DO PRIVATE(i) SHARED(c1_dxm,c1_dxp,c1_dxhm,c1_dxhp)
        Do i = 1, Nx-1, 1
          c1_dxm (i)  = 1.0d0 /   dxm (i)
          c1_dxp (i)  = 1.0d0 /   dxp (i)
          c1_dxhm(i)  = 1.0d0 /   dxhm(i)
          c1_dxhp(i)  = 1.0d0 /   dxhp(i)
        End Do
        !$OMP End PARALLEL DO


!       ------ Velocity Gradient------
        
        Do k =1,  Nz-1
         Do j = 1,  Ny-1 
           Do i =   1, Nx-1, 1  
!       ------ (i,j,k) = (1,1)------
          dudx(i,j,k) =             (    - U(i-1,j  ,k) + U(i  ,j  ,k)    )*c1_dx(i)        
!       ------ (i,j,k) = (1,2)------
          dudy(i,j,k) = c1_4 * ( +  (    - U(i-1,j-1,k) + U(i-1,j,k  )    )*c1_dy                 &  
                                 +  (    - U(i-1,j,k  ) + U(i-1,j+1,k)    )*c1_dy                 &     
                                 +  (    - U(i  ,j-1,k) + U(i  ,j,k  )    )*c1_dy                 &
                                 +  (    - U(i  ,j  ,k) + U(i,  j+1,k)    )*c1_dy       )         
!       ------ (i,j,k) = (1,3)------
          dudz(i,j,k) = c1_4 * ( +  (    - U(i-1,j,k-1) + U(i-1,j,k  )    )*c1_dz                 & 
                                 +  (    - U(i-1,j,k  ) + U(i-1,j,k+1)    )*c1_dz                  &           
                                 +  (    - U(i  ,j,k-1) + U(i  ,j,k  )    )*c1_dz           & 
                                 +  (    - U(i  ,j,k  ) + U(i,  j,k+1)    )*c1_dz       )      
!       ------ (i,j,k) = (2,1)------
          dvdx(i,j,k) = c1_4 * ( +  (    - V(i-1,j-1,k) + V(i  ,j-1,k)    )*c1_dxhm(i)            &
                                 +  (    - V(i  ,j-1,k) + V(i+1,j-1,k)    )*c1_dxhp(i)            &
                                 +  (    - V(i-1,j  ,k) + V(i  ,j  ,k)    )*c1_dxhm(i)            &
                                 +  (    - V(i  ,j  ,k) + V(i+1,j  ,k)    )*c1_dxhp(i)  )         
!       ------ (i,j,k) = (2,2)------
          dvdy(i,j,k) =             (    - V(i  ,j-1,k) + V(i  ,j  ,k)    )*c1_dy  
!       ------ (i,j,k) = (2,3)------
          dvdz(i,j,k) = c1_4 * ( +  (    - V(i,j-1,k-1) + V(i,j-1,k  )    )*c1_dz          &
                                 +  (    - V(i,j-1,k  ) + V(i,j-1,k+1)    )*c1_dz               &        
                                 +  (    - V(i,j  ,k-1) + V(i,j  ,k  )    )*c1_dz              &
                                 +  (    - V(i,j  ,k  ) + V(i,j  ,k+1)    )*c1_dz       )          

!       ------ (i,j,k) = (3,1)------
          dwdx(i,j,k) =    c1_4 * ( +  (    - W(i-1,j,k-1) + W(i  ,j,k-1)    )*c1_dxhm(i)            &
                                 +  (    - W(i  ,j,k-1) + W(i+1,j,k-1)    )*c1_dxhp(i)            &
                                 +  (    - W(i-1,j,k  ) + W(i  ,j,k  )    )*c1_dxhm(i)            &
                                 +  (    - W(i  ,j,k  ) + W(i+1,j,k  )    )*c1_dxhp(i)  )  

!       ------ (i,j,k) = (3,2)------
          dwdy(i,j,k) =    c1_4 * ( +  (    - W(i,j-1,k-1) + W(i,j  ,k-1)    )*c1_dy          &
                                 +  (    - W(i,j  ,k-1) + W(i,j+1,k-1)    )*c1_dy              &
                                 +  (    - W(i,j-1,k  ) + W(i,j  ,k  )    )*c1_dy              &
                                 +  (    - W(i,j  ,k  ) + W(i,j+1,k  )    )*c1_dy       )           
!       ------ (i,j,k) = (3,3)------                 
          dwdz(i,j,k) =                (    - W(i  ,j,k-1) + W(i  ,j  ,k)    )*c1_dz
        
       End Do
         End Do 
        End Do

        
        Do k = 145,  176
          Do j = 145,  176 
            Do i =   1, Nx-1, 1       
          dd(1,1,i,j,k) = dudx(i,j,k)
          dd(1,2,i,j,k) = dudy(i,j,k)
          dd(1,3,i,j,k) = dudz(i,j,k)
          dd(2,1,i,j,k) = dvdx(i,j,k)
          dd(2,2,i,j,k) = dvdy(i,j,k)
          dd(2,3,i,j,k) = dvdz(i,j,k)
          dd(3,1,i,j,k) = dwdx(i,j,k)
          dd(3,2,i,j,k) = dwdy(i,j,k)
          dd(3,3,i,j,k) = dwdz(i,j,k)
            End Do
          End Do
        End Do

!       ------ Levi-Civita ------
    Do k = 1, 3, 1
    Do j = 1, 3, 1
        Do i = 1, 3, 1
          levi(i,j,k) = 0.0d0  
    End Do; End Do; End Do  

        levi(1,2,3) = 1.0d0 
        levi(3,1,2) = 1.0d0 
        levi(2,3,1) = 1.0d0 

        levi(1,3,2) = -1.0d0 
        levi(2,1,3) = -1.0d0 
        levi(3,2,1) = -1.0d0      



        Omega(:,:,:,:) = 0.0d0
        
        Do k = 1, Nz-1
          Do j = 1, Ny-1 
            Do i = 1, Nx-1, 1     
          Do l = 1, 3       
          Do m = 1, 3 
          Do n = 1, 3  
            Omega(l,i,j,k) = Omega(l,i,j,k) + levi(l,m,n) *  dd(m,n,i,j,k) 
          End Do; End Do; End Do        
        End Do
          End Do
        End Do
end program

At line 72 of file vorticity.f90 (unit = 40, file = 'fgg0126Ob_ityp_UVWPT_bu')
Fortran runtime error: End of file

Screenshot from 2018-04-20 22-02-17.png (28.95 KB, 下载次数: 225)

这是原写入代码

这是原写入代码
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

2033

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1642 元
贡献
709 点

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

沙发
发表于 2018-4-21 08:08:46 | 只看该作者
end-of-file

这是读取文件时遇到了文件的结束。例如,代码要求数据有3行数据,而实际输入文件只有2行。在某些时候,甚至输入文件根本不存在或是空白文件。此外,数据文件缺失某些行某些列也是较大的可能。当然,也可能是循环读取文件时没控制住。比如想读100行,结果写错了,读了1000行。有时候,可能是文件路径错误,导致实际读取了另一个空白的文件。或者文件扩展名被隐藏了,比如读取 a.txt,但实际的文件名却是 a.txt.txt
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-12-27 09:58

Powered by Tencent X3.4

© 2013-2024 Tencent

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