Arguments are always passed by reference in Fortran, so a subprogram can
change their values as seen by the calling program.  If this is not desired,
the subprograms should not modify their arguments.

Change

        double precision function dk22 (x1, x2)

to
        double precision function dk22 (a1, a2)
        double precision a1, a2
        x1 = a1
        x2 = a2

The function dk4 contains the same probable error, although it is doing no
harm now.  You should fix it anyway, as the calling program may change in
the future in a way that makes the error matter.

Jonathan Fry
SPSS Inc.
--------------------------------------------------------------

"Ming Dai , MTH" wrote:

> Please help me with the following Fortran program. When the line labeled
> 60 does not run, the result for q2 is correct; but when this line runs,
> the results are totally wrong, since the values of z in the do-loop
> change. Can someone tell why and how to correct it? Thanks in advance.
>
>         program  reproducingkernel
>         parameter  ( nobs = 10, m=4)
>         double precision z(m), q1(m,m), q2(m,m), dk4, dk22
>         do 10 j=1,m
>               z(j) = j*1.d0/nobs
> 10      continue
>         do 40 i=1,m
>           do 40 j=1,m
>                 write(*,*) i, j, z(i), z(j)
>                 q2(i,j) = - dk4( z(i) - z(j) )*1000.d0
> 60              q1(i,j) = dk22( z(i), z(j) ) * 1000.d0 + q2(i,j)
> 50        continue
> 40      continue
>
>         write(*,*) 'This is the RK for Ht'
>         write(*,*) q1
>         write(*,*)
>         write(*,*) 'This is the RK for Hw'
>         write(*,*) q2
>         end
>
>         double precision function dk22 (x1, x2)
>         double precision x1, x2
>         x1 = ( x1 - .5d0 ) ** 2
>         x1 = ( x1 - 1.d0 / 12.d0 ) / 2.d0
>         x2 = ( x2 - .5d0 ) ** 2
>         x2 = ( x2 - 1.d0 / 12.d0 ) / 2.d0
>         dk22 = x1 * x2
>         return
>         end
>
>         double precision function  dk4 (x)
>         double precision x
>         x = abs (x)
>         x = ( x - .5d0 ) ** 2
>         dk4 = ( x ** 2 - x /2.d0 + 7.d0 / 240.d0 ) / 24.d0
>         return
>         end
>
> =================================================================
> Instructions for joining and leaving this list and remarks about
> the problem of INAPPROPRIATE MESSAGES are available at
>                   http://jse.stat.ncsu.edu/
> =================================================================



=================================================================
Instructions for joining and leaving this list and remarks about
the problem of INAPPROPRIATE MESSAGES are available at
                  http://jse.stat.ncsu.edu/
=================================================================

Reply via email to