Fortran Coder

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

[求助] 用allocate重写数组声明后出现 Can't open module file gai'ru'he'jie'j...

[复制链接]

4

帖子

2

主题

0

精华

新人

计算固体力学研发

F 币
6 元
贡献
15 点
跳转到指定楼层
楼主
发表于 2022-10-9 11:53:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
8F 币
本帖最后由 xiejihong0306 于 2022-10-9 12:18 编辑

已知在我把主程序和子程序的数组声明都改写成allocate形式之后(在此之前是直接指定的数组大小,可以正常编译),例如

[Fortran] 纯文本查看 复制代码
integer(kind=4) :: Iorder_, l, js(:)
real(kind=8), allocatable :: FmatrixCoeff_(:, :), FvectorRside_(:), x(:)
allocate(FmatrixCoeff_(Iorder_, Iorder_), FvectorRside_(Iorder_), x(Iorder_), js(Iorder_))


就出现以下报错:

Fatal Error: Can't open module file 'subroutines.mod' for reading at (1): No such file or directory
compilation terminated.
终端进程“C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command gfortran -g d:\_Personal__backup##\100__Project\VSCode_Fortran\Fortran_Alog_2nd_XuShiLiang\*.f90 -o 'D:\_Personal__backup##\100__Project\VSCode_Fortran\Fortran_Alog_2nd_XuShiLiang\1-1 AGAUS All-choice principal element Gaussian elimination method.exe'”已终止,退出代码: 1。


gFortran编译,算法没问题,可以忽略,肯定是语法上哪里细节错了,实在找不到问题了。

求助,感激不尽。源代码如下:


-----------------------------------------------------------------------------------
[Fortran] 纯文本查看 复制代码
!  All-choice principal element Gaussian elimination method
!  Solve the system of linear algebraic equations AX = B.

      module SUBROUTINES
        contains  ! Used to encapsulate functions or subroutines
        !implicit none  ! Used to encapsulate variables
        Subroutine SUB_agaus(FmatrixCoeff_, FvectorRside_, Iorder_, x, l, js)
          integer(kind=4) :: row = 0, col = 0
          integer(kind=4) :: Iorder_, l, js(:)          
          real(kind=8) :: b, t
          real(kind=8), allocatable :: FmatrixCoeff_(:, :), FvectorRside_(:), x(:)
          allocate(FmatrixCoeff_(Iorder_, Iorder_), FvectorRside_(Iorder_), x(Iorder_), js(Iorder_)) 

          l = 1
          Do k = 1, Iorder_ - 1
            d = 0.0
            ! Do i = k, Iorder_
            !   Do j = k, Iorder_
            !     If (abs(FmatrixCoeff_(i,j))>d) Then
            !       d = abs(FmatrixCoeff_(i,j))
            !       js(k) = j
            !       is = i
            !     End If
            !   End Do
            ! End Do
            forall ( row = k:Iorder_, col = k:Iorder_, abs(FmatrixCoeff_(row, col))>d ) 
              d = abs(FmatrixCoeff_(row, col))
              js(k) = col
              is = row
            end forall

            If (d+1.0==1.0) Then
              l = 0
            Else
              If (js(k)/=k) Then
                Do i = 1, Iorder_
                  t = FmatrixCoeff_(i, k)
                  FmatrixCoeff_(i, k) = FmatrixCoeff_(i, js(k))
                  FmatrixCoeff_(i, js(k)) = t
                End Do
              End If
              If (is/=k) Then
                Do j = k, Iorder_
                  t = FmatrixCoeff_(k, j)
                  FmatrixCoeff_(k, j) = FmatrixCoeff_(is, j)
                  FmatrixCoeff_(is, j) = t
                End Do
                t = FvectorRside_(k)
                FvectorRside_(k) = FvectorRside_(is)
                FvectorRside_(is) = t
              End If
            End If
            !If l=0, it means that the coefficient matrix of the system of equations is singular, and the solution fails; if L=0, it means that the normal return
            If (l==0) Then
              Write (*, 100)
              Return
            End If
            Do j = k + 1, Iorder_
              FmatrixCoeff_(k, j) = FmatrixCoeff_(k, j)/FmatrixCoeff_(k, k)
            End Do
            FvectorRside_(k) = FvectorRside_(k)/FmatrixCoeff_(k, k)
            Do i = k + 1, Iorder_
              Do j = k + 1, Iorder_
                FmatrixCoeff_(i, j) = FmatrixCoeff_(i, j) - FmatrixCoeff_(i, k)*FmatrixCoeff_(k, j)
              End Do
              FvectorRside_(i) = FvectorRside_(i) - FmatrixCoeff_(i, k)*FvectorRside_(k)
            End Do
          End Do
          If (abs(FmatrixCoeff_(Iorder_, Iorder_))+1.0==1.0) Then
            l = 0
            Write (*, 100)
            Return
          End If
          x(Iorder_) = FvectorRside_(Iorder_)/FmatrixCoeff_(Iorder_, Iorder_)
          Do i = Iorder_ - 1, 1, -1
            t = 0.0
            Do j = i + 1, Iorder_
              t = t + FmatrixCoeff_(i, j)*x(j)
            End Do
            x(i) = FvectorRside_(i) - t
          End Do
          js(Iorder_) = Iorder_
          Do k = Iorder_, 1, -1
            If (js(k)/=k) Then
              t = x(k)
              x(k) = x(js(k))
              x(js(k)) = t
            End If
          End Do
          Return
          100 Format (1X, ' FAIL ')
        End Subroutine SUB_agaus
      end module SUBROUTINES




!// ForQuill v1.01 Beta www.fcode.cn


! NOTE:
!
program PROGRAM_NAME
  use SUBROUTINES, only : SUB_agaus
  implicit none
  integer ExitKey
  integer(kind=4) :: i, n = 4, l
  integer(kind=4), allocatable :: js(:) !Declare a variable-size array  
  real(kind=8), allocatable :: a(:, :), b(:), x(:) !Declare a variable-size array
  allocate(js(n), a(n, n), b(n), x(n)) !Configure memory space

  Data a/0.2368, 0.1968, 0.1582, 1.1161, 0.2471, 0.2071, 1.1675, 0.1254 &
  , 0.2568, 1.2168, 0.1768, 0.1397, 1.2671, 0.2271, 0.1871, 0.1490/
  Data b/1.8471, 1.7471, 1.6471, 1.5471/
  
  Call SUB_agaus(a, b, n, x, l, js)
  If (l /= 0) write(unit=6, fmt="('X(', I2, ' )=', D15.6)") (i, x(i), i=1, 4)


! Avoid having the command window exit before the results are output
  write ( *, *) 'Press input any words to exit...'
  read ( *, *) ExitKey
  stop
end program PROGRAM_NAME



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

2033

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1641 元
贡献
709 点

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

沙发
发表于 2022-10-9 14:43:45 | 只看该作者
需要把 js 也定义为 allocatable 的数组,此外,请一定要写 implicit none,它非常重要
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-12-24 03:01

Powered by Tencent X3.4

© 2013-2024 Tencent

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