Fortran Coder

查看: 1372|回复: 5
打印 上一主题 下一主题

[数学库] IMSL编译问题

[复制链接]

4

帖子

1

主题

0

精华

新人

F 币
20 元
贡献
9 点
跳转到指定楼层
楼主
发表于 2023-8-14 16:44:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
之前没啥代码经验,现在导师需要,在自学fortran
导师让把一个MATLAB的程序改为fortran的在这过程中遇到了一个编译问题,把其他的语法错误改完了后,编译器只剩下一个编译错误,但是自己看下来不知道到底哪里出错了,想请大神们帮帮
[Fortran] 纯文本查看 复制代码
 !传递函数a
    subroutine a(inc,theta0,point0,point2,point3)
        implicit none
        real :: inc
        real :: aa(2,2)
        real theta0,point0(2),point2(4),point3(4)
        real m23
        m23 = (point3(4)-point2(4))/(point3(3)-point2(3))
        aa(1,1) = 1
        aa(1,2) = -m23
        aa(2,1) = 1
        aa(2,2) = -tan(0.5*(theta0+inc))
        return
    end subroutine
    
    !传递函数b
    subroutine b(inc,theta0,point0,point2,point3)
        implicit none
        real inc
        real :: bb(2)
        real theta0,point0(2),point2(4),point3(4)
        real m23
        m23 = (point3(4)-point2(4))/(point3(3)-point2(3))
        bb(1) = point3(4)-m23*point3(3)
        bb(2) = point0(2)-tan(0.5*(theta0+inc))*point0(1)
        return
    end subroutine
    
    !左行壁面进程
    subroutine wall_plus(theta0,point0,point2,point3)
    
    include "link_fnl_shared.h"
    use numerical_libraries
    use linear_operators
    use operation_ix
    use operation_t
    real theta0,point0(2),point2(4),point3(4)
    real theta_new,point_new(2),old_theta,old_point(2)
    real th,tol
    real results(2)
    
    th = 1.0e-7
    tol = 1.0e3
    theta_new = theta0
    point_new(1) = point0(1)
    point_new(2) = point0(2)
    
    do while(tol>th)
        old_point = point_new
        old_theta = theta_new
        inc = theta_new
        call a(inc,theta0,point0,point2,point3)
        call b(inc,theta0,point0,point2,point3)
        point_new = aa .ix. bb
        theta_new = point2(1)+sqrt(((point_new(1)-point2(3))**2+(point_new(2)-point2(4))**2)/&
            ((point3(3)-point2(3))**2+(point3(4)-point2(4))**2))*(point3(1)-point2(1))
        tol=max(abs(point_new(1)-old_point(1)),abs(point_new(2)-old_point(2)))
        tol=max(tol,abs(theta_new-old_theta))
    end do
    results(1) = theta_new
    results(2) = .t. point_new
    
    end subroutine


报错结果是:error1:Compilation Aborted (code1)

这个程序在MATLAB的源程序如下
function results=wall_plus(theta0,point0,point2,point3)
    global th
    %theta0 is a scalar
    %point0 is an array
    %point1 and point3 are arrays
    m23=(point3(4)-point2(4))/(point3(3)-point2(3));
    A=@(INC) [1,-m23;1,-tan(0.5*(theta0+INC))]; %2x2 matrix
    B=@(INC) [point3(4)-m23*point3(3);point0(2)-tan(0.5*(theta0+INC))*point0(1)];

    tol=1e3;
    theta_new=theta0;
    point_new=[point0(1);point0(2)];
    while(tol>th)
        old_point=point_new;
        old_theta=theta_new;
        point_new=A(theta_new)\B(theta_new); %array
        theta_new=point2(1)+sqrt(((point_new(1)-point2(3))^2+(point_new(2)-point2(4))^2)/...
            ((point3(3)-point2(3))^2+(point3(4)-point2(4))^2))*(point3(1)-point2(1));
        tol=max(abs(point_new(1)-old_point(1)),abs(point_new(2)-old_point(2)));
        tol=max(tol,abs(theta_new-old_theta));
    end
    results=[theta_new,point_new'];
end


fortran程序中用了IMSL的库计算了矩阵相除,不知道是不是这个库的问题
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

4

帖子

1

主题

0

精华

新人

F 币
20 元
贡献
9 点
沙发
 楼主| 发表于 2023-8-14 16:49:36 来自移动端 | 只看该作者
在subroutine下一行加入implicit none后也会继续报错,说我引入的这个库的ix,t都没有定义。用注释验证过后,发现前面两个传递函数是没有编译问题的,果然还是出在了子函数里面

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
631 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
板凳
发表于 2023-8-14 17:08:57 | 只看该作者
本帖最后由 kyra 于 2023-8-14 17:11 编辑

error1:Compilation Aborted (code1)
不是一个编译器抛出的错误。而是编译环境抛出的错误。意思是:由于一个(或一些)编译器抛出的错误,而编译中止
(题外话,为什么是中止呢?因为编译环境设计时认为有多个源代码文件需要编译,当前面的遇到了编译错误,那么后面的就没必要编译了,就中止了)

具体编译器抛出的错误,应该在前面显示。如果你从“错误列表”中无法看到前面有编译器抛出的错误,尝试在“输出”窗口查看。(题外话,错误列表是对输出窗口的美化,但Visual Studio经常会美化错误,所以需要看原始的“输出”窗口)

IMSL有若干版本,要根据你安装的版本来决定该如何使用IMSl函数库。

4

帖子

1

主题

0

精华

新人

F 币
20 元
贡献
9 点
地板
 楼主| 发表于 2023-8-14 17:17:17 | 只看该作者
kyra 发表于 2023-8-14 17:08
error1:Compilation Aborted (code1)
不是一个编译器抛出的错误。而是编译环境抛出的错误。意思是:由于 ...

前面两个传递函数没有问题,用注释查看后是后面的子函数有问题,IMSL我装的应该是6.0,引用的话是按照说明书上引用的,就是不知道子函数中还有没有哪里出错了,我回去再看看输出列表,谢谢您

4

帖子

1

主题

0

精华

新人

F 币
20 元
贡献
9 点
5#
 楼主| 发表于 2023-8-15 09:41:10 | 只看该作者
kyra 发表于 2023-8-14 17:08
error1:Compilation Aborted (code1)
不是一个编译器抛出的错误。而是编译环境抛出的错误。意思是:由于 ...

这是输出列表,看样子不是IMSL的问题,这个internal error内部错误是什么原因呢,不知道大佬知道吗
1>------ 已启动生成: 项目: MLN, 配置: Debug Win32 ------
1>Compiling with Intel(R) Visual Fortran Compiler XE 14.0.1.139 [IA-32]...
1>Console1.f90
1>E:\MLN\axisymmetric-mln-fortran\MLN\MLN\Console1.f90(277): internal error: Please visit 'http://www.intel.com/software/products/support' for assistance.
1>    th = 1.0*10**(-7.0)
1>^
1>[ Aborting due to internal error. ]
1>compilation aborted for E:\MLN\axisymmetric-mln-fortran\MLN\MLN\Console1.f90 (code 1)
1>
1>Build log written to  "file://E:\MLN\axisymmetric-mln-fortran\MLN\MLN\Debug\BuildLog.htm"
1>MLN - 1 error(s), 0 warning(s)
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
631 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
6#
发表于 2023-8-15 11:28:19 | 只看该作者
那应该是IMSL版本和编译器有一些不匹配。
根据我使用IMSL的经验,这不是一个大问题。你可以试试去掉 use numerical_libraries 这个语句。

除此之外,代码中的问题还是挺多的。
首先,implicit none 不能去掉,一定要写!!
然后,aa , bb , inc 这些变量在 subroutine a 和 subroutine b 中定义了,但 subroutine wall_plus 中没有。

你需要理解,不同的子程序之间,变量作用域是独立的。所以 subroutine a 里面的 aa,不能在 wall_plus 中使用。
要使用的话,你可以通过参数传递,或者 common 公共区,或者module。

[Fortran] 纯文本查看 复制代码
module dataMod
  implicit none
  real :: inc,aa(2,2),bb(2)

contains
!传递函数a
subroutine a(theta0,point0,point2,point3)
  real theta0,point0(2),point2(4),point3(4)
  real m23
  m23 = (point3(4)-point2(4))/(point3(3)-point2(3))
  aa(1,1) = 1
  aa(1,2) = -m23
  aa(2,1) = 1
  aa(2,2) = -tan(0.5*(theta0+inc))
end subroutine a

!传递函数b
subroutine b(theta0,point0,point2,point3)
  real theta0,point0(2),point2(4),point3(4)
  real m23
  m23 = (point3(4)-point2(4))/(point3(3)-point2(3))
  bb(1) = point3(4)-m23*point3(3)
  bb(2) = point0(2)-tan(0.5*(theta0+inc))*point0(1)
end subroutine b

!左行壁面进程
subroutine wall_plus(theta0,point0,point2,point3,theta_new,point_new)
  include "link_fnl_shared.h"
  use linear_operators
  implicit none
  real theta0,point0(2),point2(4),point3(4)
  real theta_new,point_new(2),old_theta,old_point(2)
  real , parameter :: th = 1.0e-7
  real tol
  tol = 1.0e3
  theta_new = theta0
  point_new(:) = point0(:)

  do while(tol>th)
    old_point = point_new
    old_theta = theta_new
    inc = theta_new
    call a(theta0,point0,point2,point3)
    call b(theta0,point0,point2,point3)
    point_new = aa .ix. bb
    theta_new = point2(1)+sqrt(((point_new(1)-point2(3))**2+(point_new(2)-point2(4))**2)/&
      ((point3(3)-point2(3))**2+(point3(4)-point2(4))**2))*(point3(1)-point2(1))
    tol=max(abs(point_new(1)-old_point(1)),abs(point_new(2)-old_point(2)))
    tol=max(tol,abs(theta_new-old_theta))
  end do
end subroutine wall_plus

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

本版积分规则

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

GMT+8, 2024-4-29 17:12

Powered by Tencent X3.4

© 2013-2024 Tencent

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