墨o离 发表于 2023-8-14 16:44:39

IMSL编译问题

之前没啥代码经验,现在导师需要,在自学fortran
导师让把一个MATLAB的程序改为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) ; %2x2 matrix
    B=@(INC) ;

    tol=1e3;
    theta_new=theta0;
    point_new=;
    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=;
end


fortran程序中用了IMSL的库计算了矩阵相除,不知道是不是这个库的问题:'(

墨o离 发表于 2023-8-14 16:49:36

在subroutine下一行加入implicit none后也会继续报错,说我引入的这个库的ix,t都没有定义。用注释验证过后,发现前面两个传递函数是没有编译问题的,果然还是出在了子函数里面

kyra 发表于 2023-8-14 17:08:57

本帖最后由 kyra 于 2023-8-14 17:11 编辑

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

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

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

墨o离 发表于 2023-8-14 17:17:17

kyra 发表于 2023-8-14 17:08
error1:Compilation Aborted (code1)
不是一个编译器抛出的错误。而是编译环境抛出的错误。意思是:由于 ...

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

墨o离 发表于 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 ...
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 个 ==========

kyra 发表于 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。

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
页: [1]
查看完整版本: IMSL编译问题