Fortran Coder

小数部位该为0却不是0

查看数: 8154 | 评论数: 2 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2018-2-1 15:30

正文摘要:

程序中的aa和C1数组均为实型,其中,C1数组在后续组成线性方程组的系数矩阵。问题出现在:Fortran中输出的aa数组其小数位都为0,而C1数组其小数位不为0;用matlab得到C1数组的结果小数位是等于0的。是不是跟实数的标 ...

回复

pasuka 发表于 2018-2-1 16:43:16
C1数组没有赋初值,与aa结果不一致又有啥奇怪呢?
-finit-local-zero
-finit-derived
-finit-integer=n
-finit-real=<zero|inf|-inf|nan|snan>
-finit-logical=<true|false>
-finit-character=n
The -finit-local-zero option instructs the compiler to initialize local INTEGER, REAL, and COMPLEX variables to zero, LOGICAL variables to false, and CHARACTER variables to a string of null bytes. Finer-grained initialization options are provided by the -finit-integer=n, -finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real and imaginary parts of local COMPLEX variables), -finit-logical=<true|false>, and -finit-character=n (where n is an ASCII character value) options. Components of derived type variables will be initialized according to these flags only with -finit-derived. These options do not initialize

allocatable arrays
variables that appear in an EQUIVALENCE statement.
(These limitations may be removed in future releases).

Note that the -finit-real=nan option initializes REAL and COMPLEX variables with a quiet NaN. For a signalling NaN use -finit-real=snan; note, however, that compile-time optimizations may convert them into quiet NaN and that trapping needs to be enabled (e.g. via -ffpe-trap).

Finally, note that enabling any of the -finit-* options will silence warnings that would have been emitted by -Wuninitialized for the affected local variables.


NeilYo 发表于 2018-2-1 15:43:23
下面是相应地代码:
[Fortran] 纯文本查看 复制代码
program Compute
    implicit none
    integer,parameter::M=1,N=2
    real,dimension(:,:),allocatable::C1
    integer i,j,k,m1,n1,a1,a2,ETL(M*N,5)
    real aa(4,4)
    allocate(C1((M+1)*(N+1),(M+1)*(N+1)))
    open(unit=15,file='storett3',access='sequential',action='write')
    open(unit=14,file='storeaa3',access='sequential',action='write')
    data aa/4,2,1,2,2,4,2,1,1,2,4,2,2,1,2,4/
    k=0
    do j=1,M
       do i=1,N
          k=k+1
          ETL(k,1)=k
          m1=mod(i,N)
          if(m1==0) then
             n1=j*(N+1)-1
          else
             n1=(j-1)*(N+1)+m1
          end if
          ETL(k,2)=n1
          ETL(k,3)=n1+1
          ETL(k,4)=n1+N+2
          ETL(k,5)=n1+N+1
        end do
    end do    
    do k=1,M*N
       do i=1,4
          do j=1,4
             a1=ETL(k,i+1)
             a2=ETL(k,j+1)
             C1(a1,a2)=C1(a1,a2)+aa(i,j)
          end do
       end do
    end do
    write(14,"(<4>('',f,''))")((aa(i,j),i=1,4),j=1,4)
    write(15,"(<6>('',f,''))")((C1(i,j),i=1,6),j=1,6)
end

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

GMT+8, 2024-11-24 01:15

Powered by Tencent X3.4

© 2013-2024 Tencent

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