Fortran Coder

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

[稀疏矩阵] 如何将压缩储存的稀疏矩阵转化为满秩矩阵

[复制链接]

1963

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1357 元
贡献
574 点

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

楼主
发表于 2018-6-26 08:28:06 | 显示全部楼层
[Fortran] 纯文本查看 复制代码
program fcode_cn
  Implicit None
  Real , allocatable    :: rMatrix(:,:) , value(:)
  Integer , allocatable :: ipodia(:) , indexJ(:)
  Integer :: N , M , i , j
  Open( 12 , File = "Ipodia.txt")
  Open( 13 , File = "Index J.txt")
  Open( 14 , File = "Value.txt")
  N = GetFileN( 12 )
  M = GetFileN( 13 )
  Allocate( rMatrix(N,N) , ipodia(0:N) , indexJ(M) , value(M) )
  rMatrix   = 0
  ipodia(0) = 0
  Read(12,*) ipodia(1:)
  Read(13,*) indexJ
  Read(14,*) value
  Do i = 1 , N
    rMatrix( indexJ( ipodia(i-1)+1 : ipodia(i) ) , i ) = value( ipodia(i-1)+1 : ipodia(i) )
    rMatrix( i , :i-1 ) = rMatrix( :i-1 , i )
  End Do
  Close(12)
  Close(13)
  Close(14)
  
contains

  Integer Function GetFileN( iFileUnit )
    Integer , Intent( IN ) :: iFileUnit
    character( Len = 1 ) :: cDummy
    integer :: ierr
    GetFileN = 0
    Rewind( iFileUnit )
    Do
      Read( iFileUnit , * , ioStat = ierr ) cDummy
      If( ierr /= 0 ) Exit
      GetFileN = GetFileN + 1
    End Do
    Rewind( iFileUnit )
  End Function GetFileN 
  
end program fcode_cn
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-7 08:17

Powered by Tencent X3.4

© 2013-2024 Tencent

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