Patch to userlib/deriv.pro to add MAX_VALUE keyword [message #1558] |
Fri, 24 December 1993 09:22  |
rfinch
Messages: 51 Registered: March 1991
|
Member |
|
|
Following context diff, when run through patch, will add the MAX_VALUE
keyword to the userlib function deriv.pro. However, I still believe
it would be better if IDL had the fundamental notion of missing values
built-in to their basic mathematics; IEEE NaN might be a good choice.
If IDL understood NaN's, you wouldn't even need keywords for missing
values or max_value (presuming that most usage of MAX_VALUE really is
for missing values).
*** deriv.pro Fri Dec 24 09:19:35 1993
--- deriv.pro~ Fri Dec 24 09:20:03 1993
***************
*** 1,6 ****
! Function Deriv, X, Y, max_value=max_value
;+
; NAME:
; DERIV
--- 1,6 ----
! Function Deriv, X, Y
;+
; NAME:
; DERIV
***************
*** 13,20 ****
; Numerical analysis.
;
; CALLING SEQUENCE:
! ; Dy = Deriv(Y, max_value=mv) ;Dy(i)/di, point spacing = 1.
! ; Dy = Deriv(X, Y, max_value=mv) ;Dy/Dx, unequal point spacing.
;
; INPUTS:
; Y: Variable to be differentiated.
--- 13,20 ----
; Numerical analysis.
;
; CALLING SEQUENCE:
! ; Dy = Deriv(Y) ;Dy(i)/di, point spacing = 1.
! ; Dy = Deriv(X, Y) ;Dy/Dx, unequal point spacing.
;
; INPUTS:
; Y: Variable to be differentiated.
***************
*** 22,30 ****
; spacing for Y (i.e., X(i) = i) is assumed.
;
; OPTIONAL INPUT PARAMETERS:
! ;max_value: Maximum value; original values greater than this and
! ; their neighbors will be restored to their original value,
! ; not the first derivative.
;
; OUTPUTS:
; Returns the derivative.
--- 22,28 ----
; spacing for Y (i.e., X(i) = i) is assumed.
;
; OPTIONAL INPUT PARAMETERS:
! ; As above.
;
; OUTPUTS:
; Returns the derivative.
***************
*** 51,78 ****
n = n_elements(x)
if n lt 3 then message, 'Parameters must have at least 3 points'
- count=0
if n_params(0) ge 2 then begin
if n ne n_elements(y) then message,'Vectors must have same size'
- IF KEYWORD_SET(max_value) THEN BEGIN
- mv_ndx = where(y GT max_value OR $
- shift(y, -1) GT max_value OR $
- shift(y, +1) GT max_value, count)
- ENDIF
d = float(shift(y,-1) - shift(y,1))/(shift(x,-1) - shift(x,1))
d(0) = (-3.0*y(0) + 4.0*y(1) - y(2))/(x(2)-x(0))
d(n-1) = (3.*y(n-1) - 4.*y(n-2) + y(n-3))/(x(n-1)-x(n-3))
- IF count GT 0 THEN d(mv_ndx) = y(mv_ndx)
end else begin
- IF KEYWORD_SET(max_value) THEN BEGIN
- mv_ndx = where(x GT max_value OR $
- shift(x, -1) GT max_value OR $
- shift(x, +1) GT max_value, count)
- ENDIF
d = (shift(x,-1) - shift(x,1))/2.
d(0) = (-3.0*x(0) + 4.0*x(1) - x(2))/2.
d(n-1) = (3.*x(n-1) - 4.*x(n-2) + x(n-3))/2.
- IF count GT 0 THEN d(mv_ndx) = x(mv_ndx)
endelse
return, d
end
--- 49,63 ----
--
Ralph Finch 916-653-8268 voice
rfinch@venice.water.ca.gov 916-653-6077 fax
Any opinions expressed are my own; they do not represent the DWR
|
|
|