Search code examples
functiongraphplotfortrandouble-precision

Double-precision error using Dislin


I get the following error when trying to compile:

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

Everything seems to be in double precision so I can't help but think it is a Dislin error, especially considering that it appears with reference to a Dislin statement. What am I doing wrong? My code is the following:

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

Solution

  • From the DISLIN manual I read that qplot requires (single precision) floats:

     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.
    

    So you need to convert Z and B to real:

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

    Instead of using fixed numbers for the kind of numbers (which vary between compilers), please consider using the ISO_Fortran_env module and the pre-defined constants REAL32 and REAL64.