On 10 Jan 2001 10:39:24 -0800, [EMAIL PROTECTED] (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.

If I remember correctly ... whether this compiles, or 
how this performs, should depend on the version
of the Fortran compiler you are using ....  I haven't
read a Fortan Standards manual in 15 years, so 
I could be out of date.  It was 5 or 10 years earlier
when I thought I had documented this ugly flaw in a 
compiler.  (In the end:  "It's not a bug, it's a feature.")

 = dk22(x1,x2) is a FUNCTION =
According to the original Fortran standard, a "function" 
is not allowed to change the values of its arguments, but
your dk22 does.  Or tries to.  

 a) Some Fortran compilers allow you  to change the values, 
and they call it an "extension" to the language.
 b) Some don't, and also refuse to compile the routine.  
 c) Others allow you to pretend to change the values (okay, if you 
want to do some 'intermediate computations' before your final
computation), but don't return values to the calling program.

(c) will foul you up if you are counting on (a), and vice-versa.


>       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
-- 
Rich Ulrich, [EMAIL PROTECTED]
http://www.pitt.edu/~wpilib/index.html


=================================================================
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