使用 Dislin 的双精度错误

Double-precision error using Dislin

我在尝试编译时遇到以下错误:

 call qplot (Z, B, m + 1)
             1
 Error: Type mismatch in argument 'x' at (1); passed REAL(8) to REAL(4)

一切似乎都是双精度的,所以我不禁认为这是一个 Dislin 错误,尤其是考虑到它是参考 Dislin 语句出现的。我究竟做错了什么?我的代码如下:

program test

use dislin

integer :: i
integer, parameter :: n = 2
integer, parameter :: m = 5000
real (kind = 8) :: X(n + 1), Z(0:m), B(0:m)

X(1) = 1.D0
X(2) = 0.D0
X(3) = 2.D0

do i = 0, m
    Z(i) = -1.D0 + (2.D0*i) / m
    B(i) = f(Z(i))
end do

call qplot (Z, B, m + 1)

    read(*,*)

contains

real (kind = 8) function f(t)           
    implicit none
    real (kind = 8), intent(in) :: t
        real (kind = 8), parameter :: pi = Atan(1.D0)*4.D0  
            f = cos(pi*t)
end function f

end program

DISLIN manual 我读到 qplot 需要(单精度)浮点数:

 QPLOT connects data points with lines.

The call is:    CALL QPLOT (XRAY, YRAY, N)  level 0, 1
or:     void qplot (const float *xray, const float *yray, int n);

XRAY, YRAY  are arrays that contain X- and Y-coordinates.
N   is the number of data points.

所以你需要将ZB转换为real

call qplot (real(Z), real(B), m + 1)

请考虑使用 ISO_Fortran_env 模块和预定义常量 REAL32REAL64,而不是使用固定数字作为数字种类(编译器之间有所不同)。

qplot 例程需要默认实数。您可以转换您的数据

 call qplot(real(Z), real(B), m + 1)

赞成kind = 8的评论,很丑,如果你坚持8至少要声明一个常量

   integer, parameter :: rp = 8

并使用

   real(rp) ::

正如前两个答案所解释的,dislin 例程的标准版本需要单精度参数。我发现使用它们最方便,因为我可能有单参数或双参数,使用 real 技术转换双变量的类型。丢失的精度似乎不太可能在图表上被察觉。但是,如果您希望完全以双精度工作,则可以使用一组替代例程。它们具有相同的名称,但采用双精度参数。要获得它们,link 在图书馆 "dislin_d"。