; $Id: ops2d.pro,v 1.4 2005/02/03 18:04:12 azuah Exp $
;###############################################################################
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used of if the code in this file is
;  included in another product.
;
;###############################################################################
; Written by J.R.D. Copley.
;;;**********************************************************************
; Addition of quantities: [a,da]+[b,db] --> [a+b,da+db].
function a2d,a,b
as = size(a,/tname) eq "STRUCT" ; a has an associated error
bs = size(b,/tname) eq "STRUCT" ; b has an associated error
if (not as and not bs) then return, a+b
if (not as and bs) then return, {q:a+b.(0),e:b.(1)}
if (as and not bs) then return, {q:a.(0)+b,e:a.(1)}
if (as and bs) then return, {q:a.(0)+b.(0),e:a.(1)+b.(1)}
end

;;;**********************************************************************
; Subtraction of quantities: [a,da]-[b,db] --> [a-b,da-db].
function s2d,a,b
as = size(a,/tname) eq "STRUCT" ; a has an associated error
bs = size(b,/tname) eq "STRUCT" ; b has an associated error
if (not as and not bs) then return, a-b
if (not as and bs) then return, {q:a-b.(0),e:-b.(1)}
if (as and not bs) then return, {q:a.(0)-b,e:a.(1)}
if (as and bs) then return, {q:a.(0)-b.(0),e:a.(1)-b.(1)}
end

;;;**********************************************************************
; Multiplication of quantities: [a,da]*[b,db] --> [a*b,b*da+a*db].
function m2d,a,b
as = size(a,/tname) eq "STRUCT" ; a has an associated error
bs = size(b,/tname) eq "STRUCT" ; b has an associated error
if (not as and not bs) then return, a*b
if (not as and bs) then return, {q:a*b.(0),e:a*b.(1)}
if (as and not bs) then return, {q:a.(0)*b,e:a.(1)*b}
if (as and bs) then return, {q:a.(0)*b.(0),e:b.(0)*a.(1)+a.(0)*b.(1)}
end

;;;**********************************************************************
; Division of quantities: [a,da]/[b,db] --> [a/b,(b*da-a*db)/b^2].
function d2d,a,b
as = size(a,/tname) eq "STRUCT" ; a has an associated error
bs = size(b,/tname) eq "STRUCT" ; b has an associated error
if (not as and not bs) then return, float(a)/b
if (not as and bs) then return, {q:float(a)/b.(0),e:-float(a)*b.(1)/b.(0)^2}
if (as and not bs) then return, {q:float(a.(0))/b,e:float(a.(1))/b}
if (as and bs) then return, $
	{q:float(a.(0))/b.(0),e:float(a.(1))/b.(0)-float(a.(0))* b.(1)/b.(0)^2}
end

;;;**********************************************************************
; Raising a quantity to a power: [a,da]^p --> [a^p,p*a^(p-1)*da].
function p2d,a,p
as = size(a,/tname) eq "STRUCT" ; a has an associated error
if (not as) then return, a^p else return, {q:a.(0)^p,e:p*a.(0)^(p-1)*a.(1)}
end

;;;**********************************************************************
; This function definition is included so that the mathematical functions
; are compiled by including a statement such as "z=ops2d()".
;
function ops2d
return,1
end
